www.pudn.com > LightTrack.rar > Clipp3D.cpp


/** 3DGPL *************************************************\ 
 * ()                                                     * 
 * 3-D volume and Z clipping.                             * 
 *                                                        * 
 * Defines:                                               * 
 *  C_volume_clipping        Out of view-volume elements; * 
 *                                                        * 
 *  C_line_z_clipping        Clipping a line;             * 
 *  C_polygon_z_clipping     View plane cliping;          * 
 *  C_line_xyz_clipping      Arbitrry clipping of a line; * 
 *  C_polygon_xyz_clipping   Arbitrry plane cliping.      * 
 *                                                        * 
 * (c) 1995-98 Sergei Savchenko, (savs@cs.mcgill.ca)      * 
\**********************************************************/ 
 
//Clipp3D.cpp 
 
#include "LightTrack.h"           /* HW_copy_int stuff */ 
#include "Trans.h"                 /* T_plane etc. */ 
#include "Clipper.h"             /* clipping constants */ 
#include                          /* INT_MAX & INT_MIN */ 
 
int C_3D_clipping;                          /* type of performed clipping */ 
 
/**********************************************************\ 
 * Accept/reject volume clipping.                         * 
 *                                                        * 
 * RETURNS:  0 when extend is for sure outside the        * 
 * --------    view volume, just discard it;              * 
 *          -1 when further clipping is required;         * 
 *           1 when element has a fair chance to be       * 
 *             inside the view volume, and should be      * 
 *             clipped by 2-D clipping when rasterizing.  * 
 *                                                        * 
 *               | z                                      * 
 *          \    |    /      Clipping volume is a pyramid * 
 *           \   |   /       with 90 degree angle,        * 
 *            \  |  /        so the real view volume      * 
 *        -x>z \ | /  x>z    better be inside it.         *  
 *              \|/                                       * 
 *       --------+--------- x                             * 
 *       z>1; 
    whereto=m[2] 2-2'-5'-6-1-2    * 
 *         |5'                                             * 
 *      5*-*-----*6     If first vertex in the line is     * 
 *      /  |      \     clipped, both vertices are copyed, * 
 *    4*   |       *1   If no clipping or second one is    * 
 *      \  |      /     clipped then only second one is    * 
 *      3*-*-----*2     copyed. If both vertices are       * 
 *         |2'          clipped, neither one is copyed.    * 
 *                                                         * 
\***********************************************************/ 
 
int C_polygon_z_clipping(int *from,register int *to, 
                         int dimension,int length 
                        ) 
{ 
 register int i; 
 int *v1,*v2,new_lng=0; 
 int *first_vrtx=to;                        /* begining of the source */ 
 
 for(i=0;iC_TOLERANCE) 
        )                                   /* not close enough */ 
   { 
    if(whereto==1) { t=l; l=m; m=t; } 
    else           { t=r; r=m; m=t; } 
    for(i=0;i>1; 
    whereto=T_vertex_on_plane(m,plane)<0; 
   } 
   *vmn=m;                                  /* that is why m[] is static */ 
   C_3D_clipping=swap^1; 
  } 
  return(1);                                /* partialy or not clipped */ 
 } 
} 
 
/**********************************************************\ 
 * Creating a polygon clipped by any plane.               * 
 *                                                        * 
 * RETURNS: number of vertices in the clipped polygon.    * 
 * -------- (0 when compleately clipped)                  * 
 *                                                        * 
 *                       1-2-3-4-5-6-1  -> 2'-3'-5'-6'    * 
 *        \ 5'                                            * 
 *      5*-*------*6     If first vertex in the line is   * 
 *      /   \       \    being clipped both vertices are  * 
 *    4*     \       *1  copyed If no clipping or second  * 
 *      \     \ 3'  /    one is clipped then only second  * 
 *      3*-----*--*2     one is copyed. If both vertices  * 
 *              \        are clipped, neither is copyed.  * 
 *                                                        * 
\**********************************************************/ 
 
int C_polygon_xyz_clipping(int *from,register int *to, 
                           int *by1,int *by2,int *by3, 
                           int dimension,int length 
                          ) 
{ 
 register int i; 
 int *v1,*v2,new_lng=0; 
 int *first_vrtx=to;                        /* begining of the source */ 
 
 for(i=0;i