1 /**
2 * This file is a part of the Cairo-Dock project
3 *
4 * Copyright : (C) see the 'copyright' file.
5 * E-mail    : see the 'copyright' file.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 3
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #include <stdlib.h>
21 #include <string.h>
22 #include <math.h>
23 
24 #include "applet-struct.h"
25 #include "applet-mesh-factory.h"
26 
27 #define RADIAN (G_PI / 180.0)  // Conversion Radian/Degres
28 
cairo_dock_load_capsule_calllist(void)29 GLuint cairo_dock_load_capsule_calllist (void)
30 {
31 	GLuint iCallList = glGenLists (1);
32 	int        deg, deg2, iter, nb_iter=20;
33 	float        amp, rayon, c=2.;
34 
35 	rayon        = 1.0f/c;
36 	amp        = 90.0 / nb_iter;
37 	deg2        = 0;
38 
39 	glNewList(iCallList, GL_COMPILE); // Go pour la compilation de la display list
40 	glPolygonMode (GL_FRONT, GL_FILL);
41 
42 	/**glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR ); // ok la on selectionne le type de generation des coordonnees de la texture
43 	glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR );
44 	glTexGenfv(GL_S, GL_OBJECT_PLANE, fCapsuleObjectPlaneS); // On place la texture correctement en X
45 	glTexGenfv(GL_T, GL_OBJECT_PLANE, fCapsuleObjectPlaneT); // Et en Y
46 	glEnable(GL_TEXTURE_GEN_S);                // oui je veux une generation en S
47 	glEnable(GL_TEXTURE_GEN_T);                // Et en T aussi
48 
49 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);  // pour les bouts de textures qui depassent.
50 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);*/
51 
52 	glMatrixMode(GL_TEXTURE); // On selectionne la matrice des textures
53 	glPushMatrix ();
54 	glLoadIdentity(); // On la reset
55 	glTranslatef(0.5f, 0.5f, 0.); // Et on decale la texture pour un affiche propre
56 	glRotatef (180, 1, 0, 0);  // sinon les icones sont a l'envers.
57 	glMatrixMode(GL_MODELVIEW); // On revient sur la matrice d'affichage
58 
59 	// bon la je commente pas on fait juste une demi sphere applatie
60 	double a = .5/c;  // applatissement;
61 	double b = 1./nb_iter;
62 	double xab, yab, zab, xac, yac, zac, nx, ny, nz, n;
63 
64 	glBegin(GL_QUADS);
65 	for (iter = 0;iter < nb_iter-1;iter ++)
66 	{
67 		for (deg = 0;deg < 360;deg += 10)
68 		{
69 			xab = b * cos(deg*RADIAN);
70 			yab = b * sin(deg*RADIAN);
71 			zab = a * sin(deg2*RADIAN) - a * sin((deg2+amp)*RADIAN);
72 			//zab = a*cos (deg2*RADIAN) * amp*RADIAN;
73 			xac = rayon * cos((deg+10)*RADIAN) - (rayon-b) * cos(deg*RADIAN);
74 			yac = rayon * sin((deg+10)*RADIAN) - (rayon-b) * sin(deg*RADIAN);
75 			zac = a * sin(deg2*RADIAN) - a * sin((deg2+amp)*RADIAN);
76 			//zac = a * sin((deg2+amp)*RADIAN) - a * sin(deg2*RADIAN);
77 			nx = yab*zac - zab*yac;
78 			ny = zab*xac - xab*zac;
79 			nz = xab*yac - yab*xac;
80 			n = sqrt (nx*nx + ny*ny + nz*nz);
81 
82 			glNormal3f (nx/n, ny/n, nz/n);
83 
84 			glVertex3f((rayon-b) * cos(deg*RADIAN),
85 				(rayon-b) * sin(deg*RADIAN),
86 				a * sin((deg2+amp)*RADIAN) + 0.1f/c);
87 			glVertex3f(rayon * cos(deg*RADIAN),
88 				rayon * sin(deg*RADIAN),
89 				a * sin(deg2*RADIAN) + 0.1f/c);
90 			glVertex3f(rayon * cos((deg+10)*RADIAN),
91 				rayon * sin((deg+10)*RADIAN),
92 				a * sin(deg2*RADIAN) + 0.1f/c);
93 			glVertex3f((rayon-b) * cos((deg+10)*RADIAN),
94 				(rayon-b) * sin((deg+10)*RADIAN),
95 				a * sin((deg2+amp)*RADIAN) + 0.1f/c);
96 
97 			//nx = - nx;
98 			//ny = - ny;
99 			nz = - nz;
100 
101 			glNormal3f (nx/n, ny/n, nz/n);
102 			glVertex3f((rayon-b) * cos(deg*RADIAN),
103 				 (rayon-b) * sin(deg*RADIAN),
104 				-a * sin((deg2+amp)*RADIAN) - 0.1f/c);
105 			glVertex3f(rayon * cos(deg*RADIAN),
106 				 rayon * sin(deg*RADIAN),
107 				-a * sin(deg2*RADIAN) - 0.1f/c);
108 			glVertex3f(rayon * cos((deg+10)*RADIAN),
109 				 rayon * sin((deg+10)*RADIAN),
110 				-a * sin(deg2*RADIAN) - 0.1f/c);
111 			glVertex3f((rayon-b) * cos((deg+10)*RADIAN),
112 				 (rayon-b) * sin((deg+10)*RADIAN),
113 				-a * sin((deg2+amp)*RADIAN) - 0.1f/c);
114 		}
115 		rayon    -= b/c;
116 		deg2    += amp;
117 	}
118 	glEnd();
119 
120 	glMatrixMode(GL_TEXTURE); // On selectionne la matrice des textures
121 	glPopMatrix ();
122 	glMatrixMode(GL_MODELVIEW); // On revient sur la matrice d'affichage
123 
124 	// Ici c'est pour faire le cylindre qui relie les demi spheres
125 	glEnable(GL_TEXTURE_2D);
126 	glColor4f(1.0f, 1.0f, 1.0f, 1.0f); // Couleur a fond
127 	//GLfloat fMaterial[4] = {1., 1., 1., 1.};
128 	//glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, fMaterial);  // on definit Les proprietes materielles de l'objet.
129 	cd_debug ("iChromeTexture : %d", myData.iChromeTexture);
130 
131 	/*glBindTexture(GL_TEXTURE_2D, myData.iChromeTexture);
132 	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT); // Ici c'est pour le type de combinaison de texturing en cas de multi
133 	glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_REPLACE); // pas de multi je remplace donc l'ancienne texture par celle ci
134 
135 	glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); // ok la on selectionne le type de generation des coordonnees de la texture
136 	glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); // Ce sera du sphere mapping pour un petit effet chrome
137 	glEnable(GL_TEXTURE_GEN_S); // oui je veux une generation en S
138 	glEnable(GL_TEXTURE_GEN_T); // Et en T aussi
139 	*/
140 
141 	glActiveTexture(GL_TEXTURE1);
142 	glDisable(GL_TEXTURE_2D);
143 	glDisable(GL_TEXTURE_GEN_S);
144 	glDisable(GL_TEXTURE_GEN_T);
145 	glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE, 1.);
146 	glActiveTexture(GL_TEXTURE0);
147 	glDisable(GL_TEXTURE_2D);
148 	glDisable(GL_TEXTURE_GEN_S);
149 	glDisable(GL_TEXTURE_GEN_T);
150 
151 	glColor4f (.4, .5, .8, .7);
152 	rayon = 1.0f/c;
153 	glBegin(GL_QUADS);
154 	//for (iter = 0;iter < 5;iter ++)
155 	{
156 		for (deg = 0;deg < 360;deg += 10)
157 		{
158 			xab = rayon * sin((deg+10)*RADIAN) - rayon * sin(deg*RADIAN);
159 			yab = rayon * cos((deg+10)*RADIAN) - rayon * cos(deg*RADIAN);
160 			zab = 0.;
161 			xac = xab;
162 			yac = yab;
163 			zac = -0.2/c;
164 
165 			nx = yab*zac - zab*yac;
166 			ny = zab*xac - xab*zac;
167 			nz = xab*yac - yab*xac;
168 			n = sqrt (nx*nx + ny*ny + nz*nz);
169 
170 			glNormal3f (nx/n, ny/n,
171 			nz/n);
172 
173 			glVertex3f(rayon * sin(deg*RADIAN), rayon * cos(deg*RADIAN), 0.1f/c);
174 			glVertex3f(rayon * sin((deg+10)*RADIAN), rayon * cos((deg+10)*RADIAN), 0.1f/c);
175 			glVertex3f(rayon * sin((deg+10)*RADIAN), rayon * cos((deg+10)*RADIAN), -0.1f/c);
176 			glVertex3f(rayon * sin(deg*RADIAN), rayon * cos(deg*RADIAN), -0.1f/c);
177 
178 		}
179 
180 		rayon -= 0.2f/c;
181 		deg2 += amp;
182 	}
183 	glEnd();
184 
185 	glEndList(); // Fini la display list
186 
187 	/**glDisable(GL_TEXTURE_GEN_S);
188 	glDisable(GL_TEXTURE_GEN_T);
189 	glDisable(GL_TEXTURE_2D); // Plus de texture merci
190 	glDisable(GL_TEXTURE);*/
191 
192 	return iCallList;
193 }
194 
cairo_dock_load_ring_calllist(void)195 GLuint cairo_dock_load_ring_calllist (void)
196 {
197 	GLuint iCallList = glGenLists (1);
198 	int        deg, deg2, nb_iter=20;
199 	float        amp, rayon, c=2.;
200 
201 	rayon        = 1.0f/c;
202 	amp        = 90.0 / nb_iter;
203 	deg2        = 0;
204 
205 	glNewList(iCallList, GL_COMPILE); // Go pour la compilation de la display list
206 	glPolygonMode (GL_FRONT, GL_FILL);
207 	//double a = .4/c;  // applatissement;
208 	//double b = 1./nb_iter;
209 	double xab, yab, zab, xac, yac, zac, nx, ny, nz, n;
210 
211 	glColor4f (.4, .5, .8, .7);
212 
213 	rayon = 1.0f/c;
214 	glBegin(GL_QUADS);
215 	//for (iter = 0;iter < 5;iter ++)
216 	{
217 		for (deg = 0;deg < 360;deg += 10)
218 		{
219 			xab = rayon * sin((deg+10)*RADIAN) - rayon * sin(deg*RADIAN);
220 			yab = rayon * cos((deg+10)*RADIAN) - rayon * cos(deg*RADIAN);
221 			zab = 0.;
222 			xac = xab;
223 			yac = yab;
224 			zac = -0.2/c;
225 
226 			nx = yab*zac - zab*yac;
227 			ny = zab*xac - xab*zac;
228 			nz = xab*yac - yab*xac;
229 			n = sqrt (nx*nx + ny*ny + nz*nz);
230 
231 			glNormal3f (nx/n, ny/n, nz/n);
232 
233 			glVertex3f(rayon * sin(deg*RADIAN), rayon * cos(deg*RADIAN), 0.1f/c);
234 			glVertex3f(rayon * sin((deg+10)*RADIAN), rayon * cos((deg+10)*RADIAN), 0.1f/c);
235 			glVertex3f(rayon * sin((deg+10)*RADIAN), rayon * cos((deg+10)*RADIAN), -0.1f/c);
236 			glVertex3f(rayon * sin(deg*RADIAN), rayon * cos(deg*RADIAN), -0.1f/c);
237 
238 		}
239 
240 		rayon -= 0.2f/c;
241 		deg2 += amp;
242 	}
243 	glEnd();
244 
245 	glEndList(); // Fini la display list
246 	return iCallList;
247 }
248 
249 
cairo_dock_load_square_calllist(void)250 GLuint cairo_dock_load_square_calllist (void)
251 {
252 	GLuint iCallList = glGenLists (1);
253 	glNewList(iCallList, GL_COMPILE); // Go pour la compilation de la display list
254 	glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
255 
256 	glNormal3f(0,0,1);
257 	glBegin(GL_QUADS);
258 	glMultiTexCoord2f( GL_TEXTURE1_ARB,0., 0.); glVertex3f(-.5,  .5, 0.);  // Bottom Left Of The Texture and Quad
259 	glMultiTexCoord2f( GL_TEXTURE1_ARB,1., 0.); glVertex3f( .5,  .5, 0.);  // Bottom Right Of The Texture and Quad
260 	glMultiTexCoord2f( GL_TEXTURE1_ARB,1., 1.); glVertex3f( .5, -.5, 0.);  // Top Right Of The Texture and Quad
261 	glMultiTexCoord2f( GL_TEXTURE1_ARB,0., 1.); glVertex3f(-.5, -.5, 0.);  // Top Left Of The Texture and Quad
262 	glEnd();
263 
264 	glEndList(); // Fini la display list
265 	return iCallList;
266 }
267 
cairo_dock_load_cube_calllist(void)268 GLuint cairo_dock_load_cube_calllist (void)
269 {
270 	GLuint iCallList = glGenLists (1);
271 	glNewList(iCallList, GL_COMPILE); // Go pour la compilation de la display list
272 	glPolygonMode (GL_FRONT, GL_FILL);
273 
274 	double a = .5 / sqrt (2.5);  // approximation de la distance max au centre du cube de la projection sur le plan de l'ecran d'un des coins, sachant que phi = teta/4.
275 	glBegin(GL_QUADS);
276 	// Front Face (note that the texture's corners have to match the quad's corners)
277 	glNormal3f(0,0,1);
278 	glMultiTexCoord2f( GL_TEXTURE1_ARB,0., 0.); glVertex3f(-a,  a,  a);  // Bottom Left Of The Texture and Quad
279 	glMultiTexCoord2f( GL_TEXTURE1_ARB,1., 0.); glVertex3f( a,  a,  a);  // Bottom Right Of The Texture and Quad
280 	glMultiTexCoord2f( GL_TEXTURE1_ARB,1., 1.); glVertex3f( a, -a,  a);  // Top Right Of The Texture and Quad
281 	glMultiTexCoord2f( GL_TEXTURE1_ARB,0., 1.); glVertex3f(-a, -a,  a);  // Top Left Of The Texture and Quad
282 	// Back Face
283 	glNormal3f(0,0,-1);
284 	glMultiTexCoord2f( GL_TEXTURE1_ARB,1., 0.); glVertex3f( -a, a, -a);  // Bottom Right Of The Texture and Quad
285 	glMultiTexCoord2f( GL_TEXTURE1_ARB,1., 1.); glVertex3f( -a, -a, -a);  // Top Right Of The Texture and Quad
286 	glMultiTexCoord2f( GL_TEXTURE1_ARB,0., 1.); glVertex3f(a, -a, -a);  // Top Left Of The Texture and Quad
287 	glMultiTexCoord2f( GL_TEXTURE1_ARB,0., 0.); glVertex3f(a, a, -a);  // Bottom Left Of The Texture and Quad
288 	// Top Face
289 	glNormal3f(0,1,0);
290 	glMultiTexCoord2f( GL_TEXTURE1_ARB,0., 1.); glVertex3f(-a,  a,  a);  // Top Left Of The Texture and Quad
291 	glMultiTexCoord2f( GL_TEXTURE1_ARB,0., 0.); glVertex3f(-a,  a, -a);  // Bottom Left Of The Texture and Quad
292 	glMultiTexCoord2f( GL_TEXTURE1_ARB,1., 0.); glVertex3f( a,  a, -a);  // Bottom Right Of The Texture and Quad
293 	glMultiTexCoord2f( GL_TEXTURE1_ARB,1., 1.); glVertex3f( a,  a,  a);  // Top Right Of The Texture and Quad
294 	// Bottom Face
295 	glNormal3f(0,-1,0);
296 	glMultiTexCoord2f( GL_TEXTURE1_ARB,1., 1.); glVertex3f( a, -a, -a);  // Top Right Of The Texture and Quad
297 	glMultiTexCoord2f( GL_TEXTURE1_ARB,0., 1.); glVertex3f(-a, -a, -a);  // Top Left Of The Texture and Quad
298 	glMultiTexCoord2f( GL_TEXTURE1_ARB,0., 0.); glVertex3f(-a, -a,  a);  // Bottom Left Of The Texture and Quad
299 	glMultiTexCoord2f( GL_TEXTURE1_ARB,1., 0.); glVertex3f( a, -a,  a);  // Bottom Right Of The Texture and Quad
300 	// Right face
301 	glNormal3f(1,0,0);
302 	glMultiTexCoord2f( GL_TEXTURE1_ARB,1., 0.);  glVertex3f( a,  a, -a);  // Bottom Right Of The Texture and Quad
303 	glMultiTexCoord2f( GL_TEXTURE1_ARB,1., 1.);  glVertex3f( a, -a, -a);  // Top Right Of The Texture and Quad
304 	glMultiTexCoord2f( GL_TEXTURE1_ARB,0., 1.);  glVertex3f( a, -a,  a);  // Top Left Of The Texture and Quad
305 	glMultiTexCoord2f( GL_TEXTURE1_ARB,0., 0.);  glVertex3f( a,  a,  a);  // Bottom Left Of The Texture and Quad
306 	// Left Face
307 	glNormal3f(-1,0,0);
308 	glMultiTexCoord2f( GL_TEXTURE1_ARB,0., 0.);  glVertex3f(-a,  a, -a);  // Bottom Left Of The Texture and Quad
309 	glMultiTexCoord2f( GL_TEXTURE1_ARB,1., 0.);  glVertex3f(-a,  a,  a);  // Bottom Right Of The Texture and Quad
310 	glMultiTexCoord2f( GL_TEXTURE1_ARB,1., 1.);  glVertex3f(-a, -a,  a);  // Top Right Of The Texture and Quad
311 	glMultiTexCoord2f( GL_TEXTURE1_ARB,0., 1.);  glVertex3f(-a, -a, -a);  // Top Left Of The Texture and Quad
312 	glEnd();
313 
314 	glEndList(); // Fini la display list
315 	return iCallList;
316 }
317 
318 
cd_animations_load_mesh(CDAnimationsMeshType iMeshType)319 GLuint cd_animations_load_mesh (CDAnimationsMeshType iMeshType)
320 {
321 	GLuint iCallList = 0;
322 	switch (iMeshType)
323 	{
324 		case CD_SQUARE_MESH :
325 			iCallList = cairo_dock_load_square_calllist ();
326 		break ;
327 
328 		case CD_CUBE_MESH :
329 			iCallList = cairo_dock_load_cube_calllist ();
330 		break ;
331 
332 		case CD_CAPSULE_MESH :
333 			iCallList = cairo_dock_load_capsule_calllist ();
334 		break ;
335 		case CD_ANIMATIONS_NB_MESH :
336 		break;
337 	}
338 	return iCallList;
339 }
340