home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 1995 September / PCPRO2_995.ISO / virtek / dos / examples / simfly.c < prev   
Encoding:
C/C++ Source or Header  |  1995-07-16  |  3.7 KB  |  164 lines

  1. #include <stdio.h>
  2. #include "..\3d-ware\dddware.h"                                                
  3.  
  4. short    no_of_shapes=0;
  5. short    flyspeed=0;
  6. long    pos[3]={0,0,0};
  7. short    ang[3]={0,0,0};
  8.  
  9. void     ChangeViewAnglesUsingMouse(void);
  10. short LoadWorld(char *path);
  11.  
  12. struct 
  13.     {
  14.     long                 x,y,z;        
  15.     short             ax,ay,az;
  16.     unsigned short handle;
  17.     } far wshape[2500];
  18.  
  19.  
  20. void main(int argc,char *argv[])
  21. {
  22.     short i=0;
  23.  
  24.     if(argc<2)
  25.     {
  26.         printf("(C) 1994 VIRTEK INTERNATIONAL CORP.\n");                
  27.         printf("USAGE: EXAMPLE <filename.WLD>\n");                    
  28.         return;
  29.     }
  30.  
  31.     dddInitAll();                                                                
  32.     if(LoadWorld(argv[1])==-1)        
  33.     {
  34.         dddRestoreAll();
  35.         printf("Error Loading World\n");                                                        
  36.         return;                                                                    
  37.     }
  38.     dddmouse_x=160;
  39.     dddmouse_y=100;
  40.  
  41.     while(dddkeycode!=_ESC)
  42.     {
  43.         //Setup View position and angles
  44.         dddSetViewPos16(pos[0],pos[1],pos[2]);                                
  45.         dddSetViewAngles(-ang[0],-ang[1],ang[2]);
  46.  
  47.         //Draw a horizon
  48.         dddHoriFade(-ang[0],ang[2]);                                         
  49.  
  50.         //Draw Objects in world
  51.         dddClearObjects();                                                    
  52.         for(i=0;i<no_of_shapes;i++) 
  53.             dddInsertObject16(DRW_MOBILE,wshape[i].handle,0,
  54.                                     wshape[i].x,wshape[i].y,wshape[i].z,
  55.                                     wshape[i].ax,wshape[i].ay,wshape[i].az);
  56.         dddDrawObjects();                                                            
  57.  
  58.         //Use the mouse to change the viewer's angles
  59.         ChangeViewAnglesUsingMouse();                                            
  60.  
  61.         //Use the viewer's angles to change the view position
  62.         dddProjectForward(pos,ang,flyspeed);
  63.  
  64.  
  65.         //Show the new world view
  66.         dddScreenSwap();                                                            
  67.     }
  68.     dddRestoreAll();                                                                
  69.     
  70. }
  71.  
  72. void ChangeViewAnglesUsingMouse()
  73. {
  74.     dddReadMousePosition();                                                     
  75.  
  76.     if(dddlbutton)
  77.         flyspeed+=10;
  78.     else 
  79.         if(flyspeed>0) 
  80.             flyspeed-=3;
  81.  
  82.     ang[0]=-(dddmouse_y-100)*50;
  83.     ang[1]+=(dddmouse_x-160)*10;
  84.     ang[2]=(dddmouse_x-160)*50;
  85. }
  86.  
  87.  
  88. #include <string.h>
  89. #include <dos.h>    
  90. #include <dir.h>
  91.  
  92. short LoadWorld(char *path)
  93. {
  94.  
  95. struct ffblk fileinfo;
  96. char shape_name[14];
  97. char currpal[14];
  98. FILE *file_ptr;
  99. char tmp[128];
  100. float fileversion;
  101. char horitoggle=0;
  102. int    ith=0;
  103.  
  104.     if(findfirst(path,&fileinfo,0)!=0)
  105.     {
  106.         return(-1);
  107.     }
  108.     if((file_ptr=fopen(path,"rt"))==NULL)
  109.         {
  110.         return(-1);
  111.         }
  112.     fseek(file_ptr,0,SEEK_SET);
  113.     fscanf(file_ptr,"%s%s%s%f",&tmp,&tmp,&tmp,&fileversion);
  114.     if(fileversion!=1.0)
  115.         return(-1);
  116.  
  117.     fscanf(file_ptr,"%s",&tmp);
  118.     fscanf(file_ptr,"%s",&tmp);
  119.     fscanf(file_ptr,"%s",&tmp);
  120.     fscanf(file_ptr,"%s",&tmp);
  121.     fscanf(file_ptr,"%s",&tmp);
  122.     fscanf(file_ptr,"%s%d",&tmp,&horitoggle);
  123.     fscanf(file_ptr,"%s%s",&tmp,&tmp);
  124.     fscanf(file_ptr,"%s",&tmp);
  125.     if((stricmp(tmp,"DEFAULT")!=0)&&(tmp))
  126.     {
  127.         strcpy(currpal,tmp);
  128.         dddLoadColors(currpal);                                                    // Load in the requested palette.
  129.     }
  130.     else
  131.     {
  132.         strset(currpal,NULL);                                                    // Clear palette to black.
  133.     }
  134.     dddSetPal(dddstandardpal);                                     // Initialise the palette registers.
  135.  
  136.     fscanf(file_ptr,"%s",&tmp);
  137.     fscanf(file_ptr,"%s",&tmp);
  138.     fscanf(file_ptr,"%s",&tmp);
  139.     fscanf(file_ptr,"%s",&tmp);
  140.     fscanf(file_ptr,"%s",&tmp);
  141.     fscanf(file_ptr,"%s",&tmp);
  142.     fscanf(file_ptr,"%s",&tmp);
  143.     fscanf(file_ptr,"%s",shape_name);
  144.     if(stricmp(shape_name,"FLAT:")==0)
  145.         fscanf(file_ptr,"%s",shape_name);
  146.     while((!(feof(file_ptr))>0)&&(ith<2500))
  147.     {
  148.         fscanf(file_ptr,"%Fld",&wshape[ith].x);
  149.         fscanf(file_ptr,"%Fld",&wshape[ith].y);
  150.         fscanf(file_ptr,"%Fld",&wshape[ith].z);
  151.         fscanf(file_ptr,"%Fld",&wshape[ith].ax);
  152.         fscanf(file_ptr,"%Fld",&wshape[ith].ay);
  153.         fscanf(file_ptr,"%Fld",&wshape[ith].az);
  154.         wshape[ith].handle = dddShapeLoad(shape_name);              // Load the geometry file.
  155.         ith++;
  156.         fscanf(file_ptr,"%s",shape_name);
  157.         if(stricmp(shape_name,"FLAT")==0)
  158.             fscanf(file_ptr,"%s",shape_name);
  159.     }
  160.     no_of_shapes=ith;
  161.     fclose(file_ptr);
  162.     return(0);
  163. }
  164.