3D.INC 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
  11. ifndef _3D_INC
  12. _3D_INC equ 1
  13. MAX_POINTS_IN_POLY = 100
  14. include fix.inc
  15. include vecmat.inc
  16. ;Structures
  17. ;Stucture to store clipping codes in a word
  18. g3s_codes STRUCT 2t
  19. cc_or ubyte ? ;or is low byte
  20. cc_and ubyte ? ;and is high byte
  21. g3s_codes ENDS
  22. ;Used to store rotated points for mines. Has frame count to indictate
  23. ;if rotated, and flag to indicate if projected.
  24. g3s_point struct
  25. union
  26. p3_vec vms_vector <>
  27. struct
  28. x fix ?
  29. y fix ?
  30. z fix ?
  31. ends
  32. xyz fix 3t DUP (?)
  33. ends ;end of union
  34. p3_u fix ? ;u & v for this point
  35. p3_v fix ?
  36. p3_l fix ?
  37. p3_sx fix ? ;screen x & y
  38. p3_sy fix ?
  39. p3_codes db ? ;clipping codes
  40. p3_flags db ? ;projected?
  41. p3_pad dw ? ;keep longword aligned
  42. g3s_point ends
  43. ;Flags
  44. ;for g3_flags field of g3s_point
  45. PF_PROJECTED equ 1 ;has been projected
  46. PF_OVERFLOW equ 2 ;can't project
  47. PF_TEMP_POINT equ 4 ;created during clip
  48. PF_UVS equ 8 ;has uv values set
  49. PF_LVS equ 16 ;has lighting values set
  50. ;for clipping codes
  51. CC_OFF_LEFT equ 1
  52. CC_OFF_RIGHT equ 2
  53. CC_OFF_BOT equ 4
  54. CC_OFF_TOP equ 8
  55. CC_BEHIND equ 80h
  56. _DATA segment dword public USE32 'DATA'
  57. ;Global variables
  58. extdef vms_vector,View_position,Matrix_scale,Window_scale
  59. extdef vms_matrix,View_matrix,Unscaled_matrix
  60. extf View_zoom
  61. extd Vbuf0,Vbuf1,Num_points
  62. extd Canvas_width,Canvas_height ;the actual width & height
  63. extf Canv_w2,Canv_h2 ;fixed-point width,height/2
  64. extf Vertex_list
  65. ;Variables local to 3d library
  66. extd free_point_num
  67. _DATA ends
  68. _TEXT segment dword public USE32 'CODE'
  69. ;Routines
  70. ;from setup.asm
  71. extn g3_init ;eax=point list, edx=vec list
  72. extn g3_close ;takes nothing, ret nothing
  73. extn g3_start_frame ;takes nothing, ret nothing
  74. extn g3_end_frame ;takes nothing, ret nothing
  75. ;from matrix.asm
  76. extn g3_set_view_angles ;esi=angvec,esi=pos,eax=zoom
  77. extn g3_set_view_matrix ;esi=matrix,edi=pos,eax=zoom
  78. ;from points.asm
  79. ;;extn g3_set_points ;eax=point list, edx=vec list
  80. extn g3_rotate_point ;edi=dest point, esi=src vec
  81. extn g3_project_point ;esi=point
  82. extn g3_point_2_vec ;esi=vec, eax,ebx = 2d point (shorts)
  83. extn g3_code_point ;eax=point, fill in code, ret bl=code
  84. extn g3_rotate_delta_x ;edi=dest vec, ebx=delta
  85. extn g3_rotate_delta_y ;edi=dest vec, ebx=delta
  86. extn g3_rotate_delta_z ;edi=dest vec, ebx=delta
  87. extn g3_rotate_delta_vec ;edi=dest vec, esi=delta vec
  88. extn g3_add_delta_vec ;eax=dest pnt, esi=src pnt, edi=delta vec. ret bl=codes
  89. extn g3_calc_point_depth ;esi=point, ret eax=depth
  90. extn proj_div0,proj_div1,div_overflow_handler,code_point
  91. extn blob_div0,blob_div1,blob_overflow_handler
  92. extn sphere_proj_div,sphere_div_overflow_handler
  93. ;from draw.asm
  94. extn g3_draw_line ;esi,edi=points
  95. extn g3_draw_poly ;ecx=cnt, esi=point nums, al=ret: 1 off screen, 0 drew
  96. extn g3_check_and_draw_poly ;ecx=cnt, esi=point nums, edi=normal, al=ret: -1 not facing, 1 off screen, 0 drew
  97. extn g3_draw_tmap ;ecx=cnt, esi=point nums, ebx=uvs, edx=bitmap, al=ret: 1 off screen, 0 drew
  98. 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
  99. extn g3_check_normal_facing ;esi=vec, edi=norm, ret al
  100. ;;extn g3_compute_lighting_value ;ecx=surface normal scale, esi=rotated point, ret ecx
  101. extn g3_draw_sphere ;esi=pos (rotated), ecx=radius
  102. extn g3_set_special_render ;eax=tmap draw, edx=flat drawer, ebx=line drawer
  103. ;from clipper.asm
  104. extn clip_line ;esi,edi=points (ptrs)
  105. extn reset_temp_points ;(takes nothing)
  106. extn free_temp_point ;esi=point (ptr)
  107. extn clip_polygon ;esi=src list,edi=dest list,ecx=n, al=codes_or
  108. ;from objects.asm
  109. extn g3_draw_object ;esi=pos,edi=mat,eax=size,ebx=obj_id
  110. ;from horizon.asm
  111. extn g3_draw_horizon ;eax=sky_color, edx=ground_color
  112. extn g3_compute_sky_polygon ;ebx=2d points, ecx=vecs
  113. ;from instance.asm
  114. extn g3_start_instance_matrix ;esi=pos,edi=matrix. trashes esi,edi
  115. extn g3_start_instance_angles ;esi=pos,edi=angvec. trashes esi,edi
  116. extn g3_done_instance ;no parms
  117. ;from rod.asm
  118. extn g3_draw_rod_tmap ;esi,edi=bot,top points,eax,edx=bot,top width, ebx=bitmap, ecx=lightval
  119. extn g3_draw_rod_flat ;esi,edi=bot,top points,eax,edx=bot,top width
  120. extn g3_draw_bitmap ;esi=pos,ebx=width3d,ecx=height3d,eax=bm, trashes eax,ecx,esi
  121. ;from interp.asm
  122. extn g3_set_interp_points ;eax=ptr to list
  123. extn g3_draw_polygon_model ;esi=model ptr, edi=bitmap list ptr, eax=anim angles, edx=light, ebx=ptr to glow values (or NULL)
  124. extn g3_init_polygon_model ;esi=model ptr
  125. extn g3_uninit_polygon_model ;esi=model ptr
  126. extn g3_draw_morphing_model ;esi=model ptr, edi=bitmap list ptr, eax=anim angles, edx=light, ebx=new points
  127. extn g3_remap_interp_colors ;(void)
  128. _TEXT ends
  129. ;check for overflow before doing divide.
  130. ;assume numerator is in edx:eax. Denominator and label to jump to if
  131. ;overflow are passed.
  132. divcheck macro den,lbl
  133. local not_neg1,not_neg2
  134. push ecx
  135. mov ecx,edx
  136. or ecx,ecx
  137. jns not_neg1
  138. neg ecx
  139. not_neg1: shld ecx,eax,1 ;num * 2
  140. cmp ecx,den
  141. pop ecx
  142. jae lbl
  143. endm
  144. ;see if any free points left unfreed, and if so, reset the free point list
  145. check_free_points macro
  146. local free_points_ok
  147. test free_point_num,-1
  148. jz free_points_ok
  149. debug_brk "Error: free_point_num != 0 after draw"
  150. call reset_temp_points
  151. free_points_ok:
  152. endm
  153. endif