home *** CD-ROM | disk | FTP | other *** search
/ Photo CD Demo 1 / Demo.bin / graphtal / ray.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-19  |  1.0 KB  |  46 lines

  1. /*
  2.  * Ray.C
  3.  *
  4.  * Copyright (C) 1992, Christoph Streit (streit@iam.unibe.ch)
  5.  * All rights reserved.
  6.  *
  7.  * This software may be freely copied, modified, and redistributed
  8.  * provided that this copyright notice is preserved on all copies.
  9.  *
  10.  * You may not distribute this software, in whole or in part, as part of
  11.  * any commercial product without the express consent of the authors.
  12.  *
  13.  * There is no warranty or other guarantee of fitness of this software
  14.  * for any purpose.  It is provided solely "as is".
  15.  *
  16.  */
  17.  
  18. #include "Ray.h"
  19. #include "transform.h"
  20.  
  21. //___________________________________________________________ Ray
  22.  
  23. Ray::Ray(const Vector& origin, const Vector& direction)
  24. : orig(origin), dir(direction)
  25. {}
  26.  
  27. real Ray::transform(const TransMatrix& tmat)
  28. {
  29.   orig = orig*tmat;
  30.  
  31.   /*
  32.    * apply the transformation to the direction 
  33.    * (translations has no effect)
  34.    */
  35.   dir = vectorTransform(dir, tmat);
  36.  
  37.   /*
  38.    * compute the that the ray is stretched due to the transformation
  39.    */
  40.   real d = dir.length();
  41.   dir.normalize();
  42.  
  43.   return d;
  44. }
  45.  
  46.