Place meshes on terrain

Blitz3D Forums/Blitz3D Programming/Place meshes on terrain

Paulo(Posted 2005) [#1]
Hi all,

Can anyone help with this please? I want to place trees on my terrain map (generated via an image map) and I wondered if I could place them via an image map as well. I had it in mind to make a map that had a specific coloured pixel representing a tree and read that image back in and use the coordinates to place the trees.

But I have no idea how to tackle converting the pixel data from an image in to PositionEntity tree,x,y,z and it seemed that even if I can get the X,Z, the Y might be more difficult. Any tips would be greatly appreicated.

Cheers,
Paulo


Damien Sturdy(Posted 2005) [#2]
Y=terrainy() ;)

Sorry mate i wont be around later to help, Just remember that your moving fireball problem is just a visual effect, its not actually happening.

now,You know how large the map you used to create the terrain is:

make your tree map the same size.
You also know how much you scaled the terrain.

So, load in the tree image, read through it, and when you find a tree

treex=pixelX*terrainScaleX
treez=pixely*terrainScaleZ

Treey=Terrainy(treex,treez); (well, i dont remember this command but this is close...)



Cheers


Paulo(Posted 2005) [#3]
nice one buddy, I get the TerrainY bit :) I'll see what I can do, but I can't get me head round...

load in the tree image, (thats easy enough) - read through it... this bit I dont get, how to read through and get the correct pixel data. :|


Thats cool about the fireball!! damn weird effect tho.

cya soon


Stevie G(Posted 2005) [#4]
I'd recommend having the heightmap / object data on the same image ... the red rgb is used for terrain heightmap so you could use the blue rgb value for the objects.

Say you had 10 objects.

Object1 , blue = 0
Object2 , blue = 25
etc....

Then you would colour that pixel based on it's height ( red ) and object ( blue )

So if the pixel was Color 255, 50,0 it would be object type 3 at the highest possible landheight.

To retreive the object data it's a simple case of checking the blue value in each pixel ...

e.g. Like this ...

Objectindex = Floor( ColorBlue() / 25 )

Select ObjectIndex
case 0 DoTree()
case 1 DoBuilding()
end select

etc....


Paulo(Posted 2005) [#5]
aye thanks Steve, agreed I would also prefer it on one map, I think I understand you, hopefully I can sort this out :)
Thanks again.


John Blackledge(Posted 2005) [#6]
Paulo, you need something like:
For x = 0 to <bitmap width>-1
 For y = 0 to <bitmap height>-1
  LockBuffer TextureBuffer(bitmap handle)
  rgb = ReadPixelFast(x,y,TextureBuffer(bitmap handle))
  UnlockBuffer TextureBuffer(bitmap handle)
  nClrR = rgb Shr 16 And %11111111
  nClrG = rgb Shr 8 And %11111111
  nClrB = rgb And %11111111
  If nClrG=255
   MakeTreeAt(x,y)
  Endif
 Next
Next

I'd make the bitmap separate from the others (not an alpha channel), so it's easier to change.
Make it black and spray it green (rgb=0,255,0) where you want trees.
Whenever a green pixel is found the coords will be sent to the MakeTreeAt() routine.


Paulo(Posted 2005) [#7]
Wow thanks John, thats really good of you!! :) I was still struggling with this!. Thanks again.