CUGL 2.5
Cornell University Game Library
|
#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) | |
Vec3 & | operator= (const float *array) |
Vec3 & | set (float x, float y, float z) |
Vec3 & | set (const float *array) |
Vec3 & | set (const Vec3 v) |
Vec3 & | set (const Vec3 p1, const Vec3 p2) |
Vec3 & | setZero () |
Vec3 & | clamp (const Vec3 min, const Vec3 max) |
Vec3 | getClamp (const Vec3 min, const Vec3 max) const |
Vec3 & | add (const Vec3 v) |
Vec3 & | add (float x, float y, float z) |
Vec3 & | subtract (const Vec3 v) |
Vec3 & | subtract (float x, float y, float z) |
Vec3 & | scale (float s) |
Vec3 & | scale (float sx, float sy, float sz) |
Vec3 & | scale (const Vec3 v) |
Vec3 & | divide (float s) |
Vec3 & | divide (float sx, float sy, float sz) |
Vec3 & | divide (const Vec3 v) |
Vec3 & | negate () |
Vec3 & | reciprocate () |
Vec3 | getNegation () const |
Vec3 | getReciprocal () const |
Vec3 & | map (std::function< float(float)> func) |
Vec3 | getMap (std::function< float(float)> func) const |
Vec3 & | operator+= (const Vec3 v) |
Vec3 & | operator-= (const Vec3 v) |
Vec3 & | operator*= (float s) |
Vec3 & | operator*= (const Vec3 v) |
Vec3 & | operator/= (float s) |
Vec3 & | operator/= (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 |
Vec3 & | cross (const Vec3 v) |
Vec3 | getCross (const Vec3 other) const |
Vec3 & | normalize () |
Vec3 | getNormalization () const |
Vec3 | getMidpoint (const Vec3 other) const |
Vec3 & | project (const Vec3 other) |
Vec3 | getProjection (const Vec3 other) const |
Vec3 & | lerp (const Vec3 other, float alpha) |
Vec3 | getLerp (const Vec3 other, float alpha) |
Vec3 & | smooth (const Vec3 target, float elapsed, float response) |
std::string | toString (bool verbose=false) const |
operator std::string () const | |
operator Color4 () const | |
Vec3 (Color4 color) | |
Vec3 & | operator= (Color4 color) |
operator Color4f () const | |
Vec3 (const Color4f color) | |
Vec3 & | operator= (const Color4f color) |
operator Vec2 () const | |
Vec3 (const Vec2 v) | |
Vec3 (const Vec2 v, float z) | |
Vec3 & | operator= (const Vec2 v) |
operator Vec4 () const | |
Vec3 (const Vec4 v) | |
Vec3 & | operator= (const Vec4 size) |
Static Public Member Functions | |
static Vec3 * | clamp (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 Vec3 * | add (const Vec3 v1, const Vec3 v2, Vec3 *dst) |
static Vec3 * | subtract (const Vec3 v1, const Vec3 v2, Vec3 *dst) |
static Vec3 * | scale (const Vec3 v, float s, Vec3 *dst) |
static Vec3 * | scale (const Vec3 v1, const Vec3 v2, Vec3 *dst) |
static Vec3 * | divide (const Vec3 v, float s, Vec3 *dst) |
static Vec3 * | divide (const Vec3 v1, const Vec3 v2, Vec3 *dst) |
static Vec3 * | reciprocate (const Vec3 v, Vec3 *dst) |
static Vec3 * | negate (const Vec3 v, Vec3 *dst) |
static float | dot (const Vec3 v1, const Vec3 v2) |
static Vec3 * | cross (const Vec3 v1, const Vec3 v2, Vec3 *dst) |
static Vec3 * | normalize (const Vec3 v, Vec3 *dst) |
static Vec3 * | midpoint (const Vec3 v1, const Vec3 v2, Vec3 *dst) |
static Vec3 * | project (const Vec3 v1, const Vec3 v2, Vec3 *dst) |
static Vec3 * | lerp (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 |
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.
|
inline |
Constructs a new vector initialized to all zeros.
|
inline |
Constructs a new vector initialized to the specified values.
x | The x coordinate. |
y | The y coordinate. |
z | The z coordinate. |
|
inline |
Constructs a new vector from the values in the specified array.
array | An array containing the elements of the vector in the order x, y, z. |
Constructs a vector that describes the direction between the specified points.
p1 | The first point. |
p2 | The second point. |
|
explicit |
Creates a vector from the given color.
The attributes are read in the order r,g,b. The alpha value is dropped.
color | The color to convert |
|
explicit |
Creates a vector from the given color.
The attributes are read in the order r,g,b. The alpha value is dropped.
color | The color to convert |
|
explicit |
Creates a 3d vector from the given 2d one.
The z-value is set to 0.
v | The vector to convert |
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
v | The vector to convert |
z | The z-coordinate |
|
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.
v | The vector to convert |
Adds the given vector to this one in place.
v | The vector to add |
Adds the specified vectors and stores the result in dst.
v1 | The first vector. |
v2 | The second vector. |
dst | A vector to store the result in |
|
inline |
Adds the given values to this vector.
x | The x coordinate to add. |
y | The y coordinate to add. |
z | The z coordinate to add. |
|
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.
v1 | The first vector. |
v2 | The second vector. |
up | The up direction (defaults to Vec3::UNIT_Z) |
Clamps this vector within the given range.
min | The minimum value. |
max | The maximum value. |
Clamps the specified vector within the given range and returns it in dst.
v | The vector to clamp. |
min | The minimum value. |
max | The maximum value. |
dst | A vector to store the result in. |
Sets this vector to the cross product between itself and the specified one.
v | The vector to cross with |
Computes the cross product of the vectors and stores the result in dst.
v1 | The first vector. |
v2 | The second vector. |
dst | The destination vector. |
|
inline |
Returns the distance between this vector and v.
v | The other vector. |
{
|
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).
v | The other vector. |
{
Divides this vector in place by the given vector.
This method is provided to support non-uniform scaling.
v | The vector to divide by |
Divides the specified vector and stores the result in dst.
The division is uniform by the constant s.
v | The vector to divide. |
s | The uniform division factor. |
dst | The destination vector. |
Divides the specified vector and stores the result in dst.
The division is nonuniform by the attributes in v2.
v1 | The vector to divide. |
v2 | The nonuniform division factor. |
dst | The destination vector. |
Vec3 & cugl::Vec3::divide | ( | float | s | ) |
Divides this vector in place by the given factor.
s | The scalar to divide by |
Vec3 & cugl::Vec3::divide | ( | float | sx, |
float | sy, | ||
float | sz | ||
) |
Divides this vector nonuniformly by the given factors.
sx | The scalar to divide the x-axis |
sy | The scalar to divide the y-axis |
sz | The scalar to divide the z-axis |
|
inline |
Returns the dot product of this vector and the specified vector.
v | The vector to compute the dot product with. |
Returns the dot product between the specified vectors.
v1 | The first vector. |
v2 | The second vector. |
|
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)
v | The vector to compare against. |
epsilon | The comparison tolerance. |
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.
other | The vector to sweep towards. |
up | The up direction (defaults to Vec3::UNIT_Z) |
Returns a copy of this vector clamped within the given range.
Note: this does not modify this vector.
min | The minimum value. |
max | The maximum value. |
Returns the cross product of this vector with another
Note: this does not modify this vector.
other | The vector to cross with |
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.
other | The other end of the line segment. |
alpha | The interpolation value in 0..1 |
|
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.
func | The function to map on the coordinates. |
Returns the midpoint between this point and another.
Note: this does not modify this vector.
other | The other end of the line segment. |
|
inline |
Returns a negated copy of this vector.
Note: This method does not modify the vector
|
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 the projection of this vector on to the other one.
Note: this does not modify this vector.
other | The vector to project on. |
|
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
|
inline |
Returns true if this vector contains no zeroes.
|
inline |
Returns true if this vector is with tolerance of the origin.
epsilon | The comparison tolerance |
|
inline |
Returns true if this vector contains all ones.
|
inline |
Returns true if this vector is a unit vector.
epsilon | The comparison tolerance |
|
inline |
Returns true this vector contains all zeros.
|
inline |
|
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).
{
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.
other | The other end of the line segment. |
alpha | The interpolation value in 0..1 |
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.
v1 | The first point. |
v2 | The second point. |
alpha | The interpolation value. |
dst | The destination vector. |
|
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.
func | The function to map on the coordinates. |
Computes the midpoint between two points and stores it in dst.
v1 | The first point. |
v2 | The second point. |
dst | The destination vector. |
|
inline |
Negates this vector.
Negates the specified vector and stores the result in dst.
v | The vector to negate. |
dst | The destination vector. |
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.
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.
v | The vector to normalize. |
dst | The destination vector. |
|
inline |
Cast from Vec3 to a string.
cugl::Vec3::operator Vec4 | ( | ) | 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.
v | The vector to compare against. |
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.
v | The vector to scale by. |
|
inline |
Returns the scalar product of this vector with the given value.
Note: this does not modify this vector.
s | The value to scale by. |
Scales this vector nonuniformly by the given vector.
v | The vector to scale by |
|
inline |
Scales this vector in place by the given factor.
s | The value to scale by |
Returns the sum of this vector with the given vector.
Note: this does not modify this vector.
v | The vector to add. |
Adds the given vector to this one in place.
v | The vector to add |
|
inline |
Returns the negation of this vector.
Note: this does not modify this vector.
Returns the difference of this vector with the given vector.
Note: this does not modify this vector.
v | The vector to subtract. |
Subtracts the given vector from this one in place.
v | The vector to subtract |
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.
v | the vector to divide this vector with |
|
inline |
Returns a copy of this vector divided by the given constant
Note: this does not modify this vector.
s | the constant to divide this vector with |
Divides this vector in place by the given vector.
This method is provided to support non-uniform scaling.
v | The vector to divide by |
|
inline |
Divides this vector in place by the given factor.
s | The scalar to divide by |
|
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().
v | The vector to compare against. |
|
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().
v | The vector to compare against. |
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.
color | The color to convert. |
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.
color | The color to convert. |
|
inline |
Sets the elements of this vector from the values in the specified array.
array | An array containing the elements of the vector in the order x, y, z. |
Sets the coordinates of this vector to those of the given 2d vector.
The z-value is set to 0.
v | The vector to convert |
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.
size | The vector to convert |
|
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.
v | The vector to compare against. |
|
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().
v | The vector to compare against. |
|
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().
v | The vector to compare against. |
|
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.
v | The vector to compare against. |
Modifies this vector to be its projection on to the other one.
other | The vector to project on. |
Computes the projection of one vector on to another and stores it in dst.
v1 | The original vector. |
v2 | The vector to project on. |
dst | The destination vector. |
|
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.
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.
v | The vector to reciprocate. |
dst | The destination vector. |
Scales this vector nonuniformly by the given vector.
v | The vector to scale by |
Scales the specified vector and stores the result in dst.
The scale is uniform by the constant s.
v | The vector to scale. |
s | The uniform scaling factor. |
dst | The destination vector. |
Scales the specified vector and stores the result in dst.
The scale is nonuniform by the attributes in v2.
v1 | The vector to scale. |
v2 | The nonuniform scaling factor. |
dst | The destination vector. |
|
inline |
Scales this vector in place by the given factor.
s | The scalar to multiply by |
|
inline |
Scales this vector nonuniformly by the given factors.
sx | The scalar to multiply the x-axis |
sy | The scalar to multiply the y-axis |
sz | The scalar to multiply the z-axis |
|
inline |
Sets the elements of this vector from the values in the specified array.
array | An array containing the elements of the vector in the order x, y, z. |
Sets this vector to the directional vector between the specified points.
p1 | The initial point of the vector. |
p2 | The terminal point of the vector. |
Sets the elements of this vector to those in the specified vector.
v | The vector to copy. |
|
inline |
Sets the elements of this vector to the specified values.
x | The new x coordinate. |
y | The new y coordinate. |
z | The new z coordinate. |
|
inline |
Sets the elements of this vector to zero.
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.
target | The target value. |
elapsed | The elapsed time between calls. |
response | The response time (in the same units as elapsed). |
Subtracts the given vector from this one in place.
v | The vector to subtract |
Subtracts the specified vectors and stores the result in dst. The resulting vector is computed as (v1 - v2).
v1 | The first vector. |
v2 | The second vector. |
dst | The destination vector. |
|
inline |
Subtracts the given values from this vector.
x | The x coordinate to subtract. |
y | The y coordinate to subtract. |
z | The z coordinate to subtract. |
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.
verbose | Whether to include class information |
|
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.
v | The vector to compare against. |
|
static |
The ones vector Vec3(1,1,1)
|
static |
The x-axis Vec3(1,0,0)
|
static |
The y-axis Vec3(0,1,0)
|
static |
The z-axis Vec3(0,0,1)
float cugl::Vec3::x |
The x-coordinate.
float cugl::Vec3::y |
The y-coordinate.
float cugl::Vec3::z |
The z-coordinate.
|
static |
The zero vector Vec3(0,0,0)