home *** CD-ROM | disk | FTP | other *** search
- /*
- * GeoObject.C - base class for geometric primitives.
- *
- * Copyright (C) 1992, Christoph Streit (streit@iam.unibe.ch)
- * University of Berne, Switzerland
- * All rights reserved.
- *
- * This software may be freely copied, modified, and redistributed
- * provided that this copyright notice is preserved on all copies.
- *
- * You may not distribute this software, in whole or in part, as part of
- * any commercial product without the express consent of the authors.
- *
- * There is no warranty or other guarantee of fitness of this software
- * for any purpose. It is provided solely "as is".
- *
- */
-
- #include "GeoObject.h"
- #include "transform.h"
-
- //___________________________________________________________ GeoObject
-
- long GeoObject::intersectionTests = 0;
- long GeoObject::intersections = 0;
-
- implementList(GeoObjectList, GeoObjectPtr);
-
- GeoObject::GeoObject()
- : trans(NULL), itrans(NULL)
- {}
-
- GeoObject::~GeoObject()
- {
- if (trans != NULL) delete trans;
- if (itrans != NULL) delete itrans;
- }
-
- /*
- *
- */
- Vector GeoObject::getNormal(const Vector& p) const
- {
- if (itrans != NULL) {
-
- /*
- * Transform intersection point to object space and compute normal.
- */
- Vector n = normal(p*(*itrans));
-
- /*
- * Transform normal back to world space (multiply by the transpose of
- * the inverse transformation matrix, not regarding the translations).
- */
- return normalTransform(n, *itrans);
- }
- else
- return normal(p);
- }
-
- /*
- * Set the transformation matrix and compute the inverse of it.
- * SetTransform returns FALSE if the matrix is singular, TRUE
- * otherwise.
- */
- int GeoObject::setTransform(TransMatrix* tmat)
- {
- trans = tmat;
- itrans = new TransMatrix(*trans);
- return itrans->invert();
- }
-
-