vector_3d.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053 #ifndef LASS_GUARDIAN_OF_INCLUSION_PRIM_VECTOR_3D_H
00054 #define LASS_GUARDIAN_OF_INCLUSION_PRIM_VECTOR_3D_H
00055
00056
00057
00058
00059 #include "prim_common.h"
00060 #include "../io/xml_o_stream.h"
00061
00062
00063
00064 namespace lass
00065 {
00066
00067 namespace prim
00068 {
00069
00070 template<typename T>
00071 struct Vector3D
00072 {
00073 typedef Vector3D<T> TSelf;
00074
00075 typedef typename util::CallTraits<T>::TValue TValue;
00076 typedef typename util::CallTraits<T>::TParam TParam;
00077 typedef typename util::CallTraits<T>::TReference TReference;
00078 typedef typename util::CallTraits<T>::TConstReference TConstReference;
00079 typedef num::NumTraits<T> TNumTraits;
00080
00081 enum { dimension = 3 };
00082
00083 template <typename U> struct Rebind
00084 {
00085 typedef Vector3D<U> Type;
00086 };
00087
00088
00089
00090
00091 TValue x;
00092 TValue y;
00093 TValue z;
00094
00095
00096
00097
00098 Vector3D();
00099 Vector3D(TParam x, TParam y, TParam z);
00100 template <typename U> explicit Vector3D(const Vector3D<U>& other);
00101 template <typename U> Vector3D(const U& x, const U& y, const U& z);
00102
00103 typename Vector3D::TConstReference operator[](size_t index) const;
00104 typename Vector3D::TReference operator[](size_t index) ;
00105 typename Vector3D::TConstReference at(signed index) const;
00106 typename Vector3D::TReference at(signed index);
00107
00108 const Vector3D<T>& operator+() const;
00109 const Vector3D<T> operator-() const;
00110 Vector3D<T>& operator+=(const Vector3D<T>& other);
00111 Vector3D<T>& operator-=(const Vector3D<T>& other);
00112 Vector3D<T>& operator*=(const Vector3D<T>& other);
00113 Vector3D<T>& operator/=(const Vector3D<T>& other);
00114 Vector3D<T>& operator+=(TParam other);
00115 Vector3D<T>& operator-=(TParam other);
00116 Vector3D<T>& operator*=(TParam other);
00117 Vector3D<T>& operator/=(TParam other);
00118
00119 const bool isZero() const;
00120 const bool isNaN() const;
00121 const TValue squaredNorm() const;
00122 const TValue norm() const;
00123 const Vector3D<T> normal() const;
00124 const Vector3D<T> reciprocal() const;
00125 const Vector3D<T> project(const Vector3D<T>& other) const;
00126 const Vector3D<T> reject(const Vector3D<T>& other) const;
00127 const Vector3D<T> reflect(const Vector3D<T>& other) const;
00128 const Vector3D<T> transform(T (*op)(T)) const;
00129
00130 void normalize();
00131
00132 template <class RandomGenerator> static Vector3D<T> random(RandomGenerator& generator);
00133 };
00134
00135 template<typename T> typename Vector3D<T>::TValue dot(const Vector3D<T>& a, const Vector3D<T>& b);
00136 template<typename T> Vector3D<T> cross(const Vector3D<T>& a, const Vector3D<T>& b);
00137
00138 template<typename T> bool operator==(const Vector3D<T>& a, const Vector3D<T>& b);
00139 template<typename T> bool operator!=(const Vector3D<T>& a, const Vector3D<T>& b);
00140
00141 template<typename T> Vector3D<T> operator+(const Vector3D<T>& a, const Vector3D<T>& b);
00142 template<typename T> Vector3D<T> operator-(const Vector3D<T>& a, const Vector3D<T>& b);
00143 template<typename T> Vector3D<T> operator*(const Vector3D<T>& a, const Vector3D<T>& b);
00144 template<typename T> Vector3D<T> operator/(const Vector3D<T>& a, const Vector3D<T>& b);
00145
00146 template<typename T> Vector3D<T> operator+(const Vector3D<T>& a, typename Vector3D<T>::TParam b);
00147 template<typename T> Vector3D<T> operator-(const Vector3D<T>& a, typename Vector3D<T>::TParam b);
00148 template<typename T> Vector3D<T> operator*(const Vector3D<T>& a, typename Vector3D<T>::TParam b);
00149 template<typename T> Vector3D<T> operator/(const Vector3D<T>& a, typename Vector3D<T>::TParam b);
00150
00151 template<typename T> Vector3D<T> operator+(typename Vector3D<T>::TParam a, const Vector3D<T>& b);
00152 template<typename T> Vector3D<T> operator-(typename Vector3D<T>::TParam a, const Vector3D<T>& b);
00153 template<typename T> Vector3D<T> operator*(typename Vector3D<T>::TParam a, const Vector3D<T>& b);
00154
00155
00156 template<typename T> Vector3D<T> pointwiseMin(const Vector3D<T>& a, const Vector3D<T>& b);
00157 template<typename T> Vector3D<T> pointwiseMax(const Vector3D<T>& a, const Vector3D<T>& b);
00158
00159 template <typename T> Vector3D<T> lerp(const Vector3D<T>& a, const Vector3D<T>& b, typename Vector3D<T>::TParam t);
00160
00161 template<typename T, typename Char, typename Traits>
00162 std::basic_ostream<Char, Traits>& operator<<(std::basic_ostream<Char, Traits>& stream, const Vector3D<T>& b);
00163 template<typename T, typename Char, typename Traits>
00164 std::basic_istream<Char, Traits>& operator>>(std::basic_istream<Char, Traits>& stream, Vector3D<T>& b);
00165
00166 template<typename T> io::XmlOStream& operator<<(io::XmlOStream& stream, const Vector3D<T>& b);
00167
00168
00169
00170 }
00171
00172 }
00173
00174 #include "vector_3d.inl"
00175
00176 #define LASS_PRIM_HAVE_PY_EXPORT_TRAITS_VECTOR_3D
00177 #ifdef LASS_GUARDIAN_OF_INCLUSION_UTIL_PYOBJECT_PLUS_H
00178 # include "pyobject_util.h"
00179 #endif
00180
00181 #endif