I have 2 moving objects, blue car and red car. The red car being human controlled. The blue car rotating, permanently, around a roundabout.
I understand how to (very simply) detect collision between the red car and static objects, just by making the co-ordinates out of bounds, but have no idea how to go about doing something like this with a moving object.
Any help would be grand!!
depending on what kind of detail you want to have in your game you could use anything from simple point-in-circle or point-inside-polygon tests to more advanced stuff like oriented bounding boxes (which are harder to code).
In any way, this has not much to do with OpenGL so you’re better off going to a forum like gamedev.net where this can be discussed in detail.
glGenQueries (1, cd);
glBeginQuery (GL_COLLIDE_DETECT, cd);
... drawing stuff
glGetQueryObjectiv (cd, GL_COLLIDE_DETECT, t);
// has collided
r = t.resultant;
m = t.moment;
// do the collision response
// has not collided
Forgive me please.
Following can be a possible way of detecting collision between Red car and the blue car.(I may be wrong also)
Construct Bounding spheres of both the cars.
Bounding sphere will return radius and centre of the sphere. The centre can be considered as the centre of Gravity for better understanding
During every iteration check for sphere / sphere overlap. Collision is detected if these two spheres overlap
There are lot of websites talks about algorithms and even source code for constructing Bounding sphere construction
Sphere/ sphere overlap test is easy to implement. ( if radii distance is lessthan the distance between their centers, an overlap exists)
This is my solution for Collision detection.
Bangalore - 1
Hey mate, on me website, I have a very simple collision detection method which can be used for circles or spheres. It is less accurate to that of a bounding box but is perfect for the beginner.
It basically does what <Rajesh.R> describes above.
The link is: