Advertisement

collision detection

Started by February 05, 2003 08:55 PM
2 comments, last by jverkoey 22 years ago
I am making a 1st person game, where I have objects and stuff that you can look at and run in to, but I have a dillema: with all of my objects, when I rotate them, I still run in to the original collision detected area. I know why this happens, but the thing is, I can't think of an efficient way to make it take the rotation in to account. All there is is a rotation on the Y plane, no x or z rotations. so if you were to rotate something 90 degrees, it would rotate so it's exactly perpendicular to what it was before, but what I want to do, is say, be able to see if, if the table is rotated 20 degrees, I can still tell if I run in to that table, just as if it were at 0 degrees. here is an example of the collision code for one of my objects:
      

bool BloodRight3d::CanMove()
{
	for(int a=0;a<NUMTABLES;a++)
	{
		if(-C1.xpos<Tables[a].xpos+5.0f && -C1.xpos>Tables[a].xpos-5.0f && -C1.zpos<Tables[a].zpos+2.4f && -C1.zpos>Tables[a].zpos-2.4f)
			return false;
	}
//Rest of collision stuff goes here

}

      
And there is another line of code below that moves you, runs this test, if(!CanMove()), then if it returned a false, it will negate your movement so you move back to your original spot. So, if you could help me, that would be great, and if you need more examples of what i'm talking about, I'll post them here. Here's a screenshot of what the program looks like: NOTE::If you can't see the pic, just type in the link. http://www22.brinkster.com/ezroms/screenshot.gif and if you still don't understand what I mean, and you're more of a graphical person: http://www22.brinkster.com/ezroms/pic.gif http://www22.brinkster.com/ezroms/pic2.gif -jverkoey [edited by - jverkoey on February 5, 2003 10:10:05 PM] [edited by - jverkoey on February 5, 2003 10:44:58 PM]
if the objects are seperated from the rest of the scene, as they appear to be, then, you can store their polygons seperatly, and when you want to do a collision detection test, multiply the position you are testing by the inverse of the matrix of those objects... ie, instead of rotating the chairs vertices for the collision detection test, rotate the collision detection test by the opposite amount, making the collision detection test realitive to the chair instead of the chair realitive to the test.

| - Project-X - my mega project.. yup, still cracking along - | - adDeath - an ad blocker I made - | - email me - |
Advertisement
oook....do you think you could explain that again? i don''t get what you mean.
HRESULT MatrixInvert( D3DMATRIX& q, D3DMATRIX& a )
{
if( fabs(a._44 - 1.0f) > .001f)
return E_INVALIDARG;
if( fabs(a._14) > .001f || fabs(a._24) > .001f || fabs(a._34) > .001f )
return E_INVALIDARG;

FLOAT fDetInv = 1.0f / ( a._11 * ( a._22 * a._33 - a._23 * a._32 ) -
a._12 * ( a._21 * a._33 - a._23 * a._31 ) +
a._13 * ( a._21 * a._32 - a._22 * a._31 ) );

q._11 = fDetInv * ( a._22 * a._33 - a._23 * a._32 );
q._12 = -fDetInv * ( a._12 * a._33 - a._13 * a._32 );
q._13 = fDetInv * ( a._12 * a._23 - a._13 * a._22 );
q._14 = 0.0f;

q._21 = -fDetInv * ( a._21 * a._33 - a._23 * a._31 );
q._22 = fDetInv * ( a._11 * a._33 - a._13 * a._31 );
q._23 = -fDetInv * ( a._11 * a._23 - a._13 * a._21 );
q._24 = 0.0f;

q._31 = fDetInv * ( a._21 * a._32 - a._22 * a._31 );
q._32 = -fDetInv * ( a._11 * a._32 - a._12 * a._31 );
q._33 = fDetInv * ( a._11 * a._22 - a._12 * a._21 );
q._34 = 0.0f;

q._41 = -( a._41 * q._11 + a._42 * q._21 + a._43 * q._31 );
q._42 = -( a._41 * q._12 + a._42 * q._22 + a._43 * q._32 );
q._43 = -( a._41 * q._13 + a._42 * q._23 + a._43 * q._33 );
q._44 = 1.0f;

return S_OK;
}

Fantasio

This topic is closed to new replies.

Advertisement