original resources are provided under the zlib/libpng License. See COPYING
for complete details.
-
Dependencies:
-boost headers 1.35.0
-libGL
-libSDL 1.2.13
-libSDL_image 1.2.7
+boost headers
+OpenGL (libGL, libGL or opengl32, glu32)
+libSDL
+libSDL_image (with libpng support)
+libSDL_sound (with libogg support)
+libopenal
+libalut
+
+
+Notes regarding the code:
+
+I've made some effort to put the more generic or reusable code into a separate
+library called Moof. I've also made an effort to incorporate 3rd-party code
+that happened to fit well into what I needed. So, generally, the source code is
+separated into these three categories:
+
+1. Yoink-specific code.
+
+This is the code directly in src/. These classes reside in no namespace.
+
+2. Reusable code.
+
+Currently, the code is in src/Moof/, and it is compiled as a convenience
+library. These classes and other helper functions reside in the Mf namespace.
+Since I wrote this code alongside the Yoink-specific stuff, there is somewhat of
+a blurry line between the two categories.
+
+3. 3rd-party code.
-Note: The version numbers are the versions I have been using for development,
-not necessarily the minimum required version numbers.
+This is made up of free code from other projects or libraries (aside from the
+explicit dependencies above), the licenses of which are also in the COPYING
+file. This code resides in various namespaces and in various subdirectories.
current.mass = 1.0;
current.inverseMass = 1.0 / current.mass;
+ // gravity
current.force = Mf::Vector2(0.0, -120.0);
+ // starting position
current.position = Mf::Vector2(64.0, 64.0);
current.momentum = Mf::Vector2(0.0, 0.0);
current.recalculate();
updateContainers();
}
-Character::~Character()
-{
- //delete texture;
- //delete anim;
-}
-
void Character::update(Mf::Scalar t, Mf::Scalar dt)
{
#include <Moof/Event.hh>
#include <Moof/Math.hh>
#include <Moof/Octree.hh>
-#include <Moof/Physics.hh>
+#include <Moof/RK4.hh>
#include <Moof/Tilemap.hh>
recalculate();
}
+ // these two operator overloads all using the state in generic
+ // interpolator implementations
+
State operator*(Mf::Scalar scalar) const
{
State state = *this;
}
Character(const std::string& name);
- virtual ~Character();
+ inline virtual ~Character() {}
void update(Mf::Scalar t, Mf::Scalar dt);
void handleEvent(const Mf::Event& event);
};
-inline Character::State operator*(Mf::Scalar scalar,
- const Character::State& state)
-{
- Character::State newState = state;
- newState.position *= scalar;
- newState.momentum *= scalar;
- newState.recalculate();
- return newState;
-}
+//inline Character::State operator*(Mf::Scalar scalar,
+ //const Character::State& state)
+//{
+ //Character::State newState = state;
+ //newState.position *= scalar;
+ //newState.momentum *= scalar;
+ //newState.recalculate();
+ //return newState;
+//}
#endif // _CHARACTER_HH_
Moof/Octree.cc \
Moof/Octree.hh \
Moof/OpenGL.hh \
- Moof/Physics.hh \
Moof/Plane.cc \
Moof/Plane.hh \
Moof/Random.cc \
Moof/Rectangle.hh \
Moof/Resource.cc \
Moof/Resource.hh \
+ Moof/RK4.hh \
Moof/Scene.cc \
Moof/Scene.hh \
Moof/Serializable.cc \
Matrix4 modelview_;
Frustum frustum_;
- Lerpv3 pInterp_;
+ Lerp3 pInterp_;
};
inline Dispatcher::Handler addHandler(const std::string& message,
const Dispatcher::Function& callback)
{
- Dispatcher::getInstance().addHandler(message, callback);
+ return Dispatcher::getInstance().addHandler(message, callback);
}
inline Dispatcher::Handler addHandler(const std::string& message,
const Dispatcher::Function& callback, Dispatcher::Handler id)
{
- Dispatcher::getInstance().addHandler(message, callback, id);
+ return Dispatcher::getInstance().addHandler(message, callback, id);
}
inline void removeHandler(Dispatcher::Handler id)
namespace Mf {
+// TODO - cleanup these classes
+
class Interpolator
{
void clamp(Scalar& value)
bool stopped_;
};
-template <class T>
+template <class T = Scalar>
class InterpolatorBase : public Interpolator
{
public:
};
-template <class T, int D>
-class BinomialInterpolator : public InterpolatorBase<T>
+template <int D, class T = Scalar>
+class PolynomialInterpolator : public InterpolatorBase<T>
{
public:
- BinomialInterpolator() {}
+ PolynomialInterpolator() {}
- explicit BinomialInterpolator(const T coefficients[D+1],
+ PolynomialInterpolator(const T coefficients[D+1],
Scalar seconds = 1.0, Interpolator::Mode mode = Interpolator::STOP)
{
init(coefficients, seconds, mode);
fac[1] = 1.0;
// build an array of the computed factorials we will need
- for (int i = 2; i <= D; i++)
+ for (int i = 2; i <= D; ++i)
{
fac[i] = i * fac[i - 1];
}
// combine the coefficients for fast updating
- for (int i = 0; i <= D; i++)
+ for (int i = 0; i <= D; ++i)
{
// n! / (k! * (n - k)!)
coefficients_[i] = coefficients[i] * fac[D] / (fac[i] * fac[D - i]);
value = coefficients_[0] * std::pow(beta, D);
- for (int i = 1; i <= D; i++)
+ for (int i = 1; i <= D; ++i)
{
value += coefficients_[i] * std::pow(beta, D - i) *
std::pow(alpha, i);
};
+// specialized linear interpolator
+
template <class T>
-class BinomialInterpolator<T,1> : public InterpolatorBase<T>
+class PolynomialInterpolator<1,T> : public InterpolatorBase<T>
{
public:
- BinomialInterpolator() {}
+ PolynomialInterpolator() {}
- explicit BinomialInterpolator(const T coefficients[2], Scalar seconds = 1.0,
+ PolynomialInterpolator(const T coefficients[2], Scalar seconds = 1.0,
Interpolator::Mode mode = Interpolator::STOP)
//InterpolatorBase<T>(seconds, mode)
{
// interpolation functions in cml for other types of interpolation such as
// slerp and some multi-alpha interpolators.
-typedef BinomialInterpolator<Scalar, 1> Lerps; // linear
-typedef BinomialInterpolator<Vector2,1> Lerpv2;
-typedef BinomialInterpolator<Vector3,1> Lerpv3;
-typedef BinomialInterpolator<Vector4,1> Lerpv4;
+typedef PolynomialInterpolator<1> Lerp; // linear
+typedef PolynomialInterpolator<1,Vector2> Lerp2;
+typedef PolynomialInterpolator<1,Vector3> Lerp3;
+typedef PolynomialInterpolator<1,Vector4> Lerp4;
-typedef BinomialInterpolator<Scalar ,2> Qerps; // quadratic
-typedef BinomialInterpolator<Vector2,2> Qerpv2;
-typedef BinomialInterpolator<Vector3,2> Qerpv3;
-typedef BinomialInterpolator<Vector4,2> Qerpv4;
+typedef PolynomialInterpolator<2> Qerp; // quadratic
+typedef PolynomialInterpolator<2,Vector2> Qerp2;
+typedef PolynomialInterpolator<2,Vector3> Qerp3;
+typedef PolynomialInterpolator<2,Vector4> Qerp4;
-typedef BinomialInterpolator<Scalar ,3> Cerps; // cubic
-typedef BinomialInterpolator<Vector2,3> Cerpv2;
-typedef BinomialInterpolator<Vector3,3> Cerpv3;
-typedef BinomialInterpolator<Vector4,3> Cerpv4;
+typedef PolynomialInterpolator<3> Cerp; // cubic
+typedef PolynomialInterpolator<3,Vector2> Cerp2;
+typedef PolynomialInterpolator<3,Vector3> Cerp3;
+typedef PolynomialInterpolator<3,Vector4> Cerp4;
} // namespace Mf
*******************************************************************************/
-#ifndef _MOOF_PHYSICS_HH_
-#define _MOOF_PHYSICS_HH_
+#ifndef _MOOF_RK4_HH_
+#define _MOOF_RK4_HH_
#include <Moof/Math.hh>
namespace Mf {
// Generic implementation of the RK4 integrator. To use, you need one type
-// representing the state and another containing the derivatives of the state.
+// representing the state and another containing the derivatives of the primary
+// state variables. The state class must implement these methods:
+//
+// void getDerivative(Derivative_Type& derivative, Scalar absoluteTime);
+// void applyDerivative(const Derivative_Type& derivative, Scalar deltaTime);
+//
+// Additionally, the derivative class must overload a few operators:
+//
+// Derivative_Type operator+(const Derivative_Type& other) const
+// Derivative_Type operator*(const Derivative_Type& other) const
template<typename S, typename D>
inline D evaluate(const S& state, Scalar t)
D c = evaluate<S,D>(state, t, dt * 0.5, b);
D d = evaluate<S,D>(state, t, dt, c);
- //state += (a + (b + c) * 2.0 + d) * (1.0/6.0) * dt;
state.applyDerivative((a + (b + c) * 2.0 + d) * (1.0/6.0), dt);
}
} // namespace Mf
-#endif // _MOOF_PHYSICS_HH_
+#endif // _MOOF_RK4_HH_
/** vim: set ts=4 sw=4 tw=80: *************************************************/
temporary_type result;
detail::InterpResize(result, val1, size_tag());
- result = (Scalar(1) - u) * val0 + u * val1;
+ result = val0 * (Scalar(1) - u) + val1 * u;
return result;
}
heroine = Character::alloc("RobotTrooper");
heroine->getAnimation().startSequence("Run");
- font = new TilemapFont;
+ Mf::Scalar a[6] = {0.0, 1.5, -0.5, 3.0, -1.5, 1.0};
+ interp.init(a, 2.0, Mf::Interpolator::OSCILLATE);
- Mf::Scalar coeffs[4];
- coeffs[0] = 0.0;
- coeffs[1] = 1.5;
- coeffs[2] = -0.5;
- coeffs[3] = 1.0;
- interp.init(coeffs, 1.0, Mf::Interpolator::OSCILLATE);
-
- Mf::Scalar coeff[2] = {1.0, 0.0};
- fadeIn.init(coeff, 0.1);
+ Mf::Scalar b[2] = {1.0, 0.0};
+ fadeIn.init(b, 1.0);
testScene = Mf::Scene::alloc("Test");
heroine->treeNode = testScene->getOctree()->insert(heroine);
YoinkApp::~YoinkApp()
{
- //delete heroine;
- delete font;
-
Mf::dispatcher::removeHandler(this);
}
void YoinkApp::contextRecreated(const Mf::Notification* note)
{
- // Whenever the context and a new one created, it probably won't contain our
- // state so we need to set that up again.
+ // Whenever the context is destroyed and a new one created, it probably
+ // won't contain our state so we need to set that up again.
setupGL();
}
void YoinkApp::update(Mf::Scalar t, Mf::Scalar dt)
{
- //dt *= 0.5;
+ //dt *= 0.1;
music.update(t, dt);
fadeIn.update(dt);
camera.setPosition(Mf::Vector3(-heroine->current.position[0], -heroine->current.position[1], -256));
interp.update(dt);
- hud.setBar1Progress(interp.getValue());
- hud.setBar2Progress(1.0 - interp.getValue());
+ hud.setBar1Progress(interp.getState(dt));
+ hud.setBar2Progress(1.0 - interp.getState(dt));
}
{
Mf::logError("unhandled exception: <<%s>>", e.what());
Mf::logInfo("it's time to crash now :-(");
- status = 1;
+ //status = 1;
+ throw e;
}
std::cout << std::endl << "Goodbye..." << std::endl << std::endl;
#include <Moof/Interpolator.hh>
#include <Moof/Math.hh>
#include <Moof/Scene.hh>
-
-#include "Character.hh"
-#include "TilemapFont.hh"
-
#include <Moof/Sound.hh>
+#include "Character.hh"
#include "Hud.hh"
CharacterP heroine;
Mf::Sound punchSound;
- TilemapFont *font;
- Mf::Cerps interp;
- Mf::Lerps fadeIn;
+ Mf::PolynomialInterpolator<5> interp;
+ Mf::Lerp fadeIn;
Mf::Camera camera;
Mf::SceneP testScene;