Jump to content
  • Advertisement
Sign in to follow this  
FireSoul

Collision Detection: converting rays into object space

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

Hello, at the moment im trying to do collision detection with my objects using by calculaitng every frame if one intersects with another. The way in which I am doing this is by creating a vector (or ray) between the position of the object your currently testing with another object that exists within the game. Using this vector, I am trying to transform it into object space, so that i can pass it to the D3DXIntersect() method. The problem is converting the ray so that it is rotated int he same way the object is, inversly so that it is in the right positions in object space. The collision works perfectly whenever the object being tested against has not rotated, for this I use the following code: D3DXMATRIXA16 m = pGlobal_Game->pData->objData[n].mt.d3dMat, inverse_m; D3DXMatrixInverse(&inverse_m, NULL, &m); BOOL bHit; DWORD dwFace; float bc_uPos, bc_vPos, fDist; vPos = vPos; vDir = vDirPos; fCurrentDist = GetDistBetweenVector(vPos, vDirPos); Normalise(&vDir); D3DXIntersect(pGlobal_Game->pData->Files[pGlobal_Game->pData->objData[n].pObjT->iFileNo].m.pMesh, &vPos, &vDir, &bHit, &dwFace, &bc_uPos, &bc_vPos, &fDist, NULL, NULL); if(bHit) { if(fDist < fMoveDist) { return true; } } But in my attempt to transform the ray inversly so that it conforms with the rotations of the object, it does not work well (only gets the position of the object correct). Below, 'm' is the matrix in which i want to transform the ray relative to, 'inverse_m' being its inverse. I have only my own understanding of how matrices are used, and so i dont know if this is correct. D3DXMATRIXA16 m = pGlobal_Game->pData->objData[n].mt.d3dMat, inverse_m; D3DXMatrixInverse(&inverse_m, NULL, &m); BOOL bHit; DWORD dwFace; float bc_uPos, bc_vPos, fDist; vPos.x = vPos.x * inverse_m._11 + vPos.y * inverse_m._21 + vPos.z * inverse_m._31; vPos.y = vPos.x * inverse_m._12 + vPos.y * inverse_m._22 + vPos.z * inverse_m._32; vPos.z = vPos.x * inverse_m._13 + vPos.y * inverse_m._23 + vPos.z * inverse_m._33; vDirPos.x = vDirPos.x * inverse_m._11 + vDirPos.y * inverse_m._21 + vDirPos.z * inverse_m._31; vDirPos.y = vDirPos.x * inverse_m._12 + vDirPos.y * inverse_m._22 + vDirPos.z * inverse_m._32; vDirPos.z = vDirPos.x * inverse_m._13 + vDirPos.y * inverse_m._23 + vDirPos.z * inverse_m._33; vPos = vPos; vDir = vDirPos; fCurrentDist = GetDistBetweenVector(vPos, vDirPos); Normalise(&vDir); D3DXIntersect(pGlobal_Game->pData->Files[pGlobal_Game->pData->objData[n].pObjT->iFileNo].m.pMesh, &vPos, &vDir, &bHit, &dwFace, &bc_uPos, &bc_vPos, &fDist, NULL, NULL); if(bHit) { if(fDist < fMoveDist) { return true; } } Can someone tell me how i could possibly transform a ray into object space, given its matrix (the ray having two 3d co-ordinates). Any help is appreciated. Thanks.

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!