3D.INC 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. ;THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
  2. ;SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
  3. ;END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
  4. ;ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
  5. ;IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
  6. ;SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
  7. ;FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
  8. ;CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
  9. ;AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
  10. ;COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
  11. ;
  12. ; $Source: f:/miner/source/3d/rcs/3d.inc $
  13. ; $Revision: 1.30 $
  14. ; $Author: matt $
  15. ; $Date: 1995/02/09 22:00:50 $
  16. ;
  17. ; Header file for 3d library
  18. ;
  19. ; $Log: 3d.inc $
  20. ; Revision 1.30 1995/02/09 22:00:50 matt
  21. ; Removed dependence on divide overflow handler; we now check for overflow
  22. ; before dividing. This fixed problems on some TI chips.
  23. ;
  24. ; Revision 1.29 1994/11/11 19:22:15 matt
  25. ; Added new function, g3_calc_point_depth()
  26. ;
  27. ; Revision 1.28 1994/09/09 14:24:13 matt
  28. ; Added support for glowing textures, to add engine glow to Descent.
  29. ;
  30. ; Revision 1.27 1994/09/01 10:42:26 matt
  31. ; Blob routine, renamed g3_draw_bitmap(), now takes seperate 3d width & height.
  32. ;
  33. ; Revision 1.26 1994/07/29 18:15:53 matt
  34. ; Added instance by angles, and corrected parms for g3_init()
  35. ;
  36. ; Revision 1.25 1994/07/25 00:00:01 matt
  37. ; Made 3d no longer deal with point numbers, but only with pointers.
  38. ;
  39. ; Revision 1.24 1994/07/22 17:57:57 matt
  40. ; Changed the name of the rod functions, and took out some debugging code
  41. ;
  42. ; Revision 1.23 1994/06/07 16:49:35 matt
  43. ; Made interpreter take lighting value as parm, rather than in global var
  44. ;
  45. ; Revision 1.22 1994/05/31 18:35:19 matt
  46. ; Added light value to g3_draw_facing_bitmap()
  47. ;
  48. ; Revision 1.21 1994/05/30 22:48:15 matt
  49. ; Added support for morph effect
  50. ;
  51. ; Revision 1.20 1994/05/30 11:36:25 matt
  52. ; Added g3_set_special_render() to allow a user to specify functions to
  53. ; call for 2d draws.
  54. ;
  55. ; Revision 1.19 1994/05/19 21:46:30 matt
  56. ; Moved texture lighting out of 3d and into the game
  57. ;
  58. ; Revision 1.18 1994/04/19 18:26:41 matt
  59. ; Added g3_draw_sphere() function.
  60. ;
  61. ; Revision 1.17 1994/03/25 18:22:39 matt
  62. ; g3_draw_polygon_model() now takes ptr to list of angles
  63. ;
  64. ; Revision 1.16 1994/03/15 21:23:14 matt
  65. ; Added interpreter functions
  66. ;
  67. ; Revision 1.15 1994/02/15 17:37:35 matt
  68. ; New function, g3_draw_blob()
  69. ;
  70. ; Revision 1.14 1994/02/10 18:00:10 matt
  71. ; Changed 'if DEBUG_ON' to 'ifndef NDEBUG'
  72. ;
  73. ; Revision 1.13 1994/02/09 11:47:34 matt
  74. ; Added rod & delta point functions
  75. ;
  76. ; Revision 1.12 1994/01/26 12:38:20 matt
  77. ; Added function g3_compute_lighting_value()
  78. ;
  79. ; Revision 1.11 1994/01/24 14:08:24 matt
  80. ; Added instancing functions
  81. ;
  82. ; Revision 1.10 1994/01/22 18:22:07 matt
  83. ; New lighting stuff now done in 3d; g3_draw_tmap() takes lighting parm
  84. ;
  85. ; Revision 1.9 1994/01/20 17:21:46 matt
  86. ; New function g3_compute_sky_polygon()
  87. ;
  88. ; Revision 1.8 1994/01/14 17:21:02 matt
  89. ; Added new function g3_draw_horizon()
  90. ;
  91. ; Revision 1.6 1993/12/20 20:21:43 matt
  92. ; Added g3_point_2_vec()
  93. ;
  94. ; Revision 1.5 1993/12/05 23:47:13 matt
  95. ; Added function g3_draw_line_ptrs()
  96. ;
  97. ; Revision 1.4 1993/11/21 20:08:16 matt
  98. ; Added functions g3_rotate_point & g3_draw_object
  99. ;
  100. ; Revision 1.3 1993/11/04 18:49:42 matt
  101. ; Made g3_init() have functionality of g3_set_points(), which I killed
  102. ;
  103. ; Revision 1.2 1993/11/04 12:38:29 mike
  104. ; Add PF_LVS, flag for lighting value
  105. ;
  106. ; Revision 1.1 1993/10/29 22:20:27 matt
  107. ; Initial revision
  108. ;
  109. ;
  110. ;
  111. ifndef _3D_INC
  112. _3D_INC equ 1
  113. MAX_POINTS_IN_POLY = 100
  114. include fix.inc
  115. include vecmat.inc
  116. ;Structures
  117. ;Stucture to store clipping codes in a word
  118. g3s_codes STRUCT 2t
  119. cc_or ubyte ? ;or is low byte
  120. cc_and ubyte ? ;and is high byte
  121. g3s_codes ENDS
  122. ;Used to store rotated points for mines. Has frame count to indictate
  123. ;if rotated, and flag to indicate if projected.
  124. g3s_point struct
  125. union
  126. p3_vec vms_vector <>
  127. struct
  128. x fix ?
  129. y fix ?
  130. z fix ?
  131. ends
  132. xyz fix 3t DUP (?)
  133. ends ;end of union
  134. p3_u fix ? ;u & v for this point
  135. p3_v fix ?
  136. p3_l fix ?
  137. p3_sx fix ? ;screen x & y
  138. p3_sy fix ?
  139. p3_codes db ? ;clipping codes
  140. p3_flags db ? ;projected?
  141. p3_pad dw ? ;keep longword aligned
  142. g3s_point ends
  143. ;Flags
  144. ;for g3_flags field of g3s_point
  145. PF_PROJECTED equ 1 ;has been projected
  146. PF_OVERFLOW equ 2 ;can't project
  147. PF_TEMP_POINT equ 4 ;created during clip
  148. PF_UVS equ 8 ;has uv values set
  149. PF_LVS equ 16 ;has lighting values set
  150. ;for clipping codes
  151. CC_OFF_LEFT equ 1
  152. CC_OFF_RIGHT equ 2
  153. CC_OFF_BOT equ 4
  154. CC_OFF_TOP equ 8
  155. CC_BEHIND equ 80h
  156. _DATA segment dword public USE32 'DATA'
  157. ;Global variables
  158. extdef vms_vector,View_position,Matrix_scale,Window_scale
  159. extdef vms_matrix,View_matrix,Unscaled_matrix
  160. extf View_zoom
  161. extd Vbuf0,Vbuf1,Num_points
  162. extd Canvas_width,Canvas_height ;the actual width & height
  163. extf Canv_w2,Canv_h2 ;fixed-point width,height/2
  164. extf Vertex_list
  165. ;;extw _Frame_count
  166. _DATA ends
  167. _TEXT segment dword public USE32 'CODE'
  168. ;Routines
  169. ;from setup.asm
  170. extn g3_init ;eax=point list, edx=vec list
  171. extn g3_close ;takes nothing, ret nothing
  172. extn g3_start_frame ;takes nothing, ret nothing
  173. extn g3_end_frame ;takes nothing, ret nothing
  174. ;from matrix.asm
  175. extn g3_set_view_angles ;esi=angvec,esi=pos,eax=zoom
  176. extn g3_set_view_matrix ;esi=matrix,edi=pos,eax=zoom
  177. ;from points.asm
  178. ;;extn g3_set_points ;eax=point list, edx=vec list
  179. extn g3_rotate_point ;edi=dest point, esi=src vec
  180. extn g3_project_point ;esi=point
  181. extn g3_point_2_vec ;esi=vec, eax,ebx = 2d point (shorts)
  182. extn g3_code_point ;eax=point, fill in code, ret bl=code
  183. extn g3_rotate_delta_x ;edi=dest vec, ebx=delta
  184. extn g3_rotate_delta_y ;edi=dest vec, ebx=delta
  185. extn g3_rotate_delta_z ;edi=dest vec, ebx=delta
  186. extn g3_rotate_delta_vec ;edi=dest vec, esi=delta vec
  187. extn g3_add_delta_vec ;eax=dest pnt, esi=src pnt, edi=delta vec. ret bl=codes
  188. extn g3_calc_point_depth ;esi=point, ret eax=depth
  189. extn proj_div0,proj_div1,div_overflow_handler,code_point
  190. extn blob_div0,blob_div1,blob_overflow_handler
  191. extn sphere_proj_div,sphere_div_overflow_handler
  192. ;from draw.asm
  193. extn g3_draw_line ;esi,edi=points
  194. extn g3_draw_poly ;ecx=cnt, esi=point nums, al=ret: 1 off screen, 0 drew
  195. extn g3_check_and_draw_poly ;ecx=cnt, esi=point nums, edi=normal, al=ret: -1 not facing, 1 off screen, 0 drew
  196. extn g3_draw_tmap ;ecx=cnt, esi=point nums, ebx=uvs, edx=bitmap, al=ret: 1 off screen, 0 drew
  197. extn g3_check_and_draw_tmap ;ecx=cnt, esi=point nums, ebx=uvs, edx=bitmap, edi=normal, al=ret: -1 not facing, 1 off screen, 0 drew
  198. extn g3_check_normal_facing ;esi=vec, edi=norm, ret al
  199. ;;extn g3_compute_lighting_value ;ecx=surface normal scale, esi=rotated point, ret ecx
  200. extn g3_draw_sphere ;esi=pos (rotated), ecx=radius
  201. extn g3_set_special_render ;eax=tmap draw, edx=flat drawer, ebx=line drawer
  202. ;from clipper.asm
  203. extn clip_line ;esi,edi=points (ptrs)
  204. extn free_temp_point ;esi=point (ptr)
  205. extn clip_polygon ;esi=src list,edi=dest list,ecx=n, al=codes_or
  206. ;from objects.asm
  207. extn g3_draw_object ;esi=pos,edi=mat,eax=size,ebx=obj_id
  208. ;from horizon.asm
  209. extn g3_draw_horizon ;eax=sky_color, edx=ground_color
  210. extn g3_compute_sky_polygon ;ebx=2d points, ecx=vecs
  211. ;from instance.asm
  212. extn g3_start_instance_matrix ;esi=pos,edi=matrix. trashes esi,edi
  213. extn g3_start_instance_angles ;esi=pos,edi=angvec. trashes esi,edi
  214. extn g3_done_instance ;no parms
  215. ;from rod.asm
  216. extn g3_draw_rod_tmap ;esi,edi=bot,top points,eax,edx=bot,top width, ebx=bitmap, ecx=lightval
  217. extn g3_draw_rod_flat ;esi,edi=bot,top points,eax,edx=bot,top width
  218. extn g3_draw_bitmap ;esi=pos,ebx=width3d,ecx=height3d,eax=bm, trashes eax,ecx,esi
  219. ;from interp.asm
  220. extn g3_set_interp_points ;eax=ptr to list
  221. extn g3_draw_polygon_model ;esi=model ptr, edi=bitmap list ptr, eax=anim angles, edx=light, ebx=ptr to glow values (or NULL)
  222. extn g3_init_polygon_model ;esi=model ptr
  223. extn g3_draw_morphing_model ;esi=model ptr, edi=bitmap list ptr, eax=anim angles, edx=light, ebx=new points
  224. _TEXT ends
  225. ;check for overflow before doing divide.
  226. ;assume numerator is in edx:eax. Denominator and label to jump to if
  227. ;overflow are passed.
  228. divcheck macro den,lbl
  229. local not_neg1,not_neg2
  230. push ecx
  231. mov ecx,edx
  232. or ecx,ecx
  233. jns not_neg1
  234. neg ecx
  235. not_neg1: shld ecx,eax,1 ;num * 2
  236. cmp ecx,den
  237. pop ecx
  238. jae lbl
  239. endm
  240. endif