home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1998 #6 / amigaacscoverdisc1998-061998.iso / games / descent / source / 3d / 3d.h next >
C/C++ Source or Header  |  1998-06-08  |  15KB  |  395 lines

  1. /*
  2. THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
  3. SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
  4. END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
  5. ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
  6. IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
  7. SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
  8. FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
  9. CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
  10. AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.  
  11. COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
  12. */
  13. /*
  14.  * $Source: f:/miner/source/3d/rcs/3d.h $
  15.  * $Revision: 1.34 $
  16.  * $Author: matt $
  17.  * $Date: 1994/11/11 19:22:14 $
  18.  *
  19.  * Header file for 3d library
  20.  *
  21.  * $Log: 3d.h $
  22.  * Revision 1.34  1994/11/11  19:22:14  matt
  23.  * Added new function, g3_calc_point_depth()
  24.  * 
  25.  * Revision 1.33  1994/09/09  14:23:58  matt
  26.  * Added support for glowing textures, to add engine glow to Descent.
  27.  * 
  28.  * Revision 1.32  1994/09/01  10:42:27  matt
  29.  * Blob routine, renamed g3_draw_bitmap(), now takes seperate 3d width & height.
  30.  * 
  31.  * Revision 1.31  1994/07/29  18:16:14  matt
  32.  * Added instance by angles, and corrected parms for g3_init()
  33.  * 
  34.  * Revision 1.30  1994/07/25  00:00:00  matt
  35.  * Made 3d no longer deal with point numbers, but only with pointers.
  36.  * 
  37.  * Revision 1.29  1994/07/22  17:57:27  matt
  38.  * Changed the name of the rod functions, and took out some debugging code
  39.  * 
  40.  * Revision 1.28  1994/06/07  16:49:12  matt
  41.  * Made interpreter take lighting value as parm, rather than in global var
  42.  * 
  43.  * Revision 1.27  1994/05/31  18:35:28  matt
  44.  * Added light value to g3_draw_facing_bitmap()
  45.  * 
  46.  * Revision 1.26  1994/05/30  22:48:04  matt
  47.  * Added support for morph effect
  48.  * 
  49.  * Revision 1.25  1994/05/30  11:34:57  matt
  50.  * Added g3_set_special_render() to allow a user to specify functions to
  51.  * call for 2d draws.
  52.  * 
  53.  * Revision 1.24  1994/05/19  21:46:31  matt
  54.  * Moved texture lighting out of 3d and into the game
  55.  * 
  56.  * Revision 1.23  1994/05/14  15:26:48  matt
  57.  * Added extern for polyobj outline flag
  58.  * 
  59.  * Revision 1.22  1994/04/19  18:26:33  matt
  60.  * Added g3_draw_sphere() function.
  61.  * 
  62.  * Revision 1.21  1994/03/25  18:22:28  matt
  63.  * g3_draw_polygon_model() now takes ptr to list of angles
  64.  * 
  65.  * Revision 1.20  1994/03/15  21:23:23  matt
  66.  * Added interpreter functions
  67.  * 
  68.  * Revision 1.19  1994/02/15  17:37:34  matt
  69.  * New function, g3_draw_blob()
  70.  * 
  71.  * Revision 1.18  1994/02/09  11:47:47  matt
  72.  * Added rod & delta point functions
  73.  * 
  74.  * Revision 1.17  1994/01/26  12:38:11  matt
  75.  * Added function g3_compute_lighting_value()
  76.  * 
  77.  * Revision 1.16  1994/01/25  18:00:02  yuan
  78.  * Fixed variable beam_brightness...
  79.  * 
  80.  * Revision 1.15  1994/01/24  14:08:34  matt
  81.  * Added instancing functions
  82.  * 
  83.  * Revision 1.14  1994/01/22  18:21:48  matt
  84.  * New lighting stuff now done in 3d; g3_draw_tmap() takes lighting parm
  85.  * 
  86.  * Revision 1.13  1994/01/20  17:21:24  matt
  87.  * New function g3_compute_sky_polygon()
  88.  * 
  89.  * Revision 1.12  1994/01/14  17:20:25  matt
  90.  * Added prototype for new function g3_draw_horizon()
  91.  * 
  92.  * Revision 1.10  1993/12/20  20:21:52  matt
  93.  * Added g3_point_2_vec()
  94.  * 
  95.  * Revision 1.9  1993/12/07  23:05:47  matt
  96.  * Fixed mistyped function name.
  97.  * 
  98.  * Revision 1.8  1993/12/05  23:47:03  matt
  99.  * Added function g3_draw_line_ptrs()
  100.  * 
  101.  * Revision 1.7  1993/12/05  23:13:22  matt
  102.  * Added prototypes for g3_rotate_point() and g3_project_point()
  103.  * 
  104.  * Revision 1.6  1993/12/05  23:03:28  matt
  105.  * Changed uvl structs to g3s_uvl
  106.  * 
  107.  * Revision 1.5  1993/11/22  10:51:09  matt
  108.  * Moved uvl structure here from segment.h, made texture map functions use it
  109.  * 
  110.  * Revision 1.4  1993/11/21  20:08:31  matt
  111.  * Added function g3_draw_object()
  112.  * 
  113.  * Revision 1.3  1993/11/04  18:49:19  matt
  114.  * Added system to only rotate points once per frame
  115.  * 
  116.  * Revision 1.2  1993/11/04  08:16:06  mike
  117.  * Add light field (p3_l) to g3s_point.
  118.  * 
  119.  * Revision 1.1  1993/10/29  22:20:56  matt
  120.  * Initial revision
  121.  * 
  122.  *
  123.  */
  124.  
  125. #ifndef _3D_H
  126. #define _3D_H
  127.  
  128. #include "fix.h"
  129. #include "vecmat.h"    //the vector/matrix library
  130. #include "gr.h"
  131.  
  132. extern int g3d_interp_outline;        //if on, polygon models outlined in white
  133.  
  134. //Structure for storing u,v,light values.  This structure doesn't have a
  135. //prefix because it was defined somewhere else before it was moved here
  136. typedef struct g3s_uvl {
  137.     fix u,v,l;
  138. } g3s_uvl;
  139.  
  140. //Stucture to store clipping codes in a word
  141. typedef struct g3s_codes {
  142.     ubyte or,and;    //or is low byte, and is high byte
  143. } g3s_codes;
  144.  
  145. //flags for point structure
  146. #define PF_PROJECTED     1    //has been projected, so sx,sy valid
  147. #define PF_OVERFLOW        2    //can't project
  148. #define PF_TEMP_POINT    4    //created during clip
  149. #define PF_UVS                8    //has uv values set
  150.  
  151. //clipping codes flags
  152.  
  153. #define CC_OFF_LEFT    1
  154. #define CC_OFF_RIGHT    2
  155. #define CC_OFF_BOT    4
  156. #define CC_OFF_TOP    8
  157. #define CC_BEHIND        0x80
  158.  
  159. //Used to store rotated points for mines.  Has frame count to indictate
  160. //if rotated, and flag to indicate if projected.
  161. typedef struct g3s_point {
  162.     union {                   //post rotation point
  163.         vms_vector p3_vec;         //reference as vector...
  164.         struct {fix x,y,z;};   //...or by element name
  165.         fix xyz[3];            //...or by element number
  166.     };
  167.     union {                    //u,v,light values for texture mapper
  168.         struct {fix p3_u,p3_v,p3_l;};
  169.         g3s_uvl p3_uvl;
  170.     };
  171.     fix p3_sx,p3_sy;        //screen x&y
  172.     ubyte p3_codes;        //clipping codes
  173.     ubyte p3_flags;        //projected?
  174.     short p3_pad;            //keep structure longwork aligned
  175. } g3s_point;
  176.  
  177. //An object, such as a robot
  178. typedef struct g3s_object {
  179.     vms_vector o3_pos;       //location of this object
  180.     vms_angvec o3_orient;    //orientation of this object
  181.     int o3_nverts;           //number of points in the object
  182.     int o3_nfaces;           //number of faces in the object
  183.  
  184.     //this will be filled in later
  185.  
  186. } g3s_object;
  187.  
  188. //Functions in library
  189.  
  190. //3d system startup and shutdown:
  191.  
  192. //initialize the 3d system
  193. void g3_init(void);
  194.  
  195. //close down the 3d system
  196. void g3_close(void);
  197.  
  198.  
  199. //Frame setup functions:
  200.  
  201. //start the frame
  202. void g3_start_frame(void);
  203.  
  204. //set view from x,y,z & p,b,h, zoom.  Must call one of g3_set_view_*() 
  205. void g3_set_view_angles(vms_vector *view_pos,vms_angvec *view_orient,fix zoom);
  206.  
  207. //set view from x,y,z, viewer matrix, and zoom.  Must call one of g3_set_view_*() 
  208. void g3_set_view_matrix(vms_vector *view_pos,vms_matrix *view_matrix,fix zoom);
  209.  
  210. //end the frame
  211. void g3_end_frame(void);
  212.  
  213. //draw a horizon
  214. void g3_draw_horizon(int sky_color,int ground_color);
  215.  
  216. //get vectors that are edge of horizon
  217. int g3_compute_sky_polygon(fix *points_2d,vms_vector *vecs);
  218.  
  219. //Instancing
  220.  
  221. //instance at specified point with specified orientation
  222. void g3_start_instance_matrix(vms_vector *pos,vms_matrix *orient);
  223.  
  224. //instance at specified point with specified orientation
  225. void g3_start_instance_angles(vms_vector *pos,vms_angvec *angles);
  226.  
  227. //pops the old context
  228. void g3_done_instance();
  229.  
  230. //Misc utility functions:
  231.  
  232. //get current field of view.  Fills in angle for x & y
  233. void g3_get_FOV(fixang *fov_x,fixang *fov_y);
  234.  
  235. //get zoom.  For a given window size, return the zoom which will achieve
  236. //the given FOV along the given axis.
  237. fix g3_get_zoom(char axis,fixang fov,short window_width,short window_height);
  238.  
  239. //returns the normalized, unscaled view vectors
  240. void g3_get_view_vectors(vms_vector *forward,vms_vector *up,vms_vector *right);
  241.  
  242. //returns true if a plane is facing the viewer. takes the unrotated surface 
  243. //normal of the plane, and a point on it.  The normal need not be normalized
  244. bool g3_check_normal_facing(vms_vector *v,vms_vector *norm);
  245.  
  246. //Point definition and rotation functions:
  247.  
  248. //specify the arrays refered to by the 'pointlist' parms in the following
  249. //functions.  I'm not sure if we will keep this function, but I need
  250. //it now.
  251. //void g3_set_points(g3s_point *points,vms_vector *vecs);
  252.  
  253. //returns codes_and & codes_or of a list of points numbers
  254. g3s_codes g3_check_codes(int nv,g3s_point **pointlist);
  255.  
  256. //rotates a point. returns codes.  does not check if already rotated
  257. ubyte g3_rotate_point(g3s_point *dest,vms_vector *src);
  258.  
  259. //projects a point
  260. void g3_project_point(g3s_point *point);
  261.  
  262. //calculate the depth of a point - returns the z coord of the rotated point
  263. fix g3_calc_point_depth(vms_vector *pnt);
  264.  
  265. //from a 2d point, compute the vector through that point
  266. void g3_point_2_vec(vms_vector *v,short sx,short sy);
  267.  
  268. //code a point.  fills in the p3_codes field of the point, and returns the codes
  269. ubyte g3_code_point(g3s_point *point);
  270.  
  271. //delta rotation functions
  272. vms_vector *g3_rotate_delta_x(vms_vector *dest,fix dx);
  273. vms_vector *g3_rotate_delta_y(vms_vector *dest,fix dy);
  274. vms_vector *g3_rotate_delta_z(vms_vector *dest,fix dz);
  275. vms_vector *g3_rotate_delta_vec(vms_vector *dest,vms_vector *src);
  276. ubyte g3_add_delta_vec(g3s_point *dest,g3s_point *src,vms_vector *deltav);
  277.  
  278. //Drawing functions:
  279.  
  280. //draw a flat-shaded face.
  281. //returns 1 if off screen, 0 if drew
  282. bool g3_draw_poly(int nv,g3s_point **pointlist);
  283.  
  284. //draw a texture-mapped face.
  285. //returns 1 if off screen, 0 if drew
  286. bool g3_draw_tmap(int nv,g3s_point **pointlist,g3s_uvl *uvl_list,grs_bitmap *bm);
  287.  
  288. //draw a sortof sphere - i.e., the 2d radius is proportional to the 3d
  289. //radius, but not to the distance from the eye
  290. g3_draw_sphere(g3s_point *pnt,fix rad);
  291.  
  292. //@@//return ligting value for a point
  293. //@@fix g3_compute_lighting_value(g3s_point *rotated_point,fix normval);
  294.  
  295.  
  296. //like g3_draw_poly(), but checks to see if facing.  If surface normal is
  297. //NULL, this routine must compute it, which will be slow.  It is better to 
  298. //pre-compute the normal, and pass it to this function.  When the normal
  299. //is passed, this function works like g3_check_normal_facing() plus
  300. //g3_draw_poly().
  301. //returns -1 if not facing, 1 if off screen, 0 if drew
  302. bool g3_check_and_draw_poly(int nv,g3s_point **pointlist,vms_vector *norm,vms_vector *pnt);
  303. bool g3_check_and_draw_tmap(int nv,g3s_point **pointlist,g3s_uvl *uvl_list,grs_bitmap *bm,vms_vector *norm,vms_vector *pnt);
  304.  
  305. //draws a line. takes two points.
  306. bool g3_draw_line(g3s_point *p0,g3s_point *p1);
  307.  
  308. //draw a polygon that is always facing you
  309. g3_draw_rod_flat(g3s_point *bot_point,fix bot_width,g3s_point *top_point,fix top_width);
  310.  
  311. //draw a bitmap object that is always facing you
  312. g3_draw_rod_tmap(grs_bitmap *bitmap,g3s_point *bot_point,fix bot_width,g3s_point *top_point,fix top_width,fix light);
  313.  
  314. //draws a bitmap with the specified 3d width & height 
  315. g3_draw_bitmap(vms_vector *pos,fix width,fix height,grs_bitmap *bm);
  316.  
  317. //specifies 2d drawing routines to use instead of defaults.  Passing
  318. //NULL for either or both restores defaults
  319. g3_set_special_render(void *tmap_drawer(),void *flat_drawer(),void *line_drawer());
  320.  
  321. //Object functions:
  322.  
  323. //gives the interpreter an array of points to use
  324. void g3_set_interp_points(g3s_point *pointlist);
  325.  
  326. //calls the object interpreter to render an object.  The object renderer
  327. //is really a seperate pipeline. returns true if drew
  328. bool g3_draw_polygon_model(void *model_ptr,grs_bitmap **model_bitmaps,vms_angvec *anim_angles,fix light,fix *glow_values);
  329.  
  330. //init code for bitmap models
  331. void g3_init_polygon_model(void *model_ptr);
  332.  
  333. //alternate interpreter for morphing object
  334. bool g3_draw_morphing_model(void *model_ptr,grs_bitmap **model_bitmaps,vms_angvec *anim_angles,fix light,vms_vector *new_points);
  335.  
  336. //Pragmas
  337.  
  338. #pragma aux g3_init "*" modify exact [eax edx];
  339. #pragma aux g3_close "*" parm [] modify exact [];
  340. #pragma aux g3_start_frame "*" parm [] modify exact [];
  341. #pragma aux g3_end_frame "*" parm [] modify exact [];
  342.  
  343. #pragma aux g3_set_view_angles "*" parm [edi] [esi] [eax] modify exact [];
  344. #pragma aux g3_set_view_matrix "*" parm [edi] [esi] [eax] modify exact [];
  345.  
  346. #pragma aux g3_rotate_point "*" parm [edi] [esi] value [bl] modify exact [ebx];
  347. #pragma aux g3_project_point "*" parm [esi] modify exact [];
  348.  
  349. #pragma aux g3_calc_point_depth "*" parm [esi] value [eax] modify exact [eax];
  350.  
  351. #pragma aux g3_point_2_vec "*" parm [esi] [eax] [ebx] modify exact [eax ebx];
  352.  
  353. #pragma aux g3_draw_line "*" parm [esi] [edi] value [al] modify exact [eax];
  354. #pragma aux g3_draw_poly "*" parm [ecx] [esi] value [al] modify exact [eax ecx esi edx];
  355. #pragma aux g3_check_and_draw_poly "*" parm [ecx] [esi] [edi] [ebx] value [al] modify exact [eax ecx esi edx edi];
  356. #pragma aux g3_draw_tmap "*" parm [ecx] [esi] [ebx] [edx] value [al] modify exact [eax ecx esi edx];
  357. #pragma aux g3_check_and_draw_tmap "*" parm [ecx] [esi] [ebx] [edx] [edi] [eax] value [al] modify exact [eax ecx esi edx];
  358. #pragma aux g3_check_normal_facing "*" parm [esi] [edi] value [al] modify exact [eax esi edi];
  359.  
  360. #pragma aux g3_draw_object "*" parm [ebx] [esi] [edi] [eax] modify exact [];
  361.  
  362. #pragma aux g3_draw_horizon "*" parm [eax] [edx] modify exact [];
  363. #pragma aux g3_compute_sky_polygon "*" parm [ebx] [ecx] value [eax] modify exact [eax];
  364.  
  365. #pragma aux g3_start_instance_matrix "*" parm [esi] [edi] modify exact [esi edi];
  366. #pragma aux g3_start_instance_angles "*" parm [esi] [edi] modify exact [esi edi];
  367. #pragma aux g3_done_instance "*" modify exact [];
  368. #pragma aux g3_new_points "*" parm [esi] [edi] modify exact [];
  369. #pragma aux g3_restore_points "*" modify exact [];
  370.  
  371. //@@#pragma aux g3_compute_lighting_value "*" parm [esi] [ecx] value [ecx] modify exact [ecx];
  372. #pragma aux g3_draw_rod_tmap "*" parm [ebx] [esi] [eax] [edi] [edx] [ecx] modify exact [];
  373. #pragma aux g3_draw_rod_flat "*" parm [esi] [eax] [edi] [edx] modify exact [];
  374. #pragma aux g3_draw_bitmap "*" parm [esi] [ebx] [ecx] [eax] modify exact [esi ecx eax];
  375. #pragma aux g3_draw_sphere "*" parm [esi] [ecx] modify exact [];
  376.  
  377. #pragma aux g3_code_point "*" parm [eax] value [bl] modify exact [bl];
  378.  
  379. //delta rotation functions
  380. #pragma aux g3_rotate_delta_x "*" parm [edi] [ebx] value [edi] modify exact [];
  381. #pragma aux g3_rotate_delta_y "*" parm [edi] [ebx] value [edi] modify exact [];
  382. #pragma aux g3_rotate_delta_z "*" parm [edi] [ebx] value [edi] modify exact [];
  383. #pragma aux g3_rotate_delta_vec "*" parm [edi] [esi] value [edi] modify exact [];
  384. #pragma aux g3_add_delta_vec "*" parm [eax] [esi] [edi] value [bl] modify exact [bl];
  385.  
  386. #pragma aux g3_set_interp_points "*" parm [eax] modify exact [];
  387. #pragma aux g3_draw_polygon_model "*" parm [esi] [edi] [eax] [edx] [ebx] value [al] modify exact [];
  388. #pragma aux g3_init_polygon_model "*" parm [esi] modify exact [];
  389. #pragma aux g3_draw_morphing_model "*" parm [esi] [edi] [eax] [edx] [ebx] value [al] modify exact [];
  390.  
  391. #pragma aux g3_set_special_render "*" parm [eax] [edx] [ebx] modify exact [eax edx ebx];
  392.  
  393. #endif
  394.  
  395.