squash.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 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 /* squash.c */
00025 
00026 #include <math.h>
00027 #include <windows.h>
00028 #include <commctrl.h>
00029 
00030 #include "squash.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 *parameters, sfxinfo *SFXinfo,
00090                                  vertex *v){
00091  double scale,dpmax,dpmin,t,sp;
00092  int PRMcomp;
00093  long i;
00094  char buffer[128];
00095  int PRMeffect, PRMplane, axis, paxis, paxis2;
00096  sscanf(parameters,"%s %d %d %d",buffer,&PRMeffect,&PRMplane,&PRMcomp);
00097  t=SFXinfo->time;
00098  t = -1.00 * (t*t) + 2.00 * t;
00099  if(PRMeffect == 2) t = 1.00 - t;
00100  if(PRMplane == 1){           /* Horizontal Plane */
00101   axis=2; paxis=1; paxis2=0;
00102  }
00103  else if(PRMplane == 2){      /* Vertical Plane */
00104   axis=1; paxis=0; paxis2=2;
00105  }
00106  dpmax=max(fabs(SFXinfo->vmin[axis]),fabs(SFXinfo->vmax[axis]));
00107  dpmin=dpmax-t*dpmax*((double)PRMcomp/100.0);
00108  sp=dpmin/dpmax;
00109  for(i=0;i<SFXinfo->nvert;i++){
00110   scale=1.0+((double)PRMcomp/100.0)*t*cos(PI/2*v[i].p[axis]/dpmax);
00111   v[i].p[axis]   *= sp;
00112   v[i].p[paxis]  *= 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 scale,dpmax,dpmin,t,sp;
00121  int PRMcomp;
00122  long i;
00123  char buffer[128];
00124  int PRMeffect, PRMplane, axis, paxis, paxis2;
00125  sscanf(parameters,"%s %d %d %d",buffer,&PRMeffect,&PRMplane,&PRMcomp);
00126  t=SFXinfo->time;
00127  t = -1.00 * (t*t) + 2.00 * t;
00128  if(PRMeffect == 2) t = 1.00 - t;
00129  if(PRMplane == 1){           /* Horizontal Plane */
00130   axis=2; paxis=1; paxis2=0;
00131  }
00132  else if(PRMplane == 2){      /* Vertical Plane */
00133   axis=1; paxis=0; paxis2=2;
00134  }
00135  dpmax=max(fabs(SFXinfo->vmin[axis]),fabs(SFXinfo->vmax[axis]));
00136  dpmin=dpmax-t*dpmax*((double)PRMcomp/100.0);
00137  sp=dpmin/dpmax;
00138  for(i=0;i<SFXinfo->nvert;i++){
00139   scale=1.0+((double)PRMcomp/100.0)*t*cos(PI/2*v[i][axis]/dpmax);
00140   v[i][axis]   *= sp;
00141   v[i][paxis]  *= scale;
00142   v[i][paxis2] *= scale;
00143  }
00144 }
00145 
00146 BOOL CALLBACK DlgProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam);
00147 
00148 static int squash=1,plane=1,fraction=75;
00149 
00150 char * _SetExternalParameters(
00151   char *Op,                 /* string for the parameters                  */
00152   HWND hWnd,                /* parent window                              */
00153   long ruler,               /* ruler scale value to facilitate scaling    */
00154   char *name,               /* name of DLL file with the effect           */
00155   X__MEMORY_MANAGER *lpEVI /* pointer to structure with memory functions */
00156   ){
00157  char buffer[128];
00158  if(Op != NULL){  /* parameters exist so read them off the list          */
00159                   /* the name of the DLL file is always the first string */
00160    sscanf(Op,"%s %ld %ld %ld",buffer,&squash,&plane,&fraction);
00161  }
00162  if(DialogBox(hDLLinstance,MAKEINTRESOURCE(DLG_SQUASH),hWnd,
00163               (DLGPROC)DlgProc) == FALSE)return Op;
00164  if(Op != NULL)CALL_FREE(Op);  /* free the old string */
00165  sprintf(buffer,"6 %ld %ld %ld",squash,plane,fraction);
00166  if((Op=(char *)CALL_MALLOC(strlen(buffer)+1)) == NULL){
00167   MessageBox (GetFocus(),"External effect: Out of memory","Error",
00168                 MB_OK|MB_TASKMODAL|MB_ICONSTOP);
00169    return NULL;
00170  }
00171  strcpy(Op,buffer);
00172  return Op;
00173 }
00174 
00175 BOOL CALLBACK DlgProc(HWND hDlg,UINT msg,WPARAM wparam,LPARAM lparam){
00176  char str[12];
00177  switch( msg ) {
00178    case WM_INITDIALOG:
00179      if(squash == 1)SendDlgItemMessage(hDlg,DLG_SQUASH_SQUASH,BM_SETCHECK,1,0);
00180      else SendDlgItemMessage(hDlg,DLG_SQUASH_UNSQUASH,BM_SETCHECK,1,0);
00181      if(plane == 1)SendDlgItemMessage(hDlg,DLG_SQUASH_HORIZ,BM_SETCHECK,1,0);
00182      else          SendDlgItemMessage(hDlg,DLG_SQUASH_VERT,BM_SETCHECK,1,0);
00183      SetDlgItemInt(hDlg,DLG_SQUASH_FRACTION,fraction,FALSE);
00184      LoadAnimatedClip(hDlg);
00185      CentreDialogOnScreen(hDlg);
00186      return TRUE;
00187    case WM_PAINT:
00188      PaintBackground(hDlg);
00189      break;
00190    case WM_SYSCOMMAND:
00191      switch(LOWORD(wparam & 0xfff0)){
00192        case SC_CLOSE:
00193          EndDialog(hDlg,FALSE);
00194          return(TRUE);
00195        default:
00196          break;
00197      }
00198      break;
00199    case WM_COMMAND:
00200      switch(LOWORD(wparam)){
00201         case DLG_SQUASH_SQUASH:    squash=1; break;
00202         case DLG_SQUASH_UNSQUASH:  squash=2; break;
00203         case DLG_SQUASH_HORIZ:     plane=1; break;
00204         case DLG_SQUASH_VERT:      plane=2; break;
00205         case DLG_SQUASH_OK:
00206           if(GetDlgItemText(hDlg,DLG_SQUASH_FRACTION,str,3) != 0)
00207             fraction=atoi(str);
00208           EndDialog(hDlg,TRUE);
00209           return(TRUE);
00210         case DLG_SQUASH_CANCEL:
00211           EndDialog(hDlg,FALSE);
00212           return(TRUE);
00213         default:
00214           break;
00215       }
00216       break;
00217     default: break;
00218  }
00219  return FALSE;
00220 }
Generated on Tue Jan 28 06:18:29 2014 for OpenFX by  doxygen 1.6.3