I have this code:
- Code: Select all
void apply_force_and_torque (const NewtonBody* const body, dFloat timestep, int threadIndex)
{
float gravity = 10.0f;
float force[3] =
{
0.0f,
gravity,
0.0f,
};
NewtonBodySetForce (body, force);
}
void newton_test (int steps_per_second)
{
float transformation_matrix[16] =
{
1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f
};
NewtonWorld* const world = NewtonCreate ();
NewtonCollision* const collision = NewtonCreateBox (world, 10, 10, 10, 0, NULL);
NewtonBody* const body = NewtonCreateDynamicBody (world, collision, transformation_matrix);
NewtonBodySetForceAndTorqueCallback (body, apply_force_and_torque);
NewtonBodySetMassProperties (body, 10, collision);
int i;
for (i = 0; i < 10 * steps_per_second; i++)
{
NewtonUpdate (world, 1.0f / steps_per_second);
}
printf ("%d steps at %d steps per second (%.2f seconds)\n", i, steps_per_second, (1.0f * i / steps_per_second));
float velocity[3];
NewtonBodyGetVelocity (body, velocity);
printf ("velocity: %.2f\n", velocity[1]);
NewtonBodyGetMatrix (body, transformation_matrix);
printf ("position: %.2f\n\n", transformation_matrix[13]);
NewtonDestroyAllBodies (world);
NewtonDestroy (world);
}
int main (int argc, const char * argv[])
{
newton_test (50);
newton_test (60);
newton_test (100);
newton_test (120);
return 0;
}
with this output:
- Code: Select all
500 steps at 50 steps per second (10.00 seconds)
velocity: 6.68
position: 38.26
600 steps at 60 steps per second (10.00 seconds)
velocity: 5.70
position: 34.37
1000 steps at 100 steps per second (10.00 seconds)
velocity: 2.78
position: 20.76
1200 steps at 120 steps per second (10.00 seconds)
velocity: 1.98
position: 16.02
I'm wondering, since the world is being simulated for the same total amount of time for each timestep, shouldn't the velocity and postion of the body end at about the same value for each?
I assume I'm missing something, but I don't know what.