# trying to show the ray D3DXintersect creates

This topic is 3764 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

i have set the RayPos , to the bottom far left corner of the bounding box and RayDir to top far corner of the bounding box , then draw a line to represent the ray but when i move the mesh with the bounding box around in to the another mesh , it dosent say intersected screenshot http://img352.imageshack.us/my.php?image=bblinehi0.jpg here is the intersect code this code is inside the draw primitive function btw
        D3DXVECTOR3 RayPos;
D3DXVECTOR3 RayDir;
BOOL pHit = false;
DWORD FaceIndex;
float u;
float v;
float distance;

RayDir.x = minBounds.x;
RayDir.y = maxBounds.y;
RayDir.z = minBounds.z;

RayPos.x = minBounds.x;
RayPos.y = minBounds.y;
RayPos.z = maxBounds.z;

if(Mesh)
{
hr = D3DXIntersect(meshSpaceship2 ,
&RayPos ,
&RayDir ,
&pHit ,
&FaceIndex ,
&u ,
&v ,
&distance,
NULL,
NULL);

if(SUCCEEDED(hr))
{
if(pHit)
{
//MessageBox(NULL,"intersected","",0);
sprintf(data , "%s\n" , "intersecting");
WriteConsole(Console,data, sizeof(data) , &written, NULL);
}
}

}


##### Share on other sites
I think what you meant for the RayDir is:
TopFarCorner - BottomFarLeftCorner

Setting a position vector as a RayDirection only works if the source of the ray is the origin.

A direction vector in 3D space is the result of PositionA - PositionB. Only when PositionB is the origin (0, 0, 0), can we then simplify the direction to PositionA.

If you doing collision testing, I thinking using separating axis therom(SAT) test is more robust. For more information on the method, you can check out:

http://www.gamasutra.com/features/19991018/Gomez_1.htm
http://www.gamasutra.com/features/20000203/lander_01.htm

##### Share on other sites
yeh i was thinking of creating 4 rays going upwards for each corner but i know the other way of testing collision with bounding box , is the intersect function better when you its a first person type game where you move the camera to move the player ,

##### Share on other sites
Do you want to detect collisions between 2 objects or a single ray with an object?

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5

• 14
• 12
• 9
• 12
• 37
• ### Forum Statistics

• Total Topics
631424
• Total Posts
3000010
×