CUGL 2.5
Cornell University Game Library
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | List of all members
cugl::Vec3 Class Reference

#include <CUVec3.h>

Public Member Functions

 Vec3 ()
 
 Vec3 (float x, float y, float z)
 
 Vec3 (const float *array)
 
 Vec3 (const Vec3 p1, const Vec3 p2)
 
Vec3operator= (const float *array)
 
Vec3set (float x, float y, float z)
 
Vec3set (const float *array)
 
Vec3set (const Vec3 v)
 
Vec3set (const Vec3 p1, const Vec3 p2)
 
Vec3setZero ()
 
Vec3clamp (const Vec3 min, const Vec3 max)
 
Vec3 getClamp (const Vec3 min, const Vec3 max) const
 
Vec3add (const Vec3 v)
 
Vec3add (float x, float y, float z)
 
Vec3subtract (const Vec3 v)
 
Vec3subtract (float x, float y, float z)
 
Vec3scale (float s)
 
Vec3scale (float sx, float sy, float sz)
 
Vec3scale (const Vec3 v)
 
Vec3divide (float s)
 
Vec3divide (float sx, float sy, float sz)
 
Vec3divide (const Vec3 v)
 
Vec3negate ()
 
Vec3reciprocate ()
 
Vec3 getNegation () const
 
Vec3 getReciprocal () const
 
Vec3map (std::function< float(float)> func)
 
Vec3 getMap (std::function< float(float)> func) const
 
Vec3operator+= (const Vec3 v)
 
Vec3operator-= (const Vec3 v)
 
Vec3operator*= (float s)
 
Vec3operator*= (const Vec3 v)
 
Vec3operator/= (float s)
 
Vec3operator/= (const Vec3 v)
 
const Vec3 operator+ (const Vec3 v) const
 
const Vec3 operator- (const Vec3 v) const
 
const Vec3 operator- () const
 
const Vec3 operator* (float s) const
 
const Vec3 operator* (const Vec3 v) const
 
const Vec3 operator/ (float s) const
 
const Vec3 operator/ (const Vec3 v) const
 
bool operator< (const Vec3 v) const
 
bool operator<= (const Vec3 v) const
 
bool operator> (const Vec3 v) const
 
bool operator>= (const Vec3 v) const
 
bool operator== (const Vec3 v) const
 
bool operator!= (const Vec3 v) const
 
bool under (const Vec3 v) const
 
bool over (const Vec3 v) const
 
bool equals (const Vec3 v, float epsilon=CU_MATH_EPSILON) const
 
bool isZero () const
 
bool isNearZero (float epsilon=CU_MATH_EPSILON) const
 
bool isOne () const
 
bool isInvertible () const
 
bool isUnit (float epsilon=CU_MATH_EPSILON) const
 
float getAngle (const Vec3 other, const Vec3 up=Vec3::UNIT_Z) const
 
float distance (const Vec3 v) const
 
float distanceSquared (const Vec3 v) const
 
float length () const
 
float lengthSquared () const
 
float dot (const Vec3 v) const
 
Vec3cross (const Vec3 v)
 
Vec3 getCross (const Vec3 other) const
 
Vec3normalize ()
 
Vec3 getNormalization () const
 
Vec3 getMidpoint (const Vec3 other) const
 
Vec3project (const Vec3 other)
 
Vec3 getProjection (const Vec3 other) const
 
Vec3lerp (const Vec3 other, float alpha)
 
Vec3 getLerp (const Vec3 other, float alpha)
 
Vec3smooth (const Vec3 target, float elapsed, float response)
 
std::string toString (bool verbose=false) const
 
 operator std::string () const
 
 operator Color4 () const
 
 Vec3 (Color4 color)
 
Vec3operator= (Color4 color)
 
 operator Color4f () const
 
 Vec3 (const Color4f color)
 
Vec3operator= (const Color4f color)
 
 operator Vec2 () const
 
 Vec3 (const Vec2 v)
 
 Vec3 (const Vec2 v, float z)
 
Vec3operator= (const Vec2 v)
 
 operator Vec4 () const
 
 Vec3 (const Vec4 v)
 
Vec3operator= (const Vec4 size)
 

Static Public Member Functions

static Vec3clamp (const Vec3 v, const Vec3 min, const Vec3 max, Vec3 *dst)
 
static float angle (const Vec3 v1, const Vec3 v2, const Vec3 up=Vec3::UNIT_Z)
 
static Vec3add (const Vec3 v1, const Vec3 v2, Vec3 *dst)
 
static Vec3subtract (const Vec3 v1, const Vec3 v2, Vec3 *dst)
 
static Vec3scale (const Vec3 v, float s, Vec3 *dst)
 
static Vec3scale (const Vec3 v1, const Vec3 v2, Vec3 *dst)
 
static Vec3divide (const Vec3 v, float s, Vec3 *dst)
 
static Vec3divide (const Vec3 v1, const Vec3 v2, Vec3 *dst)
 
static Vec3reciprocate (const Vec3 v, Vec3 *dst)
 
static Vec3negate (const Vec3 v, Vec3 *dst)
 
static float dot (const Vec3 v1, const Vec3 v2)
 
static Vec3cross (const Vec3 v1, const Vec3 v2, Vec3 *dst)
 
static Vec3normalize (const Vec3 v, Vec3 *dst)
 
static Vec3midpoint (const Vec3 v1, const Vec3 v2, Vec3 *dst)
 
static Vec3project (const Vec3 v1, const Vec3 v2, Vec3 *dst)
 
static Vec3lerp (const Vec3 v1, const Vec3 v2, float alpha, Vec3 *dst)
 

Public Attributes

float x
 
float y
 
float z
 

Static Public Attributes

static const Vec3 ZERO
 
static const Vec3 ONE
 
static const Vec3 UNIT_X
 
static const Vec3 UNIT_Y
 
static const Vec3 UNIT_Z
 

Detailed Description

This class defines a 3-element floating point vector.

This class may be used to represent either a normal, a direction or a point interchangeably without casting. In addition, instances of this class may be freely cast to Color4 and vectors of other sizes.

This class is in standard layout with fields of uniform type. This means that it is safe to reinterpret_cast objects to float arrays.

Constructor & Destructor Documentation

◆ Vec3() [1/9]

cugl::Vec3::Vec3 ( )
inline

Constructs a new vector initialized to all zeros.

◆ Vec3() [2/9]

cugl::Vec3::Vec3 ( float  x,
float  y,
float  z 
)
inline

Constructs a new vector initialized to the specified values.

Parameters
xThe x coordinate.
yThe y coordinate.
zThe z coordinate.

◆ Vec3() [3/9]

cugl::Vec3::Vec3 ( const float *  array)
inline

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

Parameters
arrayAn array containing the elements of the vector in the order x, y, z.

◆ Vec3() [4/9]

cugl::Vec3::Vec3 ( const Vec3  p1,
const Vec3  p2 
)
inline

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

Parameters
p1The first point.
p2The second point.

◆ Vec3() [5/9]

cugl::Vec3::Vec3 ( Color4  color)
explicit

Creates a vector from the given color.

The attributes are read in the order r,g,b. The alpha value is dropped.

Parameters
colorThe color to convert

◆ Vec3() [6/9]

cugl::Vec3::Vec3 ( const Color4f  color)
explicit

Creates a vector from the given color.

The attributes are read in the order r,g,b. The alpha value is dropped.

Parameters
colorThe color to convert

◆ Vec3() [7/9]

cugl::Vec3::Vec3 ( const Vec2  v)
explicit

Creates a 3d vector from the given 2d one.

The z-value is set to 0.

Parameters
vThe vector to convert

◆ Vec3() [8/9]

cugl::Vec3::Vec3 ( const Vec2  v,
float  z 
)

Creates a 3d vector from the given 2d one.

The z-coordinate is given the appropriate value

Parameters
vThe vector to convert
zThe z-coordinate

◆ Vec3() [9/9]

cugl::Vec3::Vec3 ( const Vec4  v)
explicit

Creates a 3d vector from the given homogenous one.

All coordinates are divided by the w-coordinate (assuming it is not zero) before this conversion. Afterwards, w is dropped.

Parameters
vThe vector to convert

Member Function Documentation

◆ add() [1/3]

Vec3 & cugl::Vec3::add ( const Vec3  v)
inline

Adds the given vector to this one in place.

Parameters
vThe vector to add
Returns
A reference to this (modified) Vec3 for chaining.

◆ add() [2/3]

static Vec3 * cugl::Vec3::add ( const Vec3  v1,
const Vec3  v2,
Vec3 dst 
)
static

Adds the specified vectors and stores the result in dst.

Parameters
v1The first vector.
v2The second vector.
dstA vector to store the result in
Returns
A reference to dst for chaining

◆ add() [3/3]

Vec3 & cugl::Vec3::add ( float  x,
float  y,
float  z 
)
inline

Adds the given values to this vector.

Parameters
xThe x coordinate to add.
yThe y coordinate to add.
zThe z coordinate to add.
Returns
A reference to this (modified) Vec3 for chaining.

◆ angle()

static float cugl::Vec3::angle ( const Vec3  v1,
const Vec3  v2,
const Vec3  up = Vec3::UNIT_Z 
)
static

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

The resulting angle is signed. It uses the (optional) up direction to determine the relative plane for signing the angle. If either vector is zero, the result is undefined.

Parameters
v1The first vector.
v2The second vector.
upThe up direction (defaults to Vec3::UNIT_Z)
Returns
The angle between the two vectors (in radians).

◆ clamp() [1/2]

Vec3 & cugl::Vec3::clamp ( const Vec3  min,
const Vec3  max 
)
inline

Clamps this vector within the given range.

Parameters
minThe minimum value.
maxThe maximum value.
Returns
A reference to this (modified) Vec3 for chaining.

◆ clamp() [2/2]

static Vec3 * cugl::Vec3::clamp ( const Vec3  v,
const Vec3  min,
const Vec3  max,
Vec3 dst 
)
static

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

Parameters
vThe vector to clamp.
minThe minimum value.
maxThe maximum value.
dstA vector to store the result in.
Returns
A reference to dst for chaining

◆ cross() [1/2]

Vec3 & cugl::Vec3::cross ( const Vec3  v)
inline

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

Parameters
vThe vector to cross with
Returns
A reference to this (modified) Vec3 for chaining.

◆ cross() [2/2]

static Vec3 * cugl::Vec3::cross ( const Vec3  v1,
const Vec3  v2,
Vec3 dst 
)
static

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

Parameters
v1The first vector.
v2The second vector.
dstThe destination vector.
Returns
A reference to dst for chaining

◆ distance()

float cugl::Vec3::distance ( const Vec3  v) const
inline

Returns the distance between this vector and v.

Parameters
vThe other vector.
Returns
The distance between this vector and v.

{

See also
distanceSquared}

◆ distanceSquared()

float cugl::Vec3::distanceSquared ( const Vec3  v) const
inline

Returns the squared distance between this vector and v.

This method is faster than distance because it does not need to compute a square root. Hence it is best to us this method when it is not necessary to get the exact distance between two vectors (e.g. when simply comparing the distance between different vectors).

Parameters
vThe other vector.
Returns
The squared distance between this vector and v.

{

See also
distance}

◆ divide() [1/5]

Vec3 & cugl::Vec3::divide ( const Vec3  v)

Divides this vector in place by the given vector.

This method is provided to support non-uniform scaling.

Parameters
vThe vector to divide by
Returns
A reference to this (modified) Vec3 for chaining.

◆ divide() [2/5]

static Vec3 * cugl::Vec3::divide ( const Vec3  v,
float  s,
Vec3 dst 
)
static

Divides the specified vector and stores the result in dst.

The division is uniform by the constant s.

Parameters
vThe vector to divide.
sThe uniform division factor.
dstThe destination vector.
Returns
A reference to dst for chaining

◆ divide() [3/5]

static Vec3 * cugl::Vec3::divide ( const Vec3  v1,
const Vec3  v2,
Vec3 dst 
)
static

Divides the specified vector and stores the result in dst.

The division is nonuniform by the attributes in v2.

Parameters
v1The vector to divide.
v2The nonuniform division factor.
dstThe destination vector.
Returns
A reference to dst for chaining

◆ divide() [4/5]

Vec3 & cugl::Vec3::divide ( float  s)

Divides this vector in place by the given factor.

Parameters
sThe scalar to divide by
Returns
A reference to this (modified) Vec3 for chaining.

◆ divide() [5/5]

Vec3 & cugl::Vec3::divide ( float  sx,
float  sy,
float  sz 
)

Divides this vector nonuniformly by the given factors.

Parameters
sxThe scalar to divide the x-axis
syThe scalar to divide the y-axis
szThe scalar to divide the z-axis
Returns
A reference to this (modified) Vec3 for chaining.

◆ dot() [1/2]

float cugl::Vec3::dot ( const Vec3  v) const
inline

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

Parameters
vThe vector to compute the dot product with.
Returns
The dot product.

◆ dot() [2/2]

static float cugl::Vec3::dot ( const Vec3  v1,
const Vec3  v2 
)
static

Returns the dot product between the specified vectors.

Parameters
v1The first vector.
v2The second vector.
Returns
The dot product between the vectors.

◆ equals()

bool cugl::Vec3::equals ( const Vec3  v,
float  epsilon = CU_MATH_EPSILON 
) const
inline

Returns true if the vectors are within tolerance of each other.

The tolerance bounds the traditional Euclidean difference between the two vectors (treated as points)

Parameters
vThe vector to compare against.
epsilonThe comparison tolerance.
Returns
true if the vectors are within tolerance of each other.

◆ getAngle()

float cugl::Vec3::getAngle ( const Vec3  other,
const Vec3  up = Vec3::UNIT_Z 
) const

Returns the angle between this vector and other.

The resulting angle is signed. It uses the (optional) up direction to determine the relative plane for signing the angle. If either vector is zero, the result is undefined.

Parameters
otherThe vector to sweep towards.
upThe up direction (defaults to Vec3::UNIT_Z)
Returns
the angle between this vector and other.

◆ getClamp()

Vec3 cugl::Vec3::getClamp ( const Vec3  min,
const Vec3  max 
) const
inline

Returns a copy of this vector clamped within the given range.

Note: this does not modify this vector.

Parameters
minThe minimum value.
maxThe maximum value.
Returns
A copy of this vector clamped within the given range.

◆ getCross()

Vec3 cugl::Vec3::getCross ( const Vec3  other) const
inline

Returns the cross product of this vector with another

Note: this does not modify this vector.

Parameters
otherThe vector to cross with
Returns
the cross product of this vector with another

◆ getLerp()

Vec3 cugl::Vec3::getLerp ( const Vec3  other,
float  alpha 
)
inline

Returns the linear interpolation of this vector with other.

If alpha is 0, the vector is unchanged. If alpha is 1, the vector is other. Otherwise it is a value on the line ab. This method supports alpha outside of the range 0..1.

Parameters
otherThe other end of the line segment.
alphaThe interpolation value in 0..1
Returns
The linear interpolation of this vector with other.

◆ getMap()

Vec3 cugl::Vec3::getMap ( std::function< float(float)>  func) const
inline

Returns a copy of this vector with func applied to each component.

This method supports any function that has the signature float func(float); This includes many of the functions in math.h.

Parameters
funcThe function to map on the coordinates.
Returns
A copy of this vector with func applied to each component.

◆ getMidpoint()

Vec3 cugl::Vec3::getMidpoint ( const Vec3  other) const
inline

Returns the midpoint between this point and another.

Note: this does not modify this vector.

Parameters
otherThe other end of the line segment.
Returns
the midpoint between this point and another.

◆ getNegation()

Vec3 cugl::Vec3::getNegation ( ) const
inline

Returns a negated copy of this vector.

Note: This method does not modify the vector

Returns
a negated copy of this vector.

◆ getNormalization()

Vec3 cugl::Vec3::getNormalization ( ) const
inline

Returns a normalized copy of this vector.

This method creates a copy of this vector that is of unit length (i.e. 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. Note: this does not modify this vector.

Returns
A normalized copy of this vector.

◆ getProjection()

Vec3 cugl::Vec3::getProjection ( const Vec3  other) const
inline

Returns the projection of this vector on to the other one.

Note: this does not modify this vector.

Parameters
otherThe vector to project on.
Returns
the projection of this vector on to the other one.

◆ getReciprocal()

Vec3 cugl::Vec3::getReciprocal ( ) const
inline

Returns a reciprocated copy of this vector.

The reciprocal is computed for each element invidiually. This method does not check that all elements are non-zero. If any element is zero, the result will be system-dependent.

Note: This method does not modify the vector

Returns
a reciprocated copy of this vector.

◆ isInvertible()

bool cugl::Vec3::isInvertible ( ) const
inline

Returns true if this vector contains no zeroes.

Returns
true if this vector contains no zeroes, false otherwise.

◆ isNearZero()

bool cugl::Vec3::isNearZero ( float  epsilon = CU_MATH_EPSILON) const
inline

Returns true if this vector is with tolerance of the origin.

Parameters
epsilonThe comparison tolerance
Returns
true if this vector is with tolerance of the origin.

◆ isOne()

bool cugl::Vec3::isOne ( ) const
inline

Returns true if this vector contains all ones.

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

◆ isUnit()

bool cugl::Vec3::isUnit ( float  epsilon = CU_MATH_EPSILON) const
inline

Returns true if this vector is a unit vector.

Parameters
epsilonThe comparison tolerance
Returns
true if this vector is a unit vector.

◆ isZero()

bool cugl::Vec3::isZero ( ) const
inline

Returns true this vector contains all zeros.

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

◆ length()

float cugl::Vec3::length ( ) const
inline

Returns the length of this vector.

Returns
The length of the vector.

{

See also
lengthSquared}

◆ lengthSquared()

float cugl::Vec3::lengthSquared ( ) const
inline

Returns the squared length of this vector.

This method is faster than length because it does not need to compute a square root. Hence it is best to us this method when it is not necessary to get the exact length of a vectors (e.g. when simply comparing the length to a threshold value).

Returns
The squared length of the vector.

{

See also
length}

◆ lerp() [1/2]

Vec3 & cugl::Vec3::lerp ( const Vec3  other,
float  alpha 
)
inline

Modifies this vector to be the linear interpolation with other.

If alpha is 0, the vector is unchanged. If alpha is 1, the vector is other. Otherwise it is a value on the line ab. This method supports alpha outside of the range 0..1.

Parameters
otherThe other end of the line segment.
alphaThe interpolation value in 0..1
Returns
This vector, after the interpolation.

◆ lerp() [2/2]

static Vec3 * cugl::Vec3::lerp ( const Vec3  v1,
const Vec3  v2,
float  alpha,
Vec3 dst 
)
static

Computes the linear interpolation of two vectors and stores it in dst.

If alpha is 0, the vector is a copy of v1. If alpha is 1, the vector is a copy of v2. Otherwise it is a value on the line v1v2. This method supports alpha outside of the range 0..1.

Parameters
v1The first point.
v2The second point.
alphaThe interpolation value.
dstThe destination vector.
Returns
The linear interpolation of this vector with other.

◆ map()

Vec3 & cugl::Vec3::map ( std::function< float(float)>  func)
inline

Maps the given function to the vector coordinates in place.

This method supports any function that has the signature float func(float); This includes many of the functions in math.h.

Parameters
funcThe function to map on the coordinates.
Returns
A reference to this (modified) Vec3 for chaining.

◆ midpoint()

static Vec3 * cugl::Vec3::midpoint ( const Vec3  v1,
const Vec3  v2,
Vec3 dst 
)
static

Computes the midpoint between two points and stores it in dst.

Parameters
v1The first point.
v2The second point.
dstThe destination vector.
Returns
A reference to dst for chaining

◆ negate() [1/2]

Vec3 & cugl::Vec3::negate ( )
inline

Negates this vector.

Returns
A reference to this (modified) Vec3 for chaining.

◆ negate() [2/2]

static Vec3 * cugl::Vec3::negate ( const Vec3  v,
Vec3 dst 
)
static

Negates the specified vector and stores the result in dst.

Parameters
vThe vector to negate.
dstThe destination vector.
Returns
A reference to dst for chaining

◆ normalize() [1/2]

Vec3 & cugl::Vec3::normalize ( )

Normalizes this vector.

This method normalizes the vector so that it is of unit length (i.e. 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.

◆ normalize() [2/2]

static Vec3 * cugl::Vec3::normalize ( const Vec3  v,
Vec3 dst 
)
static

Normalizes the specified vector and stores the result in dst.

If the quaternion already has unit length or if the length of the quaternion is zero, this method copies v into dst.

Parameters
vThe vector to normalize.
dstThe destination vector.
Returns
A reference to dst for chaining

◆ operator Color4()

cugl::Vec3::operator Color4 ( ) const

Cast from Vec3 to a Color4.

◆ operator Color4f()

cugl::Vec3::operator Color4f ( ) const

Cast from Vec3 to a Color4f.

◆ operator std::string()

cugl::Vec3::operator std::string ( ) const
inline

Cast from Vec3 to a string.

◆ operator Vec2()

cugl::Vec3::operator Vec2 ( ) const

Casts from Vec2 to Vec3.

The z-value is dropped.

◆ operator Vec4()

cugl::Vec3::operator Vec4 ( ) const

Casts from Vec3 to Vec4.

The w-value is set to 1. That is because the standard usage of Vec4 objects is homogenous coords.

◆ operator!=()

bool cugl::Vec3::operator!= ( const Vec3  v) const
inline

Returns true if this vector is not equal to the given vector.

Comparison is exact, which may be unreliable given that the attributes are floats.

Parameters
vThe vector to compare against.
Returns
True if this vector is not equal to the given vector.

◆ operator*() [1/2]

const Vec3 cugl::Vec3::operator* ( const Vec3  v) const
inline

Returns the scalar product of this vector with the given vector.

This method is provided to support non-uniform scaling. Note: this does not modify this vector.

Parameters
vThe vector to scale by.
Returns
The scalar product of this vector with the given vector.

◆ operator*() [2/2]

const Vec3 cugl::Vec3::operator* ( float  s) const
inline

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

Note: this does not modify this vector.

Parameters
sThe value to scale by.
Returns
The scalar product of this vector with the given value.

◆ operator*=() [1/2]

Vec3 & cugl::Vec3::operator*= ( const Vec3  v)
inline

Scales this vector nonuniformly by the given vector.

Parameters
vThe vector to scale by
Returns
A reference to this (modified) Vec3 for chaining.

◆ operator*=() [2/2]

Vec3 & cugl::Vec3::operator*= ( float  s)
inline

Scales this vector in place by the given factor.

Parameters
sThe value to scale by
Returns
A reference to this (modified) Vec3 for chaining.

◆ operator+()

const Vec3 cugl::Vec3::operator+ ( const Vec3  v) const
inline

Returns the sum of this vector with the given vector.

Note: this does not modify this vector.

Parameters
vThe vector to add.
Returns
The sum of this vector with the given vector.

◆ operator+=()

Vec3 & cugl::Vec3::operator+= ( const Vec3  v)
inline

Adds the given vector to this one in place.

Parameters
vThe vector to add
Returns
A reference to this (modified) Vec3 for chaining.

◆ operator-() [1/2]

const Vec3 cugl::Vec3::operator- ( ) const
inline

Returns the negation of this vector.

Note: this does not modify this vector.

Returns
The negation of this vector.

◆ operator-() [2/2]

const Vec3 cugl::Vec3::operator- ( const Vec3  v) const
inline

Returns the difference of this vector with the given vector.

Note: this does not modify this vector.

Parameters
vThe vector to subtract.
Returns
The difference of this vector with the given vector.

◆ operator-=()

Vec3 & cugl::Vec3::operator-= ( const Vec3  v)
inline

Subtracts the given vector from this one in place.

Parameters
vThe vector to subtract
Returns
A reference to this (modified) Vec3 for chaining.

◆ operator/() [1/2]

const Vec3 cugl::Vec3::operator/ ( const Vec3  v) const
inline

Returns a copy of this vector divided by the given vector.

This method is provided to support non-uniform scaling. Note: this does not modify this vector.

Parameters
vthe vector to divide this vector with
Returns
A copy of this vector divided by the given vector

◆ operator/() [2/2]

const Vec3 cugl::Vec3::operator/ ( float  s) const
inline

Returns a copy of this vector divided by the given constant

Note: this does not modify this vector.

Parameters
sthe constant to divide this vector with
Returns
A copy of this vector divided by the given constant

◆ operator/=() [1/2]

Vec3 & cugl::Vec3::operator/= ( const Vec3  v)
inline

Divides this vector in place by the given vector.

This method is provided to support non-uniform scaling.

Parameters
vThe vector to divide by
Returns
A reference to this (modified) Vec3 for chaining.

◆ operator/=() [2/2]

Vec3 & cugl::Vec3::operator/= ( float  s)
inline

Divides this vector in place by the given factor.

Parameters
sThe scalar to divide by
Returns
A reference to this (modified) Vec3 for chaining.

◆ operator<()

bool cugl::Vec3::operator< ( const Vec3  v) const
inline

Returns true if this vector is less than the given vector.

This comparison uses the lexicographical order. To test if all components in this vector are less than those of v, use the method under().

Parameters
vThe vector to compare against.
Returns
True if this vector is less than the given vector.

◆ operator<=()

bool cugl::Vec3::operator<= ( const Vec3  v) const
inline

Returns true if this vector is less than or equal the given vector.

This comparison uses the lexicographical order. To test if all components in this vector are less than those of v, use the method under().

Parameters
vThe vector to compare against.
Returns
True if this vector is less than or equal the given vector.

◆ operator=() [1/5]

Vec3 & cugl::Vec3::operator= ( Color4  color)

Sets the coordinates of this vector to those of the given color.

The attributes are read in the order r,g,b. The alpha value is dropped.

Parameters
colorThe color to convert.
Returns
A reference to this (modified) Vec3 for chaining.

◆ operator=() [2/5]

Vec3 & cugl::Vec3::operator= ( const Color4f  color)

Sets the coordinates of this vector to those of the given color.

The attributes are read in the order r,g,b. The alpha value is dropped.

Parameters
colorThe color to convert.
Returns
A reference to this (modified) Vec3 for chaining.

◆ operator=() [3/5]

Vec3 & cugl::Vec3::operator= ( const float *  array)
inline

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

Parameters
arrayAn array containing the elements of the vector in the order x, y, z.
Returns
A reference to this (modified) Vec3 for chaining.

◆ operator=() [4/5]

Vec3 & cugl::Vec3::operator= ( const Vec2  v)

Sets the coordinates of this vector to those of the given 2d vector.

The z-value is set to 0.

Parameters
vThe vector to convert
Returns
A reference to this (modified) Vec3 for chaining.

◆ operator=() [5/5]

Vec3 & cugl::Vec3::operator= ( const Vec4  size)

Sets the coordinates of this vector to those of the given homogenous vector.

All coordinates are divided by the w-coordinate (assuming it is not zero) before this conversion. Afterwards, w is dropped.

Parameters
sizeThe vector to convert
Returns
A reference to this (modified) Vec3 for chaining.

◆ operator==()

bool cugl::Vec3::operator== ( const Vec3  v) const
inline

Returns true if this vector is equal to the given vector.

Comparison is exact, which may be unreliable given that the attributes are floats.

Parameters
vThe vector to compare against.
Returns
True if this vector is equal to the given vector.

◆ operator>()

bool cugl::Vec3::operator> ( const Vec3  v) const
inline

Returns true if this vector is greater than the given vector.

This comparison uses the lexicographical order. To test if all components in this vector are greater than those of v, use the method over().

Parameters
vThe vector to compare against.
Returns
True if this vector is greater than the given vector.

◆ operator>=()

bool cugl::Vec3::operator>= ( const Vec3  v) const
inline

Returns true if this vector is greater than or equal the given vector.

This comparison uses the lexicographical order. To test if all components in this vector are greater than those of v, use the method over().

Parameters
vThe vector to compare against.
Returns
True if this vector is greater than or equal the given vector.

◆ over()

bool cugl::Vec3::over ( const Vec3  v) const
inline

Returns true if this vector dominates the given vector.

Domination means that all components of this vector are greater than or equal to the components of the given vector.

Parameters
vThe vector to compare against.
Returns
True if this vector is dominated by the given vector.

◆ project() [1/2]

Vec3 & cugl::Vec3::project ( const Vec3  other)
inline

Modifies this vector to be its projection on to the other one.

Parameters
otherThe vector to project on.
Returns
This vector, after the projection.

◆ project() [2/2]

static Vec3 * cugl::Vec3::project ( const Vec3  v1,
const Vec3  v2,
Vec3 dst 
)
static

Computes the projection of one vector on to another and stores it in dst.

Parameters
v1The original vector.
v2The vector to project on.
dstThe destination vector.
Returns
A reference to dst for chaining

◆ reciprocate() [1/2]

Vec3 & cugl::Vec3::reciprocate ( )
inline

Reciprovates this vector in place.

The reciprocal is computed for each element invidiually. This method does not check that all elements are non-zero. If any element is zero, the result will be system-dependent.

Returns
A reference to this (modified) Vec4 for chaining.

◆ reciprocate() [2/2]

static Vec3 * cugl::Vec3::reciprocate ( const Vec3  v,
Vec3 dst 
)
static

Reciprocates the specified quaternion and stores the result in dst.

Reciprocation is applied to each element invidiually. This method does not check that all elements are non-zero. If any element is zero, the result will be system-dependent.

Parameters
vThe vector to reciprocate.
dstThe destination vector.
Returns
A reference to dst for chaining

◆ scale() [1/5]

Vec3 & cugl::Vec3::scale ( const Vec3  v)
inline

Scales this vector nonuniformly by the given vector.

Parameters
vThe vector to scale by
Returns
A reference to this (modified) Vec3 for chaining.

◆ scale() [2/5]

static Vec3 * cugl::Vec3::scale ( const Vec3  v,
float  s,
Vec3 dst 
)
static

Scales the specified vector and stores the result in dst.

The scale is uniform by the constant s.

Parameters
vThe vector to scale.
sThe uniform scaling factor.
dstThe destination vector.
Returns
A reference to dst for chaining

◆ scale() [3/5]

static Vec3 * cugl::Vec3::scale ( const Vec3  v1,
const Vec3  v2,
Vec3 dst 
)
static

Scales the specified vector and stores the result in dst.

The scale is nonuniform by the attributes in v2.

Parameters
v1The vector to scale.
v2The nonuniform scaling factor.
dstThe destination vector.
Returns
A reference to dst for chaining

◆ scale() [4/5]

Vec3 & cugl::Vec3::scale ( float  s)
inline

Scales this vector in place by the given factor.

Parameters
sThe scalar to multiply by
Returns
A reference to this (modified) Vec3 for chaining.

◆ scale() [5/5]

Vec3 & cugl::Vec3::scale ( float  sx,
float  sy,
float  sz 
)
inline

Scales this vector nonuniformly by the given factors.

Parameters
sxThe scalar to multiply the x-axis
syThe scalar to multiply the y-axis
szThe scalar to multiply the z-axis
Returns
A reference to this (modified) Vec3 for chaining.

◆ set() [1/4]

Vec3 & cugl::Vec3::set ( const float *  array)
inline

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

Parameters
arrayAn array containing the elements of the vector in the order x, y, z.
Returns
A reference to this (modified) Vec3 for chaining.

◆ set() [2/4]

Vec3 & cugl::Vec3::set ( const Vec3  p1,
const Vec3  p2 
)
inline

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

Parameters
p1The initial point of the vector.
p2The terminal point of the vector.
Returns
A reference to this (modified) Vec3 for chaining.

◆ set() [3/4]

Vec3 & cugl::Vec3::set ( const Vec3  v)
inline

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

Parameters
vThe vector to copy.
Returns
A reference to this (modified) Vec3 for chaining.

◆ set() [4/4]

Vec3 & cugl::Vec3::set ( float  x,
float  y,
float  z 
)
inline

Sets the elements of this vector to the specified values.

Parameters
xThe new x coordinate.
yThe new y coordinate.
zThe new z coordinate.
Returns
A reference to this (modified) Vec3 for chaining.

◆ setZero()

Vec3 & cugl::Vec3::setZero ( )
inline

Sets the elements of this vector to zero.

Returns
A reference to this (modified) Vec3 for chaining.

◆ smooth()

Vec3 & cugl::Vec3::smooth ( const Vec3  target,
float  elapsed,
float  response 
)

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
targetThe target value.
elapsedThe elapsed time between calls.
responseThe response time (in the same units as elapsed).
Returns
This vector, after smoothing

◆ subtract() [1/3]

Vec3 & cugl::Vec3::subtract ( const Vec3  v)
inline

Subtracts the given vector from this one in place.

Parameters
vThe vector to subtract
Returns
A reference to this (modified) Vec3 for chaining.

◆ subtract() [2/3]

static Vec3 * cugl::Vec3::subtract ( const Vec3  v1,
const Vec3  v2,
Vec3 dst 
)
static

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

Parameters
v1The first vector.
v2The second vector.
dstThe destination vector.
Returns
A reference to dst for chaining

◆ subtract() [3/3]

Vec3 & cugl::Vec3::subtract ( float  x,
float  y,
float  z 
)
inline

Subtracts the given values from this vector.

Parameters
xThe x coordinate to subtract.
yThe y coordinate to subtract.
zThe z coordinate to subtract.
Returns
A reference to this (modified) Vec3 for chaining.

◆ toString()

std::string cugl::Vec3::toString ( bool  verbose = false) const

Returns a string representation of this vector for debuggging purposes.

If verbose is true, the string will include class information. This allows us to unambiguously identify the class.

Parameters
verboseWhether to include class information
Returns
a string representation of this vector for debuggging purposes.

◆ under()

bool cugl::Vec3::under ( const Vec3  v) const
inline

Returns true if this vector is dominated by the given vector.

Domination means that all components of the given vector are greater than or equal to the components of this one.

Parameters
vThe vector to compare against.
Returns
True if this vector is dominated by the given vector.

Member Data Documentation

◆ ONE

const Vec3 cugl::Vec3::ONE
static

The ones vector Vec3(1,1,1)

◆ UNIT_X

const Vec3 cugl::Vec3::UNIT_X
static

The x-axis Vec3(1,0,0)

◆ UNIT_Y

const Vec3 cugl::Vec3::UNIT_Y
static

The y-axis Vec3(0,1,0)

◆ UNIT_Z

const Vec3 cugl::Vec3::UNIT_Z
static

The z-axis Vec3(0,0,1)

◆ x

float cugl::Vec3::x

The x-coordinate.

◆ y

float cugl::Vec3::y

The y-coordinate.

◆ z

float cugl::Vec3::z

The z-coordinate.

◆ ZERO

const Vec3 cugl::Vec3::ZERO
static

The zero vector Vec3(0,0,0)


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