2 #define WIN32_LEAN_AND_MEAN
5 #if defined(__APPLE__) && defined(__MACH__)
6 #include <OpenGL/gl.h> // Header File For The OpenGL32 Library
7 #include <OpenGL/glu.h> // Header File For The GLu32 Library
9 #include <GL/gl.h> // Header File For The OpenGL32 Library
10 #include <GL/glu.h> // Header File For The GLu32 Library
13 #include "SDL/SDL_image.h"
14 #include "SDL/SDL_timer.h"
15 #include "SDL/SDL_mixer.h"
17 #include "e3d_engine.h"
19 // Desde nespa.cpp; Callbacks
20 extern void callback_Checkpoint_onChange(int new_checkpoint
);
21 extern void callback_Checkpoint_done(int checkpoint
, int points_earned
);
24 string
e3D_Sprite::spritelist
[MAX_SPRITE_LIMIT
];
25 GLuint
e3D_Sprite::maxsprite
;
26 GLuint
e3D_Sprite::sprite_shadow
;
27 e3D_Checkpoint
e3D_Checkpoint::*checkpointlist
[128];
28 int e3D_Checkpoint::maxcheckpoint
=0;
29 int e3D_Checkpoint::currentpoint
=0;
32 e3D_Sprite::e3D_Sprite(e3D_Object
*parent
, const char *sprite
) : e3D_Object(parent
)
34 // Ship.LoadObj(fileobj,size);
35 // cout << "Create ship:" << fileobj << endl;
36 //matrixidentity(position);
37 //matrixidentity(inverse);
38 //matrixidentity(inverse_orientation);
41 for (i
=1;i
<=this->maxsprite
&& i
<MAX_SPRITE_LIMIT
;i
++)
43 if (this->spritelist
[i
]==sprite
)
46 // cout << "Located sprite " << sprite << " onto " << nsprite << endl;
49 if (!nsprite
) LoadSprite(sprite
);
57 e3D_Sprite::e3D_Sprite(e3D_Object
*parent
, const char *sprite
, double size
, double density
) : e3D_Object(parent
)
62 for (i
=1;i
<=this->maxsprite
&& i
<MAX_SPRITE_LIMIT
;i
++)
64 if (this->spritelist
[i
]==sprite
)
69 if (!nsprite
) LoadSprite(sprite
);
72 init_physics(size
,density
);
75 void e3D_Sprite::LoadShadow(const char *spritefile
)
77 SDL_Surface
*pixsprite
;
78 pixsprite
= IMG_Load(spritefile
);
80 cout
<< "Can't load sprite " << spritefile
<< " onto " << nsprite
<< endl
;
83 // Create MipMapped Texture
85 glGenTextures(1, &texture
);
88 glBindTexture(GL_TEXTURE_2D
, texture
);
89 glTexParameteri(GL_TEXTURE_2D
,GL_TEXTURE_MAG_FILTER
,GL_LINEAR
);
90 glTexParameteri(GL_TEXTURE_2D
,GL_TEXTURE_MIN_FILTER
,GL_LINEAR_MIPMAP_NEAREST
);
91 gluBuild2DMipmaps(GL_TEXTURE_2D
, GL_RGBA
,
92 pixsprite
->w
, pixsprite
->h
, GL_RGBA
, GL_UNSIGNED_BYTE
,
96 sprite_shadow
=texture
;
97 spritelist
[sprite_shadow
]=spritefile
;
98 if (maxsprite
<sprite_shadow
) maxsprite
=sprite_shadow
;
100 cout
<< "Loaded sprite " << spritefile
<< " onto " << texture
<< endl
;
105 void e3D_Sprite::LoadSprite(const char *spritefile
)
107 if (!this->sprite_shadow
)
109 LoadShadow("images/shadow1.png");
111 SDL_Surface
*pixsprite
;
112 pixsprite
= IMG_Load(spritefile
);
114 cout
<< "Can't load sprite " << spritefile
<< " onto " << nsprite
<< endl
;
117 // Create MipMapped Texture
119 glGenTextures(1, &texture
);
122 glBindTexture(GL_TEXTURE_2D
, texture
);
123 glTexParameteri(GL_TEXTURE_2D
,GL_TEXTURE_MAG_FILTER
,GL_LINEAR
);
124 glTexParameteri(GL_TEXTURE_2D
,GL_TEXTURE_MIN_FILTER
,GL_LINEAR_MIPMAP_NEAREST
);
125 gluBuild2DMipmaps(GL_TEXTURE_2D
, GL_RGBA
,
126 pixsprite
->w
, pixsprite
->h
, GL_RGBA
, GL_UNSIGNED_BYTE
,
131 spritelist
[nsprite
]=spritefile
;
132 if (maxsprite
<nsprite
) maxsprite
=nsprite
;
133 if (__E3D_ENGINE_DEBUG
) cout
<< "Loaded sprite " << spritefile
<< " onto " << nsprite
<< endl
;
137 void e3D_Sprite::Draw(int pass
=0)
140 glDisable(GL_LIGHTING
);
142 //glDepthMask(GL_FALSE);
143 // glDepthMask(GL_TRUE);
148 glGetDoublev(GL_MODELVIEW_MATRIX
,M
);
151 glRotated(angle
,0,0,1);
154 glBlendFunc(GL_ONE_MINUS_SRC_ALPHA
,GL_SRC_COLOR
); // Sustractivo
155 glBindTexture(GL_TEXTURE_2D
, sprite_shadow
);
156 glColor4f(1.0f
,1.0f
,1.0f
,1.0f
);
158 glNormal3f( 0.0f
, 0.0f
, -1.0f
);
159 glTexCoord2f(1.0f
, 0.0f
); glVertex3f( 1.0f
, -1.0f
, 0.0f
);
160 glTexCoord2f(1.0f
, 1.0f
); glVertex3f( 1.0f
, 1.0f
, 0.0f
);
161 glTexCoord2f(0.0f
, 1.0f
); glVertex3f(-1.0f
, 1.0f
, 0.0f
);
162 glTexCoord2f(0.0f
, 0.0f
); glVertex3f(-1.0f
, -1.0f
, 0.0f
);
166 glBindTexture(GL_TEXTURE_2D
, nsprite
);
167 glBlendFunc(GL_SRC_ALPHA
,GL_ONE
); // Aditivo
168 //Render->LoadCameraRot(Render->Camera);
171 glNormal3f( 0.0f
, 0.0f
, -1.0f
);
172 glTexCoord2f(1.0f
, 0.0f
); glVertex3f( 1.0f
, -1.0f
, 0.0f
);
173 glTexCoord2f(1.0f
, 1.0f
); glVertex3f( 1.0f
, 1.0f
, 0.0f
);
174 glTexCoord2f(0.0f
, 1.0f
); glVertex3f(-1.0f
, 1.0f
, 0.0f
);
175 glTexCoord2f(0.0f
, 0.0f
); glVertex3f(-1.0f
, -1.0f
, 0.0f
);
183 void e3D_Shoot::Draw(int pass
=0)
186 ApplyGravityForces(Render
->OG_Planets
);
187 if (scale_x
<max_size
)
189 scale_x
*=1+0.02/scale_x
;
190 scale_y
*=1+0.02/scale_y
;
191 scale_z
*=1+0.02/scale_z
;
192 dBodyAddRelForce(body
,0,0,-speed
*(max_size
-scale_x
));
197 AutoDeleteAfterDraw
=1;
201 scale_x
=max_size
*(life
)/3.0;
202 scale_y
=max_size
*(life
)/3.0;
203 scale_z
=max_size
*(life
)/3.0;
205 glBindTexture(GL_TEXTURE_2D
, nsprite
);
206 glDisable(GL_LIGHTING
);
208 glDepthMask(GL_FALSE
);
209 glDisable(GL_ALPHA_TEST
);
211 glBlendFunc(GL_SRC_ALPHA
,GL_ONE
); // Aditivo
216 glGetDoublev(GL_MODELVIEW_MATRIX
,M
);
219 glRotated(angle
,0,0,1);
220 //Render->LoadCameraRot(Render->Camera);
221 //glColor4f(1.0f,1.0f,1.0f,1.0f);
224 glNormal3f( 0.0f
, 0.0f
, -1.0f
);
225 glTexCoord2f(1.0f
, 0.0f
); glVertex3f( 1.0f
, -1.0f
, 0.0f
);
226 glTexCoord2f(1.0f
, 1.0f
); glVertex3f( 1.0f
, 1.0f
, 0.0f
);
227 glTexCoord2f(0.0f
, 1.0f
); glVertex3f(-1.0f
, 1.0f
, 0.0f
);
228 glTexCoord2f(0.0f
, 0.0f
); glVertex3f(-1.0f
, -1.0f
, 0.0f
);
234 void e3D_Checkpoint::Draw(int pass
)
236 e3D_Sprite::Draw(pass
);
237 float d
=1+sin(Render
->App
->total_time
/120.0)/15.0;
238 if (cpoint
!=currentpoint
) d
=1+sin(Render
->App
->total_time
/240.0)/15.0;
240 e3D_Sprite::Draw(pass
);
244 Parent
->GetXYZ(&Ax
,&Ay
,&Az
);
245 Render
->Ship1
->GetXYZ(&Bx
,&By
,&Bz
);
247 double ABx
=Bx
-Ax
,ABy
=By
-Ay
,ABz
=Bz
-Az
;
248 double Rxy
=sqrt(ABx
*ABx
+ABy
*ABy
);
249 double R2
=Rxy
*Rxy
+ABz
*ABz
;
251 if (cpoint
!=currentpoint
&& cpoint
!=currentpoint
-1)
253 this->A
=(this->A
*800+0)/801.0;
254 this->R
=(this->R
*30+1)/31.0;
255 this->G
=(this->G
*60+1)/61.0;
256 this->B
=(this->B
*120+1)/121.0;
260 this->A
=(this->A
*300+1)/301.0;
261 if (cpoint
==currentpoint
)
265 this->R
=(this->R
*100+0)/101.0;
266 this->G
=(this->G
*100+1)/101.0;
267 this->B
=(this->B
*100+0.5)/101.0;
271 this->R
=(this->R
*100+1)/101.0;
272 this->G
=(this->G
*100+2/scale_x
)/101.0;
273 this->B
=(this->B
*100+1/scale_x
)/101.0;
278 this->R
=(this->R
*100+0)/101.0;
279 this->G
=(this->G
*30+.2)/31.0;
280 this->B
=(this->B
*100+1)/101.0;
283 if (this->R
>1) this->R
=1;
284 if (this->G
>1) this->G
=1;
285 if (this->B
>1) this->B
=1;
286 if (this->A
>1) this->A
=1;
289 if (R
/planet_size
<scale_x
) {
290 if (cpoint
==currentpoint
)
293 callback_Checkpoint_onChange(currentpoint
);
295 if (cpoint
>currentpoint
)
297 int score
=sqrt(planet_size
)*50.0*(scale_x
-R
/planet_size
)/(R
/planet_size
);
299 Render
->Ship1
->score
+=score
;
300 if (Render
->Ship1
->used_fuel
<0) Render
->Ship1
->used_fuel
=0;
301 scale_x
=scale_y
=scale_z
=R
/planet_size
;
303 } else if (R
/planet_size
>scale_x
*3 && scale_x
<2 && cpoint
>currentpoint
) {
307 callback_Checkpoint_done(cpoint
, total_score
);
316 e3D_Checkpoint::e3D_Checkpoint(e3D_Object
*parent
) : e3D_Sprite(parent
,"images/escudos.png")
323 planet_size
=Parent
->scale_x
;
324 float max_size
=sqrt(planet_size
)*1;
325 Scale(max_size
,max_size
,max_size
);
326 //checkpointlist[maxcheckpoint]=this;
327 cpoint
=currentpoint
=maxcheckpoint
;