Go to the documentation of this file.00001 #ifndef __BASE_VERTEX_HPP__
00002 #define __BASE_VERTEX_HPP__
00003
00004
00005 #include <iostream>
00006 #include <math.h>
00007
00008 using namespace std;
00009
00010 namespace lssr
00011 {
00012
00013
00014 template<typename T> class Matrix4;
00015
00021 template<typename CoordType>
00022 class Vertex{
00023
00024 public:
00025
00030 Vertex()
00031 {
00032 m_x = m_y = m_z = 0;
00033 }
00034
00038 Vertex(const CoordType &x, const CoordType &y, const CoordType &z)
00039 {
00040 m_x = x;
00041 m_y = y;
00042 m_z = z;
00043 }
00044
00048 Vertex(const Vertex &o)
00049 {
00050 m_x = o.m_x;
00051 m_y = o.m_y;
00052 m_z = o.m_z;
00053 }
00054
00058 virtual ~Vertex(){};
00059
00063 CoordType length();
00064
00071 Vertex<CoordType> cross(const Vertex &other) const;
00072
00073
00080 void rotate(const Matrix4<CoordType> &m);
00081
00088 void rotateCM(const Matrix4<CoordType> &m);
00089
00096 void rotateRM(const Matrix4<CoordType> &m);
00097
00104 void transform(const Matrix4<CoordType> &m);
00105
00112 void transformRM(const Matrix4<CoordType> &m);
00113
00120 void transformCM(const Matrix4<CoordType> &m);
00121
00122
00123
00124
00130 virtual void crossTo(const Vertex &other);
00131
00135 virtual CoordType operator*(const Vertex &other) const;
00136
00137
00141 virtual Vertex<CoordType> operator*(const CoordType &scale) const;
00142
00143 virtual Vertex<CoordType> operator+(const Vertex &other) const;
00144
00145
00149 virtual Vertex<CoordType> operator-(const Vertex &other) const;
00150
00154 virtual void operator-=(const Vertex &other);
00155
00159 virtual void operator+=(const Vertex<CoordType> &other);
00160
00161
00165 virtual void operator*=(const CoordType &scale);
00166
00167
00171 virtual void operator/=(const CoordType &scale);
00172
00176 virtual bool operator==(const Vertex &other) const;
00177
00181 virtual bool operator!=(const Vertex &other) const
00182 {
00183 return !(*this == other);
00184 }
00185
00189 virtual CoordType operator[](const int &index) const;
00190
00194 virtual CoordType& operator[](const int &index);
00195
00196
00198 CoordType m_x;
00199
00201 CoordType m_y;
00202
00204 CoordType m_z;
00205
00206 private:
00207
00209 static const float epsilon = 0.001;
00210 };
00211
00212
00216 template<typename CoordType>
00217 inline ostream& operator<<(ostream& os, const Vertex<CoordType> v){
00218 os << "Vertex: " << v.m_x << " " << v.m_y << " " << v.m_z << endl;
00219 return os;
00220 }
00221
00222
00224 typedef Vertex<float> Vertexf;
00225
00227 typedef Vertex<double> Vertexd;
00228
00229 }
00230
00231 #include "Vertex.tcc"
00232
00233 #endif