Collision Detecting

Started by
32 comments, last by Running_Wolf 23 years, 2 months ago
Running_Wolf,
Send your zipped Project , I''ve Visual Studio 6 Enterprise.
I can run though the Code.

BGCJR@hotmail.com
Game Core
Advertisement
Seach this message board for 'Toom frustum culling', He's written a great tutorial on frustum culling, which can quickly and easily detect whether a polygon can be seen or not, and thus you may choose to draw it. Im not good at memorizing addys, so i couldnt post the url to it.

About limiting the number of polys to be detected for collisions with the player, i think you would find that using a limited number of rays to check for the nearest poly would be more time comsuming, and less accurate (some polys may escape all the rays you define) than just checking for a collision to start with. I dont know of a better way to do this.

- Wav

Edited by - wAVaRiaN on January 25, 2001 1:18:57 AM
if ((bx>=x1) && (sx<= x2) && (bz>=z1) && (sz <=z2) )
if (by>=y1 && sy<=y2)
if (Distance<0.9f && Distance>(-0.9f)) collide=1;
Game Core
i used the routine for collision detection with planes.
the comparasion works for indidividual walls,but I can''t walk
up slopes. Anyone show how exactly how to test if the point or line actually pierces or is on a polygon?

void Collision()

{ collide=0;
GLfloat tx1,ty1,tz1;
GLfloat tx2,ty2,tz2;
GLfloat tx3,ty3,tz3;
GLfloat Nx,Ny,Nz;
GLfloat Mag;
GLfloat D,d;
GLfloat sx=xpos-(0.3f);
GLfloat bx=xpos+(0.3f);
GLfloat sz=zpos-(0.3f);
GLfloat bz=zpos+(0.3f);
GLfloat by=ypos;
GLfloat sy=ypos-0.63f;
GLfloat top,bottom,u;
GLfloat x1,x2,z1,z2,y1,y2;
GLfloat dv1,dv2,dv3;


int numtriangles = sector1.numtriangles;
for (int loop=0; loop < numtriangles;loop++)
{
tx1 = sector1.triangle[loop].vertex[0].x;
ty1 = sector1.triangle[loop].vertex[0].y;
tz1 = sector1.triangle[loop].vertex[0].z;

tx2 = sector1.triangle[loop].vertex[1].x;
ty2 = sector1.triangle[loop].vertex[1].y;
tz2 = sector1.triangle[loop].vertex[1].z;

tx3 = sector1.triangle[loop].vertex[2].x;
ty3 = sector1.triangle[loop].vertex[2].y;
tz3 = sector1.triangle[loop].vertex[2].z;

if (tx1 else { x2 = tx1;x1 = tx3;}
if (tz1 else { z1 = tz3; z2 = tz1;}
if (ty1 else {y1 = ty3; y2 = ty1;}

Nx = ty1*(tz2 - tz3) + ty2*(tz3 - tz1) + ty3*(tz1 - tz2);
Ny = tz1*(tx2 - tx3) + tz2*(tx3 - tx1) + tz3*(tx1 - tx2);
Nz = tx1*(ty2 - ty3) + tx2*(ty3 - ty1) + tx3*(ty1 - ty2);

/*
Then you should normalize this vector to make it easier for openGL to digest:
*/

Mag = sqrt((Nx*Nx)+(Ny*Ny)+(Nz*Nz)); // Length of Vector
Nx = Nx / Mag;// Normalize Vector
Ny = Ny / Mag;
Nz = Nz / Mag;

D = -(Nx*tx1 + Ny*ty1 + Nz*tz1);

Distance = Nx*(xpos) + Ny*(ypos) + Nz*(zpos) + D;

if ((bx>=x1) && (sx<= x2) && (bz>=z1) && (sz <=z2) )
if (by>=y1 && sy<=y2)
if (Distance<0.8f && Distance>(-0.8f)) collide=1;


}
}

This topic is closed to new replies.

Advertisement