OGRE-Next: Ogre::Vector2 Class Reference

| OGRE-Next 3.0.0 Object-Oriented Graphics Rendering Engine

Loading...
Searching...
No Matches
Ogre::Vector2 Class Reference
Core » Math

Standard 2-dimensional vector. More...

`#include <OgreVector2.h>`

## Public Member Functions
| Vector2 ()
| Default constructor.
| Vector2 (const int afCoordinate[2])
| Vector2 (const Real afCoordinate[2])
| Vector2 (const Real fX, const Real fY)
| Vector2 (const Real scaler)
| Vector2 (Real *const r)
Ogre::Radian | angleBetween (const Ogre::Vector2 &other) const
| Gets the angle between 2 vectors.
Ogre::Radian | angleTo (const Ogre::Vector2 &other) const
| Gets the oriented angle between 2 vectors.
Real | crossProduct (const Vector2 &rkVector) const
| Calculates the 2 dimensional cross-product of 2 vectors, which results in a single floating point value which is 2 times the area of the triangle.
Real | distance (const Vector2 &rhs) const
| Returns the distance to another vector.
Real | dotProduct (const Vector2 &vec) const
| Calculates the dot (scalar) product of this vector with another.
bool | isNaN () const
| Check whether this vector contains valid values.
bool | isZeroLength () const
| Returns true if this vector is zero length.
Real | length () const
| Returns the length (magnitude) of the 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.
void | makeFloor (const Vector2 &cmp)
| Sets this vector's components to the minimum of its own and the ones of the passed in vector.
Vector2 | midPoint (const Vector2 &vec) const
| Returns a vector at a point half way between this and the passed in vector.
Real | normalise ()
| Normalises the vector.
Vector2 | normalisedCopy () const
| As normalise, except that this vector is unaffected and the normalised vector is returned as a copy.
bool | operator!= (const Vector2 &rkVector) const
Vector2 | operator* (const Real fScalar) const
Vector2 | operator* (const Vector2 &rhs) const
Vector2 & | operator*= (const Real fScalar)
Vector2 & | operator*= (const Vector2 &rkVector)
const Vector2 & | operator+ () const
Vector2 | operator+ (const Vector2 &rkVector) const
Vector2 & | operator+= (const Real fScaler)
Vector2 & | operator+= (const Vector2 &rkVector)
Vector2 | operator- () const
Vector2 | operator- (const Vector2 &rkVector) const
Vector2 & | operator-= (const Real fScaler)
Vector2 & | operator-= (const Vector2 &rkVector)
Vector2 | operator/ (const Real fScalar) const
Vector2 | operator/ (const Vector2 &rhs) const
Vector2 & | operator/= (const Real fScalar)
Vector2 & | operator/= (const Vector2 &rkVector)
bool | operator< (const Vector2 &rhs) const
| Returns true if the vector's scalar components are all greater that the ones of the vector it is compared against.
Vector2 & | operator= (const Real fScalar)
bool | operator== (const Vector2 &rkVector) const
bool | operator> (const Vector2 &rhs) const
| Returns true if the vector's scalar components are all smaller that the ones of the vector it is compared against.
Real & | operator[] (const size_t i)
Real | operator[] (const size_t i) const
Vector2 | perpendicular () const
| Generates a vector perpendicular to this vector (eg an 'up' vector).
Real * | ptr ()
| Pointer accessor for direct copying.
const Real * | ptr () const
| Pointer accessor for direct copying.
Vector2 | randomDeviant (Radian angle) const
| Generates a new random vector which deviates from this vector by a given angle in a random direction.
Vector2 | reflect (const Vector2 &normal) const
| Calculates a reflection vector to the plane with the given normal .
Real | squaredDistance (const Vector2 &rhs) const
| Returns the square of the distance to another vector.
Real | squaredLength () const
| Returns the square of the length(magnitude) of the vector.
void | swap (Vector2 &other)
| Exchange the contents of this vector with another.

## Public Attributes
Real | x
Real | y

## Static Public Attributes
static const Vector2 | NEGATIVE_UNIT_X
static const Vector2 | NEGATIVE_UNIT_Y
static const Vector2 | UNIT_SCALE
static const Vector2 | UNIT_X
static const Vector2 | UNIT_Y
static const Vector2 | ZERO

## Detailed Description

Standard 2-dimensional vector.

Remarks
  A direction in 2D space represented as distances along the 2 orthogonal axes (x, y). Note that positions, directions and scaling factors can be represented by a vector, depending on how you interpret the values.

## Constructor & Destructor Documentation

## ◆ Vector2() [1/6]

Ogre::Vector2::Vector2 | ( |  | ) |
| inline

Default constructor.

Note
  It does NOT initialize the vector for efficiency.

Referenced by crossProduct(), distance(), dotProduct(), makeCeil(), makeFloor(), midPoint(), normalisedCopy(), operator!=(), operator*(), operator*, operator*(), operator*=(), operator*=(), operator+(), operator+, operator+, operator+(), operator+=(), operator+=(), operator-(), operator-, operator-, operator-(), operator-=(), operator-=(), operator/(), operator/, operator/(), operator/=(), operator/=(), operator<(), operator<<, operator=(), operator==(), operator>(), perpendicular(), randomDeviant(), reflect(), squaredDistance(), and swap().

## ◆ Vector2() [2/6]

Ogre::Vector2::Vector2 | ( | const Real | fX,
|  | const Real | fY )
| inline

References x, and y.

## ◆ Vector2() [3/6]

Ogre::Vector2::Vector2 | ( | const Real | scaler | ) |
| inlineexplicit

References x, and y.

## ◆ Vector2() [4/6]

Ogre::Vector2::Vector2 | ( | const Real | afCoordinate[2] | ) |
| inlineexplicit

References x, and y.

## ◆ Vector2() [5/6]

Ogre::Vector2::Vector2 | ( | const int | afCoordinate[2] | ) |
| inlineexplicit

References x, and y.

## ◆ Vector2() [6/6]

Ogre::Vector2::Vector2 | ( | Real *const | r | ) |
| inlineexplicit

References x, and y.

## Member Function Documentation

## ◆ angleBetween()

Ogre::Radian Ogre::Vector2::angleBetween | ( | const Ogre::Vector2 & | other | ) | const
| inline

Gets the angle between 2 vectors.

Remarks
  Vectors do not have to be unit-length but must represent directions.

References Ogre::Math::ACos(), Ogre::Math::Clamp(), dotProduct(), and length().

Referenced by angleTo().

## ◆ angleTo()

Ogre::Radian Ogre::Vector2::angleTo | ( | const Ogre::Vector2 & | other | ) | const
| inline

Gets the oriented angle between 2 vectors.

Remarks
  Vectors do not have to be unit-length but must represent directions. The angle is comprised between 0 and 2 PI.

References angleBetween(), crossProduct(), and Ogre::Math::TWO_PI.

## ◆ crossProduct()

Real Ogre::Vector2::crossProduct | ( | const Vector2 & | rkVector | ) | const
| inline

Calculates the 2 dimensional cross-product of 2 vectors, which results in a single floating point value which is 2 times the area of the triangle.

References Vector2(), x, and y.

Referenced by angleTo().

## ◆ distance()

Real Ogre::Vector2::distance | ( | const Vector2 & | rhs | ) | const
| inline

Returns the distance to another vector.

Warning
  This operation requires a square root and is expensive in terms of CPU operations. If you don't need to know the exact distance (e.g. for just comparing distances) use squaredDistance() instead.

References Vector2().

## ◆ dotProduct()

Real Ogre::Vector2::dotProduct | ( | const Vector2 & | vec | ) | const
| inline

Calculates the dot (scalar) product of this vector with another.

Remarks
  The dot product can be used to calculate the angle between 2 vectors. If both are unit vectors, the dot product is the cosine of the angle; otherwise the dot product must be divided by the product of the lengths of both vectors to get the cosine of the angle. This result can further be used to calculate the distance of a point from a plane.

Parameters

  vec | Vector with which to calculate the dot product (together with this one).

Returns
  A float representing the dot product value.

References Vector2(), x, and y.

Referenced by angleBetween(), and reflect().

## ◆ isNaN()

bool Ogre::Vector2::isNaN | ( |  | ) | const
| inline

Check whether this vector contains valid values.

References Ogre::Math::isNaN(), x, and y.

## ◆ isZeroLength()

bool Ogre::Vector2::isZeroLength | ( |  | ) | const
| inline

Returns true if this vector is zero length.

References x, and y.

## ◆ length()

Real Ogre::Vector2::length | ( |  | ) | const
| inline

Returns the length (magnitude) of the vector.

Warning
  This operation requires a square root and is expensive in terms of CPU operations. If you don't need to know the exact length (e.g. for just comparing lengths) use squaredLength() instead.

References Ogre::Math::Sqrt(), x, and y.

Referenced by angleBetween().

## ◆ makeCeil()

void Ogre::Vector2::makeCeil | ( | const Vector2 & | cmp | ) |
| inline

Sets this vector's components to the maximum of its own and the ones of the passed in vector.

Remarks
  'Maximum' in this case means the combination of the highest value of x, y and z from both vectors. Highest is taken just numerically, not magnitude, so 1 > -3.

References Vector2(), x, and y.

## ◆ makeFloor()

void Ogre::Vector2::makeFloor | ( | const Vector2 & | cmp | ) |
| inline

Sets this vector's components to the minimum of its own and the ones of the passed in vector.

Remarks
  'Minimum' in this case means the combination of the lowest value of x, y and z from both vectors. Lowest is taken just numerically, not magnitude, so -1 < 0.

References Vector2(), x, and y.

## ◆ midPoint()

Vector2 Ogre::Vector2::midPoint | ( | const Vector2 & | vec | ) | const
| inline

Returns a vector at a point half way between this and the passed in vector.

References Vector2(), x, and y.

## ◆ normalise()

Real Ogre::Vector2::normalise | ( |  | ) |
| inline

Normalises the vector.

Remarks
  This method normalises the vector such that it's length / magnitude is 1. The result is called a unit vector.

Note
  This function will not crash for zero-sized vectors, but there will be no changes made to their components.

Returns
  The previous length of the vector.

References Ogre::Math::Sqrt(), x, and y.

Referenced by normalisedCopy().

## ◆ normalisedCopy()

Vector2 Ogre::Vector2::normalisedCopy | ( |  | ) | const
| inline

As normalise, except that this vector is unaffected and the normalised vector is returned as a copy.

References Vector2(), and normalise().

## ◆ operator!=()

bool Ogre::Vector2::operator!= | ( | const Vector2 & | rkVector | ) | const
| inline

References Vector2(), x, and y.

## ◆ operator*() [1/2]

Vector2 Ogre::Vector2::operator* | ( | const Real | fScalar | ) | const
| inline

References Vector2(), x, and y.

## ◆ operator*() [2/2]

Vector2 Ogre::Vector2::operator* | ( | const Vector2 & | rhs | ) | const
| inline

References Vector2(), x, and y.

## ◆ operator*=() [1/2]

Vector2 & Ogre::Vector2::operator*= | ( | const Real | fScalar | ) |
| inline

References Vector2(), x, and y.

## ◆ operator*=() [2/2]

Vector2 & Ogre::Vector2::operator*= | ( | const Vector2 & | rkVector | ) |
| inline

References Vector2(), x, and y.

## ◆ operator+() [1/2]

const Vector2 & Ogre::Vector2::operator+ | ( |  | ) | const
| inline

References Vector2().

## ◆ operator+() [2/2]

Vector2 Ogre::Vector2::operator+ | ( | const Vector2 & | rkVector | ) | const
| inline

References Vector2(), x, and y.

## ◆ operator+=() [1/2]

Vector2 & Ogre::Vector2::operator+= | ( | const Real | fScaler | ) |
| inline

References Vector2(), x, and y.

## ◆ operator+=() [2/2]

Vector2 & Ogre::Vector2::operator+= | ( | const Vector2 & | rkVector | ) |
| inline

References Vector2(), x, and y.

## ◆ operator-() [1/2]

Vector2 Ogre::Vector2::operator- | ( |  | ) | const
| inline

References Vector2(), x, and y.

## ◆ operator-() [2/2]

Vector2 Ogre::Vector2::operator- | ( | const Vector2 & | rkVector | ) | const
| inline

References Vector2(), x, and y.

## ◆ operator-=() [1/2]

Vector2 & Ogre::Vector2::operator-= | ( | const Real | fScaler | ) |
| inline

References Vector2(), x, and y.

## ◆ operator-=() [2/2]

Vector2 & Ogre::Vector2::operator-= | ( | const Vector2 & | rkVector | ) |
| inline

References Vector2(), x, and y.

## ◆ operator/() [1/2]

Vector2 Ogre::Vector2::operator/ | ( | const Real | fScalar | ) | const
| inline

References Vector2(), x, and y.

## ◆ operator/() [2/2]

Vector2 Ogre::Vector2::operator/ | ( | const Vector2 & | rhs | ) | const
| inline

References Vector2(), x, and y.

## ◆ operator/=() [1/2]

Vector2 & Ogre::Vector2::operator/= | ( | const Real | fScalar | ) |
| inline

References Vector2(), x, and y.

## ◆ operator/=() [2/2]

Vector2 & Ogre::Vector2::operator/= | ( | const Vector2 & | rkVector | ) |
| inline

References Vector2(), x, and y.

## ◆ operator<()

bool Ogre::Vector2::operator< | ( | const Vector2 & | rhs | ) | const
| inline

Returns true if the vector's scalar components are all greater that the ones of the vector it is compared against.

References Vector2(), x, and y.

## ◆ operator=()

Vector2 & Ogre::Vector2::operator= | ( | const Real | fScalar | ) |
| inline

References Vector2(), x, and y.

## ◆ operator==()

bool Ogre::Vector2::operator== | ( | const Vector2 & | rkVector | ) | const
| inline

References Vector2(), x, and y.

## ◆ operator>()

bool Ogre::Vector2::operator> | ( | const Vector2 & | rhs | ) | const
| inline

Returns true if the vector's scalar components are all smaller that the ones of the vector it is compared against.

References Vector2(), x, and y.

## ◆ operator[]() [1/2]

Real & Ogre::Vector2::operator[] | ( | const size_t | i | ) |
| inline

References x.

## ◆ operator[]() [2/2]

Real Ogre::Vector2::operator[] | ( | const size_t | i | ) | const
| inline

References x.

## ◆ perpendicular()

Vector2 Ogre::Vector2::perpendicular | ( |  | ) | const
| inline

Generates a vector perpendicular to this vector (eg an 'up' vector).

Remarks
  This method will return a vector which is perpendicular to this vector. There are an infinite number of possibilities but this method will guarantee to generate one of them. If you need more control you should use the Quaternion class.

References Vector2(), x, and y.

## ◆ ptr() [1/2]

Real * Ogre::Vector2::ptr | ( |  | ) |
| inline

Pointer accessor for direct copying.

References x.

## ◆ ptr() [2/2]

const Real * Ogre::Vector2::ptr | ( |  | ) | const
| inline

Pointer accessor for direct copying.

References x.

## ◆ randomDeviant()

Vector2 Ogre::Vector2::randomDeviant | ( | Radian | angle | ) | const
| inline

Generates a new random vector which deviates from this vector by a given angle in a random direction.

Remarks
  This method assumes that the random number generator has already been seeded appropriately.

Parameters

  angle | The angle at which to deviate in radians

Returns
  A random vector which deviates from this vector by angle. This vector will not be normalised, normalise it if you wish afterwards.

References Vector2(), Ogre::Math::Cos(), Ogre::Math::RangeRandom(), Ogre::Math::Sin(), x, and y.

## ◆ reflect()

Vector2 Ogre::Vector2::reflect | ( | const Vector2 & | normal | ) | const
| inline

Calculates a reflection vector to the plane with the given normal .

Remarks
  NB assumes 'this' is pointing AWAY FROM the plane, invert if it is not.

References Vector2(), and dotProduct().

## ◆ squaredDistance()

Real Ogre::Vector2::squaredDistance | ( | const Vector2 & | rhs | ) | const
| inline

Returns the square of the distance to another vector.

Remarks
  This method is for efficiency - calculating the actual distance to another vector requires a square root, which is expensive in terms of the operations required. This method returns the square of the distance to another vector, i.e. the same as the distance but before the square root is taken. Use this if you want to find the longest / shortest distance without incurring the square root.

References Vector2().

## ◆ squaredLength()

Real Ogre::Vector2::squaredLength | ( |  | ) | const
| inline

Returns the square of the length(magnitude) of the vector.

Remarks
  This method is for efficiency - calculating the actual length of a vector requires a square root, which is expensive in terms of the operations required. This method returns the square of the length of the vector, i.e. the same as the length but before the square root is taken. Use this if you want to find the longest / shortest vector without incurring the square root.

References x, and y.

## ◆ swap()

void Ogre::Vector2::swap | ( | Vector2 & | other | ) |
| inline

Exchange the contents of this vector with another.

References Vector2(), std::swap(), x, and y.

## Member Data Documentation

## ◆ NEGATIVE_UNIT_X

const Vector2 Ogre::Vector2::NEGATIVE_UNIT_X
| static

## ◆ NEGATIVE_UNIT_Y

const Vector2 Ogre::Vector2::NEGATIVE_UNIT_Y
| static

## ◆ UNIT_SCALE

const Vector2 Ogre::Vector2::UNIT_SCALE
| static

## ◆ UNIT_X

const Vector2 Ogre::Vector2::UNIT_X
| static

## ◆ UNIT_Y

const Vector2 Ogre::Vector2::UNIT_Y
| static

## ◆ x

Real Ogre::Vector2::x

Referenced by Vector2(), Vector2(), Vector2(), Vector2(), Vector2(), crossProduct(), dotProduct(), isNaN(), isZeroLength(), length(), makeCeil(), makeFloor(), midPoint(), normalise(), operator!=(), operator*(), operator*, operator*(), operator*=(), operator*=(), operator+, operator+, operator+(), operator+=(), operator+=(), operator-(), operator-, operator-, operator-(), operator-=(), operator-=(), operator/(), operator/, operator/(), operator/=(), operator/=(), operator<(), operator=(), operator==(), operator>(), operator[](), operator[](), perpendicular(), ptr(), ptr(), randomDeviant(), squaredLength(), and swap().

## ◆ y

Real Ogre::Vector2::y

Referenced by Vector2(), Vector2(), Vector2(), Vector2(), Vector2(), crossProduct(), dotProduct(), isNaN(), isZeroLength(), length(), makeCeil(), makeFloor(), midPoint(), normalise(), operator!=(), operator*(), operator*, operator*(), operator*=(), operator*=(), operator+, operator+, operator+(), operator+=(), operator+=(), operator-(), operator-, operator-, operator-(), operator-=(), operator-=(), operator/(), operator/, operator/(), operator/=(), operator/=(), operator<(), operator=(), operator==(), operator>(), perpendicular(), randomDeviant(), squaredLength(), and swap().

## ◆ ZERO

const Vector2 Ogre::Vector2::ZERO
| static

Referenced by Ogre::StringConverter::parseVector2().

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

- OgreVector2.h