Libprimis
Imprimis' 3D destroyable world engine
|
three dimensional Cartesian vector object More...
#include <geom.h>
Public Member Functions | |
vec (int a) | |
vec (float a) | |
vec (float a, float b, float c) | |
vec (int v[3]) | |
vec (const float *v) | |
vec (const vec2 &v, float z=0) | |
vec (const vec4< float > &v) | |
vec (const ivec &v) | |
vec (const svec &v) | |
vec (float yaw, float pitch) | |
vec & | set (int i, float f) |
float & | operator[] (int i) |
float | operator[] (int i) const |
bool | operator== (const vec &o) const |
bool | operator!= (const vec &o) const |
vec | operator+ (const vec &v2) |
vec | operator- (const vec &v2) |
vec | operator- () |
template<typename T > | |
vec | operator* (const T &n) |
vec | operator* (const vec &v2) |
template<typename T > | |
vec | operator/ (const T &n) |
vec | operator/ (const vec &v2) |
bool | iszero () const |
Returns whether this vec is exactly zero in all axes. | |
float | squaredlen () const |
Returns the square of this vec 's magnitude. | |
vec & | square () |
Sets this vec to its elementwise square. | |
vec & | neg2 () |
vec & | neg () |
vec & | abs () |
vec & | recip () |
float | magnitude2 () const |
float | magnitude () const |
vec & | normalize () |
vec & | safenormalize () |
bool | isnormalized () const |
vec & | mul (float f) |
vec & | mul2 (float f) |
vec & | div (float f) |
vec & | div2 (float f) |
vec & | add (float f) |
vec & | add2 (float f) |
vec & | addz (float f) |
vec & | sub (float f) |
vec & | sub2 (float f) |
vec & | subz (float f) |
vec & | min (float f) |
vec & | max (float f) |
vec & | clamp (float l, float h) |
vec & | mul (const vec &o) |
vec & | div (const vec &o) |
vec & | add (const vec &o) |
vec & | sub (const vec &o) |
vec & | min (const vec &o) |
vec & | max (const vec &o) |
float | dot2 (const vec2 &o) const |
float | dot2 (const vec &o) const |
float | dot (const vec &o) const |
float | squaredot (const vec &o) const |
float | absdot (const vec &o) const |
float | zdot (const vec &o) const |
float | squaredist (const vec &e) const |
float | dist (const vec &e) const |
float | dist (const vec &e, vec &t) const |
float | dist2 (const vec &o) const |
bool | reject (const vec &o, float r) const |
Checks whether the x,y dimensions are outside a distance from a vec. | |
template<class A , class B > | |
vec & | cross (const A &a, const B &b) |
vec & | cross (const vec &o, const vec &a, const vec &b) |
float | scalartriple (const vec &a, const vec &b) const |
scalar triple product A*(BxC) | |
float | zscalartriple (const vec &a, const vec &b) const |
z component only of scalar triple product (A*(BxC)) | |
vec & | reflectz (float rz) |
vec & | reflect (const vec &n) |
vec & | project (const vec &n) |
vec & | projectxydir (const vec &n) |
vec & | projectxy (const vec &n) |
vec & | projectxy (const vec &n, float threshold) |
vec & | lerp (const vec &b, float t) |
Linearly interpolates between another vec2 according to scale t. | |
vec & | lerp (const vec &a, const vec &b, float t) |
Linearly interpolates between two other vecs according to scale t. | |
vec & | avg (const vec &b) |
Sets this vec to the arithmetic mean of itself and another vec . | |
template<class B > | |
vec & | madd (const vec &a, const B &b) |
template<class B > | |
vec & | msub (const vec &a, const B &b) |
vec & | rescale (float k) |
vec & | rotate_around_z (float c, float s) |
vec & | rotate_around_x (float c, float s) |
vec & | rotate_around_y (float c, float s) |
vec & | rotate_around_z (float angle) |
vec & | rotate_around_x (float angle) |
vec & | rotate_around_y (float angle) |
vec & | rotate_around_z (const vec2 &sc) |
vec & | rotate_around_x (const vec2 &sc) |
vec & | rotate_around_y (const vec2 &sc) |
vec & | rotate (float c, float s, const vec &d) |
vec & | rotate (float angle, const vec &d) |
vec & | rotate (const vec2 &sc, const vec &d) |
void | orthogonal (const vec &d) |
void | orthonormalize (vec &s, vec &t) const |
template<class T > | |
bool | insidebb (const T &bbmin, const T &bbmax) const |
template<class T , class U > | |
bool | insidebb (const T &bbmin, const T &bbmax, U margin) const |
bool | insidebb (const ivec &o, int size) const |
Determines whether this vec is within the boundaries {o, o+size}. | |
bool | insidebb (const ivec &o, int size, int margin) const |
Determines whether this vec is within the boundaries {o-margin, o+size+margin}. | |
float | dist_to_bb (const ivec &min, const ivec &max) const |
float | project_bb (const ivec &min, const ivec &max) const |
Returns the dot product of this and min/max, depending on sign. | |
int | tohexcolor () const |
Static Public Member Functions | |
static vec | hexcolor (int color) |
Public Attributes | ||
union { | ||
struct { | ||
float x | ||
float y | ||
float z | ||
} | ||
struct { | ||
float r | ||
float g | ||
float b | ||
} | ||
float v [3] | ||
}; | ||
three dimensional Cartesian vector object
This object represents a three-dimensional positiom or vector in Cartesian space, represented by the axes x
,y
,z
(r
,g
,b
). Many operators and utility functions corresponding to operations on the 2D plane are defined.
The axis aliases r
g
b
are provided for manipulation as a color, in which case the values for each dimension should be no greater than 1.f
for easy conversion to bvec
byte representation.
This object finds uses in nearly every part of the engine, including world geometry, mapmodels, particles, projectiles, colors, etc.
Sets this vec
to the arithmetic mean of itself and another vec
.
Each axis has its arithmetic mean (average) set independently.
b | the other vec to average with |
bool vec::insidebb | ( | const ivec & | o, |
int | size ) const |
Determines whether this vec is within the boundaries {o, o+size}.
The conditions cannot be met if size
is negative (will always return false). If this
is on the boundary of the bounding box, returns true.
o | the position of the bounding box start |
size | the projection in +x,+y,+z for the bounding box to occupy |
this
is inside the bounding box this
is not inside it bool vec::insidebb | ( | const ivec & | o, |
int | size, | ||
int | margin ) const |
Determines whether this vec is within the boundaries {o-margin, o+size+margin}.
The conditions cannot be met if size
is negative (will always return false). If this
is on the boundary of the bounding box (including margin), returns true.
o | the position of the bounding box start |
size | the projection in +x,+y,+z for the bounding box to occupy |
margin | distance in every direction around bounding box |
this
is inside the bounding box this
is not inside it
|
inline |
Returns whether this vec
is exactly zero in all axes.
The values are compared to zero under the IEEE 754 equality condition, meaning that negative zero is treated as equal to positive zero.
Linearly interpolates between two other vecs according to scale t.
If 0 < t < 1 then the matrix will be t% of the way between this
and to
. Values outside 0..1 imply a linear extrapolation.
a | the first vec to interpolate from |
b | the other vec to interpolate between |
t | the interpolation factor |
Returns the dot product of this and min/max, depending on sign.
Returns the dot product between this
and an ivec generated from min
and max
. The generated vector to dot product is determined by this
's sign for each dimension; if the dimension is negative then max
is used, and if it is zero or positive then min
is used.
min | the ivec to use for positive/zero values |
max | the ivec to use for negative values |
this
and min
/max
|
inline |
Checks whether the x,y dimensions are outside a distance from a vec.
If this vector's x
or y
coordinates are within r
of the passed vec o
, the function returns false; otherwise return true. If the value is exactly r
away from the vec o
in either direction, the function returns false
o | the vec to check nearness |
r | the distance at which to check |
this
vec is close to o
this
vec is far away from o
|
inline |
Sets this vec
to its elementwise square.
Each axis is independently multiplied by itself and assigned to this
.
|
inline |
Returns the square of this vec
's magnitude.
This is equivalent to the dot product of this vec
with itself.
vec