]> Dogcows Code - chaz/yoink/blob - src/Moof/Transition.hh
more explicit constructors
[chaz/yoink] / src / Moof / Transition.hh
1
2 /*] Copyright (c) 2009-2010, Charles McGarvey [**************************
3 **] All rights reserved.
4 *
5 * vi:ts=4 sw=4 tw=75
6 *
7 * Distributable under the terms and conditions of the 2-clause BSD license;
8 * see the file COPYING for a complete text of the license.
9 *
10 **************************************************************************/
11
12 #define _MOOF_TRANSITION_HH_
13 #ifndef _MOOF_TRANSITION_HH_
14 #define _MOOF_TRANSITION_HH_
15
16 #include <boost/shared_ptr.hpp>
17
18 #include <Moof/Core.hh>
19 #include <Moof/Interpolator.hh>
20 #include <Moof/Layer.hh>
21 #include <Moof/Log.hh>
22 #include <Moof/Math.hh>
23 #include <Moof/OpenGL.hh>
24 #include <Moof/Texture.hh>
25
26
27 namespace Mf {
28
29
30 template <class T>
31 class Transition : public Layer
32 {
33 LayerP mTo;
34 LayerP mFrom;
35
36 T mInterp;
37
38 public:
39
40 Transition(LayerP t, LayerP f, const T& interp) :
41 mTo(t),
42 mFrom(f),
43 mInterp(interp) {}
44
45 typedef boost::shared_ptr<Transition> Ptr;
46
47 static Ptr alloc(LayerP t, LayerP f, const T& interp)
48 {
49 return Ptr(new Transition(t, f, interp));
50 }
51
52
53 void removedFromCore(Core& core)
54 {
55 if (mTo) core.push(mTo);
56 }
57
58 void update(Core& core, Scalar t, Scalar dt)
59 {
60 mInterp.update(t, dt);
61
62 if (mFrom) mFrom->update(core, t, dt);
63 if (mTo) mTo->update(core, t, dt);
64
65 if (mInterp.isDone())
66 {
67 // to should /replace/ this
68 core.pop(this);
69 }
70 }
71
72 void drawFade(Scalar alpha) const
73 {
74 // DRAW FADE
75 glDisable(GL_DEPTH_TEST);
76 glDisable(GL_ALPHA_TEST);
77 glEnable(GL_BLEND);
78 glMatrixMode(GL_PROJECTION);
79 glPushMatrix();
80 glLoadIdentity();
81 glMatrixMode(GL_MODELVIEW);
82 glPushMatrix();
83 glLoadIdentity();
84 glColor(1.0, 1.0, 1.0, alpha);
85 Mf::Texture::resetBind();
86
87 //glRectf(-1.0f, -1.0f, 1.0f, 1.0f);
88 glBegin(GL_QUADS);
89 glVertex(-1.0, -1.0, -0.1);
90 glVertex(1.0, -1.0, -0.1);
91 glVertex(1.0, 1.0, -0.1);
92 glVertex(-1.0, 1.0, -0.1);
93 glEnd();
94
95 glDisable(GL_BLEND);
96 glEnable(GL_DEPTH_TEST);
97 glEnable(GL_ALPHA_TEST);
98
99 glMatrixMode(GL_PROJECTION);
100 glPopMatrix();
101 glMatrixMode(GL_MODELVIEW);
102 glPopMatrix();
103 }
104
105 void draw(Core& core, Scalar alpha) const
106 {
107 Scalar a = mInterp.getState(alpha);
108 logInfo << "transition state: " << a << std::endl;
109
110 //glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
111
112 if (mFrom)
113 {
114 glPushMatrix();
115 glLoadIdentity();
116 glRotate(180.0 * a, 0.0, 1.0, 0.0);
117 mFrom->draw(core, alpha);
118 glPopMatrix();
119 }
120 //drawFade(a);
121
122 if (mTo)
123 {
124 glPushMatrix();
125 glLoadIdentity();
126 glRotate(180.0 * (1.0 - a), 0.0, 1.0, 0.0);
127 mTo->draw(core, alpha);
128 glPopMatrix();
129 }
130 //drawFade(1.0 - a);
131 }
132
133 bool handleEvent(Core& core, const Event& event)
134 {
135 if (mTo)
136 {
137 return mTo->handleEvent(core, event);
138 }
139 else if (mFrom)
140 {
141 return mFrom->handleEvent(core, event);
142 }
143 return false;
144 }
145 };
146
147
148 } // namespace Mf
149
150 #endif // _MOOF_TRANSITION_HH_
151
This page took 0.036968 seconds and 4 git commands to generate.