X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=examples%2Fbassteroids%2Fsource%2Fphysics.cpp;h=0fb43260f4cff7b82f57e39eb6fed6aa72b3b954;hb=da195e0fa114b82708d7c2bbd6297590f34f79a4;hp=db8e494f4d4f179aa8e02eddad9b909f53e9a951;hpb=391f1ab3c7ca52a9990f516f4cdd7094f60350df;p=libs%2Fgame.git diff --git a/examples/bassteroids/source/physics.cpp b/examples/bassteroids/source/physics.cpp index db8e494..0fb4326 100644 --- a/examples/bassteroids/source/physics.cpp +++ b/examples/bassteroids/source/physics.cpp @@ -75,7 +75,11 @@ 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.external_force = body->get_force(); + entity.external_torque = body->get_torque(); entity.velocity = body->get_velocity(); + entity.angular_velocity = body->get_angular_velocity(); } } @@ -90,6 +94,8 @@ 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); + body->clear_forces(); } } @@ -102,6 +108,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; } }