00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 #include <stdlib.h>
00041 #include <stdio.h>
00042 #include <float.h>
00043 #include <math.h>
00044 #include <windows.h>
00045 #include "struct.h"
00046 #include "..\common\postprocess\ximage.h"
00047 #include "local.h"
00048
00049 #include "halo.h"
00050
00051 #if __X__MIPS__
00052 BOOL WINAPI _CRT_INIT(HINSTANCE ,DWORD , LPVOID );
00053 #endif
00054
00055 static HINSTANCE hDLLinstance=NULL;
00056 static long version=1;
00057
00058
00059
00060 #include "utils.h"
00061 #include "paint.c"
00062
00063
00064
00065 #if __WATCOMC__
00066 int APIENTRY LibMain(HANDLE hDLL, DWORD dwReason, LPVOID lpReserved){
00067 #elif __BC__
00068 BOOL WINAPI DllEntryPoint(HANDLE hDLL, DWORD dwReason, LPVOID lpReserved){
00069 #else
00070 BOOL WINAPI DllMain(HANDLE hDLL, DWORD dwReason, LPVOID lpReserved){
00071 #endif
00072 switch (dwReason) {
00073 case DLL_PROCESS_ATTACH:
00074 #if __X__MIPS__
00075 if(!_CRT_INIT(hDLL,dwReason,lpReserved))return(int)FALSE;
00076 #endif
00077 hDLLinstance = hDLL;
00078 break;
00079 case DLL_PROCESS_DETACH:
00080 #if __X__MIPS__
00081 if(!_CRT_INIT(hDLL,dwReason,lpReserved))return(int)FALSE;
00082 #endif
00083 break;
00084 }
00085 return (int)TRUE;
00086 }
00087
00088 #if __SC__
00089 #pragma startaddress(DllMain)
00090 #endif
00091
00092 static void DrawInBuffer(long x, long y, fullscreenbuffer *Screen,
00093 long X, long Y, long radius,
00094 double r, double g, double b,
00095 double z, float *Zb,
00096 BOOL bDraw, long hide){
00097
00098 long i,j;
00099 double d;
00100 fullscreenbuffer *S;
00101
00102 for(i=x-radius;i<=x+radius;i++)for(j=y-radius;j<=y+radius;j++){
00103 if(i < 0 || i >= X || j < 0 || j >= Y)continue;
00104 S=(Screen + j*X + i);
00105 if(radius < 1)d=1.0;
00106 else{
00107 d=sqrt((double)(i-x)*(double)(i-x) + (double)(j-y)*(double)(j-y));
00108 d=255.0*((double)radius-d)/(double)radius;
00109 d=max(0.0,d);
00110 }
00111
00112 if(!hide || bDraw || z < *(Zb + j*X + i)){
00113 S->R = (unsigned char)min(255.0,(double)S->R+d*r);
00114 S->G = (unsigned char)min(255.0,(double)S->G+d*g);
00115 S->B = (unsigned char)min(255.0,(double)S->B+d*b);
00116 }
00117 }
00118 return;
00119 }
00120
00121 long _RenderImageProcess(char *PrmList, XIMAGE *lpXimage){
00122
00123
00124
00125
00126 int i,j;
00127 char dummy[255];
00128 double x,y,z,mr,r,g,b;
00129 long xx,yy,radius,iradius,hide,miradius,type,id;
00130 float *Zb;
00131 BOOL bDraw;
00132 if(lpXimage->Nlights == 0 || lpXimage->Lights == NULL)return 1;
00133 sscanf(PrmList,"%s %ld %ld %ld %ld %ld",dummy,&version,
00134 &iradius,&hide,&type,&id);
00135 if(lpXimage->Morph && lpXimage->mParameters != NULL){
00136 mr=lpXimage->MorphRatio;
00137 sscanf(lpXimage->mParameters,"%s %ld %ld",dummy,&version,&miradius);
00138 iradius=(long)((double)miradius + mr*((double)iradius-(double)miradius));
00139 }
00140 Zb=lpXimage->Zbuffer;
00141 for(i=0;i<lpXimage->Nlights;i++){
00142 if(type == 2 && lpXimage->Lights[i].type != DUMMYL)continue;
00143 if(type == 3 && lpXimage->Lights[i].AnimatorID != id)continue;
00144 x=lpXimage->Lights[i].p[0];
00145 y=lpXimage->Lights[i].p[1];
00146 z=lpXimage->Lights[i].p[2];
00147 if(y >= 1.000){
00148 xx=lpXimage->Xmax/2 +
00149 (long)(lpXimage->Xscale*x/y);
00150 yy=lpXimage->Ymax/2 -
00151 (long)(lpXimage->Yscale*z/y);
00152 if(xx >= 0 && xx < lpXimage->Xmax &&
00153 yy >= 0 && yy < lpXimage->Ymax){
00154
00155
00156 if(Zb != NULL){
00157 if(y < *(Zb + (yy * lpXimage->Xmax) + xx))bDraw=TRUE;
00158 else bDraw=FALSE;
00159 }
00160 else bDraw=TRUE;
00161 radius = (long)(lpXimage->Xscale*(double)iradius/y);
00162 r=(double)(lpXimage->Lights[i].color[0])/255.0;
00163 g=(double)(lpXimage->Lights[i].color[1])/255.0;
00164 b=(double)(lpXimage->Lights[i].color[2])/255.0;
00165 DrawInBuffer(xx,yy,lpXimage->Screen,
00166 lpXimage->Xmax,lpXimage->Ymax,radius,
00167 r,g,b,
00168 y,Zb,bDraw,hide);
00169 }
00170 }
00171 }
00172 return 1;
00173 }
00174
00175
00176
00177 long _RenderGLexternal(char *PrmList, XIMAGE *lpXimage){
00178 MessageBox(NULL,"Fog OpenGL function called","OK",MB_OK);
00179 return 1;
00180 }
00181
00182
00183
00184
00185
00186
00187 BOOL CALLBACK DlgProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam);
00188
00189 static double rad=1.0;
00190 static long hide=1,type=1,id = -1;
00191 static X__MEMORY_MANAGER *lpLocalEVI;
00192
00193 char * _SetExternalParameters(
00194 char *Op,
00195 HWND hWnd,
00196 long ruler,
00197 char *name,
00198 X__MEMORY_MANAGER *lpEVI
00199 ){
00200
00201 char buffer[256];
00202 long irad;
00203 if(Op != NULL){
00204 sscanf(Op,"%s %ld %ld %ld %ld %ld",buffer,&version,&irad,&hide,&type,&id);
00205
00206 rad=(double)irad/(double)ruler;
00207 }
00208
00209
00210 lpLocalEVI=lpEVI;
00211 if(DialogBox(hDLLinstance,MAKEINTRESOURCE(DLG_HALO),hWnd,
00212 (DLGPROC)DlgProc) == FALSE)return Op;
00213
00214 if(Op != NULL)CALL_FREE(Op);
00215
00216
00217 irad=(long)(rad*(double)ruler);
00218 sprintf(buffer,"%s %ld %ld %ld %ld %ld",name,version,irad,hide,type,id);
00219
00220 if((Op=(char *)CALL_MALLOC(strlen(buffer)+1)) == NULL){
00221 MessageBox (GetFocus(),"External effect: Out of memory","Error",
00222 MB_OK|MB_TASKMODAL|MB_ICONSTOP);
00223 return NULL;
00224 }
00225
00226 strcpy(Op,buffer);
00227 return Op;
00228 }
00229
00230 BOOL CALLBACK DlgProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam){
00231
00232
00233
00234
00235 char str[32];
00236 switch( msg ) {
00237 case WM_INITDIALOG:
00238 sprintf(str,"%.3f",rad);
00239 SetDlgItemText(hwnd,DLG_HALO_RADIUS,str);
00240 if(hide == 1)SendDlgItemMessage(hwnd,DLG_HALO_HIDE,BM_SETCHECK,TRUE,0);
00241 if(type == 1)SendDlgItemMessage(hwnd,DLG_HALO_TYPE1,BM_SETCHECK,TRUE,0);
00242 if(type == 2)SendDlgItemMessage(hwnd,DLG_HALO_TYPE2,BM_SETCHECK,TRUE,0);
00243 if(type == 3)SendDlgItemMessage(hwnd,DLG_HALO_TYPE3,BM_SETCHECK,TRUE,0);
00244 if(id >= 0)SendDlgItemMessage(hwnd,DLG_HALO_NAME,WM_SETTEXT,
00245 0,(LPARAM)GetActorsName(lpLocalEVI->lpAni,id));
00246 CentreDialogOnScreen(hwnd);
00247 return TRUE;
00248 case WM_PAINT:
00249 PaintBackground(hwnd);
00250 break;
00251 case WM_COMMAND:
00252 switch(LOWORD(wparam)){
00253 case DLG_HALO_SETID:
00254 id=GetActorsID(lpLocalEVI->lpAni,hwnd);
00255 if(id >= 0)SendDlgItemMessage(hwnd,DLG_HALO_NAME,WM_SETTEXT,
00256 0,(LPARAM)GetActorsName(lpLocalEVI->lpAni,id));
00257 break;
00258 case IDCANCEL:
00259 EndDialog(hwnd,FALSE);
00260 return(TRUE);
00261 case IDOK:
00262 if(GetDlgItemText(hwnd,DLG_HALO_RADIUS,str,12) != 0)
00263 sscanf(str,"%f",&rad);
00264 if(SendDlgItemMessage(hwnd,DLG_HALO_HIDE,BM_GETCHECK,0,0))
00265 hide=1;
00266 else hide=0;
00267 if(SendDlgItemMessage(hwnd,DLG_HALO_TYPE1,BM_GETCHECK,0,0))type=1;
00268 if(SendDlgItemMessage(hwnd,DLG_HALO_TYPE2,BM_GETCHECK,0,0))type=2;
00269 if(SendDlgItemMessage(hwnd,DLG_HALO_TYPE3,BM_GETCHECK,0,0))type=3;
00270 EndDialog(hwnd,TRUE);
00271 return(TRUE);
00272 default:
00273 break;
00274 }
00275 break;
00276 default: break;
00277 }
00278 return FALSE;
00279 }
00280