3D Collision Detection OpenGL

Started by
7 comments, last by RobTheBloke 15 years, 4 months ago
Hi, I want to do something like aabb. I am very new to this, I have my objects being rendered, moving and all Now I need collision detection. I have done some research and I have some code which calculates the new min and max and which checks for intersection..so this is what I have come up with 1)make a struct for a bounding box (bb) **giv it a vector3 called max and another called min 2)put this bb in my GameObject class 3)make a method in the GameOject class called "bool hasCollieded(BoundingBox * bb)" 4) now where do i check for collision? postRender?..preRender?.. OK, here is what i dont get, at some point im going to have recalculate the min and max..when do i do this?.. I need to get this work in on Friday, any quick help would be greatly appricated
Advertisement
Hello. I'm not currently using OpenGL but I do know of a good site for tutorials on it.

This one talks about collision detection.

http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=30

For more just go here:

http://nehe.gamedev.net/default.asp

This is another tutorial I found, not sure how good it is.

http://www.videotutorialsrock.com/opengl_tutorial/collision_detection/text.php

The VIDEO:
http://www.videotutorialsrock.com/opengl_tutorial/collision_detection/video.php

Good luck! :)
the computationally least complex form of collision detection is probobly spherical, followed by AABB, so you should look into those two, collision detection isn't really library specific unless you use library specific routines(like D3DX functions)
--------------------------------------Not All Martyrs See Divinity, But At Least You Tried
also collision, like other updates, is typically performed pre-render.
ah thanks! one more thing (hopefully its the last one!!)

how do i find the minimum and maximum coordinates for each axis among all the vertices?

Im going to be awake two days to get this finished..its due in on Friday.. :-C
something like this would work


//you can repeat this for y and z
float minX = 0,maxX = 0;

for(int i = 0;i<numVertices;i++)
{
if(Verts.x < minX)
minX = Verts.x

if(Verts.x > maxX)
maxX = Verts.x;

}





--------------------------------------Not All Martyrs See Divinity, But At Least You Tried
Thanks!

ok so from that sample I have made this

float min[3];
float max[3];
for (i = 0; i < numOfVerts; i++)
{
...if ( V.x < min.x ) min.x = V.x;
...if ( V.y < min.y ) min.y = V.y;
...if ( V.z < min.z ) min.z = V.z;
...if ( V.x > max.x ) max.x = V.x;
...if ( V.y > max.y ) max.y = V.y;
...if ( V.z > max.z ) max.z = V.z;
}

Free Image Hosting at www.ImageShack.us

Ok firstly, im soo embarrassed/sorry for dragging this on for so long!

but if its possible, can someone look at the above screenshot?

i have highlighted from where im going to read the verts of the object..I would just REALLY like to confirm that i am readin from the right place

the screen shot shows the entire hierarchy of the model/mesh holder.

thank you all again
if pVerts is your list of vertices, then replace V[] in your example code with pVerts[] and it should be good, but its hard to tell.
--------------------------------------Not All Martyrs See Divinity, But At Least You Tried
Quote:Original post by godsenddeath
//you can repeat this for y and z
float minX = 0,maxX = 0;
for(int i = 0;i<numVertices;i++)
{
if(Verts.x < minX)
minX = Verts.x

if(Verts.x > maxX)
maxX = Verts.x;

}


or better yet... use something that actually works (and doesn't use if statements...) ;)

#include <float.h>float minx=FLT_MAX,miny=FLT_MAX,minz=FLT_MAX;float maxx=FLT_MIN,maxy=FLT_MIN,maxz=FLT_MIN;for(int i=0;i<numVerts;++i){  minx = min(Verts.x,minx);  miny = min(Verts.y,miny);  minz = min(Verts.z,minz);  maxx = max(Verts.x,minx);  maxy = max(Verts.y,miny);  maxz = max(Verts.z,minz);}


To answer the OP, don't bother writing your own collision engine unless that complexity of maths actually appeals to you. I'd recommend downloading and using the PhysX SDK from nvidia...

This topic is closed to new replies.

Advertisement