Object Maps?

Blitz3D Forums/Blitz3D Programming/Object Maps?

Baystep Productions(Posted 2004) [#1]
Is there an way to use an image map, that positions entities depending on the location and color of a pixel in the image, like "BlitzGrass 3D"? A simple color map to make entities like trees and grass. Any ideas. I mean codes at least...


Picklesworth(Posted 2004) [#2]
I did this a while ago to make a map that determined what spots have better resources in a turn based strategy game. I'm gonig to give you a little example and see if you can figure it out (so you get a better grasp of the evil pixel functions while you're at it)

Just load in a grayscale map, and then do something like the following:

Since ReadPixel returns an annoying Bit colour for the read data, use this function to get the right R,G,B values.
Function BitToComponent(ARGB)
	B2Cr=ARGB Shr 16 And $FF
	B2Cg=ARGB Shr 8 And $FF
	B2Cb=ARGB And $FF
End Function

If you are using a grayscale map, you could just make this read the red value and return it.

Now, you divide this new number (which should be out of 255) by 255. So something like: Value = B2Cr / 255
This will return a number that can be used as a percentage. This number can then help to determine whatever percentage you need to find out in order to do something, so for your image map, you would have it read through every pixel (possibly with a step value of 5 or something) and then
If Value > 0.5 ;if colour is bigger than 50 percent white
 ;Random number for if object placement allowed
 ;(I would assume this could be useful to stop
 ;from getting huge masses of objects

 ;Object placement goes here if random number 
 ;is the right one, with Coordinate X being pixel X and 
 ;Coordinate Z being pixel Y

 ;If you are using a terrain, Y is terrainHeight 
 ;at those coordinates.
endIf

I hope this helped.


Bot Builder(Posted 2004) [#3]
Also, for the function to work you need these globals:
Global B2Cr,B2Cg,B2Cb


Then, after calling the function you can retrieve the value with these.