| 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-black-hole.h" |
| 26 |
|
| 27 |
#define SPIRAL_NB_PTS 31 // 1+2*15 |
| 28 |
|
| 29 |
static inline void _calculate_grid (CDIllusionData *pData) |
| 30 |
{ |
| 31 |
double fOmega0 = 2*G_PI*myConfig.fBlackHoleRotationSpeed; |
| 32 |
double r, R = sqrt(2)/2; |
| 33 |
double T = myConfig.iBlackHoleDuration; |
| 34 |
double t = pData->fTime; |
| 35 |
double a = myConfig.iAttraction; |
| 36 |
|
| 37 |
int i, j, n=0; |
| 38 |
CDIllusionBlackHole *pPoint; |
| 39 |
for (j = 0; j < SPIRAL_NB_PTS; j ++) |
| 40 |
{ |
| 41 |
for (i = 0; i < SPIRAL_NB_PTS; i ++) |
| 42 |
{ |
| 43 |
pPoint = &pData->pBlackHolePoints[n]; |
| 44 |
r = pPoint->r0; |
| 45 |
r = pow (r / R, 1 + a*t/T) * R; // effet "trou noir". |
| 46 |
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. |
| 47 |
pPoint->x = r * cos (pPoint->fTheta); |
| 48 |
pPoint->y = - r * sin (pPoint->fTheta); // le (-) est la pour palier a l'inversion de la texture par cairo. |
| 49 |
|
| 50 |
n ++; |
| 51 |
} |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
static inline void _update_coords (CDIllusionData *pData) |
| 56 |
{ |
| 57 |
//g_print ("%s ()\n", __func__); |
| 58 |
int i, j, n=0; // parcours des carre. |
| 59 |
int k, ix, iy; // parcours des coins. |
| 60 |
CDIllusionBlackHole *pPoint; // point de la grille correspondant au coin courant. |
| 61 |
for (j = 0; j < SPIRAL_NB_PTS-1; j ++) |
| 62 |
{ |
| 63 |
for (i = 0; i < SPIRAL_NB_PTS-1; i ++) |
| 64 |
{ |
| 65 |
//g_print (" %d) %d;%d\n", n, i, j); |
| 66 |
for (k = 0; k < 4; k ++) |
| 67 |
{ |
| 68 |
ix = ((k+1)&2)/2; // 0,1,1,0 |
| 69 |
iy = (k&2)/2; // 0,0,1,1 |
| 70 |
|
| 71 |
//g_print (" %d) %d;%d\n", k, ix, iy); |
| 72 |
pPoint = &pData->pBlackHolePoints[(j+iy) * SPIRAL_NB_PTS + (i+ix)]; |
| 73 |
//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)); |
| 74 |
pData->pBlackHoleCoords[2*(4*n+k)] = pPoint->u; |
| 75 |
pData->pBlackHoleCoords[2*(4*n+k)+1] = pPoint->v; |
| 76 |
|
| 77 |
pData->pBlackHoleVertices[2*(4*n+k)] = pPoint->x; |
| 78 |
pData->pBlackHoleVertices[2*(4*n+k)+1] = pPoint->y; |
| 79 |
} |
| 80 |
|
| 81 |
n ++; |
| 82 |
} |
| 83 |
} |
| 84 |
//g_print ("done.\n"); |
| 85 |
} |
| 86 |
|
| 87 |
gboolean cd_illusion_init_black_hole (Icon *pIcon, CairoDock *pDock, CDIllusionData *pData) |
| 88 |
{ |
| 89 |
pData->pBlackHolePoints = g_new0 (CDIllusionBlackHole, SPIRAL_NB_PTS * SPIRAL_NB_PTS); |
| 90 |
pData->pBlackHoleCoords = g_new0 (GLfloat, 8 * (SPIRAL_NB_PTS - 1) * (SPIRAL_NB_PTS - 1)); |
| 91 |
pData->pBlackHoleVertices = g_new0 (GLfloat, 8 * (SPIRAL_NB_PTS - 1) * (SPIRAL_NB_PTS - 1)); |
| 92 |
|
| 93 |
int i, j, n=0; |
| 94 |
double u, v, x, y; |
| 95 |
CDIllusionBlackHole *pPoint; |
| 96 |
for (j = 0; j < SPIRAL_NB_PTS; j ++) // bas -> haut. |
| 97 |
{ |
| 98 |
v = (double) j / SPIRAL_NB_PTS; |
| 99 |
y = v - .5; |
| 100 |
for (i = 0; i < SPIRAL_NB_PTS; i ++) // gauche -> droite. |
| 101 |
{ |
| 102 |
u = (double) i / SPIRAL_NB_PTS; |
| 103 |
x = u - .5; |
| 104 |
|
| 105 |
pPoint = &pData->pBlackHolePoints[n]; // n = j*N+i |
| 106 |
pPoint->u = u; |
| 107 |
pPoint->v = v; |
| 108 |
pPoint->fTheta0 = atan2 (y, x); |
| 109 |
pPoint->r0 = sqrt (x*x + y*y); |
| 110 |
|
| 111 |
n ++; |
| 112 |
} |
| 113 |
} |
| 114 |
|
| 115 |
_calculate_grid (pData); |
| 116 |
|
| 117 |
_update_coords (pData); |
| 118 |
|
| 119 |
return TRUE; |
| 120 |
} |
| 121 |
|
| 122 |
|
| 123 |
void cd_illusion_update_black_hole (Icon *pIcon, CairoDock *pDock, CDIllusionData *pData) |
| 124 |
{ |
| 125 |
_calculate_grid (pData); |
| 126 |
|
| 127 |
_update_coords (pData); |
| 128 |
|
| 129 |
cairo_dock_redraw_container (CAIRO_CONTAINER (pDock)); |
| 130 |
} |
| 131 |
|
| 132 |
//static float fCapsuleObjectPlaneS[4] = { 0.5f, 0., 0., 0. }; // pour un plaquages propre des textures |
| 133 |
//static float fCapsuleObjectPlaneT[4] = { 0., 0.5f, 0., 0. }; // le 2 c'est le 'c'. |
| 134 |
void cd_illusion_draw_black_hole_icon (Icon *pIcon, CairoDock *pDock, CDIllusionData *pData) |
| 135 |
{ |
| 136 |
_cairo_dock_enable_texture (); |
| 137 |
_cairo_dock_set_alpha (pIcon->fAlpha); |
| 138 |
if (pIcon->fAlpha == 1) |
| 139 |
_cairo_dock_set_blend_over (); |
| 140 |
else |
| 141 |
_cairo_dock_set_blend_alpha (); |
| 142 |
glBindTexture(GL_TEXTURE_2D, pIcon->image.iTexture); |
| 143 |
|
| 144 |
glPushMatrix (); |
| 145 |
cairo_dock_set_icon_scale (pIcon, CAIRO_CONTAINER (pDock), 1.); |
| 146 |
|
| 147 |
glEnableClientState (GL_TEXTURE_COORD_ARRAY); |
| 148 |
glEnableClientState (GL_VERTEX_ARRAY); |
| 149 |
|
| 150 |
glTexCoordPointer (2, GL_FLOAT, 2 * sizeof(GLfloat), pData->pBlackHoleCoords); |
| 151 |
glVertexPointer (2, GL_FLOAT, 2 * sizeof(GLfloat), pData->pBlackHoleVertices); |
| 152 |
glDrawArrays (GL_QUADS, 0, 4 * (SPIRAL_NB_PTS - 1) * (SPIRAL_NB_PTS - 1)); |
| 153 |
|
| 154 |
glPopMatrix (); |
| 155 |
|
| 156 |
glDisableClientState (GL_TEXTURE_COORD_ARRAY); |
| 157 |
glDisableClientState (GL_VERTEX_ARRAY); |
| 158 |
_cairo_dock_disable_texture (); |
| 159 |
} |