Angel 3.2
A 2D Game Prototyping Engine
Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | List of all members
Vector3 Struct Reference

A three-dimensional floating point vector and associated math functions. More...

#include <Vector3.h>

Public Member Functions

 Vector3 (float x, float y, float z)
 
 Vector3 (float value)
 
 Vector3 ()
 
float Length ()
 
float LengthSquared ()
 
void Normalize ()
 
bool operator== (const Vector3 &v) const
 
bool operator!= (const Vector3 &v) const
 
Vector3 operator- () const
 
Vector3 operator- (const Vector3 &v) const
 
Vector3 operator+ (const Vector3 &v) const
 
Vector3 operator/ (float divider) const
 
Vector3 operator* (float scaleFactor) const
 
Vector3operator+= (const Vector3 &v)
 
Vector3operator-= (const Vector3 &v)
 
Vector3operator*= (float f)
 
Vector3operator/= (float f)
 

Static Public Member Functions

static float Distance (const Vector3 &value1, const Vector3 &value2)
 
static float DistanceSquared (const Vector3 &value1, const Vector3 &value2)
 
static float Dot (const Vector3 &value1, const Vector3 &value2)
 
static Vector3 Normalize (const Vector3 &value)
 
static Vector3 Reflect (const Vector3 &vector, const Vector3 &normal)
 
static Vector3 Min (const Vector3 &value1, const Vector3 &value2)
 
static Vector3 Max (const Vector3 &value1, const Vector3 &value2)
 
static Vector3 Clamp (const Vector3 &value1, const Vector3 &min, const Vector3 &max)
 
static Vector3 Lerp (const Vector3 &value1, const Vector3 &value2, float amount)
 
static Vector3 Negate (const Vector3 &value)
 

Public Attributes

float X
 
float Y
 
float Z
 

Static Public Attributes

static Vector3 Zero
 
static Vector3 One
 
static Vector3 UnitX
 
static Vector3 UnitY
 
static Vector3 UnitZ
 

Detailed Description

A floating point three-dimensional vector. Can be used either as a traditional vector (indicating a direction) or a position (treating X, Y, and Z as coordinates).

Definition at line 38 of file Vector3.h.

Constructor & Destructor Documentation

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

Constructor to initialize the vector to set dimensions

Parameters
xThe X dimension
yThe Y dimension
zThe Z dimension

Definition at line 43 of file Vector3.cpp.

Vector3::Vector3 ( float  value)

Constructor to initialize the vector to uniform dimensions

Parameters
valueThe value to use for the X, Y, and Z dimensions

Definition at line 49 of file Vector3.cpp.

Vector3::Vector3 ( )

Constructor to initialize a zero-length vector (0, 0, 0)

Definition at line 55 of file Vector3.cpp.

Member Function Documentation

float Vector3::Length ( )

Get the absolute magnitude of the vector. Uses a square-root, so be careful calling this too much within a loop.

Returns
The length (magnitude) of the vector

Definition at line 61 of file Vector3.cpp.

float Vector3::LengthSquared ( )

Get the squared magnitude of the vector – if all you care about is comparison, it's a lot faster to consider the squared lengths of the vectors.

Returns
The length (magnitude) of the vector squared

Definition at line 66 of file Vector3.cpp.

float Vector3::Distance ( const Vector3 value1,
const Vector3 value2 
)
static

Get the absolute distance between two points (most useful if the Vector2 represents a position). Uses a square-root, so be careful calling this too much within a loop.

Parameters
value1The first point
value2The second point
Returns
The distance between the two points

Definition at line 71 of file Vector3.cpp.

float Vector3::DistanceSquared ( const Vector3 value1,
const Vector3 value2 
)
static

Get the absolute distance between two points – if all you care about is comparison, it's a lot faster to consider the squared lengths of the vectors.

Parameters
value1The first point
value2The second point
Returns
The distance between the two points squared

Definition at line 76 of file Vector3.cpp.

float Vector3::Dot ( const Vector3 value1,
const Vector3 value2 
)
static

Get the dot product of two vectors.

Parameters
value1The first vector
value2The second vector
Returns
The dot product

Definition at line 82 of file Vector3.cpp.

void Vector3::Normalize ( )

Normalizes a vector in place – retains its direction, but ensures that its magnitude is equal to 1.0.

Definition at line 87 of file Vector3.cpp.

Vector3 Vector3::Normalize ( const Vector3 value)
static

Get the normalized value for a Vector2 without affecting the original.

Parameters
valueThe Vector3 to normalize
Returns
A normalized version of the passed-in Vector3

Definition at line 107 of file Vector3.cpp.

Vector3 Vector3::Reflect ( const Vector3 vector,
const Vector3 normal 
)
static

Reflect one Vector around another

Parameters
vectorThe vector to reflect
normalThe normal to reflect it around
Returns
The new vector resulting from the reflection

Definition at line 114 of file Vector3.cpp.

Vector3 Vector3::Min ( const Vector3 value1,
const Vector3 value2 
)
static

Get a new vector from the minimum X, Y, and Z of the two

Returns
The vector composed from minimums on all axes

Definition at line 119 of file Vector3.cpp.

Vector3 Vector3::Max ( const Vector3 value1,
const Vector3 value2 
)
static

Get a new vector from the maximum X, Y, and Z of the two

Returns
The vector composed from the maximums on all axes

Definition at line 124 of file Vector3.cpp.

Vector3 Vector3::Clamp ( const Vector3 value1,
const Vector3 min,
const Vector3 max 
)
static

Clamp a vector to a given minimum and maximum

Parameters
valueThe vector to be clamped
minThe vector representing the X, Y, and Z minimums for the clamping
maxThe vector representing the X, Y, and Z maximums for the clamping
Returns
The clamped vector

Definition at line 129 of file Vector3.cpp.

Vector3 Vector3::Lerp ( const Vector3 value1,
const Vector3 value2,
float  amount 
)
static

Perform a linear interpolation between two vectors

Parameters
value1The starting point vector
value2The ending point vector
amountThe amount (from 0.0 to 1.0) to interpolate between them
Returns
The interpolated vector

Definition at line 134 of file Vector3.cpp.

Vector3 Vector3::Negate ( const Vector3 value)
static

Get a negated vector – if you add the result and the original, you should get a zero-length vector (0, 0)

Parameters
valueThe vector to negate
Returns
The negated vector

Definition at line 138 of file Vector3.cpp.

Member Data Documentation

float Vector3::X

The X dimension, publicly available because it's so often gotten or set and there's no good reason to encapsulate it.

Definition at line 44 of file Vector3.h.

float Vector3::Y

The Z dimension, publicly available because it's so often gotten or set and there's no good reason to encapsulate it.

Definition at line 50 of file Vector3.h.

float Vector3::Z

The Z dimension, publicly available because it's so often gotten or set and there's no good reason to encapsulate it.

Definition at line 56 of file Vector3.h.

Vector3 Vector3::Zero
static

A reference to a zero-length vector (0, 0, 0)

NB: We can't make a static member variable constant, so it is possible to change this value. That is a horrible idea and will make the engine act "odd" at best.

Definition at line 65 of file Vector3.h.

Vector3 Vector3::One
static

A reference to a (1, 1, 1) vector

NB: We can't make a static member variable constant, so it is possible to change this value. That is a horrible idea and will make the engine act "odd" at best.

Definition at line 74 of file Vector3.h.

Vector3 Vector3::UnitX
static

A reference to a (1, 0, 0) vector

NB: We can't make a static member variable constant, so it is possible to change this value. That is a horrible idea and will make the engine act "odd" at best.

Definition at line 83 of file Vector3.h.

Vector3 Vector3::UnitY
static

A reference to a (0, 1, 0) vector

NB: We can't make a static member variable constant, so it is possible to change this value. That is a horrible idea and will make the engine act "odd" at best.

Definition at line 92 of file Vector3.h.

Vector3 Vector3::UnitZ
static

A reference to a (0, 0, 1) vector

NB: We can't make a static member variable constant, so it is possible to change this value. That is a horrible idea and will make the engine act "odd" at best.

Definition at line 101 of file Vector3.h.


The documentation for this struct was generated from the following files: