If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.
![]() |
|
|
#1 |
|
Member
Join Date: Aug 2003
Location: Barcelona
Posts: 132
|
Sorry if this is not the place for this.
I am making a game for one of my University subjects and I am having problems with the collision detection. Right now I use a simple but fast sphere-based collision detection system. The problem of it is that it detects collisions a lot of time before "the real collision" happens. I am actually looking for a box-based system. That's the one I am currently using. I found it on gamedev. Very simple to understand and implement. The problem is that is too unefficient. bool bSphereTest(Object3D* obj1, Object3D* obj2 ) { point relPos = obj1->GetPos() - obj2->GetPos(); //Calculem el vector entre els 2 float dist = relPos.x * relPos.x + relPos.y * relPos.y + relPos.z * relPos.z; //DistĂ*ncia que els separa float minDist = obj1->GetRadi() + obj2->GetRadi(); //La suma de les 2 distĂ*ncies return dist <= minDist * minDist; //Si això es compleix vol dir que s'estan tocant ! retornem 1 } Can you give me the scopes of a better algorythm ???
__________________
Shos !!! |
|
|
|
|
|
#2 |
|
Crazy coder
|
What kinds of objects are you collision detecting? Are there any static objects?
|
|
|
|
|
|
#3 |
|
Member
Join Date: Aug 2003
Location: Barcelona
Posts: 132
|
They are tanks in a 3D field. Only the x and z coordinates vary since the y is invariable. But I plan on put other objects such as houses, trees...and I would like to use the same collision detection system.
__________________
Shos !!! |
|
|
|
|
|
#4 |
|
Passenger on Serenity
Join Date: Jul 2002
Location: Object in Space
Posts: 1,891
|
does the turret stick out beyond the body of the tank? If it does, do you have to keep it that way?
if the turret does not extend beyond the body of the tank then a simple bounding box should do the trick. later, epic
__________________
"everyone is entitled to his own opinion, but not his own facts" |
|
|
|
|
|
#5 |
|
Member
Join Date: Aug 2003
Location: Barcelona
Posts: 132
|
I've tried to use a Bounding Box but it doesn't seem to work. First when loading the 3D model from the .ASE file, I save the greatest x, y, z coordinate in order to make the box.
Then, every time I want to check a colision I create 4 points for the object to test (if I had movement in the Y-AXIS they would be 8) and for each point I test if it colides with the box of the other object. //Hem de mirar en quins 3 eixos es toquen bool bBoxTest(Object3D* obj1, Object3D* obj2 ) { float overlapx, overlapy,overlapz; obj1->calcular_BB(); for(int i=0;i<4;i++) { if(obj2->GetPos().x+obj2->caixa_contenidora.xmax<=obj1->test_points[i].x) return false; if(obj2->GetPos().x-obj2->caixa_contenidora.xmax>=obj1->test_points[i].x) return false; if(obj2->GetPos().z+obj2->caixa_contenidora.zmax<=obj1->test_points[i].z) return false; if(obj2->GetPos().z-obj2->caixa_contenidora.zmax>=obj1->test_points[i].z) return false; } return true; } However, it doesn't seem to work.
__________________
Shos !!! |
|
|
|
|
|
#6 |
|
Member
Join Date: Aug 2003
Location: Barcelona
Posts: 132
|
I've found the problem. Probably nobody cares but I solved it:
quins 3 eixos es toquen bool bBoxTest(Object3D* obj1, Object3D* obj2 ) { // float overlapx, overlapy,overlapz; bool sit=false; obj1->calcular_BB(); for(int i=0;i<4;i++) { sit=true; if(obj2->GetPos().x+obj2->caixa_contenidora.xmax<=obj1->test_points[i].x) sit= false; if(obj2->GetPos().x-obj2->caixa_contenidora.xmax>=obj1->test_points[i].x) sit= false; if(obj2->GetPos().z+obj2->caixa_contenidora.zmax<=obj1->test_points[i].z) sit= false; if(obj2->GetPos().z-obj2->caixa_contenidora.zmax>=obj1->test_points[i].z) sit= false; if(sit) return true; } return false; }
__________________
Shos !!! |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| AnandTech article up (X360 vs PS3) | pipo | Console Technology | 87 | 26-Jun-2005 05:58 |
| Opengl per pixel collision detection | K.I.L.E.R | 3D Technology & Algorithms | 4 | 19-Jun-2005 23:03 |
| collision detection | AlStrong | 3D Technology & Algorithms | 9 | 29-Jul-2004 08:16 |
| UT2004, Far Cry - CPU and VPU (nv40, R420) | ShePearl | 3D Architectures & Chips | 196 | 27-May-2004 09:11 |
| The next-generation: The camera and collision detection | Ooh-videogames | Console Technology | 21 | 24-Feb-2003 02:47 |