home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1998 #6 / amigaacscoverdisc1998-061998.iso / games / descent / source / 3d / instance.asm < prev    next >
Assembly Source File  |  1998-06-08  |  4KB  |  183 lines

  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/instance.asm $
  13. ; $Revision: 1.8 $
  14. ; $Author: matt $
  15. ; $Date: 1994/07/29 18:16:16 $
  16. ; Code for handling instanced 3d objects
  17. ; $Log: instance.asm $
  18. ; Revision 1.8  1994/07/29  18:16:16  matt
  19. ; Added instance by angles, and corrected parms for g3_init()
  20. ; Revision 1.7  1994/07/25  00:00:02  matt
  21. ; Made 3d no longer deal with point numbers, but only with pointers.
  22. ; Revision 1.6  1994/06/16  17:52:31  matt
  23. ; If NULL passed for instance matrix, don't rotate (just do offset)
  24. ; Revision 1.5  1994/06/01  18:10:22  matt
  25. ; Fixed register trash in g3_start_instance_matrix()
  26. ; Revision 1.4  1994/03/25  17:09:20  matt
  27. ; Increase MAX_INSTANCE_DEPTH to 5 (from 3)
  28. ; Revision 1.3  1994/02/10  18:00:43  matt
  29. ; Changed 'if DEBUG_ON' to 'ifndef NDEBUG'
  30. ; Revision 1.2  1994/01/24  14:08:45  matt
  31. ; Added code to this previously dull file
  32. ; Revision 1.1  1994/01/23  15:22:52  matt
  33. ; Initial revision
  34.  
  35.  
  36.  
  37. .386
  38.     option    oldstructs
  39.  
  40.     .nolist
  41.     include    types.inc
  42.     include    psmacros.inc
  43.     include    vecmat.inc
  44.     include    3d.inc
  45.     .list
  46.  
  47.     assume    cs:_TEXT, ds:_DATA
  48.  
  49. _DATA    segment    dword public USE32 'DATA'
  50.  
  51. rcsid    db    "$Id: instance.asm 1.8 1994/07/29 18:16:16 matt Exp $"
  52.     align    4
  53.  
  54. MAX_INSTANCE_DEPTH    equ    5
  55.  
  56. inst_context_size    equ    ((size vms_matrix) + (size vms_vector))
  57.  
  58. instance_stack    db    MAX_INSTANCE_DEPTH*inst_context_size dup (?)
  59.  
  60. instance_depth    dd    0
  61.  
  62. tempv    vms_vector <>
  63. tempm    vms_matrix <>
  64. tempm2    vms_matrix <>
  65.  
  66. instmat    vms_matrix <>
  67.  
  68. _DATA    ends
  69.  
  70.  
  71. _TEXT    segment    dword public USE32 'CODE'
  72.  
  73. ;start instancing, using angles (called vm_angles_2_matrix)
  74. ;takes esi=position, edi=angvec. trashes esi,edi
  75. ;if angles==NULL, don't modify matrix.  This will be like doing an offset
  76. g3_start_instance_angles:
  77.     or    edi,edi
  78.     jz    g3_start_instance_matrix    ;no new matrix
  79.  
  80.     push    esi
  81.     mov    esi,edi
  82.     lea    edi,instmat
  83.     call    vm_angles_2_matrix
  84.     pop    esi
  85.  
  86. ;    fall    g3_start_instance_matrix
  87.  
  88. ;start instancing, using a matrix
  89. ;takes esi=position, edi=matrix. trashes esi,edi
  90. ;if matrix==NULL, don't modify matrix.  This will be like doing an offset   
  91. g3_start_instance_matrix:
  92.     pushm    eax,ebx,ecx
  93.  
  94.     push    edi    ;save matrix
  95.     push    esi    ;save position
  96.  
  97. ;save current context
  98.     mov    eax,instance_depth
  99.     inc    instance_depth
  100.  
  101.     ifndef    NDEBUG
  102.      cmp    eax,MAX_INSTANCE_DEPTH
  103.      break_if    e,'Already at max depth'
  104.     endif
  105.  
  106.     imul    eax,inst_context_size
  107.     lea    edi,instance_stack[eax]
  108.  
  109.     lea    esi,View_position
  110.     mov    ecx,3
  111.     rep    movsd
  112.     lea    esi,View_matrix
  113.     mov    ecx,9
  114.     rep    movsd
  115.  
  116.  
  117. ;step 1: subtract object position from view position
  118.     pop    esi    ;object position
  119.     lea    edi,View_position
  120.     call    vm_vec_sub2
  121.  
  122. ;step 2: rotate view vector through object matrix
  123.  
  124.     pop    edi    ;get object matrix
  125.     or    edi,edi    ;null matrix?
  126.     jz    no_inst_matrix
  127.     lea    esi,View_position
  128.     lea    eax,tempv
  129.     call    vm_vec_rotate
  130.     vm_copy    esi,eax,ebx
  131.  
  132. ;step 3: rotate object matrix through view_matrix (vm = ob * vm)
  133.  
  134.     mov    esi,edi    ;object matrix
  135.  lea edi,tempm2
  136.  call vm_copy_transpose_matrix
  137.  lea esi,tempm2
  138.     lea    edi,View_matrix
  139.     lea    eax,tempm
  140.     call    vm_matrix_x_matrix
  141.     mov    esi,eax
  142.     mov    ecx,9
  143.     rep    movsd
  144.  
  145. no_inst_matrix:
  146.  
  147. ;now we are done! 
  148.     popm    eax,ebx,ecx
  149.     ret
  150.  
  151. ;we are done instancing
  152. g3_done_instance:    pushm    eax,ecx,esi,edi
  153.     dec    instance_depth
  154.     break_if    s,'Instance stack underflow!'
  155.     mov    eax,instance_depth
  156.     imul    eax,inst_context_size
  157.     lea    esi,instance_stack[eax]
  158.     lea    edi,View_position
  159.     mov    ecx,3
  160.     rep    movsd
  161.     lea    edi,View_matrix
  162.     mov    ecx,9
  163.     rep    movsd
  164.     popm    eax,ecx,esi,edi
  165.     ret
  166.  
  167.  
  168. _TEXT    ends
  169.  
  170.     end
  171.  
  172.