Jump to content
  • Advertisement
Sign in to follow this  
brain21

OpenGL OpenGL + object collision

This topic is 4826 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

Im using OpenGL for simple rectangular prisms. I want to add some collision detection algo's. I have written one that will detect collision between these object, but now I don't know how to put the two together. I want OpenGL to draw them, but I need to do the rotation and translation of the objects myself (for the collision algo). Is there an easier way of doing this? Can I somehow access OpenGL vars to get the points of the objects after it has rotates/translated them? What do you think? Brain21

Share this post


Link to post
Share on other sites
Advertisement
You'll need to learn a little matrix math, and how to transform vectors by matrices. You might check out the math articles here on gamedev. Just keep in mind that OpenGL uses column vectors and column-major matrices, and the examples in the articles might not necessarily match OpenGL convention.

Share this post


Link to post
Share on other sites
Actually, the collision algo I use does not use glGetFloatv.

Slow collision:
Loop throgh all the transformed triangles
1. Make 3 vectors for each vertex of the triangle
2. get the normal of the triangl
3. check to see if the point or sphere is behind, front or intersects the poly
4. check if the point is in the tri
5. check for edge collision
6. handle the response

I could post some code but I'm on a net cafe so you may have to wait till tomorrow. :*(

Share this post


Link to post
Share on other sites
ok, I already know matrix math. I was just wondering is there was a way to get OpenGL to do some of the math for me. But I guess thats that the function will give me. I just need to multiply my vector with it. I think I'll just keep track of the points myself and do the rotations my self and keep track of the translation. So when I draw the cube, it's centerec at 0,0,0 and is already rotated using my rotation function, so I just need to use open gl to translate it, then draw it. Does this sound like a good way?

For collision detection, I store the normal of each face with the polygone. For each pair of cubes, I check to see if any of the 8 points of each cube is inside the other cube, and vise versa. The way I check for the point inside the cube, is I draw a line from the point I want to check to the normal vector and check the angle in between. sort of like the back-face culling technique. If the angle is > than 90 then the point is on the backside of the poly (assuming I draw all of them in the same clockwise order). If the point is on the back side of all the polys in the cube, then there is a collision. I know, it's a little confusing. But its the same as back-face culling.

Brain21

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!