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: $ 00022 */ 00023 00024 00025 #ifndef TEDDY__MODELS__VERTEX__H 00026 #define TEDDY__MODELS__VERTEX__H 00027 00028 00029 #if defined(_MSC_VER) 00030 #pragma warning(disable:4521) // multiple copy constructors defined (!) 00031 #endif 00032 00033 00034 #include "Teddy/Graphics/Color.h" 00035 #include "Teddy/Maths/Vector.h" 00036 #include "Teddy/Maths/Matrix.h" 00037 #include "Teddy/MixIn/Options.h" 00038 #include "Teddy/Models/Element.h" 00039 #include "Teddy/SysSupport/StdList.h" 00040 using namespace Teddy::Graphics; 00041 using namespace Teddy::Maths; 00042 using namespace Teddy::MixIn; 00043 00044 00045 namespace Teddy { 00046 namespace Models { 00047 00048 00049 class Face; 00050 00051 00064 class Vertex : public Element { 00065 public: 00066 Vertex(); 00067 Vertex( Vertex *v ); 00068 Vertex( Vertex &v ); 00069 Vertex( const Vertex &v ); 00070 Vertex( const Vector &v ); 00071 Vertex( const float x, const float y, const float z ); 00072 virtual ~Vertex(); 00073 00074 virtual double getMaxVector() const; 00075 00076 public: 00077 virtual void debug (); 00078 virtual void draw ( Projection *p ); 00079 virtual void applyColor ( Projection *p ); 00080 virtual void applyNormal ( Projection *p ); 00081 virtual void applyTexture( Projection *p ); 00082 virtual void applyVertex ( Projection *p ); 00083 00084 void neg (); 00085 void transform ( const Matrix &m, const Matrix &normal_matrix ); 00086 void setParent ( const Vertex &vert ); 00087 void setVertex ( const Vector &vert ); 00088 void setVertex ( const float x, const float y, const float z ); 00089 void setColor ( const Color &color ); 00090 void setNormal ( const Vector &normal ); 00091 void setNormal ( const float x, const float y, const float z ); 00092 void setTexture ( const Vector &texture ); 00093 void setTexture ( const float s, const float t, const float u = 0.0f ); 00094 void addNormal ( const Vector &add ); 00095 void normNormal (); 00096 void removeNormal(); 00097 Vertex *getRoot (); 00098 Vertex *getParent (); 00099 Vector &getVertex (); 00100 Color &getColor (); 00101 Vector &getNormal (); 00102 Vector &getTexture (); 00103 list<Face*> &getFaces (); 00104 void addFace ( Face *face ); 00105 00106 // Basic operations on vertex 00107 Vertex &operator+=( Vertex &v ){ vert += v.getVertex(); return *this; }; 00108 Vertex &operator-=( Vertex &v ){ vert -= v.getVertex(); return *this; }; 00109 Vertex &operator*=( float k ){ vert *= k; return *this; }; 00110 Vertex &operator/=( float k ){ vert /= k; return *this; }; 00111 00112 Vertex &operator+=( const Vertex &v ){ vert += v.vert; return *this; }; 00113 Vertex &operator-=( const Vertex &v ){ vert -= v.vert; return *this; }; 00114 // Vertex &operator*=( const float k ){ vert *= k; return *this; }; 00115 // Vertex &operator/=( const float k ){ vert /= k; return *this; }; 00116 00117 Vertex operator+( Vertex &v ){ return new Vertex(vert+v.vert); }; 00118 Vertex operator-( Vertex &v ){ return new Vertex(vert-v.vert); }; 00119 Vertex operator*( float k ){ return new Vertex(vert*k ); }; 00120 Vertex operator/( float k ){ return new Vertex(vert/k ); }; 00121 00122 Vertex operator+( const Vertex &v ){ return new Vertex(vert+v.vert); }; 00123 Vertex operator-( const Vertex &v ){ return new Vertex(vert-v.vert); }; 00124 // Vertex operator*( const float k ){ return new Vertex(vert*k ); }; 00125 // Vertex operator/( const float k ){ return new Vertex(vert/k ); }; 00126 00127 // Flip code; FIX if parent vertex is being used, copy it and only change the copy 00128 void flipX (){ getVertex().v[0] *= -1; }; 00129 void flipY (){ getVertex().v[1] *= -1; }; 00130 void flipZ (){ getVertex().v[2] *= -1; }; 00131 00132 // Length code; FIX if parent vertex is being used, copy it and only change the copy 00133 void normalize(){ getVertex().normalize(); }; 00134 float magnitude(){ return getVertex().magnitude(); }; 00135 00136 public: 00137 list<Face*> faces; 00138 00139 protected: 00140 Vertex *parent; 00141 Vector vert; 00142 Vector normal; 00143 Color color; 00144 Vector texturecoord; 00145 }; 00146 00147 00148 }; // namespace Models 00149 }; // namespace Teddy 00150 00151 00152 #endif // TEDDY__MODELS__VERTEX__H 00153