Archived

This topic is now archived and is closed to further replies.

mesh vs. terrain collision

This topic is 5010 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

hi there, i have my airplane flies pretty good but my collision with terrain is not correct. Both are .x meshes. I am using D3DXIntersect func. and i figured out that is working correct, but problem is that intersection test returns earlier hits. For example: A H1 | --------- | H2 / \ | /------------\ / \ \/ / \ / \----------/ \ / H3 A = airplane H1 = highest hill H2 = lower hill H3 = valey first of all hills are not even close to each other. When i fly near two hills it will first occur hit with H1 and then with H2, but i dont want that. How to pass two wrong hits and find latest third hit with valey H3? Which is the best method to find out good intersection hits? anyway i am using basic hit detection with passing terrain LPD3DXMESH object to function. tnx

Share this post


Link to post
Share on other sites
Could you actually post your intersection/collision detection code? Also, it would be very helpful if you could explain your problem in a little clearer, and with some more detail. Are you getting collisions when you don''t actually hit a hill, or is it that you''re not getting collision when you should?

Share this post


Link to post
Share on other sites
well nice ascii art after all ... 8-)

lets get to point..
Iam not getting collisions when i should. thats the best explanation. it seems that iam getting collisions earlier but look at the code:
btw code is from Jim Adams book.


float sIgrac::soulD3D_Kolizija_Y(LPD3DXMESH mesh,float x,float y,float z)
{
float Ydole,Ygore;

Ygore = soulD3D_Kolizija_YDole(mesh, x, y, z);
Ydole = soulD3D_Kolizija_YGore(mesh, x, y, z);

if(fabs(Ygore-y) < fabs(Ydole-y))
{
m_bHitOK = TRUE;
return Ygore;
}
else
{
m_bHitOK = FALSE;
}

return Ydole;
}

float sIgrac::soulD3D_Kolizija_YDole(LPD3DXMESH mesh,float x,float y,float z)
{
BOOL dodir;
float u,v;
DWORD faceIndex;
LPD3DXBUFFER bafer;

D3DXIntersect( mesh, // vrati adresu pokazivaca na mesh objekat

&D3DXVECTOR3(x,y,z), // pozicija trajektorije

&D3DXVECTOR3(0.0f,-1.0f,0.0f), // pravac trajektorije (nadole)

&dodir, // dali smo dodirnuli

&faceIndex, &u,&v, // rezervisano za druge stvari

&Distanca, // distanca do dodira

&bafer, // sadrzi odredjene hit infoe

&brojDodira // broj dodira

);

if( dodir == TRUE )
return y-Distanca;
return y;
}

float sIgrac::soulD3D_Kolizija_YGore(LPD3DXMESH mesh,float x,float y,float z)
{
BOOL dodir;
float u,v;
DWORD faceIndex;
LPD3DXBUFFER bafer;

D3DXIntersect( mesh, // vrati adresu pokazivaca na mesh objekat

&D3DXVECTOR3(x,y,z), // pozicija trajektorije

&D3DXVECTOR3(0.0f, 1.0f,0.0f), // pravac trajektorije (nagore)

&dodir, // dali smo dodirnuli

&faceIndex, &u,&v, // rezervisano za druge stvari

&Distanca, // distanca do dodira

&bafer, // sadrzi odredjene hit infoe

&brojDodira // broj dodira

);

if( dodir == TRUE )
return y+Distanca;
return y;
}

</code>



[edited by - Mursel on March 29, 2004 2:33:53 PM]

Share this post


Link to post
Share on other sites
Anyway i rewritted code. Well i figured out that d3dxintersect() is not used for real intersections between two meshes. So...only important thing to me was returned distance and that ray is just a imaginary vector used in conjuction with his origin and direction to detect hits.

thx for reply

Share this post


Link to post
Share on other sites