00001
00002
00003
00004
00005 #include "lines.h"
00006 #include <math.h>
00007 #include <stdlib.h>
00008 #include <stdio.h>
00009 #include "goom_tools.h"
00010 #include "drawmethods.h"
00011
00012 extern unsigned int resolx, c_resoly;
00013
00014 static inline unsigned char
00015 lighten (unsigned char value, float power)
00016 {
00017 int val = value;
00018 float t = (float) val * log10(power) / 2.0;
00019
00020 if (t > 0) {
00021 val = (int) t;
00022 if (val > 255)
00023 val = 255;
00024 if (val < 0)
00025 val = 0;
00026 return val;
00027 }
00028 else {
00029 return 0;
00030 }
00031 }
00032
00033 static void
00034 lightencolor (int *col, float power)
00035 {
00036 unsigned char *color;
00037
00038 color = (unsigned char *) col;
00039 *color = lighten (*color, power);
00040 color++;
00041 *color = lighten (*color, power);
00042 color++;
00043 *color = lighten (*color, power);
00044 color++;
00045 *color = lighten (*color, power);
00046 }
00047
00048 static void
00049 genline (int id, float param, GMUnitPointer * l, int rx, int ry)
00050 {
00051 int i;
00052
00053 switch (id) {
00054 case GML_HLINE:
00055 for (i = 0; i < 512; i++) {
00056 l[i].x = ((float) i * rx) / 512.0f;
00057 l[i].y = param;
00058 l[i].angle = M_PI / 2.0f;
00059 }
00060 return;
00061 case GML_VLINE:
00062 for (i = 0; i < 512; i++) {
00063 l[i].y = ((float) i * ry) / 512.0f;
00064 l[i].x = param;
00065 l[i].angle = 0.0f;
00066 }
00067 return;
00068 case GML_CIRCLE:
00069 for (i = 0; i < 512; i++) {
00070 float cosa, sina;
00071
00072 l[i].angle = 2.0f * M_PI * (float) i / 512.0f;
00073 cosa = param * cos (l[i].angle);
00074 sina = param * sin (l[i].angle);
00075 l[i].x = ((float) rx / 2.0f) + cosa;
00076 l[i].y = (float) ry / 2.0f + sina;
00077 }
00078 return;
00079 }
00080 }
00081
00082 static guint32 getcouleur (int mode)
00083 {
00084 switch (mode) {
00085 case GML_RED:
00086 return (230 << (ROUGE * 8)) | (120 << (VERT * 8)) | (10 << (BLEU * 8));
00087 case GML_ORANGE_J:
00088 return (120 << (VERT * 8)) | (252 << (ROUGE * 8)) | (10 << (BLEU * 8));
00089 case GML_ORANGE_V:
00090 return (160 << (VERT * 8)) | (236 << (ROUGE * 8)) | (40 << (BLEU * 8));
00091 case GML_BLEUBLANC:
00092 return (40 << (BLEU * 8)) | (220 << (ROUGE * 8)) | (140 << (VERT * 8));
00093 case GML_VERT:
00094 return (200 << (VERT * 8)) | (80 << (ROUGE * 8)) | (10 << (BLEU * 8));
00095 case GML_BLEU:
00096 return (250 << (BLEU * 8)) | (30 << (VERT * 8)) | (80 << (ROUGE * 8));
00097 case GML_BLACK:
00098 return 0x5 << (BLEU * 8);
00099 }
00100 return 0;
00101 }
00102
00103 void
00104 goom_lines_set_res (GMLine * gml, int rx, int ry)
00105 {
00106 if (gml != NULL) {
00107
00108
00109 gml->screenX = rx;
00110 gml->screenY = ry;
00111
00112 genline (gml->IDdest, gml->param, gml->points2, rx, ry);
00113 }
00114 }
00115
00116
00117 static void
00118 goom_lines_move (GMLine * l)
00119 {
00120 int i;
00121 unsigned char *c1, *c2;
00122
00123 for (i = 0; i < 512; i++) {
00124 l->points[i].x = (l->points2[i].x + 39.0f * l->points[i].x) / 40.0f;
00125 l->points[i].y = (l->points2[i].y + 39.0f * l->points[i].y) / 40.0f;
00126 l->points[i].angle =
00127 (l->points2[i].angle + 39.0f * l->points[i].angle) / 40.0f;
00128 }
00129
00130 c1 = (unsigned char *) &l->color;
00131 c2 = (unsigned char *) &l->color2;
00132 for (i = 0; i < 4; i++) {
00133 int cc1, cc2;
00134
00135 cc1 = *c1;
00136 cc2 = *c2;
00137 *c1 = (unsigned char) ((cc1 * 63 + cc2) >> 6);
00138 ++c1;
00139 ++c2;
00140 }
00141
00142 l->power += l->powinc;
00143 if (l->power < 1.1f) {
00144 l->power = 1.1f;
00145 l->powinc = (float) (iRAND (20) + 10) / 300.0f;
00146 }
00147 if (l->power > 17.5f) {
00148 l->power = 17.5f;
00149 l->powinc = -(float) (iRAND (20) + 10) / 300.0f;
00150 }
00151
00152 l->amplitude = (99.0f * l->amplitude + l->amplitudeF) / 100.0f;
00153 }
00154
00155 void
00156 goom_lines_switch_to (GMLine * gml, int IDdest,
00157 float param, float amplitude, int col)
00158 {
00159 genline (IDdest, param, gml->points2, gml->screenX, gml->screenY);
00160 gml->IDdest = IDdest;
00161 gml->param = param;
00162 gml->amplitudeF = amplitude;
00163 gml->color2 = getcouleur (col);
00164
00165 }
00166
00167 GMLine *
00168 goom_lines_init (int rx, int ry,
00169 int IDsrc, float paramS, int coulS,
00170 int IDdest, float paramD, int coulD)
00171 {
00172
00173
00174
00175
00176 GMLine *l = (GMLine *) malloc (sizeof (GMLine));
00177
00178 l->points = (GMUnitPointer *) malloc (512 * sizeof (GMUnitPointer));
00179 l->points2 = (GMUnitPointer *) malloc (512 * sizeof (GMUnitPointer));
00180 l->nbPoints = 512;
00181
00182 l->IDdest = IDdest;
00183 l->param = paramD;
00184
00185 l->amplitude = l->amplitudeF = 1.0f;
00186
00187 genline (IDsrc, paramS, l->points, rx, ry);
00188 genline (IDdest, paramD, l->points2, rx, ry);
00189
00190 l->color = getcouleur (coulS);
00191 l->color2 = getcouleur (coulD);
00192
00193 l->screenX = rx;
00194 l->screenY = ry;
00195
00196 l->power = 0.0f;
00197 l->powinc = 0.01f;
00198
00199 goom_lines_switch_to (l, IDdest, paramD, 1.0f, coulD);
00200
00201 return l;
00202 }
00203
00204 void
00205 goom_lines_free (GMLine ** l)
00206 {
00207 free ((*l)->points);
00208 free ((*l)->points2);
00209 free (*l);
00210 l = NULL;
00211 }
00212
00213 void
00214 goom_lines_draw (GMLine * line, gint16 data[512], unsigned int *p)
00215 {
00216 if (line != NULL) {
00217 int i, x1, y1;
00218 guint32 color = line->color;
00219 GMUnitPointer *pt = &(line->points[0]);
00220
00221 float cosa = cos (pt->angle) / 1000.0f;
00222 float sina = sin (pt->angle) / 1000.0f;
00223
00224 lightencolor ((int *)&color, line->power);
00225
00226 x1 = (int) (pt->x + cosa * line->amplitude * data[0]);
00227 y1 = (int) (pt->y + sina * line->amplitude * data[0]);
00228
00229 for (i = 1; i < 512; i++) {
00230 int x2, y2;
00231 GMUnitPointer *pt = &(line->points[i]);
00232
00233 float cosa = cos (pt->angle) / 1000.0f;
00234 float sina = sin (pt->angle) / 1000.0f;
00235
00236 x2 = (int) (pt->x + cosa * line->amplitude * data[i]);
00237 y2 = (int) (pt->y + sina * line->amplitude * data[i]);
00238
00239 draw_line ((int *)p, x1, y1, x2, y2, color, line->screenX, line->screenY);
00240 DRAWMETHOD_DONE ();
00241
00242 x1 = x2;
00243 y1 = y2;
00244 }
00245 goom_lines_move (line);
00246 }
00247 }