Libprimis
Imprimis' 3D destroyable world engine
|
A four dimensional Cartesian-space vector template. More...
#include <geom.h>
Public Member Functions | |
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) |
T | operator[] (int i) const |
bool | operator== (const vec4 &o) const |
bool | operator!= (const vec4 &o) const |
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) |
template<class B > | |
vec4 & | msub (const vec4 &a, const B &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 svalue passed. | |
vec4 & | sub (T f) |
vec4 & | subw (T f) |
vec4 & | neg3 () |
vec4 & | neg () |
vec4 & | clamp (T l, T h) |
vec4 | operator+ (const vec4 &v2) const |
vec4 | operator- (const vec4 &v2) const |
vec4 | operator- () const |
template<typename U > | |
vec4 | operator* (const U &n) const |
vec4 | operator* (const vec4 &v2) const |
template<typename U > | |
vec4 | operator/ (const U &n) const |
vec4 | operator/ (const vec4 &v2) const |
template<class A , class B > | |
vec4 & | cross (const A &a, const B &b) |
vec4 & | cross (const vec &o, const vec &a, const vec &b) |
void | setxyz (const vec &v) |
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) |
vec4 & | rotate_around_x (T angle) |
vec4 & | rotate_around_y (T angle) |
vec4 & | rotate_around_z (const vec2 &sc) |
vec4 & | rotate_around_x (const vec2 &sc) |
vec4 & | rotate_around_y (const vec2 &sc) |
vec | tonormal () const |
Public Attributes | ||
union { | ||
struct { | ||
T x | ||
T y | ||
T z | ||
T w | ||
} | ||
struct { | ||
T r | ||
T g | ||
T b | ||
T a | ||
} | ||
T v [4] | ||
uint mask | ||
}; | ||
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).
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 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 |
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
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 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 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 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 |
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 |
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 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 first three entries this
the svalue 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 uint vec4< T >::mask |
four-entry array representation
T vec4< T >::v[4] |
color space representation (red, green, blue, alpha)