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

« back to all changes in this revision

Viewing changes to illusion/src/applet-black-hole.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-black-hole.h"
 
35
 
 
36
#define SPIRAL_NB_PTS 31  // 1+2*15
 
37
 
 
38
static inline void _calculate_grid (CDIllusionData *pData)
 
39
{
 
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;
 
45
        
 
46
        int i, j, n=0;
 
47
        CDIllusionBlackHole *pPoint;
 
48
        for (j = 0; j < SPIRAL_NB_PTS; j ++)
 
49
        {
 
50
                for (i = 0; i < SPIRAL_NB_PTS; i ++)
 
51
                {
 
52
                        pPoint = &pData->pBlackHolePoints[n];
 
53
                        r = pPoint->r0;
 
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.
 
58
                        
 
59
                        n ++;
 
60
                }
 
61
        }
 
62
}
 
63
 
 
64
static inline void _update_coords (CDIllusionData *pData)
 
65
{
 
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 ++)
 
71
        {
 
72
                for (i = 0; i < SPIRAL_NB_PTS-1; i ++)
 
73
                {
 
74
                        //g_print (" %d) %d;%d\n", n, i, j);
 
75
                        for (k = 0; k < 4; k ++)
 
76
                        {
 
77
                                ix = ((k+1)&2)/2;  // 0,1,1,0
 
78
                                iy = (k&2)/2;  // 0,0,1,1
 
79
                                
 
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;
 
85
                                
 
86
                                pData->pBlackHoleVertices[2*(4*n+k)] = pPoint->x;
 
87
                                pData->pBlackHoleVertices[2*(4*n+k)+1] = pPoint->y;
 
88
                        }
 
89
                        
 
90
                        n ++;
 
91
                }
 
92
        }
 
93
        //g_print ("done.\n");
 
94
}
 
95
 
 
96
gboolean cd_illusion_init_black_hole (Icon *pIcon, CairoDock *pDock, CDIllusionData *pData)
 
97
{
 
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));
 
101
        
 
102
        int i, j, n=0;
 
103
        double u, v, x, y, r;
 
104
        CDIllusionBlackHole *pPoint;
 
105
        for (j = 0; j < SPIRAL_NB_PTS; j ++)  // bas -> haut.
 
106
        {
 
107
                v = (double) j / SPIRAL_NB_PTS;
 
108
                y = v - .5;
 
109
                for (i = 0; i < SPIRAL_NB_PTS; i ++)  // gauche -> droite.
 
110
                {
 
111
                        u = (double) i / SPIRAL_NB_PTS;
 
112
                        x = u - .5;
 
113
                        
 
114
                        pPoint = &pData->pBlackHolePoints[n];  // n = j*N+i
 
115
                        pPoint->u = u;
 
116
                        pPoint->v = v;
 
117
                        pPoint->fTheta0 = atan2 (y, x);
 
118
                        pPoint->r0 = sqrt (x*x + y*y);
 
119
                        
 
120
                        n ++;
 
121
                }
 
122
        }
 
123
        
 
124
        _calculate_grid (pData);
 
125
        
 
126
        _update_coords (pData);
 
127
        
 
128
        return TRUE;
 
129
}
 
130
 
 
131
 
 
132
void cd_illusion_update_black_hole (Icon *pIcon, CairoDock *pDock, CDIllusionData *pData)
 
133
{
 
134
        _calculate_grid (pData);
 
135
        
 
136
        _update_coords (pData);
 
137
        
 
138
        cairo_dock_redraw_icon (pIcon, pDock);
 
139
}
 
140
 
 
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)
 
144
{
 
145
        _cairo_dock_enable_texture ();
 
146
        _cairo_dock_set_alpha (pIcon->fAlpha);
 
147
        if (pIcon->fAlpha == 1)
 
148
                _cairo_dock_set_blend_over ();
 
149
        else
 
150
                _cairo_dock_set_blend_alpha ();
 
151
        glBindTexture(GL_TEXTURE_2D, pIcon->iIconTexture);
 
152
        
 
153
        glPushMatrix ();
 
154
        cairo_dock_set_icon_scale (pIcon, pDock, 1.);
 
155
        
 
156
        glEnableClientState (GL_TEXTURE_COORD_ARRAY);
 
157
        glEnableClientState (GL_VERTEX_ARRAY);
 
158
        
 
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));
 
162
        
 
163
        glPopMatrix ();
 
164
        
 
165
        glDisableClientState (GL_TEXTURE_COORD_ARRAY);
 
166
        glDisableClientState (GL_VERTEX_ARRAY);
 
167
        _cairo_dock_disable_texture ();
 
168
}