-/*] 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_
{
typedef moof::vector< scalar, fixed<D> > vector;
typedef boost::function<const vector& (const linear_state&)>
- force_function;
+ force_function;
// primary
-
vector position;
vector momentum;
// secondary
-
vector velocity;
// user
-
vector force;
std::vector<force_function> forces;
// constant
-
scalar mass;
scalar inverse_mass;
-
void recalculate()
{
velocity = momentum * inverse_mass;
}
-
struct gravity_force
{
explicit gravity_force(scalar a = -9.8)
return force;
}
-
private:
vector force;
scalar acceleration;
};
-
void init()
{
position.zero();
inverse_mass = 1.0 / mass;
}
-
struct derivative
{
vector velocity;
}
};
-
vector total_force() const
{
vector f(force);
}
};
-
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;
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;
}
};
-
template <class T>
inline T interpolate(const T& a, const T& b, scalar alpha)
{
}
template <>
-inline state2 interpolate<state2>(const state2& a, const state2& b,
- scalar alpha)
+inline state2
+interpolate<state2>(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<state3>(const state3& a, const state3& b,
- scalar alpha)
+inline state3
+interpolate<state3>(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 T>
class rigid_body : public entity
{