home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include "..\3d-ware\dddware.h"
-
- short no_of_shapes=0;
- short flyspeed=0;
- long pos[3]={0,0,0};
- short ang[3]={0,0,0};
-
- void ChangeViewAnglesUsingMouse(void);
- short LoadWorld(char *path);
-
- struct
- {
- long x,y,z;
- short ax,ay,az;
- unsigned short handle;
- } far wshape[2500];
-
-
- void main(int argc,char *argv[])
- {
- short i=0;
-
- if(argc<2)
- {
- printf("(C) 1994 VIRTEK INTERNATIONAL CORP.\n");
- printf("USAGE: EXAMPLE <filename.WLD>\n");
- return;
- }
-
- dddInitAll();
- if(LoadWorld(argv[1])==-1)
- {
- dddRestoreAll();
- printf("Error Loading World\n");
- return;
- }
- dddmouse_x=160;
- dddmouse_y=100;
-
- while(dddkeycode!=_ESC)
- {
- //Setup View position and angles
- dddSetViewPos16(pos[0],pos[1],pos[2]);
- dddSetViewAngles(-ang[0],-ang[1],ang[2]);
-
- //Draw a horizon
- dddHoriFade(-ang[0],ang[2]);
-
- //Draw Objects in world
- dddClearObjects();
- for(i=0;i<no_of_shapes;i++)
- dddInsertObject16(DRW_MOBILE,wshape[i].handle,0,
- wshape[i].x,wshape[i].y,wshape[i].z,
- wshape[i].ax,wshape[i].ay,wshape[i].az);
- dddDrawObjects();
-
- //Use the mouse to change the viewer's angles
- ChangeViewAnglesUsingMouse();
-
- //Use the viewer's angles to change the view position
- dddProjectForward(pos,ang,flyspeed);
-
-
- //Show the new world view
- dddScreenSwap();
- }
- dddRestoreAll();
-
- }
-
- void ChangeViewAnglesUsingMouse()
- {
- dddReadMousePosition();
-
- if(dddlbutton)
- flyspeed+=10;
- else
- if(flyspeed>0)
- flyspeed-=3;
-
- ang[0]=-(dddmouse_y-100)*50;
- ang[1]+=(dddmouse_x-160)*10;
- ang[2]=(dddmouse_x-160)*50;
- }
-
-
- #include <string.h>
- #include <dos.h>
- #include <dir.h>
-
- short LoadWorld(char *path)
- {
-
- struct ffblk fileinfo;
- char shape_name[14];
- char currpal[14];
- FILE *file_ptr;
- char tmp[128];
- float fileversion;
- char horitoggle=0;
- int ith=0;
-
- if(findfirst(path,&fileinfo,0)!=0)
- {
- return(-1);
- }
- if((file_ptr=fopen(path,"rt"))==NULL)
- {
- return(-1);
- }
- fseek(file_ptr,0,SEEK_SET);
- fscanf(file_ptr,"%s%s%s%f",&tmp,&tmp,&tmp,&fileversion);
- if(fileversion!=1.0)
- return(-1);
-
- fscanf(file_ptr,"%s",&tmp);
- fscanf(file_ptr,"%s",&tmp);
- fscanf(file_ptr,"%s",&tmp);
- fscanf(file_ptr,"%s",&tmp);
- fscanf(file_ptr,"%s",&tmp);
- fscanf(file_ptr,"%s%d",&tmp,&horitoggle);
- fscanf(file_ptr,"%s%s",&tmp,&tmp);
- fscanf(file_ptr,"%s",&tmp);
- if((stricmp(tmp,"DEFAULT")!=0)&&(tmp))
- {
- strcpy(currpal,tmp);
- dddLoadColors(currpal); // Load in the requested palette.
- }
- else
- {
- strset(currpal,NULL); // Clear palette to black.
- }
- dddSetPal(dddstandardpal); // Initialise the palette registers.
-
- fscanf(file_ptr,"%s",&tmp);
- fscanf(file_ptr,"%s",&tmp);
- fscanf(file_ptr,"%s",&tmp);
- fscanf(file_ptr,"%s",&tmp);
- fscanf(file_ptr,"%s",&tmp);
- fscanf(file_ptr,"%s",&tmp);
- fscanf(file_ptr,"%s",&tmp);
- fscanf(file_ptr,"%s",shape_name);
- if(stricmp(shape_name,"FLAT:")==0)
- fscanf(file_ptr,"%s",shape_name);
- while((!(feof(file_ptr))>0)&&(ith<2500))
- {
- fscanf(file_ptr,"%Fld",&wshape[ith].x);
- fscanf(file_ptr,"%Fld",&wshape[ith].y);
- fscanf(file_ptr,"%Fld",&wshape[ith].z);
- fscanf(file_ptr,"%Fld",&wshape[ith].ax);
- fscanf(file_ptr,"%Fld",&wshape[ith].ay);
- fscanf(file_ptr,"%Fld",&wshape[ith].az);
- wshape[ith].handle = dddShapeLoad(shape_name); // Load the geometry file.
- ith++;
- fscanf(file_ptr,"%s",shape_name);
- if(stricmp(shape_name,"FLAT")==0)
- fscanf(file_ptr,"%s",shape_name);
- }
- no_of_shapes=ith;
- fclose(file_ptr);
- return(0);
- }
-