Two questions:

Epimetheus

17-02-2006 16:53:56

1. How do i create a spring (or any other motor that exists)?

2. How do would i do to cancel out force? If i have sent an object flying and want it to stop, how do i calculate how much force to apply to counter the current velocity (or torque)?

walaber

17-02-2006 19:01:23

1. springs can be implemented by the user quite simply, search any physics page for spring formulas... but the basic formulas are:

F = -k * d
k is the spring constant (stiffness)
d is how far the spring is "stretched" from its neutral position.

you also may want to add damping to the equation like this:
F = (-k * d) + (d * v)
d is damping factor
v is relative velocity of the spring between head and tail.


2. to stop an object, you need to calculate the amount of force required to result in a new velocity of zero.

F = m*a
m is mass
a is acceleration.

so you need to know the acceleration to result in 0 velocity.
a = dv / dt
dv is change in velocity
dt is change in time.

so, you want to do this:

Ogre::Vector3 currentVel = mBody->getVelocity();
Ogre::Vector3 force = Ogre::Vector3::ZERO;

Ogre::Vector3 inertia;
Ogre::Real mass;

mBody->getMassMatrix( mass, inertia );

Ogre::Vector3 accel = (0.0f - currentVel) / mBody->getWorld()->getTimeStep();

force = accel * mass;

mBody->addForce( force );

Epimetheus

17-02-2006 20:49:15

Oh! I thought that newton had a function for springs :O

Anyway, thanks alot for the info

walaber

17-02-2006 21:36:06

however you can motorize the built-in joints pretty simply.

also the custom joint system has a cool spring system built in as well, for making spring-loaded hinges, etc.

Epimetheus

18-02-2006 16:38:43

Is there any documentation on this subject? It would be really cool