wave.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 /* wave.c */
00007 
00008 #include <math.h>
00009 #include <windows.h>
00010 #include <commctrl.h>
00011 
00012 #include "wave.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 //MessageBox(NULL,"Attach","Wave",MB_OK);
00045      hDLLinstance = hDLL;  /* handle to DLL file */
00046      break;
00047    case DLL_PROCESS_DETACH:
00048 #if __X__MIPS__
00049       if(!_CRT_INIT(hDLL,dwReason,lpReserved))return(int)FALSE;
00050 #endif
00051 //MessageBox(NULL,"Detach","Wave",MB_OK);
00052      break;
00053  }
00054  return (int)TRUE;
00055 }
00056 
00057 #if __SC__
00058 #pragma startaddress(LibMain)
00059 #endif
00060 
00061 /* internal effects have no need to use this */
00062 
00063 long _RenderGlobalEffect
00064 (char *PrmList, sfxinfo *SFXinfo, sfxdata *SFXdata, vertex *v){
00065  return 1;
00066 }
00067 
00068 void _PreviewGlobalEffect
00069 (char *PrmList, sfxinfo *SFXinfo, sfxdata *SFXdata, Svertex *Vlist){
00070  return;
00071 }
00072 
00073 long _RenderExternalEffect(char *parameters, sfxinfo *SFXinfo,
00074                                  vertex *v){
00075  double amplitude,wavelength,displacement,PRMamp,PRMlngth,PRMfreq,d,maxd;
00076  char buffer[256];
00077  int type, PRMaxis, axis, fade, paxis, paxis2;
00078  long i;
00079 //MessageBox(NULL,parameters,NULL,MB_OK);
00080  sscanf(parameters,"%s %d %d %f %f %f %d",buffer,&type,&PRMaxis,&PRMamp,
00081         &PRMlngth,&PRMfreq,&fade);
00082  if(PRMaxis == 3) axis=1;         /* F / B */
00083  else if(PRMaxis == 1) axis=2;    /* U / D */
00084  else if(PRMaxis == 2) axis=0;    /* L / R */
00085  if(axis == 0){      paxis = 1; paxis2 = 2; }
00086  else if(axis == 2){ paxis = 1; paxis2 = 0; }
00087  else if(axis == 1){ paxis = 0; paxis2 = 2; }
00088  wavelength=max((SFXinfo->vmax[paxis]-SFXinfo->vmin[paxis]) * PRMlngth,1.0);
00089  amplitude=(PRMamp/25.0) * (wavelength/8);
00090  if(type == 2){                        /* Radial */
00091   maxd=0.00;
00092   for(i=0;i<SFXinfo->nvert;i++){
00093    d=sqrt(v[i].p[paxis]*v[i].p[paxis] + v[i].p[paxis2]*v[i].p[paxis2]);
00094    maxd=max(maxd,d);
00095   }
00096  }
00097  for(i=0;i<SFXinfo->nvert;i++){
00098   if(type == 1) d=v[i].p[paxis];       /* Linear */
00099   else if(type == 2){                  /* Radial */
00100    d=sqrt(v[i].p[paxis]*v[i].p[paxis] + v[i].p[paxis2]*v[i].p[paxis2]);
00101   }
00102   displacement=amplitude*cos(PI*2*((SFXinfo->time*PRMfreq)-d/wavelength));
00103   if(type == 1){                       /* Linear */
00104    d = v[i].p[paxis]-SFXinfo->vmin[paxis];
00105    maxd = SFXinfo->vmax[paxis]-SFXinfo->vmin[paxis];
00106   }
00107   if(fade == 2) displacement *= d / maxd;             /* fade up */
00108   else if(fade == 3) displacement *= 1 - d / maxd;    /* fade down */
00109   v[i].p[axis] += displacement;
00110  }
00111  return 1;
00112 }
00113 
00114 void _PreviewExternalEffect(char *parameters, sfxinfo *SFXinfo,
00115                                     Svertex *v){
00116  double amplitude,wavelength,displacement,PRMamp,PRMlngth,PRMfreq,d,maxd;
00117  char buffer[256];
00118  int type, PRMaxis, axis, fade, paxis, paxis2;
00119  long i;
00120 //MessageBox(NULL,parameters,NULL,MB_OK);
00121  sscanf(parameters,"%s %d %d %f %f %f %d",buffer,&type,&PRMaxis,&PRMamp,
00122         &PRMlngth,&PRMfreq,&fade);
00123  if(PRMaxis == 3) axis=1;         /* F / B */
00124  else if(PRMaxis == 1) axis=2;    /* U / D */
00125  else if(PRMaxis == 2) axis=0;    /* L / R */
00126  if(axis == 0){      paxis = 1; paxis2 = 2; }
00127  else if(axis == 2){ paxis = 1; paxis2 = 0; }
00128  else if(axis == 1){ paxis = 0; paxis2 = 2; }
00129  wavelength=max((SFXinfo->vmax[paxis]-SFXinfo->vmin[paxis]) * PRMlngth,1.0);
00130  amplitude=(PRMamp/25.0) * (wavelength/8);
00131  if(type == 2){                        /* Radial */
00132   maxd=0.00;
00133   for(i=0;i<SFXinfo->nvert;i++){
00134    d=sqrt(v[i][paxis]*v[i][paxis] + v[i][paxis2]*v[i][paxis2]);
00135    maxd=max(maxd,d);
00136   }
00137  }
00138  for(i=0;i<SFXinfo->nvert;i++){
00139   if(type == 1) d=v[i][paxis];       /* Linear */
00140   else if(type == 2){                  /* Radial */
00141    d=sqrt(v[i][paxis]*v[i][paxis] + v[i][paxis2]*v[i][paxis2]);
00142   }
00143   displacement=amplitude*cos(PI*2*((SFXinfo->time*PRMfreq)-d/wavelength));
00144   if(type == 1){                       /* Linear */
00145    d = v[i][paxis]-SFXinfo->vmin[paxis];
00146    maxd = SFXinfo->vmax[paxis]-SFXinfo->vmin[paxis];
00147   }
00148   if(fade == 2) displacement *= d / maxd;             /* fade up */
00149   else if(fade == 3) displacement *= 1 - d / maxd;    /* fade down */
00150   v[i][axis] += displacement;
00151  }
00152 }
00153 
00154 BOOL CALLBACK DlgProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam);
00155 
00156 static int type=1,motion=1,fade=1;
00157 static double amp=25.0,length=1.0,freq=1.0;
00158 
00159 char * _SetExternalParameters(
00160   char *Op,                 /* string for the parameters                  */
00161   HWND hWnd,                /* parent window                              */
00162   long ruler,               /* ruler scale value to facilitate scaling    */
00163   char *name,               /* name of DLL file with the effect           */
00164   X__MEMORY_MANAGER *lpEVI /* pointer to structure with memory functions */
00165   ){
00166  char buffer[128];
00167  if(Op != NULL){  /* parameters exist so read them off the list          */
00168                   /* the name of the DLL file is always the first string */
00169    sscanf(Op,"%s %ld %ld %f %f %f %ld",buffer,&type,&motion,
00170           &amp,&length,&freq,&fade);
00171  }
00172 //MessageBox(hWnd,"Set Params","Debug",MB_OK);
00173  if(DialogBox(hDLLinstance,MAKEINTRESOURCE(DLG_WAVE),hWnd,
00174               (DLGPROC)DlgProc) == FALSE)return Op;
00175  if(Op != NULL)CALL_FREE(Op);  /* free the old string */
00176  sprintf(buffer,"4 %ld %ld %f %f %f %ld",type,motion,amp,length,freq,fade);
00177  if((Op=(char *)CALL_MALLOC(strlen(buffer)+1)) == NULL){
00178   MessageBox (GetFocus(),"External effect: Out of memory","Error",
00179                 MB_OK|MB_TASKMODAL|MB_ICONSTOP);
00180    return NULL;
00181  }
00182  strcpy(Op,buffer);
00183 //MessageBox(NULL,Op,NULL,MB_OK);
00184  return Op;
00185 }
00186 
00187 BOOL CALLBACK DlgProc(HWND hDlg,UINT msg,WPARAM wparam,LPARAM lparam){
00188  char str[16];
00189  switch( msg ) {
00190    case WM_INITDIALOG:
00191      if(type == 2)SendDlgItemMessage(hDlg,DLG_WAVE_RADIAL,BM_SETCHECK,1,0);
00192      else         SendDlgItemMessage(hDlg,DLG_WAVE_LINEAR,BM_SETCHECK,1,0);
00193      if     (motion == 3)SendDlgItemMessage(hDlg,DLG_WAVE_FB,BM_SETCHECK,1,0);
00194      else if(motion == 2)SendDlgItemMessage(hDlg,DLG_WAVE_LR,BM_SETCHECK,1,0);
00195      else                SendDlgItemMessage(hDlg,DLG_WAVE_UD,BM_SETCHECK,1,0);
00196      if     (fade == 3)SendDlgItemMessage(hDlg,DLG_WAVE_FADE_DOWN,BM_SETCHECK,1,0);
00197      else if(fade == 2)SendDlgItemMessage(hDlg,DLG_WAVE_FADE_UP,BM_SETCHECK,1,0);
00198      else              SendDlgItemMessage(hDlg,DLG_WAVE_FADE_NONE,BM_SETCHECK,1,0);
00199      sprintf(str,"%.2f",amp);
00200      SetDlgItemText(hDlg,DLG_WAVE_AMP,str);
00201      sprintf(str,"%.2f",length);
00202      SetDlgItemText(hDlg,DLG_WAVE_LENGTH,str);
00203      sprintf(str,"%.2f",freq);
00204      SetDlgItemText(hDlg,DLG_WAVE_FREQ,str);
00205      LoadAnimatedClip(hDlg);
00206      CentreDialogOnScreen(hDlg);
00207      return TRUE;
00208    case WM_PAINT:
00209      PaintBackground(hDlg);
00210      break;
00211     case WM_SYSCOMMAND:
00212       switch(LOWORD(wparam & 0xfff0)){
00213         case SC_CLOSE:
00214           EndDialog(hDlg,FALSE);
00215           return(TRUE);
00216         default:
00217           break;
00218       }
00219       break;
00220    case WM_COMMAND:
00221      switch(LOWORD(wparam)){
00222         case DLG_WAVE_LINEAR:    type=1; break;
00223         case DLG_WAVE_RADIAL:    type=2; break;
00224         case DLG_WAVE_UD:        motion=1; break;
00225         case DLG_WAVE_LR:        motion=2; break;
00226         case DLG_WAVE_FB:        motion=3; break;
00227         case DLG_WAVE_FADE_NONE: fade=1; break;
00228         case DLG_WAVE_FADE_UP:   fade=2; break;
00229         case DLG_WAVE_FADE_DOWN: fade=3; break;
00230         case DLG_WAVE_OK:
00231           if(GetDlgItemText(hDlg,DLG_WAVE_AMP,str,12) != 0)
00232             sscanf(str,"%f",&amp);
00233           if(GetDlgItemText(hDlg,DLG_WAVE_LENGTH,str,12) != 0)
00234             sscanf(str,"%f",&length);
00235           if(GetDlgItemText(hDlg,DLG_WAVE_FREQ,str,12) != 0)
00236             sscanf(str,"%f",&freq);
00237           EndDialog(hDlg,TRUE);
00238           return(TRUE);
00239         case DLG_WAVE_CANCEL:
00240           EndDialog(hDlg,FALSE);
00241           return(TRUE);
00242         default:
00243           break;
00244       }
00245       break;
00246     default: break;
00247  }
00248  return FALSE;
00249 }
Generated on Tue Jan 28 06:18:30 2014 for OpenFX by  doxygen 1.6.3