arsa  2.7
Public Member Functions | Public Attributes | List of all members
irr::core::vector3d< T > Class Template Reference

3d vector template class with lots of operators and methods. More...

#include <vector3d.h>

Public Member Functions

 vector3d ()
 Default constructor (null vector). More...
 
 vector3d (T nx, T ny, T nz)
 Constructor with three different values. More...
 
 vector3d (T n)
 Constructor with the same value for all elements. More...
 
 vector3d (const vector3d< T > &other)
 Copy constructor. More...
 
vector3d< T > operator- () const
 
vector3d< T > & operator= (const vector3d< T > &other)
 
vector3d< T > operator+ (const vector3d< T > &other) const
 
vector3d< T > & operator+= (const vector3d< T > &other)
 
vector3d< T > operator+ (const T val) const
 
vector3d< T > & operator+= (const T val)
 
vector3d< T > operator- (const vector3d< T > &other) const
 
vector3d< T > & operator-= (const vector3d< T > &other)
 
vector3d< T > operator- (const T val) const
 
vector3d< T > & operator-= (const T val)
 
vector3d< T > operator * (const vector3d< T > &other) const
 
vector3d< T > & operator *= (const vector3d< T > &other)
 
vector3d< T > operator * (const T v) const
 
vector3d< T > & operator *= (const T v)
 
vector3d< T > operator/ (const vector3d< T > &other) const
 
vector3d< T > & operator/= (const vector3d< T > &other)
 
vector3d< T > operator/ (const T v) const
 
vector3d< T > & operator/= (const T v)
 
T & operator [] (u32 index)
 
const T & operator [] (u32 index) const
 
bool operator<= (const vector3d< T > &other) const
 sort in order X, Y, Z. Equality with rounding tolerance. More...
 
bool operator>= (const vector3d< T > &other) const
 sort in order X, Y, Z. Equality with rounding tolerance. More...
 
bool operator< (const vector3d< T > &other) const
 sort in order X, Y, Z. Difference must be above rounding tolerance. More...
 
bool operator> (const vector3d< T > &other) const
 sort in order X, Y, Z. Difference must be above rounding tolerance. More...
 
bool operator== (const vector3d< T > &other) const
 use weak float compare More...
 
bool operator!= (const vector3d< T > &other) const
 
bool equals (const vector3d< T > &other, const T tolerance=(T) ROUNDING_ERROR_f32) const
 returns if this vector equals the other one, taking floating point rounding errors into account More...
 
vector3d< T > & set (const T nx, const T ny, const T nz)
 
vector3d< T > & set (const vector3d< T > &p)
 
getLength () const
 Get length of the vector. More...
 
getLengthSQ () const
 Get squared length of the vector. More...
 
dotProduct (const vector3d< T > &other) const
 Get the dot product with another vector. More...
 
getDistanceFrom (const vector3d< T > &other) const
 Get distance from another point. More...
 
getDistanceFromSQ (const vector3d< T > &other) const
 Returns squared distance from another point. More...
 
vector3d< T > crossProduct (const vector3d< T > &p) const
 Calculates the cross product with another vector. More...
 
bool isBetweenPoints (const vector3d< T > &begin, const vector3d< T > &end) const
 Returns if this vector interpreted as a point is on a line between two other points. More...
 
vector3d< T > & normalize ()
 Normalizes the vector. More...
 
vector3d< T > & setLength (T newlength)
 Sets the length of the vector to a new value. More...
 
vector3d< T > & invert ()
 Inverts the vector. More...
 
void rotateXZBy (f64 degrees, const vector3d< T > &center=vector3d< T >())
 Rotates the vector by a specified number of degrees around the Y axis and the specified center. More...
 
void rotateXYBy (f64 degrees, const vector3d< T > &center=vector3d< T >())
 Rotates the vector by a specified number of degrees around the Z axis and the specified center. More...
 
void rotateYZBy (f64 degrees, const vector3d< T > &center=vector3d< T >())
 Rotates the vector by a specified number of degrees around the X axis and the specified center. More...
 
vector3d< T > getInterpolated (const vector3d< T > &other, f64 d) const
 Creates an interpolated vector between this vector and another vector. More...
 
vector3d< T > getInterpolated_quadratic (const vector3d< T > &v2, const vector3d< T > &v3, f64 d) const
 Creates a quadratically interpolated vector between this and two other vectors. More...
 
vector3d< T > & interpolate (const vector3d< T > &a, const vector3d< T > &b, f64 d)
 Sets this vector to the linearly interpolated vector between a and b. More...
 
vector3d< T > getHorizontalAngle () const
 Get the rotations that would make a (0,0,1) direction vector point in the same direction as this direction vector. More...
 
vector3d< T > getSphericalCoordinateAngles () const
 Get the spherical coordinate angles. More...
 
vector3d< T > rotationToDirection (const vector3d< T > &forwards=vector3d< T >(0, 0, 1)) const
 Builds a direction vector from (this) rotation vector. More...
 
void getAs4Values (T *array) const
 Fills an array of 4 values with the vector data (usually floats). More...
 
void getAs3Values (T *array) const
 Fills an array of 3 values with the vector data (usually floats). More...
 
template<>
vector3d< s32operator/ (s32 val) const
 partial specialization for integer vectors More...
 
template<>
vector3d< s32 > & operator/= (s32 val)
 
template<>
vector3d< s32getSphericalCoordinateAngles () const
 

Public Attributes

X
 X coordinate of the vector. More...
 
Y
 Y coordinate of the vector. More...
 
Z
 Z coordinate of the vector. More...
 

Detailed Description

template<class T>
class irr::core::vector3d< T >

3d vector template class with lots of operators and methods.

The vector3d class is used in Irrlicht for three main purposes: 1) As a direction vector (most of the methods assume this). 2) As a position in 3d space (which is synonymous with a direction vector from the origin to this position). 3) To hold three Euler rotations, where X is pitch, Y is yaw and Z is roll.

Definition at line 22 of file vector3d.h.

Constructor & Destructor Documentation

◆ vector3d() [1/4]

template<class T>
irr::core::vector3d< T >::vector3d ( )
inline

Default constructor (null vector).

Definition at line 26 of file vector3d.h.

26 : X(0), Y(0), Z(0) {}
T Y
Y coordinate of the vector.
Definition: vector3d.h:427
T X
X coordinate of the vector.
Definition: vector3d.h:424
T Z
Z coordinate of the vector.
Definition: vector3d.h:430

◆ vector3d() [2/4]

template<class T>
irr::core::vector3d< T >::vector3d ( nx,
ny,
nz 
)
inline

Constructor with three different values.

Definition at line 28 of file vector3d.h.

28 : X(nx), Y(ny), Z(nz) {}
T Y
Y coordinate of the vector.
Definition: vector3d.h:427
T X
X coordinate of the vector.
Definition: vector3d.h:424
GLfixed ny
GLbyte nx
GLfixed GLfixed nz
T Z
Z coordinate of the vector.
Definition: vector3d.h:430

◆ vector3d() [3/4]

template<class T>
irr::core::vector3d< T >::vector3d ( n)
inlineexplicit

Constructor with the same value for all elements.

Definition at line 30 of file vector3d.h.

30 : X(n), Y(n), Z(n) {}
T Y
Y coordinate of the vector.
Definition: vector3d.h:427
GLdouble n
T X
X coordinate of the vector.
Definition: vector3d.h:424
T Z
Z coordinate of the vector.
Definition: vector3d.h:430

◆ vector3d() [4/4]

template<class T>
irr::core::vector3d< T >::vector3d ( const vector3d< T > &  other)
inline

Copy constructor.

Definition at line 32 of file vector3d.h.

32 : X(other.X), Y(other.Y), Z(other.Z) {}
T Y
Y coordinate of the vector.
Definition: vector3d.h:427
T X
X coordinate of the vector.
Definition: vector3d.h:424
T Z
Z coordinate of the vector.
Definition: vector3d.h:430

Member Function Documentation

◆ crossProduct()

template<class T>
vector3d<T> irr::core::vector3d< T >::crossProduct ( const vector3d< T > &  p) const
inline

Calculates the cross product with another vector.

Parameters
pVector to multiply with.
Returns
Crossproduct of this vector with p.

Definition at line 161 of file vector3d.h.

162  {
163  return vector3d<T>(Y * p.Z - Z * p.Y, Z * p.X - X * p.Z, X * p.Y - Y * p.X);
164  }
T Y
Y coordinate of the vector.
Definition: vector3d.h:427
GLfloat GLfloat p
T X
X coordinate of the vector.
Definition: vector3d.h:424
T Z
Z coordinate of the vector.
Definition: vector3d.h:430

◆ dotProduct()

template<class T>
T irr::core::vector3d< T >::dotProduct ( const vector3d< T > &  other) const
inline

Get the dot product with another vector.

Definition at line 139 of file vector3d.h.

140  {
141  return X*other.X + Y*other.Y + Z*other.Z;
142  }
T Y
Y coordinate of the vector.
Definition: vector3d.h:427
T X
X coordinate of the vector.
Definition: vector3d.h:424
T Z
Z coordinate of the vector.
Definition: vector3d.h:430

◆ equals()

template<class T>
bool irr::core::vector3d< T >::equals ( const vector3d< T > &  other,
const tolerance = (T)ROUNDING_ERROR_f32 
) const
inline

returns if this vector equals the other one, taking floating point rounding errors into account

Definition at line 120 of file vector3d.h.

121  {
122  return core::equals(X, other.X, tolerance) &&
123  core::equals(Y, other.Y, tolerance) &&
124  core::equals(Z, other.Z, tolerance);
125  }
T Y
Y coordinate of the vector.
Definition: vector3d.h:427
T X
X coordinate of the vector.
Definition: vector3d.h:424
bool equals(const T a, const T b, const T tolerance=roundingError< T >())
returns if a equals b, taking possible rounding errors into account
Definition: irrMath.h:246
T Z
Z coordinate of the vector.
Definition: vector3d.h:430

◆ getAs3Values()

template<class T>
void irr::core::vector3d< T >::getAs3Values ( T *  array) const
inline

Fills an array of 3 values with the vector data (usually floats).

Useful for setting in shader constants for example.

Definition at line 415 of file vector3d.h.

416  {
417  array[0] = X;
418  array[1] = Y;
419  array[2] = Z;
420  }
T Y
Y coordinate of the vector.
Definition: vector3d.h:427
T X
X coordinate of the vector.
Definition: vector3d.h:424
T Z
Z coordinate of the vector.
Definition: vector3d.h:430
GLenum array

◆ getAs4Values()

template<class T>
void irr::core::vector3d< T >::getAs4Values ( T *  array) const
inline

Fills an array of 4 values with the vector data (usually floats).

Useful for setting in shader constants for example. The fourth value will always be 0.

Definition at line 405 of file vector3d.h.

406  {
407  array[0] = X;
408  array[1] = Y;
409  array[2] = Z;
410  array[3] = 0;
411  }
T Y
Y coordinate of the vector.
Definition: vector3d.h:427
T X
X coordinate of the vector.
Definition: vector3d.h:424
T Z
Z coordinate of the vector.
Definition: vector3d.h:430
GLenum array

◆ getDistanceFrom()

template<class T>
T irr::core::vector3d< T >::getDistanceFrom ( const vector3d< T > &  other) const
inline

Get distance from another point.

Here, the vector is interpreted as point in 3 dimensional space.

Definition at line 146 of file vector3d.h.

147  {
148  return vector3d<T>(X - other.X, Y - other.Y, Z - other.Z).getLength();
149  }
T Y
Y coordinate of the vector.
Definition: vector3d.h:427
T X
X coordinate of the vector.
Definition: vector3d.h:424
T Z
Z coordinate of the vector.
Definition: vector3d.h:430

◆ getDistanceFromSQ()

template<class T>
T irr::core::vector3d< T >::getDistanceFromSQ ( const vector3d< T > &  other) const
inline

Returns squared distance from another point.

Here, the vector is interpreted as point in 3 dimensional space.

Definition at line 153 of file vector3d.h.

154  {
155  return vector3d<T>(X - other.X, Y - other.Y, Z - other.Z).getLengthSQ();
156  }
T Y
Y coordinate of the vector.
Definition: vector3d.h:427
T X
X coordinate of the vector.
Definition: vector3d.h:424
T Z
Z coordinate of the vector.
Definition: vector3d.h:430

◆ getHorizontalAngle()

template<class T>
vector3d<T> irr::core::vector3d< T >::getHorizontalAngle ( ) const
inline

Get the rotations that would make a (0,0,1) direction vector point in the same direction as this direction vector.

Thanks to Arras on the Irrlicht forums for this method. This utility method is very useful for orienting scene nodes towards specific targets. For example, if this vector represents the difference between two scene nodes, then applying the result of getHorizontalAngle() to one scene node will point it at the other one. Example code: Where target and seeker are of type ISceneNode* const vector3df toTarget(target->getAbsolutePosition() - seeker->getAbsolutePosition()); const vector3df requiredRotation = toTarget.getHorizontalAngle(); seeker->setRotation(requiredRotation);

Returns
A rotation vector containing the X (pitch) and Y (raw) rotations (in degrees) that when applied to a +Z (e.g. 0, 0, 1) direction vector would make it point in the same direction as this vector. The Z (roll) rotation is always 0, since two Euler rotations are sufficient to point in any given direction.

Definition at line 315 of file vector3d.h.

316  {
317  vector3d<T> angle;
318 
319  // tmp avoids some precision troubles on some compilers when working with T=s32
320  f64 tmp = (atan2((f64)X, (f64)Z) * RADTODEG64);
321  angle.Y = (T)tmp;
322 
323  if (angle.Y < 0)
324  angle.Y += 360;
325  if (angle.Y >= 360)
326  angle.Y -= 360;
327 
328  const f64 z1 = core::squareroot(X*X + Z*Z);
329 
330  tmp = (atan2((f64)z1, (f64)Y) * RADTODEG64 - 90.0);
331  angle.X = (T)tmp;
332 
333  if (angle.X < 0)
334  angle.X += 360;
335  if (angle.X >= 360)
336  angle.X -= 360;
337 
338  return angle;
339  }
const f64 RADTODEG64
64bit constant for converting from radians to degrees
Definition: irrMath.h:84
T Y
Y coordinate of the vector.
Definition: vector3d.h:427
REALINLINE f32 squareroot(const f32 f)
Definition: irrMath.h:495
T X
X coordinate of the vector.
Definition: vector3d.h:424
double f64
64 bit floating point variable.
Definition: irrTypes.h:112
T Z
Z coordinate of the vector.
Definition: vector3d.h:430
GLfloat angle

◆ getInterpolated()

template<class T>
vector3d<T> irr::core::vector3d< T >::getInterpolated ( const vector3d< T > &  other,
f64  d 
) const
inline

Creates an interpolated vector between this vector and another vector.

Parameters
otherThe other vector to interpolate with.
dInterpolation value between 0.0f (all the other vector) and 1.0f (all this vector). Note that this is the opposite direction of interpolation to getInterpolated_quadratic()
Returns
An interpolated vector. This vector is not modified.

Definition at line 261 of file vector3d.h.

262  {
263  const f64 inv = 1.0 - d;
264  return vector3d<T>((T)(other.X*inv + X*d), (T)(other.Y*inv + Y*d), (T)(other.Z*inv + Z*d));
265  }
T Y
Y coordinate of the vector.
Definition: vector3d.h:427
T X
X coordinate of the vector.
Definition: vector3d.h:424
double f64
64 bit floating point variable.
Definition: irrTypes.h:112
T Z
Z coordinate of the vector.
Definition: vector3d.h:430

◆ getInterpolated_quadratic()

template<class T>
vector3d<T> irr::core::vector3d< T >::getInterpolated_quadratic ( const vector3d< T > &  v2,
const vector3d< T > &  v3,
f64  d 
) const
inline

Creates a quadratically interpolated vector between this and two other vectors.

Parameters
v2Second vector to interpolate with.
v3Third vector to interpolate with (maximum at 1.0f)
dInterpolation value between 0.0f (all this vector) and 1.0f (all the 3rd vector). Note that this is the opposite direction of interpolation to getInterpolated() and interpolate()
Returns
An interpolated vector. This vector is not modified.

Definition at line 273 of file vector3d.h.

274  {
275  // this*(1-d)*(1-d) + 2 * v2 * (1-d) + v3 * d * d;
276  const f64 inv = (T) 1.0 - d;
277  const f64 mul0 = inv * inv;
278  const f64 mul1 = (T) 2.0 * d * inv;
279  const f64 mul2 = d * d;
280 
281  return vector3d<T> ((T)(X * mul0 + v2.X * mul1 + v3.X * mul2),
282  (T)(Y * mul0 + v2.Y * mul1 + v3.Y * mul2),
283  (T)(Z * mul0 + v2.Z * mul1 + v3.Z * mul2));
284  }
T Y
Y coordinate of the vector.
Definition: vector3d.h:427
T X
X coordinate of the vector.
Definition: vector3d.h:424
GLfloat GLfloat GLfloat v2
double f64
64 bit floating point variable.
Definition: irrTypes.h:112
GLfloat GLfloat GLfloat GLfloat v3
T Z
Z coordinate of the vector.
Definition: vector3d.h:430

◆ getLength()

template<class T>
T irr::core::vector3d< T >::getLength ( ) const
inline

Get length of the vector.

Definition at line 131 of file vector3d.h.

131 { return core::squareroot( X*X + Y*Y + Z*Z ); }
T Y
Y coordinate of the vector.
Definition: vector3d.h:427
REALINLINE f32 squareroot(const f32 f)
Definition: irrMath.h:495
T X
X coordinate of the vector.
Definition: vector3d.h:424
T Z
Z coordinate of the vector.
Definition: vector3d.h:430

◆ getLengthSQ()

template<class T>
T irr::core::vector3d< T >::getLengthSQ ( ) const
inline

Get squared length of the vector.

This is useful because it is much faster than getLength().

Returns
Squared length of the vector.

Definition at line 136 of file vector3d.h.

136 { return X*X + Y*Y + Z*Z; }
T Y
Y coordinate of the vector.
Definition: vector3d.h:427
T X
X coordinate of the vector.
Definition: vector3d.h:424
T Z
Z coordinate of the vector.
Definition: vector3d.h:430

◆ getSphericalCoordinateAngles() [1/2]

template<class T>
vector3d<T> irr::core::vector3d< T >::getSphericalCoordinateAngles ( ) const
inline

Get the spherical coordinate angles.

This returns Euler degrees for the point represented by this vector. The calculation assumes the pole at (0,1,0) and returns the angles in X and Y.

Definition at line 346 of file vector3d.h.

347  {
348  vector3d<T> angle;
349  const f64 length = X*X + Y*Y + Z*Z;
350 
351  if (length)
352  {
353  if (X!=0)
354  {
355  angle.Y = (T)(atan2((f64)Z,(f64)X) * RADTODEG64);
356  }
357  else if (Z<0)
358  angle.Y=180;
359 
361  }
362  return angle;
363  }
const f64 RADTODEG64
64bit constant for converting from radians to degrees
Definition: irrMath.h:84
T Y
Y coordinate of the vector.
Definition: vector3d.h:427
T X
X coordinate of the vector.
Definition: vector3d.h:424
double f64
64 bit floating point variable.
Definition: irrTypes.h:112
T Z
Z coordinate of the vector.
Definition: vector3d.h:430
GLfloat angle
GLuint GLsizei GLsizei * length
REALINLINE f64 reciprocal_squareroot(const f64 x)
Definition: irrMath.h:521

◆ getSphericalCoordinateAngles() [2/2]

template<>
vector3d< s32 > irr::core::vector3d< s32 >::getSphericalCoordinateAngles ( ) const
inline

Definition at line 441 of file vector3d.h.

442  {
443  vector3d<s32> angle;
444  const f64 length = X*X + Y*Y + Z*Z;
445 
446  if (length)
447  {
448  if (X!=0)
449  {
450  angle.Y = round32((f32)(atan2((f64)Z,(f64)X) * RADTODEG64));
451  }
452  else if (Z<0)
453  angle.Y=180;
454 
456  }
457  return angle;
458  }
const f64 RADTODEG64
64bit constant for converting from radians to degrees
Definition: irrMath.h:84
REALINLINE s32 round32(f32 x)
Definition: irrMath.h:657
T Y
Y coordinate of the vector.
Definition: vector3d.h:427
float f32
32 bit floating point variable.
Definition: irrTypes.h:108
T X
X coordinate of the vector.
Definition: vector3d.h:424
double f64
64 bit floating point variable.
Definition: irrTypes.h:112
T Z
Z coordinate of the vector.
Definition: vector3d.h:430
GLfloat angle
GLuint GLsizei GLsizei * length
REALINLINE f64 reciprocal_squareroot(const f64 x)
Definition: irrMath.h:521

◆ interpolate()

template<class T>
vector3d<T>& irr::core::vector3d< T >::interpolate ( const vector3d< T > &  a,
const vector3d< T > &  b,
f64  d 
)
inline

Sets this vector to the linearly interpolated vector between a and b.

Parameters
afirst vector to interpolate with, maximum at 1.0f
bsecond vector to interpolate with, maximum at 0.0f
dInterpolation value between 0.0f (all vector b) and 1.0f (all vector a) Note that this is the opposite direction of interpolation to getInterpolated_quadratic()

Definition at line 292 of file vector3d.h.

293  {
294  X = (T)((f64)b.X + ( ( a.X - b.X ) * d ));
295  Y = (T)((f64)b.Y + ( ( a.Y - b.Y ) * d ));
296  Z = (T)((f64)b.Z + ( ( a.Z - b.Z ) * d ));
297  return *this;
298  }
T Y
Y coordinate of the vector.
Definition: vector3d.h:427
T X
X coordinate of the vector.
Definition: vector3d.h:424
double f64
64 bit floating point variable.
Definition: irrTypes.h:112
GLboolean GLboolean GLboolean b
T Z
Z coordinate of the vector.
Definition: vector3d.h:430
GLboolean GLboolean GLboolean GLboolean a

◆ invert()

template<class T>
vector3d<T>& irr::core::vector3d< T >::invert ( )
inline

Inverts the vector.

Definition at line 203 of file vector3d.h.

204  {
205  X *= -1;
206  Y *= -1;
207  Z *= -1;
208  return *this;
209  }
T Y
Y coordinate of the vector.
Definition: vector3d.h:427
T X
X coordinate of the vector.
Definition: vector3d.h:424
T Z
Z coordinate of the vector.
Definition: vector3d.h:430

◆ isBetweenPoints()

template<class T>
bool irr::core::vector3d< T >::isBetweenPoints ( const vector3d< T > &  begin,
const vector3d< T > &  end 
) const
inline

Returns if this vector interpreted as a point is on a line between two other points.

It is assumed that the point is on the line.

Parameters
beginBeginning vector to compare between.
endEnding vector to compare between.
Returns
True if this vector is between begin and end, false if not.

Definition at line 171 of file vector3d.h.

172  {
173  const T f = (end - begin).getLengthSQ();
174  return getDistanceFromSQ(begin) <= f &&
175  getDistanceFromSQ(end) <= f;
176  }
T getDistanceFromSQ(const vector3d< T > &other) const
Returns squared distance from another point.
Definition: vector3d.h:153
GLuint GLuint end
Definition: SDL_opengl.h:1571
GLfloat f
T getLengthSQ() const
Get squared length of the vector.
Definition: vector3d.h:136

◆ normalize()

template<class T>
vector3d<T>& irr::core::vector3d< T >::normalize ( )
inline

Normalizes the vector.

In case of the 0 vector the result is still 0, otherwise the length of the vector will be 1.

Returns
Reference to this vector after normalization.

Definition at line 182 of file vector3d.h.

183  {
184  f64 length = X*X + Y*Y + Z*Z;
185  if (length == 0 ) // this check isn't an optimization but prevents getting NAN in the sqrt.
186  return *this;
188 
189  X = (T)(X * length);
190  Y = (T)(Y * length);
191  Z = (T)(Z * length);
192  return *this;
193  }
T Y
Y coordinate of the vector.
Definition: vector3d.h:427
T X
X coordinate of the vector.
Definition: vector3d.h:424
double f64
64 bit floating point variable.
Definition: irrTypes.h:112
T Z
Z coordinate of the vector.
Definition: vector3d.h:430
GLuint GLsizei GLsizei * length
REALINLINE f64 reciprocal_squareroot(const f64 x)
Definition: irrMath.h:521

◆ operator *() [1/2]

template<class T>
vector3d<T> irr::core::vector3d< T >::operator * ( const vector3d< T > &  other) const
inline

Definition at line 50 of file vector3d.h.

50 { return vector3d<T>(X * other.X, Y * other.Y, Z * other.Z); }
T Y
Y coordinate of the vector.
Definition: vector3d.h:427
T X
X coordinate of the vector.
Definition: vector3d.h:424
T Z
Z coordinate of the vector.
Definition: vector3d.h:430

◆ operator *() [2/2]

template<class T>
vector3d<T> irr::core::vector3d< T >::operator * ( const v) const
inline

Definition at line 52 of file vector3d.h.

52 { return vector3d<T>(X * v, Y * v, Z * v); }
T Y
Y coordinate of the vector.
Definition: vector3d.h:427
T X
X coordinate of the vector.
Definition: vector3d.h:424
const GLdouble * v
Definition: SDL_opengl.h:2064
T Z
Z coordinate of the vector.
Definition: vector3d.h:430

◆ operator *=() [1/2]

template<class T>
vector3d<T>& irr::core::vector3d< T >::operator *= ( const vector3d< T > &  other)
inline

Definition at line 51 of file vector3d.h.

51 { X*=other.X; Y*=other.Y; Z*=other.Z; return *this; }
T Y
Y coordinate of the vector.
Definition: vector3d.h:427
T X
X coordinate of the vector.
Definition: vector3d.h:424
T Z
Z coordinate of the vector.
Definition: vector3d.h:430

◆ operator *=() [2/2]

template<class T>
vector3d<T>& irr::core::vector3d< T >::operator *= ( const v)
inline

Definition at line 53 of file vector3d.h.

53 { X*=v; Y*=v; Z*=v; return *this; }
T Y
Y coordinate of the vector.
Definition: vector3d.h:427
T X
X coordinate of the vector.
Definition: vector3d.h:424
const GLdouble * v
Definition: SDL_opengl.h:2064
T Z
Z coordinate of the vector.
Definition: vector3d.h:430

◆ operator []() [1/2]

template<class T>
T& irr::core::vector3d< T >::operator [] ( u32  index)
inline

Definition at line 60 of file vector3d.h.

61  {
62  _IRR_DEBUG_BREAK_IF(index>2) // access violation
63 
64  return *(&X+index);
65  }
T X
X coordinate of the vector.
Definition: vector3d.h:424
#define _IRR_DEBUG_BREAK_IF(_CONDITION_)
define a break macro for debugging.
Definition: irrTypes.h:185
GLuint index

◆ operator []() [2/2]

template<class T>
const T& irr::core::vector3d< T >::operator [] ( u32  index) const
inline

Definition at line 67 of file vector3d.h.

68  {
69  _IRR_DEBUG_BREAK_IF(index>2) // access violation
70 
71  return *(&X+index);
72  }
T X
X coordinate of the vector.
Definition: vector3d.h:424
#define _IRR_DEBUG_BREAK_IF(_CONDITION_)
define a break macro for debugging.
Definition: irrTypes.h:185
GLuint index

◆ operator!=()

template<class T>
bool irr::core::vector3d< T >::operator!= ( const vector3d< T > &  other) const
inline

Definition at line 112 of file vector3d.h.

113  {
114  return !this->equals(other);
115  }
bool equals(const vector3d< T > &other, const T tolerance=(T) ROUNDING_ERROR_f32) const
returns if this vector equals the other one, taking floating point rounding errors into account
Definition: vector3d.h:120

◆ operator+() [1/2]

template<class T>
vector3d<T> irr::core::vector3d< T >::operator+ ( const vector3d< T > &  other) const
inline

Definition at line 40 of file vector3d.h.

40 { return vector3d<T>(X + other.X, Y + other.Y, Z + other.Z); }
T Y
Y coordinate of the vector.
Definition: vector3d.h:427
T X
X coordinate of the vector.
Definition: vector3d.h:424
T Z
Z coordinate of the vector.
Definition: vector3d.h:430

◆ operator+() [2/2]

template<class T>
vector3d<T> irr::core::vector3d< T >::operator+ ( const val) const
inline

Definition at line 42 of file vector3d.h.

42 { return vector3d<T>(X + val, Y + val, Z + val); }
T Y
Y coordinate of the vector.
Definition: vector3d.h:427
T X
X coordinate of the vector.
Definition: vector3d.h:424
GLuint GLfloat * val
T Z
Z coordinate of the vector.
Definition: vector3d.h:430

◆ operator+=() [1/2]

template<class T>
vector3d<T>& irr::core::vector3d< T >::operator+= ( const vector3d< T > &  other)
inline

Definition at line 41 of file vector3d.h.

41 { X+=other.X; Y+=other.Y; Z+=other.Z; return *this; }
T Y
Y coordinate of the vector.
Definition: vector3d.h:427
T X
X coordinate of the vector.
Definition: vector3d.h:424
T Z
Z coordinate of the vector.
Definition: vector3d.h:430

◆ operator+=() [2/2]

template<class T>
vector3d<T>& irr::core::vector3d< T >::operator+= ( const val)
inline

Definition at line 43 of file vector3d.h.

43 { X+=val; Y+=val; Z+=val; return *this; }
T Y
Y coordinate of the vector.
Definition: vector3d.h:427
T X
X coordinate of the vector.
Definition: vector3d.h:424
GLuint GLfloat * val
T Z
Z coordinate of the vector.
Definition: vector3d.h:430

◆ operator-() [1/3]

template<class T>
vector3d<T> irr::core::vector3d< T >::operator- ( ) const
inline

Definition at line 36 of file vector3d.h.

36 { return vector3d<T>(-X, -Y, -Z); }
T Y
Y coordinate of the vector.
Definition: vector3d.h:427
T X
X coordinate of the vector.
Definition: vector3d.h:424
T Z
Z coordinate of the vector.
Definition: vector3d.h:430

◆ operator-() [2/3]

template<class T>
vector3d<T> irr::core::vector3d< T >::operator- ( const vector3d< T > &  other) const
inline

Definition at line 45 of file vector3d.h.

45 { return vector3d<T>(X - other.X, Y - other.Y, Z - other.Z); }
T Y
Y coordinate of the vector.
Definition: vector3d.h:427
T X
X coordinate of the vector.
Definition: vector3d.h:424
T Z
Z coordinate of the vector.
Definition: vector3d.h:430

◆ operator-() [3/3]

template<class T>
vector3d<T> irr::core::vector3d< T >::operator- ( const val) const
inline

Definition at line 47 of file vector3d.h.

47 { return vector3d<T>(X - val, Y - val, Z - val); }
T Y
Y coordinate of the vector.
Definition: vector3d.h:427
T X
X coordinate of the vector.
Definition: vector3d.h:424
GLuint GLfloat * val
T Z
Z coordinate of the vector.
Definition: vector3d.h:430

◆ operator-=() [1/2]

template<class T>
vector3d<T>& irr::core::vector3d< T >::operator-= ( const vector3d< T > &  other)
inline

Definition at line 46 of file vector3d.h.

46 { X-=other.X; Y-=other.Y; Z-=other.Z; return *this; }
T Y
Y coordinate of the vector.
Definition: vector3d.h:427
T X
X coordinate of the vector.
Definition: vector3d.h:424
T Z
Z coordinate of the vector.
Definition: vector3d.h:430

◆ operator-=() [2/2]

template<class T>
vector3d<T>& irr::core::vector3d< T >::operator-= ( const val)
inline

Definition at line 48 of file vector3d.h.

48 { X-=val; Y-=val; Z-=val; return *this; }
T Y
Y coordinate of the vector.
Definition: vector3d.h:427
T X
X coordinate of the vector.
Definition: vector3d.h:424
GLuint GLfloat * val
T Z
Z coordinate of the vector.
Definition: vector3d.h:430

◆ operator/() [1/3]

template<class T>
vector3d<T> irr::core::vector3d< T >::operator/ ( const vector3d< T > &  other) const
inline

Definition at line 55 of file vector3d.h.

55 { return vector3d<T>(X / other.X, Y / other.Y, Z / other.Z); }
T Y
Y coordinate of the vector.
Definition: vector3d.h:427
T X
X coordinate of the vector.
Definition: vector3d.h:424
T Z
Z coordinate of the vector.
Definition: vector3d.h:430

◆ operator/() [2/3]

template<class T>
vector3d<T> irr::core::vector3d< T >::operator/ ( const v) const
inline

Definition at line 57 of file vector3d.h.

57 { T i=(T)1.0/v; return vector3d<T>(X * i, Y * i, Z * i); }
T Y
Y coordinate of the vector.
Definition: vector3d.h:427
T X
X coordinate of the vector.
Definition: vector3d.h:424
const GLdouble * v
Definition: SDL_opengl.h:2064
T Z
Z coordinate of the vector.
Definition: vector3d.h:430

◆ operator/() [3/3]

template<>
vector3d< s32 > irr::core::vector3d< s32 >::operator/ ( s32  val) const
inline

partial specialization for integer vectors

Definition at line 436 of file vector3d.h.

436 {return core::vector3d<s32>(X/val,Y/val,Z/val);}
T Y
Y coordinate of the vector.
Definition: vector3d.h:427
T X
X coordinate of the vector.
Definition: vector3d.h:424
GLuint GLfloat * val
T Z
Z coordinate of the vector.
Definition: vector3d.h:430

◆ operator/=() [1/3]

template<class T>
vector3d<T>& irr::core::vector3d< T >::operator/= ( const vector3d< T > &  other)
inline

Definition at line 56 of file vector3d.h.

56 { X/=other.X; Y/=other.Y; Z/=other.Z; return *this; }
T Y
Y coordinate of the vector.
Definition: vector3d.h:427
T X
X coordinate of the vector.
Definition: vector3d.h:424
T Z
Z coordinate of the vector.
Definition: vector3d.h:430

◆ operator/=() [2/3]

template<class T>
vector3d<T>& irr::core::vector3d< T >::operator/= ( const v)
inline

Definition at line 58 of file vector3d.h.

58 { T i=(T)1.0/v; X*=i; Y*=i; Z*=i; return *this; }
T Y
Y coordinate of the vector.
Definition: vector3d.h:427
T X
X coordinate of the vector.
Definition: vector3d.h:424
const GLdouble * v
Definition: SDL_opengl.h:2064
T Z
Z coordinate of the vector.
Definition: vector3d.h:430

◆ operator/=() [3/3]

template<>
vector3d< s32 > & irr::core::vector3d< s32 >::operator/= ( s32  val)
inline

Definition at line 438 of file vector3d.h.

438 {X/=val;Y/=val;Z/=val; return *this;}
T Y
Y coordinate of the vector.
Definition: vector3d.h:427
T X
X coordinate of the vector.
Definition: vector3d.h:424
GLuint GLfloat * val
T Z
Z coordinate of the vector.
Definition: vector3d.h:430

◆ operator<()

template<class T>
bool irr::core::vector3d< T >::operator< ( const vector3d< T > &  other) const
inline

sort in order X, Y, Z. Difference must be above rounding tolerance.

Definition at line 91 of file vector3d.h.

92  {
93  return (X<other.X && !core::equals(X, other.X)) ||
94  (core::equals(X, other.X) && Y<other.Y && !core::equals(Y, other.Y)) ||
95  (core::equals(X, other.X) && core::equals(Y, other.Y) && Z<other.Z && !core::equals(Z, other.Z));
96  }
T Y
Y coordinate of the vector.
Definition: vector3d.h:427
T X
X coordinate of the vector.
Definition: vector3d.h:424
bool equals(const T a, const T b, const T tolerance=roundingError< T >())
returns if a equals b, taking possible rounding errors into account
Definition: irrMath.h:246
T Z
Z coordinate of the vector.
Definition: vector3d.h:430

◆ operator<=()

template<class T>
bool irr::core::vector3d< T >::operator<= ( const vector3d< T > &  other) const
inline

sort in order X, Y, Z. Equality with rounding tolerance.

Definition at line 75 of file vector3d.h.

76  {
77  return (X<other.X || core::equals(X, other.X)) ||
78  (core::equals(X, other.X) && (Y<other.Y || core::equals(Y, other.Y))) ||
79  (core::equals(X, other.X) && core::equals(Y, other.Y) && (Z<other.Z || core::equals(Z, other.Z)));
80  }
T Y
Y coordinate of the vector.
Definition: vector3d.h:427
T X
X coordinate of the vector.
Definition: vector3d.h:424
bool equals(const T a, const T b, const T tolerance=roundingError< T >())
returns if a equals b, taking possible rounding errors into account
Definition: irrMath.h:246
T Z
Z coordinate of the vector.
Definition: vector3d.h:430

◆ operator=()

template<class T>
vector3d<T>& irr::core::vector3d< T >::operator= ( const vector3d< T > &  other)
inline

Definition at line 38 of file vector3d.h.

38 { X = other.X; Y = other.Y; Z = other.Z; return *this; }
T Y
Y coordinate of the vector.
Definition: vector3d.h:427
T X
X coordinate of the vector.
Definition: vector3d.h:424
T Z
Z coordinate of the vector.
Definition: vector3d.h:430

◆ operator==()

template<class T>
bool irr::core::vector3d< T >::operator== ( const vector3d< T > &  other) const
inline

use weak float compare

Definition at line 107 of file vector3d.h.

108  {
109  return this->equals(other);
110  }
bool equals(const vector3d< T > &other, const T tolerance=(T) ROUNDING_ERROR_f32) const
returns if this vector equals the other one, taking floating point rounding errors into account
Definition: vector3d.h:120

◆ operator>()

template<class T>
bool irr::core::vector3d< T >::operator> ( const vector3d< T > &  other) const
inline

sort in order X, Y, Z. Difference must be above rounding tolerance.

Definition at line 99 of file vector3d.h.

100  {
101  return (X>other.X && !core::equals(X, other.X)) ||
102  (core::equals(X, other.X) && Y>other.Y && !core::equals(Y, other.Y)) ||
103  (core::equals(X, other.X) && core::equals(Y, other.Y) && Z>other.Z && !core::equals(Z, other.Z));
104  }
T Y
Y coordinate of the vector.
Definition: vector3d.h:427
T X
X coordinate of the vector.
Definition: vector3d.h:424
bool equals(const T a, const T b, const T tolerance=roundingError< T >())
returns if a equals b, taking possible rounding errors into account
Definition: irrMath.h:246
T Z
Z coordinate of the vector.
Definition: vector3d.h:430

◆ operator>=()

template<class T>
bool irr::core::vector3d< T >::operator>= ( const vector3d< T > &  other) const
inline

sort in order X, Y, Z. Equality with rounding tolerance.

Definition at line 83 of file vector3d.h.

84  {
85  return (X>other.X || core::equals(X, other.X)) ||
86  (core::equals(X, other.X) && (Y>other.Y || core::equals(Y, other.Y))) ||
87  (core::equals(X, other.X) && core::equals(Y, other.Y) && (Z>other.Z || core::equals(Z, other.Z)));
88  }
T Y
Y coordinate of the vector.
Definition: vector3d.h:427
T X
X coordinate of the vector.
Definition: vector3d.h:424
bool equals(const T a, const T b, const T tolerance=roundingError< T >())
returns if a equals b, taking possible rounding errors into account
Definition: irrMath.h:246
T Z
Z coordinate of the vector.
Definition: vector3d.h:430

◆ rotateXYBy()

template<class T>
void irr::core::vector3d< T >::rotateXYBy ( f64  degrees,
const vector3d< T > &  center = vector3d<T>() 
)
inline

Rotates the vector by a specified number of degrees around the Z axis and the specified center.

Parameters
degreesNumber of degrees to rotate around the Z axis.
centerThe center of the rotation.

Definition at line 229 of file vector3d.h.

230  {
231  degrees *= DEGTORAD64;
232  f64 cs = cos(degrees);
233  f64 sn = sin(degrees);
234  X -= center.X;
235  Y -= center.Y;
236  set((T)(X*cs - Y*sn), (T)(X*sn + Y*cs), Z);
237  X += center.X;
238  Y += center.Y;
239  }
T Y
Y coordinate of the vector.
Definition: vector3d.h:427
T X
X coordinate of the vector.
Definition: vector3d.h:424
vector3d< T > & set(const T nx, const T ny, const T nz)
Definition: vector3d.h:127
double f64
64 bit floating point variable.
Definition: irrTypes.h:112
const f64 DEGTORAD64
64bit constant for converting from degrees to radians (formally known as GRAD_PI2)
Definition: irrMath.h:81
T Z
Z coordinate of the vector.
Definition: vector3d.h:430

◆ rotateXZBy()

template<class T>
void irr::core::vector3d< T >::rotateXZBy ( f64  degrees,
const vector3d< T > &  center = vector3d<T>() 
)
inline

Rotates the vector by a specified number of degrees around the Y axis and the specified center.

Parameters
degreesNumber of degrees to rotate around the Y axis.
centerThe center of the rotation.

Definition at line 214 of file vector3d.h.

215  {
216  degrees *= DEGTORAD64;
217  f64 cs = cos(degrees);
218  f64 sn = sin(degrees);
219  X -= center.X;
220  Z -= center.Z;
221  set((T)(X*cs - Z*sn), Y, (T)(X*sn + Z*cs));
222  X += center.X;
223  Z += center.Z;
224  }
T Y
Y coordinate of the vector.
Definition: vector3d.h:427
T X
X coordinate of the vector.
Definition: vector3d.h:424
vector3d< T > & set(const T nx, const T ny, const T nz)
Definition: vector3d.h:127
double f64
64 bit floating point variable.
Definition: irrTypes.h:112
const f64 DEGTORAD64
64bit constant for converting from degrees to radians (formally known as GRAD_PI2)
Definition: irrMath.h:81
T Z
Z coordinate of the vector.
Definition: vector3d.h:430

◆ rotateYZBy()

template<class T>
void irr::core::vector3d< T >::rotateYZBy ( f64  degrees,
const vector3d< T > &  center = vector3d<T>() 
)
inline

Rotates the vector by a specified number of degrees around the X axis and the specified center.

Parameters
degreesNumber of degrees to rotate around the X axis.
centerThe center of the rotation.

Definition at line 244 of file vector3d.h.

245  {
246  degrees *= DEGTORAD64;
247  f64 cs = cos(degrees);
248  f64 sn = sin(degrees);
249  Z -= center.Z;
250  Y -= center.Y;
251  set(X, (T)(Y*cs - Z*sn), (T)(Y*sn + Z*cs));
252  Z += center.Z;
253  Y += center.Y;
254  }
T Y
Y coordinate of the vector.
Definition: vector3d.h:427
T X
X coordinate of the vector.
Definition: vector3d.h:424
vector3d< T > & set(const T nx, const T ny, const T nz)
Definition: vector3d.h:127
double f64
64 bit floating point variable.
Definition: irrTypes.h:112
const f64 DEGTORAD64
64bit constant for converting from degrees to radians (formally known as GRAD_PI2)
Definition: irrMath.h:81
T Z
Z coordinate of the vector.
Definition: vector3d.h:430

◆ rotationToDirection()

template<class T>
vector3d<T> irr::core::vector3d< T >::rotationToDirection ( const vector3d< T > &  forwards = vector3d<T>(0, 0, 1)) const
inline

Builds a direction vector from (this) rotation vector.

This vector is assumed to be a rotation vector composed of 3 Euler angle rotations, in degrees. The implementation performs the same calculations as using a matrix to do the rotation.

Parameters
[in]forwardsThe direction representing "forwards" which will be rotated by this vector. If you do not provide a direction, then the +Z axis (0, 0, 1) will be assumed to be forwards.
Returns
A direction vector calculated by rotating the forwards direction by the 3 Euler angles (in degrees) represented by this vector.

Definition at line 373 of file vector3d.h.

374  {
375  const f64 cr = cos( core::DEGTORAD64 * X );
376  const f64 sr = sin( core::DEGTORAD64 * X );
377  const f64 cp = cos( core::DEGTORAD64 * Y );
378  const f64 sp = sin( core::DEGTORAD64 * Y );
379  const f64 cy = cos( core::DEGTORAD64 * Z );
380  const f64 sy = sin( core::DEGTORAD64 * Z );
381 
382  const f64 srsp = sr*sp;
383  const f64 crsp = cr*sp;
384 
385  const f64 pseudoMatrix[] = {
386  ( cp*cy ), ( cp*sy ), ( -sp ),
387  ( srsp*cy-cr*sy ), ( srsp*sy+cr*cy ), ( sr*cp ),
388  ( crsp*cy+sr*sy ), ( crsp*sy-sr*cy ), ( cr*cp )};
389 
390  return vector3d<T>(
391  (T)(forwards.X * pseudoMatrix[0] +
392  forwards.Y * pseudoMatrix[3] +
393  forwards.Z * pseudoMatrix[6]),
394  (T)(forwards.X * pseudoMatrix[1] +
395  forwards.Y * pseudoMatrix[4] +
396  forwards.Z * pseudoMatrix[7]),
397  (T)(forwards.X * pseudoMatrix[2] +
398  forwards.Y * pseudoMatrix[5] +
399  forwards.Z * pseudoMatrix[8]));
400  }
T Y
Y coordinate of the vector.
Definition: vector3d.h:427
T X
X coordinate of the vector.
Definition: vector3d.h:424
double f64
64 bit floating point variable.
Definition: irrTypes.h:112
const f64 DEGTORAD64
64bit constant for converting from degrees to radians (formally known as GRAD_PI2)
Definition: irrMath.h:81
T Z
Z coordinate of the vector.
Definition: vector3d.h:430

◆ set() [1/2]

template<class T>
vector3d<T>& irr::core::vector3d< T >::set ( const nx,
const ny,
const nz 
)
inline

Definition at line 127 of file vector3d.h.

127 {X=nx; Y=ny; Z=nz; return *this;}
T Y
Y coordinate of the vector.
Definition: vector3d.h:427
T X
X coordinate of the vector.
Definition: vector3d.h:424
GLfixed ny
GLbyte nx
GLfixed GLfixed nz
T Z
Z coordinate of the vector.
Definition: vector3d.h:430

◆ set() [2/2]

template<class T>
vector3d<T>& irr::core::vector3d< T >::set ( const vector3d< T > &  p)
inline

Definition at line 128 of file vector3d.h.

128 {X=p.X; Y=p.Y; Z=p.Z;return *this;}
T Y
Y coordinate of the vector.
Definition: vector3d.h:427
GLfloat GLfloat p
T X
X coordinate of the vector.
Definition: vector3d.h:424
T Z
Z coordinate of the vector.
Definition: vector3d.h:430

◆ setLength()

template<class T>
vector3d<T>& irr::core::vector3d< T >::setLength ( newlength)
inline

Sets the length of the vector to a new value.

Definition at line 196 of file vector3d.h.

197  {
198  normalize();
199  return (*this *= newlength);
200  }
vector3d< T > & normalize()
Normalizes the vector.
Definition: vector3d.h:182

Member Data Documentation

◆ X

template<class T>
T irr::core::vector3d< T >::X

X coordinate of the vector.

Definition at line 424 of file vector3d.h.

◆ Y

template<class T>
T irr::core::vector3d< T >::Y

Y coordinate of the vector.

Definition at line 427 of file vector3d.h.

◆ Z

template<class T>
T irr::core::vector3d< T >::Z

Z coordinate of the vector.

Definition at line 430 of file vector3d.h.


The documentation for this class was generated from the following file: