• Advertisement
Sign in to follow this  

How to find triangle which consists (x,z)

This topic is 1663 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

As we know terrain might be rendered from heightmap (some raw data prepared with the aid of photoshop) and from mesh which You for example prepare in some 3D tool like Blender. I am actually using the second way of terrain. I have rendered terrain with the aid of mesh. And I have object located at (x,z) and now I have to calculate height of the object location - coordinate y. So I have to find triangle from my terrain mesh which consists (x,z). I have problem with "if" condition. Could You help me to fulfill all the possibilities of "if" condition?

vector< D3DXVECTOR > terrainVerts;  //each entry has 3 floats (x,y,z) of vertex
vector< vector<u32> > terrainFace;   //each entry has 3 DWORD vertex indices

void Object::updateHeightForObject(D3DXVECTOR3& entry);
float x = entry.x; //x coordinate of my object
float y = entry.y; //y coordinate of my object which I need update 
float z = entry.z; //z coordinate of my object

u32 numFaces = static_cast<u32>(terrainFace.size());

for(u32 i=0; i<numFaces; ++i)
float x1 = terrainVerts[ terrainFace[i][0] ].x;
float x2 = terrainVerts[ terrainFace[i][1] ].x;
float x3 = terrainVerts[ terrainFace[i][2] ].x;
float y1 = terrainVerts[ terrainFace[i][0] ].y;
float y2 = terrainVerts[ terrainFace[i][1] ].y;
float y3 = terrainVerts[ terrainFace[i][2] ].y;
float z1 = terrainVerts[ terrainFace[i][0] ].z;
float z2 = terrainVerts[ terrainFace[i][1] ].z;
float z3 = terrainVerts[ terrainFace[i][2] ].z;

if(x > x1 && x < x2 ????   //there must be some complex if
      //triangle found
      //when I find triangle then I have to use some algorithm which I have in my heightmap class in order to get calculate height offset value
, however this is easy for me, because I have implementation}

Edited by anders211

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement