# Comments on Collission Detection Method?

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

## Recommended Posts

hello again! I posted a similar post a little while ago asking for comments on my culling method, and came out with a pretty good result. Everything was ok except that the objects bounding spheres are rotated into view space rather than rotating the frustum into world space. I had some suggestions, and read some promising articles, but it just seems a little over my head right now. Annnnyways, this is all beside the point. I am here to day to ask for comments or suggestions on my collision detection method. This was my first attempt. My scene consists of one square room at moment. I know how to collide objects by using their bounding boxes/spheres, but I have hit a snag. How does one handle collission detection against an object with inverted normals? this is the code I came up with to keep the player inside the square room. It works smoothly, and the player slides along the walls without sticking to them, but it only works on completely concave geometry. I guess Its needless to explain much more, so here is my code.
void ProcessInput()
{
//move player
cam += blahblahblah;
//ect, ect....

CenterMouse();

D3DXVECTOR4 cdir;
float minwalldist = 0.25f;
D3DXVECTOR3 verts[3], planeoffset, pl_int;

for(int t = 0; t < map_vcount; t+=3)
{
camvec = cam - prev_cam;
cdist = sqrt(camvec.x*camvec.x + camvec.y*camvec.y + camvec.z*camvec.z);

D3DXVec4Normalize(&cdir, &camvec);

D3DXPlaneFromPoints(&triplane, &map[t], &map[t+1], &map[t+2]);
D3DXPlaneNormalize(&triplane, &triplane);

planeoffset = (D3DXVECTOR3)triplane * minwalldist;
verts[0] = map[t] + planeoffset;
verts[1] = map[t+1] + planeoffset;
verts[2] = map[t+2] + planeoffset;

bool intersect = D3DXIntersectTri(&verts[0], &verts[1], &verts[2], (D3DXVECTOR3*)&prev_cam, (D3DXVECTOR3*)&cdir, 0, 0, &dist_int);

if(intersect == true && dist_int < cdist)
{
D3DXPlaneFromPoints(&triplane, &verts[0], &verts[1], &verts[2]);

D3DXPlaneIntersectLine(&pl_int, &triplane, (D3DXVECTOR3*)&cam,  &((D3DXVECTOR3)cam + ((D3DXVECTOR3)triplane * cdist)));
planeoffset = ((D3DXVECTOR3)triplane * 0.0001f);
cam = (D3DXVECTOR4)(pl_int + planeoffset);
}
}
}

basically what I have done, is this: since the player does not actually collide with the wall, but rather has to keep a certain distance from it, I start by moving the triangle along its normal vector by the minimum distance the player should have from the wall, and then I do the collission with it. -This would not work if the room had any convex walls -This would not work right if their were two rooms stacked -This method will be slow on a large scale. I suppose I could give every wall its own bounding box instead of doing this, and ignore the idea of inverted geometry......but anyways What do you guys think? EDIT- do modern games even collide against the actual geometry? or do they have a completely different layer dedicated specifically to collission detection?

##### Share on other sites
If you want faces to be double sided, when you pass the 3 vertices in just swap the order of them around.

Check for an intersection, if one found then continue, if none found then swap the vertices order and try again.

You only appear to be checking for collision with faces and not with triangle edges/verts too. If you run into a horizontal triangle then what should happen? I'd hope you would bump into its edge and not go straight through.

Have a look at this for some info on collision detection (swept) and response (sliding along walls etc):

It does use ellipsoid space which could be confusing but if your only interested in using a shpere around your camera then it can be simplified.

##### Share on other sites
Quote:
 Original post by NanohaIf you want faces to be double sided, when you pass the 3 vertices in just swap the order of them around (ABC -> CBA).Check for an intersection, if one found then continue, if none found then swap the vertices order and try again.You only appear to be checking for collision with faces and not with triangle edges/verts too. If you run into a horizontal triangle then what should happen? I'd hope you would bump into its edge and not go straight through.Have a look at this for some info on collision detection (swept) and response (sliding along walls etc):http://www.peroxide.dk/download/tutorials/tut10/pxdtut10.htmlIt does use ellipsoid space which could be confusing but if your only interested in using a shpere around your camera then it can be simplified.

1. 1
2. 2
Rutin
20
3. 3
khawk
17
4. 4
A4L
14
5. 5

• 12
• 16
• 26
• 10
• 44
• ### Forum Statistics

• Total Topics
633759
• Total Posts
3013720
×

## Important Information

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!