home *** CD-ROM | disk | FTP | other *** search
/ Photo CD Demo 1 / Demo.bin / graphtal / geoobjct.c < prev    next >
C/C++ Source or Header  |  1992-10-22  |  2KB  |  72 lines

  1. /*
  2.  * GeoObject.C - base class for geometric primitives.
  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 "GeoObject.h"
  19. #include "transform.h"
  20.  
  21. //___________________________________________________________ GeoObject
  22.  
  23. long GeoObject::intersectionTests = 0;
  24. long GeoObject::intersections = 0;
  25.  
  26. implementList(GeoObjectList, GeoObjectPtr);
  27.  
  28. GeoObject::GeoObject()
  29. : trans(NULL), itrans(NULL)
  30. {}
  31.  
  32. GeoObject::~GeoObject()
  33. {
  34.   if (trans != NULL)  delete trans;
  35.   if (itrans != NULL) delete itrans;
  36. }
  37.  
  38. /*
  39.  *
  40.  */
  41. Vector GeoObject::getNormal(const Vector& p) const
  42. {
  43.   if (itrans != NULL) {
  44.  
  45.     /*
  46.      * Transform intersection point to object space and compute normal.
  47.      */
  48.     Vector n = normal(p*(*itrans));
  49.  
  50.     /*
  51.      * Transform normal back to world space (multiply by the transpose of
  52.      * the inverse transformation matrix, not regarding the translations).
  53.      */
  54.     return normalTransform(n, *itrans);
  55.   }
  56.   else
  57.     return normal(p);
  58. }
  59.  
  60. /*
  61.  * Set the transformation matrix and compute the inverse of it.
  62.  * SetTransform returns FALSE if the matrix is singular, TRUE
  63.  * otherwise.
  64.  */
  65. int GeoObject::setTransform(TransMatrix* tmat)
  66. {
  67.   trans = tmat;
  68.   itrans = new TransMatrix(*trans);
  69.   return itrans->invert();
  70. }
  71.  
  72.