Morph-SynRJ

view cmn_design.h @ 0:22de913c2d84

morph-synrj intro
author "Cedric Pinson <cedric.pinson@alcove.fr> <mornifle@plopbyte.net>"
date Tue Nov 27 15:23:52 2007 +0100 (2007-11-27)
parents
children
line source
1 #ifndef CMN_DESIGN_H
2 #define CMN_DESIGN_H
4 #include "cmn_intro.h"
5 #include "cmn_texture.h"
6 #include "mth_vector2.h"
7 #include "mth_vector3.h"
11 struct cmnDesignElement_t
12 {
13 mth::Vector3_t position;
14 mth::Vector3_t target;
15 float factor;
16 float start;
17 // float start;
18 bool active;
20 virtual void Update() {
21 position+=(target-position)*factor*Timer->GetFrameTime();
23 #if 0 // put one to debug your position ...
24 cmnPushMatrix();
25 cmnPushGLState();
26 cmnSetPlanarView();
27 glDisable(GL_BLEND);
28 glColor3f(1,1,1);
29 font->Print("Position %f %f %f\n",position[0],position[1],position[2]);
30 cmnPopGLState();
31 cmnPopMatrix();
32 #endif
33 }
35 cmnDesignElement_t() {start=1e5;}
37 void Init(float _time,const mth::Vector3_t& _pos,const mth::Vector3_t& _target,float _factor=1.0) {
38 active=false;
39 start=_time;
40 position=_pos;
41 target=_target;
42 factor=_factor;
43 }
45 void Init(float _time) {
46 active=false;
47 start=_time;
48 }
50 virtual void Draw() {}
51 };
54 struct cmnDesignElementFont_t : public cmnDesignElement_t
55 {
56 const char* text;
57 float alpha;
58 float endLife;
59 float scalex;
60 float scaley;
61 float alphaFactor;
63 cmnDesignElementFont_t() { factor=1;scalex=scaley=1.0;alphaFactor=-0.1;}
65 void Update() {
66 float dt=Timer->GetFrameTime();
67 position+=(target-position)*factor*dt;
69 if (active) {
70 alpha+=alphaFactor*dt;
71 endLife-=dt;
72 if (endLife<0) {
73 active=false;
74 start=1e5;
75 }
76 }
77 }
79 void Draw() {
80 if (text) {
81 //text[1]=0;
82 glColor4f(1,1,1,alpha);
83 font->SetScaleX(scalex);
84 font->SetScaleY(scaley);
85 font->Clear();
86 float t[2]={position[0],position[1]};
87 font->SetZ(position[2]);
88 font->Print(t[0],t[1],text);
89 font->SetZ(0);
90 font->SetScale(1);
91 }
92 }
94 };
98 struct cmnDesignElementTexturedQuad_t : public cmnDesignElement_t
99 {
100 GLuint texture;
101 float sizex,sizey;
102 float alpha;
103 float fadeAlpha;
104 float color[3];
105 public:
107 void Draw();
108 cmnDesignElementTexturedQuad_t() { texture=0; alpha=1;fadeAlpha=0; color[0]=color[1]=color[2]=1.0;}
109 void Color(float a,float b,float c) { color[0]=a;color[1]=b;color[2]=c;}
110 void Update() {
111 float dt=Timer->GetFrameTime();
112 position+=(target-position)*factor*dt;
114 if (active) {
115 alpha-=0.1*fadeAlpha*dt;
116 if (alpha<0) {
117 active=false;
118 start=1e5;
119 }
120 }
121 }
123 };
128 class cmnDesign_t
129 {
130 typedef cmnDesignElement_t* ElementPtr_t;
131 double internalTime;
132 cmnDesignElement_t** elements;
133 int nbElements;
134 int maxNbElements;
136 public:
139 cmnDesign_t() { elements=0;maxNbElements= nbElements=0;internalTime=0;}
142 void Init(int _nbElements) {
143 if (elements)
144 delete [] elements;
145 elements=new ElementPtr_t[_nbElements];
146 maxNbElements=_nbElements;
147 }
149 void InitTime(double _time=0) {internalTime=_time;}
151 void Kill() {}
153 cmnDesignElement_t* Element(int _i) { SYS_ASSERT(_i>=0 && _i<nbElements); return elements[_i];}
156 void AddElement(cmnDesignElement_t* _e) {
157 SYS_ASSERT(nbElements<maxNbElements);
158 elements[nbElements++]=_e;
159 }
161 void Update();
163 void Draw();
165 };
170 class cmnDesignScroller_t
171 {
173 GLuint texture;
175 float uvs[2];
176 float scroll[2];
178 public:
181 cmnDesignScroller_t() {}
183 void Init(GLuint _texture);
184 void ScrollX(float _x) { scroll[0]=_x;}
185 void ScrollY(float _y) { scroll[1]=_y;}
186 void Update();
187 void Draw();
190 };
195 #endif