FLARE.C

Go to the documentation of this file.
00001 /* --
00002 OpenFX version 1.0 - Modelling, Animation and Rendering Package
00003 Copyright (C) 2000 OpenFX Development Team
00004 
00005 This program is free software; you can redistribute it and/or
00006 modify it under the terms of the GNU General Public License
00007 as published by the Free Software Foundation; either version 2
00008 of the License, or (at your option) any later version.
00009 
00010 This program is distributed in the hope that it will be useful,
00011 but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 GNU General Public License for more details.
00014 
00015 You should have received a copy of the GNU General Public License
00016 along with this program; if not, write to the Free Software
00017 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00018 
00019 You may contact the OpenFX development team via elecronic mail
00020 at core@openfx.org, or visit our website at http://openfx.org for
00021 further information and support details.
00022 -- */
00023 
00024 /* flare.c  image post-processor                                         */
00025 /*                                                                       */
00026 
00027 #include <stdlib.h>
00028 #include <stdio.h>
00029 #include <float.h>
00030 #include <math.h>
00031 #include <windows.h>
00032 #include <commctrl.h>
00033 #include "struct.h"           /* general structures    */
00034 #include "..\common\postprocess\ximage.h"
00035 #include "local.h"
00036 
00037 //FILE *debug;
00038 
00039 #include "flare.h"
00040 
00041 #if __X__MIPS__
00042 BOOL WINAPI _CRT_INIT(HINSTANCE ,DWORD , LPVOID );
00043 #endif
00044 
00045 static HINSTANCE hDLLinstance=NULL; /* use to pick up resources from DLL   */
00046 
00047 #include "utils.h"
00048 
00049 #include "paint.c"
00050 
00051 #if __WATCOMC__
00052 int APIENTRY LibMain(HANDLE hDLL, DWORD dwReason, LPVOID lpReserved){
00053 #elif __BC__
00054 BOOL WINAPI DllEntryPoint(HANDLE hDLL, DWORD dwReason, LPVOID lpReserved){
00055 #else
00056 BOOL WINAPI DllMain(HANDLE hDLL, DWORD dwReason, LPVOID lpReserved){
00057 #endif
00058   switch (dwReason) {
00059     case DLL_PROCESS_ATTACH:
00060 #if __X__MIPS__
00061       if(!_CRT_INIT(hDLL,dwReason,lpReserved))return(int)FALSE;
00062 #endif
00063       hDLLinstance = hDLL;  /* handle to DLL file */
00064       break;
00065     case DLL_PROCESS_DETACH:
00066 #if __X__MIPS__
00067       if(!_CRT_INIT(hDLL,dwReason,lpReserved))return(int)FALSE;
00068 #endif
00069       break;
00070   }
00071 return (int)TRUE;
00072 }
00073 
00074 #if __SC__
00075 #pragma startaddress(DllMain)
00076 #endif
00077 
00078 static void  BlurBuffer(fullscreenbuffer *s, long Xmax, long Ymax){
00079   long i,j;
00080   double sum;
00081   for(i=0;i<Ymax-1;i++)for(j=0;j<Xmax-1;j++){
00082     sum  = (double)((s+i*Xmax+j)->R);
00083     sum += (double)((s+i*Xmax+j+1)->R);
00084     sum += (double)((s+(i+1)*Xmax+j)->R);
00085     sum += (double)((s+(i+1)*Xmax+j+1)->R);
00086     (s+i*Xmax+j)->R = (unsigned char)(sum*0.25);
00087     sum  = (double)((s+i*Xmax+j)->G);
00088     sum += (double)((s+i*Xmax+j+1)->G);
00089     sum += (double)((s+(i+1)*Xmax+j)->G);
00090     sum += (double)((s+(i+1)*Xmax+j+1)->G);
00091     (s+i*Xmax+j)->G = (unsigned char)(sum*0.25);
00092     sum  = (double)((s+i*Xmax+j)->B);
00093     sum += (double)((s+i*Xmax+j+1)->B);
00094     sum += (double)((s+(i+1)*Xmax+j)->B);
00095     sum += (double)((s+(i+1)*Xmax+j+1)->B);
00096     (s+i*Xmax+j)->B = (unsigned char)(sum*0.25);
00097   }
00098   return;
00099 }
00100 
00101 static void MixBuffer(fullscreenbuffer *s, fullscreenbuffer *t,
00102                       long Xmax, long Ymax){
00103  int r,g,b;
00104  long i,j;
00105  for(i=0;i<Ymax-1;i++)for(j=0;j<Xmax-1;j++){
00106    r=(int)t->R+(int)s->R;
00107    g=(int)t->G+(int)s->G;
00108    b=(int)t->B+(int)s->B;
00109    t->R=(r>255) ? 255:r;
00110    t->G=(g>255) ? 255:g;
00111    t->B=(b>255) ? 255:b;
00112    s++; t++;
00113  }
00114  return;
00115 }
00116 
00117 double DistFromHidingObject(int x, int y, double d,
00118                             double *Zb,
00119                             int border, int X, int Y){
00120  long i,j;
00121  double e,*Z,dmin,dr;
00122  dmin=(double)(X*10);
00123  for(i=x-border;i<=x+border;i++)for(j=y-border;j<=y+border;j++){
00124    if(i < 0 || i >= X || j < 0 || j >= Y)continue;
00125    e = *(Zb + (j * X) + i);
00126    if(e < d){
00127      dr=sqrt((double)(i-x)*(double)(i-x) + (double)(j-y)*(double)(j-y));
00128      if(dr < dmin)dmin=dr;
00129    }
00130  }
00131  return dmin;
00132 }
00133 
00134 double DistFromVisibleObject(int x, int y, double d,
00135                             double *Zb,
00136                             int border, int X, int Y){
00137  long i,j;
00138  double e,*Z,dmin,dr;
00139  dmin=(double)(X*10);
00140  for(i=x-border;i<=x+border;i++)for(j=y-border;j<=y+border;j++){
00141    if(i < 0 || i >= X || j < 0 || j >= Y)continue;
00142    e = *(Zb + (j * X) + i);
00143    if(e > d){
00144      dr=sqrt((double)(i-x)*(double)(i-x) + (double)(j-y)*(double)(j-y));
00145      if(dr < dmin)dmin=dr;
00146    }
00147  }
00148  return dmin;
00149 }
00150 
00151 double Grad(double x, double y1, double y2, int x1, int x2){
00152  double g;
00153  if(x <= x1)return y1;
00154  if(x >= x2)return y2;
00155  g=(y2-y1)/(double)(x2-x1);
00156  return y1+g*(x-(double)x1);
00157 }
00158 
00159 void DrawInBuffer(fullscreenbuffer *Screen, int Xmax, int Ymax,
00160                   int x, int y, unsigned char v,
00161                   double rr, double gg, double bb){
00162  int r,g,b;
00163  fullscreenbuffer *S;
00164  if(x < 0 || y < 0 || x >= Xmax || y >= Ymax)return;
00165  S=(Screen+y*Xmax+x);
00166  r=(int)S->R+(int)((double)v*rr);
00167  g=(int)S->G+(int)((double)v*gg);
00168  b=(int)S->B+(int)((double)v*bb);
00169  S->R=(r>255) ? 255:r;
00170  S->G=(g>255) ? 255:g;
00171  S->B=(b>255) ? 255:b;
00172 }
00173 
00174 #define frac(z) fmod(z,1.0)
00175 
00176 void DrawAApixel(double x, double y, double w, double h, double C,
00177                  fullscreenbuffer *S, int X, int Y,
00178                  double r, double g, double b){
00179   int xa,xb,ya,yb,i,j,brite;
00180   double x2,y2,lfrac,rfrac,tfrac,bfrac,xfrac,yfrac;
00181   brite=(int)C;
00182   if(x < 0 || y < 0)return;
00183   x -= w*0.5; y -= h*0.5;
00184   x2 = x + w;
00185   y2 = y + w;
00186   xa = (int)x;
00187   xb = (int)x2;
00188   ya = (int)y;
00189   yb = (int)y2;
00190   lfrac = 1.0-frac(x);
00191   rfrac = frac(x2);
00192   tfrac = 1.0-frac(y);
00193   bfrac = frac(y2);
00194   if (xa==xb) {
00195     xfrac = lfrac+rfrac-1.0;
00196     if (ya==yb) {
00197       DrawInBuffer(S,X,Y,xa,ya,xfrac*(tfrac+bfrac-1.0)*brite,r,g,b);
00198     }
00199     else {
00200       DrawInBuffer(S,X,Y,xa,ya,xfrac*tfrac*brite,r,g,b);
00201       for (j=ya+1; j<yb; j++) DrawInBuffer(S,X,Y,xa,j,xfrac*brite,r,g,b);
00202       DrawInBuffer(S,X,Y,xa,yb,xfrac*bfrac*brite,r,g,b);
00203     }
00204   }
00205   else {
00206     if (ya==yb) {
00207       yfrac = tfrac+bfrac-1.0;
00208       DrawInBuffer(S,X,Y,xa,ya,yfrac*lfrac*brite,r,g,b);
00209       for (i=xa+1; i<xb; i++) DrawInBuffer(S,X,Y,i,ya,yfrac*brite,r,g,b);
00210       DrawInBuffer(S,X,Y,xb,ya,yfrac*rfrac*brite,r,g,b);
00211     }
00212     else {
00213       DrawInBuffer(S,X,Y,xa,ya,tfrac*lfrac*brite,r,g,b);
00214       for (i=xa+1; i<xb; i++) DrawInBuffer(S,X,Y,i,ya,tfrac*brite,r,g,b);
00215       DrawInBuffer(S,X,Y,xb,ya,tfrac*rfrac*brite,r,g,b);
00216       for (j=ya+1; j<yb; j++) {
00217         DrawInBuffer(S,X,Y,xa,j,lfrac*brite,r,g,b);
00218         for (i=xa+1; i<xb; i++)DrawInBuffer(S,X,Y,i,j,brite,r,g,b);
00219         DrawInBuffer(S,X,Y,xb,j,rfrac*brite,r,g,b);
00220       }
00221       DrawInBuffer(S,X,Y,xa,yb,bfrac*lfrac*brite,r,g,b);
00222       for (i=xa+1; i<xb; i++) DrawInBuffer(S,X,Y,i,yb,bfrac*brite,r,g,b);
00223       DrawInBuffer(S,X,Y,xb,yb,bfrac*rfrac*brite,r,g,b);
00224     }
00225   }
00226 }
00227 
00228 #define DIST(i,j)  sqrt((double)i * (double)i + (double)j * (double)j)
00229 
00230 static double GetW(double l, double dx, double dy,
00231                    double Wmin, double Wmax, double iScale,
00232                    BOOL linear){
00233  double d,f;
00234  d=DIST(dx,dy);
00235  f=d/l;
00236  if(linear){
00237    if(f < 0.5)return (Wmin+2.0*f*(Wmax-Wmin))*(double)iScale;
00238    return (Wmin+(Wmax-Wmin)*2.0*(1.0-f))*(double)iScale;
00239  }
00240  else{
00241    double y,dx,dw;
00242    dw=(Wmax-Wmin);
00243    if(f < 0.5)f=1.0-f;
00244    f = 2.0*(f-0.5);
00245    y=Wmax-dw*f*f*f;
00246    return y*(double)iScale;
00247  }
00248  return 0.0;
00249 }
00250 
00251 static double GetC(double l, double dx, double dy,
00252                    double Wmin, double Wmax, double iScale,
00253                    BOOL linear){
00254  double d,f;
00255  d=DIST(dx,dy);
00256  f=d/l;
00257  if(f < 0.5)return Wmax; //(Wmin+2.0*f*(Wmax-Wmin))*(double)iScale;
00258  return (Wmin+(Wmax-Wmin)*2.0*(1.0-f));
00259 }
00260 
00261 static void DrawFlareInBuffer(long x, long y, long idx, long idy,
00262                               fullscreenbuffer *Screen,
00263                               long X, long Y, double iScale,
00264                               double Cin,
00265                               double Wmin, double Wmax,
00266                               double z, float *Zb,
00267                               BOOL bDraw, BOOL linear){
00268  long i,j;
00269  double grad,error,W,l,C;
00270  if(iScale <1.1)Cin *= 2; Cin=min(255,Cin); C=Cin;
00271  if(idx == 0 && idy == 0)return;
00272  l=DIST(idx,idy);
00273  if(abs(idx) >= abs(idy)){
00274    grad=(double)idy/(double)idx; j=y;
00275    if(idy >= 0)error = -0.5; else error = 0.5;
00276    if(idx >= 0){
00277      for(i=x;i<x+idx;i++){
00278        error += grad;
00279        if(idy >= 0){
00280          if(error > 0.0){j++; error -= 1.0;}
00281        }
00282        else{
00283          if(error < 0.0){j--; error += 1.0;}
00284        }
00285        W=GetW(l,(double)(i-x),(double)(j-y),Wmin,Wmax,iScale,linear);
00286        if(!linear)C=GetC(l,(double)(i-x),(double)(j-y),Cin*0.25,Cin,1.0,TRUE);
00287        DrawAApixel((double)i,(double)j,W,W,C,Screen,X,Y,1,1,1);
00288      }
00289    }
00290    else{
00291      for(i=x;i>x+idx;i--){
00292        error -= grad;
00293        if(idy >= 0){
00294          if(error > 0.0){j++; error -= 1.0;}
00295        }
00296        else{
00297          if(error < 0.0){j--; error += 1.0;}
00298        }
00299        W=GetW(l,(double)(i-x),(double)(j-y),Wmin,Wmax,iScale,linear);
00300        if(!linear)C=GetC(l,(double)(i-x),(double)(j-y),Cin*0.25,Cin,1.0,TRUE);
00301        DrawAApixel((double)i,(double)j,W,W,C,Screen,X,Y,1,1,1);
00302      }
00303    }
00304  }
00305  else{
00306    grad=(double)idx/(double)idy; j=x;
00307    if(idx >= 0)error = -0.5; else error = 0.5;
00308    if(idy >= 0){
00309      for(i=y;i<y+idy;i++){
00310        error += grad;
00311        if(idx >= 0){
00312          if(error > 0.0){j++; error -= 1.0;}
00313        }
00314        else{
00315          if(error < 0.0){j--; error += 1.0;}
00316        }
00317        W=GetW(l,(double)(j-x),(double)(i-y),Wmin,Wmax,iScale,linear);
00318        if(!linear)C=GetC(l,(double)(j-x),(double)(i-y),Cin*0.25,Cin,1.0,TRUE);
00319        DrawAApixel((double)j,(double)i,W,W,C,Screen,X,Y,1,1,1);
00320      }
00321    }
00322    else{
00323      for(i=y;i>y+idy;i--){
00324        error -= grad;
00325        if(idx >= 0){
00326          if(error > 0.0){j++; error -= 1.0;}
00327        }
00328        else{
00329          if(error < 0.0){j--; error += 1.0;}
00330        }
00331        W=GetW(l,(double)(j-x),(double)(i-y),Wmin,Wmax,iScale,linear);
00332        if(!linear)C=GetC(l,(double)(j-x),(double)(i-y),Cin*0.25,Cin,1.0,TRUE);
00333        DrawAApixel((double)j,(double)i,W,W,C,Screen,X,Y,1,1,1);
00334      }
00335    }
00336  }
00337  return;
00338 }
00339 
00340 static double GetWL(double l, double dx, double dy,
00341                    double Wmin, double Wmax,
00342                    BOOL linear){
00343  double d,f;
00344  d=DIST(dx,dy);
00345  f=d/l;
00346  return (Wmax-(Wmax-Wmin)*f);
00347 }
00348 
00349 
00350 static void DrawFadedFlareInBuffer(long x, long y, long idx, long idy,
00351                               fullscreenbuffer *Screen,
00352                               long X, long Y,
00353                               double Cin,
00354                               double r, double g, double b,
00355                               double Wmin, double Wmax,
00356                               double z, float *Zb,
00357                               BOOL bDraw, BOOL linear){
00358  long i,j;
00359  double grad,error,W,l,C;
00360  C=Cin;
00361  l=DIST(idx,idy);
00362  if(abs(idx) >= abs(idy)){
00363    grad=(double)idy/(double)idx; j=y;
00364    if(idy >= 0)error = -0.5; else error = 0.5;
00365    if(idx >= 0){
00366      for(i=x;i<x+idx;i++){
00367        error += grad;
00368        if(idy >= 0){
00369          if(error > 0.0){j++; error -= 1.0;}
00370        }
00371        else{
00372          if(error < 0.0){j--; error += 1.0;}
00373        }
00374        W=GetWL(l,(double)(i-x),(double)(j-y),Wmin,Wmax,linear);
00375        DrawAApixel((double)i,(double)j,W,W,C,Screen,X,Y,r,g,b);
00376      }
00377    }
00378    else{
00379      for(i=x;i>x+idx;i--){
00380        error -= grad;
00381        if(idy >= 0){
00382          if(error > 0.0){j++; error -= 1.0;}
00383        }
00384        else{
00385          if(error < 0.0){j--; error += 1.0;}
00386        }
00387        W=GetWL(l,(double)(i-x),(double)(j-y),Wmin,Wmax,linear);
00388        DrawAApixel((double)i,(double)j,W,W,C,Screen,X,Y,r,g,b);
00389      }
00390    }
00391  }
00392  else{
00393    grad=(double)idx/(double)idy; j=x;
00394    if(idx >= 0)error = -0.5; else error = 0.5;
00395    if(idy >= 0){
00396      for(i=y;i<y+idy;i++){
00397        error += grad;
00398        if(idx >= 0){
00399          if(error > 0.0){j++; error -= 1.0;}
00400        }
00401        else{
00402          if(error < 0.0){j--; error += 1.0;}
00403        }
00404        W=GetWL(l,(double)(j-x),(double)(i-y),Wmin,Wmax,linear);
00405        DrawAApixel((double)j,(double)i,W,W,C,Screen,X,Y,r,g,b);
00406      }
00407    }
00408    else{
00409      for(i=y;i>y+idy;i--){
00410        error -= grad;
00411        if(idx >= 0){
00412          if(error > 0.0){j++; error -= 1.0;}
00413        }
00414        else{
00415          if(error < 0.0){j--; error += 1.0;}
00416        }
00417        W=GetWL(l,(double)(j-x),(double)(i-y),Wmin,Wmax,linear);
00418        DrawAApixel((double)j,(double)i,W,W,C,Screen,X,Y,r,g,b);
00419      }
00420    }
00421  }
00422  return;
00423 }
00424 
00425 static void DrawHaloInBuffer(long x, long y,
00426                              fullscreenbuffer *Screen,
00427                              long X, long Y, long radius,
00428                              double z, float *Zb,
00429                              BOOL bDraw,
00430                              double maxV,
00431                              double R, double G, double B){
00432  /* mix in a white halo at the screen buffer location of the light source */
00433  long i,j;
00434  double d;
00435  fullscreenbuffer *S;
00436  for(i=x-radius;i<=x+radius;i++)for(j=y-radius;j<=y+radius;j++){
00437    if(i < 0 || i >= X || j < 0 || j >= Y)continue;
00438    S=(Screen + j*X + i);
00439    d=sqrt((double)(i-x)*(double)(i-x) + (double)(j-y)*(double)(j-y));
00440    if(d < radius*0.25)d=maxV;
00441    else d=maxV*1.3333*((double)radius-d)/(double)radius;
00442    d=max(0.0,d);
00443    if(bDraw || Zb == NULL || z < *(Zb + j*X + i)){
00444      S->R = (unsigned char)min(255.0,(double)S->R+d*R);
00445      S->G = (unsigned char)min(255.0,(double)S->G+d*G);
00446      S->B = (unsigned char)min(255.0,(double)S->B+d*B);
00447    }
00448  }
00449  return;
00450 }
00451 
00452 static void DrawDiskInBuffer(long x, long y,
00453                              fullscreenbuffer *Screen,
00454                              long X, long Y, long radius,
00455                              double z, float *Zb,
00456                              BOOL bDraw,
00457                              double minV, double maxV,
00458                              double R, double G, double B){
00459  long i,j;
00460  double d;
00461  fullscreenbuffer *S;
00462  for(i=x-radius;i<=x+radius;i++)for(j=y-radius;j<=y+radius;j++){
00463    if(i < 0 || i >= X || j < 0 || j >= Y)continue;
00464    S=(Screen + j*X + i);
00465    d=sqrt((double)(i-x)*(double)(i-x) + (double)(j-y)*(double)(j-y));
00466    if(d < (double)radius){
00467      d=minV+(maxV-minV)*((double)radius-d)/(double)radius;
00468        S->R = (unsigned char)min(255.0,(double)S->R+d*R);
00469      S->G = (unsigned char)min(255.0,(double)S->G+d*G);
00470      S->B = (unsigned char)min(255.0,(double)S->B+d*B);
00471    }
00472  }
00473  return;
00474 }
00475 
00476 static void DrawDiskWithFade(long x, long y,
00477                              fullscreenbuffer *Screen,
00478                              long X, long Y,
00479                              long radius, long dradius,
00480                              double z, float *Zb,
00481                              BOOL bDraw,
00482                              double minV, double maxV,
00483                              double R, double G, double B){
00484  long i,j;
00485  double d,dr;
00486  fullscreenbuffer *S;
00487  for(i=x-dradius;i<=x+dradius;i++)for(j=y-dradius;j<=y+dradius;j++){
00488    if(i < 0 || i >= X || j < 0 || j >= Y)continue;
00489    if(bDraw || Zb == NULL || z < *(Zb + j*X + i)){
00490      S=(Screen + j*X + i);
00491      d=sqrt((double)(i-x)*(double)(i-x) + (double)(j-y)*(double)(j-y));
00492      if(d < (double)radius){
00493        d=minV+(maxV-minV)*((double)radius-d)/(double)radius;
00494        S->R = (unsigned char)min(255.0,(double)S->R+d*R);
00495        S->G = (unsigned char)min(255.0,(double)S->G+d*G);
00496        S->B = (unsigned char)min(255.0,(double)S->B+d*B);
00497      }
00498      else if(d < (double)dradius){
00499        d -= (double)radius; dr = (double)(dradius-radius);
00500        d=minV*(dr-d)/dr;
00501        S->R = (unsigned char)min(255.0,(double)S->R+d*R);
00502        S->G = (unsigned char)min(255.0,(double)S->G+d*G);
00503        S->B = (unsigned char)min(255.0,(double)S->B+d*B);
00504      }
00505    }
00506  }
00507  return;
00508 }
00509 
00510 static void DrawCircleInBuffer(long x, long y,
00511                              fullscreenbuffer *Screen,
00512                              long X, long Y,
00513                              long iradius, long oradius,
00514                              double minV, double maxV,
00515                              double R, double G, double B){
00516  long i,j;
00517  double d,dc;
00518  fullscreenbuffer *S;
00519  dc=0.5*(double)(iradius+oradius);
00520  for(i=x-oradius;i<=x+oradius;i++)for(j=y-oradius;j<=y+oradius;j++){
00521    if(i < 0 || i >= X || j < 0 || j >= Y)continue;
00522    S=(Screen + j*X + i);
00523    d=sqrt((double)(i-x)*(double)(i-x) + (double)(j-y)*(double)(j-y));
00524    if(d >= (double)iradius && d <= (double)oradius){
00525      if(d > dc){
00526        d=maxV-(maxV-minV)*(d-dc)/((double)oradius-dc);
00527      }
00528      else{
00529        d=minV+(maxV-minV)*(d-(double)iradius)/(dc-(double)iradius);
00530      }
00531      S->R = (unsigned char)min(255.0,(double)S->R+d*R);
00532      S->G = (unsigned char)min(255.0,(double)S->G+d*G);
00533      S->B = (unsigned char)min(255.0,(double)S->B+d*B);
00534    }
00535  }
00536  return;
00537 }
00538 
00539 long _RenderImageProcess(char *PrmList, XIMAGE *lpXimage){
00540  int i,j,Nl,li,n=45;
00541  char dummy[255];
00542  double x,y,z,radius,angle,atnd,atnc,atnr,atn,atnV=1.0;
00543  long v,model,type,flicker,hide,sx,sy,ipx,ipy,ipz,id;
00544  long xx,yy,Xmax,Ymax,Xc,Yc,oborder=2,border=5,dborder=8;
00545  long xBlue,yBlue,xBrown,yBrown,xGreen,yGreen,xT,yT;
00546  double bscale,rscale,iScale,ascale,lscale,dlscale,d2r,lc,dx,dy;
00547  double cr=1.0,cg=1.0,cb=1.0;
00548  float *Zb;
00549  BOOL  bDraw=TRUE;
00550 #include "pro_key.c"
00551 //debug=fopen("d:debug.evi","w");
00552 //MessageBox(NULL,PrmList,NULL,MB_OK);
00553  sscanf(PrmList,"%s %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %f %f %ld %lf",
00554         dummy,&type,&flicker,&hide,&sx,&sy,&ipx,&ipy,&ipz,&model,&v,
00555         &bscale,&rscale,&id,&angle);
00556  if(type == 1 && (lpXimage->Nlights == 0 || lpXimage->Lights == NULL))return 1;
00557  if(lpXimage->Morph){
00558    double mr=lpXimage->MorphRatio;
00559    long q_v,q_model,q_type,q_flicker,q_hide,q_sx,q_sy,q_ipx,q_ipy,q_ipz,q_id;
00560    double q_bscale,q_rscale;
00561    sscanf(lpXimage->mParameters,
00562         "%s %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %f %f %ld",
00563         dummy,&q_type,&q_flicker,&q_hide,&q_sx,&q_sy,&q_ipx,&q_ipy,&q_ipz,
00564         &q_model,&q_v,
00565         &q_bscale,&q_rscale,&q_id);
00566    bscale=q_bscale+mr*(bscale-q_bscale);
00567    rscale=q_rscale+mr*(rscale-q_rscale);
00568  }
00569  Xmax=lpXimage->Xmax;  Ymax=lpXimage->Ymax;
00570  Xc=Xmax/2; Yc=Ymax/2;
00571  iScale=rscale*(double)Xmax/320;
00572  atnV *= bscale;
00573  ascale=5.0/32767.0;
00574  lscale=80.0*(double)iScale;
00575  dlscale=80.0/32767.0*(double)iScale;
00576  d2r=3.1415626/180.0;
00577  border  *= iScale;
00578  oborder *= iScale;
00579  dborder *= iScale;
00580  Zb=lpXimage->Zbuffer;
00581  if(flicker)srand(lpXimage->Frame);
00582  else       srand(1);
00583  if(type == 1 || type == 4 || type == 5)Nl=lpXimage->Nlights;
00584  else Nl=1;
00585  for(li=0;li<Nl;li++){
00586    if(type == 4 && lpXimage->Lights[li].type != DUMMYL)continue;
00587    if(type == 5 && lpXimage->Lights[li].AnimatorID != id)continue;
00588    if(type == 1 || type == 4 || type == 5){
00589      x=lpXimage->Lights[li].p[0];
00590      y=lpXimage->Lights[li].p[1];
00591      z=lpXimage->Lights[li].p[2];
00592      cr=(double)(lpXimage->Lights[li].color[0])/255.0;
00593      cg=(double)(lpXimage->Lights[li].color[1])/255.0;
00594      cb=(double)(lpXimage->Lights[li].color[2])/255.0;
00595    }
00596    else if(type == 2){
00597      TransformIntoView(lpXimage->ViewTransform,
00598                        (double)ipx,(double)ipy,(double)ipz,
00599                        &x,&y,&z);
00600    }
00601    else if(type == 3){
00602      hide=0; y=1.1;
00603    }
00604    if(y >= 1.000){
00605      if(type == 3){
00606        xx=sx; yy=sy;
00607      }
00608      else{
00609        xx=Xc + (long)(lpXimage->Xscale*x/y);
00610        yy=Yc - (long)(lpXimage->Yscale*z/y);
00611      }
00612      if(xx >= -border && xx < Xmax+border &&
00613         yy >= -border && yy < Ymax+border){
00614        dx=(double)(xx-Xc);  dy=(double)(yy-Yc);
00615        lc=DIST(dx,dy);  dx /= lc; dy /= lc;
00616        atnc=atnV; atn=atnV;
00617        if(xx < border && yy < border){
00618          if(xx < yy){
00619            atn  = Grad((double)xx,0.0,atnV,0,border);
00620            atnc = Grad((double)xx,0.0,atnV,-border,border);
00621          }
00622          else{
00623            atn  = Grad((double)yy,0.0,atnV,0,border);
00624            atnc = Grad((double)yy,0.0,atnV,-border,border);
00625          }
00626        }
00627        else if(xx > Xmax-border && yy > Ymax-border){
00628          if(xx-Xmax > yy-Ymax){
00629            atn  = Grad((double)xx,atnV,0.0,Xmax-border,Xmax);
00630            atnc = Grad((double)xx,atnV,0.0,Xmax-border,Xmax+border);
00631          }
00632          else{
00633            atn  = Grad((double)yy,atnV,0.0,Ymax-border,Ymax);
00634            atnc = Grad((double)yy,atnV,0.0,Ymax-border,Ymax+border);
00635          }
00636        }
00637        else if(xx < border && yy > Ymax-border){
00638          if(border-xx > yy-(Ymax-border)){
00639            atn  = Grad((double)xx,0.0,atnV,0,border);
00640            atnc = Grad((double)xx,0.0,atnV,-border,border);
00641          }
00642          else{
00643            atn  = Grad((double)yy,atnV,0.0,Ymax-border,Ymax);
00644            atnc = Grad((double)yy,atnV,0.0,Ymax-border,Ymax+border);
00645          }
00646        }
00647        else if(xx > Xmax-border && yy < border){
00648          if(border-yy > xx-(Xmax-border)){
00649            atn  = Grad((double)yy,0.0,atnV,0,border);
00650            atnc = Grad((double)yy,0.0,atnV,-border,border);
00651          }
00652          else{
00653            atn  = Grad((double)xx,atnV,0.0,Xmax-border,Xmax);
00654            atnc = Grad((double)xx,atnV,0.0,Xmax-border,Xmax+border);
00655          }
00656        }
00657        else if(xx < border){
00658          atn  = Grad((double)xx,0.0,atnV,0,border);
00659          atnc = Grad((double)xx,0.0,atnV,-border,border);
00660        }
00661        else if(yy < border){
00662          atn  = Grad((double)yy,0.0,atnV,0,border);
00663          atnc = Grad((double)yy,0.0,atnV,-border,border);
00664        }
00665        else if(xx > Xmax-border){
00666          atn  = Grad((double)xx,atnV,0.0,Xmax-border,Xmax);
00667          atnc = Grad((double)xx,atnV,0.0,Xmax-border,Xmax+border);
00668        }
00669        else if(yy > Ymax-border){
00670          atn  = Grad((double)yy,atnV,0.0,Ymax-border,Ymax);
00671          atnc = Grad((double)yy,atnV,0.0,Ymax-border,Ymax+border);
00672        }
00673        atnd=atnV; atnr=1.0;
00674        if(hide && Zb != NULL && xx >= 0 && yy >= 0 && xx < Xmax && yy < Ymax){
00675          double dd;
00676          if(y < *(Zb + (yy * Xmax) + xx)){  // visible
00677            dd=DistFromHidingObject(xx,yy,y,Zb,border,Xmax,Ymax);
00678            if(dd < border){
00679              atn  = Grad(dd,atnV*0.2,atnV,0,border);
00680              atnc = Grad(dd,atnV*0.5,atnV,0,border);
00681            }
00682          }
00683          if(y > *(Zb + (yy * Xmax) + xx)){  // hidden
00684            dd=DistFromVisibleObject(xx,yy,y,Zb,dborder,Xmax,Ymax);
00685            if(dd < oborder){
00686              atn  = Grad(dd,atnV*0.2,0.0,0,oborder);
00687              atnc = Grad(dd,atnV*0.5,0.0,0,oborder);
00688            }
00689            else if(dd < dborder){
00690              atn=0.0; atnc=0.0;
00691              atnr = Grad(dd,1.0,0.0,0,dborder);
00692            }
00693            else continue;
00694          }
00695        }
00696        if(model < 3){  /* draw inter-lens reflections */
00697        DrawDiskInBuffer(Xc+(long)(1.8*lc*dx),Yc+(long)(1.8*lc*dy), // big brown
00698                         lpXimage->Screen,Xmax,Ymax,
00699                         (long)(120*iScale),
00700                         y,Zb,bDraw,20.0*atn,30.0*atn,
00701                         1.0,0.1,0.05);
00702        DrawCircleInBuffer(Xc+(long)(1.3*lc*dx),Yc+(long)(1.3*lc*dy),
00703                         lpXimage->Screen,Xmax,Ymax,            // yellow disk
00704                         (long)(10*iScale),(long)(13*iScale),
00705                         0.0*atn,30.0*atn,
00706                         1.0,1.0,0.2);
00707        DrawDiskInBuffer(Xc+(long)(1.3*lc*dx),Yc+(long)(1.3*lc*dy),
00708                         lpXimage->Screen,Xmax,Ymax,            // centre of yellow disk
00709                         (long)(15*iScale),
00710                         y,Zb,bDraw,
00711                         10.0*atn,20.0*atn,
00712                         1.0,1.0,0.2);
00713 
00714        xBlue=Xc+(long)(0.5*lc*dx); yBlue=Yc+(long)(0.5*lc*dy);
00715        DrawDiskWithFade(xBlue,yBlue, // blue overlapping
00716                         lpXimage->Screen,Xmax,Ymax,
00717                         (long)(20*iScale),(long)(25*iScale),
00718                         y,Zb,bDraw,
00719                         40.0*atn,60.0*atn,
00720                         0.0,0.0,1.0);
00721        DrawDiskWithFade(xBlue+(long)(8*iScale*dx),yBlue+(long)(8*iScale*dy),
00722                         lpXimage->Screen,Xmax,Ymax,
00723                         (long)(6*iScale),(long)(8*iScale),
00724                         y,Zb,bDraw,
00725                         40.0*atn,44.0*atn,
00726                         0.0,0.0,1.0);
00727        DrawDiskWithFade(xBlue-(long)(6*iScale*dx),yBlue-(long)(6*iScale*dy),
00728                         lpXimage->Screen,Xmax,Ymax,
00729                         (long)(9*iScale),(long)(11*iScale),
00730                         y,Zb,bDraw,
00731                         40.0*atn,44.0*atn,
00732                         0.0,0.0,1.0);
00733 
00734        xBrown=Xc-(long)(0.5*lc*dx); yBrown=Yc-(long)(0.5*lc*dy);
00735        DrawDiskWithFade(xBrown,yBrown, // brown overlapping
00736                         lpXimage->Screen,Xmax,Ymax,
00737                         (long)(18*iScale),(long)(21*iScale),
00738                         y,Zb,bDraw,
00739                         40.0*atn,44.0*atn,
00740                         1.0,0.1,0.2);
00741        DrawDiskWithFade(xBrown-(long)(8*iScale*dx),yBrown-(long)(8*iScale*dy),
00742                         lpXimage->Screen,Xmax,Ymax,
00743                         (long)(5*iScale),(long)(7*iScale),
00744                         y,Zb,bDraw,
00745                         40.0*atn,44.0*atn,
00746                         1.0,0.1,0.2);
00747        DrawDiskWithFade(xBrown+(long)(6*iScale*dx),yBrown+(long)(6*iScale*dy),
00748                         lpXimage->Screen,Xmax,Ymax,
00749                         (long)(10*iScale),(long)(12*iScale),
00750                         y,Zb,bDraw,40.0*atn,44.0*atn,
00751                         1.0,0.1,0.2);
00752 
00753        xBrown=Xc+(long)(0.35*lc*dx); yBrown=Yc+(long)(0.35*lc*dy);
00754        DrawDiskInBuffer(xBrown,yBrown, // single brown
00755                         lpXimage->Screen,Xmax,Ymax,
00756                         (long)(5*iScale),
00757                         y,Zb,bDraw,
00758                         40.0*atn,44.0*atn,
00759                         1.0,0.1,0.2);
00760 
00761        xT=Xc-(long)(0.8*lc*dx); yT=Yc-(long)(0.8*lc*dy);
00762        DrawHaloInBuffer(xT,yT,lpXimage->Screen,Xmax,Ymax,
00763                         (long)(10*iScale),
00764                         y,Zb,bDraw,
00765                         160.0*atn,
00766                         0.2,0.2,1.0);  // blue halo
00767        DrawHaloInBuffer(xT-(long)(2*iScale*dx),yT-(long)(2*iScale*dy),
00768                         lpXimage->Screen, // white bit
00769                         Xmax,Ymax,
00770                         (long)(2*iScale),
00771                         y,Zb,bDraw,
00772                         64.0*atn,
00773                         1.0,1.0,1.0);
00774        DrawDiskWithFade(xT+(long)(8*iScale*dx),yT+(long)(8*iScale*dy),
00775                         lpXimage->Screen,Xmax,Ymax,
00776                         (long)(11*iScale),(long)(13*iScale), // green bit
00777                         y,Zb,bDraw,
00778                         40.0*atn,44.0*atn,
00779                         0.5,0.8,0.2);
00780 
00781        xGreen=Xc-(long)(0.8*lc*dx); yGreen=Yc-(long)(0.8*lc*dy);
00782        DrawDiskInBuffer(xGreen,yGreen, // green disk
00783                         lpXimage->Screen,Xmax,Ymax,
00784                         (long)(30*iScale),
00785                         y,Zb,bDraw,
00786                         20.0*atn,44.0*atn,
00787                         0.4,0.5,0.2);
00788        DrawCircleInBuffer(xGreen,yGreen,
00789                         lpXimage->Screen,Xmax,Ymax,    // green outline
00790                         (long)(28*iScale),(long)(30*iScale),
00791                         0.0*atn,30.0*atn,
00792                         1.0,1.0,0.2);
00793 
00794        xT=Xc-(long)(1.2*lc*dx); yT=Yc-(long)(1.2*lc*dy); // opposite rainbow
00795        DrawCircleInBuffer(xT,yT,
00796                         lpXimage->Screen,Xmax,Ymax,
00797                         (long)(60*iScale),(long)(62*iScale),
00798                         10.0*atn,30.0*atn,
00799                         1.0,0.2,0.2);
00800        DrawCircleInBuffer(xT,yT,
00801                         lpXimage->Screen,Xmax,Ymax,
00802                         (long)(58*iScale),(long)(61*iScale),
00803                         30.0*atn,30.0*atn,
00804                         0.2,1.0,0.2);
00805        DrawCircleInBuffer(xT,yT,
00806                         lpXimage->Screen,Xmax,Ymax,
00807                         (long)(56*iScale),(long)(59*iScale),
00808                         10.0*atn,30.0*atn,
00809                         0.2,0.2,1.0);
00810 
00811        DrawAApixel(Xmax/2,Ymax/2,1.0*iScale,1.0*iScale,   // bright screen centre
00812                    255.0*atn,
00813                    lpXimage->Screen,Xmax,Ymax,
00814                    1,1,1);
00815        xT=Xc-(long)(0.35*lc*dx); yT=Yc-(long)(0.35*lc*dy);
00816        DrawHaloInBuffer(xT,yT,lpXimage->Screen,           // bright offcentre
00817                         Xmax,Ymax,
00818                         (long)(3*iScale),
00819                         y,Zb,bDraw,
00820                         255.0*atn,
00821                         0.8,0.8,1.0);
00822        } /* end inter-lens reflections */
00823        if(model == 1){
00824          DrawHaloInBuffer(xx,yy,lpXimage->Screen,Xmax,Ymax, // light halo
00825                           (long)(3*iScale),
00826                           y,Zb,bDraw,
00827                           255.0*atnc,
00828                           1.0,1.0,1.0);
00829          DrawHaloInBuffer(xx,yy,lpXimage->Screen,Xmax,Ymax, // light halo red disk
00830                           (long)(20*iScale),
00831                           y,Zb,bDraw,
00832                           80.0*atn,
00833                           1.0,0.5,0.2);
00834          DrawCircleInBuffer(xx,yy,
00835                           lpXimage->Screen,Xmax,Ymax,       // light halo outer ring
00836                           (long)(20*iScale),(long)(23*iScale),
00837                           50.0*atn,80.0*atn,
00838                           1.0,0.5,0.0);
00839          for(j=0;j<n;j++){  /* outlying spines */
00840            double a,l;
00841            long   idx,idy;
00842            a=360.0/(double)n*(double)j+ascale*(double)rand();
00843            a *= d2r;
00844            l=lscale+dlscale*(double)rand();
00845            l *= atn;
00846            idx=(long)(l*cos(a)); idy=(long)(l*sin(a));
00847            DrawFlareInBuffer(xx,yy,idx,idy,lpXimage->Screen,Xmax,Ymax,
00848                              iScale/rscale, /* don't scale size */
00849                              20.0*atn, // brightness 0-255
00850                              0.2,0.8,  // min width max width
00851                              y,Zb,bDraw,TRUE);
00852          }
00853          for(i=0;i<3;i++)for(j=0;j<n;j++){ /* centre spines */
00854            double a,l,C;
00855            long   idx,idy;
00856            a=360.0/(double)n*(double)j+ascale*(double)rand();
00857            a *= d2r;
00858            l=lscale+dlscale*(double)rand();
00859            if     (i == 0){l /= 5; l *= atnc; C=32.0*atn;}
00860            else if(i == 1){l /= 10; C=64.0*atn;}
00861            else if(i == 2){l /= 20; C=128.0*atnc;}
00862            idx=(long)(l*cos(a)); idy=(long)(l*sin(a));
00863            DrawFlareInBuffer(xx,yy,idx,idy,lpXimage->Screen,Xmax,Ymax,
00864                              iScale,
00865                              C,
00866                              0.2,0.8,
00867                              y,Zb,bDraw,TRUE);
00868          }
00869        }
00870        else if(model == 2 || model == 3){ /* model2/3 */
00871          DrawHaloInBuffer(xx,yy,lpXimage->Screen,Xmax,Ymax, // light halo
00872                           (long)(20*iScale),
00873                           y,Zb,bDraw,
00874                           255.0*atnc,
00875                           1.0,1.0,1.0);
00876          DrawHaloInBuffer(xx,yy,lpXimage->Screen,Xmax,Ymax, // light halo red disk
00877                           (long)(30*iScale),
00878                           y,Zb,bDraw,
00879                           80.0*atnc,
00880                           1.0,0.5,0.2);
00881          DrawCircleInBuffer(xx,yy,
00882                           lpXimage->Screen,Xmax,Ymax,       // light halo outer ring
00883                           (long)(150*iScale),(long)(160*iScale),
00884                           50.0*atn,80.0*atn,
00885                           1.0,0.5,0.0);
00886          if(model == 2)DrawDiskWithFade(xx,yy,
00887                          lpXimage->Screen,Xmax,Ymax,        // big obscured disk
00888                           (long)(27*iScale)*atnr,
00889                           (long)(40*iScale)*atnr,
00890                           y,Zb,(BOOL)(!hide),
00891                           100.0*atnd,100.0*atnd,
00892                           1.0,1.0,1.0);
00893          if(model == 2)for(j=0;j<10;j++){  /* spines */
00894            double a,l,ddx,ddy;
00895            long   xs,ys,idx,idy;
00896            a= -90.0 + 360.0/(double)10*(double)j;
00897            a *= d2r;
00898            l=lscale*1.5;
00899            l *= atn/bscale;  /* don't scale for brightness */
00900            ddx=l*cos(a); ddy=l*sin(a);
00901            idx=(long)ddx; idy=(long)ddy;
00902            xs=xx+(long)(ddx*0.09); ys=yy+(long)(ddy*0.09);
00903            DrawFlareInBuffer(xs,ys,idx,idy,lpXimage->Screen,Xmax,Ymax,
00904                              iScale/rscale, /* don't scale size */
00905                              40.0*atnc/bscale, // brightness 0-255
00906                              0.0,1.4*atnc/bscale,  // min width max width
00907                              y,Zb,bDraw,FALSE);
00908            DrawFlareInBuffer(xs,ys,idx,idy,lpXimage->Screen,Xmax,Ymax,
00909                              iScale/rscale, /* don't scale size */
00910                              20.0*atnc/bscale, // brightness 0-255
00911                              0.0,2.8*atnc/bscale,  // min width max width
00912                              y,Zb,bDraw,FALSE);
00913            xs=xx+(long)(ddx*0.2); ys=yy+(long)(ddy*0.2);
00914            DrawFlareInBuffer(xs,ys,idx,idy,lpXimage->Screen,Xmax,Ymax,
00915                              iScale/rscale, /* don't scale size */
00916                              10.0*atnc/bscale, // brightness 0-255
00917                              0.0,4.5*atnc/bscale,  // min width max width
00918                              y,Zb,bDraw,FALSE);
00919          }
00920        }
00921        else { /* model=4 */
00922          fullscreenbuffer *Screen;
00923          if((Screen=(fullscreenbuffer *)X__Malloc(Xmax*Ymax*
00924              (long)sizeof(fullscreenbuffer))) != NULL){
00925            memset(Screen,0,Xmax*Ymax*sizeof(fullscreenbuffer));
00926            for(j=0;j<8;j++){  /* outer */
00927              double a,l;
00928              long   idx,idy;
00929              a=360.0/(double)8*(double)j+22.5;
00930              a *= d2r;
00931              l=lscale;
00932              l *= atn;
00933              idx=(long)(l*cos(a)); idy=(long)(l*sin(a));
00934              DrawFadedFlareInBuffer(xx,yy,idx,idy,
00935                              Screen,
00936                              Xmax,Ymax,
00937                              8.0*atn, // brightness 0-255
00938                              cr,cg,cb, // colour
00939                              4.0*iScale/2,4.5*iScale/2,  // min width max width
00940                              y,Zb,
00941                              bDraw,TRUE);
00942              DrawFadedFlareInBuffer(xx,yy,idx,idy,
00943                              Screen,
00944                              Xmax,Ymax,
00945                              16.0*atn, // brightness 0-255
00946                              cr,cg,cb, // colour
00947                              1.0*iScale/2,3.0*iScale/2,  // min width max width
00948                              y,Zb,
00949                              bDraw,TRUE);
00950              DrawFadedFlareInBuffer(xx,yy,idx,idy,
00951                              Screen,
00952                              Xmax,Ymax,
00953                              80.0*atn, // brightness 0-255
00954                              1.0,1.0,1.0, // colour
00955                              0.0,2.0*iScale/2,  // min width max width
00956                              y,Zb,
00957                              bDraw,TRUE);
00958              idx /= 2; idy /=2;
00959              DrawFadedFlareInBuffer(xx,yy,idx,idy,
00960                              Screen,
00961                              Xmax,Ymax,
00962                              16.0*atn, // brightness 0-255
00963                              cr,cg,cb, // colour
00964                              0.0,2.0*iScale/2,  // min width max width
00965                              y,Zb,
00966                              bDraw,TRUE);
00967            }
00968            for(j=0;j<8;j++){  /* inner */
00969              double a,l;
00970              long   idx,idy;
00971              a=360.0/(double)8*(double)j;
00972              a *= d2r;
00973              l=lscale/2;
00974              l *= atn;
00975              idx=(long)(l*cos(a)); idy=(long)(l*sin(a));
00976              DrawFadedFlareInBuffer(xx,yy,idx,idy,
00977                              Screen,
00978                              Xmax,Ymax,
00979                              64.0*atn, // brightness 0-255
00980                              cr,cg,cb, // colour
00981                              0.8*iScale/2,1.5*iScale/2,  // min width max width
00982                              y,Zb,bDraw,TRUE);
00983            }
00984            n=36;
00985            for(j=0;j<n;j++){  /* jitter */
00986              double a,l;
00987              long   idx,idy;
00988              a=360.0/(double)n*(double)j+ascale*(double)rand();
00989              a *= d2r;
00990              l=(lscale+dlscale*(double)rand())/30;
00991              l *= atn;
00992              idx=(long)(l*cos(a)); idy=(long)(l*sin(a));
00993              DrawFadedFlareInBuffer(xx,yy,idx,idy,
00994                              Screen,
00995                              Xmax,Ymax,
00996                              255.0*atn, // brightness 0-255
00997                              1.0,1.0,1.0, // colour
00998                              0.8*iScale/2,1.2*iScale/2,  // min width max width
00999                              y,Zb,bDraw,TRUE);
01000            }
01001            DrawDiskWithFade(xx,yy,Screen,Xmax,Ymax, // light halo
01002                           (long)(5*iScale), (long)(20*iScale),
01003                           y,Zb,bDraw,
01004                           128.0*atnc/bscale,255.0*atnc/bscale,
01005                           cr,cg,cb);
01006            if(Xmax > 320)BlurBuffer(Screen,Xmax,Ymax);
01007            MixBuffer(Screen,lpXimage->Screen,Xmax,Ymax);
01008            X__Free(Screen);
01009          }
01010        }
01011      }
01012    }
01013  }
01014 //fclose(debug);
01015  return 1;
01016 }
01017 
01018 BOOL CALLBACK DlgProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam);
01019 
01020 static long   version=1,type=1,model=1,flicker=0,hide=1,id= -1,
01021               sx=0,sy=0,ipx=0,ipy=0,ipz=0;
01022 static double bscale=1.0,rscale=1.0,angle=22.5;
01023 static double px,py,pz;
01024 static X__MEMORY_MANAGER *lpLocalEVI;
01025 
01026 char * _SetExternalParameters(
01027   char *Op,                 /* string for the parameters                  */
01028   HWND hWnd,                /* parent window                              */
01029   long ruler,               /* ruler scale value to facilitate scaling    */
01030   char *name,               /* name of DLL file with the effect           */
01031   X__MEMORY_MANAGER *lpEVI /* pointer to structure with memory functions */
01032                                     ){
01033  char buffer[256];
01034 //if(lpEVI->lpAni != NULL){
01035 //sprintf(buffer,"Animator parameter=%ld",*((long *)lpEVI->lpAni));
01036 //MessageBox(NULL,buffer,"Debug",MB_OK);
01037 //}
01038  if(Op != NULL){
01039    sscanf(Op,"%s %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %f %f %ld %f",
01040           buffer,&type,&flicker,&hide,&sx,&sy,&ipx,&ipy,&ipz,&model,&version,
01041           &bscale,&rscale,&id,&angle);
01042     px=(double)ipx/(double)ruler;
01043     py=(double)ipy/(double)ruler;
01044     pz=(double)ipz/(double)ruler;
01045  }
01046  lpLocalEVI=lpEVI;
01047  if(DialogBox(hDLLinstance,MAKEINTRESOURCE(DLG_FLARE),hWnd,
01048               (DLGPROC)DlgProc) == FALSE)return Op;
01049  if(Op != NULL)CALL_FREE(Op);  /* free the old string */
01050  ipx=(long)(px*(double)ruler);
01051  ipy=(long)(py*(double)ruler);
01052  ipz=(long)(pz*(double)ruler);
01053  sprintf(buffer,"%s %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %f %f %ld %f",
01054          name,type,flicker,hide,sx,sy,ipx,ipy,ipz,model,version,
01055          bscale,rscale,id,angle);
01056  if((Op=(char *)CALL_MALLOC(strlen(buffer)+1)) == NULL){
01057    return NULL;
01058  }
01059  strcpy(Op,buffer);
01060  return Op;
01061 }
01062 
01063 static void LoadAnimatedClip(HWND hDlg){
01064  char *c,modname[256];
01065  GetModuleFileName(hDLLinstance,modname,255);
01066  if((c=strrchr(modname,'.')) != NULL){
01067    strcpy(c,".avi");
01068    Animate_Open(GetDlgItem(hDlg,DLG_IMAGE),modname);
01069    Animate_Play(GetDlgItem(hDlg,DLG_IMAGE),0, -1, -1);
01070  }
01071 }
01072 
01073 BOOL CALLBACK DlgProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam){
01074  BOOL err;
01075  char str[32];
01076  switch( msg ) {
01077    case WM_INITDIALOG:
01078      if(hide)SendDlgItemMessage(hwnd,DLG_FLARE_HIDE,BM_SETCHECK,TRUE,0);
01079      if(flicker)SendDlgItemMessage(hwnd,DLG_FLARE_FLICKER,BM_SETCHECK,TRUE,0);
01080      if     (type == 1)
01081        SendDlgItemMessage(hwnd,DLG_FLARE_TYPE1,BM_SETCHECK,TRUE,0);
01082      else if(type == 2)
01083        SendDlgItemMessage(hwnd,DLG_FLARE_TYPE2,BM_SETCHECK,TRUE,0);
01084      else if(type == 3)
01085        SendDlgItemMessage(hwnd,DLG_FLARE_TYPE3,BM_SETCHECK,TRUE,0);
01086      else if(type == 4)
01087        SendDlgItemMessage(hwnd,DLG_FLARE_TYPE4,BM_SETCHECK,TRUE,0);
01088      else if(type == 5)
01089        SendDlgItemMessage(hwnd,DLG_FLARE_TYPE5,BM_SETCHECK,TRUE,0);
01090      if     (model == 1)
01091        SendDlgItemMessage(hwnd,DLG_FLARE_MODEL1,BM_SETCHECK,TRUE,0);
01092      else if(model == 2)
01093        SendDlgItemMessage(hwnd,DLG_FLARE_MODEL2,BM_SETCHECK,TRUE,0);
01094      else if(model == 3)
01095        SendDlgItemMessage(hwnd,DLG_FLARE_MODEL3,BM_SETCHECK,TRUE,0);
01096      else if(model == 4)
01097        SendDlgItemMessage(hwnd,DLG_FLARE_MODEL4,BM_SETCHECK,TRUE,0);
01098      sprintf(str,"%.3f",px);
01099      SetDlgItemText(hwnd,DLG_FLARE_PX,str);
01100      sprintf(str,"%.3f",py);
01101      SetDlgItemText(hwnd,DLG_FLARE_PY,str);
01102      sprintf(str,"%.3f",pz);
01103      SetDlgItemText(hwnd,DLG_FLARE_PZ,str);
01104      SetDlgItemInt(hwnd,DLG_FLARE_SX,sx,FALSE);
01105      SetDlgItemInt(hwnd,DLG_FLARE_SY,sy,FALSE);
01106      sprintf(str,"%.3f",bscale);
01107      SetDlgItemText(hwnd,DLG_FLARE_BSCALE,str);
01108      sprintf(str,"%.3f",rscale);
01109      SetDlgItemText(hwnd,DLG_FLARE_RSCALE,str);
01110      if(id >= 0)SendDlgItemMessage(hwnd,DLG_FLARE_NAME,WM_SETTEXT,
01111                 0,(LPARAM)GetActorsName(lpLocalEVI->lpAni,id));
01112      LoadAnimatedClip(hwnd);
01113      CentreDialogOnScreen(hwnd);
01114      return TRUE;
01115    case WM_PAINT:
01116      PaintBackground(hwnd);
01117      break;
01118    case WM_COMMAND:
01119      switch(LOWORD(wparam)){
01120         case DLG_FLARE_SETID:
01121           id=GetActorsID(lpLocalEVI->lpAni,hwnd);
01122           if(id >= 0)SendDlgItemMessage(hwnd,DLG_FLARE_NAME,WM_SETTEXT,
01123                      0,(LPARAM)GetActorsName(lpLocalEVI->lpAni,id));
01124           break;
01125         case IDCANCEL:
01126           EndDialog(hwnd,FALSE);
01127           return(TRUE);
01128         case IDOK:
01129           if(GetDlgItemText(hwnd,DLG_FLARE_PX,str,12) != 0)
01130             sscanf(str,"%f",&px);
01131           if(GetDlgItemText(hwnd,DLG_FLARE_PY,str,12) != 0)
01132             sscanf(str,"%f",&py);
01133           if(GetDlgItemText(hwnd,DLG_FLARE_PZ,str,12) != 0)
01134             sscanf(str,"%f",&pz);
01135           if(GetDlgItemText(hwnd,DLG_FLARE_BSCALE,str,12) != 0)
01136             sscanf(str,"%f",&bscale);
01137           if(GetDlgItemText(hwnd,DLG_FLARE_RSCALE,str,12) != 0)
01138             sscanf(str,"%f",&rscale);
01139           sx=GetDlgItemInt(hwnd,DLG_FLARE_SX,&err,FALSE);
01140           sy=GetDlgItemInt(hwnd,DLG_FLARE_SY,&err,FALSE);
01141           if     (SendDlgItemMessage(hwnd,DLG_FLARE_TYPE5,BM_GETCHECK,0,0))
01142                type=5;
01143           else if(SendDlgItemMessage(hwnd,DLG_FLARE_TYPE4,BM_GETCHECK,0,0))
01144                type=4;
01145           else if(SendDlgItemMessage(hwnd,DLG_FLARE_TYPE3,BM_GETCHECK,0,0))
01146                type=3;
01147           else if(SendDlgItemMessage(hwnd,DLG_FLARE_TYPE2,BM_GETCHECK,0,0))
01148                type=2;
01149           else type=1;
01150           if(SendDlgItemMessage(hwnd,DLG_FLARE_HIDE,BM_GETCHECK,0,0))
01151                hide=1;
01152           else hide=0;
01153           if(SendDlgItemMessage(hwnd,DLG_FLARE_FLICKER,BM_GETCHECK,0,0))
01154                flicker=1;
01155           else flicker=0;
01156           if     (SendDlgItemMessage(hwnd,DLG_FLARE_MODEL4,BM_GETCHECK,0,0))
01157                model=4;
01158           else if(SendDlgItemMessage(hwnd,DLG_FLARE_MODEL3,BM_GETCHECK,0,0))
01159                model=3;
01160           else if(SendDlgItemMessage(hwnd,DLG_FLARE_MODEL2,BM_GETCHECK,0,0))
01161                model=2;
01162           else model=1;
01163           EndDialog(hwnd,TRUE);
01164           return(TRUE);
01165         default:
01166           break;
01167       }
01168       break;
01169     default: break;
01170  }
01171  return FALSE;
01172 }
01173 

Generated on Sun Apr 27 14:20:12 2014 for OpenFX by  doxygen 1.5.6