PDA

View Full Version : Collision detection



debonair
09-13-2013, 01:43 PM
In my code, I want to implement collision detection and for that i need to calculate bounding box for each object. Now, I am dynamically calculating the positions of objects in my code and hence not able to figure out how to retrieve that positions in array to compare for collision detection.

GClements
09-13-2013, 05:43 PM
In my code, I want to implement collision detection and for that i need to calculate bounding box for each object. Now, I am dynamically calculating the positions of objects in my code and hence not able to figure out how to retrieve that positions in array to compare for collision detection.
Collision detection is not something which should normally involve OpenGL. It might involve the same data as the rendering (although collision often uses a simplified version of the geometry), in which case you'd just use the client-side copy of the data rather than trying to get it back out of OpenGL. Similarly, if you need to transform the coordinates, you'd do that in the program, applying the same transformations as those used for rendering.

debonair
09-15-2013, 12:57 AM
I need actual coordinates after transformation as i will be using them for the comparison during collision detection.
For bounding box, I don't need transformed coordinates, i just can apply same transformation as that of geometry which eventually will apply to it.

I have



angle=0;
while(angle%360)
{
rotate(angle)
translate(x)
rotate(-angle)
}



Now if i calculate coordinates after last rotate call, everytime it will draw static object and not a rotating one which is the initial position and not updated one. In this case how can i calculate the transformed coords?

GClements
09-15-2013, 09:16 AM
In this case how can i calculate the transformed coords?
However you want.

You can use GLM to construct the matrices and perform the matrix-matrix and matrix-vector multiplies (although personally I wouldn't add another library dependency just for that; neither the multiplication functions nor any of the individual matrices are more than half a dozen lines of code).

If the transformations were particularly involved, you could use transform-feedback mode to read the processed vertex attributes from the hardware, but for simpler cases this will be more expensive than duplicating the transformations in the application (particularly if the data being transformed isn't the data which is used for rendering). And probably more work.

But if you've been avoiding learning anything about linear algebra and relying upon OpenGL to do it all for you, collision is usually the point where that approach stops working.