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