Libprimis
Imprimis' 3D destroyable world engine
Loading...
Searching...
No Matches
vec Struct Reference

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)
 
vecset (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.
 
vecsquare ()
 Sets this vec to its elementwise square.
 
vecneg2 ()
 
vecneg ()
 
vecabs ()
 
vecrecip ()
 
float magnitude2 () const
 
float magnitude () const
 
vecnormalize ()
 
vecsafenormalize ()
 
bool isnormalized () const
 
vecmul (float f)
 
vecmul2 (float f)
 
vecdiv (float f)
 
vecdiv2 (float f)
 
vecadd (float f)
 
vecadd2 (float f)
 
vecaddz (float f)
 
vecsub (float f)
 
vecsub2 (float f)
 
vecsubz (float f)
 
vecmin (float f)
 
vecmax (float f)
 
vecclamp (float l, float h)
 
vecmul (const vec &o)
 
vecdiv (const vec &o)
 
vecadd (const vec &o)
 
vecsub (const vec &o)
 
vecmin (const vec &o)
 
vecmax (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 >
veccross (const A &a, const B &b)
 
veccross (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))
 
vecreflectz (float rz)
 
vecreflect (const vec &n)
 
vecproject (const vec &n)
 
vecprojectxydir (const vec &n)
 
vecprojectxy (const vec &n)
 
vecprojectxy (const vec &n, float threshold)
 
veclerp (const vec &b, float t)
 Linearly interpolates between another vec2 according to scale t.
 
veclerp (const vec &a, const vec &b, float t)
 Linearly interpolates between two other vecs according to scale t.
 
vecavg (const vec &b)
 Sets this vec to the arithmetic mean of itself and another vec.
 
template<class B >
vecmadd (const vec &a, const B &b)
 
template<class B >
vecmsub (const vec &a, const B &b)
 
vecrescale (float k)
 
vecrotate_around_z (float c, float s)
 
vecrotate_around_x (float c, float s)
 
vecrotate_around_y (float c, float s)
 
vecrotate_around_z (float angle)
 
vecrotate_around_x (float angle)
 
vecrotate_around_y (float angle)
 
vecrotate_around_z (const vec2 &sc)
 
vecrotate_around_x (const vec2 &sc)
 
vecrotate_around_y (const vec2 &sc)
 
vecrotate (float c, float s, const vec &d)
 
vecrotate (float angle, const vec &d)
 
vecrotate (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] 
 
};  
 

Detailed Description

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 rgb 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.

Member Function Documentation

◆ avg()

vec & vec::avg ( const vec & b)
inline

Sets this vec to the arithmetic mean of itself and another vec.

Each axis has its arithmetic mean (average) set independently.

Parameters
bthe other vec to average with

◆ insidebb() [1/2]

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.

Parameters
othe position of the bounding box start
sizethe projection in +x,+y,+z for the bounding box to occupy
Returns
true if this is inside the bounding box
false if size is negative, or this is not inside it

◆ insidebb() [2/2]

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.

Parameters
othe position of the bounding box start
sizethe projection in +x,+y,+z for the bounding box to occupy
margindistance in every direction around bounding box
Returns
true if this is inside the bounding box
false if size is negative, or this is not inside it

◆ iszero()

bool vec::iszero ( ) const
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.

Returns
true if the vec is equal to (0,0,0)
false if the vec has any axis value that is not +/-0

◆ lerp() [1/2]

vec & vec::lerp ( const vec & a,
const vec & b,
float t )
inline

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.

Parameters
athe first vec to interpolate from
bthe other vec to interpolate between
tthe interpolation factor

◆ lerp() [2/2]

vec & vec::lerp ( const vec & b,
float t )
inline

Linearly interpolates between another vec2 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.

Parameters
bthe other vec2 to interpolate between
tthe interpolation factor

◆ project_bb()

float vec::project_bb ( const ivec & min,
const ivec & max ) const

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.

Parameters
minthe ivec to use for positive/zero values
maxthe ivec to use for negative values
Returns
the dot product between this and min/max

◆ reject()

bool vec::reject ( const vec & o,
float r ) const
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

Parameters
othe vec to check nearness
rthe distance at which to check
Returns
true if this vec is close to o
false if this vec is far away from o

◆ square()

vec & vec::square ( )
inline

Sets this vec to its elementwise square.

Each axis is independently multiplied by itself and assigned to this.

Returns
a reference to this vec

◆ squaredlen()

float vec::squaredlen ( ) const
inline

Returns the square of this vec's magnitude.

This is equivalent to the dot product of this vec with itself.

Returns
the square of the magnitude of the vec

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