CUGL 2.3
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::Vec4 Class Reference

#include <CUVec4.h>

Public Member Functions

 Vec4 ()
 
 Vec4 (float x, float y, float z, float w)
 
 Vec4 (const float *array)
 
 Vec4 (const Vec4 p1, const Vec4 p2)
 
Vec4operator= (const float *array)
 
Vec4set (float x, float y, float z, float w)
 
Vec4set (const float *array)
 
Vec4set (const Vec4 v)
 
Vec4set (const Vec4 p1, const Vec4 p2)
 
Vec4setZero ()
 
Vec4clamp (const Vec4 min, const Vec4 max)
 
Vec4 getClamp (const Vec4 min, const Vec4 max) const
 
Vec4add (const Vec4 v)
 
Vec4add (float x, float y, float z, float w)
 
Vec4subtract (const Vec4 v)
 
Vec4subtract (float x, float y, float z, float w)
 
Vec4scale (float s)
 
Vec4scale (float sx, float sy, float sz, float sw)
 
Vec4scale (const Vec4 v)
 
Vec4divide (float s)
 
Vec4divide (float sx, float sy, float sz, float sw)
 
Vec4divide (const Vec4 v)
 
Vec4negate ()
 
Vec4reciprocate ()
 
Vec4 getNegation () const
 
Vec4 getReciprocal () const
 
Vec4map (std::function< float(float)> func)
 
Vec4 getMap (std::function< float(float)> func) const
 
Vec4operator+= (const Vec4 v)
 
Vec4operator-= (const Vec4 v)
 
Vec4operator*= (float s)
 
Vec4operator*= (const Vec4 v)
 
Vec4operator/= (float s)
 
Vec4operator/= (const Vec4 v)
 
const Vec4 operator+ (const Vec4 v) const
 
const Vec4 operator- (const Vec4 v) const
 
const Vec4 operator- () const
 
const Vec4 operator* (float s) const
 
const Vec4 operator* (const Vec4 v) const
 
const Vec4 operator/ (float s) const
 
const Vec4 operator/ (const Vec4 v) const
 
bool operator< (const Vec4 v) const
 
bool operator<= (const Vec4 v) const
 
bool operator> (const Vec4 v) const
 
bool operator>= (const Vec4 v) const
 
bool operator== (const Vec4 v) const
 
bool operator!= (const Vec4 v) const
 
bool under (const Vec4 v) const
 
bool over (const Vec4 v) const
 
bool equals (const Vec4 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
 
bool isHomogenous () const
 
float getAngle (const Vec4 other) const
 
float distance (const Vec4 v) const
 
float distanceSquared (const Vec4 v) const
 
float length () const
 
float lengthSquared () const
 
float dot (const Vec4 v) const
 
Vec4 cross (const Vec4 v)
 
Vec4normalize ()
 
Vec4 getNormalization () const
 
Vec4 getMidpoint (const Vec4 other) const
 
Vec4project (const Vec4 other)
 
Vec4 getProjection (const Vec4 other) const
 
Vec4homogenize ()
 
Vec4 getHomogenized ()
 
Vec4lerp (const Vec4 other, float alpha)
 
Vec4 getLerp (const Vec4 other, float alpha)
 
void smooth (const Vec4 target, float elapsed, float response)
 
std::string toString (bool verbose=false) const
 
 operator std::string () const
 
 operator Color4 () const
 
 Vec4 (Color4 color)
 
Vec4operator= (Color4 color)
 
 operator Color4f () const
 
 Vec4 (const Color4f color)
 
Vec4operator= (const Color4f color)
 
 operator Vec2 () const
 
 Vec4 (const Vec2 v)
 
 Vec4 (const Vec2 v, float z, float w)
 
Vec4operator= (const Vec2 size)
 
 operator Vec3 () const
 
 Vec4 (const Vec3 v)
 
 Vec4 (const Vec3 v, float w)
 
Vec4operator= (const Vec3 v)
 
Vec4set (const Vec3 v, float w)
 

Static Public Member Functions

static Vec4clamp (const Vec4 v, const Vec4 min, const Vec4 max, Vec4 *dst)
 
static float angle (const Vec4 v1, const Vec4 v2)
 
static Vec4add (const Vec4 v1, const Vec4 v2, Vec4 *dst)
 
static Vec4subtract (const Vec4 v1, const Vec4 v2, Vec4 *dst)
 
static Vec4scale (const Vec4 v, float s, Vec4 *dst)
 
static Vec4scale (const Vec4 v1, const Vec4 v2, Vec4 *dst)
 
static Vec4divide (const Vec4 v, float s, Vec4 *dst)
 
static Vec4divide (const Vec4 v1, const Vec4 v2, Vec4 *dst)
 
static Vec4reciprocate (const Vec4 v, Vec4 *dst)
 
static Vec4negate (const Vec4 v, Vec4 *dst)
 
static float dot (const Vec4 v1, const Vec4 v2)
 
static Vec4cross (const Vec4 v1, const Vec4 v2, Vec4 *dst)
 
static Vec4normalize (const Vec4 v, Vec4 *dst)
 
static Vec4homogenize (const Vec4 v, Vec4 *dst)
 
static Vec4midpoint (const Vec4 v1, const Vec4 v2, Vec4 *dst)
 
static Vec4project (const Vec4 v1, const Vec4 v2, Vec4 *dst)
 
static Vec4lerp (const Vec4 v1, const Vec4 v2, float alpha, Vec4 *dst)
 

Public Attributes

float x
 
float y
 
float z
 
float w
 

Static Public Attributes

static const Vec4 ZERO
 
static const Vec4 ONE
 
static const Vec4 UNIT_X
 
static const Vec4 UNIT_Y
 
static const Vec4 UNIT_Z
 
static const Vec4 UNIT_W
 
static const Vec4 HOMOG_ORIGIN
 
static const Vec4 HOMOG_X
 
static const Vec4 HOMOG_Y
 
static const Vec4 HOMOG_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

◆ Vec4() [1/10]

cugl::Vec4::Vec4 ( )
inline

Constructs a new vector initialized to all zeros.

◆ Vec4() [2/10]

cugl::Vec4::Vec4 ( float  x,
float  y,
float  z,
float  w 
)
inline

Constructs a new vector initialized to the specified values.

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

◆ Vec4() [3/10]

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

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

The elements of the arra are in the order x, y, z, and w.

Parameters
arrayAn array containing the elements of the vector.

◆ Vec4() [4/10]

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

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

Parameters
p1The first point.
p2The second point.

◆ Vec4() [5/10]

cugl::Vec4::Vec4 ( Color4  color)
explicit

Creates a vector from the given color.

The attributes are read in the order r,g,b,a. Values are all divided uniformly by 255.0.

Parameters
colorThe color to convert

◆ Vec4() [6/10]

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

Creates a vector from the given color.

The attributes are read in the order r,g,b,a.

Parameters
colorThe color to convert

◆ Vec4() [7/10]

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

Creates a homogenous vector from the given 2d one.

The z-value is set to 0. However, the w-value is set to 1, to support homogenous coordinates.

Parameters
vThe vector to convert

◆ Vec4() [8/10]

cugl::Vec4::Vec4 ( const Vec2  v,
float  z,
float  w 
)

Creates a 4d vector from the given 2d one

The z-coordinate and w-coordinate are set to given values.

Parameters
vThe vector to convert
zThe z-coordinate
wThe w-coordinate

◆ Vec4() [9/10]

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

Creates a homogenous vector from the given 3d one.

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

Parameters
vThe vector to convert

◆ Vec4() [10/10]

cugl::Vec4::Vec4 ( const Vec3  v,
float  w 
)

Creates a 4d vector from the given 3d one

The w-value is set to given value.

Parameters
vThe vector to convert
wThe w-coordinate

Member Function Documentation

◆ add() [1/3]

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

Adds the given vector to this one in place.

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

◆ add() [2/3]

static Vec4 * cugl::Vec4::add ( const Vec4  v1,
const Vec4  v2,
Vec4 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]

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

Adds the given values to this vector.

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

◆ angle()

static float cugl::Vec4::angle ( const Vec4  v1,
const Vec4  v2 
)
static

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

This computes the angle between the vectors in 4d space. It does not treat the vectors as homogenous coordinates. To get the angle between two homogenous vectors, cast them to Vec3 and use Vec3::angle.

The angle returned is unsigned, as there is no clear sense of direction. If either vector is zero, this method returns zero.

Parameters
v1The first vector.
v2The second vector.
Returns
The angle between the two vectors (in radians).

◆ clamp() [1/2]

Vec4 & cugl::Vec4::clamp ( const Vec4  min,
const Vec4  max 
)

Clamps this vector within the given range.

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

◆ clamp() [2/2]

static Vec4 * cugl::Vec4::clamp ( const Vec4  v,
const Vec4  min,
const Vec4  max,
Vec4 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]

Vec4 cugl::Vec4::cross ( const Vec4  v)
inline

Return the cross product of this vector and the specified vector.

This method assumes that this vector and v are homogenous vectors (w=1). It returns a projection vector (w=0).

Parameters
vThe vector to cross.
Returns
The cross product.

◆ cross() [2/2]

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

Returns the cross product between the specified vectors.

The vectors are treated as 3-dimensional vectors, with the w-attribute ignored.

Parameters
v1The first vector.
v2The second vector.
dstThe destination vector.
Returns
The cross product between the vectors.

◆ distance()

float cugl::Vec4::distance ( const Vec4  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::Vec4::distanceSquared ( const Vec4  v) const

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]

Vec4 & cugl::Vec4::divide ( const Vec4  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) Vec4 for chaining.

◆ divide() [2/5]

static Vec4 * cugl::Vec4::divide ( const Vec4  v,
float  s,
Vec4 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 Vec4 * cugl::Vec4::divide ( const Vec4  v1,
const Vec4  v2,
Vec4 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]

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

Divides this vector in place by the given factor.

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

◆ divide() [5/5]

Vec4 & cugl::Vec4::divide ( float  sx,
float  sy,
float  sz,
float  sw 
)

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
swThe scalar to divide the w-axis
Returns
A reference to this (modified) Vec4 for chaining.

◆ dot() [1/2]

float cugl::Vec4::dot ( const Vec4  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::Vec4::dot ( const Vec4  v1,
const Vec4  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::Vec4::equals ( const Vec4  v,
float  epsilon = CU_MATH_EPSILON 
) const

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::Vec4::getAngle ( const Vec4  other) const

Returns the angle between this vector and other.

The angle is measured starting at this one. If either vector is zero, the result is undefined.

Parameters
otherThe vector to sweep towards.
Returns
the angle between this vector and other.

◆ getClamp()

Vec4 cugl::Vec4::getClamp ( const Vec4  min,
const Vec4  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.

◆ getHomogenized()

Vec4 cugl::Vec4::getHomogenized ( )
inline

Returns a normalized homogenous copy of this vector.

If w is 0, the copy has a w value to 1. Otherwise, the copy has all of its attributes divided by w.

Note: this does not modify this vector.

Returns
a normalized homogenous copy of this vector.

◆ getLerp()

Vec4 cugl::Vec4::getLerp ( const Vec4  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
Returns
The linear interpolation of this vector with other.

◆ getMap()

Vec4 cugl::Vec4::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()

Vec4 cugl::Vec4::getMidpoint ( const Vec4  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()

Vec4 cugl::Vec4::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()

Vec4 cugl::Vec4::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()

Vec4 cugl::Vec4::getProjection ( const Vec4  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()

Vec4 cugl::Vec4::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.

◆ homogenize() [1/2]

Vec4 & cugl::Vec4::homogenize ( )
inline

Normalizes the homogenous representation of this vector.

If w is 0, it sets the value to 1. Otherwise, it divides all attributes by w.

Returns
This vector, after homgenization.

◆ homogenize() [2/2]

static Vec4 * cugl::Vec4::homogenize ( const Vec4  v,
Vec4 dst 
)
static

Homogenizes the specified vector and stores the result in dst.

If w is 0, it sets the value to 1. Otherwise, it divides all attributes by w.

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

◆ isHomogenous()

bool cugl::Vec4::isHomogenous ( ) const
inline

Returns true if this vector is in homogenous coordinates (w=1).

Returns
true if this vector is in homogenous coordinates (w=1).

◆ isInvertible()

bool cugl::Vec4::isInvertible ( ) const

Returns true if this vector contains no zeroes.

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

◆ isNearZero()

bool cugl::Vec4::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::Vec4::isOne ( ) const

Returns true if this vector contains all ones.

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

◆ isUnit()

bool cugl::Vec4::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::Vec4::isZero ( ) const

Returns true this vector contains all zeros.

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

◆ length()

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

Returns the length of this vector.

Returns
The length of the vector.

{

See also
lengthSquared}

◆ lengthSquared()

float cugl::Vec4::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]

Vec4 & cugl::Vec4::lerp ( const Vec4  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
Returns
This vector, after the interpolation.

◆ lerp() [2/2]

static Vec4 * cugl::Vec4::lerp ( const Vec4  v1,
const Vec4  v2,
float  alpha,
Vec4 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()

Vec4 & cugl::Vec4::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) Vec4 for chaining.

◆ midpoint()

static Vec4 * cugl::Vec4::midpoint ( const Vec4  v1,
const Vec4  v2,
Vec4 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]

Vec4 & cugl::Vec4::negate ( )
inline

Negates this vector in place.

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

◆ negate() [2/2]

static Vec4 * cugl::Vec4::negate ( const Vec4  v,
Vec4 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]

Vec4 & cugl::Vec4::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 Vec4 * cugl::Vec4::normalize ( const Vec4  v,
Vec4 dst 
)
static

Normalizes the specified 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 copies v into dst.

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

◆ operator Color4()

cugl::Vec4::operator Color4 ( ) const

Cast from Vec4 to a Color4.

◆ operator Color4f()

cugl::Vec4::operator Color4f ( ) const

Cast from Vec4 to a Color4f.

◆ operator std::string()

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

Cast from Vec4 to a string.

◆ operator Vec2()

cugl::Vec4::operator Vec2 ( ) const

Casts from a homogenous vector to Vec4.

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

◆ operator Vec3()

cugl::Vec4::operator Vec3 ( ) const

Casts from Vec4 to Vec3.

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

◆ operator!=()

bool cugl::Vec4::operator!= ( const Vec4  v) const

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 Vec4 cugl::Vec4::operator* ( const Vec4  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 Vec4 cugl::Vec4::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]

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

Scales this vector nonuniformly by the given vector.

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

◆ operator*=() [2/2]

Vec4 & cugl::Vec4::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) Vec4 for chaining.

◆ operator+()

const Vec4 cugl::Vec4::operator+ ( const Vec4  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+=()

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

Adds the given vector to this one in place.

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

◆ operator-() [1/2]

const Vec4 cugl::Vec4::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 Vec4 cugl::Vec4::operator- ( const Vec4  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-=()

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

Subtracts the given vector from this one in place.

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

◆ operator/() [1/2]

const Vec4 cugl::Vec4::operator/ ( const Vec4  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 Vec4 cugl::Vec4::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]

Vec4 & cugl::Vec4::operator/= ( const Vec4  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) Vec4 for chaining.

◆ operator/=() [2/2]

Vec4 & cugl::Vec4::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) Vec4 for chaining.

◆ operator<()

bool cugl::Vec4::operator< ( const Vec4  v) const

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::Vec4::operator<= ( const Vec4  v) const

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]

Vec4 & cugl::Vec4::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,a. Values are all divided uniformly by 255.0.

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

◆ operator=() [2/5]

Vec4 & cugl::Vec4::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,a.

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

◆ operator=() [3/5]

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

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

The elements of the array are in the order x, y, z, and w.

Parameters
arrayAn array containing the elements of the vector.
Returns
A reference to this (modified) Vec4 for chaining.

◆ operator=() [4/5]

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

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

The z-value is set to 0. However, the w-value is set to 1, to support homogenous coordinates.

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

◆ operator=() [5/5]

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

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

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

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

◆ operator==()

bool cugl::Vec4::operator== ( const Vec4  v) const

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::Vec4::operator> ( const Vec4  v) const

Determines 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::Vec4::operator>= ( const Vec4  v) const

Determines 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::Vec4::over ( const Vec4  v) const

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]

Vec4 & cugl::Vec4::project ( const Vec4  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 Vec4 * cugl::Vec4::project ( const Vec4  v1,
const Vec4  v2,
Vec4 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]

Vec4 & cugl::Vec4::reciprocate ( )

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 Vec4 * cugl::Vec4::reciprocate ( const Vec4  v,
Vec4 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]

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

Scales this vector nonuniformly by the given vector.

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

◆ scale() [2/5]

static Vec4 * cugl::Vec4::scale ( const Vec4  v,
float  s,
Vec4 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 Vec4 * cugl::Vec4::scale ( const Vec4  v1,
const Vec4  v2,
Vec4 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]

Vec4 & cugl::Vec4::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) Vec4 for chaining.

◆ scale() [5/5]

Vec4 & cugl::Vec4::scale ( float  sx,
float  sy,
float  sz,
float  sw 
)
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
swThe scalar to divide the w-axis
Returns
A reference to this (modified) Vec4 for chaining.

◆ set() [1/5]

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

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

The elements of the arra are in the order x, y, z, and w.

Parameters
arrayAn array containing the elements of the vector.
Returns
A reference to this (modified) Vec4 for chaining.

◆ set() [2/5]

Vec4 & cugl::Vec4::set ( const Vec3  v,
float  w 
)

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

The w-value is set to given value.

Parameters
vThe vector to convert
wThe w-coordinate
Returns
A reference to this (modified) Vec4 for chaining.

◆ set() [3/5]

Vec4 & cugl::Vec4::set ( const Vec4  p1,
const Vec4  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) Vec2 for chaining.

◆ set() [4/5]

Vec4 & cugl::Vec4::set ( const Vec4  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) Vec2 for chaining.

◆ set() [5/5]

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

Sets the elements of this vector to the specified values.

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

◆ setZero()

Vec4 & cugl::Vec4::setZero ( )
inline

Sets the elements of this vector to zero.

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

◆ smooth()

void cugl::Vec4::smooth ( const Vec4  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).

◆ subtract() [1/3]

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

Subtracts the given vector from this one in place.

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

◆ subtract() [2/3]

static Vec4 * cugl::Vec4::subtract ( const Vec4  v1,
const Vec4  v2,
Vec4 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]

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

Subtracts the given values from this vector.

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

◆ toString()

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

Returns a string representation of this vector for debugging 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 debugging purposes.

◆ under()

bool cugl::Vec4::under ( const Vec4  v) const

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

◆ HOMOG_ORIGIN

const Vec4 cugl::Vec4::HOMOG_ORIGIN
static

The homogenous origin Vec4(0,0,0,1)

◆ HOMOG_X

const Vec4 cugl::Vec4::HOMOG_X
static

The homogenous x-axis Vec4(1,0,0,1)

◆ HOMOG_Y

const Vec4 cugl::Vec4::HOMOG_Y
static

The homogenous y-axis Vec4(0,1,0,1)

◆ HOMOG_Z

const Vec4 cugl::Vec4::HOMOG_Z
static

The homogenous z-axis Vec4(0,0,1,1)

◆ ONE

const Vec4 cugl::Vec4::ONE
static

The ones vector Vec4(1,1,1,1)

◆ UNIT_W

const Vec4 cugl::Vec4::UNIT_W
static

The w-axis Vec4(0,0,0,1)

◆ UNIT_X

const Vec4 cugl::Vec4::UNIT_X
static

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

◆ UNIT_Y

const Vec4 cugl::Vec4::UNIT_Y
static

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

◆ UNIT_Z

const Vec4 cugl::Vec4::UNIT_Z
static

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

◆ w

float cugl::Vec4::w

The w-coordinate.

◆ x

float cugl::Vec4::x

The x-coordinate.

◆ y

float cugl::Vec4::y

The y-coordinate.

◆ z

float cugl::Vec4::z

The z-coordinate.

◆ ZERO

const Vec4 cugl::Vec4::ZERO
static

The zero vector Vec4(0,0,0,0)


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