1 #ifndef BLUB_MATH_VECTOR3_HPP
2 #define BLUB_MATH_VECTOR3_HPP
4 #include "blub/core/classVersion.hpp"
5 #include "blub/core/globals.hpp"
6 #include "blub/math/math.hpp"
7 #include "blub/math/predecl.hpp"
8 #include "blub/serialization/access.hpp"
9 #include "blub/serialization/nameValuePair.hpp"
11 # include <foundation/PxVec3.h>
14 #ifdef BLUB_USE_BULLET
36 #ifndef BLUB_NO_OGRE3D
37 vector3(
const Ogre::Vector3 &vec);
38 operator Ogre::Vector3()
const;
41 vector3(
const physx::PxVec3& other)
42 : x(other.x), y(other.y), z(other.z)
44 operator physx::PxVec3()
const
45 {
return physx::PxVec3(x,y,z);}
47 #ifdef BLUB_USE_BULLET
49 operator btVector3()
const;
52 vector3(
const real fX,
const real fY,
const real fZ)
68 bool operator <= (
const vector3& rhs )
const
70 return x <= rhs.x && y <= rhs.y && z <= rhs.z;
73 bool operator >= (
const vector3& rhs )
const
75 return x >= rhs.x && y >= rhs.y && z >= rhs.z;
86 std::swap(x, other.x);
87 std::swap(y, other.y);
88 std::swap(z, other.z);
91 inline real operator [] (
const size_t i )
const
98 inline real& operator [] (
const size_t i )
110 inline const real*
ptr()
const
138 inline bool operator == (
const vector3& rkVector )
const
140 return ( x == rkVector.x && y == rkVector.y && z == rkVector.z );
143 inline bool operator != (
const vector3& rkVector )
const
145 return ( x != rkVector.x || y != rkVector.y || z != rkVector.z );
149 inline vector3 operator + (
const vector3& rkVector )
const
157 inline vector3 operator - (
const vector3& rkVector )
const
165 inline vector3 operator * (
const real fScalar )
const
173 inline vector3 operator * (
const vector3& rhs)
const
181 inline vector3 operator / (
const real fScalar )
const
183 BASSERT( fScalar != 0.0 );
185 real fInv = 1.0f / fScalar;
193 inline vector3 operator / (
const vector3& rhs)
const
201 inline const vector3& operator + ()
const
206 inline vector3 operator - ()
const
208 return vector3(-x, -y, -z);
212 inline friend vector3 operator * (
const real fScalar,
const vector3& rkVector )
215 fScalar * rkVector.x,
216 fScalar * rkVector.y,
217 fScalar * rkVector.z);
220 inline friend vector3 operator / (
const real fScalar,
const vector3& rkVector )
223 fScalar / rkVector.x,
224 fScalar / rkVector.y,
225 fScalar / rkVector.z);
228 inline friend vector3 operator + (
const vector3& lhs,
const real rhs)
236 inline friend vector3 operator + (
const real lhs,
const vector3& rhs)
244 inline friend vector3 operator - (
const vector3& lhs,
const real rhs)
252 inline friend vector3 operator - (
const real lhs,
const vector3& rhs)
261 inline vector3& operator += (
const vector3& rkVector )
270 inline vector3& operator += (
const real fScalar )
278 inline vector3& operator -= (
const vector3& rkVector )
287 inline vector3& operator -= (
const real fScalar )
295 inline vector3& operator *= (
const real fScalar )
303 inline vector3& operator *= (
const vector3& rkVector )
312 inline vector3& operator /= (
const real fScalar )
314 BASSERT( fScalar != 0.0 );
316 real fInv = 1.0f / fScalar;
325 inline vector3& operator /= (
const vector3& rkVector )
344 return math::sqrt( x * x + y * y + z * z );
359 return x * x + y * y + z * z;
371 return (*
this - rhs).length();
386 return (*
this - rhs).squaredLength();
405 return x * vec.x + y * vec.y + z * vec.z;
420 return math::abs(x * vec.x) + math::abs(y * vec.y) + math::abs(z * vec.z);
434 real fLength = math::sqrt( x * x + y * y + z * z );
439 if ( fLength > real(0.0f) )
441 real fInvLength = 1.0f / fLength;
481 y * rkVector.z - z * rkVector.y,
482 z * rkVector.x - x * rkVector.z,
483 x * rkVector.y - y * rkVector.x);
492 ( x + vec.x ) * 0.5f,
493 ( y + vec.y ) * 0.5f,
494 ( z + vec.z ) * 0.5f );
502 if( x < rhs.x && y < rhs.y && z < rhs.z )
512 if( x > rhs.x && y > rhs.y && z > rhs.z )
526 if( cmp.x < x ) x = cmp.x;
527 if( cmp.y < y ) y = cmp.y;
528 if( cmp.z < z ) z = cmp.z;
540 if( cmp.x > x ) x = cmp.x;
541 if( cmp.y > y ) y = cmp.y;
542 if( cmp.z > z ) z = cmp.z;
554 static const real fSquareZero = (real)(1e-06 * 1e-06);
581 if(lenProduct < 1e-6f)
586 f = math::clamp(f, (real)-1.0, (real)1.0);
587 return math::acos(f);
599 const vector3& fallbackAxis = vector3::ZERO)
const;
604 real sqlen = (x * x) + (y * y) + (z * z);
605 return (sqlen < (1e-06 * 1e-06));
648 real absx = math::abs(x);
649 real absy = math::abs(y);
650 real absz = math::abs(z);
653 return x > 0 ? vector3::UNIT_X : vector3::NEGATIVE_UNIT_X;
655 return z > 0 ? vector3::UNIT_Z : vector3::NEGATIVE_UNIT_Z;
658 return y > 0 ? vector3::UNIT_Y : vector3::NEGATIVE_UNIT_Y;
660 return z > 0 ? vector3::UNIT_Z : vector3::NEGATIVE_UNIT_Z;
672 static const vector3 NEGATIVE_UNIT_X;
673 static const vector3 NEGATIVE_UNIT_Y;
674 static const vector3 NEGATIVE_UNIT_Z;
675 static const vector3 UNIT_SCALE;
678 BLUB_SERIALIZATION_ACCESS
680 template <
class formatType>
681 void serialize(formatType & readWrite,
const uint32& version)
685 readWrite & BLUB_SERIALIZATION_NAMEVALUEPAIR(x);
686 readWrite & BLUB_SERIALIZATION_NAMEVALUEPAIR(y);
687 readWrite & BLUB_SERIALIZATION_NAMEVALUEPAIR(z);
692 std::ostream& operator<< (std::ostream& ostr,
const vector3& toCast);
693 std::size_t hash_value(
const vector3& value);
700 #endif // BLUB_MATH_VECTOR3_HPP
real angleBetween(const vector3 &dest) const
Definition: vector3.hpp:576
vector3 normalisedCopy(void) const
Definition: vector3.hpp:618
real length() const
Definition: vector3.hpp:342
real squaredLength() const
Definition: vector3.hpp:357
vector3 primaryAxis() const
Extract the primary (dominant) axis from this direction vector.
Definition: vector3.hpp:646
Definition: quaternion.hpp:25
real squaredDistance(const vector3 &rhs) const
Definition: vector3.hpp:384
void makeCeil(const vector3 &cmp)
Definition: vector3.hpp:538
real absDotProduct(const vector3 &vec) const
Definition: vector3.hpp:418
real dotProduct(const vector3 &vec) const
Definition: vector3.hpp:403
bool operator>(const vector3 &rhs) const
Definition: vector3.hpp:510
real distance(const vector3 &rhs) const
Definition: vector3.hpp:369
bool positionCloses(const vector3 &rhs, real tolerance=1e-03f) const
Definition: vector3.hpp:639
quaternion getRotationTo(const vector3 &dest, const vector3 &fallbackAxis=vector3::ZERO) const
Definition: vector3.cpp:70
const real * ptr() const
Pointer accessor for direct copying.
Definition: vector3.hpp:110
void swap(vector3 &other)
Definition: vector3.hpp:84
real normalise()
Definition: vector3.hpp:432
void makeFloor(const vector3 &cmp)
Definition: vector3.hpp:524
vector3 reflect(const vector3 &normal) const
Definition: vector3.hpp:628
Definition: vector3.hpp:26
vector3 crossProduct(const vector3 &rkVector) const
Definition: vector3.hpp:478
vector3 perpendicular(void) const
Definition: vector3.hpp:552
real * ptr()
Pointer accessor for direct copying.
Definition: vector3.hpp:105
bool isZeroLength(void) const
Definition: vector3.hpp:602
vector3 midPoint(const vector3 &vec) const
Definition: vector3.hpp:489
vector3 getNormalise() const
Definition: vector3.hpp:611
Definition: deadlineTimer.hpp:10
Definition: axisAlignedBox.hpp:10
vector3 & operator=(const real fScaler)
Definition: vector3.hpp:129
bool operator<(const vector3 &rhs) const
Definition: vector3.hpp:500