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 #include <stdlib.h>
00027 #include <stdio.h>
00028 #include <float.h>
00029 #include <math.h>
00030 #include <windows.h>
00031 #include "struct.h"
00032 #include "..\common\postprocess\ximage.h"
00033 #include "local.h"
00034
00035 #define y1 myy1
00036
00037 #include "lasers.h"
00038
00039 #if __X__MIPS__
00040 BOOL WINAPI _CRT_INIT(HINSTANCE ,DWORD , LPVOID );
00041 #endif
00042
00043 static HINSTANCE hDLLinstance=NULL;
00044 static long version=1;
00045
00046 #include "utils.h"
00047 #include "paint.c"
00048
00049
00050 #if __WATCOMC__
00051 int APIENTRY LibMain(HANDLE hDLL, DWORD dwReason, LPVOID lpReserved){
00052 #elif __BC__
00053 BOOL WINAPI DllEntryPoint(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;
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(DllMain)
00075 #endif
00076
00077 static void SetColour(unsigned char *colour, HWND parent){
00078 CHOOSECOLOR cc;
00079 static COLORREF CustColours[16]={
00080 RGB(255,255,255), RGB(239,239,239), RGB(223,223,223), RGB(207,207,207),
00081 RGB(191,191,191), RGB(175,175,175), RGB(159,159,159), RGB(143,143,143),
00082 RGB(127,127,127), RGB(111,111,111), RGB( 95, 95, 95), RGB( 79, 79, 79),
00083 RGB( 63, 63, 63), RGB( 47, 47, 47), RGB( 31, 31, 31), RGB( 15, 15, 15) };
00084 cc.lStructSize=sizeof(CHOOSECOLOR);
00085 cc.hwndOwner=parent;
00086 cc.rgbResult=RGB((BYTE)colour[0],(BYTE)colour[1],(BYTE)colour[2]);
00087 cc.lpCustColors=(LPDWORD)CustColours;
00088 cc.Flags= CC_RGBINIT;
00089 cc.lCustData=(DWORD)0;
00090 if(ChooseColor(&cc)){
00091 colour[0]=(unsigned char)GetRValue(cc.rgbResult);
00092 colour[1]=(unsigned char)GetGValue(cc.rgbResult);
00093 colour[2]=(unsigned char)GetBValue(cc.rgbResult);
00094 }
00095 }
00096
00097 static void DrawInBuffer1(long x, long y, fullscreenbuffer *Screen,
00098 long X, long Y, long radius,
00099 double r, double g, double b,
00100 double z, float *Zb, BOOL bDraw){
00101 long i,j;
00102 double d;
00103 fullscreenbuffer *S;
00104 for(i=x-radius;i<=x+radius;i++)for(j=y-radius;j<=y+radius;j++){
00105 if(i < 0 || i >= X || j < 0 || j >= Y)continue;
00106 S=(Screen + j*X + i);
00107 if(radius < 1)d=1.0;
00108 else{
00109 d=sqrt((double)(i-x)*(double)(i-x) + (double)(j-y)*(double)(j-y));
00110 d=255.0*((double)radius-d)/(double)radius;
00111 d=max(0.0,d);
00112 }
00113 if(Zb == NULL || !bDraw || z < *(Zb + j*X + i)){
00114 S->R = (unsigned char)min(255.0,(double)S->R+d*r);
00115 S->G = (unsigned char)min(255.0,(double)S->G+d*g);
00116 S->B = (unsigned char)min(255.0,(double)S->B+d*b);
00117 }
00118 }
00119 return;
00120 }
00121
00122 void DrawInBuffer(fullscreenbuffer *Screen, int Xmax, int Ymax,
00123 int x, int y, double v,
00124 double rr, double gg, double bb,
00125 double z, float *Zb,BOOL bDraw){
00126 int r,g,b;
00127 fullscreenbuffer *S;
00128 if(x < 0 || y < 0 || x >= Xmax || y >= Ymax)return;
00129 if(Zb == NULL || !bDraw || z < *(Zb + y*Xmax + x)){
00130 S=(Screen+y*Xmax+x);
00131 r=(int)S->R+(int)((double)v*rr);
00132 g=(int)S->G+(int)((double)v*gg);
00133 b=(int)S->B+(int)((double)v*bb);
00134 S->R=(r>255) ? 255:r;
00135 S->G=(g>255) ? 255:g;
00136 S->B=(b>255) ? 255:b;
00137 }
00138 }
00139
00140 #define frac(z) fmod(z,1.0)
00141 #define imod(z,a) ((z) - ((z)/(a))*(a))
00142
00143 void DrawAApixel(double x, double y, double w, double h, double C,
00144 fullscreenbuffer *S, int X, int Y,
00145 double r, double g, double b,
00146 double z, float *Zb, BOOL bDraw){
00147 int xa,xb,ya,yb,i,j,brite;
00148 double x2,y2,lfrac,rfrac,tfrac,bfrac,xfrac,yfrac;
00149 if(w > 3 || h > 3){
00150 DrawInBuffer1((long)x,(long)y,S,X,Y,(long)w,r,g,b,z,Zb,bDraw);
00151 return;
00152 }
00153 brite=(int)C;
00154 if(x < 0 || y < 0)return;
00155 x -= w*0.5; y -= h*0.5;
00156 x2 = x + w;
00157 y2 = y + w;
00158 xa = (int)x;
00159 xb = (int)x2;
00160 ya = (int)y;
00161 yb = (int)y2;
00162 lfrac = 1.0-frac(x);
00163 rfrac = frac(x2);
00164 tfrac = 1.0-frac(y);
00165 bfrac = frac(y2);
00166 if (xa==xb) {
00167 xfrac = lfrac+rfrac-1.0;
00168 if (ya==yb){
00169 DrawInBuffer(S,X,Y,xa,ya,xfrac*(tfrac+bfrac-1.0)*brite,
00170 r,g,b,z,Zb,bDraw);
00171 }
00172 else {
00173 DrawInBuffer(S,X,Y,xa,ya,xfrac*tfrac*brite,r,g,b,z,Zb,bDraw);
00174 for (j=ya+1; j<yb; j++)DrawInBuffer(S,X,Y,xa,j,xfrac*brite,
00175 r,g,b,z,Zb,bDraw);
00176 DrawInBuffer(S,X,Y,xa,yb,xfrac*bfrac*brite,r,g,b,z,Zb,bDraw);
00177 }
00178 }
00179 else {
00180 if (ya==yb) {
00181 yfrac = tfrac+bfrac-1.0;
00182 DrawInBuffer(S,X,Y,xa,ya,yfrac*lfrac*brite,r,g,b,z,Zb,bDraw);
00183 for (i=xa+1; i<xb; i++)DrawInBuffer(S,X,Y,i,ya,yfrac*brite,
00184 r,g,b,z,Zb,bDraw);
00185 DrawInBuffer(S,X,Y,xb,ya,yfrac*rfrac*brite,r,g,b,z,Zb,bDraw);
00186 }
00187 else {
00188 DrawInBuffer(S,X,Y,xa,ya,tfrac*lfrac*brite,r,g,b,z,Zb,bDraw);
00189 for (i=xa+1; i<xb; i++)DrawInBuffer(S,X,Y,i,ya,tfrac*brite,
00190 r,g,b,z,Zb,bDraw);
00191 DrawInBuffer(S,X,Y,xb,ya,tfrac*rfrac*brite,r,g,b,z,Zb,bDraw);
00192 for (j=ya+1; j<yb; j++) {
00193 DrawInBuffer(S,X,Y,xa,j,lfrac*brite,r,g,b,z,Zb,bDraw);
00194 for (i=xa+1; i<xb; i++)DrawInBuffer(S,X,Y,i,j,brite,
00195 r,g,b,z,Zb,bDraw);
00196 DrawInBuffer(S,X,Y,xb,j,rfrac*brite,r,g,b,z,Zb,bDraw);
00197 }
00198 DrawInBuffer(S,X,Y,xa,yb,bfrac*lfrac*brite,r,g,b,z,Zb,bDraw);
00199 for (i=xa+1; i<xb; i++)DrawInBuffer(S,X,Y,i,yb,bfrac*brite,
00200 r,g,b,z,Zb,bDraw);
00201 DrawInBuffer(S,X,Y,xb,yb,bfrac*rfrac*brite,r,g,b,z,Zb,bDraw);
00202 }
00203 }
00204 }
00205
00206 #define DIST(i,j) sqrt((double)i * (double)i + (double)j * (double)j)
00207
00208 #define DIST3(i,j,k) sqrt((double)(i) * (double)(i) + \
00209 (double)(j) * (double)(j) + \
00210 (double)(k) * (double)(k) )
00211
00212 static double GetW(double l, double dx, double dy,
00213 double Wmin, double Wmax){
00214 double d,f;
00215 d=DIST(dx,dy);
00216 f=d/l;
00217 return (Wmin+(Wmax-Wmin)*f);
00218 }
00219
00220 static double GetZ(long i, long j , long x, long y, long xt, long yt,
00221 double y1, double y2){
00222 double d;
00223 d=DIST((xt-x),(yt-y));
00224 if(d < 1.e-10)return y1;
00225 d=DIST((i-x),(j-y))/d;
00226 return y1+d*(y2-y1);
00227 }
00228
00229 static void DrawLineInBuffer(long x, long y, long xt, long yt,
00230 double x1, double y1, double z1,
00231 double x2, double y2, double z2,
00232 fullscreenbuffer *Screen,
00233 long X, long Y,
00234 double Cin,
00235 double r, double g, double b,
00236 double Wmin, double Wmax,
00237 float *Zb, BOOL bDraw){
00238 long i,j,idx,idy;
00239 double z,grad,error,W,l,C;
00240 idx=xt-x; idy=yt-y;
00241 C=Cin;
00242 l=DIST(idx,idy);
00243 if(abs(idx) >= abs(idy)){
00244 grad=(double)idy/(double)idx; j=y;
00245 if(idy >= 0)error = -0.5; else error = 0.5;
00246 if(idx >= 0){
00247 for(i=x;i<x+idx;i++){
00248 error += grad;
00249 if(idy >= 0){
00250 if(error > 0.0){j++; error -= 1.0;}
00251 }
00252 else{
00253 if(error < 0.0){j--; error += 1.0;}
00254 }
00255 W=GetW(l,(double)(i-x),(double)(j-y),Wmin,Wmax);
00256 z=GetZ(i,j,x,y,xt,yt,y1,y2);
00257 DrawAApixel((double)i,(double)j,W,W,C,Screen,X,Y,r,g,b,z,Zb,bDraw);
00258 }
00259 }
00260 else{
00261 for(i=x;i>x+idx;i--){
00262 error -= grad;
00263 if(idy >= 0){
00264 if(error > 0.0){j++; error -= 1.0;}
00265 }
00266 else{
00267 if(error < 0.0){j--; error += 1.0;}
00268 }
00269 W=GetW(l,(double)(i-x),(double)(j-y),Wmin,Wmax);
00270 z=GetZ(i,j,x,y,xt,yt,y1,y2);
00271 DrawAApixel((double)i,(double)j,W,W,C,Screen,X,Y,r,g,b,z,Zb,bDraw);
00272 }
00273 }
00274 }
00275 else{
00276 grad=(double)idx/(double)idy; j=x;
00277 if(idx >= 0)error = -0.5; else error = 0.5;
00278 if(idy >= 0){
00279 for(i=y;i<y+idy;i++){
00280 error += grad;
00281 if(idx >= 0){
00282 if(error > 0.0){j++; error -= 1.0;}
00283 }
00284 else{
00285 if(error < 0.0){j--; error += 1.0;}
00286 }
00287 W=GetW(l,(double)(j-x),(double)(i-y),Wmin,Wmax);
00288 z=GetZ(j,i,x,y,xt,yt,y1,y2);
00289 DrawAApixel((double)j,(double)i,W,W,C,Screen,X,Y,r,g,b,z,Zb,bDraw);
00290 }
00291 }
00292 else{
00293 for(i=y;i>y+idy;i--){
00294 error -= grad;
00295 if(idx >= 0){
00296 if(error > 0.0){j++; error -= 1.0;}
00297 }
00298 else{
00299 if(error < 0.0){j--; error += 1.0;}
00300 }
00301 W=GetW(l,(double)(j-x),(double)(i-y),Wmin,Wmax);
00302 z=GetZ(j,i,x,y,xt,yt,y1,y2);
00303 DrawAApixel((double)j,(double)i,W,W,C,Screen,X,Y,r,g,b,z,Zb,bDraw);
00304 }
00305 }
00306 }
00307 return;
00308 }
00309
00310 static double GetYint(double x, double y, double dx, double dy, double xe){
00311 double grad;
00312 grad=dy/dx;
00313 return grad*(xe-x)+y;
00314 }
00315
00316 static double GetXint(double x, double y, double dx, double dy, double ye){
00317 double grad;
00318 grad=dx/dy;
00319 return grad*(ye-y)+x;
00320 }
00321
00322 static void GetBorderPosition(long xc, long yc,
00323 long *x, long *y,
00324 long Xmax, long Ymax){
00325 long dx,dy;
00326 double ddx,ddy,dxc,dyc,ye,xe,ds,de,fr;
00327 dx = *x - xc;
00328 dy = *y - yc;
00329 if(dx == 0 && dy == 0)dx=1;
00330 ddx=(double)dx; ddy=(double)dy;
00331 dxc=(double)xc; dyc=(double)yc;
00332 if(dx == 0){
00333 xe=xc;
00334 if(dy > 0)ye=(double)Ymax;
00335 else ye=0.0;
00336 }
00337 else if(dy == 0){
00338 ye=yc;
00339 if(dx < 0)xe=0.0;
00340 else xe=(double)Xmax;
00341 }
00342 else {
00343 if(dx > 0)xe=(double)Xmax;
00344 else xe=0.0;
00345 ye=GetYint(dxc,dyc,ddx,ddy,xe);
00346 if(ye < 0){
00347 xe=GetXint(dxc,dyc,ddx,ddy,0);
00348 ye=0.0;
00349 }
00350 else if(ye > Ymax){
00351 xe=GetXint(dxc,dyc,ddx,ddy,(double)Ymax);
00352 ye=(double)Ymax;
00353 }
00354 }
00355 *x=(long)xe;
00356 *y=(long)ye;
00357 return;
00358 }
00359
00360 static BOOL ClipView(double *x1, double *y1, double *z1,
00361 double *x2, double *y2, double *z2){
00362 double mu;
00363 if(*y1 >= 0.0 && *y2 >= 0.0)return TRUE;
00364 if(*y1 <= 0.0 && *y2 <= 0.0)return FALSE;
00365 if(*y1 < 0.0){
00366 mu = (*y1 - *y2) / *y1;
00367 *y1 = 0.1;
00368 *x1 = *x1 + mu*(*x2 - *x1);
00369 *z1 = *z1 + mu*(*z2 - *z1);
00370 }
00371 else{
00372 mu = (*y2 - *y1) / *y2;
00373 *y2 = 0.1;
00374 *x2 = *x2 + mu*(*x1 - *x2);
00375 *z2 = *z2 + mu*(*z1 - *z2);
00376 }
00377 return TRUE;
00378 }
00379
00380 static BOOL ClipScreen(long *x1, long *y1,
00381 long *x2, long *y2,
00382 long xmin, long xmax,
00383 long ymin, long ymax){
00384 if((*x1 < 0 || *x1 >= xmax) &&
00385 (*y1 < 0 || *y1 >= ymax) &&
00386 (*x2 < 0 || *x2 >= xmax) &&
00387 (*y2 < 0 || *y2 >= ymax))return FALSE;
00388 if((*x1 >= 0 && *x1 < xmax) &&
00389 (*y1 >= 0 && *y1 < ymax) &&
00390 (*x2 >= 0 && *x2 < xmax) &&
00391 (*y2 >= 0 && *y2 < ymax))return TRUE;
00392 if((*x1 >= 0 && *x1 < xmax) &&
00393 (*y1 >= 0 && *y1 < ymax)){
00394 GetBorderPosition(*x1,*y1,x2,y2,xmax,ymax);
00395 }
00396 else{
00397 GetBorderPosition(*x2,*y2,x1,y1,xmax,ymax);
00398 }
00399 return TRUE;
00400 }
00401
00402 long _RenderImageProcess(char *PrmList, XIMAGE *lpXimage){
00403 int i,j;
00404 char buffer[255];
00405 double x1,y1,z1,x2,y2,z2,mr=0.0,r,g,b,rad,dx,dy,dz;
00406 long xx1,yy1,xx2,yy2,dframe;
00407 long irad,hide,hold,type,c1,c2,c3,type1,id1,ix1,iy1,iz1,type2,id2,ix2,iy2,iz2,
00408 mirad,mhide,mhold,mtype,mc1,mc2,mc3,mtype1,mid1,mix1,miy1,miz1,
00409 mtype2,mid2,mix2,miy2,miz2;
00410 float *Zb;
00411 BOOL bDraw,bMorph=FALSE;
00412 #include "pro_key.c"
00413 sscanf(PrmList,
00414 "%s %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld",
00415 buffer,&version,&irad,
00416 &hide,&hold,&type,&c1,&c2,&c3,
00417 &type1,&id1,&ix1,&iy1,&iz1,
00418 &type2,&id2,&ix2,&iy2,&iz2);
00419 if(lpXimage->Morph && lpXimage->mParameters != NULL){
00420 bMorph=TRUE; mr=lpXimage->MorphRatio;
00421 sscanf(PrmList,
00422 "%s %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld",
00423 buffer,&version,&mirad,
00424 &mhide,&mhold,&mtype,&mc1,&mc2,&mc3,
00425 &mtype1,&mid1,&mix1,&miy1,&miz1,
00426 &mtype2,&mid2,&mix2,&miy2,&miz2);
00427 irad=(long)((double)mirad + mr*((double)irad-(double)mirad));
00428 c1=(long)((double)mc1+mr*((double)c1-(double)mc1));
00429 c2=(long)((double)mc2+mr*((double)c2-(double)mc2));
00430 c3=(long)((double)mc3+mr*((double)c3-(double)mc3));
00431 ix1=(long)((double)mix1+mr*((double)ix1-(double)mix1));
00432 iy1=(long)((double)miy1+mr*((double)iy1-(double)miy1));
00433 iz1=(long)((double)miz1+mr*((double)iz1-(double)miz1));
00434 ix2=(long)((double)mix2+mr*((double)ix2-(double)mix2));
00435 iy2=(long)((double)miy2+mr*((double)iy2-(double)miy2));
00436 iz2=(long)((double)miz2+mr*((double)iz2-(double)miz2));
00437 }
00438 if(!bMorph){
00439 mr=(double)(lpXimage->last_frame - lpXimage->first_frame);
00440 if(mr < 1.0)return 1;
00441 mr=(double)(lpXimage->this_frame - lpXimage->first_frame)/mr;
00442 }
00443 dframe=lpXimage->this_frame - lpXimage->first_frame;
00444 r=(double)c1/255.0;
00445 g=(double)c2/255.0;
00446 b=(double)c3/255.0;
00447 Zb=lpXimage->Zbuffer;
00448 if(hide && Zb != NULL)bDraw=TRUE;
00449 else bDraw=FALSE;
00450 rad = (double)irad*(double)lpXimage->Xmax/320.0;
00451 if(type1 == 1 || lpXimage->Nlights == 0)
00452 TransformIntoView(lpXimage->ViewTransform,
00453 (double)ix1,(double)iy1,(double)iz1,&x1,&y1,&z1);
00454 else for(i=0;i<lpXimage->Nlights;i++){
00455 if(lpXimage->Lights[i].AnimatorID != id1)continue;
00456 x1=lpXimage->Lights[i].p[0];
00457 y1=lpXimage->Lights[i].p[1];
00458 z1=lpXimage->Lights[i].p[2];
00459 break;
00460 }
00461 if(type2 == 1 || lpXimage->Nlights == 0)
00462 TransformIntoView(lpXimage->ViewTransform,
00463 (double)ix2,(double)iy2,(double)iz2,&x2,&y2,&z2);
00464 else for(i=0;i<lpXimage->Nlights;i++){
00465 if(lpXimage->Lights[i].AnimatorID != id2)continue;
00466 x2=lpXimage->Lights[i].p[0];
00467 y2=lpXimage->Lights[i].p[1];
00468 z2=lpXimage->Lights[i].p[2];
00469 break;
00470 }
00471 if(!ClipView(&x1,&y1,&z1,&x2,&y2,&z2))return 1;
00472 if(type == 2){
00473 double f=0.1,l,px,py,pz,px1,py1,pz1,px2,py2,pz2;
00474 dx=x2-x1; dy=y2-y1; dz=z2-z1;
00475 px=x1+mr*dx; py=y1+mr*dy; pz=z1+mr*dz;
00476 l=DIST3(dx,dy,dz);
00477 px1=px-f*dx; py1=py-f*dy; pz1=pz-f*dz;
00478 if(DIST3((x1-px1),(y1-py1),(z1-pz1)) < l*f){px1=x1; py1=y1; pz1=z1;}
00479 px2=px+f*dx; py2=py+f*dy; pz2=pz+f*dz;
00480 if(DIST3((x2-px2),(y2-py2),(z2-pz2)) < l*f){px2=x2; py2=y2; pz2=z2;}
00481 x1=px1; y1=py1; z1=pz1;
00482 x2=px2; y2=py2; z2=pz2;
00483 }
00484 else if(hold == 1){
00485 dx=x2-x1; dy=y2-y1; dz=z2-z1;
00486 x2=x1+mr*dx; y2=y1+mr*dy; z2=z1+mr*dz;
00487 }
00488 else if(hold == 3){
00489 dx=x2-x1; dy=y2-y1; dz=z2-z1;
00490 x1=x1+mr*dx; y1=y1+mr*dy; z1=z1+mr*dz;
00491 }
00492 if(type == 3){
00493 long i,istart,n=30,ninc=3;
00494 double px1,py1,pz1,px2,py2,pz2;
00495 dx=x2-x1; dy=y2-y1; dz=z2-z1;
00496 dx /= (double)n; dy /= (double)n; dz /= (double)n;
00497 px1=x1; py1=y1; pz1=z1;
00498 istart=imod(dframe,ninc);
00499 for(i=istart;i<n;i+=ninc){
00500 px1=x1+(double)i*dx; px2=px1+dx;
00501 py1=y1+(double)i*dy; py2=py1+dy;
00502 pz1=z1+(double)i*dz; pz2=pz1+dz;
00503 xx1=lpXimage->Xmax/2 + (long)(lpXimage->Xscale*px1/py1);
00504 yy1=lpXimage->Ymax/2 - (long)(lpXimage->Yscale*pz1/py1);
00505 xx2=lpXimage->Xmax/2 + (long)(lpXimage->Xscale*px2/py2);
00506 yy2=lpXimage->Ymax/2 - (long)(lpXimage->Yscale*pz2/py2);
00507 if(!ClipScreen(&xx1,&yy1,&xx2,&yy2,
00508 0,lpXimage->Xmax,0,lpXimage->Ymax))return 1;
00509 DrawLineInBuffer(xx1,yy1,xx2,yy2,
00510 px1,py1,pz1,
00511 px2,py2,pz2,
00512 lpXimage->Screen,
00513 lpXimage->Xmax,lpXimage->Ymax,
00514 255.0,r,g,b,
00515 (double)rad,(double)rad,
00516 Zb,bDraw);
00517 }
00518 }
00519 else{
00520 xx1=lpXimage->Xmax/2 + (long)(lpXimage->Xscale*x1/y1);
00521 yy1=lpXimage->Ymax/2 - (long)(lpXimage->Yscale*z1/y1);
00522 xx2=lpXimage->Xmax/2 + (long)(lpXimage->Xscale*x2/y2);
00523 yy2=lpXimage->Ymax/2 - (long)(lpXimage->Yscale*z2/y2);
00524 if(!ClipScreen(&xx1,&yy1,&xx2,&yy2,
00525 0,lpXimage->Xmax,0,lpXimage->Ymax))return 1;
00526 DrawLineInBuffer(xx1,yy1,xx2,yy2,
00527 x1,y1,z1,
00528 x2,y2,z2,
00529 lpXimage->Screen,
00530 lpXimage->Xmax,lpXimage->Ymax,
00531 255.0,r,g,b,
00532 (double)rad,(double)rad,
00533 Zb,bDraw);
00534 }
00535 return 1;
00536 }
00537
00538
00539
00540 long _RenderGLexternal(char *PrmList, XIMAGE *lpXimage){
00541 MessageBox(NULL,"OpenGL function called","OK",MB_OK);
00542 return 1;
00543 }
00544
00545
00546
00547 BOOL CALLBACK DlgProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam);
00548
00549 static double x1=0.0,y1=0.0,z1=0.0,x2=0.0,y2=1.0,z2=0.0;
00550 static long irad=2,hide=1,hold=2,type=1,id1 = -1, id2 = -1,type1=1,type2=1,
00551 c1=255,c2=0,c3=0;
00552 static X__MEMORY_MANAGER *lpLocalEVI;
00553
00554
00555 char * _SetExternalParameters(
00556 char *Op,
00557 HWND hWnd,
00558 long ruler,
00559 char *name,
00560 X__MEMORY_MANAGER *lpEVI
00561 ){
00562 char buffer[512];
00563 long ix1,iy1,iz1,ix2,iy2,iz2;
00564 if(Op != NULL){
00565 sscanf(Op,"%s %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld",
00566 buffer,&version,&irad,
00567 &hide,&hold,&type,&c1,&c2,&c3,
00568 &type1,&id1,&ix1,&iy1,&iz1,
00569 &type2,&id2,&ix2,&iy2,&iz2);
00570 x1=(double)ix1/(double)ruler;
00571 y1=(double)iy1/(double)ruler;
00572 z1=(double)iz1/(double)ruler;
00573 x2=(double)ix2/(double)ruler;
00574 y2=(double)iy2/(double)ruler;
00575 z2=(double)iz2/(double)ruler;
00576 }
00577 lpLocalEVI=lpEVI;
00578 if(DialogBox(hDLLinstance,MAKEINTRESOURCE(DLG_LASER),hWnd,
00579 (DLGPROC)DlgProc) == FALSE)return Op;
00580 if(Op != NULL)CALL_FREE(Op);
00581 ix1=(long)(x1*(double)ruler);
00582 iy1=(long)(y1*(double)ruler);
00583 iz1=(long)(z1*(double)ruler);
00584 ix2=(long)(x2*(double)ruler);
00585 iy2=(long)(y2*(double)ruler);
00586 iz2=(long)(z2*(double)ruler);
00587 sprintf(buffer,
00588 "%s %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld",
00589 name,version,irad,
00590 hide,hold,type,c1,c2,c3,
00591 type1,id1,ix1,iy1,iz1,
00592 type2,id2,ix2,iy2,iz2);
00593 if((Op=(char *)CALL_MALLOC(strlen(buffer)+1)) == NULL){
00594 MessageBox (GetFocus(),"External effect: Out of memory","Error",
00595 MB_OK|MB_TASKMODAL|MB_ICONSTOP);
00596 return NULL;
00597 }
00598 strcpy(Op,buffer);
00599 return Op;
00600 }
00601
00602 BOOL CALLBACK DlgProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam){
00603 BOOL err;
00604 char str[32];
00605 switch( msg ) {
00606 case WM_INITDIALOG:
00607 SetDlgItemInt(hwnd,DLG_LASER_RADIUS,irad,TRUE);
00608 if(hide == 1)SendDlgItemMessage(hwnd,DLG_LASER_HIDE,BM_SETCHECK,TRUE,0);
00609 if(type == 1)SendDlgItemMessage(hwnd,DLG_LASER_TYPE1,BM_SETCHECK,TRUE,0);
00610 if(type == 2)SendDlgItemMessage(hwnd,DLG_LASER_TYPE2,BM_SETCHECK,TRUE,0);
00611 if(type == 3)SendDlgItemMessage(hwnd,DLG_LASER_TYPE3,BM_SETCHECK,TRUE,0);
00612 if(hold == 1)SendDlgItemMessage(hwnd,DLG_LASER_IN,BM_SETCHECK,TRUE,0);
00613 if(hold == 2)SendDlgItemMessage(hwnd,DLG_LASER_HOLD,BM_SETCHECK,TRUE,0);
00614 if(hold == 3)SendDlgItemMessage(hwnd,DLG_LASER_OUT,BM_SETCHECK,TRUE,0);
00615 if(type1 == 1)SendDlgItemMessage(hwnd,DLG_LASER_1_TYPE1,BM_SETCHECK,TRUE,0);
00616 if(type1 == 2)SendDlgItemMessage(hwnd,DLG_LASER_1_TYPE2,BM_SETCHECK,TRUE,0);
00617 if(id1 >= 0)SendDlgItemMessage(hwnd,DLG_LASER_1_NAME,WM_SETTEXT,
00618 0,(LPARAM)GetActorsName(lpLocalEVI->lpAni,id1));
00619 sprintf(str,"%.3f",x1); SetDlgItemText(hwnd,DLG_LASER_1_X,str);
00620 sprintf(str,"%.3f",y1); SetDlgItemText(hwnd,DLG_LASER_1_Y,str);
00621 sprintf(str,"%.3f",z1); SetDlgItemText(hwnd,DLG_LASER_1_Z,str);
00622 if(type2 == 1)SendDlgItemMessage(hwnd,DLG_LASER_2_TYPE1,BM_SETCHECK,TRUE,0);
00623 if(type2 == 2)SendDlgItemMessage(hwnd,DLG_LASER_2_TYPE2,BM_SETCHECK,TRUE,0);
00624 if(id2 >= 0)SendDlgItemMessage(hwnd,DLG_LASER_2_NAME,WM_SETTEXT,
00625 0,(LPARAM)GetActorsName(lpLocalEVI->lpAni,id2));
00626 sprintf(str,"%.3f",x2); SetDlgItemText(hwnd,DLG_LASER_2_X,str);
00627 sprintf(str,"%.3f",y2); SetDlgItemText(hwnd,DLG_LASER_2_Y,str);
00628 sprintf(str,"%.3f",z2); SetDlgItemText(hwnd,DLG_LASER_2_Z,str);
00629 CentreDialogOnScreen(hwnd);
00630 return TRUE;
00631 case WM_PAINT:
00632 PaintBackground(hwnd);
00633 break;
00634 case WM_DRAWITEM:{
00635 LPDRAWITEMSTRUCT lpdis;
00636 HBRUSH hbr,hbrold;
00637 BYTE r,g,b;
00638 lpdis=(LPDRAWITEMSTRUCT)lparam;
00639 if(lpdis->CtlID == DLG_LASER_COLOUR){
00640 r=(BYTE)c1; g=(BYTE)c2; b=(BYTE)c3;
00641 if(lpdis->itemState & ODS_SELECTED)
00642 InvertRect(lpdis->hDC,&(lpdis->rcItem));
00643 else{
00644 hbr=CreateSolidBrush(RGB(r,g,b));
00645 hbrold=SelectObject(lpdis->hDC,hbr);
00646 Rectangle(lpdis->hDC,lpdis->rcItem.left,lpdis->rcItem.top,
00647 lpdis->rcItem.right,lpdis->rcItem.bottom);
00648 SelectObject(lpdis->hDC,hbrold);
00649 DeleteObject(hbr);
00650 }
00651 }
00652 }
00653 break;
00654 case WM_COMMAND:
00655 switch(LOWORD(wparam)){
00656 case DLG_LASER_COLOUR:{
00657 unsigned char colour[3];
00658 colour[0]=(unsigned char)c1;
00659 colour[1]=(unsigned char)c2;
00660 colour[2]=(unsigned char)c3;
00661 SetColour(colour,hwnd);
00662 c1=(long)colour[0]; c2=(long)colour[1]; c3=(long)colour[2];
00663 InvalidateRect(GetDlgItem(hwnd,DLG_LASER_COLOUR),NULL,FALSE);
00664 }
00665 break;
00666 case DLG_LASER_1_SETID:
00667 id1=GetActorsID(lpLocalEVI->lpAni,hwnd);
00668 if(id1 >= 0)SendDlgItemMessage(hwnd,DLG_LASER_1_NAME,WM_SETTEXT,
00669 0,(LPARAM)GetActorsName(lpLocalEVI->lpAni,id1));
00670 break;
00671 case DLG_LASER_2_SETID:
00672 id2=GetActorsID(lpLocalEVI->lpAni,hwnd);
00673 if(id2 >= 0)SendDlgItemMessage(hwnd,DLG_LASER_2_NAME,WM_SETTEXT,
00674 0,(LPARAM)GetActorsName(lpLocalEVI->lpAni,id2));
00675 break;
00676 case IDCANCEL:
00677 EndDialog(hwnd,FALSE);
00678 return(TRUE);
00679 case IDOK:
00680 irad=GetDlgItemInt(hwnd,DLG_LASER_RADIUS,&err,FALSE);
00681 if(SendDlgItemMessage(hwnd,DLG_LASER_HIDE,BM_GETCHECK,0,0))
00682 hide=1;
00683 else hide=0;
00684 if(SendDlgItemMessage(hwnd,DLG_LASER_TYPE1,BM_GETCHECK,0,0))type=1;
00685 if(SendDlgItemMessage(hwnd,DLG_LASER_TYPE2,BM_GETCHECK,0,0))type=2;
00686 if(SendDlgItemMessage(hwnd,DLG_LASER_TYPE3,BM_GETCHECK,0,0))type=3;
00687 if(SendDlgItemMessage(hwnd,DLG_LASER_IN,BM_GETCHECK,0,0))hold=1;
00688 if(SendDlgItemMessage(hwnd,DLG_LASER_HOLD,BM_GETCHECK,0,0))hold=2;
00689 if(SendDlgItemMessage(hwnd,DLG_LASER_OUT,BM_GETCHECK,0,0))hold=3;
00690 if(SendDlgItemMessage(hwnd,DLG_LASER_1_TYPE1,BM_GETCHECK,0,0))
00691 type1=1;
00692 if(SendDlgItemMessage(hwnd,DLG_LASER_1_TYPE2,BM_GETCHECK,0,0))
00693 type1=2;
00694 if(GetDlgItemText(hwnd,DLG_LASER_1_X,str,12) != 0)
00695 sscanf(str,"%f",&x1);
00696 if(GetDlgItemText(hwnd,DLG_LASER_1_Y,str,12) != 0)
00697 sscanf(str,"%f",&y1);
00698 if(GetDlgItemText(hwnd,DLG_LASER_1_Z,str,12) != 0)
00699 sscanf(str,"%f",&z1);
00700 if(GetDlgItemText(hwnd,DLG_LASER_2_X,str,12) != 0)
00701 sscanf(str,"%f",&x2);
00702 if(GetDlgItemText(hwnd,DLG_LASER_2_Y,str,12) != 0)
00703 sscanf(str,"%f",&y2);
00704 if(GetDlgItemText(hwnd,DLG_LASER_2_Z,str,12) != 0)
00705 sscanf(str,"%f",&z2);
00706 if(SendDlgItemMessage(hwnd,DLG_LASER_2_TYPE1,BM_GETCHECK,0,0))
00707 type2=1;
00708 if(SendDlgItemMessage(hwnd,DLG_LASER_2_TYPE2,BM_GETCHECK,0,0))
00709 type2=2;
00710 EndDialog(hwnd,TRUE);
00711 return(TRUE);
00712 default:
00713 break;
00714 }
00715 break;
00716 default: break;
00717 }
00718 return FALSE;
00719 }
00720