FIREBALL.C

Go to the documentation of this file.
00001 /* --
00002 OpenFX version 2.0 - Modelling, Animation and Rendering Package
00003 Copyright (C) 2000 - 2007 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 /* fireball.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 #include "defines.h"
00037 
00038 #include "fireball.h"
00039 
00040 #if __X__MIPS__
00041 BOOL WINAPI _CRT_INIT(HINSTANCE ,DWORD , LPVOID );
00042 #endif
00043 
00044 static HINSTANCE hDLLinstance=NULL; /* use to pick up resources from DLL   */
00045 static long version=1;
00046 
00047 /************************** Local Utility Functions ***********************/
00048 
00049 #include "utils.h"
00050 #include "paint.c"
00051 
00052 /************************** DLL entry point ********************************/
00053 
00054 #if __WATCOMC__
00055 int APIENTRY LibMain(HANDLE hDLL, DWORD dwReason, LPVOID lpReserved){
00056 #elif __BC__
00057 BOOL WINAPI DllEntryPoint(HANDLE hDLL, DWORD dwReason, LPVOID lpReserved){
00058 #else
00059 BOOL WINAPI DllMain(HANDLE hDLL, DWORD dwReason, LPVOID lpReserved){
00060 #endif
00061   switch (dwReason) {
00062     case DLL_PROCESS_ATTACH:
00063 #if __X__MIPS__
00064       if(!_CRT_INIT(hDLL,dwReason,lpReserved))return(int)FALSE;
00065 #endif
00066       hDLLinstance = hDLL;  /* handle to DLL file */
00067       break;
00068     case DLL_PROCESS_DETACH:
00069 #if __X__MIPS__
00070       if(!_CRT_INIT(hDLL,dwReason,lpReserved))return(int)FALSE;
00071 #endif
00072       break;
00073   }
00074 return (int)TRUE;
00075 }
00076 
00077 #if __SC__
00078 #pragma startaddress(DllMain)
00079 #endif
00080 
00081 #define RS              (1.0/(double)RAND_MAX)
00082 #define CF(c)           ((double)(c)/(double)(255))
00083 #define FC(c)           ((unsigned char)(c*255.0))
00084 #define VECCOPY(a,b)    { b[0] = a[0]; b[1] = a[1]; b[2] = a[2]; }
00085 #define INVERT(a)       { a[0] = -a[0]; a[1] = -a[1]; a[2] = -a[2]; }
00086 #define VECSUB(a,b,c)   { c[0]=a[0]-b[0]; c[1]=a[1]-b[1]; c[2]=a[2]-b[2];}
00087 #define VECSUM(a,b,c)   { c[0]=a[0]+b[0]; c[1]=a[1]+b[1]; c[2]=a[2]+b[2];}
00088 #define VECSCALE(a,b,c) { c[0]=(a)*b[0]; c[1]=(a)*b[1]; c[2]=(a)*b[2];}
00089 #define DOT(a,b)        ( (a[0]*b[0]) + (a[1]*b[1]) + (a[2]*b[2]) )
00090 #define CROSS(v1,v2,r)  { \
00091                           r[0] = (v1[1]*v2[2]) - (v2[1]*v1[2]);  \
00092                           r[1] = (v1[2]*v2[0]) - (v1[0]*v2[2]);  \
00093                           r[2] = (v1[0]*v2[1]) - (v2[0]*v1[1]);  \
00094                         }
00095 #define ONE_256 3.90625e-3
00096 
00097 static long GetSphereIntersection(vector d, vector P,
00098                                 double radius,
00099                                 double *dn, double *df){
00100  double ddotr,pdotr,a,a2,b,c,b4,mu1,mu2,lambda1,lambda2;
00101  vector A,B,tv;
00102  a=1.0;
00103  b=-2*(DOT(d,P));
00104  c=DOT(P,P)-radius*radius;
00105  b4=b*b-4.0*a*c;
00106  if(b4 < 0.0)return 0;
00107  else if(b4 < 1.e-10){
00108    *dn = *df = -b/(2*a);
00109  }
00110  else{
00111    b4=sqrt(b4);
00112    a2=0.5/a;
00113    mu1=(-b+b4)*a2;
00114    mu2=(-b-b4)*a2;
00115    if(mu1 < 0.0){
00116      *dn=0.0; *df=mu2;
00117    }
00118    else if(mu2 < 0){
00119      *dn=0.0; *df=mu1;
00120    }
00121    else{
00122      if(mu1 < mu2){*dn=mu1; *df=mu2;}
00123      else         {*dn=mu2; *df=mu1;}
00124    }
00125  }
00126  return 2;
00127 }
00128 
00129 static double NoiseScale=12000.0;
00130 static vector color1={CF(252),CF(202),CF(  0)};
00131 static vector color2={CF(225),CF( 30),CF( 30)};
00132 static vector color3={0.1,0.1,0.1};
00133 static BOOL flametype=FALSE;  // tendrils ?
00134 static double linear_falloff;
00135 static double stretch=1.0f;
00136 static double regularity=0.2f;  // 0.0 - 1.0
00137 static double levels=3.0f;
00138 static double density=15.0f;
00139 static double phase=0.0f;
00140 static double drift=0.0f;
00141 static BOOL explode=TRUE;
00142 static BOOL smoke=TRUE;
00143 static double fury=1.0f;
00144 static double rfact;
00145 static double m_ratio=1.0;
00146 
00147 static void SetExplodeParameters(void){
00148  int i;
00149  density /= 50.0f;
00150  if(stretch !=0.0f) stretch = 1.0f/stretch;
00151 
00152  phase=m_ratio*300.0;
00153 
00154  if(explode && (phase < 0.0f || phase > 300.0f)) {  // Outside of explosion.
00155     rfact   = 0.0f;
00156     density = 0.0f;
00157  }
00158  else if(explode){ // In explosion
00159    rfact = (float)sqrt(phase/100.0f);
00160    if(phase > 100.0f) {
00161      float u = 1.0f - (phase-100.0f)/200.0f;
00162      density *= (u*u * (3.0f - 2.0f*u));
00163    }
00164    if(smoke){
00165      if(phase > 200.0f){ // Solid smoke
00166         VECCOPY(color3,color1)
00167         VECCOPY(color3,color2)
00168      }
00169      else if( phase > 100.0f){ // Interpolate to smoke color
00170        float u = (phase-100.0f)/100.0f;
00171        u = (u*u * (3.0f - 2.0f*u));
00172        for(i=0;i<3;i++){
00173          color1[i] += color3[i]*u - color1[i]*u;
00174          color2[i] += color3[i]*u - color2[i]*u;
00175        }
00176      }
00177    }
00178    // Convert phase to a reasonable value and
00179    // add in fury factor
00180    phase = (double)(sqrt(phase/75.0f))/2.0f * 5.0f * fury;
00181  }
00182  else{ // Not doing an explosion
00183    rfact = 1.0f;
00184    phase = phase/300.0f * 5.0f;
00185  }
00186 
00187  rfact *= (1.0+1.6*(1.0 - regularity));
00188 }
00189 
00190 double NoiseFunc(vector p, double phase, double levels, int invert,
00191                  XIMAGE *lpXimage){
00192   double nn;
00193   double sum = 0.0f;
00194   double l,f = 1.0f;
00195   for(l = levels; l>=1.0f; l-=1.0f) {
00196     nNoise(p[0]*f/NoiseScale+phase,
00197            p[1]*f/NoiseScale+phase,
00198            p[2]*f/NoiseScale+phase,
00199            &nn);
00200     nn = (nn-0.5)*0.3;
00201     sum += fabs(nn)/f;            //(double)fabs(noise4(p*f,phase))/f;
00202     f *= 2.0f;
00203   }
00204   if(l > 0.0f){
00205     nNoise(p[0]*f/NoiseScale+phase,
00206            p[1]*f/NoiseScale+phase,
00207            p[2]*f/NoiseScale+phase,
00208            &nn);
00209     nn = (nn-0.5)*0.3;
00210     sum += l*fabs(nn)/f;          //l*(double)fabs(noise4(p*f,phase))/f;
00211   }
00212   if(sum > 1.0)sum=1.0;
00213   if(invert){
00214     sum = 0.5f-sum;
00215     return sum>0.0f?sum:0.0f;
00216   }
00217   return sum;
00218 }
00219 
00220 static void TraceSphericalVolume(long Nsamples, vector dLook, vector pLight,
00221                                  double dns, double z, double dfs,
00222                                  double max_attn, vector colour,
00223                                  light *Lp, XIMAGE *lpXimage){
00224  vector c={0.0,0.0,0.0};
00225  double u,n,opac,o=0.0;
00226  long i;
00227  double ds;
00228  vector p,dp,dd;
00229  ds=(dfs-dns);
00230  if(z < dfs){
00231    max_attn = max_attn*(z-dns)/ds;
00232    dfs=min(z,dfs);
00233    ds=(dfs-dns);
00234  }
00235  ds=ds/(double)Nsamples;
00236  VECSCALE(dns,dLook,p)
00237  VECSCALE(ds,dLook,dd);
00238  for(i=0;i<Nsamples;i++){
00239 //   VECSCALE(ds*(double)rand()*RS,dLook,dp) VECSUM(dp,p,dp)
00240    VECCOPY(p,dp)
00241    u=sqrt((dp[0]-pLight[0])*(dp[0]-pLight[0])+
00242           (dp[1]-pLight[1])*(dp[1]-pLight[1])+
00243           (dp[2]-pLight[2])*(dp[2]-pLight[2]));
00244    u *= linear_falloff/rfact;
00245    n=NoiseFunc(dp,phase,levels,flametype,lpXimage);
00246    if(u > regularity){
00247      n -= u-regularity;
00248      if(n < 0.0f)n=0.0f;
00249    }
00250    opac = (1.0f-u)*n*ds*density/200;
00251    c[0] += (color1[0]*n + (1.0f-n)*color2[0])*opac;
00252    c[1] += (color1[1]*n + (1.0f-n)*color2[1])*opac;
00253    c[2] += (color1[2]*n + (1.0f-n)*color2[2])*opac;
00254    o += opac;
00255    VECSUM(p,dd,p)
00256  }
00257  o = 1.0f - exp(-o);
00258  for(i=0;i<3;i++){
00259    c[i] = 1.0f - exp(-c[i]);
00260    colour[i] += c[i]-(colour[i]*o);
00261  }
00262  return;
00263 }
00264 
00265 
00266 long _RenderImageProcess(char *PrmList, XIMAGE *lpXimage){
00267  int i,j,k;
00268  char dummy[255];
00269  double tan_theta1,tan_theta2,cos_theta2;
00270  double Sx,Sy,dn,df,dns,dfs,dmin,dmax,l,mu,lambda;
00271  double noise_scale,radius_multiplier;
00272  long Xmax,Ymax,flames,type,id,nc,Nsamples,expl,smok;
00273  light *Lp;
00274  BOOL bOriginInCone,bIlluminated;
00275  vector d,dl,colour,phat;
00276  double tan_theta_sq;
00277  float *Zb;
00278  double z;
00279  fullscreenbuffer *S,*s;
00280  if(lpXimage->Nlights == 0 || lpXimage->Lights == NULL)return 1;
00281  sscanf(PrmList,"%s %ld %f %ld %ld %ld %ld %ld %ld %f %f %f %f"
00282                 " %f %f %f %f %f %f %f %f %f",
00283         dummy,&version,
00284         &noise_scale,&flames,&type,&id,&Nsamples,&expl,&smok,
00285         &stretch,&regularity,&radius_multiplier,&density,
00286         &color1[0],&color1[1],&color1[2],
00287         &color2[0],&color2[1],&color2[2],
00288         &color3[0],&color3[1],&color3[2]);
00289  if(lpXimage->Morph && lpXimage->mParameters != NULL){
00290    m_ratio=lpXimage->MorphRatio;
00291  }
00292  else{
00293    m_ratio=(double)(lpXimage->last_frame - lpXimage->first_frame);
00294    if(m_ratio < 1.0)m_ratio=0.4;
00295    else m_ratio=(double)(lpXimage->this_frame - lpXimage->first_frame)/m_ratio;
00296  }
00297  if(expl == 0)explode=FALSE; else explode=TRUE;
00298  if(flames == 1)flametype=TRUE; else flametype=FALSE;
00299  NoiseScale *= noise_scale;
00300  SetExplodeParameters();
00301  Zb=lpXimage->Zbuffer;
00302  S=lpXimage->Screen;
00303  Xmax=lpXimage->Xmax;
00304  Ymax=lpXimage->Ymax;
00305  Sx=lpXimage->Xscale;
00306  Sy=lpXimage->Yscale;
00307  for(k=0;k<lpXimage->Nlights;k++){
00308    Lp=(lpXimage->Lights+k);
00309    if(type == 2 && Lp->type != DUMMYL)continue;
00310    if(type == 3 && Lp->AnimatorID != id)continue;
00311    if(Lp->type != SPOTLIGHT){ // non spots can only do if falloff
00312      if(Lp->dc){              // light fall off
00313        linear_falloff=Lp->dc_l/radius_multiplier;
00314        for(j=0;j<Ymax;j++){
00315          lpXimage->fp_Yield();
00316          if((lpXimage->fp_Terminate()) < 0)goto XXIT;
00317          for(i=0;i<Xmax;i++){
00318            d[2] = -((double)j + 0.5 - (double)Ymax/2.0)/Sy;
00319            d[2] *= stretch;
00320            d[0] =  ((double)i + 0.5 - (double)Xmax/2.0)/Sx;
00321            d[1] =  1.0;
00322            normalize(d);
00323            nc=GetSphereIntersection(d,Lp->p,rfact/linear_falloff,&dns,&dfs);
00324            if(nc > 1){  // inside sphere as well
00325              z = (double)(*(Zb + (j*Xmax)+i))/d[1];
00326              if(dns < z){
00327                s = (S+(j*Xmax)+i);
00328                colour[0]=ONE_256*(double)s->R;
00329                colour[1]=ONE_256*(double)s->G;
00330                colour[2]=ONE_256*(double)s->B;
00331                TraceSphericalVolume(Nsamples,d,Lp->p,dns,z,dfs,1.0,colour,Lp,lpXimage);
00332                s->R=(unsigned char)min(255L,(long)(256.0*colour[0]));
00333                s->G=(unsigned char)min(255L,(long)(256.0*colour[1]));
00334                s->B=(unsigned char)min(255L,(long)(256.0*colour[2]));
00335              }
00336            }
00337          }
00338        }
00339      }
00340    }
00341  }
00342  XXIT:
00343  return 1;
00344 }
00345 
00346 /*************** Function that renders any of the OpenGL Functionality ************/
00347 
00348 long _RenderGLexternal(char *PrmList, XIMAGE *lpXimage){
00349 MessageBox(NULL,"OpenGL function called","OK",MB_OK);
00350  return 1;
00351 }
00352 
00353 /*************** +++++++++++++++++++++++++++++++++++++++++++++++++++++ ************/
00354 
00355 BOOL CALLBACK DlgProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam);
00356 
00357 static double nvar=1.0;
00358 static double radm=1.0;
00359 static long   samples=16,flames=0,type=1,id = -1,expl=1,smok=1;
00360 static vector c1={CF(252),CF(202),CF(  0)};
00361 static vector c2={CF(225),CF( 30),CF( 30)};
00362 static vector c3={0.1,0.1,0.1};
00363 static double stre=1.0f;
00364 static double regu=0.2f;  // 0.0 - 1.0
00365 static double dens=15.0f;
00366 
00367 static X__MEMORY_MANAGER *lpLocalEVI;
00368 
00369 char * _SetExternalParameters(
00370   char *Op,                 /* string for the parameters                  */
00371   HWND hWnd,                /* parent window                              */
00372   long ruler,               /* ruler scale value to facilitate scaling    */
00373   char *name,               /* name of DLL file with the effect           */
00374   X__MEMORY_MANAGER *lpEVI /* pointer to structure with memory functions */
00375                                     ){
00376  /* output name and buffer should be as long as necessary to hold full string */
00377  char buffer[256];
00378  if(Op != NULL){  /* parameters exist so read them off the list */
00379    sscanf(Op,"%s %ld %f %ld %ld %ld %ld %ld %ld %f %f %f %f"
00380              " %f %f %f %f %f %f %f %f %f",
00381           buffer,&version,
00382           &nvar,&flames,&type,&id,&samples,&expl,&smok,
00383           &stre,&regu,&radm,&dens,
00384           &c1[0],&c1[1],&c1[2],
00385           &c2[0],&c2[1],&c2[2],
00386           &c3[0],&c3[1],&c3[2]);
00387  }
00388  lpLocalEVI=lpEVI;
00389  if(DialogBox(hDLLinstance,MAKEINTRESOURCE(DLG_FIREBALL),hWnd,
00390               (DLGPROC)DlgProc) == FALSE)return Op;
00391  if(Op != NULL)CALL_FREE(Op);  /* free the old string */
00392  sprintf(buffer,"%s %ld %f %ld %ld %ld %ld %ld %ld %f %f %f %f"
00393          " %f %f %f %f %f %f %f %f %f",name,version,
00394          nvar,flames,type,id,samples,expl,smok,
00395          stre,regu,radm,dens,
00396          c1[0],c1[1],c1[2],
00397          c2[0],c2[1],c2[2],
00398          c3[0],c3[1],c3[2]);
00399  if((Op=(char *)CALL_MALLOC(strlen(buffer)+1)) == NULL){
00400   MessageBox (GetFocus(),"External effect: Out of memory","Error",
00401                 MB_OK|MB_TASKMODAL|MB_ICONSTOP);
00402    return NULL;
00403  }
00404  strcpy(Op,buffer);
00405  return Op;
00406 }
00407 
00408 static void LoadAnimatedClip(HWND hDlg){
00409  char *c,modname[256];
00410  GetModuleFileName(hDLLinstance,modname,255);
00411  if((c=strrchr(modname,'.')) != NULL){
00412    strcpy(c,".avi");
00413    Animate_Open(GetDlgItem(hDlg,DLG_IMAGE),modname);
00414    Animate_Play(GetDlgItem(hDlg,DLG_IMAGE),0, -1, -1);
00415  }
00416 }
00417 
00418 static void SetColour(unsigned char *colour, HWND parent){
00419  CHOOSECOLOR cc;
00420  static COLORREF CustColours[16]={
00421    RGB(255,255,255), RGB(239,239,239), RGB(223,223,223), RGB(207,207,207),
00422    RGB(191,191,191), RGB(175,175,175), RGB(159,159,159), RGB(143,143,143),
00423    RGB(127,127,127), RGB(111,111,111), RGB( 95, 95, 95), RGB( 79, 79, 79),
00424    RGB( 63, 63, 63), RGB( 47, 47, 47), RGB( 31, 31, 31), RGB( 15, 15, 15) };
00425  cc.lStructSize=sizeof(CHOOSECOLOR);
00426  cc.hwndOwner=parent;
00427  cc.rgbResult=RGB((BYTE)colour[0],(BYTE)colour[1],(BYTE)colour[2]);
00428  cc.lpCustColors=(LPDWORD)CustColours;
00429  cc.Flags= CC_RGBINIT;
00430  cc.lCustData=(DWORD)0;
00431  if(ChooseColor(&cc)){
00432    colour[0]=(unsigned char)GetRValue(cc.rgbResult);
00433    colour[1]=(unsigned char)GetGValue(cc.rgbResult);
00434    colour[2]=(unsigned char)GetBValue(cc.rgbResult);
00435  }
00436 }
00437 
00438 BOOL CALLBACK DlgProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam){
00439  char str[32];
00440  switch( msg ) {
00441    case WM_INITDIALOG:
00442      sprintf(str,"%.3f",nvar);
00443      SetDlgItemText(hwnd,DLG_FIREBALL_NOISESCALE,str);  // Noise Variability
00444      sprintf(str,"%.3f",stre);
00445      SetDlgItemText(hwnd,DLG_FIREBALL_STRETCH,str);
00446      sprintf(str,"%.3f",regu);
00447      SetDlgItemText(hwnd,DLG_FIREBALL_REGULARITY,str);
00448      sprintf(str,"%.3f",radm);
00449      SetDlgItemText(hwnd,DLG_FIREBALL_RADIUSMULTIPLIER,str);
00450      sprintf(str,"%.3f",dens);
00451      SetDlgItemText(hwnd,DLG_FIREBALL_DENSITY,str);
00452      sprintf(str,"%ld",samples);
00453      SetDlgItemText(hwnd,DLG_FIREBALL_SAMPLES,str);
00454      if(flames == 1)SendDlgItemMessage(hwnd,DLG_FIREBALL_FLAMES,BM_SETCHECK,TRUE,0);
00455      if(expl   == 1)SendDlgItemMessage(hwnd,DLG_FIREBALL_EXPLODE,BM_SETCHECK,TRUE,0);
00456      if(type == 1)SendDlgItemMessage(hwnd,DLG_FIREBALL_TYPE1,BM_SETCHECK,TRUE,0);
00457      if(type == 2)SendDlgItemMessage(hwnd,DLG_FIREBALL_TYPE2,BM_SETCHECK,TRUE,0);
00458      if(type == 3)SendDlgItemMessage(hwnd,DLG_FIREBALL_TYPE3,BM_SETCHECK,TRUE,0);
00459      if(id >= 0)SendDlgItemMessage(hwnd,DLG_FIREBALL_NAME,WM_SETTEXT,
00460                 0,(LPARAM)GetActorsName(lpLocalEVI->lpAni,id));
00461      LoadAnimatedClip(hwnd);
00462      CentreDialogOnScreen(hwnd);
00463      return TRUE;
00464    case WM_PAINT:
00465      PaintBackground(hwnd);
00466      break;
00467    case WM_DRAWITEM:{
00468        LPDRAWITEMSTRUCT lpdis;
00469        HBRUSH   hbr,hbrold;
00470        BYTE r,g,b;
00471        lpdis=(LPDRAWITEMSTRUCT)lparam;
00472        if(lpdis->CtlID == DLG_FIREBALL_COLOUR1 ||
00473           lpdis->CtlID == DLG_FIREBALL_COLOUR2 ||
00474           lpdis->CtlID == DLG_FIREBALL_COLOUR3){
00475          if(lpdis->CtlID == DLG_FIREBALL_COLOUR1){
00476            r=FC(c1[0]); g=FC(c1[1]); b=FC(c1[2]);
00477          }
00478          else if(lpdis->CtlID == DLG_FIREBALL_COLOUR2){
00479            r=FC(c2[0]); g=FC(c2[1]); b=FC(c2[2]);
00480          }
00481          else if(lpdis->CtlID == DLG_FIREBALL_COLOUR3){
00482            r=FC(c3[0]); g=FC(c3[1]); b=FC(c3[2]);
00483          }
00484          if(lpdis->itemState & ODS_SELECTED)
00485             InvertRect(lpdis->hDC,&(lpdis->rcItem));
00486          else{
00487            hbr=CreateSolidBrush(RGB(r,g,b));
00488            hbrold=SelectObject(lpdis->hDC,hbr);
00489            Rectangle(lpdis->hDC,lpdis->rcItem.left,lpdis->rcItem.top,
00490                          lpdis->rcItem.right,lpdis->rcItem.bottom);
00491            SelectObject(lpdis->hDC,hbrold);
00492            DeleteObject(hbr);
00493          }
00494        }
00495      }
00496      break;
00497    case WM_COMMAND:
00498      switch(LOWORD(wparam)){
00499         case DLG_FIREBALL_COLOUR1:{
00500             unsigned char colour[3];
00501             colour[0]=FC(c1[0]);
00502             colour[1]=FC(c1[1]);
00503             colour[2]=FC(c1[2]);
00504             SetColour(colour,hwnd);
00505             c1[0]=CF(colour[0]); c1[1]=CF(colour[1]); c1[2]=CF(colour[2]);
00506             InvalidateRect(GetDlgItem(hwnd,DLG_FIREBALL_COLOUR1),NULL,FALSE);
00507           }
00508           break;
00509         case DLG_FIREBALL_COLOUR2:{
00510             unsigned char colour[3];
00511             colour[0]=FC(c2[0]);
00512             colour[1]=FC(c2[1]);
00513             colour[2]=FC(c2[2]);
00514             SetColour(colour,hwnd);
00515             c2[0]=CF(colour[0]); c2[1]=CF(colour[1]); c2[2]=CF(colour[2]);
00516             InvalidateRect(GetDlgItem(hwnd,DLG_FIREBALL_COLOUR2),NULL,FALSE);
00517           }
00518           break;
00519         case DLG_FIREBALL_COLOUR3:{
00520             unsigned char colour[3];
00521             colour[0]=FC(c3[0]);
00522             colour[1]=FC(c3[1]);
00523             colour[2]=FC(c3[2]);
00524             SetColour(colour,hwnd);
00525             c3[0]=CF(colour[0]); c3[1]=CF(colour[1]); c3[2]=CF(colour[2]);
00526             InvalidateRect(GetDlgItem(hwnd,DLG_FIREBALL_COLOUR3),NULL,FALSE);
00527           }
00528           break;
00529         case DLG_FIREBALL_SETID:
00530           id=GetActorsID(lpLocalEVI->lpAni,hwnd);
00531           if(id >= 0)SendDlgItemMessage(hwnd,DLG_FIREBALL_NAME,WM_SETTEXT,
00532                      0,(LPARAM)GetActorsName(lpLocalEVI->lpAni,id));
00533           break;
00534         case IDCANCEL:
00535           EndDialog(hwnd,FALSE);
00536           return(TRUE);
00537         case IDOK:
00538           if(GetDlgItemText(hwnd,DLG_FIREBALL_NOISESCALE,str,12) != 0)
00539             sscanf(str,"%f",&nvar);
00540           if(GetDlgItemText(hwnd,DLG_FIREBALL_STRETCH,str,12) != 0)
00541             sscanf(str,"%f",&stre);
00542           if(GetDlgItemText(hwnd,DLG_FIREBALL_REGULARITY,str,12) != 0)
00543             sscanf(str,"%f",&regu);
00544           if(GetDlgItemText(hwnd,DLG_FIREBALL_RADIUSMULTIPLIER,str,12) != 0)
00545             sscanf(str,"%f",&radm);
00546           if(GetDlgItemText(hwnd,DLG_FIREBALL_DENSITY,str,12) != 0)
00547             sscanf(str,"%f",&dens);
00548           if(GetDlgItemText(hwnd,DLG_FIREBALL_SAMPLES,str,12) != 0)
00549             sscanf(str,"%ld",&samples);
00550           if(SendDlgItemMessage(hwnd,DLG_FIREBALL_FLAMES,BM_GETCHECK,0,0))
00551                flames=1;
00552           else flames=0;
00553           if(SendDlgItemMessage(hwnd,DLG_FIREBALL_EXPLODE,BM_GETCHECK,0,0))
00554                expl=1;
00555           else expl=0;
00556           if(SendDlgItemMessage(hwnd,DLG_FIREBALL_TYPE1,BM_GETCHECK,0,0))type=1;
00557           if(SendDlgItemMessage(hwnd,DLG_FIREBALL_TYPE2,BM_GETCHECK,0,0))type=2;
00558           if(SendDlgItemMessage(hwnd,DLG_FIREBALL_TYPE3,BM_GETCHECK,0,0))type=3;
00559           EndDialog(hwnd,TRUE);
00560           return(TRUE);
00561         default:
00562           break;
00563       }
00564       break;
00565     default: break;
00566  }
00567  return FALSE;
00568 }
00569 
00570 
00571 #if 0
00572 old function
00573 double NoiseFunc(vector p, double phase, double levels, int invert,
00574                  XIMAGE *lpXimage){
00575   double nn;
00576   double sum = 0.0f;
00577   double l,f = 1.0f;
00578   //return 0.5;
00579   //sTurbulence(p[0]*f/NoiseScale,p[1]*f/NoiseScale,p[2]*f/NoiseScale,&nn);
00580   //return nn;
00581   for(l = levels; l>=1.0f; l-=1.0f) {
00582     nNoise(p[0]*f/NoiseScale,p[1]*f/NoiseScale,p[2]*f/NoiseScale,&nn);
00583 //    nNoise((p[0]*f/NoiseScale),
00584 //           (p[1]*f/NoiseScale),
00585 //           (p[2]*f/NoiseScale+phase),&nn);
00586     nn = (nn-0.5)*0.3;
00587     sum += fabs(nn)/f;            //(double)fabs(noise4(p*f,phase))/f;
00588     f *= 2.0f;
00589   }
00590   if(l > 0.0f){
00591     nNoise(p[0]*f/NoiseScale,p[1]*f/NoiseScale,p[2]*f/NoiseScale,&nn);
00592 //    nNoise((p[0]*f/NoiseScale),
00593 //           (p[1]*f/NoiseScale),
00594 //           (p[2]*f/NoiseScale+phase),&nn);
00595     nn = (nn-0.5)*0.3;
00596     sum += l*fabs(nn)/f;          //l*(double)fabs(noise4(p*f,phase))/f;
00597   }
00598   //sum /= 3.333;
00599   if(sum > 1.0)sum=1.0;
00600   if(invert){
00601     sum = 0.5f-sum;
00602     return sum>0.0f?sum:0.0f;
00603   }
00604   return sum;
00605 }
00606 #endif
00607 
00608 

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