Jump to content

Get Terrain height


Rick
 Share

Recommended Posts

assume the same as in LE2:

terrain:GetHeight(x,y) - Retrieves relative height - returned as a value between 0 and 1

terrain:GetElevation(x,y) - Retrieves the terrain height at the specified position. The height will be interpolated between the nearest 4 grid points to provide a very close estimation of the terrain height at any given position.

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

  • 1 year later...

Sorry to necro this but how do you do this in C?  Anyone have a code example since the functions don't seem to be documented (or invisible for some people again)?  I tried traversing the entities but world->GetEntity() doesn't recognize GetHeight or GetElevation (though I see the functions in Terran.h).

Link to comment
Share on other sites

how are you getting the terrain? It should work if you are properly accessing the terrain. Granted, the GetHeight() does not appear to provide any information anymore, but GetElevation() appears to work just fine.

window = Window:Create("terrain example",0,0,800,600)
context = Context:Create(window)
world = World:Create()
camera = Camera:Create()
camera:SetPosition(0,60,0)
camera:SetRotation(0,45,0)
camera:SetMultisampleMode(8)
pickinfo = PickInfo()
Map:Load("Maps/terrain.map")
for i=0,world:CountEntities()-1 do
	if world:GetEntity(i):GetClass()==Object.TerrainClass then
		terrain=world:GetEntity(i)
		tolua.cast(terrain,"Terrain")
		break
	end
end

camrot = camera:GetRotation()
gx=Math:Round(context:GetWidth()/2)
gy=Math:Round(context:GetHeight()/2)
move = 0
strafe = 0

while window:KeyDown(Key.Escape)==false do
	if window:Closed() then break end
	mouseposition = window:GetMousePosition()
	dx = mouseposition.x - gx
	dy = mouseposition.y - gy
	camrot.x = camrot.x + dy / 10.0
	camrot.y = camrot.y + dx / 10.0
	camera:SetRotation(camrot)
	window:SetMousePosition(gx,gy)
	move = Math:Curve(((window:KeyDown(Key.W)and 1 or 0) - (window:KeyDown(Key.S) and 1 or 0)),move,10)
	strafe = Math:Curve(((window:KeyDown(Key.D)and 1 or 0) - (window:KeyDown(Key.A) and 1 or 0)),strafe,10)
	camera:Move(strafe,0,move)
	
	p = window:GetMousePosition()
	if window:MouseDown(1) then
		pick = camera:Pick(p.x,p.y,pickinfo,9,true)
	end
	
	Time:Update()
	world:Update()
	world:Render()
 
	
	if pick then
		context:SetBlendMode(Blend.Alpha)
		context:DrawText("Height: "..terrain:GetHeight(pickinfo.position.x, pickinfo.position.y), 2, 2)
		context:DrawText("Elevation: "..terrain:GetElevation(pickinfo.position.x, pickinfo.position.z), 2, 22)
		context:SetBlendMode(Blend.Solid)
	end
	context:Sync()
end

 

terrain.jpg.f23407bdaefe53468cf6ca7b7cd4e058.jpg

  • Like 1

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...