home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / demos / GL / flight / cull.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  2.3 KB  |  82 lines

  1. /*
  2.  * Copyright 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17.  
  18. /*
  19.  *  flight/cull.c $Revision: 1.2 $
  20.  *
  21.  *  culling routines
  22.  */
  23.  
  24. #include "flight.h"
  25. #include <math.h>
  26.  
  27.  
  28. /*
  29.  *  cull_sphere() returns TRUE if the sphere is outside the viewing frustom,
  30.  *  FALSE other wise.
  31.  */
  32. cull_sphere(float *center, float radius)
  33. {
  34.     int i;
  35.  
  36.     if (clip_planes[0][3] + DOT(clip_planes[0], center) > radius)
  37.     return(TRUE);
  38.     if (clip_planes[1][3] + DOT(clip_planes[1], center) > radius)
  39.     return(TRUE);
  40.     if (clip_planes[2][3] + DOT(clip_planes[2], center) > radius)
  41.     return(TRUE);
  42.     if (clip_planes[3][3] + DOT(clip_planes[3], center) > radius)
  43.     return(TRUE);
  44.  
  45.     return(FALSE);
  46. }
  47.  
  48.  
  49. /*
  50.  *  cull_shadow() returns TRUE if the shadow of plane pp is outside the
  51.  *  viewing frustom, FALSE other wise.
  52.  */
  53. cull_shadow(Plane pp, float xf, float zf)
  54. {
  55.     float v1[3], v2[3];
  56.     float radius;
  57.  
  58.     radius = planeobj[pp->type]->radius;
  59.     v1[X] = pp->x + (pp->y + radius) * xf;
  60.     v1[Y] = 0;
  61.     v1[Z] = pp->z + (pp->y + radius) * zf;
  62.     v2[X] = pp->x + (pp->y - radius) * xf;
  63.     v2[Y] = 0;
  64.     v2[Z] = pp->z + (pp->y - radius) * zf;
  65.  
  66.     if (clip_planes[0][3] + DOT(clip_planes[0], v1) > radius &&
  67.     clip_planes[0][3] + DOT(clip_planes[0], v2) > radius)
  68.     return(TRUE);
  69.     if (clip_planes[1][3] + DOT(clip_planes[1], v1) > radius &&
  70.     clip_planes[1][3] + DOT(clip_planes[1], v2) > radius)
  71.     return(TRUE);
  72.     if (clip_planes[2][3] + DOT(clip_planes[2], v1) > radius &&
  73.     clip_planes[2][3] + DOT(clip_planes[2], v2) > radius)
  74.     return(TRUE);
  75.     if (clip_planes[3][3] + DOT(clip_planes[3], v1) > radius &&
  76.     clip_planes[3][3] + DOT(clip_planes[3], v2) > radius)
  77.     return(TRUE);
  78.  
  79.     return(FALSE);
  80. }
  81.  
  82.