ROD.ASM 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  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. ALWAYS_USE_SCALER = 0 ;if true, use scaler even when banked
  12. .386
  13. option oldstructs
  14. .nolist
  15. include pstypes.inc
  16. include psmacros.inc
  17. include gr.inc
  18. include 3d.inc
  19. .list
  20. assume cs:_TEXT, ds:_DATA
  21. public _blob_vertices
  22. _DATA segment dword public USE32 'DATA'
  23. rcsid db "$Id: rod.asm 1.24 1996/01/08 14:59:13 matt Exp $"
  24. align 4
  25. bot_width fix ?
  26. top_width fix ?
  27. rod_points db 4*size g3s_point dup (?)
  28. delta_x fix ?
  29. delta_y fix ?
  30. edge_vec_x fix ?
  31. edge_vec_y fix ?
  32. vertbuf fix 4 dup (?,?)
  33. _blob_vertices fix 4 dup (?,?)
  34. bitmap_ptr dd ?
  35. delta_vec vms_vector <>
  36. rod_norm vms_vector <>
  37. temp_vec vms_vector <>
  38. top_pnt dd ?
  39. bot_pnt dd ?
  40. rod_point_list dd rod_points
  41. dd rod_points+(size g3s_point)
  42. dd rod_points+(size g3s_point)*2
  43. dd rod_points+(size g3s_point)*3
  44. ;values here are set to be half a pixel in from the edges so the texture
  45. ;mapper doesn't read past the bitmap
  46. uvl_list fix 200h,200h,0
  47. fix 0fe00h,200h,0
  48. fix 0fe00h,0fe00h,0
  49. fix 200h,0fe00h,0
  50. ;;uvl_list fix 0,0,0
  51. ;; fix 10000h,0,0
  52. ;; fix 10000h,10000h,0
  53. ;; fix 0,10000h,0
  54. _orientation_save dd ?
  55. _DATA ends
  56. _TEXT segment dword public USE32 'CODE'
  57. extn scale_bitmap_
  58. ;draws a polygon that's always facing the viewer
  59. ;takes esi,edi=bottom & top points (g3s_point *), eax,edx=3d width at bottom,top
  60. g3_draw_rod_flat: pushm eax,ebx,ecx,edx,esi,edi
  61. call calc_rod_corners
  62. or cl,cl ;check codes
  63. jnz no_draw
  64. mov ecx,4 ;4 corners
  65. lea esi,rod_point_list
  66. call g3_draw_poly
  67. popm eax,ebx,ecx,edx,esi,edi
  68. ret
  69. ;draws bitmap that's always facing the viewer
  70. ;takes esi,edi=bottom & top points (g3s_point *), eax,edx=3d width at bottom,top
  71. ;ebx = bitmap
  72. ;points must be rotated
  73. g3_draw_rod_tmap:
  74. pushm eax,ebx,ecx,edx,esi,edi
  75. mov bitmap_ptr,ebx
  76. ;save lighting values
  77. mov uvl_list+8,ecx
  78. mov uvl_list+20,ecx
  79. mov uvl_list+32,ecx
  80. mov uvl_list+44,ecx
  81. call calc_rod_corners
  82. or cl,cl ;check codes
  83. jnz no_draw
  84. mov ecx,4
  85. lea esi,rod_point_list
  86. lea ebx,uvl_list
  87. mov edx,bitmap_ptr
  88. call g3_draw_tmap
  89. jmp no_draw
  90. ;;@@;can use use scaler?
  91. ;;@@if not ALWAYS_USE_SCALER
  92. ;;@@ mov eax,vertbuf+4 ;point 0 y
  93. ;;@@ cmp eax,vertbuf+12 ;point 1 y
  94. ;;@@ jne must_roll
  95. ;;@@;use the scaler!
  96. ;;@@endif
  97. ;;@@ mov eax,bitmap_ptr
  98. ;;@@ lea edx,vertbuf
  99. ;;@@ call scale_bitmap_
  100. ;;@@ jmp no_draw
  101. ;;@@
  102. ;;@@;can't call the scaler
  103. ;;@@must_roll: mov eax,bitmap_ptr
  104. ;;@@ lea edx,vertbuf
  105. ;;@@ mov ebx,15 ;light value
  106. ;;@@ call rotate_bitmap_
  107. no_draw:
  108. popm eax,ebx,ecx,edx,esi,edi
  109. ret
  110. ;draws a bitmap with the specified 3d width & height
  111. ;takes esi=position, ebx=width, ecx=height, eax=bitmap
  112. ; edx=orientation: bits set mean: 0=flip in u, 1=flip in v, 2=exchange u, v
  113. ;modifies eax,esi,ecx
  114. ; bool g3_draw_bitmap(vms_vector *pos,fix width,fix height,grs_bitmap *bm);
  115. g3_draw_bitmap: pushm edx,edi
  116. mov _orientation_save, edx
  117. mov bitmap_ptr,eax ;save bitmap
  118. push ebx ;save width
  119. lea edi,rod_points ;get dest point
  120. call g3_rotate_point
  121. or bl,bl ;off screen?
  122. pop ebx ;restore width
  123. js blob_off_screen
  124. ;we should check if off screen based on rad
  125. mov esi,edi
  126. call g3_project_point
  127. test [esi].p3_flags,PF_OVERFLOW
  128. jnz blob_off_screen
  129. ;get 2d width & height
  130. mov eax,ebx ;get width
  131. imul Canv_w2
  132. blob_div0: divcheck [esi].z,blob_overflow_handler
  133. idiv [esi].z ;width3d*canv_w/z
  134. fixmul Matrix_scale.x ;*scale
  135. mov edi,eax ;save width
  136. mov eax,ecx ;get height
  137. imul Canv_h2
  138. blob_div1: divcheck [esi].z,blob_overflow_handler
  139. idiv [esi].z ;height3d*canv_h/z
  140. fixmul Matrix_scale.y ;*scale
  141. mov ecx,eax ;save height
  142. ;copy 2d points into buffer
  143. lea edx,_blob_vertices
  144. mov eax,[esi].p3_sx
  145. sub eax,edi ;- width
  146. mov [edx],eax ;p0.x
  147. lea eax,[eax+edi*2] ;+ 2*width
  148. mov 8[edx],eax ;p1.x
  149. mov 16[edx],eax ;p2.x
  150. mov eax,[esi].p3_sy
  151. sub eax,ecx ;- height
  152. mov 4[edx],eax ;p0.y
  153. mov 12[edx],eax ;p1.y
  154. lea eax,[eax+ecx*2] ;+ 2*height
  155. mov 20[edx],eax ;p2.y
  156. ;now draw
  157. mov eax,bitmap_ptr ;get bitmap ptr
  158. push ebx
  159. mov ebx, _orientation_save ; use normal orientation, no rotation, flip.
  160. call scale_bitmap_ ;vertbuf in edx
  161. pop ebx
  162. blob_off_screen: popm edx,edi
  163. ret
  164. blob_overflow_handler:
  165. ;debug_brk "blob overflow - get Matt"
  166. jmp blob_off_screen
  167. ;compute the corners of a rod. fills in vertbuf. ret codes in al.
  168. ;points in esi,edi, widths in eax,edx
  169. ;trashes piles of registers
  170. calc_rod_corners:
  171. mov bot_width,eax
  172. mov top_width,edx
  173. mov bot_pnt,esi
  174. mov top_pnt,edi
  175. ;compute vector from one point to other, do cross product with vector
  176. ;from eye to get perpendiclar
  177. lea eax,delta_vec
  178. call vm_vec_sub
  179. ;unscale for aspect
  180. mov eax,delta_vec.x
  181. fixdiv matrix_scale.x
  182. mov delta_vec.x,eax
  183. mov eax,delta_vec.y
  184. fixdiv matrix_scale.y
  185. mov delta_vec.y,eax
  186. ;calc perp vector
  187. ;do lots of normalizing to prevent overflowing. When this code works,
  188. ;it should be optimized
  189. lea esi,delta_vec
  190. call vm_vec_normalize
  191. vm_copy temp_vec,edi
  192. mov edi,esi
  193. lea esi,temp_vec
  194. call vm_vec_normalize
  195. xchg esi,edi
  196. lea eax,rod_norm
  197. call vm_vec_crossprod
  198. mov esi,eax
  199. call vm_vec_normalize
  200. ;scale for aspect
  201. mov eax,rod_norm.x
  202. fixmul matrix_scale.x
  203. mov rod_norm.x,eax
  204. mov eax,rod_norm.y
  205. fixmul matrix_scale.y
  206. mov rod_norm.y,eax
  207. ;now we have the usable edge. generate four points
  208. mov cl,0ffh ;codes and
  209. push ebp
  210. lea ebp,rod_points
  211. ;top points
  212. lea edi,temp_vec
  213. lea ebx,rod_norm
  214. mov ecx,top_width
  215. call vm_vec_copy_scale
  216. mov temp_vec.z,0
  217. mov eax,ebp
  218. mov esi,top_pnt ;temp vec in edi
  219. call vm_vec_add
  220. add eax,size g3s_point
  221. call vm_vec_sub
  222. lea ebp,size g3s_point[eax]
  223. ;bot points
  224. lea edi,temp_vec
  225. lea ebx,rod_norm
  226. mov ecx,bot_width
  227. call vm_vec_copy_scale
  228. mov temp_vec.z,0
  229. mov eax,ebp
  230. mov esi,bot_pnt ;temp vec in edi
  231. call vm_vec_sub
  232. add eax,size g3s_point
  233. call vm_vec_add
  234. pop ebp
  235. ;now code the four points
  236. mov cl,0ffh ;codes and
  237. lea eax,rod_points
  238. call code_point
  239. and cl,bl
  240. add eax,size g3s_point
  241. call code_point
  242. and cl,bl
  243. add eax,size g3s_point
  244. call code_point
  245. and cl,bl
  246. add eax,size g3s_point
  247. call code_point
  248. and cl,bl
  249. jnz new_new_off_screen
  250. push ecx ;save codes
  251. ;clear flags for new points (not projected)
  252. lea esi,rod_points
  253. mov [esi].p3_flags,0
  254. mov [esi+size g3s_point].p3_flags,0
  255. mov [esi+(size g3s_point)*2].p3_flags,0
  256. mov [esi+(size g3s_point)*3].p3_flags,0
  257. pop ecx ;restore codes
  258. ret
  259. new_new_off_screen:
  260. ret
  261. _TEXT ends
  262. end