00001 00002 /* 00003 TEDDY - General graphics application library 00004 Copyright (C) 1999-2002 Timo Suoranta 00005 tksuoran@cc.helsinki.fi 00006 00007 This library is free software; you can redistribute it and/or 00008 modify it under the terms of the GNU Lesser General Public 00009 License as published by the Free Software Foundation; either 00010 version 2.1 of the License, or (at your option) any later version. 00011 00012 This library is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 Lesser General Public License for more details. 00016 00017 You should have received a copy of the GNU Lesser General Public 00018 License along with this library; if not, write to the Free Software 00019 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00020 00021 $Id: Vertex.h,v 1.6 2002/02/16 12:41:39 tksuoran Exp $ 00022 */ 00023 00024 00025 #if 0 00026 #ifndef TEDDY__MODELS__VERTEX__H 00027 #define TEDDY__MODELS__VERTEX__H 00028 00029 00030 #if defined(_MSC_VER) 00031 #pragma warning(disable:4521) // multiple copy constructors defined (!) 00032 #endif 00033 00034 00035 #include "Teddy/Graphics/Color.h" 00036 #include "Teddy/Maths/Vector.h" 00037 #include "Teddy/Maths/Matrix.h" 00038 #include "Teddy/MixIn/Options.h" 00039 #include "Teddy/Models/Element.h" 00040 #include "Teddy/SysSupport/StdList.h" 00041 using namespace Teddy::Graphics; 00042 using namespace Teddy::Maths; 00043 using namespace Teddy::MixIn; 00044 00045 00046 namespace Teddy { 00047 namespace Models { 00048 00049 00050 class Face; 00051 00052 00065 class Vertex : public Element { 00066 public: 00067 Vertex(); 00068 Vertex( Vertex *v ); 00069 Vertex( Vertex &v ); 00070 Vertex( const Vertex &v ); 00071 Vertex( const Vector &v ); 00072 Vertex( const float x, const float y, const float z ); 00073 virtual ~Vertex(); 00074 00075 virtual double getMaxVector() const; 00076 00077 public: 00078 virtual void debug (); 00079 virtual void draw ( Projection *p ); 00080 virtual void applyColor ( Projection *p ); 00081 virtual void applyNormal ( Projection *p ); 00082 virtual void applyTexture( Projection *p ); 00083 virtual void applyVertex ( Projection *p ); 00084 00085 void neg (); 00086 void transform ( const Matrix &m, const Matrix &normal_matrix ); 00087 void setParent ( const Vertex &vert ); 00088 void setVertex ( const Vector &vert ); 00089 void setColor ( const Color &color ); 00090 void setNormal ( const Vector &normal ); 00091 void setTexture ( const Vector &texture ); 00092 void addNormal ( const Vector &add ); 00093 void normNormal (); 00094 void removeNormal(); 00095 Vertex *getRoot (); 00096 Vertex *getParent (); 00097 Vector &getVertex (); 00098 Color &getColor (); 00099 Vector &getNormal (); 00100 Vector &getTexture (); 00101 list<Face*> &getFaces (); 00102 void addFace ( Face *face ); 00103 00104 // Basic operations on vertex 00105 Vertex &operator+=( Vertex &v ){ vert += v.getVertex(); return *this; }; 00106 Vertex &operator-=( Vertex &v ){ vert -= v.getVertex(); return *this; }; 00107 Vertex &operator*=( float k ){ vert *= k; return *this; }; 00108 Vertex &operator/=( float k ){ vert /= k; return *this; }; 00109 00110 Vertex &operator+=( const Vertex &v ){ vert += v.vert; return *this; }; 00111 Vertex &operator-=( const Vertex &v ){ vert -= v.vert; return *this; }; 00112 // Vertex &operator*=( const float k ){ vert *= k; return *this; }; 00113 // Vertex &operator/=( const float k ){ vert /= k; return *this; }; 00114 00115 Vertex operator+( Vertex &v ){ return new Vertex(vert+v.vert); }; 00116 Vertex operator-( Vertex &v ){ return new Vertex(vert-v.vert); }; 00117 Vertex operator*( float k ){ return new Vertex(vert*k ); }; 00118 Vertex operator/( float k ){ return new Vertex(vert/k ); }; 00119 00120 Vertex operator+( const Vertex &v ){ return new Vertex(vert+v.vert); }; 00121 Vertex operator-( const Vertex &v ){ return new Vertex(vert-v.vert); }; 00122 // Vertex operator*( const float k ){ return new Vertex(vert*k ); }; 00123 // Vertex operator/( const float k ){ return new Vertex(vert/k ); }; 00124 00125 // Flip code; FIX if parent vertex is being used, copy it and only change the copy 00126 void flipX (){ getVertex().v[0] *= -1; }; 00127 void flipY (){ getVertex().v[1] *= -1; }; 00128 void flipZ (){ getVertex().v[2] *= -1; }; 00129 00130 // Length code; FIX if parent vertex is being used, copy it and only change the copy 00131 void normalize(){ getVertex().normalize(); }; 00132 float magnitude(){ return getVertex().magnitude(); }; 00133 00134 public: 00135 list<Face*> faces; 00136 00137 protected: 00138 Vertex *parent; 00139 Vector vert; 00140 Vector normal; 00141 Color color; 00142 Vector texturecoord; 00143 }; 00144 00145 00146 }; // namespace Models 00147 }; // namespace Teddy 00148 00149 00150 #endif // TEDDY__MODELS__VERTEX__H 00151 00152 #endif