Game::Handle<RigidBody> 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();
}
Game::Handle<RigidBody> body = entity.entity->get_body();
body->set_velocity(entity.velocity);
body->set_angular_velocity(entity.angular_velocity);
+ body->clear_forces();
}
}
float inverse_mass = 1.0f;
float moment_of_inertia = 1.0f;
Msp::LinAl::Vector<float, 2> external_force;
+ float external_torque = 0.0f;
Msp::LinAl::Vector<float, 2> position;
Msp::Geometry::Angle<float> rotation;
#include "rigidbody.h"
+#include <msp/game/entity.h>
+#include <msp/game/transform.h>
using namespace Msp;
{
angular_velocity = as;
}
+
+void RigidBody::add_force(const LinAl::Vector<float, 2> &f)
+{
+ force += f;
+}
+
+void RigidBody::add_force(const LinAl::Vector<float, 2> &f, const LinAl::Vector<float, 2> &p)
+{
+ force += f;
+ LinAl::Vector<float, 2> r = p-entity->get_transform()->get_position().slice<2>(0);
+ torque += r.x*f.y-r.y*f.x;
+}
+
+void RigidBody::add_torque(float t)
+{
+ torque += t;
+}
+
+void RigidBody::clear_forces()
+{
+ force = LinAl::Vector<float, 2>();
+ torque = 0.0f;
+}
const Setup &setup;
Msp::LinAl::Vector<float, 2> velocity;
Msp::Geometry::Angle<float> angular_velocity;
+ Msp::LinAl::Vector<float, 2> force;
+ float torque = 0.0f;
public:
RigidBody(Msp::Game::Handle<Msp::Game::Entity>, const Setup &);
float get_moment_of_inertia() const { return setup.moment_of_inertia; }
void set_velocity(const Msp::LinAl::Vector<float, 2> &);
void set_angular_velocity(Msp::Geometry::Angle<float>);
+ void add_force(const Msp::LinAl::Vector<float, 2> &);
+ void add_force(const Msp::LinAl::Vector<float, 2> &, const Msp::LinAl::Vector<float, 2> &);
+ void add_torque(float);
+ void clear_forces();
const Msp::LinAl::Vector<float, 2> &get_velocity() const { return velocity; }
Msp::Geometry::Angle<float> get_angular_velocity() const { return angular_velocity; }
+ const Msp::LinAl::Vector<float, 2> &get_force() const { return force; }
+ float get_torque() const { return torque; }
};
#endif