Sign in to follow this  

3D Collision Detection OpenGL

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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! :)

Share this post


Link to post
Share on other sites
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)

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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[i].x < minX)
minX = Verts[i].x

if(Verts[i].x > maxX)
maxX = Verts[i].x;

}





Share this post


Link to post
Share on other sites
Thanks!

ok so from that sample I have made this

float min[3];
float max[3];
for (i = 0; i < numOfVerts; i++)
{
...if ( V[i].x < min.x ) min.x = V[i].x;
...if ( V[i].y < min.y ) min.y = V[i].y;
...if ( V[i].z < min.z ) min.z = V[i].z;
...if ( V[i].x > max.x ) max.x = V[i].x;
...if ( V[i].y > max.y ) max.y = V[i].y;
...if ( V[i].z > max.z ) max.z = V[i].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

Share this post


Link to post
Share on other sites
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[i].x < minX)
minX = Verts[i].x

if(Verts[i].x > maxX)
maxX = Verts[i].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[i].x,minx);
miny = min(Verts[i].y,miny);
minz = min(Verts[i].z,minz);
maxx = max(Verts[i].x,minx);
maxy = max(Verts[i].y,miny);
maxz = max(Verts[i].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...

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this