home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 543a.lha / Nebula / source.LZH / source / 3d.h < prev    next >
Encoding:
C/C++ Source or Header  |  1991-06-10  |  8.9 KB  |  342 lines

  1. /*
  2.  
  3. ------------------------------------------------------------------
  4.  
  5. Black Nebula
  6.  
  7. File :                3d.h
  8. Programmer:        Colin Adams
  9. Date:                4/3/91
  10. Last Modified :    10/6/91
  11.  
  12. Description:
  13.  
  14. Include file for Amiga data and 3d data.
  15.  
  16. ------------------------------------------------------------------
  17.  
  18. */
  19.  
  20. #include <stdlib.h>
  21. #include <string.h>
  22. #include <stdio.h>
  23. #include <math.h>
  24.  
  25. #ifdef AMIGA_INCLUDES
  26.  
  27. #include <proto/graphics.h>
  28. #include <proto/intuition.h>
  29. #include <proto/exec.h>
  30. #include <proto/dos.h>
  31. #include <intuition/intuition.h>
  32. #include <graphics/gfx.h>
  33. #include <graphics/gfxbase.h>
  34. #include <graphics/gfxmacros.h>
  35. #include <graphics/display.h>
  36. #include <exec/exec.h>
  37.  
  38. #endif
  39.  
  40. #define TRUE 1
  41. #define FALSE 0
  42. #define DEGREES 360
  43. #define MAX_POINTS 12
  44. #define MAX_OBJ_POINTS 40
  45. #define MAX_POLYGONS 30
  46. #define MAX_EXPLOSIONS 60
  47. #define TOTAL_MAX_OBJECTS 120
  48. #define MAX_OBJECTS 10
  49. #define NO_OBJ_TYPES 11
  50.  
  51. /*
  52. Screen size, G is the width, depth is in bitplanes and colours should
  53. be depth^2
  54. */
  55.  
  56. #define G 320
  57. #define HEIGHT 256
  58. #define DEPTH 4
  59. #define COLOURS 16
  60.  
  61. /* viewport size (co-ordinates of window on the screen) */
  62.  
  63. #define Y_MAX 141
  64. #define Y_MIN 20
  65.  
  66. #define X_MAX 269
  67. #define X_MIN 50
  68.  
  69. /* buffer for the area fill */
  70.  
  71. #define BUFFER_SIZE (MAX_POINTS*5)/2
  72.  
  73. /* World size defines */
  74.  
  75. #define MAX_WORLD_X 8000
  76. #define MAX_WORLD_Y 2000
  77. #define MAX_WORLD_Z 8000
  78. #define Y_OFFSET 10
  79.  
  80. enum    /* used for object->type */
  81. {
  82.     ENEMYMISSILE, // 0
  83.     FIXED,            // 1
  84.     SHUTTLE,            // 2
  85.     KRAIT,            // 3
  86.     GECKO,            // 4
  87.     THARGOID,        // 5
  88.     MAMBA,            // 6
  89.     MYMISSILE,        // 7
  90.     GUIDEDMISSILE, // 8
  91.     EXPLOSION,        // 9
  92.     PLAYER,
  93. };
  94.  
  95. /*    ----------------------------------------------------------------
  96.         DATA STRUCTURES
  97.         ----------------------------------------------------------------
  98. */
  99.  
  100. #ifdef MAINCODE
  101. #define extern  
  102. #endif
  103.  
  104. typedef struct
  105. {
  106.     int numer;
  107.     int denom;
  108. } fixed;
  109.  
  110. /*    ------------------------------------------------------------------
  111.         Object Definitions
  112.         
  113.         An Object is comprised of a series of points and polygons.
  114.         Polygons are defined by a sequence of the points which
  115.         comprise the object. Points have x,y,z values.
  116.         ------------------------------------------------------------------
  117. */
  118.  
  119. typedef struct
  120. {
  121.     short x, y, z;
  122. } point;
  123.  
  124. typedef struct
  125. {
  126.     char numpoints;    /* number of points in polygon */
  127.     short colour;        /* colour of the polygon */
  128.     point centre;        /* centre co-ord of polygon */
  129.     short back_face;    /* boolean test if back face */
  130.     short back_face_2, back_face_last;
  131.  
  132.     short p[MAX_POINTS];             /* list of object points that form polygon */
  133.  
  134.     short x[MAX_POINTS]; /* x-ord converted to 2d */
  135.     short y[MAX_POINTS]; /* y-ord converted to 2d */
  136.     
  137.     short last_num;                /* last draw no. of points */
  138.     short last_x[MAX_POINTS];    /* last draw x co-ords */
  139.     short last_y[MAX_POINTS];    /*    last draw y co_ords */
  140.  
  141.     short last_num2;
  142.     short last_x2[MAX_POINTS];
  143.     short last_y2[MAX_POINTS];
  144.         
  145.     short clip_num;              /* number of clipped points */
  146.     short clip_x[MAX_POINTS]; /* x ord after clipping */
  147.     short clip_y[MAX_POINTS]; /* y ord after clipping */
  148.  
  149.     void *next;                      /* next polygon in list */
  150. } polygon;
  151.  
  152. typedef struct
  153. {
  154.     char type;                                     /* enum type of object */
  155.     char explode;
  156.     char lastdrawme;                            /* did i draw last time ? */
  157.     char lastdraw2;                            /* did i draw time before last */
  158.     char drawme;                                /* boolean: will i draw it */
  159.     short centre_x, centre_y, centre_z; /* centre of object */
  160.     short start_x, start_y, start_z;        /* unchanging centre of obj */
  161.     short radius;                                /* used for collision detection */
  162.  
  163.     short velocity, heading;                /* used for speed obviously */
  164.     short timeinflight;                        /* used for missiles */
  165.     short i_am_dying;                            /* i am about to die! */
  166.     short up_or_down;
  167.     
  168.     short trans_x, trans_y, trans_z;     /* current translation from origin */
  169.     short rot_x, rot_y, rot_z;             /* current rotation angles */
  170.     
  171.     point objpoints[MAX_OBJ_POINTS];        /* points comprising the object */
  172.     short numpoints;                             /* number of points in object */
  173.     short pointx[MAX_OBJ_POINTS];            /* points in object once in 2d */
  174.     short pointy[MAX_OBJ_POINTS];
  175.     
  176.     polygon *draworder[MAX_POLYGONS];    /* list of order to draw polys */
  177.     void *target;                            /* target for missiles! */
  178.  
  179.     polygon *poly;                 /* pointer to 1st polygon making up object */
  180. } object;
  181.  
  182. extern short obj_free[NO_OBJ_TYPES][MAX_OBJECTS];/*flag to see if in use */
  183. extern object obj_types[NO_OBJ_TYPES][MAX_OBJECTS]; /* static mem. alloc */
  184.  
  185. extern object explosions[MAX_EXPLOSIONS];
  186. extern short exp_free[MAX_EXPLOSIONS];
  187.  
  188. extern object *active_list[TOTAL_MAX_OBJECTS+1]; /* pointers to objects */
  189. extern short no_objects; /* number in use */
  190.  
  191. extern short manipulate_x[MAX_OBJ_POINTS]; /* work space for 3d t&r's */
  192. extern short manipulate_y[MAX_OBJ_POINTS];
  193. extern short manipulate_z[MAX_OBJ_POINTS];
  194.  
  195. extern short velocity, debug;
  196. extern short view_mode, View_Angle;
  197.  
  198. /*    -----------------------------------------------------------------
  199.         AMIGA SPECIFIC DATA
  200.         -----------------------------------------------------------------
  201. */
  202.  
  203. #ifdef AMIGA_INCLUDES
  204.  
  205. extern UWORD areabuffer[BUFFER_SIZE];
  206. extern PLANEPTR extra_space;
  207.  
  208. extern struct RastPort *rastport;
  209.  
  210. extern struct GfxBase *GfxBase;
  211. extern struct IntuitionBase *IntuitionBase;
  212.  
  213. extern struct AreaInfo my_area_info;
  214. extern struct TmpRas my_temp_ras;
  215.  
  216. #endif
  217.  
  218. #ifdef extern
  219. #undef extern
  220. #endif
  221.  
  222.  
  223. /*    ----------------------------------------------------------------
  224.         3D VARIABLES
  225.         ----------------------------------------------------------------
  226. */
  227.  
  228. #ifdef D3ROUT
  229. #define extern  
  230. #endif
  231.  
  232. /* viewing vectors */
  233.  
  234. extern int ex, ey, ez; /* location of eye */
  235.  
  236. extern fixed ux, uy, uz;    /* direction eye is pointing (unit vector) */
  237.  
  238. extern fixed vx, vy, vz; /* top of head vector */
  239.  
  240. extern fixed wx, wy, wz; /* out of right ear vector */
  241.  
  242. /* displacement of eye to point such that
  243.  
  244. (rx, ry, rz) = (px-ex, py-ey, pz-ez)
  245.  
  246. depth of the point is d = rx*ux + ry*uy + rz*uz
  247. */
  248.  
  249. extern int d;
  250.  
  251. /* K is related to lens angle
  252.  
  253. k = (G/2)/tan(B)
  254.  
  255. where G is the number of pixels accross the screen and B is half the
  256. angular width of the field of view
  257.  
  258. */
  259.  
  260. extern fixed k;
  261. extern int x, y;
  262. extern short am_i_dead;
  263.  
  264. extern int sintable[DEGREES+1], costable[DEGREES+1];
  265. extern int anti_sin[4097]; /* big precalculate table for asin */
  266.  
  267. #define FastSin(value,angle) ((sintable[angle]*value)>>16)
  268. #define FastCos(value,angle) ((costable[angle]*value)>>16)
  269.  
  270. /*    ------------------------------------------------------------------
  271.         Move/Draw Macros
  272.         ------------------------------------------------------------------
  273. */
  274.  
  275. #define MoveTo(x,y) (AreaMove(rastport,x,y))
  276. #define DrawTo(x,y) (AreaDraw(rastport,x,y))
  277. #define FillArea() (AreaEnd(rastport))
  278.  
  279. /*    ------------------------------------------------------------------
  280.         FIXED POINT MACROS
  281.         I've ended up inlining most of this macros for speed, but I'll
  282.         leave them here to help people write fast code.  This method
  283.         is much faster than moving the decimal point and doing lots
  284.         of shifts!
  285.         ------------------------------------------------------------------
  286. */
  287.  
  288. #define setconst(x,i) { x.numer=i; x.denom=1; }
  289.  
  290. #define fixvalue(x) ( x.denom ? x.numer/x.denom : 0)
  291.  
  292. #define add(x,y,sum) { sum.denom = x.denom * y.denom; sum.numer = x.denom * y.numer + y.denom * x.denom; }
  293.  
  294. #define mult(x,y,p) { p.numer= x.numer*y.numer; p.denom= x.denom*y.denom; }
  295.  
  296. #define div(x,y,d) { d.numer = x.numer*y.denom; d.denom= x.denom*y.numer; }
  297.  
  298. #define getmultC(x,const) ((x.numer*const)/x.denom)
  299.  
  300. #define SetFixed(x,y,z) { x.numer = y; x.denom = z; }
  301.  
  302. #ifdef extern
  303. #undef extern
  304. #endif
  305.  
  306. /*    ------------------------------------------------------------------
  307.         Function Prototypes
  308.         
  309.         Who says nobody compiles with -cf ?
  310.         ------------------------------------------------------------------
  311. */
  312.  
  313. extern void TrigSetUp(void), Rotate_Obj_Abs(object *, short, short, short);
  314. extern void Rotate_Obj_Rel(object *, short, short, short);
  315. extern void Translate_Obj_Abs(object *, short, short, short);
  316. extern void Translate_Obj_Rel(object *, short, short, short);
  317. extern void Destroy_Object(object *), Save_Object(object *, char *);
  318. extern void AddPoly(object *, polygon *), get2d(short, short, short);
  319. extern void SpinThatObject(object *), PrepareObject(object *);
  320. extern void DrawObject(object *), EraseObject(object *), loadpic(char *);
  321. extern void polygon_clip(polygon *poly), DepthSort(object *);
  322. extern void CleanUpandExit(void), SetUpViews(void), FreeView(void);
  323. extern void Do3d(void), Setupangles(void), SetUp3d(void);
  324. extern void AddObject(char *, short), CreateExplosion(object *);
  325. extern void CalculateObjects(void), ClearObjects(void), DisplayObjects(void);
  326. extern void MoveObjects(void), SoundSetUp(void), StartSound(int);
  327. extern void EndSound(void), DoIntro(void), KillAllObjects(void);
  328. extern float fsqrt(float);
  329. extern void SetRandom(void), UpdateObjects(void);
  330. extern int getrandom(int, int);
  331.  
  332. extern double deg(int);
  333.  
  334. #ifdef AMIGA_INCLUDES
  335. extern UBYTE Joystick(void), Keyboard(void);
  336. #endif
  337.  
  338. extern int Load_Object(object *, char *);
  339. extern object *CreateObject(void);
  340.  
  341. /* end of module 3d.h */
  342.