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

Intersection Detection Question

Started by Innovatus Dec 31, 2002 at 6:49 AM 4 replies 350+ 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
Innovatus
Innovatus
I have to add the Direction to the Postion the Direction I pass it is the velocity of the projectile. ie.
Position.x = 10.0
Position.y = 1.0
Position.z = 10.0

Direction.x = 1.0
Direction.y = 0.0
Direction.z = 1.0

so I need to add them to get the proper direction I dont want the direction to point to 1.0,0.0,1.0 I want it to point at 11.0,1.0,11.0.

Also the function works as is when checking the terrain mesh just not when going through the tank meshes
Inno
moonw
moonw


your are using the direction as the a point in space. that is wrong, when we say we are at

Position.x = 10.0
Position.y = 1.0
Position.z = 1.0

and or direction is

dirc = (1,0,0)
it mean we are hading at the positive direct of the x axis.
dirc = (-1,0,0)
the nagative direction and so on,
one way to do it is to
subtract the new pos form the old pos and normalize the result that will be you direction.

Innovatus
Innovatus
I got this Function working by inversing the Position and direction by each objects Local Matrix.

Also for some reason the Function works only sometimes when I DONT add vDir += vPos

when I do include that the Function seems more accurate when I dont add it, the projectile will pass through the object 30percent of the time.

Inno
Inno
moonw
moonw
this is from the directx docs

pRayPos
[in] Pointer to a D3DXVECTOR3 structure, specifying the origin coordinate of the ray.
pRayDir
[in] Pointer to a D3DXVECTOR3 structure, specifying the direction of the ray.


the mesh itself is not translated or rotated
so if your postion is translated and your direction is rotateid you need to multiple it by the inverse of your local matirx to but them in the correct space acording to the mesh space. or what works for you.

[edited by - moonw on January 2, 2003 5:27:16 PM]

Topic Locked

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

Sign in to reply to this topic.