X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2Fmoof%2Frigid_body.hh;h=67e12ddce4d4b87e1a48e7b17816cf3806c63bb5;hp=65e502c8483ae1530c594882b1adb4e1258254f1;hb=574af38ed616d1adfa5e6ce35f67cda1f707f89d;hpb=6c9943707d4f33035830eba0587a61a34eaecbc2 diff --git a/src/moof/rigid_body.hh b/src/moof/rigid_body.hh index 65e502c..67e12dd 100644 --- a/src/moof/rigid_body.hh +++ b/src/moof/rigid_body.hh @@ -1,13 +1,11 @@ -/*] Copyright (c) 2009-2010, Charles McGarvey [************************** +/*] Copyright (c) 2009-2011, Charles McGarvey [***************************** **] All rights reserved. * -* vi:ts=4 sw=4 tw=75 -* * Distributable under the terms and conditions of the 2-clause BSD license; * see the file COPYING for a complete text of the license. * -**************************************************************************/ +*****************************************************************************/ #ifndef _MOOF_RIGID_BODY_HH_ #define _MOOF_RIGID_BODY_HH_ @@ -34,34 +32,28 @@ struct linear_state { typedef moof::vector< scalar, fixed > vector; typedef boost::function - force_function; + force_function; // primary - vector position; vector momentum; // secondary - vector velocity; // user - vector force; std::vector forces; // constant - scalar mass; scalar inverse_mass; - void recalculate() { velocity = momentum * inverse_mass; } - struct gravity_force { explicit gravity_force(scalar a = -9.8) @@ -76,14 +68,12 @@ struct linear_state return force; } - private: vector force; scalar acceleration; }; - void init() { position.zero(); @@ -98,7 +88,6 @@ struct linear_state inverse_mass = 1.0 / mass; } - struct derivative { vector velocity; @@ -121,7 +110,6 @@ struct linear_state } }; - vector total_force() const { vector f(force); @@ -148,30 +136,24 @@ struct linear_state } }; - struct rotational_state2 { // primary - scalar orientation; scalar angular_momentum; // secondary - scalar angularVelocity; // constant - scalar inertia; scalar inverse_inertia; - void recalculate() { angularVelocity = angular_momentum * inertia; } - struct derivative { scalar angularVelocity; @@ -189,21 +171,17 @@ struct rotational_state2 struct rotational_state3 { // primary - quaternion orientation; vector3 angular_momentum; // secondary - quaternion spin; vector3 angularVelocity; // constant - scalar inertia; scalar inverse_inertia; - void recalculate() { angularVelocity = angular_momentum * inertia; @@ -239,7 +217,6 @@ struct state3 : public linear_state<3>, public rotational_state3 } }; - template inline T interpolate(const T& a, const T& b, scalar alpha) { @@ -247,37 +224,34 @@ inline T interpolate(const T& a, const T& b, scalar alpha) } template <> -inline state2 interpolate(const state2& a, const state2& b, - scalar alpha) +inline state2 +interpolate(const state2& a, const state2& b, scalar alpha) { state2 state(b); state.position = interpolate(a.position, b.position, alpha); state.momentum = interpolate(a.momentum, b.momentum, alpha); state.orientation = interpolate(a.orientation, b.orientation, alpha); state.angular_momentum = interpolate(a.angular_momentum, - b.angular_momentum, alpha); + b.angular_momentum, alpha); return state; } template <> -inline state3 interpolate(const state3& a, const state3& b, - scalar alpha) +inline state3 +interpolate(const state3& a, const state3& b, scalar alpha) { state3 state(b); state.position = interpolate(a.position, b.position, alpha); state.momentum = interpolate(a.momentum, b.momentum, alpha); state.orientation = slerp(a.orientation, b.orientation, alpha); state.angular_momentum = interpolate(a.angular_momentum, - b.angular_momentum, alpha); + b.angular_momentum, alpha); return state; } - - /** * Interface for anything that can move. */ - template class rigid_body : public entity {