OBJECTS.ASM 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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 vecmat.inc
  17. include 3d.inc
  18. include fix.inc
  19. .list
  20. assume cs:_TEXT, ds:_DATA
  21. _DATA segment dword public USE32 'DATA'
  22. rcsid db "$Id: objects.asm 1.6 1996/01/08 14:59:08 matt Exp $"
  23. align 4
  24. obj_pos dd ? ;ptr to pos vector
  25. obj_type dd ?
  26. obj_matrix dd ?
  27. new_obj_matrix vms_matrix <>
  28. obj_vec_g vms_vector <> ;object->eye, global frame
  29. obj_vec_obj vms_vector <> ;in objects frame of ref.
  30. vec_matrix_g vms_matrix <>
  31. ;3d points for corners of bitmap
  32. up_left_v vms_vector <>
  33. up_right_v vms_vector <>
  34. down_right_v vms_vector <>
  35. up_left_p g3s_point <>
  36. up_right_p g3s_point <>
  37. down_right_p g3s_point <>
  38. bitmap_points dd up_left_p,up_right_p,down_right_p
  39. bitmap_number dd ?
  40. up_vec vms_vector <>
  41. right_vec vms_vector <>
  42. public draw_bitmap_lines
  43. draw_bitmap_lines dd 0
  44. extb _Vector_to_viewnum,_up_vecs
  45. extb _Vector_to_viewnum2,_up_vecs2
  46. _DATA ends
  47. _TEXT segment dword public USE32 'CODE'
  48. extn render_object_
  49. ;draws a bitmap object. takes esi=pos, edi=matrix, eax=size, ebx=obj type
  50. g3_draw_object: pushm eax,ebx,ecx,edx,esi,edi
  51. mov obj_type,ebx ;save objnum
  52. mov obj_pos,esi ;save pos
  53. mov obj_matrix,edi ;save matrix
  54. push eax ;save size
  55. ;get vector from object to eye
  56. lea eax,obj_vec_g ;dest
  57. mov edi,esi ;obj position
  58. lea esi,View_position ;eye positon
  59. call vm_vec_sub
  60. ;normalize vector
  61. lea esi,obj_vec_g
  62. call vm_vec_normalize
  63. ;rotate into object's frame of reference
  64. lea eax,obj_vec_obj
  65. lea esi,obj_vec_g
  66. mov edi,obj_matrix
  67. call vm_vec_rotate
  68. ;select the right bitmap by looking in a table.
  69. ;get five bits for each of x,y,z, make a 15-bit index, and look in table
  70. mov eax,obj_vec_obj.x
  71. add eax,f1_0 ;make in range 0..2
  72. break_if s,'bad value in vector'
  73. cmp eax,f2_0
  74. jl not_max_x
  75. dec eax ;make less than 1
  76. not_max_x: sar eax,2
  77. and eax,111110000000000b
  78. mov ebx,eax
  79. mov eax,obj_vec_obj.y
  80. add eax,f1_0 ;make in range 0..2
  81. break_if s,'bad value in vector'
  82. cmp eax,f2_0
  83. jl not_max_y
  84. dec eax ;make less than 1
  85. not_max_y: sar eax,2+5
  86. and eax,1111100000b
  87. or ebx,eax
  88. mov eax,obj_vec_obj.z
  89. add eax,f1_0 ;make in range 0..2
  90. break_if s,'bad value in vector'
  91. cmp eax,f2_0
  92. jl not_max_z
  93. dec eax ;make less than 1
  94. not_max_z: sar eax,2+10
  95. and eax,11111b
  96. or ebx,eax
  97. movzx eax,_Vector_to_viewnum[ebx]
  98. cmp obj_type,1 ;other object?
  99. jne got_viewnum
  100. movzx eax,_Vector_to_viewnum2[ebx]
  101. got_viewnum:
  102. mov bitmap_number,eax
  103. ;; debug "bm=%d\n",eax
  104. ;build matrix with vec from obj to eye & bitmap's up vector
  105. mov eax,bitmap_number
  106. sal eax,1 ;*2
  107. add eax,bitmap_number ;*3
  108. sal eax,2 ;*12
  109. lea eax,_up_vecs[eax]
  110. cmp obj_type,1 ;other object/
  111. jne got_up_vec
  112. add eax,offset _up_vecs2
  113. sub eax,offset _up_vecs
  114. got_up_vec:
  115. lea edi,vec_matrix_g
  116. lea esi,obj_vec_obj ;obj_vec_g
  117. call vm_vector_2_matrix
  118. ;rotate object's matrix through new matrix
  119. lea eax,new_obj_matrix
  120. mov esi,obj_matrix
  121. lea edi,vec_matrix_g
  122. call vm_matrix_x_matrix
  123. ;now, up and right describe edges
  124. vm_copy up_vec,new_obj_matrix.uvec
  125. vm_copy right_vec,new_obj_matrix.rvec
  126. ;calculate corner points of bitmap
  127. pop ecx ;get size
  128. sar ecx,1
  129. lea ebx,up_vec
  130. call vm_vec_scale
  131. lea ebx,right_vec
  132. call vm_vec_scale
  133. ;upper left
  134. lea eax,up_left_v
  135. mov esi,obj_pos
  136. lea edi,right_vec
  137. call vm_vec_add
  138. mov edi,eax
  139. lea esi,up_vec
  140. call vm_vec_add2
  141. ;upper right
  142. lea eax,up_right_v
  143. lea esi,up_left_v
  144. lea edi,right_vec
  145. call vm_vec_sub
  146. mov esi,edi ;rvec
  147. mov edi,eax ;dest=up_right
  148. call vm_vec_sub2
  149. ;lower right
  150. lea eax,down_right_v
  151. lea esi,up_right_v
  152. lea edi,up_vec
  153. call vm_vec_sub
  154. mov esi,edi ;uvec
  155. mov edi,eax ;dest=down_right
  156. call vm_vec_sub2
  157. ;now take three points, rotate & project
  158. lea esi,up_left_v
  159. lea edi,up_left_p
  160. call g3_rotate_point
  161. or bl,bl
  162. js obj_off_screen
  163. lea esi,up_right_v
  164. lea edi,up_right_p
  165. call g3_rotate_point
  166. or bl,bl
  167. js obj_off_screen
  168. lea esi,down_right_v
  169. lea edi,down_right_p
  170. call g3_rotate_point
  171. or bl,bl
  172. js obj_off_screen
  173. ;set all z values same before project
  174. mov eax,up_left_p.z
  175. mov up_right_p.z,eax
  176. mov down_right_p.z,eax
  177. lea esi,up_left_p
  178. call g3_project_point
  179. lea esi,up_right_p
  180. call g3_project_point
  181. lea esi,down_right_p
  182. call g3_project_point
  183. mov eax,obj_type
  184. mov edx,bitmap_number
  185. lea ebx,bitmap_points
  186. call render_object_
  187. test draw_bitmap_lines,-1
  188. jz skip_lines
  189. extn gr_setcolor_,gr_line_
  190. mov eax,15
  191. call gr_setcolor_
  192. mov eax,up_left_p.p3_sx
  193. mov edx,up_left_p.p3_sy
  194. mov ebx,up_right_p.p3_sx
  195. mov ecx,up_right_p.p3_sy
  196. call gr_line_
  197. mov ebx,up_right_p.p3_sx
  198. mov ecx,up_right_p.p3_sy
  199. mov eax,down_right_p.p3_sx
  200. mov edx,down_right_p.p3_sy
  201. call gr_line_
  202. skip_lines:
  203. obj_off_screen:
  204. popm eax,ebx,ecx,edx,esi,edi
  205. ret
  206. _TEXT ends
  207. end