5#ifndef __IRR_POINT_3D_H_INCLUDED__
6#define __IRR_POINT_3D_H_INCLUDED__
43 vector3d<T>& operator+=(
const T val) {
X+=val;
Y+=val;
Z+=val;
return *
this; }
48 vector3d<T>& operator-=(
const T val) {
X-=val;
Y-=val;
Z-=val;
return *
this; }
53 vector3d<T>& operator*=(
const T v) {
X*=v;
Y*=v;
Z*=v;
return *
this; }
58 vector3d<T>& operator/=(
const T v) { T i=(T)1.0/v;
X*=i;
Y*=i;
Z*=i;
return *
this; }
95 return this->
equals(other);
100 return !this->
equals(other);
113 vector3d<T>& set(
const T nx,
const T ny,
const T nz) {
X=nx;
Y=ny;
Z=nz;
return *
this;}
127 return X*other.
X +
Y*other.
Y +
Z*other.
Z;
173 length = core::reciprocal_squareroot(length);
185 return (*
this *= newlength);
203 f64 cs = cos(degrees);
204 f64 sn = sin(degrees);
207 set((T)(
X*cs -
Z*sn),
Y, (T)(
X*sn +
Z*cs));
218 f64 cs = cos(degrees);
219 f64 sn = sin(degrees);
222 set((T)(
X*cs -
Y*sn), (T)(
X*sn +
Y*cs),
Z);
233 f64 cs = cos(degrees);
234 f64 sn = sin(degrees);
237 set(
X, (T)(
Y*cs -
Z*sn), (T)(
Y*sn +
Z*cs));
249 const f64 inv = 1.0 - d;
250 return vector3d<T>((T)(other.
X*inv +
X*d), (T)(other.
Y*inv +
Y*d), (T)(other.
Z*inv +
Z*d));
262 const f64 inv = (T) 1.0 - d;
263 const f64 mul0 = inv * inv;
264 const f64 mul1 = (T) 2.0 * d * inv;
265 const f64 mul2 = d * d;
268 (T)(
Y * mul0 + v2.
Y * mul1 + v3.
Y * mul2),
269 (T)(
Z * mul0 + v2.
Z * mul1 + v3.
Z * mul2));
280 X = (T)((
f64)b.
X + ( ( a.
X - b.
X ) * d ));
281 Y = (T)((
f64)b.
Y + ( ( a.
Y - b.
Y ) * d ));
282 Z = (T)((
f64)b.
Z + ( ( a.
Z - b.
Z ) * d ));
313 const f64 z1 = core::squareroot(
X*
X +
Z*
Z);
344 angle.
X = (T)(acos(
Y * core::reciprocal_squareroot(length)) *
RADTODEG64);
366 const f64 srsp = sr*sp;
367 const f64 crsp = cr*sp;
369 const f64 pseudoMatrix[] = {
370 ( cp*cy ), ( cp*sy ), ( -sp ),
371 ( srsp*cy-cr*sy ), ( srsp*sy+cr*cy ), ( sr*cp ),
372 ( crsp*cy+sr*sy ), ( crsp*sy-sr*cy ), ( cr*cp )};
375 (T)(forwards.X * pseudoMatrix[0] +
376 forwards.Y * pseudoMatrix[3] +
377 forwards.Z * pseudoMatrix[6]),
378 (T)(forwards.X * pseudoMatrix[1] +
379 forwards.Y * pseudoMatrix[4] +
380 forwards.Z * pseudoMatrix[7]),
381 (T)(forwards.X * pseudoMatrix[2] +
382 forwards.Y * pseudoMatrix[5] +
383 forwards.Z * pseudoMatrix[8]));
428 const f64 length = X*X + Y*Y + Z*Z;
439 angle.X = round32((
f32)(acos(Y * core::reciprocal_squareroot(length)) *
RADTODEG64));
451 template<
class S,
class T>
Self reallocating template array (like stl vector) with additional features.
Definition irrArray.h:23
3d vector template class with lots of operators and methods.
Definition vector3d.h:23
T getDistanceFromSQ(const vector3d< T > &other) const
Returns squared distance from another point.
Definition vector3d.h:139
vector3d(const vector3d< T > &other)
Copy constructor.
Definition vector3d.h:32
vector3d(T n)
Constructor with the same value for all elements.
Definition vector3d.h:30
vector3d(T nx, T ny, T nz)
Constructor with three different values.
Definition vector3d.h:28
vector3d< T > & setLength(T newlength)
Sets the length of the vector to a new value.
Definition vector3d.h:182
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.
Definition vector3d.h:278
bool operator<(const vector3d< T > &other) const
sort in order X, Y, Z. Difference must be above rounding tolerance.
Definition vector3d.h:77
T getLengthSQ() const
Get squared length of the vector.
Definition vector3d.h:122
bool operator<=(const vector3d< T > &other) const
sort in order X, Y, Z. Equality with rounding tolerance.
Definition vector3d.h:61
vector3d< T > getHorizontalAngle() const
Get the rotations that would make a (0,0,1) direction vector point in the same direction as this dire...
Definition vector3d.h:301
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:106
void rotateXZBy(f64 degrees, const vector3d< T > ¢er=vector3d< T >())
Rotates the vector by a specified number of degrees around the Y axis and the specified center.
Definition vector3d.h:200
vector3d< T > crossProduct(const vector3d< T > &p) const
Calculates the cross product with another vector.
Definition vector3d.h:147
T getLength() const
Get length of the vector.
Definition vector3d.h:117
vector3d< T > getInterpolated(const vector3d< T > &other, f64 d) const
Creates an interpolated vector between this vector and another vector.
Definition vector3d.h:247
bool operator>=(const vector3d< T > &other) const
sort in order X, Y, Z. Equality with rounding tolerance.
Definition vector3d.h:69
f32 X
Definition vector3d.h:408
vector3d< T > & normalize()
Normalizes the vector.
Definition vector3d.h:168
void getAs4Values(T *array) const
Fills an array of 4 values with the vector data (usually floats).
Definition vector3d.h:389
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.
Definition vector3d.h:259
void rotateYZBy(f64 degrees, const vector3d< T > ¢er=vector3d< T >())
Rotates the vector by a specified number of degrees around the X axis and the specified center.
Definition vector3d.h:230
T getDistanceFrom(const vector3d< T > &other) const
Get distance from another point.
Definition vector3d.h:132
vector3d< T > rotationToDirection(const vector3d< T > &forwards=vector3d< T >(0, 0, 1)) const
Builds a direction vector from (this) rotation vector.
Definition vector3d.h:357
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.
Definition vector3d.h:157
f32 Z
Definition vector3d.h:414
void rotateXYBy(f64 degrees, const vector3d< T > ¢er=vector3d< T >())
Rotates the vector by a specified number of degrees around the Z axis and the specified center.
Definition vector3d.h:215
vector3d< T > & invert()
Inverts the vector.
Definition vector3d.h:189
bool operator>(const vector3d< T > &other) const
sort in order X, Y, Z. Difference must be above rounding tolerance.
Definition vector3d.h:85
T dotProduct(const vector3d< T > &other) const
Get the dot product with another vector.
Definition vector3d.h:125
vector3d()
Default constructor (null vector).
Definition vector3d.h:26
vector3d< T > getSphericalCoordinateAngles() const
Get the spherical coordinate angles.
Definition vector3d.h:330
f32 Y
Definition vector3d.h:411
void getAs3Values(T *array) const
Fills an array of 3 values with the vector data (usually floats).
Definition vector3d.h:399
bool operator==(const vector3d< T > &other) const
use weak float compare
Definition vector3d.h:93
Basic classes such as vectors, planes, arrays, lists, and so on can be found in this namespace.
Definition aabbox3d.h:15
vector3d< f32 > vector3df
Typedef for a f32 3d vector.
Definition vector3d.h:445
vector3d< s32 > vector3di
Typedef for an integer 3d vector.
Definition vector3d.h:448
const f64 DEGTORAD64
64bit constant for converting from degrees to radians (formally known as GRAD_PI2)
Definition irrMath.h:80
bool equals(const f64 a, const f64 b, const f64 tolerance=ROUNDING_ERROR_f64)
returns if a equals b, taking possible rounding errors into account
Definition irrMath.h:185
const f64 RADTODEG64
64bit constant for converting from radians to degrees
Definition irrMath.h:83
Everything in the Irrlicht Engine can be found in this namespace.
Definition Skylicht.h:33
float f32
32 bit floating point variable.
Definition irrTypes.h:104
double f64
64 bit floating point variable.
Definition irrTypes.h:108
signed int s32
32 bit signed variable.
Definition irrTypes.h:66