flap.c

Go to the documentation of this file.
00001 /* --
00002 OpenFX version 2.0 - Modelling, Animation and Rendering Package
00003 Copyright (C) 2000 -  OpenFX Development Team
00004 -- */
00005 
00006 /* flap.c */
00007 
00008 #include <math.h>
00009 #include <windows.h>
00010 #include <commctrl.h>
00011 
00012 #include "flap.h"
00013 
00014 #if __ZTC__ || __SC__
00015 #ifndef max
00016 #define max(a,b)  ( ((a) > (b)) ? (a) : (b) )
00017 #endif
00018 #endif
00019 
00020 #ifndef PI
00021 #define PI 3.1415926
00022 #endif
00023 
00024 #if __X__MIPS__
00025 BOOL WINAPI _CRT_INIT(HINSTANCE ,DWORD , LPVOID );
00026 #endif
00027 
00028 static HINSTANCE hDLLinstance=NULL;
00029 
00030 #include "pstruct.h"
00031 
00032 #include "paint.c"
00033 
00034 #if __WATCOMC__
00035 int APIENTRY LibMain(HANDLE hDLL, DWORD dwReason, LPVOID lpReserved){
00036 #else
00037 BOOL WINAPI DllMain(HANDLE hDLL, DWORD dwReason, LPVOID lpReserved){
00038 #endif
00039  switch (dwReason) {
00040    case DLL_PROCESS_ATTACH:
00041 #if __X__MIPS__
00042       if(!_CRT_INIT(hDLL,dwReason,lpReserved))return(int)FALSE;
00043 #endif
00044      hDLLinstance = hDLL;  /* handle to DLL file */
00045      break;
00046    case DLL_PROCESS_DETACH:
00047 #if __X__MIPS__
00048       if(!_CRT_INIT(hDLL,dwReason,lpReserved))return(int)FALSE;
00049 #endif
00050      break;
00051  }
00052  return (int)TRUE;
00053 }
00054 
00055 #if __SC__
00056 #pragma startaddress(LibMain)
00057 #endif
00058 
00059 long _RenderGlobalEffect
00060 (char *PrmList, sfxinfo *SFXinfo, sfxdata *SFXdata, vertex *Vlist){
00061  return 1;
00062 }
00063 
00064 void _PreviewGlobalEffect
00065 (char *PrmList, sfxinfo *SFXinfo, sfxdata *SFXdata, Svertex *Vlist){
00066  return;
00067 }
00068 
00069 long _RenderExternalEffect(char *parameters, sfxinfo *SFXinfo,
00070                                  vertex *v){
00071  double amplitude,flaplength,displacement,PRMamp,PRMuamp,PRMlngth,PRMfreq,
00072         d,maxd,scale;
00073  char buffer[256];
00074  int type, PRMaxis, axis, fade, paxis, paxis2;
00075  long i;
00076  sscanf(parameters,"%s %d %d %f %f %f %f %d",buffer,&type,&PRMaxis,
00077         &PRMuamp,&PRMamp,
00078         &PRMlngth,&PRMfreq,&fade);
00079 //MessageBox(NULL,parameters,NULL,MB_OK);
00080  if     (PRMaxis == 3) axis=1;    /* F / B */
00081  else if(PRMaxis == 1) axis=2;    /* U / D */
00082  else if(PRMaxis == 2) axis=0;    /* L / R */
00083  if     (axis == 0){ paxis = 1; paxis2 = 2; }
00084  else if(axis == 2){ paxis = 1; paxis2 = 0; }
00085  else if(axis == 1){ paxis = 0; paxis2 = 2; }
00086  flaplength=max((SFXinfo->vmax[paxis]-SFXinfo->vmin[paxis]) * PRMlngth,1.0);
00087  amplitude=(PRMamp/25.0) * (flaplength/8);
00088  if(type == 2){                        /* Radial */
00089   maxd=0.00;
00090   for(i=0;i<SFXinfo->nvert;i++){
00091    d=sqrt(v[i].p[paxis]*v[i].p[paxis] + v[i].p[paxis2]*v[i].p[paxis2]);
00092    maxd=max(maxd,d);
00093   }
00094  }
00095  for(i=0;i<SFXinfo->nvert;i++){
00096   if(type == 1) d=v[i].p[paxis];       /* Linear */
00097   else if(type == 2){                  /* Radial */
00098    d=sqrt(v[i].p[paxis]*v[i].p[paxis] + v[i].p[paxis2]*v[i].p[paxis2]);
00099   }
00100   displacement=amplitude*cos(PI*2*((SFXinfo->time*PRMfreq)-d/flaplength));
00101   if(type == 1){                       /* Linear */
00102    d = v[i].p[paxis]-SFXinfo->vmin[paxis];
00103    maxd = SFXinfo->vmax[paxis]-SFXinfo->vmin[paxis];
00104   }
00105   if(fade == 2) displacement *= d / maxd;             /* fade up */
00106   else if(fade == 3) displacement *= 1 - d / maxd;    /* fade down */
00107   v[i].p[axis] += displacement;
00108 
00109   scale=PRMuamp*cos(PI*2*((SFXinfo->time*PRMfreq)-d/flaplength));
00110   if(fade == 2) scale *= d / maxd;
00111   else if(fade == 3) scale *= 1 - d / maxd;
00112   scale = 1.0 + scale;
00113   v[i].p[paxis2] *= scale;
00114  }
00115  return 1;
00116 }
00117 
00118 void _PreviewExternalEffect(char *parameters, sfxinfo *SFXinfo,
00119                                     Svertex *v){
00120  double amplitude,flaplength,displacement,PRMamp,PRMuamp,PRMlngth,PRMfreq,
00121         d,maxd,scale;
00122  char buffer[256];
00123  int type, PRMaxis, axis, fade, paxis, paxis2;
00124  long i;
00125  sscanf(parameters,"%s %d %d %f %f %f %f %d",buffer,&type,&PRMaxis,
00126         &PRMuamp,&PRMamp,
00127         &PRMlngth,&PRMfreq,&fade);
00128  if(PRMaxis == 3) axis=1;         /* F / B */
00129  else if(PRMaxis == 1) axis=2;    /* U / D */
00130  else if(PRMaxis == 2) axis=0;    /* L / R */
00131  if     (axis == 0){ paxis = 1; paxis2 = 2; }
00132  else if(axis == 2){ paxis = 1; paxis2 = 0; }
00133  else if(axis == 1){ paxis = 0; paxis2 = 2; }
00134  flaplength=max((SFXinfo->vmax[paxis]-SFXinfo->vmin[paxis]) * PRMlngth,1.0);
00135  amplitude=(PRMamp/25.0) * (flaplength/8);
00136  if(type == 2){                        /* Radial */
00137   maxd=0.00;
00138   for(i=0;i<SFXinfo->nvert;i++){
00139    d=sqrt(v[i][paxis]*v[i][paxis] + v[i][paxis2]*v[i][paxis2]);
00140    maxd=max(maxd,d);
00141   }
00142  }
00143  for(i=0;i<SFXinfo->nvert;i++){
00144   if(type == 1) d=v[i][paxis];       /* Linear */
00145   else if(type == 2){                  /* Radial */
00146    d=sqrt(v[i][paxis]*v[i][paxis] + v[i][paxis2]*v[i][paxis2]);
00147   }
00148   displacement=amplitude*cos(PI*2*((SFXinfo->time*PRMfreq)-d/flaplength));
00149   if(type == 1){                       /* Linear */
00150    d = v[i][paxis]-SFXinfo->vmin[paxis];
00151    maxd = SFXinfo->vmax[paxis]-SFXinfo->vmin[paxis];
00152   }
00153   if(fade == 2) displacement *= d / maxd;             /* fade up */
00154   else if(fade == 3) displacement *= 1 - d / maxd;    /* fade down */
00155   v[i][axis] += displacement;
00156 
00157   scale=PRMuamp*cos(PI*2*((SFXinfo->time*PRMfreq)-d/flaplength));
00158   if(fade == 2) scale *= d / maxd;
00159   else if(fade == 3) scale *= 1 - d / maxd;
00160   scale = 1.0 + scale;
00161   v[i][paxis2] *= scale;
00162  }
00163 }
00164 
00165 BOOL CALLBACK DlgProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam);
00166 
00167 static int type=1,motion=1,xfade=1;
00168 static double uamp=0.5,amp=25.0,length=1.0,freq=1.0;
00169 
00170 char * _SetExternalParameters(
00171   char *Op,                 /* string for the parameters                  */
00172   HWND hWnd,                /* parent window                              */
00173   long ruler,               /* ruler scale value to facilitate scaling    */
00174   char *name,               /* name of DLL file with the effect           */
00175   X__MEMORY_MANAGER *lpEVI /* pointer to structure with memory functions */
00176   ){
00177  char buffer[256];
00178  if(Op != NULL){  /* parameters exist so read them off the list          */
00179                   /* the name of the DLL file is always the first string */
00180    sscanf(Op,"%s %d %d %f %f %f %f %d",buffer,&type,&motion,
00181           &uamp,&amp,&length,&freq,&xfade);
00182  }
00183  if(DialogBox(hDLLinstance,MAKEINTRESOURCE(DLG_FLAP),hWnd,
00184               (DLGPROC)DlgProc) == FALSE)return Op;
00185  if(Op != NULL)CALL_FREE(Op);  /* free the old string */
00186  sprintf(buffer,"%s %d %d %f %f %f %f %d",name,type,motion,uamp,amp,
00187          length,freq,xfade);
00188  if((Op=(char *)CALL_MALLOC(strlen(buffer)+1)) == NULL){
00189   MessageBox (GetFocus(),"External effect: Out of memory","Error",
00190                 MB_OK|MB_TASKMODAL|MB_ICONSTOP);
00191    return NULL;
00192  }
00193  strcpy(Op,buffer);
00194  return Op;
00195 }
00196 
00197 BOOL CALLBACK DlgProc(HWND hDlg,UINT msg,WPARAM wparam,LPARAM lparam){
00198  char str[16];
00199  switch( msg ) {
00200    case WM_INITDIALOG:
00201      if(type == 2)SendDlgItemMessage(hDlg,DLG_FLAP_RADIAL,BM_SETCHECK,1,0);
00202      else         SendDlgItemMessage(hDlg,DLG_FLAP_LINEAR,BM_SETCHECK,1,0);
00203      if     (motion == 3)SendDlgItemMessage(hDlg,DLG_FLAP_FB,BM_SETCHECK,1,0);
00204      else if(motion == 2)SendDlgItemMessage(hDlg,DLG_FLAP_LR,BM_SETCHECK,1,0);
00205      else                SendDlgItemMessage(hDlg,DLG_FLAP_UD,BM_SETCHECK,1,0);
00206      if     (xfade == 3)SendDlgItemMessage(hDlg,DLG_FLAP_FADE_DOWN,BM_SETCHECK,1,0);
00207      else if(xfade == 2)SendDlgItemMessage(hDlg,DLG_FLAP_FADE_UP,BM_SETCHECK,1,0);
00208      else               SendDlgItemMessage(hDlg,DLG_FLAP_FADE_NONE,BM_SETCHECK,1,0);
00209      sprintf(str,"%.2f",amp);
00210      SetDlgItemText(hDlg,DLG_FLAP_AMP,str);
00211      sprintf(str,"%.2f",uamp);
00212      SetDlgItemText(hDlg,DLG_FLAP_UAMP,str);
00213      sprintf(str,"%.2f",length);
00214      SetDlgItemText(hDlg,DLG_FLAP_LENGTH,str);
00215      sprintf(str,"%.2f",freq);
00216      SetDlgItemText(hDlg,DLG_FLAP_FREQ,str);
00217      LoadAnimatedClip(hDlg);
00218      CentreDialogOnScreen(hDlg);
00219      return TRUE;
00220    case WM_PAINT:
00221      PaintBackground(hDlg);
00222      break;
00223    case WM_SYSCOMMAND:
00224      switch(LOWORD(wparam & 0xfff0)){
00225        case SC_CLOSE:
00226          EndDialog(hDlg,FALSE);
00227          return(TRUE);
00228        default:
00229          break;
00230      }
00231      break;
00232    case WM_COMMAND:
00233      switch(LOWORD(wparam)){
00234         case DLG_FLAP_LINEAR:    type=1; break;
00235         case DLG_FLAP_RADIAL:    type=2; break;
00236         case DLG_FLAP_UD:        motion=1; break;
00237         case DLG_FLAP_LR:        motion=2; break;
00238         case DLG_FLAP_FB:        motion=3; break;
00239         case DLG_FLAP_FADE_NONE: xfade=1; break;
00240         case DLG_FLAP_FADE_UP:   xfade=2; break;
00241         case DLG_FLAP_FADE_DOWN: xfade=3; break;
00242         case DLG_FLAP_OK:
00243           if(GetDlgItemText(hDlg,DLG_FLAP_AMP,str,12) != 0)
00244             sscanf(str,"%f",&amp);
00245           if(GetDlgItemText(hDlg,DLG_FLAP_UAMP,str,12) != 0)
00246             sscanf(str,"%f",&uamp);
00247           if(GetDlgItemText(hDlg,DLG_FLAP_LENGTH,str,12) != 0)
00248             sscanf(str,"%f",&length);
00249           if(GetDlgItemText(hDlg,DLG_FLAP_FREQ,str,12) != 0)
00250             sscanf(str,"%f",&freq);
00251           EndDialog(hDlg,TRUE);
00252           return(TRUE);
00253         case DLG_FLAP_CANCEL:
00254           EndDialog(hDlg,FALSE);
00255           return(TRUE);
00256         default:
00257           break;
00258       }
00259       break;
00260     default: break;
00261  }
00262  return FALSE;
00263 }
Generated on Tue Jan 28 06:18:29 2014 for OpenFX by  doxygen 1.6.3