Terrain Meshes

Blitz3D Forums/Blitz3D Programming/Terrain Meshes

Oiduts Studios(Posted 2009) [#1]
Well i had a problem working with terrains before (LOD) so i just went with a mesh terrain. All sounded well until i have now reached the point where i would like to easily place grass on the ground. The terrain is a island shape and i was wondering if there was a command or function i could make, like terrainy(), that could return the y coordinate of the mesh at a specified x,y location? This is so i could place grass randomly or in patches along with rocks and other natural items. Other than something like terrainy, would a linepick setup work? Any help would be appreciated.


D4NM4N(Posted 2009) [#2]
Yes you can
The first bit below (the pick) is a snippet of code from T.Ed, from a case statment that operate how to "drop" a prop on the terrain using a mouse. It picks a point on the terrain using the camera and then performs a vertical linepick at that point.
Case "TOVECTOR"

	nodrop=0
	;pick nearest terrain vertex
	picx=pointer_x: picy=pointer_y	
	picked = CameraPick(actualcamera,pointer_x,pointer_y-60)
	px#=PickedX()
	py#=PickedY()
	pz#=PickedZ()

	picked=LinePick(px,py+10000,pz,0,-20000,0,2)	
	px#=0
	py#=0
	pz#=0

	;sort cursors out
	If picked=0
		change_pointer(arrowX):
		arrowtext="Align To Vector Mode (Not over terrain!)"
		nodrop=1
	Else
		change_pointer(arrowFinger):arrowtext="Align to Vector Mode"
		Aligned=1
	EndIf 
	If mouse_button1hit=0 nodrop=1
	px#=PickedX()
	py#=PickedY()
	pz#=PickedZ()

	makeselected=1

lots of code between here, but then (using the "PICK" from above):
			If aligned
				AlignToVector i\h,PickedNX(),PickedNY(),PickedNZ(),2
				i\rx=EntityPitch (i\h)
				;i\ry=EntityYaw (i\h)
				i\rz=EntityRoll (i\h)
				aligned=0

			EndIf 
;after this you can turn the rntity in Y to a random amount for some diversity


The second bit uses the original pick and aligns the prop to the normal vector at the picked location.
Also, look at the castle demo (the bullet holes in particular;)

PS you also need to set the entity to pickable, entitypickmode(ent,2) i believe


Oiduts Studios(Posted 2009) [#3]
Ok, i looked at that code for a while. Thank you for giving me a good explanation on how this would be done, but because i am still a student i am sort of confused. I really do not grasp the concept of vectors as i am currently taking Algebra 2. I sure i understand that linepick acts as a "beam" and returns the ID of the object it hit first, then PickedNX(),PickedNY(), and PickedNZ() return the location of the intersection between the beam and the object (terrain).
But would something along the lines of this work?

	
		x=Rnd(200,220)
		z=Rnd(200,220)
		LinePick(x,10000,z,0,-20000,0,2)	
		AlignToVector grass,x,PickedNY(),z),2



Matty(Posted 2009) [#4]
No.

You need to position the grass mesh using "pickedx(),pickedy(),pickedz()"

and you need to align the direction of the mesh using the picked normals..ie pickednx(),pickedny(),pickednzy() - assuming you don't just want the grass pointing vertically in which case you should not need to align it.


Oiduts Studios(Posted 2009) [#5]
opps my bad, i did not analyze that carefully...


D4NM4N(Posted 2009) [#6]
Correct use the pickedX etc to position it and then align to vector to align its rotation.