shake.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 /* shake.c */
00025 
00026 #include <math.h>
00027 #include <windows.h>
00028 #include <commctrl.h>
00029 
00030 #include "shake.h"
00031 
00032 #if __ZTC__ || __SC__
00033 #ifndef max
00034 #define max(a,b)  ( ((a) > (b)) ? (a) : (b) )
00035 #endif
00036 #endif
00037 
00038 #ifndef PI
00039 #define PI 3.1415926
00040 #endif
00041 
00042 #if __X__MIPS__
00043 BOOL WINAPI _CRT_INIT(HINSTANCE ,DWORD , LPVOID );
00044 #endif
00045 
00046 static HINSTANCE hDLLinstance=NULL;
00047 
00048 #include "pstruct.h"
00049 
00050 #include "paint.c"
00051 
00052 #if __WATCOMC__
00053 int APIENTRY LibMain(HANDLE hDLL, DWORD dwReason, LPVOID lpReserved){
00054 #else
00055 BOOL WINAPI DllMain(HANDLE hDLL, DWORD dwReason, LPVOID lpReserved){
00056 #endif
00057   switch (dwReason) {
00058     case DLL_PROCESS_ATTACH:
00059 #if __X__MIPS__
00060       if(!_CRT_INIT(hDLL,dwReason,lpReserved))return(int)FALSE;
00061 #endif
00062       hDLLinstance = hDLL;  /* handle to DLL file */
00063       break;
00064     case DLL_PROCESS_DETACH:
00065 #if __X__MIPS__
00066       if(!_CRT_INIT(hDLL,dwReason,lpReserved))return(int)FALSE;
00067 #endif
00068       break;
00069   }
00070 return (int)TRUE;
00071 }
00072 
00073 #if __SC__
00074 #pragma startaddress(LibMain)
00075 #endif
00076 
00077 /* internal effects have no need to use this */
00078 
00079 long _RenderGlobalEffect
00080 (char *PrmList, sfxinfo *SFXinfo, sfxdata *SFXdata, vertex *Vlist){
00081  return 1;
00082 }
00083 
00084 void _PreviewGlobalEffect
00085 (char *PrmList, sfxinfo *SFXinfo, sfxdata *SFXdata, Svertex *Vlist){
00086  return;
00087 }
00088 
00089 long _RenderExternalEffect(char *PrmList, sfxinfo *SFXinfo,
00090                                  vertex *v){
00091  double displacement,dpmax,dpmin,t,sp;
00092  long i;
00093  t=SFXinfo->time;
00094  dpmax=(double)(SFXinfo->vmax[2]-SFXinfo->vmin[2])*
00095        (double)(SFXinfo->vmax[2]-SFXinfo->vmin[2]);
00096  dpmin=(double)(SFXinfo->vmax[0]-SFXinfo->vmin[0])/4.0;
00097  sp=dpmin*sin(2*PI*SFXinfo->time);
00098  for(i=0;i<SFXinfo->nvert;i++){
00099   displacement=sp*((double)(v[i].p[2]-SFXinfo->vmin[2])/dpmax)*
00100                    (double)(v[i].p[2]-SFXinfo->vmin[2]);
00101   v[i].p[0] += displacement;
00102  }
00103  return 1;
00104 }
00105 
00106 void _PreviewExternalEffect(char *parameters, sfxinfo *SFXinfo,
00107                                     Svertex *v){
00108  double displacement,dpmax,dpmin,t,sp;
00109  long i;
00110  t=SFXinfo->time;
00111  dpmax=(double)(SFXinfo->vmax[2]-SFXinfo->vmin[2])*
00112        (double)(SFXinfo->vmax[2]-SFXinfo->vmin[2]);
00113  dpmin=(double)(SFXinfo->vmax[0]-SFXinfo->vmin[0])/4.0;
00114  sp=dpmin*sin(2*PI*SFXinfo->time);
00115  for(i=0;i<SFXinfo->nvert;i++){
00116   displacement=sp*((double)(v[i][2]-SFXinfo->vmin[2])/dpmax)*
00117                    (double)(v[i][2]-SFXinfo->vmin[2]);
00118   v[i][0] += displacement;
00119  }
00120 }
00121 
00122 BOOL CALLBACK DlgProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam);
00123 
00124 char * _SetExternalParameters(
00125   char *Op,                 /* string for the parameters                  */
00126   HWND hWnd,                /* parent window                              */
00127   long ruler,               /* ruler scale value to facilitate scaling    */
00128   char *name,               /* name of DLL file with the effect           */
00129   X__MEMORY_MANAGER *lpEVI /* pointer to structure with memory functions */
00130   ){
00131  char buffer[128];
00132  if(Op != NULL){  /* parameters exist so read them off the list          */
00133                   /* the name of the DLL file is always the first string */
00134    sscanf(Op,"%s",buffer);
00135  }
00136  if(DialogBox(hDLLinstance,MAKEINTRESOURCE(DLG_SHAKE),hWnd,
00137               (DLGPROC)DlgProc) == FALSE)return Op;
00138  if(Op != NULL)CALL_FREE(Op);  /* free the old string */
00139  sprintf(buffer,"9");
00140  if((Op=(char *)CALL_MALLOC(strlen(buffer)+1)) == NULL){
00141   MessageBox (GetFocus(),"External effect: Out of memory","Error",
00142                 MB_OK|MB_TASKMODAL|MB_ICONSTOP);
00143    return NULL;
00144  }
00145  strcpy(Op,buffer);
00146  return Op;
00147 }
00148 
00149 BOOL CALLBACK DlgProc(HWND hDlg,UINT msg,WPARAM wparam,LPARAM lparam){
00150  switch( msg ) {
00151    case WM_INITDIALOG:
00152      LoadAnimatedClip(hDlg);
00153      CentreDialogOnScreen(hDlg);
00154      return TRUE;
00155    case WM_PAINT:
00156      PaintBackground(hDlg);
00157      break;
00158    case WM_SYSCOMMAND:
00159      switch(LOWORD(wparam & 0xfff0)){
00160        case SC_CLOSE:
00161          EndDialog(hDlg,FALSE);
00162          return(TRUE);
00163        default:
00164          break;
00165      }
00166      break;
00167    case WM_COMMAND:
00168      switch(LOWORD(wparam)){
00169         case DLG_SHAKE_OK:
00170           EndDialog(hDlg,TRUE);
00171           return(TRUE);
00172         case DLG_SHAKE_CANCEL:
00173           EndDialog(hDlg,FALSE);
00174           return(TRUE);
00175         default:
00176           break;
00177       }
00178       break;
00179     default: break;
00180  }
00181  return FALSE;
00182 }
Generated on Tue Jan 28 06:18:29 2014 for OpenFX by  doxygen 1.6.3