2
* This file is a part of the Cairo-Dock project
4
* Copyright : (C) see the 'copyright' file.
5
* E-mail : see the 'copyright' file.
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.
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/>.
24
#include "applet-struct.h"
25
#include "applet-break.h"
27
#define xctrl(j) pCtrlPoints[2*(j)]
28
#define yctrl(j) pCtrlPoints[2*(j)+1]
29
#define xpart(j) pPart->pCoords[2*(j)]
30
#define ypart(j) pPart->pCoords[2*(j)+1]
32
gboolean cd_illusion_init_break (Icon *pIcon, CairoDock *pDock, CDIllusionData *pData)
34
int iNbCtrlPts = 4 + (2 * myConfig.iBreakNbBorderPoints) + (2 * myConfig.iBreakNbBorderPoints + 1);
35
double *pCtrlPoints = g_new0 (double, 2 * iNbCtrlPts);
36
//g_print ("iNbCtrlPts : %d\n", iNbCtrlPts);
41
double f, f0 = 1. / (myConfig.iBreakNbBorderPoints + 1); // f0 = fraction moyenne.
43
for (i = 0; i < 2*myConfig.iBreakNbBorderPoints+1; i ++, j++)
45
// un nouveau point sur l'un des cotes.
46
if (i == 2*myConfig.iBreakNbBorderPoints) // dernier coup.
49
f = f0 * (.5 + g_random_double ()); // entre .5f0 et 1.5f0, sachant que 1.5f0 <= 3/4 < 1
50
xctrl(j) = ((j>>1) & 1);
51
yctrl(j) = (1 - f) * (j > 3 ? yctrl(j-4) : yctrl(0));
52
//g_print ("yctrl(j) : %.3f (%.2f)\n", yctrl(j), f);
54
// une brisure au milieu du segment forme.
56
f = g_random_double ();
58
yctrl(j) = f * yctrl(j-1) + (1 - f) * yctrl(j-2);
60
xctrl(j) = ((j>>2) & 1); // en fait c'est toujours egal a 0.
63
pData->iNbBreakParts = 2 + (2 * myConfig.iBreakNbBorderPoints + 1);
64
pData->pBreakPart = g_new0 (CDIllusionBreak, pData->iNbBreakParts);
65
CDIllusionBreak *pPart;
66
for (i = 0; i < pData->iNbBreakParts; i ++)
68
pPart = &pData->pBreakPart[i];
89
else if (i == pData->iNbBreakParts - 1)
92
xpart(0) = xctrl(iNbCtrlPts-3);
93
ypart(0) = yctrl(iNbCtrlPts-3);
94
xpart(1) = xctrl(iNbCtrlPts-2);
95
ypart(1) = yctrl(iNbCtrlPts-2);
96
xpart(2) = xctrl(iNbCtrlPts-1);
97
ypart(2) = yctrl(iNbCtrlPts-1);
102
xpart(0) = xctrl(2*(i-1));
103
ypart(0) = yctrl(2*(i-1));
104
xpart(1) = xctrl(2*(i-1)+1);
105
ypart(1) = yctrl(2*(i-1)+1);
106
xpart(2) = xctrl(2*(i-1)+3);
107
ypart(2) = yctrl(2*(i-1)+3);
108
xpart(3) = xctrl(2*(i-1)+4);
109
ypart(3) = yctrl(2*(i-1)+4);
112
pPart->yinf = MIN (MIN (ypart(0), ypart(1)), ypart(2));
113
if (pPart->iNbPts == 4)
114
pPart->yinf = MIN (pPart->yinf, ypart(3));
115
pPart->fCrackAngle = 5 + g_random_double () * 15.; // ca separe un peu les morceaux, pour donner l'effet de brisure des le debut.
116
pPart->fRotationAngle = (pData->sens == 1 ? pPart->fCrackAngle : 91);
123
void cd_illusion_update_break (Icon *pIcon, CairoDock *pDock, CDIllusionData *pData)
126
cairo_dock_get_icon_extent (pIcon, &iWidth, &iHeight);
127
double fSizeX, fSizeY;
128
cairo_dock_get_current_icon_size (pIcon, CAIRO_CONTAINER (pDock), &fSizeX, &fSizeY);
130
double t_ = (pData->fTime / myConfig.iBreakDuration); // t/T
131
pData->dh = t_ * t_; // dh = 1/2 * g * t^2, avec g = 2/T^2 (hauteur comptee unitairement).
133
CDIllusionBreak *pPart;
135
for (i = 0; i < pData->iNbBreakParts; i ++)
137
pPart = &pData->pBreakPart[i];
138
if (pPart->yinf - pData->dh < 0) // on a touche le sol.
140
pPart->fRotationAngle += pData->sens * pData->fDeltaT / (.25 * myConfig.iBreakDuration) * 90.; // formule faite a la va-vite, avec une acceleration ca serait mieux ...
141
if (pPart->fRotationAngle < pPart->fCrackAngle)
142
pPart->fRotationAngle = pPart->fCrackAngle;
146
cairo_dock_redraw_container (CAIRO_CONTAINER (pDock));
149
void cd_illusion_draw_break_icon (Icon *pIcon, CairoDock *pDock, CDIllusionData *pData)
151
_cairo_dock_enable_texture ();
152
_cairo_dock_set_blend_alpha ();
153
_cairo_dock_set_alpha (1.);
154
glBindTexture (GL_TEXTURE_2D, pIcon->image.iTexture);
156
double fSizeX, fSizeY;
157
cairo_dock_get_current_icon_size (pIcon, CAIRO_CONTAINER (pDock), &fSizeX, &fSizeY);
160
glTranslatef (-fSizeX/2, -fSizeY/2, 0.);
161
glMatrixMode(GL_TEXTURE); // On selectionne la matrice des textures
163
glLoadIdentity(); // On la reset
164
glScalef (1., -1., 1.);
165
glMatrixMode(GL_MODELVIEW);
167
CDIllusionBreak *pPart;
168
double xt, yt; // coordonnees d'un point de texture
169
double x, y; // coordonnees du vertex associe.
170
double dh = pData->dh;
172
for (i = 0; i < pData->iNbBreakParts; i ++)
174
pPart = &pData->pBreakPart[i];
175
if (pPart->fRotationAngle > 90) // il est a plat par terre, on ne le voit plus.
178
if (pPart->fRotationAngle != 0)
181
glRotatef (pPart->fRotationAngle, 1., 0., 0.);
184
if (pPart->iNbPts == 3)
185
glBegin(GL_TRIANGLES);
189
for (j = 0; j < pPart->iNbPts; j ++)
195
if (dh > pPart->yinf)
196
y = (yt - pPart->yinf) * fSizeY;
198
y = (yt - dh) * fSizeY;
200
glTexCoord2f (xt, yt);
201
glVertex3f (x, y, 0.);
206
if (pPart->fRotationAngle != 0)
213
glMatrixMode(GL_TEXTURE); // On selectionne la matrice des textures
215
glMatrixMode(GL_MODELVIEW);
216
_cairo_dock_disable_texture ();