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