66 : x( fX ), y( fY ), z( fZ )
71 : x( afCoordinate[0] ),
77 inline explicit Vector3(
const int afCoordinate[3] )
79 x = (
Real)afCoordinate[0];
80 y = (
Real)afCoordinate[1];
81 z = (
Real)afCoordinate[2];
85 : x( r[0] ), y( r[1] ), z( r[2] )
106 inline Real operator [] (
const size_t i )
const
113 inline Real& operator [] (
const size_t i )
154 return ( x == rkVector.
x && y == rkVector.
y && z == rkVector.
z );
159 return ( x != rkVector.
x || y != rkVector.
y || z != rkVector.
z );
197 assert( fScalar != 0.0 );
199 Real fInv = 1.0f / fScalar;
229 fScalar * rkVector.
x,
230 fScalar * rkVector.
y,
231 fScalar * rkVector.
z);
237 fScalar / rkVector.
x,
238 fScalar / rkVector.
y,
239 fScalar / rkVector.
z);
328 assert( fScalar != 0.0 );
330 Real fInv = 1.0f / fScalar;
373 return x * x + y * y + z * z;
385 return (*
this - rhs).length();
400 return (*
this - rhs).squaredLength();
419 return x * vec.
x + y * vec.
y + z * vec.
z;
453 if ( fLength >
Real(0.0f) )
455 Real fInvLength = 1.0f / fLength;
495 y * rkVector.
z - z * rkVector.
y,
496 z * rkVector.
x - x * rkVector.
z,
497 x * rkVector.
y - y * rkVector.
x);
506 ( x + vec.
x ) * 0.5f,
507 ( y + vec.
y ) * 0.5f,
508 ( z + vec.
z ) * 0.5f );
516 if( x < rhs.
x && y < rhs.
y && z < rhs.
z )
524 inline bool operator > (
const Vector3& rhs )
const
526 if( x > rhs.
x && y > rhs.
y && z > rhs.
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 if( cmp.
x > x ) x = cmp.
x;
555 if( cmp.
y > y ) y = cmp.
y;
556 if( cmp.
z > z ) z = cmp.
z;
568 static const Real fSquareZero = (
Real)(1e-06 * 1e-06);
612 newUp = this->perpendicular();
638 if(lenProduct < 1e-6f)
641 Real f = dotProduct(dest) / lenProduct;
672 if (d < (1e-6f - 1.0f))
708 Real sqlen = (x * x) + (y * y) + (z * z);
709 return (sqlen < (1e-06 * 1e-06));
727 return Vector3( *
this - ( 2 * this->dotProduct(normal) * normal ) );
752 return squaredDistance(rhs) <=
764 const Radian& tolerance)
const
766 Real dot = dotProduct(rhs);
812 ( std::ostream& o,
const Vector3& v )
814 o <<
"Vector3(" << v.x <<
", " << v.y <<
", " << v.z <<
")";
static T Clamp(T val, T minval, T maxval)
Clamp a value within an inclusive range.
static Real UnitRandom()
Generate a random number of unit length.
static Radian ACos(Real fValue)
Arc cosine function.
static bool RealEqual(Real a, Real b, Real tolerance=std::numeric_limits< Real >::epsilon())
Compare 2 reals, using tolerance for inaccuracies.
static bool isNaN(Real f)
static Real Sqrt(Real fValue)
Square root function.
static Real Abs(Real fValue)
Absolute value function.
Implementation of a Quaternion, i.e.
static const Quaternion IDENTITY
void FromAngleAxis(const Radian &rfAngle, const Vector3 &rkAxis)
Setups the quaternion using the supplied vector, and "roll" around that vector by the specified radia...
Real normalise(void)
Normalises this quaternion, and returns the previous length.
Wrapper class which indicates a given angle value is in Radians.
Real valueRadians() const
Standard 3-dimensional vector.
bool isNaN() const
Check whether this vector contains valid values.
static const Vector3 UNIT_X
bool directionEquals(const Vector3 &rhs, const Radian &tolerance) const
Returns whether this vector is within a directional tolerance of another vector.
bool positionEquals(const Vector3 &rhs, Real tolerance=1e-03) const
Returns whether this vector is within a positional tolerance of another vector.
Vector3 crossProduct(const Vector3 &rkVector) const
Calculates the cross-product of 2 vectors, i.e.
void swap(Vector3 &other)
Exchange the contents of this vector with another.
Vector3 midPoint(const Vector3 &vec) const
Returns a vector at a point half way between this and the passed in vector.
Real squaredLength() const
Returns the square of the length(magnitude) of the vector.
Vector3 primaryAxis() const
Extract the primary (dominant) axis from this direction vector.
Vector3 normalisedCopy(void) const
As normalise, except that this vector is unaffected and the normalised vector is returned as a copy.
static const Vector3 NEGATIVE_UNIT_X
Real distance(const Vector3 &rhs) const
Returns the distance to another vector.
Real absDotProduct(const Vector3 &vec) const
Calculates the absolute dot (scalar) product of this vector with another.
static const Vector3 ZERO
Vector3 perpendicular(void) const
Generates a vector perpendicular to this vector (eg an 'up' vector).
void makeCeil(const Vector3 &cmp)
Sets this vector's components to the maximum of its own and the ones of the passed in vector.
Vector3(const Real fX, const Real fY, const Real fZ)
static const Vector3 UNIT_SCALE
static const Vector3 NEGATIVE_UNIT_Y
bool isZeroLength(void) const
Returns true if this vector is zero length.
void makeFloor(const Vector3 &cmp)
Sets this vector's components to the minimum of its own and the ones of the passed in vector.
Real length() const
Returns the length (magnitude) of the vector.
Vector3(const Real scaler)
Vector3 randomDeviant(const Radian &angle, const Vector3 &up=Vector3::ZERO) const
Generates a new random vector which deviates from this vector by a given angle in a random direction.
static const Vector3 UNIT_Y
Quaternion getRotationTo(const Vector3 &dest, const Vector3 &fallbackAxis=Vector3::ZERO) const
Gets the shortest arc quaternion to rotate this vector to the destination vector.
Real normalise()
Normalises the vector.
Radian angleBetween(const Vector3 &dest) const
Gets the angle between 2 vectors.
const Real * ptr() const
Pointer accessor for direct copying.
Vector3 reflect(const Vector3 &normal) const
Calculates a reflection vector to the plane with the given normal .
Vector3()
Default constructor.
static const Vector3 NEGATIVE_UNIT_Z
Vector3(const int afCoordinate[3])
bool positionCloses(const Vector3 &rhs, Real tolerance=1e-03f) const
Returns whether this vector is within a positional tolerance of another vector, also take scale of th...
Real * ptr()
Pointer accessor for direct copying.
static const Vector3 UNIT_Z
Real dotProduct(const Vector3 &vec) const
Calculates the dot (scalar) product of this vector with another.
Real squaredDistance(const Vector3 &rhs) const
Returns the square of the distance to another vector.
Vector3(const Real afCoordinate[3])
bool operator<(SharedPtr< T > const &a, SharedPtr< U > const &b)
Radian operator*(Real a, const Radian &b)
Radian operator/(Real a, const Radian &b)
bool operator!=(STLAllocator< T, P > const &, STLAllocator< T2, P > const &)
determine equality, can memory from another allocator be released by this allocator,...
bool operator==(STLAllocator< T, P > const &, STLAllocator< T2, P > const &)
determine equality, can memory from another allocator be released by this allocator,...
float Real
Software floating point type.
void swap(Ogre::SmallVectorImpl< T > &LHS, Ogre::SmallVectorImpl< T > &RHS)
Implement std::swap in terms of SmallVector swap.