Jump to content

Terrain Mesh Size or Terrain Diameter


mpatton
 Share

Recommended Posts

Hi all,

I having trouble getting the terrain mesh size in world space which I need to do some distance calculations in the vertex shader.

I have the following code in TerrainRender.cpp which I though would work, but doesn't...

shaderSolid->Uniform("meshSize", (float)(g_Game->GetWorld()->GetTerrain()->GetTilesPerSide() * TERRAIN_TILE_SIZE));

Basically what I need it for is to range the vertices e.g. -1 to 1, or 0 to 1 say.

Any ideas?

Also, is there some kind of radius or diameter used for circular terrain's? if I could grab that information as well that would help me a lot.

thanks in advance

Michael

Link to comment
Share on other sites

That looks like the right calculation to do. But techSolid/shaderSolid are used for the solid black sides of the map, not for the actual terrain tiles - you should specify the uniform inside TerrainRenderer::PrepareShader so that it's available to all the base/blend/decal terrain rendering calls.

Circular terrain is just square terrain with permanent shroud-of-darkness around the corners, so GetTilesPerSide() gives you the diameter.

Link to comment
Share on other sites

Cool thanks for that. My problem must now be with the way I get the camera normal matrix or world origin position for it, though they look correct to me...

I'm going to post my calculations here, if anyone can spot a problem with what I'm doing any help would be greatly appreciated

/*Camera Normal Matrix*/

CMatrix3D cameraInverse;

glGetFloatv(GL_MODELVIEW_MATRIX, cameraInverse._data);

CMatrix3D cameraNormalMatrix = cameraInverse.GetInverse().GetTranspose();

/*World Origin*/

CVector4D worldOrigin;

worldOrigin.X = CVector4D(cameraInverse._11, cameraInverse._12, cameraInverse._13, cameraInverse._14).Dot(CVector4D(0.0, 0.0, 0.0, 1.0));

worldOrigin.Y = CVector4D(cameraInverse._21, cameraInverse._22, cameraInverse._23, cameraInverse._44).Dot(CVector4D(0.0, 0.0, 0.0, 1.0));

worldOrigin.Z = CVector4D(cameraInverse._31, cameraInverse._32, cameraInverse._33, cameraInverse._44).Dot(CVector4D(0.0, 0.0, 0.0, 1.0));

worldOrigin.W = CVector4D(cameraInverse._41, cameraInverse._42, cameraInverse._43, cameraInverse._44).Dot(CVector4D(0.0, 0.0, 0.0, 1.0));

Ideally here I would have like to have just done cameraNormalMatrix * CVector4D(0.0, 0.0, 0.0, 1.0);

however I could not see any function to do this calculation. Is there one?

thanks in advance

Michael

Edited by mpatton
Link to comment
Share on other sites

GL_MODELVIEW_MATRIX might not always be set up correctly - the current version of the renderer tries to do everything with local per-shader transform matrices instead of the global GL state. Better to use g_Renderer.GetViewCamera().GetOrientation().GetTranslation() to get the world-space camera position (or use the g_Renderer.GetViewCamera().GetOrientation() matrix in other ways).

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.

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