3D.H 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  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-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
  12. */
  13. #ifndef _3D_H
  14. #define _3D_H
  15. #include "fix.h"
  16. #include "vecmat.h" //the vector/matrix library
  17. #include "gr.h"
  18. extern int g3d_interp_outline; //if on, polygon models outlined in white
  19. extern vms_vector Matrix_scale; //how the matrix is currently scaled
  20. #pragma aux Matrix_scale "*";
  21. //Structure for storing u,v,light values. This structure doesn't have a
  22. //prefix because it was defined somewhere else before it was moved here
  23. typedef struct g3s_uvl {
  24. fix u,v,l;
  25. } g3s_uvl;
  26. //Stucture to store clipping codes in a word
  27. typedef struct g3s_codes {
  28. ubyte or,and; //or is low byte, and is high byte
  29. } g3s_codes;
  30. //flags for point structure
  31. #define PF_PROJECTED 1 //has been projected, so sx,sy valid
  32. #define PF_OVERFLOW 2 //can't project
  33. #define PF_TEMP_POINT 4 //created during clip
  34. #define PF_UVS 8 //has uv values set
  35. #define PF_LS 16 //has lighting values set
  36. //clipping codes flags
  37. #define CC_OFF_LEFT 1
  38. #define CC_OFF_RIGHT 2
  39. #define CC_OFF_BOT 4
  40. #define CC_OFF_TOP 8
  41. #define CC_BEHIND 0x80
  42. //Used to store rotated points for mines. Has frame count to indictate
  43. //if rotated, and flag to indicate if projected.
  44. typedef struct g3s_point {
  45. vms_vector p3_vec; //x,y,z of rotated point
  46. fix p3_u,p3_v,p3_l; //u,v,l coords
  47. fix p3_sx,p3_sy; //screen x&y
  48. ubyte p3_codes; //clipping codes
  49. ubyte p3_flags; //projected?
  50. short p3_pad; //keep structure longwork aligned
  51. } g3s_point;
  52. //macros to reference x,y,z elements of a 3d point
  53. #define p3_x p3_vec.x
  54. #define p3_y p3_vec.y
  55. #define p3_z p3_vec.z
  56. //An object, such as a robot
  57. typedef struct g3s_object {
  58. vms_vector o3_pos; //location of this object
  59. vms_angvec o3_orient; //orientation of this object
  60. int o3_nverts; //number of points in the object
  61. int o3_nfaces; //number of faces in the object
  62. //this will be filled in later
  63. } g3s_object;
  64. //Functions in library
  65. //3d system startup and shutdown:
  66. //initialize the 3d system
  67. void g3_init(void);
  68. //close down the 3d system
  69. void g3_close(void);
  70. //Frame setup functions:
  71. //start the frame
  72. void g3_start_frame(void);
  73. //set view from x,y,z & p,b,h, zoom. Must call one of g3_set_view_*()
  74. void g3_set_view_angles(vms_vector *view_pos,vms_angvec *view_orient,fix zoom);
  75. //set view from x,y,z, viewer matrix, and zoom. Must call one of g3_set_view_*()
  76. void g3_set_view_matrix(vms_vector *view_pos,vms_matrix *view_matrix,fix zoom);
  77. //end the frame
  78. void g3_end_frame(void);
  79. //draw a horizon
  80. void g3_draw_horizon(int sky_color,int ground_color);
  81. //get vectors that are edge of horizon
  82. int g3_compute_sky_polygon(fix *points_2d,vms_vector *vecs);
  83. //Instancing
  84. //instance at specified point with specified orientation
  85. void g3_start_instance_matrix(vms_vector *pos,vms_matrix *orient);
  86. //instance at specified point with specified orientation
  87. void g3_start_instance_angles(vms_vector *pos,vms_angvec *angles);
  88. //pops the old context
  89. void g3_done_instance();
  90. //Misc utility functions:
  91. //get current field of view. Fills in angle for x & y
  92. void g3_get_FOV(fixang *fov_x,fixang *fov_y);
  93. //get zoom. For a given window size, return the zoom which will achieve
  94. //the given FOV along the given axis.
  95. fix g3_get_zoom(char axis,fixang fov,short window_width,short window_height);
  96. //returns the normalized, unscaled view vectors
  97. void g3_get_view_vectors(vms_vector *forward,vms_vector *up,vms_vector *right);
  98. //returns true if a plane is facing the viewer. takes the unrotated surface
  99. //normal of the plane, and a point on it. The normal need not be normalized
  100. bool g3_check_normal_facing(vms_vector *v,vms_vector *norm);
  101. //Point definition and rotation functions:
  102. //specify the arrays refered to by the 'pointlist' parms in the following
  103. //functions. I'm not sure if we will keep this function, but I need
  104. //it now.
  105. //void g3_set_points(g3s_point *points,vms_vector *vecs);
  106. //returns codes_and & codes_or of a list of points numbers
  107. g3s_codes g3_check_codes(int nv,g3s_point **pointlist);
  108. //rotates a point. returns codes. does not check if already rotated
  109. ubyte g3_rotate_point(g3s_point *dest,vms_vector *src);
  110. //projects a point
  111. void g3_project_point(g3s_point *point);
  112. //calculate the depth of a point - returns the z coord of the rotated point
  113. fix g3_calc_point_depth(vms_vector *pnt);
  114. //from a 2d point, compute the vector through that point
  115. void g3_point_2_vec(vms_vector *v,short sx,short sy);
  116. //code a point. fills in the p3_codes field of the point, and returns the codes
  117. ubyte g3_code_point(g3s_point *point);
  118. //delta rotation functions
  119. vms_vector *g3_rotate_delta_x(vms_vector *dest,fix dx);
  120. vms_vector *g3_rotate_delta_y(vms_vector *dest,fix dy);
  121. vms_vector *g3_rotate_delta_z(vms_vector *dest,fix dz);
  122. vms_vector *g3_rotate_delta_vec(vms_vector *dest,vms_vector *src);
  123. ubyte g3_add_delta_vec(g3s_point *dest,g3s_point *src,vms_vector *deltav);
  124. //Drawing functions:
  125. //draw a flat-shaded face.
  126. //returns 1 if off screen, 0 if drew
  127. bool g3_draw_poly(int nv,g3s_point **pointlist);
  128. //draw a texture-mapped face.
  129. //returns 1 if off screen, 0 if drew
  130. bool g3_draw_tmap(int nv,g3s_point **pointlist,g3s_uvl *uvl_list,grs_bitmap *bm);
  131. //draw a sortof sphere - i.e., the 2d radius is proportional to the 3d
  132. //radius, but not to the distance from the eye
  133. g3_draw_sphere(g3s_point *pnt,fix rad);
  134. //@@//return ligting value for a point
  135. //@@fix g3_compute_lighting_value(g3s_point *rotated_point,fix normval);
  136. //like g3_draw_poly(), but checks to see if facing. If surface normal is
  137. //NULL, this routine must compute it, which will be slow. It is better to
  138. //pre-compute the normal, and pass it to this function. When the normal
  139. //is passed, this function works like g3_check_normal_facing() plus
  140. //g3_draw_poly().
  141. //returns -1 if not facing, 1 if off screen, 0 if drew
  142. bool g3_check_and_draw_poly(int nv,g3s_point **pointlist,vms_vector *norm,vms_vector *pnt);
  143. bool g3_check_and_draw_tmap(int nv,g3s_point **pointlist,g3s_uvl *uvl_list,grs_bitmap *bm,vms_vector *norm,vms_vector *pnt);
  144. //draws a line. takes two points.
  145. bool g3_draw_line(g3s_point *p0,g3s_point *p1);
  146. //draw a polygon that is always facing you
  147. //returns 1 if off screen, 0 if drew
  148. bool g3_draw_rod_flat(g3s_point *bot_point,fix bot_width,g3s_point *top_point,fix top_width);
  149. //draw a bitmap object that is always facing you
  150. //returns 1 if off screen, 0 if drew
  151. bool g3_draw_rod_tmap(grs_bitmap *bitmap,g3s_point *bot_point,fix bot_width,g3s_point *top_point,fix top_width,fix light);
  152. //draws a bitmap with the specified 3d width & height
  153. //returns 1 if off screen, 0 if drew
  154. bool g3_draw_bitmap(vms_vector *pos,fix width,fix height,grs_bitmap *bm, int orientation);
  155. //specifies 2d drawing routines to use instead of defaults. Passing
  156. //NULL for either or both restores defaults
  157. void g3_set_special_render(void (*tmap_drawer)(),void (*flat_drawer)(),int (*line_drawer)());
  158. //Object functions:
  159. //gives the interpreter an array of points to use
  160. void g3_set_interp_points(g3s_point *pointlist);
  161. //calls the object interpreter to render an object. The object renderer
  162. //is really a seperate pipeline. returns true if drew
  163. bool g3_draw_polygon_model(void *model_ptr,grs_bitmap **model_bitmaps,vms_angvec *anim_angles,fix light,fix *glow_values);
  164. //init code for bitmap models
  165. void g3_init_polygon_model(void *model_ptr);
  166. //un-initialize, i.e., convert color entries back to RGB15
  167. void g3_uninit_polygon_model(void *model_ptr);
  168. //alternate interpreter for morphing object
  169. bool g3_draw_morphing_model(void *model_ptr,grs_bitmap **model_bitmaps,vms_angvec *anim_angles,fix light,vms_vector *new_points);
  170. //this remaps the 15bpp colors for the models into a new palette. It should
  171. //be called whenever the palette changes
  172. void g3_remap_interp_colors(void);
  173. //Pragmas
  174. #pragma aux g3_init "*" modify exact [eax edx];
  175. #pragma aux g3_close "*" parm [] modify exact [];
  176. #pragma aux g3_start_frame "*" parm [] modify exact [];
  177. #pragma aux g3_end_frame "*" parm [] modify exact [];
  178. #pragma aux g3_set_view_angles "*" parm [edi] [esi] [eax] modify exact [];
  179. #pragma aux g3_set_view_matrix "*" parm [edi] [esi] [eax] modify exact [];
  180. #pragma aux g3_rotate_point "*" parm [edi] [esi] value [bl] modify exact [ebx];
  181. #pragma aux g3_project_point "*" parm [esi] modify exact [];
  182. #pragma aux g3_calc_point_depth "*" parm [esi] value [eax] modify exact [eax];
  183. #pragma aux g3_point_2_vec "*" parm [esi] [eax] [ebx] modify exact [eax ebx];
  184. #pragma aux g3_draw_line "*" parm [esi] [edi] value [al] modify exact [eax];
  185. #pragma aux g3_draw_poly "*" parm [ecx] [esi] value [al] modify exact [eax ecx esi edx];
  186. #pragma aux g3_check_and_draw_poly "*" parm [ecx] [esi] [edi] [ebx] value [al] modify exact [eax ecx esi edx edi];
  187. #pragma aux g3_draw_tmap "*" parm [ecx] [esi] [ebx] [edx] value [al] modify exact [eax ecx esi edx];
  188. #pragma aux g3_check_and_draw_tmap "*" parm [ecx] [esi] [ebx] [edx] [edi] [eax] value [al] modify exact [eax ecx esi edx];
  189. #pragma aux g3_check_normal_facing "*" parm [esi] [edi] value [al] modify exact [eax esi edi];
  190. #pragma aux g3_draw_object "*" parm [ebx] [esi] [edi] [eax] modify exact [];
  191. #pragma aux g3_draw_horizon "*" parm [eax] [edx] modify exact [];
  192. #pragma aux g3_compute_sky_polygon "*" parm [ebx] [ecx] value [eax] modify exact [eax];
  193. #pragma aux g3_start_instance_matrix "*" parm [esi] [edi] modify exact [esi edi];
  194. #pragma aux g3_start_instance_angles "*" parm [esi] [edi] modify exact [esi edi];
  195. #pragma aux g3_done_instance "*" modify exact [];
  196. #pragma aux g3_new_points "*" parm [esi] [edi] modify exact [];
  197. #pragma aux g3_restore_points "*" modify exact [];
  198. //@@#pragma aux g3_compute_lighting_value "*" parm [esi] [ecx] value [ecx] modify exact [ecx];
  199. #pragma aux g3_draw_rod_tmap "*" parm [ebx] [esi] [eax] [edi] [edx] [ecx] modify exact [];
  200. #pragma aux g3_draw_rod_flat "*" parm [esi] [eax] [edi] [edx] modify exact [];
  201. #pragma aux g3_draw_bitmap "*" parm [esi] [ebx] [ecx] [eax] [edx] modify exact [esi ecx eax];
  202. #pragma aux g3_draw_sphere "*" parm [esi] [ecx] modify exact [];
  203. #pragma aux g3_code_point "*" parm [eax] value [bl] modify exact [bl];
  204. //delta rotation functions
  205. #pragma aux g3_rotate_delta_x "*" parm [edi] [ebx] value [edi] modify exact [];
  206. #pragma aux g3_rotate_delta_y "*" parm [edi] [ebx] value [edi] modify exact [];
  207. #pragma aux g3_rotate_delta_z "*" parm [edi] [ebx] value [edi] modify exact [];
  208. #pragma aux g3_rotate_delta_vec "*" parm [edi] [esi] value [edi] modify exact [];
  209. #pragma aux g3_add_delta_vec "*" parm [eax] [esi] [edi] value [bl] modify exact [bl];
  210. #pragma aux g3_set_interp_points "*" parm [eax] modify exact [];
  211. #pragma aux g3_draw_polygon_model "*" parm [esi] [edi] [eax] [edx] [ebx] value [al] modify exact [];
  212. #pragma aux g3_init_polygon_model "*" parm [esi] modify exact [];
  213. #pragma aux g3_uninit_polygon_model "*" parm [esi] modify exact [];
  214. #pragma aux g3_draw_morphing_model "*" parm [esi] [edi] [eax] [edx] [ebx] value [al] modify exact [];
  215. #pragma aux g3_remap_interp_colors "*" modify exact [];
  216. #pragma aux g3_set_special_render "*" parm [eax] [edx] [ebx] modify exact [eax edx ebx];
  217. #endif