|  | overview |  | wiki |  | api reference |  | download

- Main Page
- Classes

- Class List
- Class Index
- Class Hierarchy
- Class Members

All Classes Functions Variables Typedefs Enumerations Enumerator
Public Member Functions | Static Public Member Functions | Public Attributes
gameplay::Vector3 Class Reference

`#include <Vector3.h>`

List of all members.

## Public Member Functions

| Vector3 ()
| Vector3 (float x, float y, float z)
| Vector3 (const float *array)
| Vector3 (const Vector3 &p1, const Vector3 &p2)
| Vector3 (const Vector3 &copy)
| ~Vector3 ()
bool | isZero () const
bool | isOne () const
void | add (const Vector3 &v)
void | clamp (const Vector3 &min, const Vector3 &max)
void | cross (const Vector3 &v)
float | distance (const Vector3 &v) const
float | distanceSquared (const Vector3 &v) const
float | dot (const Vector3 &v) const
float | length () const
float | lengthSquared () const
void | negate ()
Vector3 & | normalize ()
void | normalize (Vector3 *dst) const
void | scale (float scalar)
void | set (float x, float y, float z)
void | set (const float *array)
void | set (const Vector3 &v)
void | set (const Vector3 &p1, const Vector3 &p2)
void | subtract (const Vector3 &v)
void | smooth (const Vector3 &target, float elapsedTime, float responseTime)
const Vector3 | operator+ (const Vector3 &v) const
Vector3 & | operator+= (const Vector3 &v)
const Vector3 | operator- (const Vector3 &v) const
Vector3 & | operator-= (const Vector3 &v)
const Vector3 | operator- () const
const Vector3 | operator* (float x) const
Vector3 & | operator*= (float x)
const Vector3 | operator/ (float x) const
bool | operator< (const Vector3 &v) const
bool | operator== (const Vector3 &v) const
bool | operator!= (const Vector3 &v) const

## Static Public Member Functions

static Vector3 | fromColor (unsigned int color)
static const Vector3 & | zero ()
static const Vector3 & | one ()
static const Vector3 & | unitX ()
static const Vector3 & | unitY ()
static const Vector3 & | unitZ ()
static float | angle (const Vector3 &v1, const Vector3 &v2)
static void | add (const Vector3 &v1, const Vector3 &v2, Vector3 *dst)
static void | clamp (const Vector3 &v, const Vector3 &min, const Vector3 &max, Vector3 *dst)
static void | cross (const Vector3 &v1, const Vector3 &v2, Vector3 *dst)
static float | dot (const Vector3 &v1, const Vector3 &v2)
static void | subtract (const Vector3 &v1, const Vector3 &v2, Vector3 *dst)

## Public Attributes

float | x
float | y
float | z

## Detailed Description

Defines a 3-element floating point vector.

When using a vector to represent a surface normal, the vector should typically be normalized. Other uses of directional vectors may wish to leave the magnitude of the vector intact. When used as a point, the elements of the vector represent a position in 3D space.

## Constructor & Destructor Documentation

gameplay::Vector3::Vector3 | ( |  | ) |

Constructs a new vector initialized to all zeros.

gameplay::Vector3::Vector3 | ( | float | x,
|  | float | y,
|  | float | z
| ) |  |

Constructs a new vector initialized to the specified values.

Parameters:

  x | The x coordinate.
  y | The y coordinate.
  z | The z coordinate.

gameplay::Vector3::Vector3 | ( | const float * | array | ) |

Constructs a new vector from the values in the specified array.

Parameters:

  array | An array containing the elements of the vector in the order x, y, z.

gameplay::Vector3::Vector3 | ( | const Vector3 & | p1,
|  | const Vector3 & | p2
| ) |  |

Constructs a vector that describes the direction between the specified points.

Parameters:

  p1 | The first point.
  p2 | The second point.

gameplay::Vector3::Vector3 | ( | const Vector3 & | copy | ) |

Constructs a new vector that is a copy of the specified vector.

Parameters:

  copy | The vector to copy.

gameplay::Vector3::~Vector3 | ( |  | ) |

Destructor.

## Member Function Documentation

void gameplay::Vector3::add | ( | const Vector3 & | v | ) |

Adds the elements of the specified vector to this one.

Parameters:

  v | The vector to add.

static void gameplay::Vector3::add | ( | const Vector3 & | v1,
|  | const Vector3 & | v2,
|  | Vector3 * | dst
| ) |  | `[static]`

Adds the specified vectors and stores the result in dst.

Parameters:

  v1 | The first vector.
  v2 | The second vector.
  dst | A vector to store the result in.

static float gameplay::Vector3::angle | ( | const Vector3 & | v1,
|  | const Vector3 & | v2
| ) |  | `[static]`

Returns the angle (in radians) between the specified vectors.

Parameters:

  v1 | The first vector.
  v2 | The second vector.

Returns:
  The angle between the two vectors (in radians).

void gameplay::Vector3::clamp | ( | const Vector3 & | min,
|  | const Vector3 & | max
| ) |  |

Clamps this vector within the specified range.

Parameters:

  min | The minimum value.
  max | The maximum value.

static void gameplay::Vector3::clamp | ( | const Vector3 & | v,
|  | const Vector3 & | min,
|  | const Vector3 & | max,
|  | Vector3 * | dst
| ) |  | `[static]`

Clamps the specified vector within the specified range and returns it in dst.

Parameters:

  v | The vector to clamp.
  min | The minimum value.
  max | The maximum value.
  dst | A vector to store the result in.

void gameplay::Vector3::cross | ( | const Vector3 & | v | ) |

Sets this vector to the cross product between itself and the specified vector.

Parameters:

  v | The vector to compute the cross product with.

static void gameplay::Vector3::cross | ( | const Vector3 & | v1,
|  | const Vector3 & | v2,
|  | Vector3 * | dst
| ) |  | `[static]`

Computes the cross product of the specified vectors and stores the result in dst.

Parameters:

  v1 | The first vector.
  v2 | The second vector.
  dst | A vector to store the result in.

float gameplay::Vector3::distance | ( | const Vector3 & | v | ) | const

Returns the distance between this vector and v.

Parameters:

  v | The other vector.

Returns:
  The distance between this vector and v.

See also:
  distanceSquared

float gameplay::Vector3::distanceSquared | ( | const Vector3 & | v | ) | const

Returns the squared distance between this vector and v.

When it is not necessary to get the exact distance between two vectors (for example, when simply comparing the distance between different vectors), it is advised to use this method instead of distance.

Parameters:

  v | The other vector.

Returns:
  The squared distance between this vector and v.

See also:
  distance

float gameplay::Vector3::dot | ( | const Vector3 & | v | ) | const

Returns the dot product of this vector and the specified vector.

Parameters:

  v | The vector to compute the dot product with.

Returns:
  The dot product.

static float gameplay::Vector3::dot | ( | const Vector3 & | v1,
|  | const Vector3 & | v2
| ) |  | `[static]`

Returns the dot product between the specified vectors.

Parameters:

  v1 | The first vector.
  v2 | The second vector.

Returns:
  The dot product between the vectors.

static Vector3 gameplay::Vector3::fromColor | ( | unsigned int | color | ) | `[static]`

Creates a new vector from an integer interpreted as an RGB value. E.g. 0xff0000 represents red or the vector (1, 0, 0).

Parameters:

  color | The integer to interpret as an RGB value.

Returns:
  A vector corresponding to the interpreted RGB color.

bool gameplay::Vector3::isOne | ( |  | ) | const

Indicates whether this vector contains all ones.

Returns:
  true if this vector contains all ones, false otherwise.

bool gameplay::Vector3::isZero | ( |  | ) | const

Indicates whether this vector contains all zeros.

Returns:
  true if this vector contains all zeros, false otherwise.

float gameplay::Vector3::length | ( |  | ) | const

Computes the length of this vector.

Returns:
  The length of the vector.

See also:
  lengthSquared

float gameplay::Vector3::lengthSquared | ( |  | ) | const

Returns the squared length of this vector.

When it is not necessary to get the exact length of a vector (for example, when simply comparing the lengths of different vectors), it is advised to use this method instead of length.

Returns:
  The squared length of the vector.

See also:
  length

void gameplay::Vector3::negate | ( |  | ) |

Negates this vector.

Vector3& gameplay::Vector3::normalize | ( |  | ) |

Normalizes this vector.

This method normalizes this Vector3 so that it is of unit length (in other words, the length of the vector after calling this method will be 1.0f). If the vector already has unit length or if the length of the vector is zero, this method does nothing.

Returns:
  This vector, after the normalization occurs.

void gameplay::Vector3::normalize | ( | Vector3 * | dst | ) | const

Normalizes this vector and stores the result in dst.

If the vector already has unit length or if the length of the vector is zero, this method simply copies the current vector into dst.

Parameters:

  dst | The destination vector.

static const Vector3& gameplay::Vector3::one | ( |  | ) | `[static]`

Returns the one vector.

Returns:
  The 3-element vector of 1s.

bool gameplay::Vector3::operator!= | ( | const Vector3 & | v | ) | const`[inline]`

Determines if this vector is not equal to the given vector.

Parameters:

  v | The vector to compare against.

Returns:
  True if this vector is not equal to the given vector, false otherwise.

const Vector3 gameplay::Vector3::operator* | ( | float | x | ) | const`[inline]`

Calculates the scalar product of this vector with the given value.

Note: this does not modify this vector.

Parameters:

  x | The value to scale by.

Returns:
  The scaled vector.

Vector3& gameplay::Vector3::operator*= | ( | float | x | ) | `[inline]`

Scales this vector by the given value.

Parameters:

  x | The value to scale by.

Returns:
  This vector, after the scale occurs.

const Vector3 gameplay::Vector3::operator+ | ( | const Vector3 & | v | ) | const`[inline]`

Calculates the sum of this vector with the given vector.

Note: this does not modify this vector.

Parameters:

  v | The vector to add.

Returns:
  The vector sum.

Vector3& gameplay::Vector3::operator+= | ( | const Vector3 & | v | ) | `[inline]`

Adds the given vector to this vector.

Parameters:

  v | The vector to add.

Returns:
  This vector, after the addition occurs.

const Vector3 gameplay::Vector3::operator- | ( | const Vector3 & | v | ) | const`[inline]`

Calculates the difference of this vector with the given vector.

Note: this does not modify this vector.

Parameters:

  v | The vector to subtract.

Returns:
  The vector difference.

const Vector3 gameplay::Vector3::operator- | ( |  | ) | const`[inline]`

Calculates the negation of this vector.

Note: this does not modify this vector.

Returns:
  The negation of this vector.

Vector3& gameplay::Vector3::operator-= | ( | const Vector3 & | v | ) | `[inline]`

Subtracts the given vector from this vector.

Parameters:

  v | The vector to subtract.

Returns:
  This vector, after the subtraction occurs.

const Vector3 gameplay::Vector3::operator/ | ( | float | x | ) | const`[inline]`

Returns the components of this vector divided by the given constant

Note: this does not modify this vector.

Parameters:

  x | the constant to divide this vector with

Returns:
  a smaller vector

bool gameplay::Vector3::operator< | ( | const Vector3 & | v | ) | const`[inline]`

Determines if this vector is less than the given vector.

Parameters:

  v | The vector to compare against.

Returns:
  True if this vector is less than the given vector, false otherwise.

bool gameplay::Vector3::operator== | ( | const Vector3 & | v | ) | const`[inline]`

Determines if this vector is equal to the given vector.

Parameters:

  v | The vector to compare against.

Returns:
  True if this vector is equal to the given vector, false otherwise.

void gameplay::Vector3::scale | ( | float | scalar | ) |

Scales all elements of this vector by the specified value.

Parameters:

  scalar | The scalar value.

void gameplay::Vector3::set | ( | float | x,
|  | float | y,
|  | float | z
| ) |  |

Sets the elements of this vector to the specified values.

Parameters:

  x | The new x coordinate.
  y | The new y coordinate.
  z | The new z coordinate.

void gameplay::Vector3::set | ( | const float * | array | ) |

Sets the elements of this vector from the values in the specified array.

Parameters:

  array | An array containing the elements of the vector in the order x, y, z.

void gameplay::Vector3::set | ( | const Vector3 & | v | ) |

Sets the elements of this vector to those in the specified vector.

Parameters:

  v | The vector to copy.

void gameplay::Vector3::set | ( | const Vector3 & | p1,
|  | const Vector3 & | p2
| ) |  |

Sets this vector to the directional vector between the specified points.

void gameplay::Vector3::smooth | ( | const Vector3 & | target,
|  | float | elapsedTime,
|  | float | responseTime
| ) |  |

Updates this vector towards the given target using a smoothing function. The given response time determines the amount of smoothing (lag). A longer response time yields a smoother result and more lag. To force this vector to follow the target closely, provide a response time that is very small relative to the given elapsed time.

Parameters:

  target | target value.
  elapsedTime | elapsed time between calls.
  responseTime | response time (in the same units as elapsedTime).

void gameplay::Vector3::subtract | ( | const Vector3 & | v | ) |

Subtracts this vector and the specified vector as (this - v) and stores the result in this vector.

Parameters:

  v | The vector to subtract.

static void gameplay::Vector3::subtract | ( | const Vector3 & | v1,
|  | const Vector3 & | v2,
|  | Vector3 * | dst
| ) |  | `[static]`

Subtracts the specified vectors and stores the result in dst. The resulting vector is computed as (v1 - v2).

Parameters:

  v1 | The first vector.
  v2 | The second vector.
  dst | The destination vector.

static const Vector3& gameplay::Vector3::unitX | ( |  | ) | `[static]`

Returns the unit x vector.

Returns:
  The 3-element unit vector along the x axis.

static const Vector3& gameplay::Vector3::unitY | ( |  | ) | `[static]`

Returns the unit y vector.

Returns:
  The 3-element unit vector along the y axis.

static const Vector3& gameplay::Vector3::unitZ | ( |  | ) | `[static]`

Returns the unit z vector.

Returns:
  The 3-element unit vector along the z axis.

static const Vector3& gameplay::Vector3::zero | ( |  | ) | `[static]`

Returns the zero vector.

Returns:
  The 3-element vector of 0s.

## Member Data Documentation

float gameplay::Vector3::x

The x-coordinate.

float gameplay::Vector3::y

The y-coordinate.

float gameplay::Vector3::z

The z-coordinate.

All Classes Functions Variables Typedefs Enumerations Enumerator