OBJECTS.ASM 6.3 KB

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