Need help placing trees

Blitz3D Forums/Blitz3D Beginners Area/Need help placing trees

flyingrob(Posted -0001) [#1]
Worked out how to use treeparty a bit, I have a tree situated above the ground ready to drop to ground. Haven't done the collision bit yet but I can't seem to get the tree to drop yet. Can you look at my code and tell me why it's not dropping. Thanks.

Graphics3D 800,600,16,1
SetBuffer BackBuffer()

Include "Include_treeParty.bb"
tpLoadEngine()

tree=tpLoadtree("tree1.tp",2)
PositionEntity tree, Rnd(-10,0),12,Rnd(-10,10)

Function touchground(n$)
If Not EntityCollided (n$,ground)
PositionEntity (n$,EntityX(n$),EntityY(n$)-0.1,EntityZ(n$))
End If
End Function

Cam=CreateCamera()
PositionEntity Cam,0,4,-20

light=CreateLight()

ground=CreateTerrain(512)
PositionEntity ground, -500,0,-500
ScaleEntity ground, 10,15,10
tex=LoadTexture( "greenery.jpg" )
EntityTexture ground, tex

While Not KeyDown( 1 )

touchground(tree)

If KeyDown( 205 )=True Then TurnEntity cam,0,-1,0
If KeyDown( 203 )=True Then TurnEntity cam,0,1,0
If KeyDown( 208 )=True Then MoveEntity cam,0,0,-0.05
If KeyDown( 200 )=True Then MoveEntity cam,0,0,0.05
If KeyDown( 30 )=True Then MoveEntity cam,.3,0,0
If KeyDown( 44 )=True Then MoveEntity cam,-.3,0,0
If KeyDown( 31 )=True Then TurnEntity������������������������������������������������������������������������������������������������������������������������������������


flyingrob(Posted 2008) [#2]
Hi,
I've been learning with the demo version for a while and have just bought the the full version. (if you're thinking of buying full version, do it, there's lots of help and it's much easier to learn)
I'd like a bit of help if anyone can. I'm placing a group of trees randomly on a hill and want them all to automatically place themselves at ground level. I can't set a specific "Y" level because of the slope and the random spacing. I've tried various ways using TranslateEntity which tells me I'm out of bounds using it with an array. I've been trying different things in the "y" of the PositionEntity tree using TerrainY also.

Dim tree (5)
For t = 0 To 5
tree(t) = LoadMesh("tree-snowy.x")
tex=LoadTexture("tree-snowy-uv.png",4)
EntityTexture tree(t),tex
PositionEntity tree(t),Rnd(-70,80),Rnd(50,60),Rnd(400,490)
RotateEntity tree(t),0,Rnd(0,360),0
ScaleEntity tree(t),Rnd(.75,1),Rnd(.75,2),Rnd(.75,1)
EntityType tree(t), type_ob


puki(Posted 2008) [#3]
This is often done with collisions - you drop your trees into your terrain, checking for a collision with the terrain, then you generally position your tree in the ground just a bit below the original Y collision - just to make sure the whole trunk is planted into the ground. Some AAA games forget the last part - such as Oblivion, and you can find trees not properly seated into the ground all the way round the trunk.


Billp(Posted 2008) [#4]
If you are using a mesh terrain you can use linepick (your mesh must be pickable) to find the height at a given x,z coord

Function MeshTerrainY#( Entity, Pick_Top#, Pick_Distance# )
	pick=LinePick( EntityX( Entity ), EntityY( Entity )+Pick_Top#, EntityZ(Entity), 0, Pick_Distance#, 0 )
	Return (PickedY())
End Function


if using a blitz terrain then

TerrainHeight# ( terrain,grid_x,grid_z )


then as puki mentions position them a bit lower on the y axis to allow for terrain varition


flyingrob(Posted 2008) [#5]
Thanks for the replies, I'm working on them but went and bought treeparty a few days ago so I'm also spending a bit of time getting to know that.


chwaga(Posted 2008) [#6]
another solution is to simply determine the y coordinate of the heightmap's pixel in question. In other words, if the x and z of the tree are at 12, 57 on the terrain (heightmap-wise), you just read the brightness of the pixel on the heightmap at that location, and turn it into a 3d Y value.


flyingrob(Posted 2008) [#7]
Something wrong happened when I tried to upload this last time. I've only just found out how to work the code box. Worked out how to use treeparty a bit, I have a tree situated above the ground ready to drop to ground. Haven't done the collision bit yet but I can't seem to get the tree to drop yet. Can you look at my code and tell me why it's not dropping. Thanks.




flyingrob(Posted 2008) [#8]
Thanks chwaga, but what I originally was trying to do was to get a group of trees to plant themselves automatically on very uneven ground but I don't know how to code this yet, I'm an old newbie trying to learn coding and not quite up to this level of coding yet.


mtnhome3d(Posted 2008) [#9]
look in the mak directory of the samples and find the markio example, in it there is code that places about 50 trees automatically. it uses types and searches the terrain for anything above a certain point(waterline) and below a certain height and puts trees randomly throughout the prescribed area.
<edit> this can also be modified to use linepicks to find the height and check whether or not it s in the height range and the place the trees.</edit>


chwaga(Posted 2008) [#10]
what you're missing there is a loop in the touchground function, however, I think I have a simpler solution, lemme just try it first.


chwaga(Posted 2008) [#11]
here we go, this works:

Function touchground(entity, terrain)
Local lx = EntityX(entity) : Local lz = EntityZ(entity)
PositionEntity entity, lx, TerrainHeight(terrain, lx, lz), lz
End Function


note: this could also easily be turned into a create and drop function.


flyingrob(Posted 2008) [#12]
Thanks to both mtnhome3d (will check that soon) and chwaga. I've now got the code I was using before to drop a single tree onto the ground. This is when the tree is a "x" mesh. If I try to do exactly the same with a treeparty tree it just stays in the air and dosn't drop. The tp tree loads alright and animates but won't descend. Any ideas why the treeparty tree won't work ?
Here's the working code with the x mesh, and below that, the code with the treeparty loaded.



-----------------------------------------------------------------------
-----------------------------------------------------------------------




chwaga(Posted 2008) [#13]
looks like it's something to do with how treeparty works. Are you sure the entity you should be dropping is 'tree'? Also, I still think my way is better :D