Morph-SynRJ
view trans_puzzle.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_puzzle.h"
2 #include "gl_header.h"
3 #include "cmn_intro.h"
4 #include "cmn_texture.h"
12 void transPuzzle_t::Init(int _xsection,int _ysection)
13 {
14 internalTime=0;
15 texture[0]=txtCreateEmptyTexture(1024,1024);
16 texture[1]=txtCreateEmptyTexture(1024,1024);
18 nbElements=_xsection*_ysection;
19 resY=_ysection;
20 resX=_xsection;
23 elements=new transPuzzleElement_t[nbElements];
25 float divx=RX*1.0/1024/resX;
26 float divy=RY*1.0/1024/resY;
28 const float SizeX=1.5*800.0/600/resX;
29 const float SizeY=SizeX;
30 const float TimeStep=0.5/nbElements;
31 const float MaxDist=mth::Sqrt(1.0*(resY*resY+resX*resX));
33 int i,j;
34 for (j=0;j<resY;j++)
35 for (i=0;i<resX;i++) {
36 elements[i+j*resX].position.Init(i*SizeX-resX*SizeX/2+SizeX/2,j*SizeY-resY*SizeY/2+SizeY/2,0);
37 elements[i+j*resX].size[0]=SizeX*1.0/2;
38 elements[i+j*resX].size[1]=SizeY*1.0/2;
39 elements[i+j*resX].uvs.Init(i*divx,j*divy);
40 elements[i+j*resX].uvsVec.Init(divx,divy);
41 elements[i+j*resX].angle=0;
42 // elements[i+j*resX].start=TimeStep*(i+j*resX);
43 elements[i+j*resX].start=0.5*mth::Sqrt(1.0*(i*i+j*j))/MaxDist;
44 elements[i+j*resX].rotation.Init(0,1,0);
45 }
48 started=false;
49 }
52 void transPuzzle_t::GetBuffer1()
53 {
54 CopyBackBufferToTexture(texture[0],RX,RY);
55 //started=true;
56 }
58 void transPuzzle_t::GetBuffer2()
59 {
60 CopyBackBufferToTexture(texture[1],RX,RY);
61 //started=true;
62 }
68 void transPuzzleElement_t::Draw(bool reverse)
69 {
71 // cmnDisplayBackground(texture[0]);
72 // return ;
74 cmnPushMatrix();
75 glMatrixMode(GL_MODELVIEW);
77 glTranslatef(position[0],position[1],position[2]);
78 glRotatef(angle,rotation[0],rotation[1],rotation[2]);
80 glBegin(GL_QUADS);
81 if (reverse) {
83 glTexCoord2f(uvs[0]+uvsVec[0],uvs[1]+uvsVec[1]);
84 glVertex3f(-size[0],size[1],0);
86 glTexCoord2f(uvs[0],uvs[1]+uvsVec[1]);
87 glVertex3f(size[0],size[1],0);
89 glTexCoord2f(uvs[0],uvs[1]);
90 glVertex3f(size[0],-size[1],0);
92 glTexCoord2f(uvs[0]+uvsVec[0],uvs[1]);
93 glVertex3f(-size[0],-size[1],0);
96 } else {
98 glTexCoord2f(uvs[0],uvs[1]);
99 glVertex3f(-size[0],-size[1],0);
101 glTexCoord2f(uvs[0]+uvsVec[0],uvs[1]);
102 glVertex3f(size[0],-size[1],0);
104 glTexCoord2f(uvs[0]+uvsVec[0],uvs[1]+uvsVec[1]);
105 glVertex3f(size[0],size[1],0);
107 glTexCoord2f(uvs[0],uvs[1]+uvsVec[1]);
108 glVertex3f(-size[0],size[1],0);
111 }
112 glEnd();
113 cmnPopMatrix();
114 }
117 void transPuzzle_t::Draw()
118 {
119 int i;
121 cmnPushMatrix();
122 cmnSetFrustrum(90);
123 cmnSetCamera(mth::Vector3_t(0,0,1),mth::Vector3_t(0,0,0));
124 glMatrixMode(GL_MODELVIEW);
125 //glLoadIdentity();
126 glDisable(GL_BLEND);
127 glBlendFunc(GL_SRC_ALPHA,GL_ONE);
128 glDisable(GL_DEPTH_TEST);
129 glEnable(GL_CULL_FACE);
130 //glDisable(GL_CULL_FACE);
131 txtBindTexture2d(texture[0],0);
132 for (i=0;i<nbElements;i++)
133 elements[i].Draw();
134 txtBindTexture2d(texture[1],0);
135 for (i=0;i<nbElements;i++)
136 elements[i].Draw(true);
137 txtUnBindTexture2d(0);
139 cmnPopMatrix();
140 }
143 void transPuzzle_t::Update(float _time)
144 {
145 int i;
146 const float AngleAdd=360;
147 const float MaxAngle=180;
149 double dt=Timer->GetFrameTime();
150 internalTime+=dt;
152 for (i=0;i<nbElements;i++)
153 if (elements[i].start<=_time) {
154 elements[i].angle=AngleAdd*(_time-elements[i].start);
155 elements[i].angle=mth::Min(MaxAngle,elements[i].angle);
156 }
157 // elements[i].position+=mth::Vector3_t(0,0,-10)*Timer->GetFrameTime();
159 }
