Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: Collision detection

  1. #1
    Junior Member Regular Contributor
    Join Date
    Jun 2012
    Posts
    207

    Collision detection

    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.
    Last edited by debonair; 09-13-2013 at 08:32 PM.

  2. #2
    Member Regular Contributor
    Join Date
    Jun 2013
    Posts
    498
    Quote Originally Posted by debonair View Post
    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.

  3. #3
    Junior Member Regular Contributor
    Join Date
    Jun 2012
    Posts
    207
    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

    Code :
    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?

  4. #4
    Member Regular Contributor
    Join Date
    Jun 2013
    Posts
    498
    Quote Originally Posted by debonair View Post
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •