X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=examples%2Fbassteroids%2Fsource%2Fphysics.cpp;h=a8d49ec4d0331cb98437c07a24264a6c724b88a8;hb=1819b186d60376a546722d99edd686e876b81d9f;hp=db8e494f4d4f179aa8e02eddad9b909f53e9a951;hpb=391f1ab3c7ca52a9990f516f4cdd7094f60350df;p=libs%2Fgame.git diff --git a/examples/bassteroids/source/physics.cpp b/examples/bassteroids/source/physics.cpp index db8e494..a8d49ec 100644 --- a/examples/bassteroids/source/physics.cpp +++ b/examples/bassteroids/source/physics.cpp @@ -75,7 +75,9 @@ void Physics::copy_in(SimulatedEntity &entity) { Game::Handle body = entity.entity->get_body(); entity.inverse_mass = 1.0f/body->get_mass(); + entity.moment_of_inertia = body->get_moment_of_inertia(); entity.velocity = body->get_velocity(); + entity.angular_velocity = body->get_angular_velocity(); } } @@ -90,6 +92,7 @@ void Physics::copy_out(SimulatedEntity &entity) { Game::Handle body = entity.entity->get_body(); body->set_velocity(entity.velocity); + body->set_angular_velocity(entity.angular_velocity); } } @@ -102,6 +105,10 @@ void Physics::step(float dt_secs) LinAl::Vector new_velocity = entity.velocity+entity.external_force*dt_secs*entity.inverse_mass; entity.position += (entity.velocity+new_velocity)*(dt_secs/2); entity.velocity = new_velocity; + + Geometry::Angle new_angular_velocity = entity.angular_velocity+Geometry::Angle::from_radians(entity.external_torque*(dt_secs/entity.moment_of_inertia)); + entity.rotation = wrap_positive(entity.rotation+(entity.angular_velocity+new_angular_velocity)*(dt_secs/2)); + entity.angular_velocity = new_angular_velocity; } }