Libprimis
Imprimis' 3D destroyable world engine
|
A four dimensional Cartesian-space vector template. More...
#include <geom.h>
Public Member Functions | |
vec4 () | |
vec4 (const vec &p, T w=0) | |
vec4 (const vec2 &p, T z=0, T w=0) | |
vec4 (T x, T y=0, T z=0, T w=0) | |
vec4 (bvec v, uchar c) | |
vec4 (bvec v) | |
vec4 (const T *v) | |
template<class U> | |
vec4 (const vec4< U > &p) | |
template<class U> | |
operator vec4< U > () | |
T & | operator[] (int i) |
Returns the i-th dimension of this vec4. | |
T | operator[] (int i) const |
Returns the i-th dimension of this vec4. | |
T & | r () |
References the x coordinate of this vec4. | |
T & | g () |
References the y coordinate of this vec4. | |
T & | b () |
References the z coordinate of this vec4. | |
T & | a () |
References the w coordinate of this vec4. | |
T | r () const |
Returns the x coordinate of this vec4. | |
T | g () const |
Returns the y coordinate of this vec4. | |
T | b () const |
Returns the z coordinate of this vec4. | |
T | a () const |
Returns the w coordinate of this vec4. | |
const T * | data () const |
Returns a raw pointer to the data of this vec4. | |
uint * | mask () |
Returns a raw unsigned int pointer to the data in this vec4. | |
bool | operator== (const vec4 &o) const |
Returns whether two vec objects exactly match. | |
bool | operator!= (const vec4 &o) const |
Returns whether two vec objects do not match. | |
T | dot3 (const vec4 &o) const |
Returns the 3 dimensional dot product between two 4-vecs. | |
T | dot3 (const vec &o) const |
Returns the 3 dimensional dot product between this and a 3D vec. | |
T | dot (const vec4 &o) const |
Returns the scalar product with another vec4. | |
T | dot (const vec &o) const |
Returns the dot product of this and a vec3, assuming o.w = 1. | |
T | squaredlen () const |
Returns the square of the magnitude of the vector. | |
T | magnitude () const |
Returns the magnitude of the vector. | |
T | magnitude3 () const |
Returns the magnitude of the vector, ignoring the w dimension. | |
vec4 & | normalize () |
Scales the vector to have a magnitude of 1. | |
vec4 & | safenormalize () |
Scales the vector to have a magnitude of 1. | |
void | lerp (const vec4< uchar > &a, const vec4< uchar > &b, float t) |
void | lerp (const vec4< uchar > &a, const vec4< uchar > &b, int ka, int kb, int d) |
void | lerp (const vec4< uchar > &a, const vec4< uchar > &b, const vec4< uchar > &c, float ta, float tb, float tc) |
void | flip () |
Flips a vec4<uchar> by using the mask type pun. | |
vec4 & | lerp (const vec4 &b, T t) |
vec4 & | lerp (const vec4 &a, const vec4 &b, T t) |
vec4 & | avg (const vec4 &b) |
Calculates the elementwise arithmetic mean. | |
template<class B> | |
vec4 & | madd (const vec4 &a, const B &b) |
Sets this vec4 to the result of the multiply add of this with a ,b | |
template<class B> | |
vec4 & | msub (const vec4 &a, const B &b) |
Sets this vec4 to the result of the multiply subtract of this with a ,b | |
vec4 & | mul3 (T f) |
Calculates the elementwise product. | |
vec4 & | mul (T f) |
Calculates the elementwise product. | |
vec4 & | mul (const vec4 &o) |
Calculates the elementwise product. | |
vec4 & | mul (const vec &o) |
Calculates the elementwise product. | |
vec4 & | square () |
Calculates the elementwise square. | |
vec4 & | div3 (T f) |
Calculates the elementwise quotient. | |
vec4 & | div (T f) |
Calculates the elementwise quotient. | |
vec4 & | div (const vec4 &o) |
Calculates the elementwise quotient. | |
vec4 & | div (const vec &o) |
Calculates the elementwise quotient. | |
vec4 & | recip () |
Calculates the elementwise reciprocal. | |
vec4 & | add (const vec4 &o) |
Calculates the elementwise sum. | |
vec4 & | add (const vec &o) |
Calculates the elementwise sum. | |
vec4 & | add3 (T f) |
Calculates the elementwise sum. | |
vec4 & | add (T f) |
Calculates the elementwise sum. | |
vec4 & | addw (T f) |
Adds to the fourth value of the vector (w/a). | |
vec4 & | sub (const vec4 &o) |
Subtracts from this the vec4 passed. | |
vec4 & | sub (const vec &o) |
Subtracts from this the vec passed. | |
vec4 & | sub3 (T f) |
Subtracts from the first three entries this the value passed. | |
vec4 & | sub (T f) |
Subtracts from the entries this the value passed. | |
vec4 & | subw (T f) |
Subtracts from the last element only. | |
vec4 & | neg3 () |
Negates the first three elements. | |
vec4 & | neg () |
Negates all of the elements. | |
vec4 & | clamp (T l, T h) |
Clamps the elements individualy to the specified bounds. | |
vec4 | operator+ (const vec4 &v2) const |
Returns a new vec4 object equal to the sum of the passed object and this | |
vec4 | operator- (const vec4 &v2) const |
Returns a new vec4 object equal to this minus the passed object. | |
vec4 | operator- () const |
Returns a new vec4 object equal to the arithmetic inverse of this | |
template<typename U> | |
vec4 | operator* (const U &n) const |
Returns a new vec4 object equal to the scalar multiplication by a value. | |
vec4 | operator* (const vec4 &v2) const |
Returns a new vec4 equal to the elementwise product of this and the passed vec4. | |
template<typename U> | |
vec4 | operator/ (const U &n) const |
Returns a new vec4 object equal to the scalar division by a value. | |
vec4 | operator/ (const vec4 &v2) const |
Returns a new vec4 equal to the elementwise division of this and the passed vec4. | |
template<class A, class B> | |
vec4 & | cross (const A &a, const B &b) |
Sets this vec to the cross product of two passed objects. | |
vec4 & | cross (const vec &o, const vec &a, const vec &b) |
Sets this vec4 to the cross product of a,b relative to an offset c. | |
void | setxyz (const vec &v) |
Replaces the first three values of this with the passed vec. | |
vec4 & | rotate_around_z (T c, T s) |
Rotates the given 3-vector around the z-axis. | |
vec4 & | rotate_around_x (T c, T s) |
Rotates the given 3-vector around the x-axis. | |
vec4 & | rotate_around_y (T c, T s) |
Rotates the given 3-vector around the y-axis. | |
vec4 & | rotate_around_z (T angle) |
Conducts a rotation around the z-axis. | |
vec4 & | rotate_around_x (T angle) |
Conducts a rotation around the x-axis. | |
vec4 & | rotate_around_y (T angle) |
Conducts a rotation around the y-axis. | |
vec4 & | rotate_around_z (const vec2 &sc) |
Conducts a rotation around the z-axis. | |
vec4 & | rotate_around_x (const vec2 &sc) |
Conducts a rotation around the x-axis. | |
vec4 & | rotate_around_y (const vec2 &sc) |
Conducts a rotation around the y-axis. | |
vec | tonormal () const |
Returns a new vec containing values normalized to 0...255 (e.g. colors). | |
Public Attributes | |
T | x |
T | y |
T | z |
T | w |
A four dimensional Cartesian-space vector template.
This object defines a location in four dimensional Cartesian space, in whatever arithmetic type it is specialized to be. All four values are of the type T specialized, and all operators (unless explicitly specified, require types trivially convertable to T (or preferably of type T).
|
inline |
References the w coordinate of this vec4.
|
inline |
Returns the w coordinate of this vec4.
Calculates the elementwise sum.
Calculates the sum of the first three elements in this
with the first three values in o
, element-by-element. This means that the original vector is not preserved.
o | the vector to add with |
this
object following the operation Calculates the elementwise sum.
Calculates the sum of the four elements in this
with the four values in o
, element-by-element. This means that the original vector is not preserved.
o | the vector to add with |
this
object following the operation Calculates the elementwise sum.
Calculates the sum of the four elements in this
with the four elements comprising f
. This means that the original vector is not preserved.
f | the value to add with |
this
object following the operation Calculates the elementwise sum.
Calculates the sum of the first three elements in this
with the value passed to f
. This means that the original vector is not preserved.
f | the value to add with |
this
object following the operation Adds to the fourth value of the vector (w/a).
Calculates the sum of the passed value and the fourth element of the vec4, modifying the original vector to equal this sum.
f | the value to add with |
this
object following the operation Calculates the elementwise arithmetic mean.
Sets this
to the elementwise arithmetic mean of this
object and the passed object. The original vector is not preserved, but the passed one is.
b | the vec4 to average with |
this
object following the operation
|
inline |
References the z coordinate of this vec4.
|
inline |
Returns the z coordinate of this vec4.
Clamps the elements individualy to the specified bounds.
Clamps each element such that none of them exceeds the bounds specified.
l | the low value to clamp to |
h | the high value to clamp to |
|
inline |
Sets this vec to the cross product of two passed objects.
The w
field is unmodified. Only valid for vec-type objects with x,y,z scalar members.
A | the type of the first cross product operand |
B | the type of the second cross product operand |
a | the first cross product operand |
b | the second cross product operand |
Sets this vec4 to the cross product of a,b relative to an offset c.
The w
field is unmodified.
o | the origin to calculate offsets from |
a | the first vec to use |
b | the second vec to use |
|
inline |
Returns a raw pointer to the data of this vec4.
Calculates the elementwise quotient.
Calculates the quotient of the three values in this
with the four values in o
, element-by-element. This means that the original vector is not preserved.
o | the vector to divide by |
this
object following the operation Calculates the elementwise quotient.
Calculates the quotient of the four values in this
with the four values in o
, element-by-element. This means that the original vector is not preserved.
o | the vector to divide by |
this
object following the operation Calculates the elementwise quotient.
Calculates the quotient of the four values in this
with the value passed to f
. This means that the original vector is not preserved.
f | the value to divide by |
this
object following the operation Calculates the elementwise quotient.
Calculates the quotient of the first three values in this
with the value passed to f
. This means that the original vector is not preserved.
f | the value to divide by |
this
object following the operation Returns the dot product of this
and a vec3, assuming o.w = 1.
Calculates the dot product with a vec3, with o.w
implied to equal 1.
o | the vec3 to multiply by |
Returns the 3 dimensional dot product between this
and a 3D vec.
Returns the scalar (dot) product of a 3D and 4D vec, this
and the passed 3D vec, by ignoring the fourth term in the 4D vec.
o | the vec3 to multiply by |
Returns the 3 dimensional dot product between two 4-vecs.
Returns the scalar (dot) product of two 4D vecs, this
and the passed one, as if they are 3D vecs, by ignoring the fourth term in each vector.
o | the vec4 to multiply by |
|
inline |
Flips a vec4<uchar> by using the mask type pun.
Not for use with non-char vec4<> objects.
|
inline |
References the y coordinate of this vec4.
|
inline |
Returns the y coordinate of this vec4.
|
inline |
Sets this vec4 to the result of the multiply add of this
with a
,b
Returns a
*b
(elementwise multiplication) added with this
(elementwise addition).
a | value to multiply |
b | value to multiply |
this
following the operation
|
inline |
Returns the magnitude of the vector.
Calculates the magnitude (length) of the vector, by taking the square root of the dot product of the vector with itself.
this
|
inline |
Returns the magnitude of the vector, ignoring the w dimension.
Calculates the D magnitude (length) of the vector, by taking the square root of the 3D dot product of the vector with itself.
this
|
inline |
Returns a raw unsigned int pointer to the data in this vec4.
|
inline |
Sets this vec4 to the result of the multiply subtract of this
with a
,b
Returns a
*b
(elementwise multiplication) subtracted from this
(elementwise subtraction).
a | value to multiply |
b | value to multiply |
this
following the operation Calculates the elementwise product.
Calculates the elementwise product of the first three parameters in this
with the three parameters in o
. This means that the original vector is not preserved.
o | the vec3 to multiply by |
this
object following the operation Calculates the elementwise product.
Calculates the elementwise product of the four parameters in this
with the four parameters in o
. This measn that the original vector is not preserved.
o | the vec4 to multiply by |
this
object following the operation Calculates the elementwise product.
Calculates the elementwise product of f
with all four entries in this
. This means that the original vector is not preserved.
f | the value to multiply by |
this
object following the operation Calculates the elementwise product.
Calculates the elementwise product of f
with the first three entries in this
. This means that the original vector is not preserved.
f | the value to multiply by |
this
object following the operation Negates all of the elements.
this
Negates the first three elements.
w
is left unchanged.
this
Scales the vector to have a magnitude of 1.
Will cause a divide-by-zero if the vector is (0,0,0,0).
this
vector Returns whether two vec objects do not match.
If any value compares not equal (by floating point math rules), then the vec4s are considered not equal
o | the value to compare |
Returns whether two vec objects exactly match.
The two values must be exactly equal (by floating point math rules), and no tolerance is provided.
o | the value to compare |
|
inline |
Returns the i-th dimension of this vec4.
0 = x 1 = y 2 = z 3 = w
All values other than these will return a reference to x.
i | the index to access |
|
inline |
Returns the i-th dimension of this vec4.
0 = x 1 = y 2 = z 3 = w
All values other than these will return the value of x.
i | the index to access |
|
inline |
References the x coordinate of this vec4.
|
inline |
Returns the x coordinate of this vec4.
Calculates the elementwise reciprocal.
Calculates the value 1/x for each of the four values in the vector, and assigns them to this
. This means that the original vector is not preserved
this
object following the operation Conducts a rotation around the x-axis.
The w
parameter is ignored. The positive direction of rotation is counterclockwise.
sc | a vec2 containing the {cosine, sine} values to rotate with |
this
following the operation Conducts a rotation around the x-axis.
The w
parameter is ignored. The positive direction of rotation is counterclockwise.
angle | the angle (in radians) to rotate by |
this
following the operation Rotates the given 3-vector around the x-axis.
The w parameter is ignored. The positive direction of rotation is counterclockwise.
c | the raw cosine value to rotate by |
s | the raw sine value to rotate by |
Conducts a rotation around the y-axis.
The w
parameter is ignored. The positive direction of rotation is counterclockwise.
sc | a vec2 containing the {cosine, sine} values to rotate with |
this
following the operation Conducts a rotation around the y-axis.
The w
parameter is ignored. The positive direction of rotation is counterclockwise.
angle | the angle (in radians) to rotate by |
this
following the operation Rotates the given 3-vector around the y-axis.
The w parameter is ignored. The positive direction of rotation is counterclockwise.
c | the raw cosine value to rotate by |
s | the raw sine value to rotate by |
Conducts a rotation around the z-axis.
The w
parameter is ignored. The positive direction of rotation is counterclockwise.
sc | a vec2 containing the {cosine, sine} values to rotate with |
this
following the operation Conducts a rotation around the z-axis.
The w
parameter is ignored. The positive direction of rotation is counterclockwise.
angle | the angle (in radians) to rotate by |
this
following the operation Rotates the given 3-vector around the z-axis.
The w parameter is ignored. The positive direction of rotation is counterclockwise.
c | the raw cosine value to rotate by |
s | the raw sine value to rotate by |
Scales the vector to have a magnitude of 1.
Will return (0,0,0,0) if the vector passed (0,0,0,0).
this
vector Replaces the first three values of this
with the passed vec.
v | the vec to replace x,y,z of this with |
Calculates the elementwise square.
Calculates the elementwise product of this
with itself. This means that the original vector is not preserved.
this
object following the operation
|
inline |
Returns the square of the magnitude of the vector.
Calculates the dot product of the vector with itself, yielding the square of the magnitude of the vec4.
this
squared Subtracts from this
the vec passed.
Calculates the difference between the four elements in this
and the three elements of o
, modifying the original vector to equal this difference.
o | the vec to subtract |
this
object following the operation Subtracts from the entries this
the value passed.
Calculates the difference between the elements in this
and the value passed, modifying the original vector to equal this difference.
f | the value to subtract |
this
object following the operation Subtracts from the first three entries this
the value passed.
Calculates the difference between the first three elements in this
and the value passed, modifying the original vector to equal this difference.
f | the value to subtract |
this
object following the operation Subtracts from the last element only.
Calculates the difference between the last 'w' element in this
and the value passed, modifying the original vector to equal this difference.
f | the value to subtract |
this
object following the operation Returns a new vec containing values normalized to 0...255 (e.g. colors).
w
is not used in this calculation.