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 3 of 3

Thread: OpenGL Collision - any help with coll and co-ords?

  1. #1
    Junior Member Newbie
    Join Date
    Aug 2011
    Posts
    12

    OpenGL Collision - any help with coll and co-ords?

    hi,

    ok, so I know OpenGl in itself doesnt have a collision system.
    However I felt that maybe I could just set the code to recognise if a player is at a certain point within the world then i could write some more code to make the game recongnise collison.

    Is this possible?

    Any idea on how this would be written?

    at the moment i dont exactly have a proper coded camera, but just using keyboard controls to translate through the world.

    so i was thinking something along the lines of:
    case 'w':
    case 'W':
    glTranslatef(0.0, 0.0, 25.0);
    break;
    but obv that just moves the cam forward, so how would i create some rule of collision after a certain distance along the zaxis
    (if translate reeaches 100.0) for example

  2. #2
    Intern Newbie
    Join Date
    Dec 2009
    Location
    Germany
    Posts
    30

    Re: OpenGL Collision - any help with coll and co-ords?

    If you want a collision detection system as simple as you described it, you'll just need a couple of global variables holding the xyz position of moving objects in 3d space and check every frame or every time you press a key if a collision occured.

    The usual approch to a collision detection system is, as far as i know, to create a separate thread dedicated to detecting and resolving collisions. This thread would have access to a struct holding information about all objects like position and shape and be able to modify an objects position / speed / acceleration.

  3. #3
    Super Moderator OpenGL Guru
    Join Date
    Feb 2000
    Location
    Montreal, Canada
    Posts
    4,421

    Re: OpenGL Collision - any help with coll and co-ords?

    Collision detection? That's what physics engines are. Try ODE or Bullet or Newton Dynamics or PhysX. These libs have routines for collision detection (sphere to sphere, sphere to box, etc)
    ------------------------------
    Sig: http://glhlib.sourceforge.net
    an open source GLU replacement library. Much more modern than GLU.
    float matrix[16], inverse_matrix[16];
    glhLoadIdentityf2(matrix);
    glhTranslatef2(matrix, 0.0, 0.0, 5.0);
    glhRotateAboutXf2(matrix, angleInRadians);
    glhScalef2(matrix, 1.0, 1.0, -1.0);
    glhQuickInvertMatrixf2(matrix, inverse_matrix);
    glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
    glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

Posting Permissions

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