Morph-SynRJ
view trans_explode.cxx @ 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 #include "trans_explode.h"
2 #include "gl_header.h"
3 #include "cmn_intro.h"
4 #include "cmn_texture.h"
6 trans_Explode_t::trans_Explode_t(int max_x_quads, int max_y_quads)
7 {
8 res_x = max_x_quads;
9 res_y = max_y_quads;
11 quads = new transExplodeQuad[max_x_quads*max_y_quads];
13 }
15 trans_Explode_t::~trans_Explode_t(void)
16 {
17 if (quads)
18 delete [] quads;
20 }
22 GLuint trans_Explode_t::CreateTextureTransition(int x, int y)
23 {
24 GLuint txtnumber;
25 unsigned char *data;
27 glEnable(GL_TEXTURE_2D);
29 data = (unsigned char *)new GLuint[((x * y)*4*sizeof(unsigned int))];
31 glGenTextures(1, &txtnumber);
32 glBindTexture(GL_TEXTURE_2D, txtnumber);
33 glTexImage2D(GL_TEXTURE_2D, 0, 4, x, y, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
34 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
35 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
37 delete [] data;
39 return txtnumber;
40 }
43 #define TEST_PSC80
45 void trans_Explode_t::PutOneQuad(float size, float px, float py, float pz, float u, float v, float rx, float ry, float rz)
46 {
47 glPushMatrix();
49 glTranslatef(px, py, pz);
51 float uv_size = 256.f*size;
53 #ifdef TEST_PSC80
54 float quad_size = 2.f/res_x;
55 uv_size=quad_size/256.0;
56 uv_size=1.0/res_x;
58 glBegin(GL_QUADS);
59 glTexCoord2f(u, v); glVertex3f(-size, -size, 0.f);
60 glTexCoord2f(u, v+uv_size); glVertex3f(-size, size, 0.f);
61 glTexCoord2f(u+uv_size, v+uv_size); glVertex3f( size, size, 0.f);
62 glTexCoord2f(u+uv_size, v); glVertex3f( size, -size, 0.f);
63 glEnd();
65 #else
67 glBegin(GL_QUADS);
68 glTexCoord2f(u-uv_size, v-uv_size); glVertex3f(-size, -size, 0.f);
69 glTexCoord2f(u-uv_size, v+uv_size); glVertex3f(-size, size, 0.f);
70 glTexCoord2f(u+uv_size, v+uv_size); glVertex3f( size, size, 0.f);
71 glTexCoord2f(u+uv_size, v-uv_size); glVertex3f( size, -size, 0.f);
72 glEnd();
73 #endif
75 glPopMatrix();
76 }
78 void trans_Explode_t::SetQuadsProperty(void)
79 {
80 float quad_size = 2.f/res_x;
82 for (int x=0; x<res_x; x++)
83 {
84 for (int y=0; y<res_y; y++)
85 {
86 quads[x+y*res_x].Position[0] = (quad_size/2) + x * quad_size - res_x * (quad_size/2);
87 quads[x+y*res_y].Position[1] = (quad_size/2) + y * quad_size - res_y * (quad_size/2);
88 quads[x+y*res_x].Position[2] = 0.f;
90 // quads[x+y*res_x].Uvs[0] = x * 256.f / ((quad_size/2) * quad_size - res_x * (quad_size/2));
91 // quads[x+y*res_x].Uvs[1] = y * 256.f / ((quad_size/2) * quad_size - res_y * (quad_size/2));
92 #ifndef TEST_PSC80 // your version
93 quads[x+y*res_x].Uvs[0] = x * 256.f / quads[x+y*res_x].Position[0];
94 quads[x+y*res_x].Uvs[1] = y * 256.f / quads[x+y*res_x].Position[1];
95 #else
96 quads[x+y*res_x].Uvs[0] = x / (quad_size*res_x);//+ 256.f / (quad_size*rex_x);
97 quads[x+y*res_x].Uvs[1] = y / (quad_size*res_y);//+ 256.f / (quad_size*rex_x);
98 #endif
99 quads[x+y*res_x].Uvs[2] = 0.f;
100 }
101 }
103 for (int i=0; i<res_x*res_y; i++)
104 {
105 quads[i].size = 0.1f;
107 quads[i].Velocity[0] = float(4000-mth::Rand()%8000)/1000.f;
108 quads[i].Velocity[1] = float(4000-mth::Rand()%8000)/1000.f;
109 quads[i].Velocity[2] = float(mth::Rand()%4000)/1000.f;
111 quads[i].Rotation[0] = 10.f;//float(mth::Rand()%2000)/100.f;
112 quads[i].Rotation[1] = 20.f;//float(mth::Rand()%2000)/100.f;
113 quads[i].Rotation[2] = 30.f;//float(mth::Rand()%2000)/100.f;
115 quads[i].alpha = 1.f;
117 }
119 }
121 void trans_Explode_t::GetScene(GLuint texture)
122 {
123 glDisable(GL_BLEND);
126 #ifdef TEST_PSC80
128 txtBindTexture2d(texture,0);
129 glCopyTexSubImage2D(GL_TEXTURE_2D,0,0,0,200,200,256,256);
130 txtUnBindTexture2d(0);
133 #else
134 glViewport(0, 0, 256, 256);
136 glEnable(GL_TEXTURE_2D);
137 glBindTexture(GL_TEXTURE_2D, texture);
139 // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
140 // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
141 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
142 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
144 glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, 256, 256, 0);
146 // glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
147 glDisable(GL_TEXTURE_2D);
149 glViewport(0, 0, RX, RY);
150 #endif
151 glEnable(GL_BLEND);
152 }
154 void trans_Explode_t::Draw(float speed)
155 {
156 cmnSetFrustrum(90);
157 cmnSetCamera( mth::Vector3_t(0, 0, 1), mth::Vector3_t(0 ,0, 0));
159 //glEnable(GL_BLEND);
160 //glBlendFunc(GL_SRC_ALPHA, GL_DST_ALPHA);
162 glDisable(GL_BLEND);
164 for (int i=0; i<res_x*res_y; i++)
165 {
166 glColor4f(1.f, 1.f, 1.f, quads[i].alpha);
168 PutOneQuad(quads[i].size,
169 quads[i].Position[0], quads[i].Position[1], quads[i].Position[2],
170 quads[i].Uvs[0], quads[i].Uvs[1],
171 quads[i].Rotation[0]+speed, quads[i].Rotation[1]+speed, quads[i].Rotation[2]+speed);
173 #define DEBUG_QUADS
174 #ifdef DEBUG_QUADS
176 glLineWidth(2.f);
178 glDisable(GL_TEXTURE_2D);
180 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
181 PutOneQuad(quads[i].size,
182 quads[i].Position[0], quads[i].Position[1], quads[i].Position[2],
183 quads[i].Uvs[0], quads[i].Uvs[1],
184 quads[i].Rotation[0]+speed, quads[i].Rotation[1]+speed, quads[i].Rotation[2]+speed);
185 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
187 glEnable(GL_TEXTURE_2D);
188 #endif
190 }
192 glEnable(GL_BLEND);
193 }
195 void trans_Explode_t::Animate(float start_time, float end_time, float speed)
196 {
197 for (int i=0; i<=res_x*res_y; i++)
198 {
199 if (quads[i].alpha > 0.f) quads[i].alpha -= speed*2.f;
201 quads[i].Position[0] += 6.f*quads[i].Velocity[0]*speed/2.f;
202 quads[i].Position[1] += 6.f*quads[i].Velocity[1]*speed/2.f;
203 quads[i].Position[2] -= quads[i].Velocity[2]*speed;
204 }
206 }
