POINTS.ASM 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  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. .386
  12. option oldstructs
  13. .nolist
  14. include pstypes.inc
  15. include psmacros.inc
  16. include gr.inc
  17. include 3d.inc
  18. .list
  19. assume cs:_TEXT, ds:_DATA
  20. _DATA segment dword public USE32 'DATA'
  21. rcsid db "$Id: points.asm 1.14 1996/01/08 14:59:12 matt Exp $"
  22. align 4
  23. tempv vms_vector <>
  24. tempm vms_matrix <>
  25. _DATA ends
  26. _TEXT segment dword public USE32 'CODE'
  27. ;finds clipping codes for a point. takes eax=point. fills in p3_codes,
  28. ;and returns codes in bl.
  29. g3_code_point:
  30. code_point: push ecx
  31. xor bl,bl ;clear codes
  32. mov ecx,[eax].z ;get z
  33. cmp [eax].x,ecx ;x>z?
  34. jle not_right
  35. or bl,CC_OFF_RIGHT
  36. not_right: cmp [eax].y,ecx ;y>z?
  37. jle not_top
  38. or bl,CC_OFF_TOP
  39. not_top: neg ecx
  40. js not_behind
  41. or bl,CC_BEHIND
  42. not_behind: cmp [eax].x,ecx ;x<-z?
  43. jge not_left
  44. or bl,CC_OFF_LEFT
  45. not_left: cmp [eax].y,ecx ;y<-z
  46. jge not_bot
  47. or bl,CC_OFF_BOT
  48. not_bot: pop ecx
  49. mov [eax].p3_codes,bl
  50. ret
  51. ;rotate a point. don't look at rotated flags
  52. ;takes esi=dest point, esi=src vector
  53. ;returns bl=codes
  54. g3_rotate_point: pushm eax,ecx,esi,edi
  55. push edi ;save dest
  56. lea eax,tempv
  57. lea edi,View_position
  58. call vm_vec_sub
  59. mov esi,eax
  60. pop eax
  61. lea edi,View_matrix
  62. call vm_vec_rotate
  63. mov [eax].p3_flags,0 ;not projected
  64. ;;mov bx,_Frame_count ;curren frame
  65. ;;mov [eax].p3_frame,bx
  66. call code_point
  67. popm eax,ecx,esi,edi
  68. ret
  69. ;projects a point. takes esi=point
  70. g3_project_point:
  71. ;;ifndef NDEBUG
  72. ;; push eax
  73. ;; mov ax,[esi].p3_frame
  74. ;; cmp ax,_Frame_count
  75. ;; break_if ne,'Trying to project unrotated point!'
  76. ;; pop eax
  77. ;;endif
  78. test [esi].p3_flags,PF_PROJECTED
  79. jnz no_project
  80. test [esi].p3_codes,CC_BEHIND
  81. jnz no_project
  82. pushm eax,edx
  83. mov eax,[esi].x
  84. imul Canv_w2
  85. proj_div0: divcheck [esi].z,div_overflow_handler
  86. idiv [esi].z
  87. add eax,Canv_w2
  88. mov [esi].p3_sx,eax
  89. mov eax,[esi].y
  90. imul Canv_h2
  91. proj_div1: divcheck [esi].z,div_overflow_handler
  92. idiv [esi].z
  93. neg eax
  94. add eax,Canv_h2
  95. mov [esi].p3_sy,eax
  96. or [esi].p3_flags,PF_PROJECTED ;projected
  97. popm eax,edx
  98. no_project: ret
  99. div_overflow_handler:
  100. ;int 3
  101. mov [esi].p3_flags,PF_OVERFLOW
  102. popm eax,edx
  103. ret
  104. ;from a 2d point on the screen, compute the vector in 3-space through that point
  105. ;takes eax,ebx = 2d point, esi=vector
  106. ;the 2d point is relative to the center of the canvas
  107. g3_point_2_vec: pushm ecx,edx,esi,edi
  108. push esi
  109. lea esi,tempv
  110. ;;mov edx,eax
  111. ;;xor eax,eax
  112. ;;idiv Canv_w2
  113. sal eax,16
  114. sub eax,Canv_w2
  115. fixdiv Canv_w2
  116. imul Matrix_scale.z
  117. idiv Matrix_scale.x
  118. mov [esi].x,eax
  119. ;;mov edx,ebx
  120. ;;xor eax,eax
  121. ;;sub Canv_h2
  122. ;;idiv Canv_h2
  123. mov eax,ebx
  124. sal eax,16
  125. sub eax,Canv_h2
  126. fixdiv Canv_h2
  127. imul Matrix_scale.z
  128. idiv Matrix_scale.y
  129. neg eax
  130. mov [esi].y,eax
  131. mov [esi].z,f1_0
  132. call vm_vec_normalize ;get normalized rotated vec
  133. lea edi,tempm
  134. lea esi,Unscaled_matrix
  135. call vm_copy_transpose_matrix
  136. pop eax ;get dest
  137. lea esi,tempv ;edi=matrix
  138. call vm_vec_rotate
  139. popm ecx,edx,esi,edi
  140. ret
  141. ;rotate a delta y vector. takes edi=dest vec, ebx=delta y
  142. g3_rotate_delta_y: pushm eax,edx
  143. mov eax,View_matrix.m4
  144. fixmul ebx
  145. mov [edi].x,eax
  146. mov eax,View_matrix.m5
  147. fixmul ebx
  148. mov [edi].y,eax
  149. mov eax,View_matrix.m6
  150. fixmul ebx
  151. mov [edi].z,eax
  152. popm eax,edx
  153. ret
  154. ;rotate a delta x vector. takes edi=dest vec, ebx=delta x
  155. g3_rotate_delta_x: pushm eax,edx
  156. mov eax,View_matrix.m1
  157. fixmul ebx
  158. mov [edi].x,eax
  159. mov eax,View_matrix.m2
  160. fixmul ebx
  161. mov [edi].y,eax
  162. mov eax,View_matrix.m3
  163. fixmul ebx
  164. mov [edi].z,eax
  165. popm eax,edx
  166. ret
  167. ;rotate a delta x vector. takes edi=dest vec, ebx=delta z
  168. g3_rotate_delta_z: pushm eax,edx
  169. mov eax,View_matrix.m7
  170. fixmul ebx
  171. mov [edi].x,eax
  172. mov eax,View_matrix.m8
  173. fixmul ebx
  174. mov [edi].y,eax
  175. mov eax,View_matrix.m9
  176. fixmul ebx
  177. mov [edi].z,eax
  178. popm eax,edx
  179. ret
  180. ;rotate a delta vector. takes edi=dest vec, esi=src vec
  181. g3_rotate_delta_vec:
  182. pushm eax,edi
  183. mov eax,edi
  184. lea edi,View_matrix
  185. call vm_vec_rotate
  186. popm eax,edi
  187. ret
  188. ;adds a delta vector to a point. takes eax=dest point, esi=src pnt, edi=delta vec
  189. ;returns bl=codes.
  190. g3_add_delta_vec: ;;ifndef NDEBUG
  191. ;; push eax
  192. ;; mov ax,[esi].p3_frame
  193. ;; cmp ax,_Frame_count
  194. ;; break_if ne,'Trying to add delta to unrotated point!'
  195. ;; pop eax
  196. ;;endif
  197. call vm_vec_add
  198. ;;mov bx,_Frame_count
  199. ;;mov [eax].p3_frame,bx
  200. mov [eax].p3_flags,0 ;not projected
  201. call g3_code_point
  202. ret
  203. ;calculate the depth of a point - returns the z coord of the rotated point
  204. ;takes esi=vec, returns eax=depth
  205. g3_calc_point_depth:
  206. pushm edx,ebx,ecx
  207. mov eax,[esi].x
  208. sub eax,View_position.x
  209. imul View_matrix.fvec.x
  210. mov ebx,eax
  211. mov ecx,edx
  212. mov eax,[esi].y
  213. sub eax,View_position.y
  214. imul View_matrix.fvec.y
  215. add ebx,eax
  216. adc ecx,edx
  217. mov eax,[esi].z
  218. sub eax,View_position.z
  219. imul View_matrix.fvec.z
  220. add eax,ebx
  221. adc edx,ecx
  222. shrd eax,edx,16
  223. popm edx,ebx,ecx
  224. ret
  225. _TEXT ends
  226. end