3D.H 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  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. #ifndef _3D_H
  125. #define _3D_H
  126. #include "fix.h"
  127. #include "vecmat.h" //the vector/matrix library
  128. #include "gr.h"
  129. extern int g3d_interp_outline; //if on, polygon models outlined in white
  130. //Structure for storing u,v,light values. This structure doesn't have a
  131. //prefix because it was defined somewhere else before it was moved here
  132. typedef struct g3s_uvl {
  133. fix u,v,l;
  134. } g3s_uvl;
  135. //Stucture to store clipping codes in a word
  136. typedef struct g3s_codes {
  137. ubyte or,and; //or is low byte, and is high byte
  138. } g3s_codes;
  139. //flags for point structure
  140. #define PF_PROJECTED 1 //has been projected, so sx,sy valid
  141. #define PF_OVERFLOW 2 //can't project
  142. #define PF_TEMP_POINT 4 //created during clip
  143. #define PF_UVS 8 //has uv values set
  144. //clipping codes flags
  145. #define CC_OFF_LEFT 1
  146. #define CC_OFF_RIGHT 2
  147. #define CC_OFF_BOT 4
  148. #define CC_OFF_TOP 8
  149. #define CC_BEHIND 0x80
  150. //Used to store rotated points for mines. Has frame count to indictate
  151. //if rotated, and flag to indicate if projected.
  152. typedef struct g3s_point {
  153. union { //post rotation point
  154. vms_vector p3_vec; //reference as vector...
  155. struct {fix x,y,z;}; //...or by element name
  156. fix xyz[3]; //...or by element number
  157. };
  158. union { //u,v,light values for texture mapper
  159. struct {fix p3_u,p3_v,p3_l;};
  160. g3s_uvl p3_uvl;
  161. };
  162. fix p3_sx,p3_sy; //screen x&y
  163. ubyte p3_codes; //clipping codes
  164. ubyte p3_flags; //projected?
  165. short p3_pad; //keep structure longwork aligned
  166. } g3s_point;
  167. //An object, such as a robot
  168. typedef struct g3s_object {
  169. vms_vector o3_pos; //location of this object
  170. vms_angvec o3_orient; //orientation of this object
  171. int o3_nverts; //number of points in the object
  172. int o3_nfaces; //number of faces in the object
  173. //this will be filled in later
  174. } g3s_object;
  175. //Functions in library
  176. //3d system startup and shutdown:
  177. //initialize the 3d system
  178. void g3_init(void);
  179. //close down the 3d system
  180. void g3_close(void);
  181. //Frame setup functions:
  182. //start the frame
  183. void g3_start_frame(void);
  184. //set view from x,y,z & p,b,h, zoom. Must call one of g3_set_view_*()
  185. void g3_set_view_angles(vms_vector *view_pos,vms_angvec *view_orient,fix zoom);
  186. //set view from x,y,z, viewer matrix, and zoom. Must call one of g3_set_view_*()
  187. void g3_set_view_matrix(vms_vector *view_pos,vms_matrix *view_matrix,fix zoom);
  188. //end the frame
  189. void g3_end_frame(void);
  190. //draw a horizon
  191. void g3_draw_horizon(int sky_color,int ground_color);
  192. //get vectors that are edge of horizon
  193. int g3_compute_sky_polygon(fix *points_2d,vms_vector *vecs);
  194. //Instancing
  195. //instance at specified point with specified orientation
  196. void g3_start_instance_matrix(vms_vector *pos,vms_matrix *orient);
  197. //instance at specified point with specified orientation
  198. void g3_start_instance_angles(vms_vector *pos,vms_angvec *angles);
  199. //pops the old context
  200. void g3_done_instance();
  201. //Misc utility functions:
  202. //get current field of view. Fills in angle for x & y
  203. void g3_get_FOV(fixang *fov_x,fixang *fov_y);
  204. //get zoom. For a given window size, return the zoom which will achieve
  205. //the given FOV along the given axis.
  206. fix g3_get_zoom(char axis,fixang fov,short window_width,short window_height);
  207. //returns the normalized, unscaled view vectors
  208. void g3_get_view_vectors(vms_vector *forward,vms_vector *up,vms_vector *right);
  209. //returns true if a plane is facing the viewer. takes the unrotated surface
  210. //normal of the plane, and a point on it. The normal need not be normalized
  211. bool g3_check_normal_facing(vms_vector *v,vms_vector *norm);
  212. //Point definition and rotation functions:
  213. //specify the arrays refered to by the 'pointlist' parms in the following
  214. //functions. I'm not sure if we will keep this function, but I need
  215. //it now.
  216. //void g3_set_points(g3s_point *points,vms_vector *vecs);
  217. //returns codes_and & codes_or of a list of points numbers
  218. g3s_codes g3_check_codes(int nv,g3s_point **pointlist);
  219. //rotates a point. returns codes. does not check if already rotated
  220. ubyte g3_rotate_point(g3s_point *dest,vms_vector *src);
  221. //projects a point
  222. void g3_project_point(g3s_point *point);
  223. //calculate the depth of a point - returns the z coord of the rotated point
  224. fix g3_calc_point_depth(vms_vector *pnt);
  225. //from a 2d point, compute the vector through that point
  226. void g3_point_2_vec(vms_vector *v,short sx,short sy);
  227. //code a point. fills in the p3_codes field of the point, and returns the codes
  228. ubyte g3_code_point(g3s_point *point);
  229. //delta rotation functions
  230. vms_vector *g3_rotate_delta_x(vms_vector *dest,fix dx);
  231. vms_vector *g3_rotate_delta_y(vms_vector *dest,fix dy);
  232. vms_vector *g3_rotate_delta_z(vms_vector *dest,fix dz);
  233. vms_vector *g3_rotate_delta_vec(vms_vector *dest,vms_vector *src);
  234. ubyte g3_add_delta_vec(g3s_point *dest,g3s_point *src,vms_vector *deltav);
  235. //Drawing functions:
  236. //draw a flat-shaded face.
  237. //returns 1 if off screen, 0 if drew
  238. bool g3_draw_poly(int nv,g3s_point **pointlist);
  239. //draw a texture-mapped face.
  240. //returns 1 if off screen, 0 if drew
  241. bool g3_draw_tmap(int nv,g3s_point **pointlist,g3s_uvl *uvl_list,grs_bitmap *bm);
  242. //draw a sortof sphere - i.e., the 2d radius is proportional to the 3d
  243. //radius, but not to the distance from the eye
  244. g3_draw_sphere(g3s_point *pnt,fix rad);
  245. //@@//return ligting value for a point
  246. //@@fix g3_compute_lighting_value(g3s_point *rotated_point,fix normval);
  247. //like g3_draw_poly(), but checks to see if facing. If surface normal is
  248. //NULL, this routine must compute it, which will be slow. It is better to
  249. //pre-compute the normal, and pass it to this function. When the normal
  250. //is passed, this function works like g3_check_normal_facing() plus
  251. //g3_draw_poly().
  252. //returns -1 if not facing, 1 if off screen, 0 if drew
  253. bool g3_check_and_draw_poly(int nv,g3s_point **pointlist,vms_vector *norm,vms_vector *pnt);
  254. bool g3_check_and_draw_tmap(int nv,g3s_point **pointlist,g3s_uvl *uvl_list,grs_bitmap *bm,vms_vector *norm,vms_vector *pnt);
  255. //draws a line. takes two points.
  256. bool g3_draw_line(g3s_point *p0,g3s_point *p1);
  257. //draw a polygon that is always facing you
  258. g3_draw_rod_flat(g3s_point *bot_point,fix bot_width,g3s_point *top_point,fix top_width);
  259. //draw a bitmap object that is always facing you
  260. g3_draw_rod_tmap(grs_bitmap *bitmap,g3s_point *bot_point,fix bot_width,g3s_point *top_point,fix top_width,fix light);
  261. //draws a bitmap with the specified 3d width & height
  262. g3_draw_bitmap(vms_vector *pos,fix width,fix height,grs_bitmap *bm);
  263. //specifies 2d drawing routines to use instead of defaults. Passing
  264. //NULL for either or both restores defaults
  265. g3_set_special_render(void *tmap_drawer(),void *flat_drawer(),void *line_drawer());
  266. //Object functions:
  267. //gives the interpreter an array of points to use
  268. void g3_set_interp_points(g3s_point *pointlist);
  269. //calls the object interpreter to render an object. The object renderer
  270. //is really a seperate pipeline. returns true if drew
  271. bool g3_draw_polygon_model(void *model_ptr,grs_bitmap **model_bitmaps,vms_angvec *anim_angles,fix light,fix *glow_values);
  272. //init code for bitmap models
  273. void g3_init_polygon_model(void *model_ptr);
  274. //alternate interpreter for morphing object
  275. bool g3_draw_morphing_model(void *model_ptr,grs_bitmap **model_bitmaps,vms_angvec *anim_angles,fix light,vms_vector *new_points);
  276. //Pragmas
  277. #pragma aux g3_init "*" modify exact [eax edx];
  278. #pragma aux g3_close "*" parm [] modify exact [];
  279. #pragma aux g3_start_frame "*" parm [] modify exact [];
  280. #pragma aux g3_end_frame "*" parm [] modify exact [];
  281. #pragma aux g3_set_view_angles "*" parm [edi] [esi] [eax] modify exact [];
  282. #pragma aux g3_set_view_matrix "*" parm [edi] [esi] [eax] modify exact [];
  283. #pragma aux g3_rotate_point "*" parm [edi] [esi] value [bl] modify exact [ebx];
  284. #pragma aux g3_project_point "*" parm [esi] modify exact [];
  285. #pragma aux g3_calc_point_depth "*" parm [esi] value [eax] modify exact [eax];
  286. #pragma aux g3_point_2_vec "*" parm [esi] [eax] [ebx] modify exact [eax ebx];
  287. #pragma aux g3_draw_line "*" parm [esi] [edi] value [al] modify exact [eax];
  288. #pragma aux g3_draw_poly "*" parm [ecx] [esi] value [al] modify exact [eax ecx esi edx];
  289. #pragma aux g3_check_and_draw_poly "*" parm [ecx] [esi] [edi] [ebx] value [al] modify exact [eax ecx esi edx edi];
  290. #pragma aux g3_draw_tmap "*" parm [ecx] [esi] [ebx] [edx] value [al] modify exact [eax ecx esi edx];
  291. #pragma aux g3_check_and_draw_tmap "*" parm [ecx] [esi] [ebx] [edx] [edi] [eax] value [al] modify exact [eax ecx esi edx];
  292. #pragma aux g3_check_normal_facing "*" parm [esi] [edi] value [al] modify exact [eax esi edi];
  293. #pragma aux g3_draw_object "*" parm [ebx] [esi] [edi] [eax] modify exact [];
  294. #pragma aux g3_draw_horizon "*" parm [eax] [edx] modify exact [];
  295. #pragma aux g3_compute_sky_polygon "*" parm [ebx] [ecx] value [eax] modify exact [eax];
  296. #pragma aux g3_start_instance_matrix "*" parm [esi] [edi] modify exact [esi edi];
  297. #pragma aux g3_start_instance_angles "*" parm [esi] [edi] modify exact [esi edi];
  298. #pragma aux g3_done_instance "*" modify exact [];
  299. #pragma aux g3_new_points "*" parm [esi] [edi] modify exact [];
  300. #pragma aux g3_restore_points "*" modify exact [];
  301. //@@#pragma aux g3_compute_lighting_value "*" parm [esi] [ecx] value [ecx] modify exact [ecx];
  302. #pragma aux g3_draw_rod_tmap "*" parm [ebx] [esi] [eax] [edi] [edx] [ecx] modify exact [];
  303. #pragma aux g3_draw_rod_flat "*" parm [esi] [eax] [edi] [edx] modify exact [];
  304. #pragma aux g3_draw_bitmap "*" parm [esi] [ebx] [ecx] [eax] modify exact [esi ecx eax];
  305. #pragma aux g3_draw_sphere "*" parm [esi] [ecx] modify exact [];
  306. #pragma aux g3_code_point "*" parm [eax] value [bl] modify exact [bl];
  307. //delta rotation functions
  308. #pragma aux g3_rotate_delta_x "*" parm [edi] [ebx] value [edi] modify exact [];
  309. #pragma aux g3_rotate_delta_y "*" parm [edi] [ebx] value [edi] modify exact [];
  310. #pragma aux g3_rotate_delta_z "*" parm [edi] [ebx] value [edi] modify exact [];
  311. #pragma aux g3_rotate_delta_vec "*" parm [edi] [esi] value [edi] modify exact [];
  312. #pragma aux g3_add_delta_vec "*" parm [eax] [esi] [edi] value [bl] modify exact [bl];
  313. #pragma aux g3_set_interp_points "*" parm [eax] modify exact [];
  314. #pragma aux g3_draw_polygon_model "*" parm [esi] [edi] [eax] [edx] [ebx] value [al] modify exact [];
  315. #pragma aux g3_init_polygon_model "*" parm [esi] modify exact [];
  316. #pragma aux g3_draw_morphing_model "*" parm [esi] [edi] [eax] [edx] [ebx] value [al] modify exact [];
  317. #pragma aux g3_set_special_render "*" parm [eax] [edx] [ebx] modify exact [eax edx ebx];
  318. #endif