home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume21 / rayshade / part01 / src / plane.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-03-21  |  2.3 KB  |  106 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 89/10/27 02:05:59 craig Exp $
  22.  *
  23.  * $Log:    plane.c,v $
  24.  * Revision 3.0  89/10/27  02:05:59  craig
  25.  * Baseline for first official release.
  26.  * 
  27.  */
  28. #include <stdio.h>
  29. #include "constants.h"
  30. #include "typedefs.h"
  31. #include "funcdefs.h"
  32.  
  33. /*
  34.  * create plane Primitive
  35.  */
  36. Object *
  37. makplane(surf, norm, pos)
  38. char *surf;
  39. Vector *norm, *pos;
  40. {
  41.     Plane    *plane;
  42.     Vector tmpnrm;
  43.     Object *newobj;
  44.     Primitive *prim;
  45.     extern int Quiet, yylineno;
  46.  
  47.     tmpnrm = *norm;
  48.     if (normalize(&tmpnrm) == 0.) {
  49.         if (!Quiet)
  50.             fprintf(stderr, "Degenerate plane normal (line %d)\n",
  51.                             yylineno);
  52.         return (Object *)0;
  53.     }
  54.     prim = mallocprim();
  55.     prim->surf = find_surface(surf);
  56.     prim->type = PLANE;
  57.     newobj = new_object(NULL, PLANE, (char *)prim, (Trans *)NULL);
  58.     plane = (Plane *)Malloc(sizeof(Plane));
  59.     prim->objpnt.p_plane = plane;
  60.     plane->norm = tmpnrm;
  61.     plane->d = dotp(&plane->norm, pos);
  62.  
  63.     return newobj;
  64. }
  65.  
  66. double
  67. intplane(pos, ray, obj)
  68. Vector *pos;
  69. Vector *ray;
  70. Primitive *obj;
  71. {
  72.     Plane *plane;
  73.     double denom, dist;
  74.     extern unsigned long primtests[];
  75.  
  76.     primtests[PLANE]++;
  77.     plane = obj->objpnt.p_plane;
  78.  
  79.     denom = dotp(&plane->norm, ray);
  80.     if (denom == 0.)
  81.         return 0.;
  82.     dist = (plane->d - dotp(&plane->norm, pos)) / denom;
  83.     return (dist > FAR_AWAY ? 0. : dist);
  84. }
  85.  
  86. /*ARGSUSED*/
  87. nrmplane(pos, obj, nrm)
  88. Vector *pos, *nrm;
  89. Primitive *obj;
  90. {
  91.     *nrm = obj->objpnt.p_plane->norm;
  92. }
  93.  
  94. /*ARGSUSED*/
  95. planeextent(o, bounds)
  96. Primitive *o;
  97. double bounds[2][3];
  98. {
  99.     /*
  100.      * Planes are unbounded by nature.  minx > maxx signifies
  101.      * this.
  102.      */
  103.     bounds[LOW][X] = 1.0;
  104.     bounds[HIGH][X] = -1.0;
  105. }
  106.