X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2Fmoof%2Frigid_body.hh;fp=src%2Fmoof%2Frigid_body.hh;h=7ed0a88131089dc45badd3c872eb7570928c67dc;hp=b8b9048c358e92fa70f01ab9d43af899308545eb;hb=aa67fc8ab5691cad24b55d0e12aba2f6c3e58316;hpb=b7bb13579fa86907a8c221a9dc6285f26942ad44 diff --git a/src/moof/rigid_body.hh b/src/moof/rigid_body.hh index b8b9048..7ed0a88 100644 --- a/src/moof/rigid_body.hh +++ b/src/moof/rigid_body.hh @@ -27,7 +27,9 @@ namespace moof { -template +extern scalar global_acceleration; + +template struct linear_state { typedef moof::vector< scalar, fixed > vector; @@ -56,22 +58,20 @@ struct linear_state struct gravity_force { - explicit gravity_force(scalar a = -9.8) + gravity_force() { force.zero(); - acceleration = a; } const vector& operator () (const linear_state& state) { - force[1] = state.mass * acceleration; + force[1] = state.mass * global_acceleration; return force; } private: - vector force; - scalar acceleration; + vector force; }; void init() @@ -85,7 +85,7 @@ struct linear_state forces.clear(); mass = SCALAR(1.0); - inverse_mass = 1.0 / mass; + inverse_mass = SCALAR(1.0); } struct derivative @@ -114,9 +114,10 @@ struct linear_state { vector f(force); - for (size_t i = 0; i < forces.size(); ++i) + typename std::vector::const_iterator it; + for (it = forces.begin(); it != forces.end(); ++it) { - f += forces[i](*this); + f += (*it)(*this); } return f; @@ -143,7 +144,7 @@ struct rotational_state2 scalar angular_momentum; // secondary - scalar angularVelocity; + scalar angular_velocity; // constant scalar inertia; @@ -151,18 +152,18 @@ struct rotational_state2 void recalculate() { - angularVelocity = angular_momentum * inertia; + angular_velocity = angular_momentum * inertia; } struct derivative { - scalar angularVelocity; + scalar angular_velocity; scalar torque; }; void step(const derivative& derivative, scalar dt) { - orientation += dt * derivative.angularVelocity; + orientation += dt * derivative.angular_velocity; angular_momentum += dt * derivative.torque; recalculate(); } @@ -176,7 +177,7 @@ struct rotational_state3 // secondary quaternion spin; - vector3 angularVelocity; + vector3 angular_velocity; // constant scalar inertia; @@ -184,7 +185,7 @@ struct rotational_state3 void recalculate() { - angularVelocity = angular_momentum * inertia; + angular_velocity = angular_momentum * inertia; } }; @@ -255,11 +256,6 @@ interpolate(const state3& a, const state3& b, scalar alpha) template class rigid_body : public entity { -protected: - - T state_; - T prev_state_; - public: virtual ~rigid_body() {} @@ -284,6 +280,11 @@ public: { return prev_state_; } + +protected: + + T state_; + T prev_state_; }; typedef rigid_body rigid_body2;