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/>.
20
/******************************************************************************
22
This file is a part of the cairo-dock program,
23
released under the terms of the GNU General Public License.
25
Written by Fabrice Rey (for any bug report, please mail me to fabounet@users.berlios.de)
27
******************************************************************************/
33
#include "applet-struct.h"
34
#include "applet-black-hole.h"
36
#define SPIRAL_NB_PTS 31 // 1+2*15
38
static inline void _calculate_grid (CDIllusionData *pData)
40
double fOmega0 = 2*G_PI*myConfig.fBlackHoleRotationSpeed;
41
double r, R = sqrt(2)/2;
42
double T = myConfig.iBlackHoleDuration;
43
double t = pData->fTime;
44
double a = myConfig.iAttraction;
47
CDIllusionBlackHole *pPoint;
48
for (j = 0; j < SPIRAL_NB_PTS; j ++)
50
for (i = 0; i < SPIRAL_NB_PTS; i ++)
52
pPoint = &pData->pBlackHolePoints[n];
54
r = pow (r / R, 1 + a*t/T) * R; // effet "trou noir".
55
pPoint->fTheta = pPoint->fTheta0 + fOmega0 * t * 1e-3 * (1 - (r / R) * (1 - .5 * t / T)); // w = w0 - k(t)*r, avec k tel que w(R,0) = 0 et w(R,T) = w0.
56
pPoint->x = r * cos (pPoint->fTheta);
57
pPoint->y = - r * sin (pPoint->fTheta); // le (-) est la pour palier a l'inversion de la texture par cairo.
64
static inline void _update_coords (CDIllusionData *pData)
66
//g_print ("%s ()\n", __func__);
67
int i, j, n=0; // parcours des carre.
68
int k, ix, iy; // parcours des coins.
69
CDIllusionBlackHole *pPoint; // point de la grille correspondant au coin courant.
70
for (j = 0; j < SPIRAL_NB_PTS-1; j ++)
72
for (i = 0; i < SPIRAL_NB_PTS-1; i ++)
74
//g_print (" %d) %d;%d\n", n, i, j);
75
for (k = 0; k < 4; k ++)
77
ix = ((k+1)&2)/2; // 0,1,1,0
78
iy = (k&2)/2; // 0,0,1,1
80
//g_print (" %d) %d;%d\n", k, ix, iy);
81
pPoint = &pData->pBlackHolePoints[(j+iy) * SPIRAL_NB_PTS + (i+ix)];
82
//g_print (" -> point %d/%d, coord %d/%d\n", (j+iy) * SPIRAL_NB_PTS + (i+ix), SPIRAL_NB_PTS * SPIRAL_NB_PTS, 2*(4*n+k)+1, 8 * (SPIRAL_NB_PTS - 1) * (SPIRAL_NB_PTS - 1));
83
pData->pBlackHoleCoords[2*(4*n+k)] = pPoint->u;
84
pData->pBlackHoleCoords[2*(4*n+k)+1] = pPoint->v;
86
pData->pBlackHoleVertices[2*(4*n+k)] = pPoint->x;
87
pData->pBlackHoleVertices[2*(4*n+k)+1] = pPoint->y;
93
//g_print ("done.\n");
96
gboolean cd_illusion_init_black_hole (Icon *pIcon, CairoDock *pDock, CDIllusionData *pData)
98
pData->pBlackHolePoints = g_new0 (CDIllusionBlackHole, SPIRAL_NB_PTS * SPIRAL_NB_PTS);
99
pData->pBlackHoleCoords = g_new0 (GLfloat, 8 * (SPIRAL_NB_PTS - 1) * (SPIRAL_NB_PTS - 1));
100
pData->pBlackHoleVertices = g_new0 (GLfloat, 8 * (SPIRAL_NB_PTS - 1) * (SPIRAL_NB_PTS - 1));
103
double u, v, x, y, r;
104
CDIllusionBlackHole *pPoint;
105
for (j = 0; j < SPIRAL_NB_PTS; j ++) // bas -> haut.
107
v = (double) j / SPIRAL_NB_PTS;
109
for (i = 0; i < SPIRAL_NB_PTS; i ++) // gauche -> droite.
111
u = (double) i / SPIRAL_NB_PTS;
114
pPoint = &pData->pBlackHolePoints[n]; // n = j*N+i
117
pPoint->fTheta0 = atan2 (y, x);
118
pPoint->r0 = sqrt (x*x + y*y);
124
_calculate_grid (pData);
126
_update_coords (pData);
132
void cd_illusion_update_black_hole (Icon *pIcon, CairoDock *pDock, CDIllusionData *pData)
134
_calculate_grid (pData);
136
_update_coords (pData);
138
cairo_dock_redraw_icon (pIcon, pDock);
141
static float fCapsuleObjectPlaneS[4] = { 0.5f, 0., 0., 0. }; // pour un plaquages propre des textures
142
static float fCapsuleObjectPlaneT[4] = { 0., 0.5f, 0., 0. }; // le 2 c'est le 'c'.
143
void cd_illusion_draw_black_hole_icon (Icon *pIcon, CairoDock *pDock, CDIllusionData *pData)
145
_cairo_dock_enable_texture ();
146
_cairo_dock_set_alpha (pIcon->fAlpha);
147
if (pIcon->fAlpha == 1)
148
_cairo_dock_set_blend_over ();
150
_cairo_dock_set_blend_alpha ();
151
glBindTexture(GL_TEXTURE_2D, pIcon->iIconTexture);
154
cairo_dock_set_icon_scale (pIcon, pDock, 1.);
156
glEnableClientState (GL_TEXTURE_COORD_ARRAY);
157
glEnableClientState (GL_VERTEX_ARRAY);
159
glTexCoordPointer (2, GL_FLOAT, 2 * sizeof(GLfloat), pData->pBlackHoleCoords);
160
glVertexPointer (2, GL_FLOAT, 2 * sizeof(GLfloat), pData->pBlackHoleVertices);
161
glDrawArrays (GL_QUADS, 0, 4 * (SPIRAL_NB_PTS - 1) * (SPIRAL_NB_PTS - 1));
165
glDisableClientState (GL_TEXTURE_COORD_ARRAY);
166
glDisableClientState (GL_VERTEX_ARRAY);
167
_cairo_dock_disable_texture ();