This class represents a polymorphic 3-dimensional vector. More...
#include "Vector3.hpp"
Public Member Functions | |
Vector3T () | |
The default constructor. It initializes all components to zero. More... | |
Vector3T (T x_, T y_, T z_) | |
This constructor initializes the components from x_, y_ and z_ respectively. More... | |
template<class C > | |
Vector3T (const C Values[]) | |
This constructor initializes the components from an array of (at least) three Ts. More... | |
bool | IsValid () const |
Returns true if the vector is valid, that is, all components are non-NANs. More... | |
T & | operator[] (unsigned int Index) |
Component access by index number (0 to 2) rather than by name. More... | |
const T & | operator[] (unsigned int Index) const |
Component access by index number (0 to 2) rather than by name. More... | |
Vector3T< float > | AsVectorOfFloat () const |
Gets this Vector3T<T> as a Vector3T<float>, so that the cast is explicitly visible in user code. More... | |
Vector3T< double > | AsVectorOfDouble () const |
Gets this Vector3T<T> as a Vector3T<double>, so that the cast is explicitly visible in user code. More... | |
Vector3T< int > | AsVectorOfInt () const |
Gets this Vector3T<T> as a Vector3T<int>, so that the cast is explicitly visible in user code. More... | |
Group of const inspector methods. They are all const and thus do not modify this object. | |
T | GetLengthSqr () const |
Returns the square of the length of this vector. More... | |
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 geometrically closer to B than Epsilon. More... | |
Vector3T< T > | GetScaled (const T s) const |
Returns a copy of this vector scaled by s, that is, the scalar product (Skalarmultiplikation) of this vector and s. More... | |
Vector3T< T > | GetScaled (const Vector3T< T > &S) const |
Returns a copy of this vector non-uniformely scaled by S. More... | |
Vector3T< T > | GetRotX (const T Angle) const |
Returns a copy of this vector rotated around the x-axis by Angle degrees. More... | |
Vector3T< T > | GetRotY (const T Angle) const |
Returns a copy of this vector rotated around the y-axis by Angle degrees. More... | |
Vector3T< T > | GetRotZ (const T Angle) const |
Returns a copy of this vector rotated around the z-axis by Angle degrees. More... | |
void | CreateOrthoVectors (Vector3T< T > &Left, Vector3T< T > &Down) const |
Returns two vectors that are orthogonal to this vector and to each other. More... | |
Group of (constructive) binary operators that do not modify their operands. | |
bool | operator== (const Vector3T< T > &B) const |
Returns whether this vector and B are truly (bit-wise) identical. More... | |
bool | operator!= (const Vector3T< T > &B) const |
Returns whether this vector and B are not equal (bit-wise). More... | |
Vector3T< T > | operator+ (const Vector3T< T > &B) const |
Returns the sum of this Vector3T<T> and B. More... | |
Vector3T< T > | operator- (const Vector3T< T > &B) const |
Returns the difference between this Vector3T<T> and B. More... | |
Vector3T< T > | operator- () const |
The unary minus operator. B=-A is quasi identical with B=A.GetScaled(-1). More... | |
Vector3T< T > | operator* (const T s) const |
Returns a copy of this vector scaled by s, that is, the scalar product (Skalarmultiplikation) of this vector and s. More... | |
Vector3T< T > | operator/ (const T s) const |
Returns a copy of this vector divided by s, that is, the scalar product (Skalarmultiplikation) of this vector and 1/s. More... | |
T | dot (const Vector3T< T > &B) const |
Returns the dot product (Skalarprodukt) of this vector and B. More... | |
Vector3T< T > | cross (const Vector3T< T > &B) const |
Returns the cross product (Vektorprodukt) of this vector and B. More... | |
Group of operators that modify this vector. | |
Vector3T< T > & | operator+= (const Vector3T< T > &B) |
Adds B to this vector. More... | |
Vector3T< T > & | operator-= (const Vector3T< T > &B) |
Subtracts B from this vector. More... | |
Vector3T< T > & | operator*= (const T s) |
Scales this vector by s. More... | |
Vector3T< T > & | operator/= (const T s) |
Divides this vector by s. Assumes that s is not 0. More... | |
Public Attributes | |
T | x |
The x-component of this vector. More... | |
T | y |
The y-component of this vector. More... | |
T | z |
The z-component of this vector. More... | |
This class represents a polymorphic 3-dimensional vector.
In order to clearly distinguish between methods that modify their "this" Vector3T<T> and those that don't, the general idea is that all const, non-modifying methods start with "Get", e.g. GetLength(). However the dot() and cross() methods are exceptions for increased readability of user code. Semantically and intuitively, we prefer to treat them as special binary infix operators as we do in hand-written math – its just the C++ language that doesn't provide us with appropriate symbols.
For operators, it is intuitively clear whether they modify the this object or not. E.g. the += operator modifies the this object, the + operator does not. Note that there is no need to define "constructive", binary infix operators (like the + operator) outside (that is, not as members) of this class, because promotion of the left-hand argument as described in the C++ FAQs does not occur in and thus is not relevant for this class (we have no constructor to promote a built-in type to a Vector3T<T>). See http://www.parashift.com/c++-faq-lite/operator-overloading.html#faq-13.9 items 5 to 7 (especially 7) and http://www.parashift.com/c++-faq-lite/friends.html#faq-14.5 for details about this.
The default constructor. It initializes all components to zero.
This constructor initializes the components from x_, y_ and z_ respectively.
This constructor initializes the components from an array of (at least) three Ts.
Gets this Vector3T<T> as a Vector3T<double>, so that the cast is explicitly visible in user code.
Gets this Vector3T<T> as a Vector3T<float>, so that the cast is explicitly visible in user code.
Gets this Vector3T<T> as a Vector3T<int>, so that the cast is explicitly visible in user code.
|
inline |
Returns two vectors that are orthogonal to this vector and to each other.
Returns the cross product (Vektorprodukt) of this vector and B.
Returns the dot product (Skalarprodukt) of this vector and B.
|
inline |
Returns the square of the length of this vector.
Returns a copy of this vector rotated around the x-axis by Angle degrees.
Returns a copy of this vector rotated around the y-axis by Angle degrees.
Returns a copy of this vector rotated around the z-axis by Angle degrees.
Returns a copy of this vector scaled by s, that is, the scalar product (Skalarmultiplikation) of this vector and s.
s | Scale factor to scale this vector by. |
Returns a copy of this vector non-uniformely scaled by S.
|
inline |
Returns whether this vector is equal to B within tolerance Epsilon, that is, whether it is geometrically closer to B than Epsilon.
B | Vector to compare to. |
Epsilon | Tolerance value. |
|
inline |
Returns true if the vector is valid, that is, all components are non-NANs.
Returns whether this vector and B are not equal (bit-wise).
Use this operator with care, as it comes without any epsilon threshold for taking rounding errors into account.
B | Vector to compare to. |
Returns a copy of this vector scaled by s, that is, the scalar product (Skalarmultiplikation) of this vector and s.
s | Factor to multiply this vector with. |
Scales this vector by s.
Returns the sum of this Vector3T<T> and B.
Adds B to this vector.
Returns the difference between this Vector3T<T> and B.
The unary minus operator. B=-A is quasi identical with B=A.GetScaled(-1).
Subtracts B from this vector.
Returns a copy of this vector divided by s, that is, the scalar product (Skalarmultiplikation) of this vector and 1/s.
Divides this vector by s. Assumes that s is not 0.
Returns whether this vector and B are truly (bit-wise) identical.
Use this operator with care, as it comes without any epsilon threshold for taking rounding errors into account.
B | Vector to compare to. |
|
inline |
Component access by index number (0 to 2) rather than by name.
Index | Index of the component to access. Can only be 0, 1 or 2 (for x, y, z). |
InvalidOperationE | if Index is not 0, 1 or 2. |
|
inline |
Component access by index number (0 to 2) rather than by name.
Index | Index of the component to access. Can only be 0, 1 or 2 (for x, y, z). |
InvalidOperationE | if Index is not 0, 1 or 2. |
T Vector3T< T >::x |
The x-component of this vector.
T Vector3T< T >::y |
The y-component of this vector.
T Vector3T< T >::z |
The z-component of this vector.