home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1998 #6 / amigaacscoverdisc1998-061998.iso / games / descent / source / lib / 3d.inc < prev    next >
Text File  |  1998-06-08  |  9KB  |  283 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/3d.inc $
  13. ; $Revision: 1.30 $
  14. ; $Author: matt $
  15. ; $Date: 1995/02/09 22:00:50 $
  16. ;
  17. ; Header file for 3d library
  18. ;
  19. ; $Log: 3d.inc $
  20. ; Revision 1.30  1995/02/09  22:00:50  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.29  1994/11/11  19:22:15  matt
  24. ; Added new function, g3_calc_point_depth()
  25. ; Revision 1.28  1994/09/09  14:24:13  matt
  26. ; Added support for glowing textures, to add engine glow to Descent.
  27. ; Revision 1.27  1994/09/01  10:42:26  matt
  28. ; Blob routine, renamed g3_draw_bitmap(), now takes seperate 3d width & height.
  29. ; Revision 1.26  1994/07/29  18:15:53  matt
  30. ; Added instance by angles, and corrected parms for g3_init()
  31. ; Revision 1.25  1994/07/25  00:00:01  matt
  32. ; Made 3d no longer deal with point numbers, but only with pointers.
  33. ; Revision 1.24  1994/07/22  17:57:57  matt
  34. ; Changed the name of the rod functions, and took out some debugging code
  35. ; Revision 1.23  1994/06/07  16:49:35  matt
  36. ; Made interpreter take lighting value as parm, rather than in global var
  37. ; Revision 1.22  1994/05/31  18:35:19  matt
  38. ; Added light value to g3_draw_facing_bitmap()
  39. ; Revision 1.21  1994/05/30  22:48:15  matt
  40. ; Added support for morph effect
  41. ; Revision 1.20  1994/05/30  11:36:25  matt
  42. ; Added g3_set_special_render() to allow a user to specify functions to
  43. ; call for 2d draws.
  44. ; Revision 1.19  1994/05/19  21:46:30  matt
  45. ; Moved texture lighting out of 3d and into the game
  46. ; Revision 1.18  1994/04/19  18:26:41  matt
  47. ; Added g3_draw_sphere() function.
  48. ; Revision 1.17  1994/03/25  18:22:39  matt
  49. ; g3_draw_polygon_model() now takes ptr to list of angles
  50. ; Revision 1.16  1994/03/15  21:23:14  matt
  51. ; Added interpreter functions
  52. ; Revision 1.15  1994/02/15  17:37:35  matt
  53. ; New function, g3_draw_blob()
  54. ; Revision 1.14  1994/02/10  18:00:10  matt
  55. ; Changed 'if DEBUG_ON' to 'ifndef NDEBUG'
  56. ; Revision 1.13  1994/02/09  11:47:34  matt
  57. ; Added rod & delta point functions
  58. ; Revision 1.12  1994/01/26  12:38:20  matt
  59. ; Added function g3_compute_lighting_value()
  60. ; Revision 1.11  1994/01/24  14:08:24  matt
  61. ; Added instancing functions
  62. ; Revision 1.10  1994/01/22  18:22:07  matt
  63. ; New lighting stuff now done in 3d; g3_draw_tmap() takes lighting parm
  64. ; Revision 1.9  1994/01/20  17:21:46  matt
  65. ; New function g3_compute_sky_polygon()
  66. ; Revision 1.8  1994/01/14  17:21:02  matt
  67. ; Added new function g3_draw_horizon()
  68. ; Revision 1.6  1993/12/20  20:21:43  matt
  69. ; Added g3_point_2_vec()
  70. ; Revision 1.5  1993/12/05  23:47:13  matt
  71. ; Added function g3_draw_line_ptrs()
  72. ; Revision 1.4  1993/11/21  20:08:16  matt
  73. ; Added functions g3_rotate_point & g3_draw_object
  74. ; Revision 1.3  1993/11/04  18:49:42  matt
  75. ; Made g3_init() have functionality of g3_set_points(), which I killed
  76. ; Revision 1.2  1993/11/04  12:38:29  mike
  77. ; Add PF_LVS, flag for lighting value
  78. ; Revision 1.1  1993/10/29  22:20:27  matt
  79. ; Initial revision
  80. ;
  81. ;
  82.  
  83. ifndef _3D_INC
  84. _3D_INC equ 1
  85.  
  86. MAX_POINTS_IN_POLY = 100
  87.  
  88.     include    fix.inc
  89.     include    vecmat.inc
  90.  
  91. ;Structures
  92.  
  93. ;Stucture to store clipping codes in a word
  94. g3s_codes    STRUCT 2t
  95. cc_or    ubyte    ?    ;or is low byte
  96. cc_and    ubyte    ?    ;and is high byte
  97. g3s_codes    ENDS
  98.  
  99. ;Used to store rotated points for mines.  Has frame count to indictate
  100. ;if rotated, and flag to indicate if projected.
  101. g3s_point    struct
  102.     union
  103. p3_vec     vms_vector <>
  104.      struct
  105. x      fix    ?
  106. y      fix    ?
  107. z      fix    ?
  108.      ends
  109. xyz     fix    3t DUP (?)
  110.     ends    ;end of union
  111. p3_u    fix    ?    ;u & v for this point
  112. p3_v    fix    ?
  113. p3_l    fix    ?
  114. p3_sx    fix    ?    ;screen x & y
  115. p3_sy    fix    ?
  116. p3_codes    db    ?    ;clipping codes
  117. p3_flags    db    ?    ;projected?
  118. p3_pad    dw    ?    ;keep longword aligned
  119. g3s_point    ends
  120.  
  121. ;Flags
  122.  
  123. ;for g3_flags field of g3s_point
  124. PF_PROJECTED    equ    1    ;has been projected
  125. PF_OVERFLOW    equ    2    ;can't project
  126. PF_TEMP_POINT    equ    4    ;created during clip
  127. PF_UVS    equ    8    ;has uv values set
  128. PF_LVS    equ    16    ;has lighting values set
  129.  
  130. ;for clipping codes
  131. CC_OFF_LEFT    equ    1
  132. CC_OFF_RIGHT    equ    2
  133. CC_OFF_BOT    equ    4
  134. CC_OFF_TOP    equ    8
  135. CC_BEHIND    equ    80h
  136.  
  137. _DATA    segment    dword public USE32 'DATA'
  138.  
  139. ;Global variables
  140.  
  141.     extdef    vms_vector,View_position,Matrix_scale,Window_scale
  142.     extdef    vms_matrix,View_matrix,Unscaled_matrix
  143.     extf    View_zoom
  144.  
  145.     extd    Vbuf0,Vbuf1,Num_points
  146.  
  147.     extd    Canvas_width,Canvas_height    ;the actual width & height
  148.     extf    Canv_w2,Canv_h2            ;fixed-point width,height/2
  149.  
  150.     extf    Vertex_list
  151.  
  152.     ;;extw    _Frame_count
  153.  
  154. _DATA    ends
  155.  
  156. _TEXT    segment    dword public USE32 'CODE'
  157.  
  158. ;Routines
  159.  
  160. ;from setup.asm
  161.     extn    g3_init    ;eax=point list, edx=vec list
  162.     extn    g3_close    ;takes nothing, ret nothing
  163.     extn    g3_start_frame    ;takes nothing, ret nothing
  164.     extn    g3_end_frame    ;takes nothing, ret nothing
  165.  
  166. ;from matrix.asm
  167.     extn    g3_set_view_angles    ;esi=angvec,esi=pos,eax=zoom
  168.     extn    g3_set_view_matrix    ;esi=matrix,edi=pos,eax=zoom
  169.  
  170. ;from points.asm
  171.     ;;extn    g3_set_points    ;eax=point list, edx=vec list
  172.     extn    g3_rotate_point    ;edi=dest point, esi=src vec
  173.     extn    g3_project_point    ;esi=point
  174.     extn    g3_point_2_vec    ;esi=vec, eax,ebx = 2d point (shorts)
  175.     extn    g3_code_point    ;eax=point, fill in code, ret bl=code
  176.  
  177.     extn    g3_rotate_delta_x    ;edi=dest vec, ebx=delta
  178.     extn    g3_rotate_delta_y    ;edi=dest vec, ebx=delta
  179.     extn    g3_rotate_delta_z    ;edi=dest vec, ebx=delta
  180.     extn    g3_rotate_delta_vec    ;edi=dest vec, esi=delta vec
  181.     extn    g3_add_delta_vec    ;eax=dest pnt, esi=src pnt, edi=delta vec. ret bl=codes
  182.  
  183.     extn    g3_calc_point_depth    ;esi=point, ret eax=depth
  184.  
  185.     extn    proj_div0,proj_div1,div_overflow_handler,code_point
  186.     extn    blob_div0,blob_div1,blob_overflow_handler
  187.     extn    sphere_proj_div,sphere_div_overflow_handler
  188.  
  189. ;from draw.asm
  190.     extn    g3_draw_line    ;esi,edi=points
  191.     extn    g3_draw_poly    ;ecx=cnt, esi=point nums, al=ret: 1 off screen, 0 drew
  192.     extn    g3_check_and_draw_poly    ;ecx=cnt, esi=point nums, edi=normal, al=ret: -1 not facing, 1 off screen, 0 drew
  193.     extn    g3_draw_tmap    ;ecx=cnt, esi=point nums, ebx=uvs, edx=bitmap, al=ret: 1 off screen, 0 drew
  194.     extn    g3_check_and_draw_tmap    ;ecx=cnt, esi=point nums, ebx=uvs, edx=bitmap, edi=normal, al=ret: -1 not facing, 1 off screen, 0 drew
  195.     extn    g3_check_normal_facing    ;esi=vec, edi=norm, ret al
  196.     ;;extn    g3_compute_lighting_value    ;ecx=surface normal scale, esi=rotated point, ret ecx
  197.     extn    g3_draw_sphere    ;esi=pos (rotated), ecx=radius
  198.     extn    g3_set_special_render ;eax=tmap draw, edx=flat drawer, ebx=line drawer
  199.  
  200. ;from clipper.asm
  201.     extn    clip_line    ;esi,edi=points (ptrs)
  202.     extn    free_temp_point    ;esi=point (ptr)
  203.     extn    clip_polygon    ;esi=src list,edi=dest list,ecx=n, al=codes_or
  204.  
  205. ;from objects.asm
  206.     extn    g3_draw_object    ;esi=pos,edi=mat,eax=size,ebx=obj_id
  207.  
  208.  
  209. ;from horizon.asm
  210.     extn    g3_draw_horizon    ;eax=sky_color, edx=ground_color
  211.     extn    g3_compute_sky_polygon    ;ebx=2d points, ecx=vecs
  212.  
  213. ;from instance.asm
  214.     extn    g3_start_instance_matrix    ;esi=pos,edi=matrix. trashes esi,edi
  215.     extn    g3_start_instance_angles    ;esi=pos,edi=angvec. trashes esi,edi
  216.  
  217.     extn    g3_done_instance    ;no parms
  218.  
  219. ;from rod.asm
  220.     extn    g3_draw_rod_tmap    ;esi,edi=bot,top points,eax,edx=bot,top width, ebx=bitmap, ecx=lightval
  221.     extn    g3_draw_rod_flat    ;esi,edi=bot,top points,eax,edx=bot,top width
  222.     extn    g3_draw_bitmap    ;esi=pos,ebx=width3d,ecx=height3d,eax=bm, trashes eax,ecx,esi
  223.  
  224. ;from interp.asm
  225.  
  226.     extn    g3_set_interp_points    ;eax=ptr to list
  227.     extn    g3_draw_polygon_model    ;esi=model ptr, edi=bitmap list ptr, eax=anim angles, edx=light, ebx=ptr to glow values (or NULL)
  228.     extn    g3_init_polygon_model    ;esi=model ptr
  229.     extn    g3_draw_morphing_model    ;esi=model ptr, edi=bitmap list ptr, eax=anim angles, edx=light, ebx=new points
  230.  
  231. _TEXT    ends
  232.  
  233.  
  234.  
  235. ;check for overflow before doing divide.
  236. ;assume numerator is in edx:eax.  Denominator and label to jump to if
  237. ;overflow are passed.
  238. divcheck    macro    den,lbl
  239.     local    not_neg1,not_neg2
  240.     push    ecx
  241.     mov    ecx,edx
  242.     or    ecx,ecx
  243.     jns    not_neg1
  244.     neg    ecx
  245. not_neg1:    shld    ecx,eax,1    ;num * 2
  246.     cmp    ecx,den
  247.     pop    ecx
  248.     jae    lbl
  249.     endm
  250.  
  251.  
  252. endif
  253.  
  254.