Jump to content

Question about terrain


franck22000
 Share

Recommended Posts

I found this function I used to pass a position and a sample height height that returns the terrain height as well as any mesh object above it.

 

' RETURNS Y AS GROUNDHEIGHT '
Function GetPointOnGround:TVec3(pos:TVec3 var, pickheight:Float = 0)
Local retpos:TVec3;
pos.y = TerrainElevation(TTerrain(game.scene.terrain), pos.x, pos.z) ;
if (pickheight > 0)
	Local pick:TPick;
	pick = LinePick(Vec3(pos.x, pos.y + pickheight, pos.z), pos) ;
	if (pick <> null)
		pos.y = pick.y;
	End If
End If
retpos = pos;
Return retpos;
End Function

 

This next bit of code is simpler, it returns the height ABOVE the terrain rather than the actual terrain height but you can see how it works easily enough to adapt. It relies that you have access to the terrain entity which is normally done through some scene processor function if you're loading it from a file.

 

CamHeightAboveTerrain = MyCamera.Position.y - TerrainElevation(TTerrain(game.scene.terrain), MyCamera.Position.x, MyCamera.Position.z) ;

6600 2.4G / GTX 460 280.26 / 4GB Windows 7

Author: GROME Terrain Modeling for Unity, UDK, Ogre3D from PackT

Tricubic Studios Ltd. ~ Combat Helo

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