Debian Codegraph @

illusion/src/applet-explode.c

raw
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-explode.h"
26
27 static double vmax = .4;
28
29 #define _update_explosion(pData)\
30 double f = pData->fTime / myConfig.iExplodeDuration;\
31 pData->fExplosionRadius = (1 + myConfig.fExplosionRadius * f);\
32 pData->fExplosionRotation = 360. * f;\
33 pData->fExplodeAlpha = MAX (0., 1 - f);
34
35 gboolean cd_illusion_init_explode (Icon *pIcon, CairoDock *pDock, CDIllusionData *pData)
36 {
37 _update_explosion (pData);
38
39 pData->pExplosionPart = g_new0 (CDIllusionExplosion, myConfig.iExplodeNbPiecesX * myConfig.iExplodeNbPiecesY);
40 CDIllusionExplosion *pPart;
41 double v;
42 int i, j;
43 for (i = 0; i < myConfig.iExplodeNbPiecesX; i ++)
44 {
45 for (j = 0; j < myConfig.iExplodeNbPiecesY; j ++)
46 {
47 pPart = &pData->pExplosionPart[i*myConfig.iExplodeNbPiecesY+j];
48 pPart->fRotationSpeed = 2 * g_random_double (); // au plus 2 tours sur lui-meme.
49 pPart->vz = vmax * (2 * g_random_double () - 1);
50 v = sqrt (1 - pPart->vz * pPart->vz);
51 pPart->vx = v * (1 + .2 * (2 * g_random_double () - 1)) * sqrt (2)/2;
52 pPart->vy = sqrt (1 - pPart->vx * pPart->vx);
53 }
54 }
55
56 return TRUE;
57 }
58
59
60 void cd_illusion_update_explode (Icon *pIcon, CairoDock *pDock, CDIllusionData *pData)
61 {
62 _update_explosion (pData);
63
64 /*GdkRectangle area;
65 if (pDock->bIsHorizontal)
66 {
67 area.x = pIcon->fDrawX + (.5 - pData->fExplosionRadius/2) * pIcon->fWidth * pIcon->fScale;
68 area.y = MAX (0, pIcon->fDrawY + (.5 - pData->fExplosionRadius/2) * pIcon->fHeight * pIcon->fScale);
69 area.width = pData->fExplosionRadius * pIcon->fWidth * pIcon->fScale * 1;
70 area.height = pData->fExplosionRadius * pIcon->fHeight * pIcon->fScale * 1;
71 }
72 else
73 {
74 area.y = pIcon->fDrawX + (.5 - pData->fExplosionRadius/2) * pIcon->fWidth * pIcon->fScale;
75 area.x = MAX (0, pIcon->fDrawY + (.5 - pData->fExplosionRadius/2) * pIcon->fHeight * pIcon->fScale);
76 area.height = pData->fExplosionRadius * pIcon->fWidth * pIcon->fScale * 1;
77 area.width = pData->fExplosionRadius * pIcon->fHeight * pIcon->fScale * 1;
78 }
79 cairo_dock_redraw_container_area (CAIRO_CONTAINER (pDock), &area);*/
80 cairo_dock_redraw_container (CAIRO_CONTAINER (pDock));
81 }
82
83 void cd_illusion_draw_explode_icon (Icon *pIcon, CairoDock *pDock, CDIllusionData *pData)
84 {
85 if (pData->fExplodeAlpha == 0)
86 return ;
87
88 _cairo_dock_enable_texture ();
89 _cairo_dock_set_blend_alpha ();
90 _cairo_dock_set_alpha (pData->fExplodeAlpha);
91 glBindTexture (GL_TEXTURE_2D, pIcon->image.iTexture);
92 if (myConfig.bExplodeCube)
93 {
94 glEnable(GL_DEPTH_TEST);
95 }
96 else
97 {
98 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
99 }
100
101 double fWidth = pIcon->fWidth * pIcon->fScale;
102 double fHeight = pIcon->fHeight * pIcon->fScale;
103 double dTexCoordX = 1. / myConfig.iExplodeNbPiecesX;
104 double dTexCoordY = 1. / myConfig.iExplodeNbPiecesY;
105 double x, y, z=0, u, v, u_, v_, angle;
106 CDIllusionExplosion *pPart;
107 double a = .5;
108 int i, j;
109 for (i = 0; i < myConfig.iExplodeNbPiecesX; i ++)
110 {
111 for (j = 0; j < myConfig.iExplodeNbPiecesY; j ++)
112 {
113 pPart = &pData->pExplosionPart[i*myConfig.iExplodeNbPiecesY+j];
114
115 u = i * dTexCoordX;
116 v = j * dTexCoordY;
117 u_ = u + dTexCoordX;
118 v_ = v + dTexCoordY;
119 x = pData->fExplosionRadius * (u - .5 + dTexCoordX/2) * pPart->vx;
120 y = pData->fExplosionRadius * (.5 - v - dTexCoordY/2) * pPart->vy;
121 z = .5 * (pData->fExplosionRadius - 1) * pPart->vz;
122 angle = pPart->fRotationSpeed * pData->fExplosionRotation;
123 glPushMatrix ();
124
125 glTranslatef (x * fWidth, y * fHeight, 0.);
126 glRotatef (angle, 0., 1., 0.);
127 glRotatef (angle, 1., 0., 0.);
128 glScalef (fWidth / myConfig.iExplodeNbPiecesX * (1 + z), fHeight / myConfig.iExplodeNbPiecesY * (1 + z), fHeight / myConfig.iExplodeNbPiecesY * (1 + z));
129
130 glBegin(GL_QUADS);
131 if (myConfig.bExplodeCube)
132 {
133 glNormal3f(0,0,1);
134 glTexCoord2f (u, v); glVertex3f(-a, a, a); // Bottom Left Of The Texture and Quad
135 glTexCoord2f (u_, v); glVertex3f( a, a, a); // Bottom Right Of The Texture and Quad
136 glTexCoord2f (u_, v_); glVertex3f( a, -a, a); // Top Right Of The Texture and Quad
137 glTexCoord2f (u, v_); glVertex3f(-a, -a, a); // Top Left Of The Texture and Quad
138 // Back Face
139 glNormal3f(0,0,-1);
140 glTexCoord2f (u_, v); glVertex3f( -a, a, -a); // Bottom Right Of The Texture and Quad
141 glTexCoord2f (u_, v_); glVertex3f( -a, -a, -a); // Top Right Of The Texture and Quad
142 glTexCoord2f (u, v_); glVertex3f(a, -a, -a); // Top Left Of The Texture and Quad
143 glTexCoord2f (u, v); glVertex3f(a, a, -a); // Bottom Left Of The Texture and Quad
144 // Top Face
145 glNormal3f(0,1,0);
146 glTexCoord2f (u, v_); glVertex3f(-a, a, a); // Top Left Of The Texture and Quad
147 glTexCoord2f (u, v); glVertex3f(-a, a, -a); // Bottom Left Of The Texture and Quad
148 glTexCoord2f (u_, v); glVertex3f( a, a, -a); // Bottom Right Of The Texture and Quad
149 glTexCoord2f (u_, v_); glVertex3f( a, a, a); // Top Right Of The Texture and Quad
150 // Bottom Face
151 glNormal3f(0,-1,0);
152 glTexCoord2f (u_, v_); glVertex3f( a, -a, -a); // Top Right Of The Texture and Quad
153 glTexCoord2f (u, v_); glVertex3f(-a, -a, -a); // Top Left Of The Texture and Quad
154 glTexCoord2f (u, v); glVertex3f(-a, -a, a); // Bottom Left Of The Texture and Quad
155 glTexCoord2f (u_, v); glVertex3f( a, -a, a); // Bottom Right Of The Texture and Quad
156 // Right face
157 glNormal3f(1,0,0);
158 glTexCoord2f (u_, v); glVertex3f( a, a, -a); // Bottom Right Of The Texture and Quad
159 glTexCoord2f (u_, v_); glVertex3f( a, -a, -a); // Top Right Of The Texture and Quad
160 glTexCoord2f (u, v_); glVertex3f( a, -a, a); // Top Left Of The Texture and Quad
161 glTexCoord2f (u, v); glVertex3f( a, a, a); // Bottom Left Of The Texture and Quad
162 // Left Face
163 glNormal3f(-1,0,0);
164 glTexCoord2f (u, v); glVertex3f(-a, a, -a); // Bottom Left Of The Texture and Quad
165 glTexCoord2f (u_, v); glVertex3f(-a, a, a); // Bottom Right Of The Texture and Quad
166 glTexCoord2f (u_, v_); glVertex3f(-a, -a, a); // Top Right Of The Texture and Quad
167 glTexCoord2f (u, v_); glVertex3f(-a, -a, -a); // Top Left Of The Texture and Quad
168 }
169 else
170 {
171 glNormal3f(0,0,1);
172 glTexCoord2f (u, v); glVertex3f(-a, a, 0.); // Bottom Left Of The Texture and Quad
173 glTexCoord2f (u_, v); glVertex3f( a, a, 0.); // Bottom Right Of The Texture and Quad
174 glTexCoord2f (u_, v_); glVertex3f( a, -a, 0.); // Top Right Of The Texture and Quad
175 glTexCoord2f (u, v_); glVertex3f(-a, -a, 0.); // Top Left Of The Texture and Quad
176 }
177 glEnd();
178
179 glPopMatrix ();
180 }
181 }
182 _cairo_dock_disable_texture ();
183 glDisable (GL_DEPTH_TEST);
184 }