~ubuntu-branches/ubuntu/saucy/cairo-dock-plug-ins/saucy

« back to all changes in this revision

Viewing changes to Animated-icons/src/applet-mesh-factory.c

  • Committer: Bazaar Package Importer
  • Author(s): Didier Roche
  • Date: 2009-08-26 21:07:39 UTC
  • Revision ID: james.westby@ubuntu.com-20090826210739-gyjuuqezrzuluao4
Tags: upstream-2.0.8.1
ImportĀ upstreamĀ versionĀ 2.0.8.1

Show diffs side-by-side

added added

removed removed

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