00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include <stdlib.h>
00027 #include <stdio.h>
00028 #include <math.h>
00029 #include <float.h>
00030 #include <windows.h>
00031
00032 #if __ZTC__ || __SC__
00033 #ifndef max
00034 #define max(a,b) ( ((a) > (b)) ? (a) : (b) )
00035 #endif
00036 #endif
00037
00038 #if __WATCOMC__
00039 #define PI 3.1415926
00040 #endif
00041
00042 #if __X__MIPS__
00043 BOOL WINAPI _CRT_INIT(HINSTANCE ,DWORD , LPVOID );
00044 #endif
00045
00046 static HINSTANCE hDLLinstance=NULL;
00047
00048 #include "..\animate\memory.h"
00049 #include "..\animate\memdef.h"
00050 #include "defines.h"
00051 #include "rstruct.h"
00052 #include "test.h"
00053
00054 #if __WATCOMC__
00055 int APIENTRY LibMain(HANDLE hDLL, DWORD dwReason, LPVOID lpReserved){
00056 #else
00057 BOOL WINAPI DllMain(HANDLE hDLL, DWORD dwReason, LPVOID lpReserved){
00058 #endif
00059 HANDLE ghMod;
00060 switch (dwReason) {
00061 case DLL_PROCESS_ATTACH:
00062 #if __X__MIPS__
00063 if(!_CRT_INIT(hDLL,dwReason,lpReserved))return(int)FALSE;
00064 #endif
00065 hDLLinstance = hDLL;
00066 break;
00067 case DLL_PROCESS_DETACH:
00068 #if __X__MIPS__
00069 if(!_CRT_INIT(hDLL,dwReason,lpReserved))return(int)FALSE;
00070 #endif
00071 break;
00072 }
00073 return (int)TRUE;
00074 }
00075
00076 #if __SC__
00077 #pragma startaddress(DllMain)
00078 #endif
00079
00080 #define VECCOPY(a,b) { b[0] = a[0]; b[1] = a[1]; b[2] = a[2]; }
00081 #define VECSUM(a,b,c) { c[0]=a[0]+b[0]; c[1]=a[1]+b[1]; c[2]=a[2]+b[2];}
00082 #define VECSUB(a,b,c) { c[0]=a[0]-b[0]; c[1]=a[1]-b[1]; c[2]=a[2]-b[2];}
00083 #define VECSCALE(a,b,c) { c[0]=(a)*b[0]; c[1]=(a)*b[1]; c[2]=(a)*b[2];}
00084 #define DOT(a,b) ( (a[0]*b[0]) + (a[1]*b[1]) + (a[2]*b[2]) )
00085 #define CROSS(v1,v2,r) { \
00086 r[0] = (v1[1]*v2[2]) - (v2[1]*v1[2]); \
00087 r[1] = (v1[2]*v2[0]) - (v1[0]*v2[2]); \
00088 r[2] = (v1[0]*v2[1]) - (v2[0]*v1[1]); \
00089 }
00090
00091 #define IMOD(z,a) ((z) - ((z)/(a))*(a))
00092
00093 #define PATTERN(x,y,z) ( ((z)+16384L)*64536L + \
00094 ((y)+16384L)*32768L + \
00095 ((x)+16384L))
00096 #define FLOOR(x) ((x) >= 0.0 ? floor(x) : (0.0 - floor(0.0 - (x)) - 1.0))
00097 #define FMOD(x,a) ((x) >= 0.0 ? fmod(x,a) :(a - fmod(-(x),a)))
00098 #define ROOT32 0.866025403
00099 #define ROOT3 1.73205080
00100
00101 #define nnNoise(x,y,z) (2.0*(nNoise(x,y,z)-0.5))
00102
00103 #define Noise3(nr,xx,yy,zz) \
00104 { \
00105 nr = 0.5*(1+sin(6*3.1415926*nNoise(xx,yy,zz))); \
00106 }
00107
00108
00109
00110 static double turb=0.1,t1=0.4,t2=0.7,c[3]={255.0,255.0,0.0};
00111 static double x=1.0,y=1.0,z=1.0;
00112 static long tr_type=0,tr_type1=0,tr_type2=0,tr_type3=0;
00113
00114 #if 0
00115 long CALLBACK ExternalTextureStartup(
00116 #else
00117 long _ExternalTextureStartup(
00118 #endif
00119 long frame,long nframes,char *parameter_list){
00120 if(parameter_list[0] != '#'){
00121 MessageBox ( GetFocus(),
00122 (LPCTSTR) "External texture: Startup",
00123 (LPCTSTR) "Parameter list missing",
00124 MB_OK | MB_SYSTEMMODAL );
00125 }
00126 else {
00127 parameter_list++;
00128 sscanf(parameter_list,"%f %f %f %f %f %f %f %f %f %ld %ld %ld %ld",
00129 &c[0],&c[1],&c[2],&turb,&t1,&t2,&x,&y,&z,
00130 &tr_type,&tr_type1,&tr_type2,&tr_type3);
00131 }
00132 return 1;
00133 }
00134
00135 #if 0
00136 long CALLBACK ExternalTextureMorph(
00137 #else
00138 long _ExternalTextureMorph(
00139 #endif
00140 char *parameter_list, double mr){
00141 int i;
00142 double mx,my,mz;
00143 double mturb,mt1,mt2,mc[3];
00144 parameter_list++;
00145 sscanf(parameter_list,"%f %f %f %f %f %f %f %f %f",
00146 &mc[0],&mc[1],&mc[2],&mturb,&mt1,&mt2,&mx,&my,&mz);
00147 t1=mt1+(t1-mt1)*mr;
00148 t2=mt2+(t2-mt2)*mr;
00149 turb=(turb-mturb)*mr;
00150 for(i=0;i<3;i++)c[i]=mc[i]+(c[i]-mc[i])*mr;
00151 x=mx+(x-mx)*mr;
00152 y=my+(y-my)*mr;
00153 z=mz+(z-mz)*mr;
00154 return 1;
00155 }
00156
00157
00158 void Hsv2Rgb(double h, double s, double v,
00159 double *r, double *g, double *b){
00160 double rr,gg,bb,hh,ss,vv,maxcol,mincol;
00161 hh=(double)h; ss=(double)s; vv=(double)v;
00162 mincol=vv*(1.0-ss);
00163 if(hh <= 120.0){bb=mincol;
00164 if(hh <= 60){rr=vv; gg=mincol+hh*(vv-mincol)/(120.0-hh);}
00165 else {gg=vv; rr=mincol+(120.0-hh)*(vv-mincol)/hh;}
00166 }
00167 else if( hh <= 240){rr=mincol;
00168 if(hh <= 180){gg=vv; bb=mincol+(hh-120.0)*(vv-mincol)/(240.0-hh);}
00169 else {bb=vv; gg=mincol+(240.0-hh)*(vv-mincol)/(hh-120.0);}
00170 }
00171 else {gg=mincol;
00172 if(hh <= 300){bb=vv; rr=mincol+(hh-240.0)*(vv-mincol)/(360.0-hh);}
00173 else {rr=vv; bb=mincol+(360.0-hh)*(vv-mincol)/(hh-240.0);}
00174 }
00175 *r = rr;
00176 *g = gg;
00177 *b = bb;
00178 }
00179
00180 void Rgb2Hsv(double rr, double gg, double bb,
00181 double *h, double *s, double *v){
00182 double maxcol,mincol;
00183 maxcol=max(rr,max(gg,bb));
00184 mincol=min(rr,min(gg,bb));
00185 *v=maxcol;
00186 if(maxcol == mincol){*s=0; *h=0;}
00187 else{
00188 *s=(maxcol-mincol)/maxcol;
00189 if(mincol == bb)
00190 *h = 120.0*(gg-mincol)/(rr+gg-2.0*mincol);
00191 else if(mincol == rr)
00192 *h = 120.0*(1.0+(bb-mincol)/(bb+gg-2.0*mincol));
00193 else
00194 *h = 120.0*(2.0+(rr-mincol)/(rr+bb-2.0*mincol));
00195 }
00196 }
00197
00198 double hermite(double t, double tmin, double tmax){
00199 t=(t-tmin)/(tmax-tmin);
00200 return (t - t*t);
00201 }
00202
00203 double sigmoid(double t, double tmin, double tmax){
00204 t=3.1415926*(2.0*(t-tmin)/(tmax-tmin));
00205 return 0.5*(1.0-cos(t));
00206 }
00207
00208 double triangle(double value){
00209 register double offset;
00210 if (value >= 0.0) offset = value - floor(value);
00211 else offset = value - (-1.0 - floor(fabs(value)));
00212 if (offset >= 0.5) return (2.0 * (1.0 - offset));
00213 else return (2.0 * offset);
00214 }
00215
00216 double costab(double value){
00217 if (value < 0.0)return 0.0;
00218 return 0.5*(1.0+cos((value-floor(value))*3.141592657*2));
00219 }
00220
00221 double sintab(double value){
00222 if (value >= 0.0)
00223 return 0.5*(1.0+sin((value-floor(value))*3.141592657*2));
00224 return 0.0;
00225 }
00226
00227 static double ffmod(double x){
00228 if(x < 0){
00229 double a;
00230 a=fmod(-x,1.0);
00231 return 1.0-a;
00232 }
00233 return fmod(x,1.0);
00234 }
00235
00236 static double step(double a, double x){
00237 if(x < a)return 0.0;
00238 return 1.0;
00239 }
00240
00241 static void mix(double *r, double *g, double *b, double mx,
00242 double r1, double g1, double b1,
00243 double r2, double g2, double b2){
00244 *r = mx*r1 + (1.0-mx)*r2;
00245 *g = mx*g1 + (1.0-mx)*g2;
00246 *b = mx*b1 + (1.0-mx)*b2;
00247 }
00248
00249
00250 #include "randno.c"
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269 static long ip[27][3]={
00270 { 0, 0, 0},
00271 { 1, 0, 0},
00272 { 1, 1, 0},
00273 { 0, 1, 0},
00274 {-1, 1, 0},
00275 {-1, 0, 0},
00276 {-1,-1, 0},
00277 { 0,-1, 0},
00278 { 1,-1, 0},
00279 { 0, 0,-1},
00280 { 1, 0,-1},
00281 { 1, 1,-1},
00282 { 0, 1,-1},
00283 {-1, 1,-1},
00284 {-1, 0,-1},
00285 {-1,-1,-1},
00286 { 0,-1,-1},
00287 { 1,-1,-1},
00288 { 0, 0, 1},
00289 { 1, 0, 1},
00290 { 1, 1, 1},
00291 { 0, 1, 1},
00292 {-1, 1, 1},
00293 {-1, 0, 1},
00294 {-1,-1, 1},
00295 { 0,-1, 1},
00296 { 1,-1, 1}
00297 };
00298
00299 #if 0
00300 long CALLBACK ExternalTextureProcedure(
00301 #else
00302 long _ExternalTextureProcedure(
00303 #endif
00304 long coord_type, vector p, vector n,
00305 double alpha, double beta, double gamma,
00306 double bump, double map_x, double map_y,
00307 double *alpha_channel, unsigned char sc[3], double colour[3],
00308 double *reflectivity, double *transparency,
00309 X__SHADER *lpEVI
00310 ){
00311
00312 #if 0
00313
00314 long i;
00315 double a,cc,xx,yy,zz,noiseH,r,g,b;
00316 vector u,v;
00317 xx=alpha / x;
00318 yy=beta / y;
00319 zz=gamma / z;
00320 {
00321 double ss,tt,tbrick,sbrick,w,h,mf=0.03;
00322 ss = xx / 1.0; tt= yy/ 1.0;
00323 if(ffmod(tt*0.5) > 0.5)ss += 0.5;
00324 tbrick=floor(tt);
00325 ss += 0.3*(nNoise(0.0,tbrick*3,0.0) - 0.5);
00326 sbrick=floor(ss);
00327 ss -= sbrick;
00328 tt -= tbrick;
00329 vNoise(v,10*xx,10*yy,0.5);
00330 ss += (v[0]-0.5)*0.02;
00331 tt += (v[1]-0.5)*0.02;
00332 w=step(mf,ss) - step(1-mf,ss);
00333 h=step(mf,tt) - step(1-mf,tt);
00334 mix(&r,&g,&b,w*h,
00335 (double)colour[0]/255.0,(double)colour[1]/255.0,(double)colour[2]/255.0,
00336 (double)c[0]/255.0,(double)c[1]/255.0,(double)c[2]/255.0);
00337 if(w*h == 0){
00338 if(w == 0){
00339 if(ss < mf) VECCOPY(-(1.0-ss/mf)*tAxis_unorm,v)
00340 if(ss > 1-mf)VECCOPY(((ss-(1.0-mf))/mf)*tAxis_unorm,v)
00341 }
00342 else{
00343 if(tt < mf) VECCOPY((1.0-tt/mf)*tAxis_vnorm,v)
00344 if(tt > 1-mf)VECCOPY(-((tt-(1.0-mf))/mf)*tAxis_vnorm,v)
00345
00346 }
00347 VECSUM(n,0.5*v,n)
00348 vNoise(u,40*xx,40*yy,0.5);
00349 VECSUM(0.2*u,n,n)
00350 normalize(n);
00351 }
00352 else{
00353 vNoise(v,2*xx,2*yy,0.5);
00354 VECSCALE(0.2,v,v)
00355 VECSUM(n,v,n)
00356 vNoise(v,20*xx,20*yy,0.5);
00357 VECSCALE(0.1,v,v)
00358 VECSUM(n,v,n)
00359 if(ss > 1 - 2*mf)VECSUM(0.3*tAxis_unorm,n,n)
00360 else if(ss < 2*mf)VECSUM(-0.3*tAxis_unorm,n,n)
00361 else if(tt < 2*mf)VECSUM(0.3*tAxis_vnorm,n,n)
00362 else if(tt > 1 - 2*mf)VECSUM(-0.3*tAxis_vnorm,n,n)
00363 normalize(n);
00364 noiseH=nNoise(xx*5,yy*5,0.5);
00365 r -= (noiseH*0.05);
00366 g -= (noiseH*0.05);
00367 b -= (noiseH*0.05);
00368 }
00369 r=max(r,0.0); g=max(g,0.0); b=max(b,0.0);
00370 }
00371 colour[0] = r * 255.0;
00372 colour[1] = g * 255.0;
00373 colour[2] = b * 255.0;
00374 #endif
00375
00376
00377 #if 0
00378 long i;
00379 double a,cc,xx,yy,zz,noiseH,r,g,b;
00380 vector u,v,BozoTurbulence;
00381 xx=alpha / x;
00382 yy=beta / y;
00383 zz=gamma / z;
00384
00385 noiseH = nNoise(xx, yy, zz);
00386 noiseH = sintab(noiseH*10.0);
00387 if(noiseH > 0.1){
00388 noiseH=(noiseH-0.1)/(1.0-0.1);
00389 r=(noiseH*(double)c[0]+(1.0-noiseH)*(double)colour[0]);
00390 g=(noiseH*(double)c[1]+(1.0-noiseH)*(double)colour[1]);
00391 b=(noiseH*(double)c[2]+(1.0-noiseH)*(double)colour[2]);
00392 r=r/255.0;
00393 g=g/255.0;
00394 b=b/255.0;
00395 }
00396 else{
00397 r=colour[0]/255.0;
00398 g=colour[1]/255.0;
00399 b=colour[2]/255.0;
00400 }
00401 colour[0] = r * 255.0;
00402 colour[1] = g * 255.0;
00403 colour[2] = b * 255.0;
00404 #endif
00405
00406 #if 0
00407
00408 {double cellsize;
00409 int ncells=1,
00410 npoints=8;
00411 double rmax=4.0,
00412 rmin=0.5;
00413 double rr,ss,tt,scell,tcell,sctr,tctr,sa,angle;
00414 vector p0,p1,d0,d1,dr;
00415 cellsize=1.0/ncells;
00416 ss=yy*ncells; tt=xx*ncells;
00417 sctr=0.5; tctr=0.5;
00418 scell=FLOOR(ss); tcell=FLOOR(tt);
00419 sctr=scell+0.5; tctr=tcell+0.5;
00420
00421
00422
00423
00424 ss=ss*cellsize-sctr;
00425 tt=tt*cellsize-tctr;
00426
00427 sa=2*3.1415926/npoints;
00428 p0[0]=rmax; p0[1]=0.0; p0[2]=0.0;
00429 p1[0]=rmin*cos(sa/2); p1[1]=rmin*sin(sa/2); p1[2]=0.0;
00430
00431 angle=atan2(ss,tt)+3.1415926;
00432 rr=sqrt(ss*ss+tt*tt);
00433 angle /= sa;
00434 angle -= floor(angle);
00435 if(angle < 0.5)angle = 1-angle;
00436 VECSUB(p1,p0,d0)
00437 d1[0]=rr*cos(angle); d1[1]=rr*sin(angle); d1[2]=0.0;
00438 VECSUB(d1,p0,d1)
00439 CROSS(d0,d1,dr)
00440 mix(&r,&g,&b,step(0,dr[2]),
00441 (double)c[0]/255.0,
00442 (double)c[1]/255.0,
00443 (double)c[2]/255.0,
00444 (double)colour[0]/255.0,
00445 (double)colour[1]/255.0,
00446 (double)colour[2]/255.0
00447 );
00448
00449 }
00450 colour[0] = r * 255.0;
00451 colour[1] = g * 255.0;
00452 colour[2] = b * 255.0;
00453 #endif
00454
00455 #if 0
00456
00457 long i;
00458 double a,cc,xx,yy,zz,noiseH,r,g,b;
00459 vector u,v,BozoTurbulence;
00460 xx=alpha / x;
00461 yy=beta / y;
00462 zz=gamma / z;
00463 {
00464 static vector vclr[81];
00465 static double dpoint[81];
00466 static double dradius[81];
00467 static vector pp[81];
00468 double dx,dy,dz,cx,cy,cz,zb,ccc,dc,zbb,radius;
00469 long ix,iy,iz;
00470 BOOL ins;
00471 long j,jid,id,pattern,patterni;
00472
00473 long N=1;
00474 double bradius=0.5,lradius=0.01;
00475
00476
00477
00478 double len,rad;
00479 vector ppc;
00480
00481 xx *= 4.0;
00482 yy *= 4.0;
00483 zz *= 4.0;
00484
00485
00486
00487
00488
00489
00490 id=0;
00491 ix=FLOOR(xx);
00492 iy=FLOOR(yy);
00493 iz=FLOOR(zz);
00494 cx=xx-(double)ix;
00495 cy=yy-(double)iy;
00496 cz=zz-(double)iz;
00497 zb=-10.0;
00498 ins=TRUE;
00499 id = -1;
00500 len=sqrt(tAxis_u[0]*tAxis_u[0]+
00501 tAxis_u[1]*tAxis_u[1]+
00502 tAxis_u[2]*tAxis_u[2]);
00503 VECCOPY(-tAxis_n,u)
00504 VECSCALE(len,u,u)
00505 VECCOPY(tAxis_o,v)
00506 VECSUM(v,cx*tAxis_u,v)
00507 VECSUM(v,cy*tAxis_v,v)
00508 VECSUM(v,cz*u,v)
00509 for(j=0;j<27;j++){
00510 pattern=PATTERN(ix+ip[j][0],iy+ip[j][1],iz+ip[j][2]);
00511 pattern=IMOD(N*pattern,1900);
00512 for(i=0;i<N;i++){
00513 jid=j*N+i;
00514 patterni=pattern+i;
00515 VECSUM((double)ip[j],rand_v[patterni],ppc)
00516 VECSUM(tAxis_o,ppc[0]*tAxis_u,pp[jid])
00517 VECSUM(pp[jid],ppc[1]*tAxis_v,pp[jid])
00518 VECSUM(pp[jid],ppc[2]*u, pp[jid])
00519
00520 VECCOPY(rand_v[patterni],vclr[jid])
00521 radius=(bradius+lradius*(rand_v[patterni][1]-0.5))*len;
00522 dradius[jid]=radius;
00523 dpoint[jid] = -1.0;
00524 dx=(v[0]-pp[jid][0]);
00525 dy=(v[1]-pp[jid][1]);
00526 dz=(v[2]-pp[jid][2]);
00527 if(fabs(dx) > radius)continue;
00528 if(fabs(dy) > radius)continue;
00529 if(fabs(dz) > radius)continue;
00530 if((a=sqrt(dx*dx+dy*dy+dz*dz)) < radius){
00531 dpoint[jid]=a;
00532 dc=(radius-a);
00533 if(dc > zb){
00534 id=jid;
00535 zb=dc;
00536 }
00537 }
00538 }
00539 }
00540 if(id >= 0 && ins){
00541 r=colour[0]/255.0;
00542 g=colour[1]/255.0;
00543 b=colour[2]/255.0;
00544 if(1){
00545 VECCOPY(pp[id],ppc)
00546 rad=dradius[id];
00547 VECSUB(v,ppc,u)
00548 if((a=sqrt((u[0])*(u[0])+
00549 (u[1])*(u[1])+
00550 (u[2])*(u[2]))) < rad){
00551 double mu,moddn,rmu;
00552 vector c,dn;
00553 mu=DOT(u,n);
00554 c[0]=ppc[0]+mu*n[0];
00555 c[1]=ppc[1]+mu*n[1];
00556 c[2]=ppc[2]+mu*n[2];
00557 VECSUB(v,c,dn)
00558 moddn=sqrt(dn[0]*dn[0]+dn[1]*dn[1]+dn[2]*dn[2]);
00559 rmu=sqrt(rad*rad-mu*mu);
00560 if(moddn < rmu){
00561 a=1.0-moddn/rmu;
00562 normalize(dn);
00563
00564
00565 a=sin(a*1.57079);
00566
00567
00568
00569
00570 #if 0
00571 if(a < 0.06){
00572 a=0.1;
00573 }
00574 else{
00575 a=1;
00576 noiseH=nNoise(xx*5,yy*5,zz*5)-0.5;
00577 r -= (0.18+(noiseH*0.11));
00578 g -= (0.18+(noiseH*0.11));
00579 b -= (0.18+(noiseH*0.11));
00580 r=max(r,0.0); g=max(g,0.0); b=max(b,0.0);
00581 }
00582 #endif
00583
00584 VECSUM((1.0-a)*dn,(a)*n,n)
00585
00586
00587
00588 normalize(n);
00589
00590
00591
00592
00593 }
00594 }
00595 }
00596 }
00597 else{
00598 r=colour[0]/255.0;
00599 g=colour[1]/255.0;
00600 b=colour[2]/255.0;
00601
00602
00603
00604
00605
00606
00607 }
00608 }
00609 colour[0] = r * 255.0;
00610 colour[1] = g * 255.0;
00611 colour[2] = b * 255.0;
00612 #endif
00613
00614 #if 0
00615
00616 vector pp[22]={{0.25,0.0, 0.0},
00617 {0.75,0.0, 0.0},
00618 {0.0, ROOT32/2, 0.0},
00619 {0.5, ROOT32/2, 0.0},
00620 {1.0, ROOT32/2, 0.0},
00621 {0.25,ROOT32, 0.0},
00622 {0.75,ROOT32, 0.0},
00623 {0.0, 1.0/2.0/ROOT3-ROOT32/2,ROOT32/2.0},
00624 {0.5, 1.0/2.0/ROOT3-ROOT32/2,ROOT32/2.0},
00625 {1.0, 1.0/2.0/ROOT3-ROOT32/2,ROOT32/2.0},
00626 {0.25,1.0/2.0/ROOT3, ROOT32/2.0},
00627 {0.75,1.0/2.0/ROOT3, ROOT32/2.0},
00628 {0.0, 1.0/2.0/ROOT3+ROOT32/2,ROOT32/2.0},
00629 {0.5, 1.0/2.0/ROOT3+ROOT32/2,ROOT32/2.0},
00630 {1.0, 1.0/2.0/ROOT3+ROOT32/2,ROOT32/2.0},
00631 {0.25,0.0, ROOT32},
00632 {0.75,0.0, ROOT32},
00633 {0.0, ROOT32/2, ROOT32},
00634 {0.5, ROOT32/2, ROOT32},
00635 {1.0, ROOT32/2, ROOT32},
00636 {0.25,ROOT32, ROOT32},
00637 {0.75,ROOT32, ROOT32}};
00638 double dx,dy,dz,zb;
00639 double xr,xl,yr,yl,zr,zl;
00640 long i;
00641 double a,cc,xx,yy,zz,r,g,b;
00642 vector u,v;
00643 xx=alpha / x;
00644 yy=beta / y;
00645 zz=gamma / z;
00646 xx += 0.11*sin(FMOD(3*zz,2*3.1415926));
00647 xx += 0.2*sin(FMOD(0.1*yy,2*3.1415926));
00648 yy += 0.15*cos(FMOD(4*xx,2*3.1415926));
00649 yy += 0.2*sin(FMOD(0.1*zz,2*3.1415926));
00650 zz += 0.18*cos(FMOD(5*yy,2*3.1415926));
00651 zz += 0.2*sin(FMOD(0.1*xx,2*3.1415926));
00652 cc=0.25;
00653 yy /= ROOT32;
00654 xx=FMOD(xx,1.0);
00655 yy=FMOD(yy,ROOT32);
00656 zz /= ROOT32;
00657 zz=FMOD(zz,ROOT32);
00658 zb=0.0;
00659 r=colour[0];
00660 g=colour[1];
00661 b=colour[2];
00662 for(i=0;i<22;i++){
00663 dx=(xx-pp[i][0]);
00664 dy=(yy-pp[i][1]);
00665 dz=(zz-pp[i][2]);
00666 if((a=sqrt(dx*dx+dy*dy+dz*dz)) < cc){
00667 if((cc-a) > zb){
00668 zb=(cc-a);
00669 r=c[0];
00670 g=c[1];
00671 b=c[2];
00672 if(a > 0.20){
00673 mix(&r,&g,&b,(a-0.20)/(cc-0.20),
00674 (double)colour[0],
00675 (double)colour[1],
00676 (double)colour[2],
00677 r,g,b);
00678 }
00679 }
00680 }
00681 }
00682 colour[0] = r;
00683 colour[1] = g;
00684 colour[2] = b;
00685
00686 {
00687 long k;
00688 double xm[]={-1, 1,-1, 1,-1, 1,-1, 1,-1, 1, 0, 0, 0, 0},
00689 ym[]={-1,-1, 1, 1,-1,-1, 1, 1, 0, 0,-1, 1, 0, 0},
00690 zm[]={-1,-1,-1,-1, 1, 1, 1, 1, 0, 0, 0, 0,-1, 1};
00691 double delta,xxx,yyy,zzz;
00692 cc=0.14;
00693 cc=0.09; delta=0.12;
00694 xxx=xx; yyy=yy; zzz=zz;
00695 for(k=0;k<14;k++){
00696 zb=0.0;
00697 r=colour[0];
00698 g=colour[1];
00699 b=colour[2];
00700 xx = xxx+delta*xm[k]; yy = yyy+delta*ym[k]; zz = zzz+delta*zm[k];
00701 for(i=0;i<22;i++){
00702 dx=(xx-pp[i][0]);
00703 dy=(yy-pp[i][1]);
00704 dz=(zz-pp[i][2]);
00705 if(fabs(dx) > cc)continue;
00706 if(fabs(dy) > cc)continue;
00707 if(fabs(dz) > cc)continue;
00708 if((a=sqrt(dx*dx+dy*dy+dz*dz)) < cc){
00709 if((cc-a) > zb){
00710 zb=(cc-a);
00711 r=96;
00712 g=96;
00713 b=96;
00714 if(a > 0.01){
00715 mix(&r,&g,&b,(a-0.01)/(cc-0.01),
00716 (double)colour[0],
00717 (double)colour[1],
00718 (double)colour[2],
00719 r,g,b);
00720 }
00721 }
00722 }
00723 }
00724 colour[0] = r;
00725 colour[1] = g;
00726 colour[2] = b;
00727 }
00728 }
00729 #endif
00730
00731
00732 return 1;
00733 }
00734
00735 #if 0
00736 void CALLBACK ExternalTextureClose(void){
00737 #else
00738 void _ExternalTextureClose(void){
00739 #endif
00740 }
00741
00742 void CentreDialogOnScreen(HWND hwnd){
00743 RECT rcDlg;
00744 long Xres,Yres;
00745 Yres=GetSystemMetrics(SM_CYSCREEN);
00746 Xres=GetSystemMetrics(SM_CXSCREEN);
00747 GetWindowRect(hwnd,&rcDlg);
00748 OffsetRect(&rcDlg,-rcDlg.left,-rcDlg.top);
00749 OffsetRect(&rcDlg,(Xres-rcDlg.right)/2,(Yres-rcDlg.bottom)/2);
00750 SetWindowPos(hwnd,HWND_TOP,rcDlg.left,rcDlg.top,0,0,SWP_NOSIZE);
00751 return;
00752 }
00753
00754 static void SetColour(double *colour, HWND parent){
00755 CHOOSECOLOR cc;
00756 static COLORREF CustColours[16]={
00757 RGB(255,255,255), RGB(239,239,239), RGB(223,223,223), RGB(207,207,207),
00758 RGB(191,191,191), RGB(175,175,175), RGB(159,159,159), RGB(143,143,143),
00759 RGB(127,127,127), RGB(111,111,111), RGB( 95, 95, 95), RGB( 79, 79, 79),
00760 RGB( 63, 63, 63), RGB( 47, 47, 47), RGB( 31, 31, 31), RGB( 15, 15, 15) };
00761 cc.lStructSize=sizeof(CHOOSECOLOR);
00762 cc.hwndOwner=parent;
00763 cc.rgbResult=RGB((BYTE)colour[0],(BYTE)colour[1],(BYTE)colour[2]);
00764 cc.lpCustColors=(LPDWORD)CustColours;
00765 cc.Flags= CC_RGBINIT;
00766 cc.lCustData=(DWORD)0;
00767 if(ChooseColor(&cc)){
00768 colour[0]=(double)GetRValue(cc.rgbResult);
00769 colour[1]=(double)GetGValue(cc.rgbResult);
00770 colour[2]=(double)GetBValue(cc.rgbResult);
00771 }
00772 }
00773
00774 BOOL CALLBACK BozoDlgProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam);
00775
00776 #if 0
00777 char * CALLBACK SetExternalParameters(
00778 #else
00779 char * _SetExternalParameters(
00780 #endif
00781 char *Op,
00782 HWND hWnd,
00783 X__MEMORY_MANAGER *lpEVI
00784 ){
00785 char szbuf[255],*Op1;
00786 if(Op != NULL){
00787 Op1=Op;
00788 Op1++;
00789 sscanf(Op1,"%f %f %f %f %f %f %f %f %f %ld %ld %ld %ld",
00790 &c[0],&c[1],&c[2],&turb,&t1,&t2,&x,&y,&z,
00791 &tr_type,&tr_type1,&tr_type2,&tr_type3);
00792 }
00793 if(DialogBox(hDLLinstance,MAKEINTRESOURCE(DLG_BOZO),hWnd,
00794 (DLGPROC)BozoDlgProc) == FALSE)return Op;
00795 if(Op != NULL)CALL_FREE(Op);
00796 sprintf(szbuf,"# %.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f %ld %ld %ld %ld",
00797 c[0],c[1],c[2],turb,t1,t2,x,y,z,tr_type,tr_type1,tr_type2,tr_type3);
00798 if((Op=(char *)CALL_MALLOC(strlen(szbuf)+1)) == NULL){
00799 MessageBox (GetFocus(),"External shader: Out of memory","Error",
00800 MB_OK|MB_TASKMODAL|MB_ICONSTOP);
00801 return NULL;
00802 }
00803 strcpy(Op,szbuf);
00804 return Op;
00805 }
00806
00807 BOOL CALLBACK BozoDlgProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam){
00808 char str[16];
00809 switch( msg ) {
00810 case WM_INITDIALOG:
00811 sprintf(str,"%.2f",turb);
00812 SendDlgItemMessage(hwnd,DLG_BOZO_TURB,WM_SETTEXT,0,(LPARAM)str);
00813 SendDlgItemMessage(hwnd,DLG_BOZO_TURB,EM_LIMITTEXT,(WPARAM)12,0);
00814 sprintf(str,"%.2f",t1);
00815 SendDlgItemMessage(hwnd,DLG_BOZO_T1,WM_SETTEXT,0,(LPARAM)str);
00816 SendDlgItemMessage(hwnd,DLG_BOZO_T1,EM_LIMITTEXT,(WPARAM)12,0);
00817 sprintf(str,"%.2f",t2);
00818 SendDlgItemMessage(hwnd,DLG_BOZO_T2,WM_SETTEXT,0,(LPARAM)str);
00819 SendDlgItemMessage(hwnd,DLG_BOZO_T2,EM_LIMITTEXT,(WPARAM)12,0);
00820 sprintf(str,"%.2f",x);
00821 SendDlgItemMessage(hwnd,DLG_BOZO_XSCALE,WM_SETTEXT,0,(LPARAM)str);
00822 SendDlgItemMessage(hwnd,DLG_BOZO_XSCALE,EM_LIMITTEXT,(WPARAM)12,0);
00823 sprintf(str,"%.2f",y);
00824 SendDlgItemMessage(hwnd,DLG_BOZO_YSCALE,WM_SETTEXT,0,(LPARAM)str);
00825 SendDlgItemMessage(hwnd,DLG_BOZO_YSCALE,EM_LIMITTEXT,(WPARAM)12,0);
00826 sprintf(str,"%.2f",z);
00827 SendDlgItemMessage(hwnd,DLG_BOZO_ZSCALE,WM_SETTEXT,0,(LPARAM)str);
00828 SendDlgItemMessage(hwnd,DLG_BOZO_ZSCALE,EM_LIMITTEXT,(WPARAM)12,0);
00829 if(tr_type == 0)
00830 SendDlgItemMessage(hwnd,DLG_BOZO_SEMI,BM_SETCHECK,TRUE,0);
00831 else
00832 SendDlgItemMessage(hwnd,DLG_BOZO_SETT,BM_SETCHECK,TRUE,0);
00833 if(tr_type1 == 1)
00834 SendDlgItemMessage(hwnd,DLG_BOZO_CLEARC,BM_SETCHECK,TRUE,0);
00835 if(tr_type2 == 1)
00836 SendDlgItemMessage(hwnd,DLG_BOZO_CLEARS,BM_SETCHECK,TRUE,0);
00837 if(tr_type3 == 1)
00838 SendDlgItemMessage(hwnd,DLG_BOZO_CLEAR3,BM_SETCHECK,TRUE,0);
00839 CentreDialogOnScreen(hwnd);
00840 return TRUE;
00841 case WM_DRAWITEM:{
00842 LPDRAWITEMSTRUCT lpdis;
00843 HBRUSH hbr,hbrold;
00844 BYTE r,g,b;
00845 lpdis=(LPDRAWITEMSTRUCT)lparam;
00846 if(lpdis->CtlID == DLG_BOZO_COLOUR){
00847 r=(BYTE)c[0]; g=(BYTE)c[1]; b=(BYTE)c[2];
00848 if(lpdis->itemState & ODS_SELECTED)
00849 InvertRect(lpdis->hDC,&(lpdis->rcItem));
00850 else{
00851 hbr=CreateSolidBrush(RGB(r,g,b));
00852 hbrold=SelectObject(lpdis->hDC,hbr);
00853 Rectangle(lpdis->hDC,lpdis->rcItem.left,lpdis->rcItem.top,
00854 lpdis->rcItem.right,lpdis->rcItem.bottom);
00855 SelectObject(lpdis->hDC,hbrold);
00856 DeleteObject(hbr);
00857 }
00858 }
00859 }
00860 break;
00861 case WM_COMMAND:
00862 switch(LOWORD(wparam)){
00863 case DLG_BOZO_COLOUR:
00864 SetColour(c,hwnd);
00865 InvalidateRect(GetDlgItem(hwnd,DLG_BOZO_COLOUR),NULL,FALSE);
00866 break;
00867 case IDCANCEL:
00868 case DLG_BOZO_CANCEL:
00869 EndDialog(hwnd,FALSE);
00870 return(TRUE);
00871 case IDOK:
00872 case DLG_BOZO_OK:
00873 if(GetDlgItemText(hwnd,DLG_BOZO_TURB,str,10) == 0)
00874 EndDialog(hwnd,FALSE);
00875 if((turb=atof(str)) == 0)EndDialog(hwnd,FALSE);
00876 if(GetDlgItemText(hwnd,DLG_BOZO_T1,str,10) == 0)
00877 EndDialog(hwnd,FALSE);
00878 if((t1=atof(str)) == 0)EndDialog(hwnd,FALSE);
00879 if(GetDlgItemText(hwnd,DLG_BOZO_T2,str,10) == 0)
00880 EndDialog(hwnd,FALSE);
00881 if((t2=atof(str)) == 0)EndDialog(hwnd,FALSE);
00882 if(GetDlgItemText(hwnd,DLG_BOZO_XSCALE,str,10) == 0)
00883 EndDialog(hwnd,FALSE);
00884 if((x=atof(str)) == 0)EndDialog(hwnd,FALSE);
00885 if(GetDlgItemText(hwnd,DLG_BOZO_YSCALE,str,10) == 0)
00886 EndDialog(hwnd,FALSE);
00887 if((y=atof(str)) == 0)EndDialog(hwnd,FALSE);
00888 if(GetDlgItemText(hwnd,DLG_BOZO_ZSCALE,str,10) == 0)
00889 EndDialog(hwnd,FALSE);
00890 if((z=atof(str)) == 0)EndDialog(hwnd,FALSE);
00891 if(SendDlgItemMessage(hwnd,DLG_BOZO_SETT,BM_GETCHECK,0,0))
00892 tr_type=1; else tr_type=0;
00893 if(SendDlgItemMessage(hwnd,DLG_BOZO_CLEARC,BM_GETCHECK,0,0))
00894 tr_type1=1; else tr_type1=0;
00895 if(SendDlgItemMessage(hwnd,DLG_BOZO_CLEARS,BM_GETCHECK,0,0))
00896 tr_type2=1; else tr_type2=0;
00897 if(SendDlgItemMessage(hwnd,DLG_BOZO_CLEAR3,BM_GETCHECK,0,0))
00898 tr_type3=1; else tr_type3=0;
00899 EndDialog(hwnd,TRUE);
00900 return(TRUE);
00901 default:
00902 break;
00903 }
00904 break;
00905 default: break;
00906 }
00907 return FALSE;
00908 }
00909
00910
00911