Archived

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

Wrestling with D3DXIntersect

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

Oh, how I wish the search feature was working I''m doing 3D collision detection/response for the first time, and have read up on the best ways of doing this. I''m using two great, and related articles that come highly recommended: Generic Collision Detection for Games Using Ellipsoids - Paul Nettle, 2000 Collision Detection and Response - Telemachos, 2000 I''ve been trying to implement it in DirectX, and its all set up and ready to go, except for the most important part! I basically need to know how to use the D3DXIntersect function to retrieve four values vital to the collision detection code, namely: 1) Whether a collision occurred 2) Distance to intersection point 3) Intersection point on sphere 4) Intersection point on polygon I figure that: 1) This is simply the value returned through pHit 2) The value returned through pDist 3) SpherePos - PlaneNormal? 4) Something to do with the pU, pV return values? Any help would be greatly appreciated, thanx, pan narrans

Share this post


Link to post
Share on other sites
Well I''ve looked for info on D3DXIntersect again but Google only returns about 15 links, and half of those are in foreign lingo

I understand how it works, but it only returns an index to the face that was hit and I have no idea what to do with it. I need to find the actual intersection point on the polygon?

Share this post


Link to post
Share on other sites
Apparently, there is some problem with the D3DXIntersect*() calls and the Pentium 4 by the way... If you have a P4, it''s probably best to give it up and write the intersection yourself.

- JQ
Full Speed Games. Period.

Share this post


Link to post
Share on other sites
I have a prob with the following:

----------------------------------------------------------------

struct D3DVERTEX
{
D3DXVECTOR3 p;
D3DXVECTOR3 n;
FLOAT tu, tv;
};

...

void Function
{
LPDIRECT3DVERTEXBUFFER8 pVB;
LPDIRECT3DINDEXBUFFER8 pIB;

g_Mesh->GetVertexBuffer( &pVB );
g_Mesh->GetIndexBuffer( &pIB );

WORD *pIndices;
D3DVERTEX *pVertices;

pIB->Lock( 0,0,(BYTE**)&pIndices, 0 );
pVB->Lock( 0,0,(BYTE**)&pVertices, 0 );

----------------------------------------------------------------

The Pick example uses the FVF struct D3DVERTEX for the pointer to the vertex buffer (because it defines the size of each vertex).
But my app doesn''t have such a struct, it uses meshes loaded from X files. How can I create a pointer to an area large enough to store one of my vertices?

Share this post


Link to post
Share on other sites
Kinda late, I know, since an answer was already given.

But I guess when you use D3DXIntersect() your program will be faster then when doing all the work on your own (atleast, when you use it right), since (I hope) the d3d(x) stuff is pretty wel optimized.

Anyway, you are able to calculate the intersectionpoint using the pU and the pV value. It uses a barycentric coordsystem and it can be used like this:

V1 = Face-coord 1 ( you get the face which is collided with )
V2 = Face-coord 2 ( so you are able to calculate or look them up )
V3 = Face-coord 3 ( and find there vertices )
IntersectCoord = V1 + pU*(V2-V1) + pV*(V3-V1);

The pU and the pV work somewhat like gravity in the polygonpoints. (Actually there are 3 barycentriccoords, which have a value of 1.0 when you add them. 1 - pU - pV will give you the first one.) The stronger one point gets, the more the intersectionpoint is pulled towards it.

I guess you already know this stuff, since you have written some intersectioncode yourself but it could be nice info towards other people.

Share this post


Link to post
Share on other sites