00001 /* ************************************************************************* 00002 transparenttransformatable.h - description 00003 ------------------- 00004 begin : Fri Jan 17 2003 00005 copyright : (C) 2003 by Micha Riser 00006 email : mriser@gmx.net 00007 00008 $Id: transparenttransformatable_8h-source.html,v 1.1 2005/02/04 21:02:27 micha Exp $ 00009 00010 ************************************************************************* */ 00011 00012 /* ************************************************************************* 00013 * * 00014 * This program is free software; you can redistribute it and/or modify * 00015 * it under the terms of the GNU General Public License as published by * 00016 * the Free Software Foundation; either version 2 of the License, or * 00017 * (at your option) any later version. * 00018 * * 00019 ************************************************************************* */ 00020 00021 #ifndef TRANSPARENTTRANSFORMATABLE_H 00022 #define TRANSPARENTTRANSFORMATABLE_H 00023 00024 #include "transformatable.h" 00025 #include "matrix.h" 00026 #include "ray.h" 00027 00032 class TransparentTransformatable: public Transformatable { 00033 00034 public: // Constructors and destructor 00035 00037 TransparentTransformatable(): 00038 translation(0),transformation(0),inverse(0) {} 00039 00041 TransparentTransformatable(const Vector3& loc): 00042 translation(loc),transformation(0),inverse(0) {} 00043 00045 TransparentTransformatable(const TransparentTransformatable &t): 00046 Transformatable(t), translation(t.translation), transformation(0), inverse(0) { 00047 00048 if (t.transformation) { 00049 transformation = new Matrix(*t.transformation); 00050 inverse = new Matrix(*t.inverse); 00051 } 00052 00053 } 00054 00056 virtual ~TransparentTransformatable() { 00057 delete(transformation); 00058 delete(inverse); 00059 } 00060 00061 private: 00062 TransparentTransformatable& operator=(const TransparentTransformatable); 00063 00064 public: // Methods that implement Transformatable 00065 00066 virtual void translate(const Vector3& v) {translation.add(v);} 00067 virtual void scale(const Vector3& v); 00068 virtual void rotateDeg(const Vector3& v); 00069 virtual void rotateRad(const Vector3& v); 00070 virtual void applyOrthogonalMatrix(const Matrix& m); 00071 virtual void applyMatrix(const Matrix& m); 00072 00073 public: // Additional transformation methods 00074 00077 virtual void transform(const TransparentTransformatable& t); 00078 00081 virtual void transformInverse(const TransparentTransformatable& t); 00082 00083 public: // Methods to do space transformations 00084 00087 void transformPointIn(Vector3 &p) const { 00088 // p' = T*(p-t) 00089 p.sub(translation); 00090 if (transformation) p.applyFromLeft(*transformation); 00091 } 00092 00095 void transformPointOut(Vector3 &p) const { 00096 // p = T*p'+t /* *check me* for correctness */ 00097 if (transformation) p.applyFromLeft(*inverse); 00098 p.add(translation); 00099 } 00100 00103 // void transformNormalIn(Vector3 &p) const; 00104 00107 void transformNormalOut(Vector3 &p) const { 00108 if (transformation) p.applyFromLeftTransposed(*transformation); 00109 } 00110 00113 void transformRayIn(Ray &r) const { 00114 r.origin.sub(translation); 00115 if (transformation) { 00116 r.origin.applyFromLeft(*transformation); 00117 r.direction.applyFromLeft(*transformation); 00118 } 00119 } 00120 00121 00122 public: // Functions that give read access to transformations 00126 Vector3 getTranslation() const {return translation;} 00127 00131 const Matrix* getTransformationMatrix() const {return transformation;} 00132 00136 const Matrix* getInverseMatrix() const {return inverse;} 00137 00138 protected: // Functions that give write access to transformations 00141 void clearTransformation() { 00142 delete(transformation); 00143 delete(inverse); 00144 transformation = 0; 00145 inverse = 0; 00146 translation = Vector3(0); 00147 } 00148 00151 void setTranslation(const Vector3& v) { 00152 translation = v; 00153 } 00154 00155 private: // Protected attributes 00156 00159 Vector3 translation; 00160 00163 Matrix* transformation; 00164 00167 Matrix* inverse; 00168 00169 }; 00170 00171 #endif
1.3.8