71 : x( scaler), y( scaler )
76 : x( afCoordinate[0] ),
81 inline explicit Vector2(
const int afCoordinate[2] )
83 x = (
Real)afCoordinate[0];
84 y = (
Real)afCoordinate[1];
88 : x( r[0] ), y( r[1] )
100 inline Real operator [] (
const size_t i )
const
107 inline Real& operator [] (
const size_t i )
145 inline bool operator == (
const Vector2& rkVector )
const
147 return ( x == rkVector.
x && y == rkVector.
y );
150 inline bool operator != (
const Vector2& rkVector )
const
152 return ( x != rkVector.
x || y != rkVector.
y );
186 assert( fScalar != 0.0 );
188 Real fInv = 1.0f / fScalar;
216 fScalar * rkVector.
x,
217 fScalar * rkVector.
y);
223 fScalar / rkVector.
x,
224 fScalar / rkVector.
y);
306 assert( fScalar != 0.0 );
308 Real fInv = 1.0f / fScalar;
333 return Math::Sqrt( x * x + y * y );
348 return x * x + y * y;
360 return (*
this - rhs).length();
375 return (*
this - rhs).squaredLength();
394 return x * vec.
x + y * vec.
y;
409 Real fLength = Math::Sqrt( x * x + y * y);
414 if ( fLength >
Real(0.0f) )
416 Real fInvLength = 1.0f / fLength;
430 ( x + vec.
x ) * 0.5f,
431 ( y + vec.
y ) * 0.5f );
437 inline bool operator < (
const Vector2& rhs )
const
439 if( x < rhs.
x && y < rhs.
y )
447 inline bool operator > (
const Vector2& rhs )
const
449 if( x > rhs.
x && y > rhs.
y )
463 if( cmp.
x < x ) x = cmp.
x;
464 if( cmp.
y < y ) y = cmp.
y;
476 if( cmp.
x > x ) x = cmp.
x;
477 if( cmp.
y > y ) y = cmp.
y;
497 return x * rkVector.
y - y * rkVector.
x;
514 angle *= Math::RangeRandom(-1, 1);
515 Real cosa = Math::Cos(angle);
516 Real sina = Math::Sin(angle);
517 return Vector2(cosa * x - sina * y,
518 sina * x + cosa * y);
524 Real sqlen = (x * x) + (y * y);
525 return (sqlen < (1e-06 * 1e-06));
543 return Vector2( *
this - ( 2 * this->dotProduct(normal) * normal ) );
549 return Math::isNaN(x) || Math::isNaN(y);
560 if(lenProduct < 1e-6f)
563 Ogre::Real f = dotProduct(other) / lenProduct;
578 if (crossProduct(other)<0)
595 ( std::ostream& o,
const Vector2& v )
597 o <<
"Vector2(" << v.x <<
", " << v.y <<
")";
static T Clamp(T val, T minval, T maxval)
Clamp a value within an inclusive range.
static Radian ACos(Real fValue)
Arc cosine function.
Wrapper class which indicates a given angle value is in Radians.
Standard 2-dimensional vector.
Real normalise()
Normalises the vector.
Real * ptr()
Pointer accessor for direct copying.
Vector2(const Real fX, const Real fY)
static const Vector2 UNIT_SCALE
Vector2(const Real scaler)
static const Vector2 UNIT_X
Vector2 perpendicular(void) const
Generates a vector perpendicular to this vector (eg an 'up' vector).
void makeCeil(const Vector2 &cmp)
Sets this vector's components to the maximum of its own and the ones of the passed in vector.
Real squaredLength() const
Returns the square of the length(magnitude) of the vector.
Vector2 normalisedCopy(void) const
As normalise, except that this vector is unaffected and the normalised vector is returned as a copy.
static const Vector2 NEGATIVE_UNIT_X
Vector2()
Default constructor.
Real length() const
Returns the length (magnitude) of the vector.
Vector2 randomDeviant(Radian angle) const
Generates a new random vector which deviates from this vector by a given angle in a random direction.
Vector2(const Real afCoordinate[2])
static const Vector2 ZERO
bool isNaN() const
Check whether this vector contains valid values.
Real crossProduct(const Vector2 &rkVector) const
Calculates the 2 dimensional cross-product of 2 vectors, which results in a single floating point val...
void makeFloor(const Vector2 &cmp)
Sets this vector's components to the minimum of its own and the ones of the passed in vector.
static const Vector2 NEGATIVE_UNIT_Y
void swap(Vector2 &other)
Exchange the contents of this vector with another.
Ogre::Radian angleTo(const Ogre::Vector2 &other) const
Gets the oriented angle between 2 vectors.
Vector2 reflect(const Vector2 &normal) const
Calculates a reflection vector to the plane with the given normal .
Real distance(const Vector2 &rhs) const
Returns the distance to another vector.
Vector2(const int afCoordinate[2])
Real squaredDistance(const Vector2 &rhs) const
Returns the square of the distance to another vector.
bool isZeroLength(void) const
Returns true if this vector is zero length.
static const Vector2 UNIT_Y
const Real * ptr() const
Pointer accessor for direct copying.
Real dotProduct(const Vector2 &vec) const
Calculates the dot (scalar) product of this vector with another.
Ogre::Radian angleBetween(const Ogre::Vector2 &other) const
Gets the angle between 2 vectors.
Vector2 midPoint(const Vector2 &vec) const
Returns a vector at a point half way between this and the passed in vector.
float Real
Software floating point type.
void swap(Ogre::SmallVectorImpl< T > &LHS, Ogre::SmallVectorImpl< T > &RHS)
Implement std::swap in terms of SmallVector swap.