home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / WD_SRC.ZIP / SOURCE / DRAW.HPP < prev    next >
C/C++ Source or Header  |  1995-01-12  |  5KB  |  171 lines

  1.  
  2. // A return value returned by some of the functions.
  3. enum DrawReturn { ScreenCompletelyDrawn, DrewWall, WallOffScreen };
  4.  
  5.  
  6. class X_Clip
  7. {
  8. public:
  9.     // Pointers for the linked list.
  10.     X_Clip *pNext;
  11.  
  12.     // Tells the clipping routines what flags to set with this X_Clip.
  13.     //X_ClipFlag TableFlag;
  14.  
  15.     // The x boundaries of this clip.
  16.     WORD x;
  17. };
  18.  
  19.  
  20. // This structure is passed around in all the drawing routines.
  21. class ProcessWall
  22. {
  23. public:
  24.     CLine *pLine;
  25.     Player *pPlayer;
  26.     
  27.     // World coordinates.
  28.     Fixed x1, y1, x2, y2;
  29.     
  30.     // Screen coordinates.
  31.     WORD screenX1, screenX2;
  32.  
  33.     // Unclipped screen coordinates...  screenX1 and screenX2 are clipped against
  34.     // the screen sides in the x clipping table.
  35.     WORD unclippedScreenX1, unclippedScreenX2;
  36.  
  37.     // Stuff for the Y coordinates.
  38.     Fixed topSlope, bottomSlope;
  39.     WORD yTopIntercept, yBottomIntercept;
  40.     
  41.     // Returned from clipping routines.  They represent where on the Line
  42.     // each new X coordinate lies.
  43.     Fixed t1, t2;
  44.  
  45.     // The shade at each of the screen x coordinates.
  46.     // (Put it through dr_ShadeLookup() first.)
  47.     Fixed shade1, shade2;
  48.  
  49.     // The Line's normal, after rotation.
  50.     Fixed normalX, normalY;
  51.  
  52.     // Filled in when transforming.  Tells which side the player is looking at.
  53.     SideDir viewSide;
  54.     
  55.     // The 'magic numbers' in texture mapping.
  56.     // P is the origin.
  57.     // M is the horizontal vector.
  58.     // N is the vertical vector.
  59.     Fixed Px, Py, Pz;
  60.     Fixed Mx, My, Mz;
  61.     Fixed Nx, Ny, Nz;
  62.  
  63.     Fixed Oa, Oc;
  64.     Fixed Ha, Hc;
  65.     
  66.     // Used for texture mapping .. the original Origin and Horizontal points.
  67.     Fixed originX, originZ, horzX, horzZ;
  68.     
  69.     // Lets the drawing routines know if they need to re-init the wall's texture variables.
  70.     BOOL bTextureInitted;
  71.     
  72.     BOOL bFlippedX;
  73. };
  74.  
  75.  
  76. // Should be called when initting the engine.  Loads and generates all the lookup tables.
  77. void dr_InitTables();
  78.  
  79. // Regenerates any lookup tables that need to change when the screen is resized.
  80. void dr_GenerateLookups();
  81.  
  82. // Renders the whole screen based on global variables like the player's position.
  83. void dr_DrawScreen();
  84.     
  85. // Just initializes the transformation stuff from a Player's view.
  86. void dr_SetupTransformation( Player *pPlayer );
  87.  
  88. // Should be called from the BSP routines.  The BSP routines will determine which walls need to
  89. // be drawn, and call the appropriate functions in Draw.
  90. DrawReturn dr_DrawWall( CLine *pWall, SideDir viewSide );
  91.  
  92. // Called by the BSP routines.  Sees if the wall has an entire subtree out of view.
  93. SideDir dr_PruneTree( CLine *pLine );
  94.  
  95. // Rotates and translates the wall.
  96. BOOL dr_TransformWall( ProcessWall *pWall );
  97.  
  98. // Clips against the z=0 plane.  ALSO gets the 
  99. // shade at the first and last points since this
  100. // is the last time it's clipped in 3d.
  101. // Returns FALSE if the wall is behind the player
  102. // and doesn't need to be drawn.
  103. BOOL dr_ClipWall( ProcessWall *pWall );
  104.  
  105. // Projects the vertices into screen coordinates.
  106. BOOL dr_ProjectWall( ProcessWall *pWall );
  107.  
  108. // Clips the wall against the others drawn.
  109. // Returns FALSE if the wall doesn't clip right.
  110. // ALSO changes the shade values for shade1 and shade2
  111. // if it needs to clip the wall.
  112. DrawReturn dr_TableClipAndDrawWall( ProcessWall *pWall );
  113.  
  114. // Returns an extra X clip.
  115. X_Clip *GetXClip();
  116.  
  117. // Draws a horizontal section of a wall.
  118. void dr_DrawHorizontalStrip( ProcessWall *pWall, WORD xLeft, WORD xRight );
  119.  
  120. // Draws line of a parallaxing sky..
  121. void dr_ParallaxLine( BYTE *pDrawTo, BYTE *pBuffer, BYTE *pPaletteMap, DWORD numPixels );
  122.  
  123. // Draws a line of a wall.
  124. void dr_WallLine( BYTE *pDrawTo, BYTE *pBuffer, BYTE *pPaletteMap, Fixed bufferStartPos, WORD numPixels );
  125.  
  126. // Draws the bottom line.
  127. void dr_BlankVLine( BYTE *pDrawTo, DWORD numPixels, DWORD lineAdd, BYTE color );
  128.  
  129. // Draws the whole environment in 2D.
  130. void Draw2DEnvironment( CLineArray *pLines, CPointArray *pPoints, WORD xOffset, WORD yOffset, Fixed scale, WORD maxX, WORD maxY );
  131.  
  132. // Just draws a solid line .. used to test projections.
  133. void dr_DrawLine( DWORD x1, DWORD y1, DWORD x2, DWORD y2, WORD maxX, WORD maxY, BYTE color );
  134.  
  135. // Clips against an arbitrary Y line.
  136. // Returns the number of the point that got clipped .. (1=*pX1,*pY1 and 2=*pX2,*pY2).
  137. WORD dr_ClipAgainstLine( Fixed clipLine, Fixed *pX1, Fixed *pY1, Fixed *pX2, Fixed *pY2, Fixed *pT1, Fixed *pT2, BOOL bPositiveHalf );
  138.  
  139. // Fixed math functions .. written in assembler.
  140. Fixed FDiv(Fixed numTop, Fixed numBottom);
  141. Fixed FMul(Fixed num1, Fixed num2);
  142.  
  143.  
  144. #pragma aux FDiv =          \
  145.         "cdq"                   \
  146.         "shld   edx, eax, 15"   \
  147.         "shl    eax, 15"        \
  148.         "idiv   ebx"            \
  149.         parm    [ EAX ] [ EBX ] \
  150.         modify  [ EDX ]         \
  151.         value   [ EAX ];
  152.  
  153.  
  154. #pragma aux FMul =          \
  155.         "test   eax,eax"        \ 
  156.         "jz     end"            \
  157.         "test   edx,edx"        \
  158.         "jnz    around"         \
  159.         "xor    eax,eax"        \
  160.         "jmp    end"            \
  161.         "around:"               \
  162.         "imul   edx"            \
  163.         "add    eax,32768" \
  164.         "adc    edx,0"          \
  165.         "shrd   eax, edx, 15"   \
  166.         "end:"                  \
  167.         parm    [ EAX ] [ EDX ] \
  168.         value   [ EAX ];
  169.  
  170.  
  171.