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 <math.h>
00027 #include <windows.h>
00028 #include <stdio.h>
00029 #include "stereov.h"
00030 #include "..\postprocess\utils.h"
00031
00032 #if __ZTC__ || __SC__
00033 #ifndef max
00034 #define max(a,b) ( ((a) > (b)) ? (a) : (b) )
00035 #endif
00036 #endif
00037
00038 #if __X__MIPS__
00039 BOOL WINAPI _CRT_INIT(HINSTANCE ,DWORD , LPVOID );
00040 #endif
00041
00042 static HINSTANCE hDLLinstance=NULL;
00043 static BOOL CALLBACK Instr(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);
00044
00045 #include "..\animate\astruct.h"
00046 #include "..\animate\dstruct.h"
00047
00048
00049 #if __WATCOMC__
00050 int APIENTRY LibMain(HANDLE hDLL, DWORD dwReason, LPVOID lpReserved){
00051 #else
00052 BOOL WINAPI DllMain(HANDLE hDLL, DWORD dwReason, LPVOID lpReserved){
00053 #endif
00054 switch (dwReason) {
00055 case DLL_PROCESS_ATTACH:
00056 #if __X__MIPS__
00057 if(!_CRT_INIT(hDLL,dwReason,lpReserved))return(int)FALSE;
00058 #endif
00059 hDLLinstance = hDLL;
00060 break;
00061 case DLL_PROCESS_DETACH:
00062 #if __X__MIPS__
00063 if(!_CRT_INIT(hDLL,dwReason,lpReserved))return(int)FALSE;
00064 #endif
00065 break;
00066 }
00067 return (int)TRUE;
00068 }
00069
00070 #if __SC__
00071 #pragma startaddress(LibMain)
00072 #endif
00073
00074
00075 int sep=5;
00076
00077 static BOOL CALLBACK Instr(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam){
00078
00079 int i;
00080 char str[255];
00081 BOOL err;
00082 switch( msg ) {
00083 case WM_INITDIALOG:
00084 sprintf(str,"%d",sep);
00085 SetDlgItemText(hwnd,IDC_EDIT1,str);
00086 CentreDialogOnScreen(hwnd);
00087 return TRUE;
00088 case WM_COMMAND:
00089 switch(LOWORD(wparam)){
00090 case IDOK:
00091 if(GetDlgItemText(hwnd,IDC_EDIT1,str,12) != 0)
00092 sscanf(str,"%d",&sep);
00093 if(sep>10)
00094 sep=10;
00095 EndDialog(hwnd,TRUE);
00096 return(TRUE);
00097 default:
00098 break;
00099 }
00100 break;
00101 default: break;
00102 }
00103 return(FALSE);
00104 }
00105
00106
00107 BOOL _ExternalPreset(HWND parent, ANI_STRUCTURE *lpevi){
00108 node *TargetPointer1,*TargetPointer2,*LeftCamera,*RightCamera,*Light1,*Ground1;
00109 object *Op,*Model1;
00110 position *Pp;
00111 sky *Sp;
00112 int i,np,ne;
00113 long xmax,xmin,ymax,ymin,zmax,zmin,xsize,ysize,zsize,x,y,z,separation,alpha,maxsize,dist;
00114 char strsize[255],strp[255],strnp[255],strne[255],strmaxsize[255],strdist[255],strmin[255],strorig[255],strx[255]="x coords",stry[255]="y coords",strz[255]="z coords";
00115 point *p;
00116 char f_name[255],f_dir[255];
00117 FILE *fp1,*fp2;
00118 lpEVI=lpevi;
00119
00120 DialogBox(hDLLinstance,MAKEINTRESOURCE(IDD_DIALOG1),GetFocus(),(DLGPROC)Instr);
00121 SetNumberOfFrames(60);
00122 alpha=2.35585;
00123
00124
00125
00126 if(CreatePosition(FirstNp,1,(short)Nframes) == NULL)return FALSE;
00127 strcpy(FirstNp->actorname,"Right Camera");
00128 RightCamera=FirstNp;
00129
00130
00131
00132 if(CreateNode() == NULL)return FALSE;
00133 strcpy(MainNp->actorname,"Right Target");
00134 MainNp->type=TARGET;
00135 if((Op=CreateCostume(MainNp,1,(short)Nframes)) == NULL)return FALSE;
00136 Op->type=MainNp->type;
00137 if(CreatePosition(MainNp,1,(short)Nframes) == NULL)return FALSE;
00138 TargetPointer2=MainNp;
00139
00140
00141
00142 if(CreateNode() == NULL)return FALSE;
00143 strcpy(MainNp->actorname,"Left Target");
00144 MainNp->type=TARGET;
00145 if((Op=CreateCostume(MainNp,1,(short)Nframes)) == NULL)return FALSE;
00146 Op->type=MainNp->type;
00147 if(CreatePosition(MainNp,1,(short)Nframes) == NULL)return FALSE;
00148 TargetPointer1=MainNp;
00149
00150
00151
00152 if(CreateAlign(FirstNp,1,(short)Nframes) == NULL)return FALSE;
00153 FirstNp->fali->type=TRACK; FirstNp->fali->topath=TargetPointer2;
00154
00155
00156
00157 if(CreateNode() == NULL)return FALSE;
00158 strcpy(MainNp->actorname,"Left Camera");
00159 MainNp->type=CAMERA;
00160 (*(lpEVI->Ncameras))=2;
00161
00162 if((Op=CreateCostume(MainNp,1,Nframes)) == NULL)return FALSE;
00163 Op->type=MainNp->type;
00164
00165
00166
00167 if(CreatePosition(MainNp,1,(short)Nframes) == NULL)return FALSE;
00168 LeftCamera=MainNp;
00169
00170
00171
00172
00173 if(CreateAlign(MainNp,1,(short)Nframes) == NULL)return FALSE;
00174 MainNp->fali->type=TRACK; MainNp->fali->topath=TargetPointer1;
00175
00176
00177
00178 if(CreateNode() == NULL)return FALSE;
00179 strcpy(MainNp->actorname,"Light");
00180 MainNp->type=LIGHT;
00181 if((Op=CreateCostume(MainNp,1,Nframes)) == NULL)return FALSE;
00182 Op->type=MainNp->type;
00183 Op->lighttype=SPHERE; Op->colour[0]=Op->colour[1]=Op->colour[2]=255;
00184
00185
00186
00187 if((Pp=CreatePosition(MainNp,1,(short)Nframes)) == NULL)return FALSE;
00188 Light1=MainNp;
00189
00190
00191
00192 if(CreateNode() == NULL)return FALSE;
00193 strcpy(MainNp->actorname,"Sky");
00194 MainNp->type=SKY;
00195 if((Sp=CreateSky(MainNp,1,Nframes)) == NULL)return FALSE;
00196 Sp->type=SKYCOLOURED;
00197 Sp->zcolour[0]=0; Sp->zcolour[1]=0; Sp->zcolour[2]=0;
00198
00199
00200 if(CreateNode() == NULL)return FALSE;
00201 strcpy(MainNp->actorname,"Ground");
00202 MainNp->type=GROUND;
00203 (*(lpEVI->Nground))=1;
00204 Ground1=MainNp;
00205 if((Op=CreateCostume(MainNp,1,Nframes)) == NULL)return FALSE;
00206 Op->type=MainNp->type;
00207 Op->groundtype=PLAIN;
00208 Op->colour[0]=255; Op->colour[1]=255; Op->colour[2]=255;
00209 Op->acolour[0]=0; Op->acolour[1]=0; Op->acolour[2]=0;
00210 if(CreatePosition(MainNp,1,(short)Nframes) == NULL)return FALSE;
00211
00212
00213 if(CreateNode() == NULL)return FALSE;
00214 strcpy(MainNp->actorname,"Actor");
00215 MainNp->type=NORMAL;
00216 if((Op=CreateCostume(MainNp,1,(short)Nframes)) == NULL)return FALSE;
00217 Op->type=MainNp->type;
00218 Model1=Op;
00219 strcpy(f_dir,gszHomeDir); strcat(f_dir,"objects"); strcpy(f_name,"*.mfx");
00220 if(SelectFileName(0,f_name,f_dir,"Choose Actor's Costume",
00221 "(*.MFX)|*.mfx|",parent) == TRUE){
00222 strcpy(Op->name,f_name);
00223 Op->morph=NO;
00224 if(LoadMeshObject(f_name,Op,YES,YES,NO) == FAIL)DeleteCostume(MainNp,1);
00225 }
00226 else return FALSE;
00227
00228
00229
00230 if(CreatePosition(MainNp,1,(short)Nframes) == NULL)return FALSE;
00231 MainNp->fpos->finish[0]=0;
00232 MainNp->fpos->finish[1]=0;
00233 MainNp->fpos->finish[2]=0;
00234
00235
00236
00237 if(CreateAlign(MainNp,1,(short)Nframes) == NULL)return FALSE;
00238 MainNp->fali->type=TWEEN;MainNp->fali->im=1;MainNp->fali->ima=1.0;
00239
00240
00241
00242 if(Op == NULL) {MessageBox(NULL,"Bad Op","No Object Loaded",MB_OK); return FALSE;}
00243 p=Op->points;
00244 if(p == NULL) {MessageBox(NULL,"Bad p","No Points Available",MB_OK); return FALSE;}
00245 np=Op->npoints;
00246 sprintf(strnp,"%ld",np);
00247
00248 ne=Op->nedges;
00249 sprintf(strne,"%ld",ne);
00250
00251 xmax=-MAXUNIT;
00252 xmin=MAXUNIT;
00253 ymax=-MAXUNIT;
00254 ymin=MAXUNIT;
00255 zmax=-MAXUNIT;
00256 zmin=MAXUNIT;
00257
00258
00259 for(i=0;i<np;i++) {
00260 x=p[i][0];
00261 y=p[i][1];
00262 z=p[i][2];
00263 if(x>xmax) xmax=x;
00264 if(x<xmin) xmin=x;
00265 if(y>ymax) ymax=y;
00266 if(y<ymin) ymin=y;
00267 if(z>zmax) zmax=z;
00268 if(z<zmin) zmin=z;
00269 }
00270
00271 sprintf(strmin,"%ld %ld %ld %ld %ld %ld",xmin,xmax,ymin,ymax,zmin,zmax);
00272
00273
00274 xsize=xmax-xmin;
00275 ysize=ymax-ymin;
00276 zsize=zmax-zmin;
00277 sprintf(strsize,"%ld %ld %ld",xsize,ysize,zsize);
00278
00279
00280
00281
00282 if(xsize>ysize)
00283 maxsize=xsize;
00284 else {
00285 maxsize=ysize;
00286 }
00287
00288 if(zsize>maxsize) maxsize=zsize;
00289
00290 dist=maxsize*alpha;
00291 separation=dist/(125-(sep*10));
00292
00293 sprintf(strmaxsize,"%ld",maxsize);
00294
00295
00296 sprintf(strdist,"%ld",dist);
00297
00298
00299 LeftCamera->fpos->finish[0]=(separation/2);
00300 LeftCamera->fpos->finish[1]=dist;
00301 LeftCamera->fpos->finish[2]=0;
00302
00303 RightCamera->fpos->finish[0]=-(separation/2);
00304 RightCamera->fpos->finish[1]=dist;
00305 RightCamera->fpos->finish[2]=0;
00306
00307
00308
00309 Light1->fpos->finish[0]=LeftCamera->fpos->finish[0]+TVsizeX/2;
00310 Light1->fpos->finish[1]=LeftCamera->fpos->finish[1]+TVsizeY;
00311 Light1->fpos->finish[2]=LeftCamera->fpos->finish[2]+TVsizeZ*2;
00312
00313
00314
00315 fp1=fopen("Debug1.txt","w");
00316 fprintf(fp1,"%s %s %s\n",strx,stry,strz);
00317 for(i=0;i<np;i++) {
00318 fprintf(fp1,"%ld ",p[i][0]);
00319 fprintf(fp1,"%ld ",p[i][1]);
00320 fprintf(fp1,"%ld\n",p[i][2]);
00321 }
00322 fclose(fp1);
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335 sprintf(strorig,"%ld %ld %ld",Model1->origin[0],Model1->origin[1],Model1->origin[2]);
00336 MessageBox(NULL,strorig,"Values for Origin",MB_OK);
00337
00338
00339
00340 TargetPointer1->fpos->finish[0]=xmin+(xsize/2)+(separation/2);
00341 TargetPointer1->fpos->finish[1]=ymin+(ysize/2);
00342 TargetPointer1->fpos->finish[2]=zmin+(zsize/2);
00343
00344
00345
00346 TargetPointer2->fpos->finish[0]=xmin+(xsize/2)-(separation/2);
00347 TargetPointer2->fpos->finish[1]=ymin+(ysize/2);
00348 TargetPointer2->fpos->finish[2]=zmin+(zsize/2);
00349
00350
00351
00352 Ground1->fpos->finish[0]=TargetPointer1->fpos->finish[0];
00353 Ground1->fpos->finish[1]=TargetPointer1->fpos->finish[1];
00354 Ground1->fpos->finish[2]=TargetPointer1->fpos->finish[2]-zsize;
00355
00356 return TRUE;
00357 }
00358
00359
00360 void CentreDialogOnScreen(HWND hwnd){
00361 RECT rcDlg;
00362 long Xres,Yres;
00363 Yres=GetSystemMetrics(SM_CYSCREEN);
00364 Xres=GetSystemMetrics(SM_CXSCREEN);
00365 GetWindowRect(hwnd,&rcDlg);
00366 OffsetRect(&rcDlg,-rcDlg.left,-rcDlg.top);
00367 OffsetRect(&rcDlg,(Xres-rcDlg.right)/2,(Yres-rcDlg.bottom)/2);
00368 SetWindowPos(hwnd,HWND_TOP,rcDlg.left,rcDlg.top,0,0,SWP_NOSIZE);
00369 return;
00370 }