00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include <stdlib.h>
00018 #include <stdio.h>
00019 #include <math.h>
00020 #include <float.h>
00021 #include <windows.h>
00022 #include <gl/gl.h>
00023
00024 #if __ZTC__ || __SC__
00025 #ifndef max
00026 #define max(a,b) ( ((a) > (b)) ? (a) : (b) )
00027 #endif
00028 #endif
00029
00030 #if __WATCOMC__
00031 #define PI 3.1415926
00032 #endif
00033
00034 #if __X__MIPS__
00035 BOOL WINAPI _CRT_INIT(HINSTANCE ,DWORD , LPVOID );
00036 #endif
00037
00038 static HINSTANCE hDLLinstance=NULL;
00039
00040 #include "..\animate\memory.h"
00041 #include "..\animate\memdef.h"
00042 #include "defines.h"
00043 #include "rstruct.h"
00044 #include "v_bozo.h"
00045
00046
00047 #if __WATCOMC__
00048 int APIENTRY LibMain(HANDLE hDLL, DWORD dwReason, LPVOID lpReserved){
00049 #else
00050 BOOL WINAPI DllMain(HANDLE hDLL, DWORD dwReason, LPVOID lpReserved){
00051 #endif
00052 HANDLE ghMod;
00053 switch (dwReason) {
00054 case DLL_PROCESS_ATTACH:
00055 #if __X__MIPS__
00056 if(!_CRT_INIT(hDLL,dwReason,lpReserved))return(int)FALSE;
00057 #endif
00058 hDLLinstance = hDLL;
00059 break;
00060 case DLL_PROCESS_DETACH:
00061 #if __X__MIPS__
00062 if(!_CRT_INIT(hDLL,dwReason,lpReserved))return(int)FALSE;
00063 #endif
00064 break;
00065 }
00066 return (int)TRUE;
00067 }
00068
00069 #if __SC__
00070 #pragma startaddress(DllMain)
00071 #endif
00072
00073 #define VECCOPY(a,b) { b[0] = a[0]; b[1] = a[1]; b[2] = a[2]; }
00074
00075 static double turb=0.1,t1=0.4,t2=0.7,c[3]={255.0,255.0,0.0};
00076 static double x=1.0,y=1.0,z=1.0;
00077 static long tr_type=0,tr_type1=0,tr_type2=0,tr_type3=0;
00078
00079 #if 0
00080 long CALLBACK ExternalTextureStartup(
00081 #else
00082 long _ExternalTextureStartup(
00083 #endif
00084 long frame,long nframes,char *parameter_list, X__SHADER *lpEVI){
00085 if(parameter_list[0] != '#'){
00086 MessageBox ( GetFocus(),
00087 (LPCTSTR) "External texture: Startup",
00088 (LPCTSTR) "Parameter list missing",
00089 MB_OK | MB_SYSTEMMODAL );
00090 }
00091 else {
00092 parameter_list++;
00093 sscanf(parameter_list,"%f %f %f %f %f %f %f %f %f %ld %ld %ld %ld",
00094 &c[0],&c[1],&c[2],&turb,&t1,&t2,&x,&y,&z,
00095 &tr_type,&tr_type1,&tr_type2,&tr_type3);
00096 }
00097 return LoadAndCompileShader("v_bozo");
00098
00099 }
00100
00101 #if 0
00102 long CALLBACK ExternalTextureMorph(
00103 #else
00104 long _ExternalTextureMorph(
00105 #endif
00106 char *parameter_list, double mr){
00107 int i;
00108 double mx,my,mz;
00109 double mturb,mt1,mt2,mc[3];
00110 parameter_list++;
00111 sscanf(parameter_list,"%f %f %f %f %f %f %f %f %f",
00112 &mc[0],&mc[1],&mc[2],&mturb,&mt1,&mt2,&mx,&my,&mz);
00113 t1=mt1+(t1-mt1)*mr;
00114 t2=mt2+(t2-mt2)*mr;
00115 turb=(turb-mturb)*mr;
00116 for(i=0;i<3;i++)c[i]=mc[i]+(c[i]-mc[i])*mr;
00117 x=mx+(x-mx)*mr;
00118 y=my+(y-my)*mr;
00119 z=mz+(z-mz)*mr;
00120 return 1;
00121 }
00122
00123 #if 0
00124 long CALLBACK ExternalTextureProcedure(
00125 #else
00126 long _ExternalTextureProcedure(
00127 #endif
00128 long coord_type, vector p, vector n,
00129 double alpha, double beta, double gamma,
00130 double bump, double map_x, double map_y,
00131 double *alpha_channel, unsigned char sc[3], double colour[3],
00132 double *reflectivity, double *transparency,
00133 X__SHADER *lpEVI
00134 ){
00135 double xx,yy,zz,noise;
00136 vector BozoTurbulence;
00137 xx=alpha / x;
00138 yy=beta / y;
00139 zz=gamma / z;
00140 if(turb != 0.0){
00141 vTurbulence(BozoTurbulence, xx, yy, zz);
00142 xx += BozoTurbulence[0] * turb;
00143 yy += BozoTurbulence[1] * turb;
00144 zz += BozoTurbulence[2] * turb;
00145 }
00146 nNoise(xx, yy, zz, &noise);
00147 if (noise < t1){
00148 if(tr_type == 1){
00149 if(tr_type1 == 1)*transparency=1.0;
00150 else *transparency=0.0;
00151 }
00152 return 1;
00153 }
00154 else if(noise < t2){
00155 colour[0]=(double)sc[0];
00156 colour[1]=(double)sc[1];
00157 colour[2]=(double)sc[2];
00158 if(tr_type == 1){
00159 if(tr_type2 == 1)*transparency=1.0;
00160 else *transparency=0.0;
00161 }
00162 }
00163 else {
00164 colour[0]=c[0];
00165 colour[1]=c[1];
00166 colour[2]=c[2];
00167 if(tr_type == 1){
00168 if(tr_type3 == 1)*transparency=1.0;
00169 else *transparency=0.0;
00170 }
00171 }
00172 return 1;
00173 }
00174
00175 void _ExternalTextureClose(X__SHADER *lpEVI){
00176 UnloadCompiledShader(tGLshaderID);
00177 }
00178
00179 long _ExternalTextureProcedureGL(
00180 double bump_scale,
00181 unsigned char sc[3],
00182 unsigned char ac[3],
00183 X__SHADER *lpEVI
00184 ){
00185
00186 SetUniformVector(tGLshaderID,"MaterialC",(GLfloat)ac[0]/255.0,(GLfloat)ac[1]/255.0,(GLfloat)ac[2]/255.0);
00187 SetUniformVector(tGLshaderID,"MC",(GLfloat)c[0]/255.0,(GLfloat)c[1]/255.0,(GLfloat)c[2]/255.0);
00188 SetUniformVector(tGLshaderID,"ScalingV",1.0/x,1.0/z,1.0/y);
00189 SetUniformVariable(tGLshaderID,"Turb",turb);
00190 SetUniformVariable(tGLshaderID,"T1",t1);
00191 SetUniformVariable(tGLshaderID,"T2",t2);
00192 SetUniformInteger(tGLshaderID,"Type",tr_type);
00193 SetUniformInteger(tGLshaderID,"Type1",tr_type1);
00194 SetUniformInteger(tGLshaderID,"Type2",tr_type2);
00195 SetUniformInteger(tGLshaderID,"Type3",tr_type3);
00196
00197
00198
00199 DrawShadedPolygons(tmatpass,tpass,tprogID,tattrloc,tNface,tMainFp,tNvert,tMainVp);
00200 return 1;
00201 }
00203
00204 void CentreDialogOnScreen(HWND hwnd){
00205 RECT rcDlg;
00206 long Xres,Yres;
00207 Yres=GetSystemMetrics(SM_CYSCREEN);
00208 Xres=GetSystemMetrics(SM_CXSCREEN);
00209 GetWindowRect(hwnd,&rcDlg);
00210 OffsetRect(&rcDlg,-rcDlg.left,-rcDlg.top);
00211 OffsetRect(&rcDlg,(Xres-rcDlg.right)/2,(Yres-rcDlg.bottom)/2);
00212 SetWindowPos(hwnd,HWND_TOP,rcDlg.left,rcDlg.top,0,0,SWP_NOSIZE);
00213 return;
00214 }
00215
00216 static void SetColour(double *colour, HWND parent){
00217 CHOOSECOLOR cc;
00218 static COLORREF CustColours[16]={
00219 RGB(255,255,255), RGB(239,239,239), RGB(223,223,223), RGB(207,207,207),
00220 RGB(191,191,191), RGB(175,175,175), RGB(159,159,159), RGB(143,143,143),
00221 RGB(127,127,127), RGB(111,111,111), RGB( 95, 95, 95), RGB( 79, 79, 79),
00222 RGB( 63, 63, 63), RGB( 47, 47, 47), RGB( 31, 31, 31), RGB( 15, 15, 15) };
00223 cc.lStructSize=sizeof(CHOOSECOLOR);
00224 cc.hwndOwner=parent;
00225 cc.rgbResult=RGB((BYTE)colour[0],(BYTE)colour[1],(BYTE)colour[2]);
00226 cc.lpCustColors=(LPDWORD)CustColours;
00227
00228 cc.Flags= CC_RGBINIT;
00229 cc.lCustData=(DWORD)0;
00230 if(ChooseColor(&cc)){
00231 colour[0]=(double)GetRValue(cc.rgbResult);
00232 colour[1]=(double)GetGValue(cc.rgbResult);
00233 colour[2]=(double)GetBValue(cc.rgbResult);
00234 }
00235 }
00236
00237 BOOL CALLBACK BozoDlgProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam);
00238
00239 #if 0
00240 char * CALLBACK SetExternalParameters(
00241 #else
00242 char * _SetExternalParameters(
00243 #endif
00244 char *Op,
00245 HWND hWnd,
00246 X__MEMORY_MANAGER *lpEVI
00247 ){
00248 char szbuf[255],*Op1;
00249 if(Op != NULL){
00250 Op1=Op;
00251 Op1++;
00252 sscanf(Op1,"%f %f %f %f %f %f %f %f %f %ld %ld %ld %ld",
00253 &c[0],&c[1],&c[2],&turb,&t1,&t2,&x,&y,&z,
00254 &tr_type,&tr_type1,&tr_type2,&tr_type3);
00255 }
00256 if(DialogBox(hDLLinstance,MAKEINTRESOURCE(DLG_BOZO),hWnd,
00257 (DLGPROC)BozoDlgProc) == FALSE)return Op;
00258 if(Op != NULL)CALL_FREE(Op);
00259 sprintf(szbuf,"# %.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f %ld %ld %ld %ld",
00260 c[0],c[1],c[2],turb,t1,t2,x,y,z,tr_type,tr_type1,tr_type2,tr_type3);
00261 if((Op=(char *)CALL_MALLOC(strlen(szbuf)+1)) == NULL){
00262 MessageBox (GetFocus(),"External shader: Out of memory","Error",
00263 MB_OK|MB_TASKMODAL|MB_ICONSTOP);
00264 return NULL;
00265 }
00266 strcpy(Op,szbuf);
00267 return Op;
00268 }
00269
00270 BOOL CALLBACK BozoDlgProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam){
00271 char str[16];
00272 switch( msg ) {
00273 case WM_INITDIALOG:
00274 sprintf(str,"%.2f",turb);
00275 SendDlgItemMessage(hwnd,DLG_BOZO_TURB,WM_SETTEXT,0,(LPARAM)str);
00276 SendDlgItemMessage(hwnd,DLG_BOZO_TURB,EM_LIMITTEXT,(WPARAM)12,0);
00277 sprintf(str,"%.2f",t1);
00278 SendDlgItemMessage(hwnd,DLG_BOZO_T1,WM_SETTEXT,0,(LPARAM)str);
00279 SendDlgItemMessage(hwnd,DLG_BOZO_T1,EM_LIMITTEXT,(WPARAM)12,0);
00280 sprintf(str,"%.2f",t2);
00281 SendDlgItemMessage(hwnd,DLG_BOZO_T2,WM_SETTEXT,0,(LPARAM)str);
00282 SendDlgItemMessage(hwnd,DLG_BOZO_T2,EM_LIMITTEXT,(WPARAM)12,0);
00283 sprintf(str,"%.2f",x);
00284 SendDlgItemMessage(hwnd,DLG_BOZO_XSCALE,WM_SETTEXT,0,(LPARAM)str);
00285 SendDlgItemMessage(hwnd,DLG_BOZO_XSCALE,EM_LIMITTEXT,(WPARAM)12,0);
00286 sprintf(str,"%.2f",y);
00287 SendDlgItemMessage(hwnd,DLG_BOZO_YSCALE,WM_SETTEXT,0,(LPARAM)str);
00288 SendDlgItemMessage(hwnd,DLG_BOZO_YSCALE,EM_LIMITTEXT,(WPARAM)12,0);
00289 sprintf(str,"%.2f",z);
00290 SendDlgItemMessage(hwnd,DLG_BOZO_ZSCALE,WM_SETTEXT,0,(LPARAM)str);
00291 SendDlgItemMessage(hwnd,DLG_BOZO_ZSCALE,EM_LIMITTEXT,(WPARAM)12,0);
00292 if(tr_type == 0)
00293 SendDlgItemMessage(hwnd,DLG_BOZO_SEMI,BM_SETCHECK,TRUE,0);
00294 else
00295 SendDlgItemMessage(hwnd,DLG_BOZO_SETT,BM_SETCHECK,TRUE,0);
00296 if(tr_type1 == 1)
00297 SendDlgItemMessage(hwnd,DLG_BOZO_CLEARC,BM_SETCHECK,TRUE,0);
00298 if(tr_type2 == 1)
00299 SendDlgItemMessage(hwnd,DLG_BOZO_CLEARS,BM_SETCHECK,TRUE,0);
00300 if(tr_type3 == 1)
00301 SendDlgItemMessage(hwnd,DLG_BOZO_CLEAR3,BM_SETCHECK,TRUE,0);
00302 CentreDialogOnScreen(hwnd);
00303 return TRUE;
00304 case WM_DRAWITEM:{
00305 LPDRAWITEMSTRUCT lpdis;
00306 HBRUSH hbr,hbrold;
00307 BYTE r,g,b;
00308 lpdis=(LPDRAWITEMSTRUCT)lparam;
00309 if(lpdis->CtlID == DLG_BOZO_COLOUR){
00310 r=(BYTE)c[0]; g=(BYTE)c[1]; b=(BYTE)c[2];
00311 if(lpdis->itemState & ODS_SELECTED)
00312 InvertRect(lpdis->hDC,&(lpdis->rcItem));
00313 else{
00314 hbr=CreateSolidBrush(RGB(r,g,b));
00315 hbrold=SelectObject(lpdis->hDC,hbr);
00316 Rectangle(lpdis->hDC,lpdis->rcItem.left,lpdis->rcItem.top,
00317 lpdis->rcItem.right,lpdis->rcItem.bottom);
00318 SelectObject(lpdis->hDC,hbrold);
00319 DeleteObject(hbr);
00320 }
00321 }
00322 }
00323 break;
00324 case WM_COMMAND:
00325 switch(LOWORD(wparam)){
00326 case DLG_BOZO_COLOUR:
00327 SetColour(c,hwnd);
00328 InvalidateRect(GetDlgItem(hwnd,DLG_BOZO_COLOUR),NULL,FALSE);
00329 break;
00330 case IDCANCEL:
00331 case DLG_BOZO_CANCEL:
00332 EndDialog(hwnd,FALSE);
00333 return(TRUE);
00334 case IDOK:
00335 case DLG_BOZO_OK:
00336 if(GetDlgItemText(hwnd,DLG_BOZO_TURB,str,10) == 0)
00337 EndDialog(hwnd,FALSE);
00338 if((turb=atof(str)) == 0)EndDialog(hwnd,FALSE);
00339 if(GetDlgItemText(hwnd,DLG_BOZO_T1,str,10) == 0)
00340 EndDialog(hwnd,FALSE);
00341 if((t1=atof(str)) == 0)EndDialog(hwnd,FALSE);
00342 if(GetDlgItemText(hwnd,DLG_BOZO_T2,str,10) == 0)
00343 EndDialog(hwnd,FALSE);
00344 if((t2=atof(str)) == 0)EndDialog(hwnd,FALSE);
00345 if(GetDlgItemText(hwnd,DLG_BOZO_XSCALE,str,10) == 0)
00346 EndDialog(hwnd,FALSE);
00347 if((x=atof(str)) == 0)EndDialog(hwnd,FALSE);
00348 if(GetDlgItemText(hwnd,DLG_BOZO_YSCALE,str,10) == 0)
00349 EndDialog(hwnd,FALSE);
00350 if((y=atof(str)) == 0)EndDialog(hwnd,FALSE);
00351 if(GetDlgItemText(hwnd,DLG_BOZO_ZSCALE,str,10) == 0)
00352 EndDialog(hwnd,FALSE);
00353 if((z=atof(str)) == 0)EndDialog(hwnd,FALSE);
00354 if(SendDlgItemMessage(hwnd,DLG_BOZO_SETT,BM_GETCHECK,0,0))
00355 tr_type=1; else tr_type=0;
00356 if(SendDlgItemMessage(hwnd,DLG_BOZO_CLEARC,BM_GETCHECK,0,0))
00357 tr_type1=1; else tr_type1=0;
00358 if(SendDlgItemMessage(hwnd,DLG_BOZO_CLEARS,BM_GETCHECK,0,0))
00359 tr_type2=1; else tr_type2=0;
00360 if(SendDlgItemMessage(hwnd,DLG_BOZO_CLEAR3,BM_GETCHECK,0,0))
00361 tr_type3=1; else tr_type3=0;
00362 EndDialog(hwnd,TRUE);
00363 return(TRUE);
00364 default:
00365 break;
00366 }
00367 break;
00368 default: break;
00369 }
00370 return FALSE;
00371 }