7 #ifndef CAFU_MATH_VECTOR3_HPP_INCLUDED
8 #define CAFU_MATH_VECTOR3_HPP_INCLUDED
50 Vector3T(T x_, T y_, T z_) : x(x_), y(y_), z(z_) { }
53 template<
class C>
explicit Vector3T(
const C Values[]) : x(T(Values[0])), y(T(Values[1])), z(T(Values[2])) { }
97 assert(
typeid(T)!=
typeid(
float));
107 assert(
typeid(T)!=
typeid(
double));
139 return (*
this-B).GetLengthSqr() <= Epsilon*Epsilon;
159 const T RadAngle=Angle*T(3.14159265358979323846/180.0);
160 const T SinAngle=sin(RadAngle);
161 const T CosAngle=cos(RadAngle);
164 CosAngle*y-SinAngle*
z,
165 SinAngle*y+CosAngle*
z);
171 const T RadAngle=Angle*T(3.14159265358979323846/180.0);
172 const T SinAngle=sin(RadAngle);
173 const T CosAngle=cos(RadAngle);
177 -SinAngle*x+CosAngle*
z);
183 const T RadAngle=Angle*T(3.14159265358979323846/180.0);
184 const T SinAngle=sin(RadAngle);
185 const T CosAngle=cos(RadAngle);
188 SinAngle*x+CosAngle*
y,
195 const T DistSqr=x*x+y*
y;
205 const T Dist=sqrt(DistSqr);
212 Down=Left.
cross(*
this);
280 return x*B.
x + y*B.
y + z*B.
z;
358 return A.
x*B.
x + A.
y*B.
y + A.
z*B.
z;
370 template<
class T>
inline T length(
const Vector3T<T>& A)
372 return sqrt(dot(A, A));
378 return sqrtf(dot(A, A));
385 const T Length=length(A);
396 const T Length=length(A);
398 return (Length>Epsilon) ? scale(A, T(1.0)/Length) :
Vector3T<T>(0, 0, 0);
401 template<
class T>
inline std::string convertToString(
const Vector3T<T>& A)
406 const int sigdigits=std::numeric_limits<T>::digits10 + 3;
408 std::ostringstream out;
410 out << std::setprecision(sigdigits) <<
"(" << A.
x <<
", " << A.
y <<
", " << A.
z <<
")";
416 template<
class T>
inline std::ostream& operator << (std::ostream& os, const Vector3T<T>& A)
418 return os <<
"(" << A.
x <<
", " << A.
y <<
", " << A.
z <<
")";
Vector3T< T > & operator/=(const T s)
Divides this vector by s. Assumes that s is not 0.
Definition: Vector3.hpp:329
Vector3T< double > AsVectorOfDouble() const
Gets this Vector3T<T> as a Vector3T<double>, so that the cast is explicitly visible in user code...
Definition: Vector3.hpp:104
Vector3T< T > & operator+=(const Vector3T< T > &B)
Adds B to this vector.
Definition: Vector3.hpp:299
Vector3T< T > & operator*=(const T s)
Scales this vector by s.
Definition: Vector3.hpp:319
Vector3T< float > AsVectorOfFloat() const
Gets this Vector3T<T> as a Vector3T<float>, so that the cast is explicitly visible in user code...
Definition: Vector3.hpp:94
Vector3T< T > operator*(const T s) const
Returns a copy of this vector scaled by s, that is, the scalar product (Skalarmultiplikation) of this...
Definition: Vector3.hpp:265
Vector3T< T > GetRotX(const T Angle) const
Returns a copy of this vector rotated around the x-axis by Angle degrees.
Definition: Vector3.hpp:157
T y
The y-component of this vector.
Definition: Vector3.hpp:41
This class represents a polymorphic 3-dimensional vector.
Definition: Misc.hpp:11
Vector3T< int > AsVectorOfInt() const
Gets this Vector3T<T> as a Vector3T<int>, so that the cast is explicitly visible in user code...
Definition: Vector3.hpp:114
void CreateOrthoVectors(Vector3T< T > &Left, Vector3T< T > &Down) const
Returns two vectors that are orthogonal to this vector and to each other.
Definition: Vector3.hpp:193
Vector3T< T > operator-() const
The unary minus operator. B=-A is quasi identical with B=A.GetScaled(-1).
Definition: Vector3.hpp:257
Vector3T< T > cross(const Vector3T< T > &B) const
Returns the cross product (Vektorprodukt) of this vector and B.
Definition: Vector3.hpp:284
T GetLengthSqr() const
Returns the square of the length of this vector.
Definition: Vector3.hpp:131
Invalid operation (invalid use of method, etc.).
Definition: Errors.hpp:33
bool IsEqual(const Vector3T< T > &B, const T Epsilon) const
Returns whether this vector is equal to B within tolerance Epsilon, that is, whether it is geometrica...
Definition: Vector3.hpp:137
Vector3T(const C Values[])
This constructor initializes the components from an array of (at least) three Ts. ...
Definition: Vector3.hpp:53
Vector3T< T > operator/(const T s) const
Returns a copy of this vector divided by s, that is, the scalar product (Skalarmultiplikation) of thi...
Definition: Vector3.hpp:271
bool IsValid() const
Returns true if the vector is valid, that is, all components are non-NANs.
Definition: Vector3.hpp:58
Vector3T< T > & operator-=(const Vector3T< T > &B)
Subtracts B from this vector.
Definition: Vector3.hpp:309
Vector3T()
The default constructor. It initializes all components to zero.
Definition: Vector3.hpp:47
Vector3T< T > GetRotZ(const T Angle) const
Returns a copy of this vector rotated around the z-axis by Angle degrees.
Definition: Vector3.hpp:181
bool operator==(const Vector3T< T > &B) const
Returns whether this vector and B are truly (bit-wise) identical.
Definition: Vector3.hpp:226
Vector3T(T x_, T y_, T z_)
This constructor initializes the components from x_, y_ and z_ respectively.
Definition: Vector3.hpp:50
Vector3T< T > GetScaled(const Vector3T< T > &S) const
Returns a copy of this vector non-uniformely scaled by S.
Definition: Vector3.hpp:151
T dot(const Vector3T< T > &B) const
Returns the dot product (Skalarprodukt) of this vector and B.
Definition: Vector3.hpp:278
T z
The z-component of this vector.
Definition: Vector3.hpp:42
bool operator!=(const Vector3T< T > &B) const
Returns whether this vector and B are not equal (bit-wise).
Definition: Vector3.hpp:237
Vector3T< T > operator+(const Vector3T< T > &B) const
Returns the sum of this Vector3T<T> and B.
Definition: Vector3.hpp:245
T x
The x-component of this vector.
Definition: Vector3.hpp:40
Vector3T< T > GetRotY(const T Angle) const
Returns a copy of this vector rotated around the y-axis by Angle degrees.
Definition: Vector3.hpp:169
Vector3T< T > GetScaled(const T s) const
Returns a copy of this vector scaled by s, that is, the scalar product (Skalarmultiplikation) of this...
Definition: Vector3.hpp:145
Division by zero error.
Definition: Errors.hpp:24
T & operator[](unsigned int Index)
Component access by index number (0 to 2) rather than by name.
Definition: Vector3.hpp:66