Sign in to follow this  

trying to show the ray D3DXintersect creates

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 here is the intersect code this code is inside the draw primitive function btw
        D3DXVECTOR3 RayPos;
	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;
      	hr = D3DXIntersect(meshSpaceship2 ,
		         &RayPos , 
				 &RayDir ,
				 &pHit , 
				 &FaceIndex , 
				 &u , 
				 &v , 

		       sprintf(data , "%s\n" , "intersecting");
               WriteConsole(Console,data, sizeof(data) , &written, NULL);


Share this post

Link to post
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:

Share this post

Link to post
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 this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this