Advertisement

3d collision

Started by October 03, 2001 09:13 AM
0 comments, last by flashlaser 23 years, 4 months ago
I am making a GTA syle game and I am stuck on the collision detection. I read another tutorial on collision and I got an idea from it. Tell me if this will work. My car is a mesh, so I will loop though each vector(vertex) of the car and input into my collision detection function added with another vector showing where the car will move. The function will then loop though each triangle in my city mesh and find its plane then work out if the which side of the triangle plane the car vertex will be if is moved. If the loop ends without collison being TRUE then the car is moved, else the car remains where it is. Here''s some pesudo code- D3DXVECTOR3 pos; D3DXVECTOR3 movepos; for(i=0;ipos=carVerice+movepos; collision(pos); } if (collision!=TRUE) { x=movepos.x; y=movepos.y; z=movepost.z; } VOID collision(D3DXVECTOR3 &pos) { for (each triangle of city mesh) { findPlane(); checkWhichSideOfPlanePosIsOn(); if (collision) { collision = TRUE; } } } Is there any problems with my idea. If not can someone expand my code more, like show how me code for finding the plane, etc. Any help will be helpful.
Well I can think of two problems at least with this method.
1) Looping through all vertices of a mesh and checking them against every triangle in the map is slow.
2) If some vertices are on one side of a triangle-plane and some are on the other side, then the mesh collides with the plane of the triangle and not the triangle itself. So collision could be set to TRUE even when there is no collision.

I am not sure how you could best fix these problems, it depends a bit on how your level is stored in memory and stuff like that. But if I were to make a GTA like game, I''d probably use something like a BSP tree or octree for the level and an octree or obb-tree for the car mesh.
Dirk =[Scarab]= Gerrits

This topic is closed to new replies.

Advertisement