Sign in to follow this  

Collision Detection

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

I hope this will be my last question for awhile. Ive been doing a engine, ive got a pretty good renderer(Quake 3 maps with bumpmapping / per-pixel lighting), but I can't figure out how to do collision detection. Ive read all the Quake 3 Collision detection tutorials I can find, but I can't get any of them to work right. Could anyone explain a good way to go about doing it?

Share this post


Link to post
Share on other sites
You might want to check the math forum for this one, as it really has nothing to do with OpenGL. I'll go ahead and move this one over there for you.

Share this post


Link to post
Share on other sites
What kind of collision detection do you want to do? Character/world, character/character, ray/character(for bullets or something)?

you could also test the bounding box or bounding sphere of your character against the world.

Let's say you're going to do character bounding sphere against the world. Write a sphere-polygon intersection function. Then, every frame, move your character, and then run sphere-polygon intersection between the bounding sphere and every polygon in your world. If you have an intersection, that's a collision.

Share this post


Link to post
Share on other sites
I have a ok collision detection(it only works with retangles, no curved surfaces), I use the vertexs of the BSP to create a virtual retectangle, and I test to see if a object hit it or not. My problem is it only works a little bit of the time.

can any1 tell me what i did wrong?



CVector3 newpos;

boolean WRAITHMAP::PlayerMoveOk(float pos[3])
{
// This has to be the worst thing I have EVER written! - Justin
int i = 0;

// wall cords
float x,y,z;
float x1,y1,z1;
float x2,y2,z2;
float x3,y3,z3;

// player coords
float px = pos[0];
float py = pos[1];
float pz = pos[2];

newpos.x = px;
newpos.y = py;
newpos.z = pz;

for(i=0; i<numofverts; i+=4)
{
x = BSPVertex[i].vPosition[0];
y = BSPVertex[i].vPosition[1];
z = BSPVertex[i].vPosition[2];

x1 = BSPVertex[i+1].vPosition[0];
y1 = BSPVertex[i+1].vPosition[1];
z1 = BSPVertex[i+1].vPosition[2];

x2 = BSPVertex[i+2].vPosition[0];
y2 = BSPVertex[i+2].vPosition[1];
z2 = BSPVertex[i+2].vPosition[2];

x3 = BSPVertex[i+3].vPosition[0];
y3 = BSPVertex[i+3].vPosition[1];
z3 = BSPVertex[i+3].vPosition[2];

/*
Create a boundry box around the wall,
and test to see if the player is inside this box
*/

if(z2 == z3 && z1 == z) // box is a Z face
{
if(pz >= (z2 - 1.5) && pz <= (z2 + 1.5))
{
newpos.z *=.9;
return false;
}
//Sys_Error("pz = %f z2 = %f\n",pz,z2);
}
else if(x2 == x3 && x1 == x) // box is a front
{
if(px >= (x2 - 1.5) && px <= (x2 + 1.5))
{
newpos.x *=.9;
return false;
}
}
else if(y2 == y3 && y1 == y) // box is either a cieling or floor
{
if(py >= (y2 - 1.5) && py <= (y2 + 1.5))
{
/*
if(py <= y2) // ceiling
newpos.y *=.9;
else // floor
newpos.y /=.9;
*/

return false;
}
//Sys_Error("py = %f, y2 = %f\n",py,y2);
}
else // unkown
{
Com_Printf("p%d (%f %f %f) p%d (%f %f %f) p%d (%f %f %f) p%d (%f %f %f) !\n",i,x,y,z,i+1,x1,y1,z1,i+2,x2,y2,z2);
Com_Printf("WARNING: Unkown collision type!\n");
}



}

return true;
}




[Edited by - crozzbreed23 on August 22, 2004 5:31:13 PM]

Share this post


Link to post
Share on other sites
I implemented the collision detection from http://www.nathanostgard.com/tutorials/quake3/collision/, it kinda works, but I am having problems at the line that reads
startDistance = DotProduct( inputStart, plane->vNormal ) - plane->d;
endDistance = DotProduct( inputEnd, plane->vNormal ) - plane->d;

the DotProduct returns 0. This is because two of the vNormal points are 0.

Can anyone help me?

Share this post


Link to post
Share on other sites
you can also have a look at this and talk to these guys,

http://www.gamedev.net/community/forums/topic.asp?topic_id=258231&whichpage=2�,

or grab the (unfinished) demos off my website. It's incomplete, in a sense that it's not 100% bug-proof, but it's working in the large majority of cases, unless you hit two walls at a time, which is a quite a tricky situation really.

http://uk.geocities.com/olivier_rebellion/BSPLoader.zip

it's based on nathan ostgard code, obviously, and uses the gamestutorials q3 bsp loader demo.

Share this post


Link to post
Share on other sites

This topic is 4859 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.

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