Jump to content
Rick

Get Terrain height

Recommended Posts

Is there a way to get the Terrain height in Lua? I don't see any Terrain specific stuff on the API Reference page.

Share this post


Link to post

Those are interesting links. Says I don't have permission to view them :) Thx.

Share this post


Link to post

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).

Share this post


Link to post

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

Share this post


Link to post

Thank you.  Got it through your code.  I was simply missing the cast.

Terrain *terrain = (Terrain *)world->GetEntity(i);

And in C as well, GetHeight returns 0 (which is not correct) while GetElevation returns a proper height.

 

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

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.

×
×
  • Create New...