00001
00002
00003
00004
00005
00006
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
00045 hDLLinstance = hDLL;
00046 break;
00047 case DLL_PROCESS_DETACH:
00048 #if __X__MIPS__
00049 if(!_CRT_INIT(hDLL,dwReason,lpReserved))return(int)FALSE;
00050 #endif
00051
00052 break;
00053 }
00054 return (int)TRUE;
00055 }
00056
00057 #if __SC__
00058 #pragma startaddress(LibMain)
00059 #endif
00060
00061
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
00080 sscanf(parameters,"%s %d %d %f %f %f %d",buffer,&type,&PRMaxis,&PRMamp,
00081 &PRMlngth,&PRMfreq,&fade);
00082 if(PRMaxis == 3) axis=1;
00083 else if(PRMaxis == 1) axis=2;
00084 else if(PRMaxis == 2) axis=0;
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){
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];
00099 else if(type == 2){
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){
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;
00108 else if(fade == 3) displacement *= 1 - d / maxd;
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
00121 sscanf(parameters,"%s %d %d %f %f %f %d",buffer,&type,&PRMaxis,&PRMamp,
00122 &PRMlngth,&PRMfreq,&fade);
00123 if(PRMaxis == 3) axis=1;
00124 else if(PRMaxis == 1) axis=2;
00125 else if(PRMaxis == 2) axis=0;
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){
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];
00140 else if(type == 2){
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){
00145 d = v[i][paxis]-SFXinfo->vmin[paxis];
00146 maxd = SFXinfo->vmax[paxis]-SFXinfo->vmin[paxis];
00147 }
00148 if(fade == 2) displacement *= d / maxd;
00149 else if(fade == 3) displacement *= 1 - d / maxd;
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,
00161 HWND hWnd,
00162 long ruler,
00163 char *name,
00164 X__MEMORY_MANAGER *lpEVI
00165 ){
00166 char buffer[128];
00167 if(Op != NULL){
00168
00169 sscanf(Op,"%s %ld %ld %f %f %f %ld",buffer,&type,&motion,
00170 &,&length,&freq,&fade);
00171 }
00172
00173 if(DialogBox(hDLLinstance,MAKEINTRESOURCE(DLG_WAVE),hWnd,
00174 (DLGPROC)DlgProc) == FALSE)return Op;
00175 if(Op != NULL)CALL_FREE(Op);
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
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",&);
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 }