home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1998 #6 / amigaacscoverdisc1998-061998.iso / games / descent / source / 3d / points.asm < prev    next >
Assembly Source File  |  1998-06-08  |  7KB  |  345 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/points.asm $
  13. ; $Revision: 1.13 $
  14. ; $Author: matt $
  15. ; $Date: 1995/02/09 22:00:05 $
  16. ;
  17. ; Source for point definition, rotation, etc.
  18. ;
  19. ; $Log: points.asm $
  20. ; Revision 1.13  1995/02/09  22:00:05  matt
  21. ; Removed dependence on divide overflow handler; we now check for overflow
  22. ; before dividing.  This fixed problems on some TI chips.
  23. ; Revision 1.12  1994/11/11  19:22:06  matt
  24. ; Added new function, g3_calc_point_depth()
  25. ; Revision 1.11  1994/07/25  00:00:04  matt
  26. ; Made 3d no longer deal with point numbers, but only with pointers.
  27. ; Revision 1.10  1994/07/21  09:53:32  matt
  28. ; Made g3_point_2_vec() take 2d coords relative to upper left, not center
  29. ; Revision 1.9  1994/02/10  18:00:41  matt
  30. ; Changed 'if DEBUG_ON' to 'ifndef NDEBUG'
  31. ; Revision 1.8  1994/02/09  11:48:55  matt
  32. ; Added delta rotation functions
  33. ; Revision 1.7  1994/01/13  15:39:39  mike
  34. ; Change usage of Frame_count to _Frame_count.
  35. ; Revision 1.6  1993/12/21  20:35:35  matt
  36. ; Fixed bug that left register pushed if point was already projected in
  37. ; g3_project_list()
  38. ; Revision 1.5  1993/12/21  11:45:37  matt
  39. ; Fixed negative y bug in g3_point_2_vec()
  40. ; Revision 1.4  1993/12/20  20:21:51  matt
  41. ; Added g3_point_2_vec()
  42. ; Revision 1.3  1993/11/21  20:08:41  matt
  43. ; Added function g3_rotate_point()
  44. ; Revision 1.2  1993/11/04  18:49:17  matt
  45. ; Added system to only rotate points once per frame
  46. ; Revision 1.1  1993/10/29  22:20:27  matt
  47. ; Initial revision
  48. ;
  49. ;
  50.  
  51. .386
  52.     option    oldstructs
  53.  
  54.     .nolist
  55.     include    types.inc
  56.     include    psmacros.inc
  57.     include    gr.inc
  58.     include    3d.inc
  59.     .list
  60.  
  61.     assume    cs:_TEXT, ds:_DATA
  62.  
  63. _DATA    segment    dword public USE32 'DATA'
  64.  
  65. rcsid    db    "$Id: points.asm 1.13 1995/02/09 22:00:05 matt Exp $"
  66.     align    4
  67.  
  68. tempv    vms_vector <>
  69.  
  70. tempm    vms_matrix <>
  71.  
  72. _DATA    ends
  73.  
  74.  
  75.  
  76. _TEXT    segment    dword public USE32 'CODE'
  77.  
  78. ;finds clipping codes for a point. takes eax=point. fills in p3_codes,
  79. ;and returns codes in bl.
  80. g3_code_point:
  81. code_point:    push    ecx
  82.  
  83.     xor    bl,bl    ;clear codes
  84.     mov    ecx,[eax].z    ;get z
  85.     cmp    [eax].x,ecx    ;x>z?
  86.     jle    not_right
  87.     or    bl,CC_OFF_RIGHT
  88. not_right:    cmp    [eax].y,ecx    ;y>z?
  89.     jle    not_top
  90.     or    bl,CC_OFF_TOP
  91. not_top:    neg    ecx
  92.     js    not_behind
  93.     or    bl,CC_BEHIND
  94. not_behind:    cmp    [eax].x,ecx    ;x<-z?
  95.     jge    not_left
  96.     or    bl,CC_OFF_LEFT
  97. not_left:    cmp    [eax].y,ecx    ;y<-z
  98.     jge    not_bot
  99.     or    bl,CC_OFF_BOT
  100. not_bot:    pop    ecx
  101.     mov    [eax].p3_codes,bl
  102.     ret
  103.     
  104.  
  105. ;rotate a point. don't look at rotated flags
  106. ;takes esi=dest point, esi=src vector
  107. ;returns bl=codes
  108. g3_rotate_point:    pushm    eax,ecx,esi,edi
  109.  
  110.     push    edi    ;save dest
  111.  
  112.     lea    eax,tempv
  113.     lea    edi,View_position
  114.     call    vm_vec_sub
  115.     mov    esi,eax
  116.  
  117.     pop    eax
  118.     
  119.     lea    edi,View_matrix
  120.     call    vm_vec_rotate
  121.     mov    [eax].p3_flags,0    ;not projected
  122.  
  123.     ;;mov    bx,_Frame_count    ;curren frame
  124.     ;;mov    [eax].p3_frame,bx
  125.  
  126.     call    code_point
  127.  
  128.     popm    eax,ecx,esi,edi
  129.     ret
  130.  
  131.  
  132. ;projects a point. takes esi=point  
  133. g3_project_point:
  134.     ;;ifndef    NDEBUG
  135.     ;; push    eax
  136.     ;; mov    ax,[esi].p3_frame
  137.     ;; cmp    ax,_Frame_count
  138.     ;; break_if    ne,'Trying to project unrotated point!'
  139.     ;; pop    eax
  140.     ;;endif
  141.  
  142.     test    [esi].p3_flags,PF_PROJECTED
  143.     jnz    no_project
  144.     test    [esi].p3_codes,CC_BEHIND
  145.     jnz    no_project
  146.  
  147.     pushm    eax,edx
  148.  
  149.     mov    eax,[esi].x
  150.     imul    Canv_w2
  151. proj_div0:    divcheck    [esi].z,div_overflow_handler
  152.     idiv    [esi].z
  153.     add    eax,Canv_w2
  154.     mov    [esi].p3_sx,eax
  155.  
  156.     mov    eax,[esi].y
  157.     imul    Canv_h2
  158. proj_div1:    divcheck    [esi].z,div_overflow_handler
  159.     idiv    [esi].z
  160.     neg    eax
  161.     add    eax,Canv_h2
  162.     mov    [esi].p3_sy,eax
  163.  
  164.     or    [esi].p3_flags,PF_PROJECTED    ;projected
  165.  
  166.     popm    eax,edx
  167.  
  168. no_project:    ret
  169.  
  170. div_overflow_handler:
  171.     ;int    3
  172.     mov    [esi].p3_flags,PF_OVERFLOW
  173.     popm    eax,edx
  174.     ret
  175.  
  176. ;from a 2d point on the screen, compute the vector in 3-space through that point
  177. ;takes eax,ebx = 2d point, esi=vector
  178. ;the 2d point is relative to the center of the canvas
  179. g3_point_2_vec:    pushm    ecx,edx,esi,edi
  180.  
  181.     push    esi
  182.  
  183.     lea    esi,tempv
  184.  
  185.     ;;mov    edx,eax
  186.     ;;xor    eax,eax
  187.     ;;idiv    Canv_w2
  188.     sal    eax,16
  189.     sub    eax,Canv_w2
  190.     fixdiv    Canv_w2
  191.     imul    Matrix_scale.z
  192.     idiv    Matrix_scale.x
  193.     mov    [esi].x,eax
  194.  
  195.     ;;mov    edx,ebx
  196.     ;;xor    eax,eax
  197.     ;;sub    Canv_h2
  198.     ;;idiv    Canv_h2
  199.     mov    eax,ebx
  200.     sal    eax,16
  201.     sub    eax,Canv_h2
  202.     fixdiv    Canv_h2
  203.     imul    Matrix_scale.z
  204.     idiv    Matrix_scale.y
  205.     neg    eax
  206.     mov    [esi].y,eax
  207.  
  208.     mov    [esi].z,f1_0
  209.  
  210.     call    vm_vec_normalize    ;get normalized rotated vec
  211.  
  212.     lea    edi,tempm
  213.     lea    esi,Unscaled_matrix
  214.     call    vm_copy_transpose_matrix
  215.  
  216.     pop    eax    ;get dest
  217.     lea    esi,tempv    ;edi=matrix
  218.     call    vm_vec_rotate
  219.  
  220.     popm    ecx,edx,esi,edi
  221.  
  222.     ret
  223.  
  224. ;rotate a delta y vector. takes edi=dest vec, ebx=delta y
  225. g3_rotate_delta_y:    pushm    eax,edx
  226.     mov    eax,View_matrix.m4
  227.     fixmul    ebx
  228.     mov    [edi].x,eax
  229.     mov    eax,View_matrix.m5
  230.     fixmul    ebx
  231.     mov    [edi].y,eax
  232.     mov    eax,View_matrix.m6
  233.     fixmul    ebx
  234.     mov    [edi].z,eax
  235.     popm    eax,edx
  236.     ret
  237.  
  238.  
  239. ;rotate a delta x vector. takes edi=dest vec, ebx=delta x
  240. g3_rotate_delta_x:    pushm    eax,edx
  241.     mov    eax,View_matrix.m1
  242.     fixmul    ebx
  243.     mov    [edi].x,eax
  244.     mov    eax,View_matrix.m2
  245.     fixmul    ebx
  246.     mov    [edi].y,eax
  247.     mov    eax,View_matrix.m3
  248.     fixmul    ebx
  249.     mov    [edi].z,eax
  250.     popm    eax,edx
  251.     ret
  252.  
  253.  
  254. ;rotate a delta x vector. takes edi=dest vec, ebx=delta z
  255. g3_rotate_delta_z:    pushm    eax,edx
  256.     mov    eax,View_matrix.m7
  257.     fixmul    ebx
  258.     mov    [edi].x,eax
  259.     mov    eax,View_matrix.m8
  260.     fixmul    ebx
  261.     mov    [edi].y,eax
  262.     mov    eax,View_matrix.m9
  263.     fixmul    ebx
  264.     mov    [edi].z,eax
  265.     popm    eax,edx
  266.     ret
  267.  
  268.  
  269. ;rotate a delta vector. takes edi=dest vec, esi=src vec
  270. g3_rotate_delta_vec:
  271.     pushm    eax,edi
  272.     mov    eax,edi
  273.     lea    edi,View_matrix
  274.     call    vm_vec_rotate
  275.     popm    eax,edi
  276.     ret
  277.  
  278. ;adds a delta vector to a point. takes eax=dest point, esi=src pnt, edi=delta vec
  279. ;returns bl=codes.
  280. g3_add_delta_vec:    ;;ifndef    NDEBUG
  281.     ;; push    eax
  282.     ;; mov    ax,[esi].p3_frame
  283.     ;; cmp    ax,_Frame_count
  284.     ;; break_if    ne,'Trying to add delta to unrotated point!'
  285.     ;; pop    eax
  286.     ;;endif
  287.  
  288.     call    vm_vec_add
  289.  
  290.     ;;mov    bx,_Frame_count
  291.     ;;mov    [eax].p3_frame,bx
  292.     mov    [eax].p3_flags,0    ;not projected
  293.  
  294.     call    g3_code_point
  295.  
  296.     ret
  297.  
  298. ;calculate the depth of a point - returns the z coord of the rotated point
  299. ;takes esi=vec, returns eax=depth
  300. g3_calc_point_depth:
  301.     pushm    edx,ebx,ecx
  302.  
  303.     mov    eax,[esi].x
  304.     sub    eax,View_position.x
  305.     imul    View_matrix.fvec.x
  306.     mov    ebx,eax
  307.     mov    ecx,edx
  308.  
  309.     mov    eax,[esi].y
  310.     sub    eax,View_position.y
  311.     imul    View_matrix.fvec.y
  312.     add    ebx,eax
  313.     adc    ecx,edx
  314.  
  315.     mov    eax,[esi].z
  316.     sub    eax,View_position.z
  317.     imul    View_matrix.fvec.z
  318.     add    eax,ebx
  319.     adc    edx,ecx
  320.  
  321.     shrd    eax,edx,16
  322.  
  323.     popm    edx,ebx,ecx
  324.  
  325.     ret
  326.         
  327.  
  328.  
  329. _TEXT    ends
  330.  
  331.     end
  332.