/* ------------------------------------------------------------------ Black Nebula File : 3d.h Programmer: Colin Adams Date: 4/3/91 Last Modified : 10/6/91 Description: Include file for Amiga data and 3d data. ------------------------------------------------------------------ */ #include #include #include #include #ifdef AMIGA_INCLUDES #include #include #include #include #include #include #include #include #include #include #endif #define TRUE 1 #define FALSE 0 #define DEGREES 360 #define MAX_POINTS 12 #define MAX_OBJ_POINTS 40 #define MAX_POLYGONS 30 #define MAX_EXPLOSIONS 60 #define TOTAL_MAX_OBJECTS 120 #define MAX_OBJECTS 10 #define NO_OBJ_TYPES 11 /* Screen size, G is the width, depth is in bitplanes and colours should be depth^2 */ #define G 320 #define HEIGHT 256 #define DEPTH 4 #define COLOURS 16 /* viewport size (co-ordinates of window on the screen) */ #define Y_MAX 141 #define Y_MIN 20 #define X_MAX 269 #define X_MIN 50 /* buffer for the area fill */ #define BUFFER_SIZE (MAX_POINTS*5)/2 /* World size defines */ #define MAX_WORLD_X 8000 #define MAX_WORLD_Y 2000 #define MAX_WORLD_Z 8000 #define Y_OFFSET 10 enum /* used for object->type */ { ENEMYMISSILE, // 0 FIXED, // 1 SHUTTLE, // 2 KRAIT, // 3 GECKO, // 4 THARGOID, // 5 MAMBA, // 6 MYMISSILE, // 7 GUIDEDMISSILE, // 8 EXPLOSION, // 9 PLAYER, }; /* ---------------------------------------------------------------- DATA STRUCTURES ---------------------------------------------------------------- */ #ifdef MAINCODE #define extern #endif typedef struct { int numer; int denom; } fixed; /* ------------------------------------------------------------------ Object Definitions An Object is comprised of a series of points and polygons. Polygons are defined by a sequence of the points which comprise the object. Points have x,y,z values. ------------------------------------------------------------------ */ typedef struct { short x, y, z; } point; typedef struct { char numpoints; /* number of points in polygon */ short colour; /* colour of the polygon */ point centre; /* centre co-ord of polygon */ short back_face; /* boolean test if back face */ short back_face_2, back_face_last; short p[MAX_POINTS]; /* list of object points that form polygon */ short x[MAX_POINTS]; /* x-ord converted to 2d */ short y[MAX_POINTS]; /* y-ord converted to 2d */ short last_num; /* last draw no. of points */ short last_x[MAX_POINTS]; /* last draw x co-ords */ short last_y[MAX_POINTS]; /* last draw y co_ords */ short last_num2; short last_x2[MAX_POINTS]; short last_y2[MAX_POINTS]; short clip_num; /* number of clipped points */ short clip_x[MAX_POINTS]; /* x ord after clipping */ short clip_y[MAX_POINTS]; /* y ord after clipping */ void *next; /* next polygon in list */ } polygon; typedef struct { char type; /* enum type of object */ char explode; char lastdrawme; /* did i draw last time ? */ char lastdraw2; /* did i draw time before last */ char drawme; /* boolean: will i draw it */ short centre_x, centre_y, centre_z; /* centre of object */ short start_x, start_y, start_z; /* unchanging centre of obj */ short radius; /* used for collision detection */ short velocity, heading; /* used for speed obviously */ short timeinflight; /* used for missiles */ short i_am_dying; /* i am about to die! */ short up_or_down; short trans_x, trans_y, trans_z; /* current translation from origin */ short rot_x, rot_y, rot_z; /* current rotation angles */ point objpoints[MAX_OBJ_POINTS]; /* points comprising the object */ short numpoints; /* number of points in object */ short pointx[MAX_OBJ_POINTS]; /* points in object once in 2d */ short pointy[MAX_OBJ_POINTS]; polygon *draworder[MAX_POLYGONS]; /* list of order to draw polys */ void *target; /* target for missiles! */ polygon *poly; /* pointer to 1st polygon making up object */ } object; extern short obj_free[NO_OBJ_TYPES][MAX_OBJECTS];/*flag to see if in use */ extern object obj_types[NO_OBJ_TYPES][MAX_OBJECTS]; /* static mem. alloc */ extern object explosions[MAX_EXPLOSIONS]; extern short exp_free[MAX_EXPLOSIONS]; extern object *active_list[TOTAL_MAX_OBJECTS+1]; /* pointers to objects */ extern short no_objects; /* number in use */ extern short manipulate_x[MAX_OBJ_POINTS]; /* work space for 3d t&r's */ extern short manipulate_y[MAX_OBJ_POINTS]; extern short manipulate_z[MAX_OBJ_POINTS]; extern short velocity, debug; extern short view_mode, View_Angle; /* ----------------------------------------------------------------- AMIGA SPECIFIC DATA ----------------------------------------------------------------- */ #ifdef AMIGA_INCLUDES extern UWORD areabuffer[BUFFER_SIZE]; extern PLANEPTR extra_space; extern struct RastPort *rastport; extern struct GfxBase *GfxBase; extern struct IntuitionBase *IntuitionBase; extern struct AreaInfo my_area_info; extern struct TmpRas my_temp_ras; #endif #ifdef extern #undef extern #endif /* ---------------------------------------------------------------- 3D VARIABLES ---------------------------------------------------------------- */ #ifdef D3ROUT #define extern #endif /* viewing vectors */ extern int ex, ey, ez; /* location of eye */ extern fixed ux, uy, uz; /* direction eye is pointing (unit vector) */ extern fixed vx, vy, vz; /* top of head vector */ extern fixed wx, wy, wz; /* out of right ear vector */ /* displacement of eye to point such that (rx, ry, rz) = (px-ex, py-ey, pz-ez) depth of the point is d = rx*ux + ry*uy + rz*uz */ extern int d; /* K is related to lens angle k = (G/2)/tan(B) where G is the number of pixels accross the screen and B is half the angular width of the field of view */ extern fixed k; extern int x, y; extern short am_i_dead; extern int sintable[DEGREES+1], costable[DEGREES+1]; extern int anti_sin[4097]; /* big precalculate table for asin */ #define FastSin(value,angle) ((sintable[angle]*value)>>16) #define FastCos(value,angle) ((costable[angle]*value)>>16) /* ------------------------------------------------------------------ Move/Draw Macros ------------------------------------------------------------------ */ #define MoveTo(x,y) (AreaMove(rastport,x,y)) #define DrawTo(x,y) (AreaDraw(rastport,x,y)) #define FillArea() (AreaEnd(rastport)) /* ------------------------------------------------------------------ FIXED POINT MACROS I've ended up inlining most of this macros for speed, but I'll leave them here to help people write fast code. This method is much faster than moving the decimal point and doing lots of shifts! ------------------------------------------------------------------ */ #define setconst(x,i) { x.numer=i; x.denom=1; } #define fixvalue(x) ( x.denom ? x.numer/x.denom : 0) #define add(x,y,sum) { sum.denom = x.denom * y.denom; sum.numer = x.denom * y.numer + y.denom * x.denom; } #define mult(x,y,p) { p.numer= x.numer*y.numer; p.denom= x.denom*y.denom; } #define div(x,y,d) { d.numer = x.numer*y.denom; d.denom= x.denom*y.numer; } #define getmultC(x,const) ((x.numer*const)/x.denom) #define SetFixed(x,y,z) { x.numer = y; x.denom = z; } #ifdef extern #undef extern #endif /* ------------------------------------------------------------------ Function Prototypes Who says nobody compiles with -cf ? ------------------------------------------------------------------ */ extern void TrigSetUp(void), Rotate_Obj_Abs(object *, short, short, short); extern void Rotate_Obj_Rel(object *, short, short, short); extern void Translate_Obj_Abs(object *, short, short, short); extern void Translate_Obj_Rel(object *, short, short, short); extern void Destroy_Object(object *), Save_Object(object *, char *); extern void AddPoly(object *, polygon *), get2d(short, short, short); extern void SpinThatObject(object *), PrepareObject(object *); extern void DrawObject(object *), EraseObject(object *), loadpic(char *); extern void polygon_clip(polygon *poly), DepthSort(object *); extern void CleanUpandExit(void), SetUpViews(void), FreeView(void); extern void Do3d(void), Setupangles(void), SetUp3d(void); extern void AddObject(char *, short), CreateExplosion(object *); extern void CalculateObjects(void), ClearObjects(void), DisplayObjects(void); extern void MoveObjects(void), SoundSetUp(void), StartSound(int); extern void EndSound(void), DoIntro(void), KillAllObjects(void); extern float fsqrt(float); extern void SetRandom(void), UpdateObjects(void); extern int getrandom(int, int); extern double deg(int); #ifdef AMIGA_INCLUDES extern UBYTE Joystick(void), Keyboard(void); #endif extern int Load_Object(object *, char *); extern object *CreateObject(void); /* end of module 3d.h */