Rick Posted November 18, 2015 Share Posted November 18, 2015 Is there a way to get the Terrain height in Lua? I don't see any Terrain specific stuff on the API Reference page. Quote Link to comment Share on other sites More sharing options...
macklebee Posted November 18, 2015 Share Posted November 18, 2015 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. Quote 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 More sharing options...
Rick Posted November 18, 2015 Author Share Posted November 18, 2015 Those are interesting links. Says I don't have permission to view them Thx. Quote Link to comment Share on other sites More sharing options...
macklebee Posted November 18, 2015 Share Posted November 18, 2015 hmmm - i must have super secret double permission cuz they work just fine for me. Quote 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 More sharing options...
Thirsty Panther Posted November 18, 2015 Share Posted November 18, 2015 Works for me Quote Link to comment Share on other sites More sharing options...
gamecreator Posted July 16, 2017 Share Posted July 16, 2017 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). Quote Link to comment Share on other sites More sharing options...
macklebee Posted July 16, 2017 Share Posted July 16, 2017 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 1 Quote 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 More sharing options...
gamecreator Posted July 16, 2017 Share Posted July 16, 2017 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.