home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / GRAPHICS / rayshade.lzh / plane.c < prev    next >
Text File  |  1990-05-08  |  3KB  |  109 lines

  1. /*
  2.  * plane.c
  3.  *
  4.  * Copyright (C) 1989, Craig E. Kolb
  5.  *
  6.  * This software may be freely copied, modified, and redistributed,
  7.  * provided that this copyright notice is preserved on all copies.
  8.  *
  9.  * There is no warranty or other guarantee of fitness for this software,
  10.  * it is provided solely .  Bug reports or fixes may be sent
  11.  * to the author, who may or may not act on them as he desires.
  12.  *
  13.  * You may not include this software in a program or other software product
  14.  * without supplying the source, or without informing the end-user that the
  15.  * source is available for no extra charge.
  16.  *
  17.  * If you modify this software, you should include a notice giving the
  18.  * name of the person performing the modification, the date of modification,
  19.  * and the reason for such modification.
  20.  *
  21.  * $Id: plane.c,v 3.0.1.2 90/04/04 19:02:42 craig Exp $
  22.  *
  23.  * $Log:    plane.c,v $
  24.  * Revision 3.0.1.2  90/04/04  19:02:42  craig
  25.  * patch5: Test for edge-on intersection more robust.
  26.  * 
  27.  * Revision 3.0.1.1  89/12/06  16:34:03  craig
  28.  * patch2: Added calls to new error/warning routines.
  29.  * 
  30.  * Revision 3.0  89/10/27  02:05:59  craig
  31.  * Baseline for first official release.
  32.  * 
  33.  */
  34. #include <stdio.h>
  35. #include "constants.h"
  36. #include "typedefs.h"
  37. #include "funcdefs.h"
  38.  
  39. /*
  40.  * create plane Primitive
  41.  */
  42. Object *
  43. makplane(surf, norm, pos)
  44. char *surf;
  45. Vector *norm, *pos;
  46. {
  47.     Plane    *plane;
  48.     Vector tmpnrm;
  49.     Object *newobj;
  50.     Primitive *prim;
  51.  
  52.     tmpnrm = *norm;
  53.     if (normalize(&tmpnrm) == 0.) {
  54.         yywarning("Degenerate plane normal.");
  55.         return (Object *)0;
  56.     }
  57.     prim = mallocprim();
  58.     prim->surf = find_surface(surf);
  59.     prim->type = PLANE;
  60.     newobj = new_object(NULL, PLANE, (char *)prim, (Trans *)NULL);
  61.     plane = (Plane *)Malloc(sizeof(Plane));
  62.     prim->objpnt.p_plane = plane;
  63.     plane->norm = tmpnrm;
  64.     plane->d = dotp(&plane->norm, pos);
  65.  
  66.     return newobj;
  67. }
  68.  
  69. double
  70. intplane(pos, ray, obj)
  71. Vector *pos;
  72. Vector *ray;
  73. Primitive *obj;
  74. {
  75.     Plane *plane;
  76.     double denom, dist;
  77.     extern unsigned long primtests[];
  78.  
  79.     primtests[PLANE]++;
  80.     plane = obj->objpnt.p_plane;
  81.  
  82.     denom = dotp(&plane->norm, ray);
  83.     if (equal(denom, 0.))
  84.         return 0.;
  85.     dist = (plane->d - dotp(&plane->norm, pos)) / denom;
  86.     return (dist > FAR_AWAY ? 0. : dist);
  87. }
  88.  
  89. /*ARGSUSED*/
  90. nrmplane(pos, obj, nrm)
  91. Vector *pos, *nrm;
  92. Primitive *obj;
  93. {
  94.     *nrm = obj->objpnt.p_plane->norm;
  95. }
  96.  
  97. /*ARGSUSED*/
  98. planeextent(o, bounds)
  99. Primitive *o;
  100. double bounds[2][3];
  101. {
  102.     /*
  103.      * Planes are unbounded by nature.  minx > maxx signifies
  104.      * this.
  105.      */
  106.     bounds[LOW][X] = 1.0;
  107.     bounds[HIGH][X] = -1.0;
  108. }
  109.