Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

Ogre::Vector2 Class Reference

Standard 2-dimensional vector. More...

#include <OgreVector2.h>

List of all members.

Public Member Functions

 Vector2 ()
 Vector2 (const Real fX, const Real fY)
 Vector2 (const Real scaler)
 Vector2 (const Real afCoordinate[2])
 Vector2 (const int afCoordinate[2])
 Vector2 (Real *const r)
 Vector2 (const Vector2 &rkVector)
Real operator[] (const size_t i) const
Realoperator[] (const size_t i)
Vector2operator= (const Vector2 &rkVector)
 Assigns the value of the other vector.

Vector2operator= (const Real fScalar)
bool operator== (const Vector2 &rkVector) const
bool operator!= (const Vector2 &rkVector) const
Vector2 operator+ (const Vector2 &rkVector) const
Vector2 operator- (const Vector2 &rkVector) const
Vector2 operator * (const Real fScalar) const
Vector2 operator * (const Vector2 &rhs) const
Vector2 operator/ (const Real fScalar) const
Vector2 operator- () const
Vector2operator+= (const Vector2 &rkVector)
Vector2operator+= (const Real fScaler)
Vector2operator-= (const Vector2 &rkVector)
Vector2operator-= (const Real fScaler)
Vector2operator *= (const Real fScalar)
Vector2operator/= (const Real fScalar)
Real length () const
 Returns the length (magnitude) of the vector.

Real squaredLength () const
 Returns the square of the length(magnitude) of the vector.

Real dotProduct (const Vector2 &vec) const
 Calculates the dot (scalar) product of this vector with another.

Real normalise ()
 Normalises the vector.

Vector2 midPoint (const Vector2 &vec) const
 Returns a vector at a point half way between this and the passed in vector.

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.

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.

void makeFloor (const Vector2 &cmp)
 Sets this vector's components to the minimum of its own and the ones of the passed in 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.

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

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.

Vector2 randomDeviant (Real angle) const
 Generates a new random vector which deviates from this vector by a given angle in a random direction.

bool isZeroLength (void) const
 Returns true if this vector is zero length.

Vector2 normalisedCopy (void) const
 As normalise, except that this vector is unaffected and the normalised vector is returned as a copy.

Vector2 reflect (const Vector2 &normal) const
 Calculates a reflection vector to the plane with the given normal .


Static Public Attributes

const Vector2 ZERO
const Vector2 UNIT_X
const Vector2 UNIT_Y
const Vector2 NEGATIVE_UNIT_X
const Vector2 NEGATIVE_UNIT_Y
const Vector2 UNIT_SCALE

Friends

Vector2 operator * (const Real fScalar, const Vector2 &rkVector)
Vector2 operator+ (const Vector2 &lhs, const Real rhs)
Vector2 operator+ (const Real lhs, const Vector2 &rhs)
Vector2 operator- (const Vector2 &lhs, const Real rhs)
Vector2 operator- (const Real lhs, const Vector2 &rhs)
_OgreExport friend std::ostream & operator<< (std::ostream &o, const Vector2 &v)
 Function for writing to a stream.


Detailed Description

Standard 2-dimensional vector.

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

Definition at line 42 of file OgreVector2.h.


Constructor & Destructor Documentation

Ogre::Vector2::Vector2  ) 
 

Definition at line 53 of file OgreVector2.h.

Ogre::Vector2::Vector2 const Real  fX,
const Real  fY
 

Definition at line 57 of file OgreVector2.h.

References Ogre::Real.

Ogre::Vector2::Vector2 const Real  scaler  )  [explicit]
 

Definition at line 62 of file OgreVector2.h.

References Ogre::Real.

Ogre::Vector2::Vector2 const Real  afCoordinate[2]  )  [explicit]
 

Definition at line 67 of file OgreVector2.h.

References Ogre::Real.

Ogre::Vector2::Vector2 const int  afCoordinate[2]  )  [explicit]
 

Definition at line 73 of file OgreVector2.h.

References Ogre::Real.

Ogre::Vector2::Vector2 Real *const  r  )  [explicit]
 

Definition at line 79 of file OgreVector2.h.

References Ogre::Real.

Ogre::Vector2::Vector2 const Vector2 rkVector  ) 
 

Definition at line 84 of file OgreVector2.h.


Member Function Documentation

Real Ogre::Vector2::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.

Definition at line 425 of file OgreVector2.h.

References Ogre::Real, x, and y.

Real Ogre::Vector2::dotProduct const Vector2 vec  )  const
 

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.

Definition at line 324 of file OgreVector2.h.

References Ogre::Real, x, and y.

bool Ogre::Vector2::isZeroLength void   )  const
 

Returns true if this vector is zero length.

Definition at line 460 of file OgreVector2.h.

References Ogre::Real.

Real Ogre::Vector2::length  )  const
 

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.

Definition at line 290 of file OgreVector2.h.

References Ogre::Real.

void Ogre::Vector2::makeCeil const Vector2 cmp  ) 
 

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.

Definition at line 405 of file OgreVector2.h.

References x, and y.

void Ogre::Vector2::makeFloor const Vector2 cmp  ) 
 

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.

Definition at line 392 of file OgreVector2.h.

References x, and y.

Vector2 Ogre::Vector2::midPoint const Vector2 vec  )  const
 

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

Definition at line 358 of file OgreVector2.h.

References x, and y.

Real Ogre::Vector2::normalise void   ) 
 

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.

Definition at line 338 of file OgreVector2.h.

References Ogre::Real.

Referenced by normalisedCopy().

Vector2 Ogre::Vector2::normalisedCopy void   )  const
 

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

Definition at line 469 of file OgreVector2.h.

References normalise().

Vector2 Ogre::Vector2::operator * const Vector2 rhs  )  const
 

Definition at line 164 of file OgreVector2.h.

References x, and y.

Vector2 Ogre::Vector2::operator * const Real  fScalar  )  const
 

Definition at line 154 of file OgreVector2.h.

References Ogre::Real, x, and y.

Vector2& Ogre::Vector2::operator *= const Real  fScalar  ) 
 

Definition at line 263 of file OgreVector2.h.

References Ogre::Real.

bool Ogre::Vector2::operator!= const Vector2 rkVector  )  const
 

Definition at line 128 of file OgreVector2.h.

References x, and y.

Vector2 Ogre::Vector2::operator+ const Vector2 rkVector  )  const
 

Definition at line 134 of file OgreVector2.h.

References x, and y.

Vector2& Ogre::Vector2::operator+= const Real  fScaler  ) 
 

Definition at line 239 of file OgreVector2.h.

References Ogre::Real.

Vector2& Ogre::Vector2::operator+= const Vector2 rkVector  ) 
 

Definition at line 231 of file OgreVector2.h.

References x, and y.

Vector2 Ogre::Vector2::operator-  )  const
 

Definition at line 187 of file OgreVector2.h.

References x, and y.

Vector2 Ogre::Vector2::operator- const Vector2 rkVector  )  const
 

Definition at line 144 of file OgreVector2.h.

References x, and y.

Vector2& Ogre::Vector2::operator-= const Real  fScaler  ) 
 

Definition at line 255 of file OgreVector2.h.

References Ogre::Real.

Vector2& Ogre::Vector2::operator-= const Vector2 rkVector  ) 
 

Definition at line 247 of file OgreVector2.h.

References x, and y.

Vector2 Ogre::Vector2::operator/ const Real  fScalar  )  const
 

Definition at line 174 of file OgreVector2.h.

References Ogre::Real, x, and y.

Vector2& Ogre::Vector2::operator/= const Real  fScalar  ) 
 

Definition at line 271 of file OgreVector2.h.

References Ogre::Real.

bool Ogre::Vector2::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.

Definition at line 368 of file OgreVector2.h.

References x, and y.

Vector2& Ogre::Vector2::operator= const Real  fScalar  ) 
 

Definition at line 115 of file OgreVector2.h.

References Ogre::Real.

Vector2& Ogre::Vector2::operator= const Vector2 rkVector  ) 
 

Assigns the value of the other vector.

Parameters:
rkVector The other vector

Definition at line 107 of file OgreVector2.h.

References x, and y.

bool Ogre::Vector2::operator== const Vector2 rkVector  )  const
 

Definition at line 123 of file OgreVector2.h.

References x, and y.

bool Ogre::Vector2::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.

Definition at line 378 of file OgreVector2.h.

References x, and y.

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

Definition at line 96 of file OgreVector2.h.

References Ogre::Real.

Real Ogre::Vector2::operator[] const size_t  i  )  const
 

Definition at line 89 of file OgreVector2.h.

References Ogre::Real.

Vector2 Ogre::Vector2::perpendicular void   )  const
 

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.

Definition at line 418 of file OgreVector2.h.

Vector2 Ogre::Vector2::randomDeviant Real  angle  )  const
 

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
up Any vector perpendicular to this one (which could generated by cross-product of this vector and any other non-colinear vector). If you choose not to provide this the function will derive one on it's own, however if you provide one yourself the function will be faster (this allows you to reuse up vectors if you call this method more than once)
Returns:
A random vector which deviates from this vector by angle. This vector will not be normalised, normalise it if you wish afterwards.

Definition at line 448 of file OgreVector2.h.

References Ogre::Real.

Vector2 Ogre::Vector2::reflect const Vector2 normal  )  const
 

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.

Definition at line 479 of file OgreVector2.h.

Real Ogre::Vector2::squaredLength  )  const
 

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.

Definition at line 305 of file OgreVector2.h.

References Ogre::Real.


Friends And Related Function Documentation

Vector2 operator * const Real  fScalar,
const Vector2 rkVector
[friend]
 

Definition at line 198 of file OgreVector2.h.

Vector2 operator+ const Real  lhs,
const Vector2 rhs
[friend]
 

Definition at line 214 of file OgreVector2.h.

Vector2 operator+ const Vector2 lhs,
const Real  rhs
[friend]
 

Definition at line 208 of file OgreVector2.h.

Vector2 operator- const Real  lhs,
const Vector2 rhs
[friend]
 

Definition at line 225 of file OgreVector2.h.

Vector2 operator- const Vector2 lhs,
const Real  rhs
[friend]
 

Definition at line 220 of file OgreVector2.h.

_OgreExport friend std::ostream& operator<< std::ostream &  o,
const Vector2 v
[friend]
 

Function for writing to a stream.

Definition at line 495 of file OgreVector2.h.


Member Data Documentation

const Vector2 Ogre::Vector2::NEGATIVE_UNIT_X [static]
 

Definition at line 488 of file OgreVector2.h.

const Vector2 Ogre::Vector2::NEGATIVE_UNIT_Y [static]
 

Definition at line 489 of file OgreVector2.h.

const Vector2 Ogre::Vector2::UNIT_SCALE [static]
 

Definition at line 490 of file OgreVector2.h.

const Vector2 Ogre::Vector2::UNIT_X [static]
 

Definition at line 486 of file OgreVector2.h.

const Vector2 Ogre::Vector2::UNIT_Y [static]
 

Definition at line 487 of file OgreVector2.h.

Real Ogre::Vector2::val[2]
 

Definition at line 49 of file OgreVector2.h.

Referenced by Ogre::AnimableValue::setAsBaseValue().

Real Ogre::Vector2::x
 

Definition at line 47 of file OgreVector2.h.

Referenced by crossProduct(), dotProduct(), makeCeil(), makeFloor(), midPoint(), operator *(), operator!=(), operator+(), operator+=(), operator-(), operator-=(), operator/(), operator<(), operator=(), operator==(), and operator>().

Real Ogre::Vector2::y
 

Definition at line 47 of file OgreVector2.h.

Referenced by crossProduct(), dotProduct(), makeCeil(), makeFloor(), midPoint(), operator *(), operator!=(), operator+(), operator+=(), operator-(), operator-=(), operator/(), operator<(), operator=(), operator==(), and operator>().

const Vector2 Ogre::Vector2::ZERO [static]
 

Definition at line 485 of file OgreVector2.h.


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

Copyright © 2000-2005 by The OGRE Team
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Mar 12 14:45:54 2006