PDA

View Full Version : OpenGL Collision - any help with coll and co-ords?



ctrlvee
08-18-2011, 01:58 PM
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

AleaIactaEst
08-19-2011, 04:57 AM
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.

V-man
08-19-2011, 08:59 AM
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)