PDA

View Full Version : OpenGL objects with real world collision physics



nexusone
11-27-2002, 09:07 AM
I think this should be simple to do; I want to have spheres bouncing around in a cube.
When a sphere hits another sphere I want both to be changes based on the angle of the collision, currently speed of the object is not important, though maybe need force or mass of object.
All spheres will have same velocity and mass, it that helps make the equation simpler.


To setup each object was thinking of the following:

v1[3] = current vector of object.
v2[3] = current vector of travel.

optional varaibles:
f = force
m = mass
s = speed

I don't have a physics book handy, how would I find the resulting vectors for each object after a collision?

31337
11-27-2002, 01:44 PM
Sorry to say I can't help you with the physics and I'm sure you already knew this but for the collision detection use the distance formula.

fringe
11-28-2002, 02:49 AM
I have thought a bit about this and so I now have the answer. The way to work it out is two apply energy conservation and momentum conservation. i.e. with u - init vel and v -final vel

momentum: m1u1+m2u2 = m1v1+m2v2
energy : m1(u1)^2 + m2(u2)^2 =m1(v1)^2 + m2(v2)^2

just rearrange and sub one into the other.

I will assume that m is the same for all spheres. This simply gives that v1=u1 and v2=u2 i.e. they just exchange velocities.

Now its slightly more complicated because this is only in the direction of the centers. So first we must work out the vector representing the distance between the centres of the spheres:
r=r2-r1 : r1-pos of sphere 1 and r2 pos of sphere2
now make it a unit vector r/mag(r)
now find the velocity in the r direction using the dot product. r . v gives the correct velocities. The easiest way to change the velocity is to do:

u1=-r.u1 + r.u2

And that should about do you. Hope that helps,

fringe

P.S. not sure if it is right I am just working it out now and have never tries it