home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Virtual Reality Madness
/
VRMAD96_ONE.ISO
/
virtek
/
examples
/
example.c
next >
Wrap
C/C++ Source or Header
|
1995-08-24
|
9KB
|
298 lines
// ┌─────────────────────────────────────────────────────────────┐
// │ │
// │ Filename: explore.c │
// │ Author: C.K. Donnison │
// │ <charles@virtek.com> │
// │ Position: Senior programmer │
// │ │
// │ Creation date: 3rd June 1994 │
// │ │
// │ Compiled using: Borland C++ V3.1 │
// │ │
// │ Tested by: CKD, PBA, NAJ │
// │ │
// │ │
// │ Purpose: A small program to load a 3D-Ware │
// │ world file and use a mouse to control │
// │ flight throughout the world. │
// │ │
// └─────────────────────────────────────────────────────────────┘
#include <string.h>
#include <stdio.h>
#include <dos.h>
#include <dir.h>
#include "..\3d-ware\dddware.h" // The important bit :-)
struct ffblk fileinfo;
char shape_name[14];
char currpal[14];
FILE *file_ptr;
char tmp[128];
char horitoggle=0;
float version=1.0;
float fileversion=0.0;
int no_of_shapes=0;
long int distance=16384;
long heading = 0;
short response = 19;
int flyspeed=0;
long int pos[3];
int ang[3];
int ith=0;
void FlyingControls(void);
void FlyAround(void);
void Control(void);
short LoadWorld(char *path);
typedef struct worldshape worldshape;
struct worldshape
{
long x,y,z;
short ax,ay,az;
unsigned short handle;
};
worldshape far wshape[2500];
int main(int argc,char *argv[])
{
if(argc<2)
{
printf("(C) 1994 VIRTEK INTERNATIONAL CORP.\n"); // Say hello.
printf("USAGE: EXAMPLE <filename.WLD>\n"); // Display usage.
}
else
{
dddInitAll(); // Initialise 3D-Ware.
if(LoadWorld(argv[1])==-1) // Try to load the world.
{
dddRestoreAll(); // Hmm. Can't load so exit.
return(-1); // Bye.
}
FlyAround(); // Explore the world.
dddRestoreAll(); // Clean up.
}
return(0); // Bye.
}
// ┌─────────────────────────────────────────────────────┐
// │ LoadWorld │
// │ This loads in an existing world file. │
// │ │
// └─────────────────────────────────────────────────────┘
short LoadWorld(char *path)
{
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!=version)
{
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",&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",&tmp);
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);
}
void FlyAround(void)
{
short i=0;
dddceiling =- 32000; // Really only needs to be done once.
dddfloor = -100; // Really only needs to be done once.
dddmouse_x = 160;
dddmouse_y = 100;
dddHideGraphicsMouse(); // Do not display the mouse pointer.
while(dddkeycode!=_ESC)
{
dddClearObjects(); // Clear the internal object list.
dddReadMousePosition(); // Does what it says.
if(horitoggle==0)
{
dddBox(0,0,0,319,199); // Hmmm could use dddCls();
}
else if(horitoggle==1)
{
dddHorizon(ang[0],ang[2]); // Standard Horizon.
}
else
{
dddHoriFade(ang[0],ang[2]); // Banded horizon
}
i=0;
while((i<no_of_shapes))
{
if(((pos[0]-wshape[i].x)<distance)&&((pos[0]-wshape[i].x)>-distance)&&
((pos[1]-wshape[i].y)<distance)&&((pos[1]-wshape[i].y)>-distance)&&
((pos[2]-wshape[i].z)<distance)&&((pos[2]-wshape[i].z)>-distance))
{
dddInsertObject16(DRW_MOBILE,wshape[i].handle,255,wshape[i].x,wshape[i].y,wshape[i].z,wshape[i].ax,wshape[i].ay,wshape[i].az);
}
i++;
}
dddDrawObjects(); // Draw all the inserted shapes.
FlyingControls(); // Handle the mouse input.
dddScreenSwap(); // Make the rendered screen visible.
}
}
void FlyingControls(void)
{
if((dddlbutton)||(dddkeypressed[_SPACE]))
{
if(flyspeed<400)
{
flyspeed+=10;
}
else if(flyspeed<800)
{
flyspeed+=30;
}
}
else if(flyspeed>400)
{
flyspeed-=10;
}
else if(flyspeed>0)
{
flyspeed-=3;
}
else if(flyspeed<0)
{
flyspeed=0;
}
Control();
dddProjectForward(pos,ang,flyspeed);
dddSetViewAngles(ang[0],ang[1],ang[2]);
dddSetViewPos16(pos[0],pos[1],pos[2]); // 16 bit co-ordinates.
}
void Control(void)
{
#define KEYBOARD_RESPONSE 16
long dx;
int long anx,any,anz;
int key_response;
key_response = KEYBOARD_RESPONSE;
if(dddkeypressed[_L_SHIFT])
{
key_response += key_response;
}
if(dddkeypressed[_LF_ARROW])
{
if( dddmouse_x >0)
{
dddmouse_x -= key_response;
}
if( dddmouse_x < 0)
{
dddmouse_x = 0;
}
}
if(dddkeypressed[_RT_ARROW])
{
if( dddmouse_x < 319)
{
dddmouse_x += key_response;
}
if( dddmouse_x > 319)
{
dddmouse_x = 319;
}
}
if(dddkeypressed[_UP_ARROW])
{
if( dddmouse_y >0)
{
dddmouse_y -= key_response;
}
if( dddmouse_y < 0)
{
dddmouse_y = 0;
}
}
if(dddkeypressed[_DN_ARROW])
{
if( dddmouse_y < 199)
{
dddmouse_y += key_response;
}
if( dddmouse_y > 199)
{
dddmouse_y = 199;
}
}
anz = ((dddmouse_x-160)*3) << 4;
anx = ((dddmouse_y-100)*4)<<4;
dx = ((((long)dddmouse_x - 160L) ) << response);
heading = heading - dx;
any = (heading >> 16L);
ang[0]=-(int)anx;
ang[1]=-(int)any;
ang[2]=(int)anz;
}