| 1 |
/* Libvisual-plugins - Standard plugins for libvisual |
| 2 |
* |
| 3 |
* Copyright (C) 2000, 2001 Remi Arquier <[email protected]> |
| 4 |
* |
| 5 |
* Authors: Remi Arquier <[email protected]> |
| 6 |
* Dennis Smit <[email protected]> |
| 7 |
* |
| 8 |
* $Id: draw.c,v 1.6 2006/01/18 19:45:23 synap Exp $ |
| 9 |
* |
| 10 |
* This program is free software; you can redistribute it and/or modify |
| 11 |
* it under the terms of the GNU General Public License as |
| 12 |
* published by the Free Software Foundation; either version 2 |
| 13 |
* of the License, or (at your option) any later version. |
| 14 |
* |
| 15 |
* This program is distributed in the hope that it will be useful, |
| 16 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 |
* GNU General Public License for more details. |
| 19 |
* |
| 20 |
* You should have received a copy of the GNU General Public License |
| 21 |
* along with this program; if not, write to the Free Software |
| 22 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 23 |
*/ |
| 24 |
|
| 25 |
#include <stdlib.h> |
| 26 |
#include <stdio.h> |
| 27 |
#include <math.h> |
| 28 |
|
| 29 |
#include "def.h" |
| 30 |
#include "draw.h" |
| 31 |
#include "struct.h" |
| 32 |
#include "analyser_struct.h" |
| 33 |
#include "pal.h" |
| 34 |
#include "draw_low_level.h" |
| 35 |
#include "projection.h" |
| 36 |
#include "jess.h" |
| 37 |
|
| 38 |
/*******************************************************************/ |
| 39 |
/**************** ANALYSER *****************************************/ |
| 40 |
/*******************************************************************/ |
| 41 |
|
| 42 |
void analyser(JessPrivate *priv, uint8_t * buffer) |
| 43 |
{ |
| 44 |
int i ; |
| 45 |
|
| 46 |
droite (priv, buffer, -priv->xres2, 0, -priv->xres2+10, 0, 30); |
| 47 |
|
| 48 |
for (i = -priv->xres2 ; i<-priv->xres2+5 ; i++) |
| 49 |
{ |
| 50 |
droite (priv, buffer, i, 0, i,(int)(priv->lys.E_moyen*2000) , 250); |
| 51 |
droite (priv, buffer, i+5, 0, i+5, (int)(priv->lys.dEdt_moyen*25000) , 230); |
| 52 |
droite (priv, buffer, i+10, 0, i+10, (int)(priv->lys.dEdt*25000) , 200); |
| 53 |
} |
| 54 |
} |
| 55 |
|
| 56 |
/*******************************************************************/ |
| 57 |
/**************** FUSEES *******************************************/ |
| 58 |
/*******************************************************************/ |
| 59 |
|
| 60 |
void fusee(JessPrivate *priv, uint8_t * buffer, int new) |
| 61 |
{ |
| 62 |
int i; |
| 63 |
int x=0,y=0; |
| 64 |
float factor ; |
| 65 |
|
| 66 |
if (new == NEW) /* on creer une nouvelle fusee*/ |
| 67 |
{ |
| 68 |
i=0; |
| 69 |
while (priv->life[i] > 0) |
| 70 |
{ |
| 71 |
i++; |
| 72 |
if (i == FUSEE_MAX) |
| 73 |
return; |
| 74 |
} |
| 75 |
priv->xi[i] = visual_random_context_int(priv->rcontext) % priv->resx - priv->xres2; |
| 76 |
priv->yi[i] = -visual_random_context_int(priv->rcontext) % priv->yres2; |
| 77 |
priv->life[i] = FUSEE_VIE; /* on donne la vie max*/ |
| 78 |
} |
| 79 |
else /* on gere les autres */ |
| 80 |
{ |
| 81 |
for(i = 0 ; i< FUSEE_MAX; i++) |
| 82 |
{ |
| 83 |
if (priv->life[i] > 0) /* si elle est vivante */ |
| 84 |
{ |
| 85 |
factor = priv->life[i] / FUSEE_VIE; |
| 86 |
x = priv->xi[i] * factor; |
| 87 |
y = priv->yi[i] * factor; |
| 88 |
priv->life[i]--; |
| 89 |
ball (priv, buffer, x, y, (int) FUSEE_RAYON * factor, FUSEE_COLOR); |
| 90 |
} |
| 91 |
} |
| 92 |
} |
| 93 |
} |
| 94 |
|
| 95 |
/*******************************************************************/ |
| 96 |
/**************** SUPER SPECTRAL ***********************************/ |
| 97 |
/*******************************************************************/ |
| 98 |
|
| 99 |
void super_spectral_balls(JessPrivate *priv, uint8_t * buffer) |
| 100 |
{ |
| 101 |
int i,j; |
| 102 |
|
| 103 |
float dt = priv->conteur.dt; |
| 104 |
|
| 105 |
int resx = priv->resx; |
| 106 |
int resy = priv->resy; |
| 107 |
int xres2 = priv->xres2; |
| 108 |
int yres2 = priv->yres2; |
| 109 |
|
| 110 |
for(i=0; i < 256 ;i++) /* pour chaque frequence */ |
| 111 |
{ |
| 112 |
if (priv->lys.dbeat[i] == NEW) /*creation d'une nouvelle ligne */ |
| 113 |
{ |
| 114 |
priv->lys.dbeat[i] = MANAGE; |
| 115 |
j=0; |
| 116 |
while (priv->lifev[i][j] > 0) |
| 117 |
{ |
| 118 |
j++; |
| 119 |
if (j == LINE_MAX+1) |
| 120 |
goto quit; /* pas de place desole */ |
| 121 |
} |
| 122 |
|
| 123 |
/* initialisation de la ligne */ |
| 124 |
priv->lifev[i][j] = LINE_VIE; |
| 125 |
priv->vx[i][j] = RESFACTXF( 0.025*((float) i - 128.0) * 32 +0* |
| 126 |
(1-(float)visual_random_context_int(priv->rcontext)/RAND_MAX) ); |
| 127 |
priv->vy[i][j] = RESFACTYF( (10+i)*i*priv->lys.Ed_moyen[i]*5000*( (float)j+1)/4); |
| 128 |
priv->x[i][j] = RESFACTXF( 2*(i - 128) ) +((float)j*(i-128))/2; |
| 129 |
priv->y[i][j] = 0*RESFACTXF( yres2/2-(float)((i-128)*(i-128))/256) -20*j ; |
| 130 |
} |
| 131 |
quit:; /* pas de nouvelle ligne */ |
| 132 |
|
| 133 |
for (j=0 ; j < LINE_MAX ; j++) |
| 134 |
{ |
| 135 |
if (priv->lifev[i][j] > 0) |
| 136 |
{ |
| 137 |
|
| 138 |
priv->vy[i][j] += -0.5*dt*1024; |
| 139 |
priv->x[i][j] += priv->vx[i][j] * dt; |
| 140 |
priv->y[i][j] += priv->vy[i][j] * dt; |
| 141 |
|
| 142 |
boule(priv, buffer, (int) priv->x[i][j], (int) priv->y[i][j], 5, |
| 143 |
250*(LINE_VIE-priv->lifev[i][j])/LINE_VIE); |
| 144 |
|
| 145 |
if ((priv->y[i][j] < resy) &&(priv->y[i][j] > -resy) ) /*oui !*/ |
| 146 |
{ |
| 147 |
if (i>128) |
| 148 |
droite (priv, buffer, priv->xres2, (int) priv->y[i][j] / 32, |
| 149 |
(int) priv->x[i][j], (int) priv->y[i][j], 50 * |
| 150 |
(LINE_VIE-priv->lifev[i][j]) / LINE_VIE); |
| 151 |
else |
| 152 |
droite (priv, buffer, -xres2, (int) priv->y[i][j] / 32, |
| 153 |
(int) priv->x[i][j], (int) priv->y[i][j], 50 * |
| 154 |
(LINE_VIE-priv->lifev[i][j])/LINE_VIE); |
| 155 |
} |
| 156 |
priv->lifev[i][j]--; |
| 157 |
} |
| 158 |
} |
| 159 |
} |
| 160 |
} |
| 161 |
|
| 162 |
/*******************************************************************/ |
| 163 |
/**************** SUPER SPECTRAL ***********************************/ |
| 164 |
/*******************************************************************/ |
| 165 |
|
| 166 |
void super_spectral(JessPrivate *priv, uint8_t * buffer) |
| 167 |
{ |
| 168 |
int i,j; |
| 169 |
|
| 170 |
float nx,ny; |
| 171 |
float taille,dt = priv->conteur.dt; |
| 172 |
|
| 173 |
int resx = priv->resx; |
| 174 |
int resy = priv->resy; |
| 175 |
int yres2 = priv->yres2; |
| 176 |
|
| 177 |
for(i=0; i < 256 ;i++) /* pour chaque frequence */ |
| 178 |
{ |
| 179 |
if (priv->lys.dbeat[i] == NEW) /*creation d'une nouvelle ligne */ |
| 180 |
{ |
| 181 |
priv->lys.dbeat[i] = MANAGE; |
| 182 |
j=0; |
| 183 |
while (priv->lifet[i][j] > 0) |
| 184 |
{ |
| 185 |
j++; |
| 186 |
if (j == LINE_MAX+1) |
| 187 |
goto quit; /* pas de place desole */ |
| 188 |
} |
| 189 |
/* initialisation de la ligne */ |
| 190 |
priv->lifet[i][j] = LINE_VIE; |
| 191 |
priv->ssvx[i][j] = 0*RESFACTXF( 0.025*((float) i - 128.0) * 32 + |
| 192 |
(float)visual_random_context_int(priv->rcontext)/RAND_MAX*60 ); |
| 193 |
priv->ssvy[i][j] = 0*RESFACTYF( 64 +(float)visual_random_context_int(priv->rcontext)/RAND_MAX*64); |
| 194 |
priv->ssx[i][j] = RESFACTXF( 2*(i - 128) ) +((float)j*(i-128))/2; |
| 195 |
priv->ssy[i][j] = 0*RESFACTXF( yres2/2-(float)((i-128)*(i-128))/256) -20*j+60 ; |
| 196 |
priv->sstheta[i][j] = 0; |
| 197 |
priv->ssomega[i][j] = (10+i)*i*priv->lys.Ed_moyen[i]*32; |
| 198 |
} |
| 199 |
quit:; /* pas de nouvelle ligne */ |
| 200 |
for (j=0 ; j < LINE_MAX ; j++) |
| 201 |
if (priv->lifet[i][j] > 0) |
| 202 |
{ |
| 203 |
priv->sstheta[i][j] += priv->ssomega[i][j]*dt; |
| 204 |
priv->ssvy[i][j] += -0.5*dt*1024*0; |
| 205 |
priv->ssx[i][j] += priv->ssvx[i][j] * dt; |
| 206 |
priv->ssy[i][j] += priv->ssvy[i][j] * dt; |
| 207 |
taille = RESFACTXF(70) * (0+2*(LINE_VIE-priv->lifet[i][j]))/LINE_VIE*(j+1)/6; |
| 208 |
nx = taille*sin(priv->sstheta[i][j]); |
| 209 |
ny = taille*cos(priv->sstheta[i][j]); |
| 210 |
|
| 211 |
droite (priv, buffer, (int) priv->ssx[i][j]+nx , (int) priv->ssy[i][j]+ny, (int) priv->ssx[i][j], (int) priv->ssy[i][j], 50*(LINE_VIE-priv->lifet[i][j])/LINE_VIE); |
| 212 |
|
| 213 |
if (priv->video ==8) |
| 214 |
cercle (priv, buffer, (int) priv->ssx[i][j]+nx, (int) priv->ssy[i][j]+ny, 3*j, 150*(LINE_VIE-priv->lifet[i][j])/LINE_VIE); |
| 215 |
else |
| 216 |
cercle_32 (priv, buffer, (int) priv->ssx[i][j]+nx, (int) priv->ssy[i][j]+ny, 3*j, 150*(LINE_VIE-priv->lifet[i][j])/LINE_VIE); |
| 217 |
|
| 218 |
priv->lifet[i][j]--; |
| 219 |
} |
| 220 |
} |
| 221 |
} |
| 222 |
|
| 223 |
/*******************************************************************/ |
| 224 |
/**************** GRANDE GRILLE ************************************/ |
| 225 |
/*******************************************************************/ |
| 226 |
|
| 227 |
void grille_3d (JessPrivate *priv, uint8_t * buffer, float data[2][512], float alpha, float beta, |
| 228 |
float gamma, int persp, int dist_cam) |
| 229 |
{ |
| 230 |
|
| 231 |
float x, y, z, xres2 = (float) (priv->resx >> 1); |
| 232 |
short ax = 0, ay = 0, ix, iy, i, j, nb_x, nb_y; |
| 233 |
uint8_t color; |
| 234 |
|
| 235 |
int resx = priv->resx; |
| 236 |
int resy = priv->resy; |
| 237 |
|
| 238 |
nb_x = 32; |
| 239 |
nb_y = 32; |
| 240 |
|
| 241 |
for (i = 0; i < nb_x; i++) |
| 242 |
{ |
| 243 |
/* Optimisation par Karl Soulabaille. Factorisation et expressions communes. */ |
| 244 |
for (j = 0; j < nb_y; j++) |
| 245 |
{ |
| 246 |
x = RESFACTXF ((i - ((float) nb_x) / 2) * 10); |
| 247 |
y = RESFACTYF ((j - ((float) nb_y) / 2) * 10); |
| 248 |
|
| 249 |
if (j >= 16) |
| 250 |
{ |
| 251 |
z = RESFACTXF ((float) (data[0][i + nb_x * (j - 16)]) * 256); |
| 252 |
color = data[0][i + nb_x * (j - 16)] * 64 + 100; |
| 253 |
} |
| 254 |
else |
| 255 |
{ |
| 256 |
z = RESFACTXF ((float) (data[1][i + nb_x * j]) * 256); |
| 257 |
color = (data[1][i + nb_x * j]) * 64 + 100; |
| 258 |
} |
| 259 |
|
| 260 |
rotation_3d (&x, &y, &z, alpha, beta, gamma); |
| 261 |
perspective (&x, &y, &z, persp, dist_cam); |
| 262 |
|
| 263 |
if (x >= xres2) |
| 264 |
{ |
| 265 |
x = xres2 - 1; |
| 266 |
color = 0; |
| 267 |
} |
| 268 |
if (x <= -xres2) |
| 269 |
{ |
| 270 |
x = -xres2 + 1; |
| 271 |
color = 0; |
| 272 |
} |
| 273 |
if (y >= priv->yres2) |
| 274 |
{ |
| 275 |
y = priv->yres2 - 1; |
| 276 |
color = 0; |
| 277 |
} |
| 278 |
if (y <= -priv->yres2) |
| 279 |
{ |
| 280 |
y = -priv->yres2 + 1; |
| 281 |
color = 0; |
| 282 |
} |
| 283 |
|
| 284 |
ix = (int) x; |
| 285 |
iy = (int) y; |
| 286 |
|
| 287 |
if (j != 0) |
| 288 |
droite (priv, buffer, ix, iy, ax, ay, color); |
| 289 |
|
| 290 |
ax = ix; |
| 291 |
ay = iy; |
| 292 |
} |
| 293 |
} |
| 294 |
} |
| 295 |
|
| 296 |
/*******************************************************************/ |
| 297 |
/**************** 2 GRILLES JUMELLES *******************************/ |
| 298 |
/*******************************************************************/ |
| 299 |
|
| 300 |
void l2_grilles_3d (JessPrivate *priv, uint8_t * buffer, float data[2][512], float alpha, float beta, |
| 301 |
float gamma, int persp, int dist_cam) |
| 302 |
{ |
| 303 |
|
| 304 |
float x, y, z, xres4 = (float) (priv->resx >> 2); |
| 305 |
short ax = 0, ay = 0, ix, iy, i, j, nb_x, nb_y; |
| 306 |
int tx[16][16], ty[16][16]; |
| 307 |
uint8_t color[16][16]; |
| 308 |
|
| 309 |
int resx = priv->resx; |
| 310 |
int resy = priv->resy; |
| 311 |
|
| 312 |
nb_x = 16; |
| 313 |
nb_y = 16; |
| 314 |
|
| 315 |
for (i = 0; i < nb_x; i++) |
| 316 |
{ |
| 317 |
/* Optimisation par Karl Soulabaille. Factorisation de calcul & expression commune */ |
| 318 |
x = RESFACTXF ((i - ((float) nb_x / 2)) * 15); |
| 319 |
for (j = 0; j < nb_y; j++) |
| 320 |
{ |
| 321 |
y = RESFACTYF ((j - ((float) nb_y / 2)) * 15); |
| 322 |
|
| 323 |
z = abs(RESFACTXF ((float) (data[1][i + nb_x * j]) * 256)); |
| 324 |
color[i][j] = data[1][i + nb_x * j] * 64 + 100; |
| 325 |
|
| 326 |
rotation_3d (&x, &y, &z, alpha, beta, gamma); |
| 327 |
perspective (&x, &y, &z, persp, dist_cam); |
| 328 |
|
| 329 |
ix = (int) x; |
| 330 |
iy = (int) y; |
| 331 |
|
| 332 |
tx[i][j] = ix; |
| 333 |
ty[i][j] = iy; |
| 334 |
|
| 335 |
if (j != 0) |
| 336 |
{ |
| 337 |
droite (priv, buffer, ix - xres4, iy, ax - xres4, ay, color[i][j]); |
| 338 |
droite (priv, buffer, ix + xres4, iy, ax + xres4, ay, color[i][j]); |
| 339 |
} |
| 340 |
|
| 341 |
ax = ix; |
| 342 |
ay = iy; |
| 343 |
} |
| 344 |
} |
| 345 |
} |
| 346 |
|
| 347 |
/*******************************************************************/ |
| 348 |
/**************** BURN 3D ******************************************/ |
| 349 |
/*******************************************************************/ |
| 350 |
|
| 351 |
void burn_3d (JessPrivate *priv, uint8_t * buffer, float data[2][512], float alpha, float beta, |
| 352 |
float gamma, int persp, int dist_cam, int mode) |
| 353 |
{ |
| 354 |
float x,y,z,xres2 = (float) (priv->resx >> 1), yres2 = (float) (priv->resy >> 1); |
| 355 |
short ix, iy, i, j, nb_x, nb_y, color, taille; |
| 356 |
|
| 357 |
/* Variable temporaire pour la factorisation de constantes */ |
| 358 |
float temp1, temp2, temp3, temp3b, temp4, temp4b, temp5,temp6,temp7,temp8,temp9; |
| 359 |
|
| 360 |
int resx = priv->resx; |
| 361 |
int resy = priv->resy; |
| 362 |
|
| 363 |
nb_x = 12; |
| 364 |
nb_y = 12; |
| 365 |
|
| 366 |
/* 4 cas: */ |
| 367 |
switch(mode) { |
| 368 |
case 0: |
| 369 |
|
| 370 |
temp1 = 2*PI/nb_x*cos(alpha); |
| 371 |
temp2 = 2*PI/nb_y; |
| 372 |
for (i = 0 ; i< nb_x ; i++) |
| 373 |
{ |
| 374 |
temp3 = (float)((int)(i*i)); |
| 375 |
for (j = 0 ; j<nb_y ; j++) |
| 376 |
{ |
| 377 |
x = RESFACTXF ((float) 25*(i+1)*cos(temp3*temp1+ temp2*j) ); |
| 378 |
y = RESFACTYF ((float) 25*(i+1)*sin(temp3*temp1+ temp2*j) ); |
| 379 |
z = RESFACTXF (40*cos(5*alpha)); |
| 380 |
rotation_3d (&x, &y, &z, alpha, beta, gamma); |
| 381 |
perspective (&x, &y, &z, persp, dist_cam); |
| 382 |
if (!(x >= xres2 || x <= -xres2 || y >= yres2 || y <= -yres2)) |
| 383 |
{ |
| 384 |
ix = (int) x; |
| 385 |
iy = (int) y; |
| 386 |
|
| 387 |
color = ((int)(float)(100+0.4*z)); |
| 388 |
if (color<0) |
| 389 |
color = 0; |
| 390 |
taille = color/8; |
| 391 |
|
| 392 |
boule (priv, buffer, ix, iy, taille, color); |
| 393 |
} |
| 394 |
} |
| 395 |
} |
| 396 |
break; |
| 397 |
case 1: |
| 398 |
temp1 = PI/(nb_x*nb_x*nb_x)*fabs(priv->lys.dEdt_moyen*5000); |
| 399 |
temp6 = 2*PI/nb_y; |
| 400 |
for (i = 0 ; i< nb_x ; i++) |
| 401 |
{ |
| 402 |
temp3 = (float)(i*i*i); |
| 403 |
temp4 = sin((i+1)*PI/nb_x); |
| 404 |
temp5 = 5*alpha*2*PI/nb_x*i; |
| 405 |
temp3b = temp3*temp1; |
| 406 |
temp4b = temp4*temp1; |
| 407 |
|
| 408 |
for (j = 0 ; j<nb_y ; j++) |
| 409 |
{ |
| 410 |
x = RESFACTXF ((float) 50*(temp3b + temp4*cos(temp5 + temp6*j))); |
| 411 |
y = RESFACTYF ((float) 50*(temp4b + temp4*sin(temp5 + temp6*j))); |
| 412 |
z = RESFACTXF ((float) 100*cos((float)i/nb_x*PI)*(1 + priv->lys.dEdt_moyen*1000)); |
| 413 |
rotation_3d (&x, &y, &z, alpha, beta, gamma); |
| 414 |
perspective (&x, &y, &z, persp, dist_cam); |
| 415 |
if (!(x >= xres2 || x <= -xres2 || y >= yres2 || y <= -yres2)) |
| 416 |
{ |
| 417 |
ix = (int) x; |
| 418 |
iy = (int) y; |
| 419 |
|
| 420 |
color = ((int)(float)(100+0.4*z)); |
| 421 |
if (color<0) |
| 422 |
color = 0; |
| 423 |
taille = color/8; |
| 424 |
|
| 425 |
boule (priv, buffer, ix, iy, taille, color); |
| 426 |
} |
| 427 |
} |
| 428 |
} |
| 429 |
break; |
| 430 |
case 2: |
| 431 |
temp5 = 2*PI/(5*nb_x); |
| 432 |
temp6 = 2*PI/nb_y; |
| 433 |
for (i = 0 ; i< nb_x ; i++) |
| 434 |
{ |
| 435 |
temp1 = sin((i+1)*PI/nb_x); |
| 436 |
temp2 = temp5 * -i; |
| 437 |
|
| 438 |
for (j = 0 ; j<nb_y ; j++) |
| 439 |
{ |
| 440 |
x = RESFACTXF ((float) 130*temp1*cos(temp2+ j*temp6 )); |
| 441 |
y = RESFACTYF ((float) 130*temp1*sin(temp2+ j*temp6 )); |
| 442 |
z = -RESFACTXF (130*cos((float)i/nb_x*PI)*priv->lys.dEdt_moyen*1000 ); |
| 443 |
rotation_3d (&x, &y, &z, alpha, beta, gamma); |
| 444 |
perspective (&x, &y, &z, persp, dist_cam); |
| 445 |
if (!(x >= xres2 || x <= -xres2 || y >= yres2 || y <= -yres2)) |
| 446 |
{ |
| 447 |
ix = (int) x; |
| 448 |
iy = (int) y; |
| 449 |
|
| 450 |
color = ((int)(float)(100+0.4*z)); |
| 451 |
if (color<0) |
| 452 |
color = 0; |
| 453 |
taille = color/8; |
| 454 |
|
| 455 |
boule (priv, buffer, ix, iy, taille, color); |
| 456 |
} |
| 457 |
} |
| 458 |
} |
| 459 |
break; |
| 460 |
case 3: |
| 461 |
temp5 = 25; |
| 462 |
temp6 = ((float)(-2))*PI/(10*nb_x); |
| 463 |
temp8 = (float)(2)*PI/nb_y; |
| 464 |
temp9 = 10*alpha; |
| 465 |
for (i = 0 ; i< nb_x ; i++) |
| 466 |
{ |
| 467 |
temp5 += 25; |
| 468 |
temp7 = -i*temp6; |
| 469 |
for (j = 0 ; j<nb_y ; j++) |
| 470 |
{ |
| 471 |
x = RESFACTXF ((float) temp5*cos(temp7+ temp8*j) ); |
| 472 |
y = RESFACTYF ((float) temp5*sin(temp7+ temp8*j) ); |
| 473 |
z = RESFACTXF (60* (cos(temp8*j+temp9)+cos(-temp7)) ); |
| 474 |
rotation_3d (&x, &y, &z, alpha, beta, gamma); |
| 475 |
perspective (&x, &y, &z, persp, dist_cam); |
| 476 |
if (!(x >= xres2 || x <= -xres2 || y >= yres2 || y <= -yres2)) |
| 477 |
{ |
| 478 |
ix = (int) x; |
| 479 |
iy = (int) y; |
| 480 |
|
| 481 |
color = ((int)(float)(100+0.4*z)); |
| 482 |
if (color<0) |
| 483 |
color = 0; |
| 484 |
taille = color/8; |
| 485 |
|
| 486 |
boule (priv, buffer, ix, iy, taille, color); |
| 487 |
} |
| 488 |
} |
| 489 |
} |
| 490 |
break; |
| 491 |
} |
| 492 |
} |
| 493 |
|
| 494 |
/*******************************************************************/ |
| 495 |
/**************** STARS MORPH **************************************/ |
| 496 |
/*******************************************************************/ |
| 497 |
|
| 498 |
void stars_create_state(JessPrivate *priv, float pos[3][STARS_MAX], int mode) |
| 499 |
{ |
| 500 |
int i,j,sq=sqrt(STARS_MAX); |
| 501 |
float fsq = (float) sq; |
| 502 |
|
| 503 |
|
| 504 |
switch(mode) |
| 505 |
{ |
| 506 |
case 0: |
| 507 |
for(i=0 ; i< STARS_MAX; i++) |
| 508 |
{ |
| 509 |
for(j=0; j<3 ; j++) |
| 510 |
{ |
| 511 |
pos[j][i] = 0; |
| 512 |
} |
| 513 |
} |
| 514 |
break; |
| 515 |
case 1: |
| 516 |
for(i=0 ; i< STARS_MAX; i++) |
| 517 |
{ |
| 518 |
for(j=0; j<3 ; j++) |
| 519 |
{ |
| 520 |
pos[j][i] = ((float)visual_random_context_int(priv->rcontext)/RAND_MAX-0.5); |
| 521 |
|
| 522 |
} |
| 523 |
} |
| 524 |
break; |
| 525 |
case 2: |
| 526 |
for(j=0 ; j< sq; j++) |
| 527 |
{ |
| 528 |
for(i=0 ; i< sq; i++) |
| 529 |
{ |
| 530 |
pos[0][i + j*sq] = (i - fsq/2)*2/fsq; |
| 531 |
pos[1][i + j*sq] = (j - fsq/2)*2/fsq; |
| 532 |
pos[2][i + j*sq] = 0; |
| 533 |
} |
| 534 |
} |
| 535 |
break; |
| 536 |
case 3: |
| 537 |
for(j=0 ; j< sq; j++) |
| 538 |
{ |
| 539 |
for(i=0 ; i< sq; i++) |
| 540 |
{ |
| 541 |
pos[0][i + j*sq] = sin((i+1)*PI/fsq); |
| 542 |
pos[1][i + j*sq] = sin(-i*2*PI/(10*fsq)+ j*2*PI/fsq) ; |
| 543 |
pos[2][i + j*sq] = cos(j*2*PI/fsq) ; |
| 544 |
} |
| 545 |
} |
| 546 |
break; |
| 547 |
} |
| 548 |
} |
| 549 |
|
| 550 |
void stars_manage(JessPrivate *priv, uint8_t *buffer, int new, float alpha, float beta, |
| 551 |
float gamma, int persp, int dist_cam) |
| 552 |
{ |
| 553 |
float x[STARS_MAX], y[STARS_MAX], z[STARS_MAX], xres2 = (float) (priv->resx >> 1), yres2 = (float) (priv->resy >> 1); |
| 554 |
float x_t, y_t, z_t; |
| 555 |
float mult; |
| 556 |
int ix, iy, i, color, taille; |
| 557 |
|
| 558 |
if (new == NEW_SESSION) /* explosion */ |
| 559 |
{ |
| 560 |
priv->smmorpheur = 0; |
| 561 |
priv->smselect = 1; |
| 562 |
stars_create_state(priv, priv->smpos[0], 0); |
| 563 |
stars_create_state(priv, priv->smpos[1], 1); |
| 564 |
} |
| 565 |
else if(new == NEW) /* on creer une nouvelle forme */ |
| 566 |
{ |
| 567 |
mult = 1; |
| 568 |
if ((visual_random_context_int(priv->rcontext)%3)==0) |
| 569 |
mult = 4; |
| 570 |
|
| 571 |
for(i = 0 ; i< STARS_MAX; i++) |
| 572 |
{ |
| 573 |
priv->smpos[priv->smselect][0][i]= mult*x[i]; |
| 574 |
priv->smpos[priv->smselect][1][i]= mult*y[i]; |
| 575 |
priv->smpos[priv->smselect][2][i]= mult*z[i]; |
| 576 |
} |
| 577 |
priv->smselect = 1 - priv->smselect; |
| 578 |
stars_create_state(priv, priv->smpos[priv->smselect], visual_random_context_int(priv->rcontext)%2+1); |
| 579 |
} |
| 580 |
else /* on gere */ |
| 581 |
{ |
| 582 |
priv->smmorpheur += ( 2 * (float)priv->smselect - 1) * MORPH_SPEED * priv->conteur.dt; |
| 583 |
|
| 584 |
if (priv->smmorpheur > 1) |
| 585 |
priv->smmorpheur = 1; |
| 586 |
else if (priv->smmorpheur < 0) |
| 587 |
priv->smmorpheur = 0; |
| 588 |
|
| 589 |
for(i = 0 ; i< STARS_MAX; i++) |
| 590 |
{ |
| 591 |
x[i] =(priv->smpos[1][0][i] * priv->smmorpheur + (1-priv->smmorpheur) * priv->smpos[0][0][i]); |
| 592 |
y[i] =(priv->smpos[1][1][i] * priv->smmorpheur + (1-priv->smmorpheur) * priv->smpos[0][1][i]); |
| 593 |
z[i] =(priv->smpos[1][2][i] * priv->smmorpheur + (1-priv->smmorpheur) * priv->smpos[0][2][i]); |
| 594 |
|
| 595 |
x_t = 250 * x[i]; |
| 596 |
y_t = 250 * y[i]; |
| 597 |
z_t = 250 * z[i]; |
| 598 |
|
| 599 |
rotation_3d (&x_t, &y_t, &z_t, alpha, beta, gamma); |
| 600 |
perspective (&x_t, &y_t, &z_t, persp, dist_cam); |
| 601 |
|
| 602 |
if ((int)x_t >= xres2 || (int)x_t <= -xres2 || (int)y_t >= yres2 || (int)y_t <= -yres2 || z_t >2*dist_cam) |
| 603 |
return; |
| 604 |
|
| 605 |
ix = (int) x_t; |
| 606 |
iy = (int) y_t; |
| 607 |
|
| 608 |
color = ((int)(float)(100+0.4*z_t)); |
| 609 |
if (color<0) |
| 610 |
color = 0; |
| 611 |
|
| 612 |
taille = color/8; |
| 613 |
|
| 614 |
droite(priv, buffer,ix,iy, xres2/2 ,-yres2 , color/8); |
| 615 |
boule (priv, buffer, ix, iy, taille, color); |
| 616 |
} |
| 617 |
} |
| 618 |
} |
| 619 |
|
| 620 |
/*******************************************************************/ |
| 621 |
/**************** OSCILLO ******************************************/ |
| 622 |
/*******************************************************************/ |
| 623 |
|
| 624 |
uint8_t couleur (JessPrivate *priv, short x) |
| 625 |
{ |
| 626 |
int resx = priv->resx; |
| 627 |
|
| 628 |
float xf = (float) x, resx2f = (float) resx / 2; |
| 629 |
return (uint8_t) ((float) -(xf - resx2f) * (xf + resx2f) * 150 / |
| 630 |
(resx2f * resx2f)); |
| 631 |
} |
| 632 |
|
| 633 |
void courbes (JessPrivate *priv, uint8_t * buffer, float data[2][512], uint8_t color, int type) |
| 634 |
{ |
| 635 |
int j, i, x1, y1, x2=0, y2=0; |
| 636 |
int r; |
| 637 |
|
| 638 |
int resx = priv->resx; |
| 639 |
int resy = priv->resy; |
| 640 |
|
| 641 |
#define RAYON 100 |
| 642 |
|
| 643 |
switch (type) |
| 644 |
{ |
| 645 |
case 0: |
| 646 |
for (i = 0; i < resx - 1 && i < 511; i++) |
| 647 |
{ |
| 648 |
j = i - 256; |
| 649 |
droite (priv, buffer, j, data[0][i] * (128) + resy / 6, j + 1, |
| 650 |
data[0][i + 1] * (128) + resy / 6, couleur (priv, j)); |
| 651 |
droite (priv, buffer, j, data[1][i] * (128) - resy / 6, j + 1, |
| 652 |
data[1][i + 1] * (128) - resy / 6, couleur (priv, j)); |
| 653 |
} |
| 654 |
break; |
| 655 |
case 1: |
| 656 |
r = data[0][255] * 256; |
| 657 |
x2 = (RAYON+r) * cos (255*2*PI/256); |
| 658 |
y2 = (RAYON+r) * sin (255*2*PI/256); |
| 659 |
for (i = 0; i < 256 ;i++) |
| 660 |
{ |
| 661 |
r = data[0][i] * 256; |
| 662 |
x1 = (RAYON+r) * cos (i*2*PI/256); |
| 663 |
y1 = (RAYON+r) * sin( i*2*PI/256); |
| 664 |
droite(priv, buffer,x1,y1,x2,y2,100); |
| 665 |
x2 = x1; |
| 666 |
y2 = y1; |
| 667 |
} |
| 668 |
break; |
| 669 |
default: |
| 670 |
break; |
| 671 |
} |
| 672 |
|
| 673 |
} |
| 674 |
|
| 675 |
/*******************************************************************/ |
| 676 |
/**************** SINUS_RECT ***************************************/ |
| 677 |
/*******************************************************************/ |
| 678 |
|
| 679 |
void sinus_rect (JessPrivate *priv, uint8_t * buffer, int k) |
| 680 |
{ |
| 681 |
int resx = priv->resx; |
| 682 |
int resy = priv->resy; |
| 683 |
|
| 684 |
float fk = k; |
| 685 |
|
| 686 |
ball (priv, buffer, RESFACTXF (250 * cos (fk / 25)), |
| 687 |
RESFACTYF (100 * sin (2 * fk / 25)), RESFACTXF (100), 200); |
| 688 |
ball (priv, buffer, RESFACTXF (-250 * cos (fk / 25)), |
| 689 |
RESFACTYF (100 * sin (2 * fk / 25)), RESFACTXF (100), 200); |
| 690 |
} |
| 691 |
|