Skip to main content
gamedev.net
🔒 Locked

Having problem with D3DXIntersect

Started by Andreas Persson May 14, 2006 at 3:21 AM 4 replies 1.9k views
Original Post
Andreas Persson
Andreas Persson
Hi I have a bit of trouble with D3DXIntersect. I am using it in a fps in the shooting function and there is something wrong. Hopefully someone will be able to help me. for(vector::iterator it = world->GetSoldiers()->begin(); it != world->GetSoldiers()->end(); it++) { if((*it)->GetActive() == true) { rayDir = *m_pCamera->GetLookAt() - *m_pCamera->GetPos(); D3DXVec3Normalize(&rayDir, &rayDir); float32 detG = D3DXMatrixDeterminant((*it)->GetMatrixLocal()); D3DXMATRIX m_lInverse; D3DXMatrixInverse( &m_lInverse, &detG, (*it)->GetMatrixLocal()); D3DXVECTOR3 rayPos; D3DXVec3TransformCoord( &rayPos, &m_vPos, &m_lInverse); D3DXVec3TransformNormal( &rayDir , &rayDir, &m_lInverse); D3DXVec3Normalize(&rayDir, &rayDir); D3DXIntersect((LPD3DXBASEMESH)(*it)->GetMesh()->GetD3DMesh(), &rayPos , &rayDir, &hit, &faceIndex, &u, &v, &dist, &ppAllHits, &pCountOfHits); &rayPos , &rayDir, &hit, &faceIndex, &u, &v, &dist, &ppAllHits, &pCountOfHits); if(hit == true) { (*it)->SetActive(false); } } }
Casual game dev www.apgames.se
XiotexStudios
XiotexStudios
Can you be a bit more detailed.

One observation:

If each soldier is a high poly mesh then doing this check on each mesh if there are lots of them is extremely expensive and likely to be redundant in a large world.

Try to sectorize your world so that you can narrow down the tests to only those soldiers that are in your view.

Also, do you really need to know which precise tri you hit? You could create a series of collision spheres around you mesh and simplify your intersection test to those spheres. An example is a collision sphere around the head and the torso - it would give you enough accuracy to tell you if you have a head shot :)

Byron Atkinson-JonesXiotex Studioswww.xiotex.com
Andreas Persson
Andreas Persson
Yes I will use different basic shapes for checking collision. What I was wondering is if I am doing anything wrong with the inverse and determinant or somewhere else.
Casual game dev www.apgames.se
XiotexStudios
XiotexStudios
Honestly - I don't know...

But take a look at this... it may help:

http://www.mvps.org/directx/articles/improved_ray_picking.htm

Byron Atkinson-JonesXiotex Studioswww.xiotex.com
jollyjeffers
jollyjeffers
Quote:
Original post by Andreas Persson
I am using it in a fps in the shooting function and there is something wrong.
Is this a game of 20 questions?

I've said it many times before (although you personally may have missed those), and its also in the Want to post? Read this first. sticky thread at the top of the forum listing:

Quote:
Include all the information that might be needed for people to give a good answer, including the version of DirectX you are using, as well as the SDK version, and any details about your hardware that you think might apply to the problem. If you don't give enough information, people won't be able to help you until you do.
(emphasis mine)

I dont want to sound harsh/unfriendly, but you really need to give us more information to work with: Help us to help you! [smile]

"there is something wrong" doesn't describe much to anyone - is it an actual error? Just incorrect results?

If its the latter - What sort of results are you getting? What sort of debugging have you done? Run any test-data? How are your results differing from what you're expecting?

Cheers,
Jack
<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ |
stewypeza
stewypeza
Hey,

I am having a similar problem with D3DXIntersect. I have read the following link: http://www.mvps.org/directx/articles/improved_ray_picking.htm

and seems to be relevant to myself. I am using this D3DXIntersect for my ray picking. The ray origin and direction are correct. The problem is that there is only an intersect when the ray is directed at the origin. This is where the meshes start but they have been moved into their position but it is as though they are still there. I am assuming from the above link that the faces of the mesh have to be transformed into world space. I have no idea how to do this.

Any help much appreciated.

My code for the ray picking is based on the pick example from the directX9.0 sdk. I am working with C++ directX.

Topic Locked

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

Sign in to reply to this topic.