00001 /* 00002 * Normal.hpp 00003 * 00004 * Created on: 04.02.2011 00005 * Author: Thomas Wiemann 00006 */ 00007 00008 #ifndef NORMAL_HPP_ 00009 #define NORMAL_HPP_ 00010 00011 00012 #include "./Vertex.hpp" 00013 00014 namespace lssr { 00015 00020 template<typename CoordType> 00021 class Normal : public lssr::Vertex<CoordType> 00022 { 00023 00024 public: 00025 00030 Normal() : Vertex<CoordType>() {}; 00031 00036 Normal(CoordType x, CoordType y, CoordType z) 00037 : Vertex<CoordType>(x, y, z) 00038 { 00039 normalize(); 00040 } 00041 00046 template<typename T> 00047 Normal(const Vertex<T> &other) : Vertex<T>(other) 00048 { 00049 normalize(); 00050 } 00051 00056 template<typename T> 00057 Normal(const Normal &other) 00058 { 00059 this.m_x = other.m_x; 00060 this.m_y = other.m_y; 00061 this.m_z = other.m_z; 00062 } 00063 00064 virtual ~Normal(){}; 00065 00069 void normalize(); 00070 00071 Normal<CoordType> operator+(const Normal &n) const 00072 { 00073 return Normal<CoordType>(this->m_x + n.m_x, this->m_y + n.m_y, this->m_z + n.m_z); 00074 } 00075 00076 virtual Normal<CoordType> operator-(const Normal &n) const 00077 { 00078 return Normal<CoordType>(this->m_x - n.m_x, this->m_y - n.m_y, this->m_z - n.m_z); 00079 } 00080 00081 void operator+=(const Normal &n) 00082 { 00083 *this = *this + n; 00084 } 00085 00086 void operator-=(const Normal &n) 00087 { 00088 *this = *this + n; 00089 00090 } 00091 }; 00092 00093 typedef Normal<float> Normalf; 00094 00095 typedef Normal<double> Normald; 00096 00097 template<typename T> 00098 inline ostream& operator<<(ostream& os, const Normal<T> &n) 00099 { 00100 os << "Normal: " << n.x << " " << n.y << " " << n.z << endl; 00101 return os; 00102 } 00103 00104 } // namespace lssr 00105 00106 #include "Normal.tcc" 00107 00108 #endif /* NORMAL_HPP_ */