]> git.tdb.fi Git - libs/game.git/blobdiff - examples/bassteroids/source/rigidbody.cpp
Allow external forces and torques to be added on rigid bodies
[libs/game.git] / examples / bassteroids / source / rigidbody.cpp
index c1d096e6a69817a2ba00299349810304b7f4a9f4..391707a574ee40b2e8b36f8fd098961aab95ab4f 100644 (file)
@@ -1,4 +1,6 @@
 #include "rigidbody.h"
+#include <msp/game/entity.h>
+#include <msp/game/transform.h>
 
 using namespace Msp;
 
@@ -11,3 +13,31 @@ void RigidBody::set_velocity(const LinAl::Vector<float, 2> &v)
 {
        velocity = v;
 }
+
+void RigidBody::set_angular_velocity(Geometry::Angle<float> as)
+{
+       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;
+}