Place Entity on Terrain

Blitz3D Forums/Blitz3D Programming/Place Entity on Terrain

BLaBZ(Posted 2007) [#1]
I'm trying to place an entity on a terrain with the mouse. Would I be able to do this by making it pickable somehow?

In other words...
Im trying to get an entity to be the mouse on the 3d terrain.


Tab(Posted 2007) [#2]
You can do this in many ways, but here a fast example.

Type Cube
	Field ISpicked
	Field Mesh
End Type

Graphics3D 800,600,32,2

AmbientLight 255,255,255

terrain = CreateTerrain(32) ;LoadTerrain("blbla.bmp")
EntityPickMode terrain, 2
EntityColor terrain,90,155,0

Global pivot = CreatePivot()


Global Camera = CreateCamera()
PositionEntity Camera,0,5,0
RotateEntity Camera,30,-40,0


CreateEntity(10, 0, 10)

While Not KeyHit(1)

	MouseUpdate()
	UpdateEntity()


RenderWorld
Flip

Wend




Function MouseUpdate()

CameraPick( Camera, MouseX(), MouseY() )
		
PickedEnt = PickedEntity()
		
		
PositionEntity (pivot,PickedX#(),PickedY#(),PickedZ#())

If MouseHit(1)
	If PickedEnt <> 0 
		For cub.Cube = Each Cube
			If PickedEnt = cub\Mesh
				cub\IsPicked = True
			EndIf
		Next
	EndIf
EndIf

End Function


Function CreateEntity(PosX#, PosY#, PosZ#)

cub.Cube = New Cube
cub\Mesh = CreateCube()
PositionEntity cub\Mesh,PosX#, PosY#, PosZ#

End Function


Function UpdateEntity()

For cub.Cube = Each Cube
	
	If cub\IsPicked
	
		EntityPickMode cub\Mesh,0
		EntityColor cub\Mesh,0,200,0
			
		PositionEntity cub\Mesh, EntityX(pivot), EntityY(pivot)+1, EntityZ(pivot)
			
	Else
			

		EntityPickMode cub\Mesh,2
		EntityColor cub\Mesh,255,255,255
		
	EndIf

Next

End Function



BLaBZ(Posted 2007) [#3]
That is sooo perfect
Tab you rock
Thanks a lot