Wrestling with D3DXIntersect

Started by
6 comments, last by pan narrans 21 years, 7 months ago
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
Minister of Propaganda : leighstringer.com : Nobody likes the man who brings bad news - Sophocles (496 BC - 406 BC), Antigone
Advertisement
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?
Minister of Propaganda : leighstringer.com : Nobody likes the man who brings bad news - Sophocles (496 BC - 406 BC), Antigone
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.
~phil
If you want to calculate the intersection yourself, you can check the DX 8.1 pick demo - there''s code to do it there.

Jim Adams
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?
Minister of Propaganda : leighstringer.com : Nobody likes the man who brings bad news - Sophocles (496 BC - 406 BC), Antigone
D3DXGetFVFVertexSize()

Took me a few hours to find this function a week ago ...

Domenic, Underdog
http://www.unitedunderdogs.com
Domenic, Underdoghttp://www.unitedunderdogs.com
Finally got it done. It was hard, but its nice to understand it all. Thanx everyone! I''ll have to change my old sig (it was: I HATE COLLISION DETECTION )

PAN NARRANS
Minister of Propaganda : leighstringer.com : Nobody likes the man who brings bad news - Sophocles (496 BC - 406 BC), Antigone
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.

This topic is closed to new replies.

Advertisement