Skip to main content
GameDev.net gamedev.net
🔒 Locked

Intersection Detection Question

Started by Innovatus Dec 31, 2002 at 7:24 PM 2 replies 400+ views
Original Post
Innovatus
Innovatus
This is a function in a game I am making. Can anyone see why I am not able to detect a intersection with Objects in the Tank List ? I am able to detect intersection with the Terrain mesh though. I am passing the function a Projectile Position and a Direction it is traveling. BOOL CMyD3DApplication::CheckHit(D3DXVECTOR3 vPos,D3DXVECTOR3 vDir) { BOOL Hit; float u, v, Dist; DWORD FaceIndex; vDir += vPos; cObject* TankPtr = m_TankList.GetParentNode(); while(TankPtr != NULL) { D3DXIntersect(TankPtr->mp_Mesh->GetSysMemMesh(),&vPos, &vDir,&Hit,&FaceIndex,&u,&v,&Dist,NULL,NULL); if( Hit == TRUE && TankPtr->ID != m_pSelectedObject->ID && Dist < 0.2f) { return TRUE; } TankPtr = TankPtr->Next; } // This part works D3DXIntersect(m_pTerrain->GetSysMemMesh(), &vPos, &vDir, &Hit, &FaceIndex, &u, &v, &Dist,NULL,NULL); if(Hit == TRUE && Dist < 0.01f) return TRUE; return FALSE; } Inno
Inno
moonw
moonw

vDir += vPos;


You should not add the position to the direction.


Innovatus
Innovatus
I added this to the TankList Loop and it work great now Thanks =)

TankWorldMatx = TankPtr->m_WorldPos.GetMatrix();

D3DXMatrixInverse(&InverseTankWorldMatx, NULL, TankWorldMatx);

D3DXVec3TransformCoord(&vInversePosition, &vPos, &InverseTankWorldMatx);

D3DXVec3TransformNormal(&vInverseDirection, &vDir, &InverseTankWorldMatx);

Inno
Inno

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.