-
-/*] Copyright (c) 2009-2010, 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.
-*
-**************************************************************************/
-
-#define _MOOF_TRANSITION_HH_
-#ifndef _MOOF_TRANSITION_HH_
-#define _MOOF_TRANSITION_HH_
-
-#include <boost/shared_ptr.hpp>
-
-#include <Moof/Core.hh>
-#include <Moof/Interpolator.hh>
-#include <Moof/Layer.hh>
-#include <Moof/Log.hh>
-#include <Moof/Math.hh>
-#include <Moof/OpenGL.hh>
-#include <Moof/Texture.hh>
-
-
-namespace Mf {
-
-
-template <class T>
-class Transition : public Layer
-{
- LayerP mTo;
- LayerP mFrom;
-
- T mInterp;
-
-public:
-
- Transition(LayerP t, LayerP f, const T& interp) :
- mTo(t),
- mFrom(f),
- mInterp(interp) {}
-
- typedef boost::shared_ptr<Transition> Ptr;
-
- static Ptr alloc(LayerP t, LayerP f, const T& interp)
- {
- return Ptr(new Transition(t, f, interp));
- }
-
-
- void removedFromCore(Core& core)
- {
- if (mTo) core.push(mTo);
- }
-
- void update(Core& core, Scalar t, Scalar dt)
- {
- mInterp.update(t, dt);
-
- if (mFrom) mFrom->update(core, t, dt);
- if (mTo) mTo->update(core, t, dt);
-
- if (mInterp.isDone())
- {
- // to should /replace/ this
- core.pop(this);
- }
- }
-
- void drawFade(Scalar alpha) const
- {
- // DRAW FADE
- glDisable(GL_DEPTH_TEST);
- glDisable(GL_ALPHA_TEST);
- glEnable(GL_BLEND);
- glMatrixMode(GL_PROJECTION);
- glPushMatrix();
- glLoadIdentity();
- glMatrixMode(GL_MODELVIEW);
- glPushMatrix();
- glLoadIdentity();
- glColor(1.0, 1.0, 1.0, alpha);
- Mf::Texture::resetBind();
-
- //glRectf(-1.0f, -1.0f, 1.0f, 1.0f);
- glBegin(GL_QUADS);
- glVertex(-1.0, -1.0, -0.1);
- glVertex(1.0, -1.0, -0.1);
- glVertex(1.0, 1.0, -0.1);
- glVertex(-1.0, 1.0, -0.1);
- glEnd();
-
- glDisable(GL_BLEND);
- glEnable(GL_DEPTH_TEST);
- glEnable(GL_ALPHA_TEST);
-
- glMatrixMode(GL_PROJECTION);
- glPopMatrix();
- glMatrixMode(GL_MODELVIEW);
- glPopMatrix();
- }
-
- void draw(Core& core, Scalar alpha) const
- {
- Scalar a = mInterp.getState(alpha);
- logInfo << "transition state: " << a << std::endl;
-
- //glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-
- if (mFrom)
- {
- glPushMatrix();
- glLoadIdentity();
- glRotate(180.0 * a, 0.0, 1.0, 0.0);
- mFrom->draw(core, alpha);
- glPopMatrix();
- }
- //drawFade(a);
-
- if (mTo)
- {
- glPushMatrix();
- glLoadIdentity();
- glRotate(180.0 * (1.0 - a), 0.0, 1.0, 0.0);
- mTo->draw(core, alpha);
- glPopMatrix();
- }
- //drawFade(1.0 - a);
- }
-
- bool handleEvent(Core& core, const Event& event)
- {
- if (mTo)
- {
- return mTo->handleEvent(core, event);
- }
- else if (mFrom)
- {
- return mFrom->handleEvent(core, event);
- }
- return false;
- }
-};
-
-
-} // namespace Mf
-
-#endif // _MOOF_TRANSITION_HH_
-