INSTANCE.ASM 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. .list
  19. assume cs:_TEXT, ds:_DATA
  20. _DATA segment dword public USE32 'DATA'
  21. rcsid db "$Id: instance.asm 1.10 1996/01/08 14:59:11 matt Exp $"
  22. align 4
  23. MAX_INSTANCE_DEPTH equ 5
  24. inst_context_size equ ((size vms_matrix) + (size vms_vector))
  25. instance_stack db MAX_INSTANCE_DEPTH*inst_context_size dup (?)
  26. instance_depth dd 0
  27. tempv vms_vector <>
  28. tempm vms_matrix <>
  29. tempm2 vms_matrix <>
  30. instmat vms_matrix <>
  31. _DATA ends
  32. _TEXT segment dword public USE32 'CODE'
  33. ;start instancing, using angles (called vm_angles_2_matrix)
  34. ;takes esi=position, edi=angvec. trashes esi,edi
  35. ;if angles==NULL, don't modify matrix. This will be like doing an offset
  36. g3_start_instance_angles:
  37. or edi,edi
  38. jz g3_start_instance_matrix ;no new matrix
  39. push esi
  40. mov esi,edi
  41. lea edi,instmat
  42. call vm_angles_2_matrix
  43. pop esi
  44. ; fall g3_start_instance_matrix
  45. ;start instancing, using a matrix
  46. ;takes esi=position, edi=matrix. trashes esi,edi
  47. ;if matrix==NULL, don't modify matrix. This will be like doing an offset
  48. g3_start_instance_matrix:
  49. pushm eax,ebx,ecx
  50. push edi ;save matrix
  51. push esi ;save position
  52. ;save current context
  53. mov eax,instance_depth
  54. inc instance_depth
  55. cmp eax,MAX_INSTANCE_DEPTH
  56. jl depth_ok
  57. ;we've overflowed the instance stack. Return without doing anything
  58. debug_brk 'Already at or over max depth'
  59. pop eax
  60. pop eax ;fix stack
  61. jmp no_inst_matrix
  62. depth_ok:
  63. imul eax,inst_context_size
  64. lea edi,instance_stack[eax]
  65. lea esi,View_position
  66. mov ecx,3
  67. rep movsd
  68. lea esi,View_matrix
  69. mov ecx,9
  70. rep movsd
  71. ;step 1: subtract object position from view position
  72. pop esi ;object position
  73. lea edi,View_position
  74. call vm_vec_sub2
  75. ;step 2: rotate view vector through object matrix
  76. pop edi ;get object matrix
  77. or edi,edi ;null matrix?
  78. jz no_inst_matrix
  79. lea esi,View_position
  80. lea eax,tempv
  81. call vm_vec_rotate
  82. vm_copy esi,eax,ebx
  83. ;step 3: rotate object matrix through view_matrix (vm = ob * vm)
  84. mov esi,edi ;object matrix
  85. lea edi,tempm2
  86. call vm_copy_transpose_matrix
  87. lea esi,tempm2
  88. lea edi,View_matrix
  89. lea eax,tempm
  90. call vm_matrix_x_matrix
  91. mov esi,eax
  92. mov ecx,9
  93. rep movsd
  94. no_inst_matrix:
  95. ;now we are done!
  96. popm eax,ebx,ecx
  97. ret
  98. ;we are done instancing
  99. g3_done_instance: pushm eax,ecx,esi,edi
  100. dec instance_depth
  101. break_if s,'Instance stack underflow!'
  102. mov eax,instance_depth
  103. cmp eax,MAX_INSTANCE_DEPTH ;over the limit?
  104. jae skip_restore ;..yes, so don't do anything
  105. imul eax,inst_context_size
  106. lea esi,instance_stack[eax]
  107. lea edi,View_position
  108. mov ecx,3
  109. rep movsd
  110. lea edi,View_matrix
  111. mov ecx,9
  112. rep movsd
  113. skip_restore: popm eax,ecx,esi,edi
  114. ret
  115. _TEXT ends
  116. end