Eidolon
Public Member Functions | Static Public Member Functions | Private Attributes | Friends | List of all members
vec3 Class Reference

The all-important 3-space vector type. Note the lack of virtual members implies no vtable pointer. More...

#include <RenderTypes.h>

Collaboration diagram for vec3:
Collaboration graph

Public Member Functions

 vec3 (real val=0)
 Construct a vector by setting all components to `val'. More...
 
 vec3 (real x, real y, real z=0)
 Construct a vector with the given components. More...
 
 vec3 (const vec3 &v)
 Copy constructor. More...
 
real x () const
 
real y () const
 
real z () const
 
real x (real v)
 
real y (real v)
 
real z (real v)
 
void setBuff (float *v) const
 
vec3 operator+ (const vec3 &v) const
 
vec3 operator- (const vec3 &v) const
 
vec3 operator* (const vec3 &v) const
 
vec3 operator/ (const vec3 &v) const
 
vec3 operator+ (real v) const
 
vec3 operator- (real v) const
 
vec3 operator* (real v) const
 
vec3 operator/ (real v) const
 
vec3 operator- () const
 
vec3 abs () const
 Return a vector with the absolute value of each component of `this'. More...
 
vec3 inv () const
 Return a vector with each component of `this' inverted or 0 if already 0. More...
 
vec3 sign () const
 Return a vector with each component of `this' replaced with 1 if positive otherwise -1. More...
 
vec3 cross (const vec3 &v) const
 Return the cross product of `this' and `v'. More...
 
real dot (const vec3 &v) const
 Return the dot product of `this' and `v'. More...
 
real len () const
 Return the length of `this'. More...
 
real lenSq () const
 Return the squared length of `this'; this is faster than len(). More...
 
vec3 norm () const
 Return the normalized version of `this', or a zero vector if `this' is zero-length. More...
 
real distTo (const vec3 &v) const
 Return the distance from `this' to `v'. More...
 
real distToSq (const vec3 &v) const
 Return the squared distance from `this' to `v'; this is faster than dist(). More...
 
vec3 clamp (const vec3 &v1, const vec3 &v2) const
 Return a vector whose components are clamped within the AABB defined by the given vectors. More...
 
void setMinVals (const vec3 &v)
 Set each component of `this' to minimum of its component and the equivalent in `v'. More...
 
void setMaxVals (const vec3 &v)
 Set each component of `this' to maximum of its component and the equivalent in `v'. More...
 
void normThis ()
 Normalizes `this', or do nothing if zero-length. More...
 
vec3 toPolar () const
 Returns an equivalent vector in polar coordinates, assuming `this' was in cartesian coordinates. More...
 
vec3 toCylindrical () const
 Returns an equivalent vector in cylindrical coordinates, assuming `this' was in cartesian coordinates. More...
 
vec3 fromPolar () const
 Returns an equivalent vector in cartesian coordinates, assuming `this' was in polar coordinates. More...
 
vec3 fromCylindrical () const
 Returns an equivalent vector in cartesian coordinates, assuming `this' was in cylindrical coordinates. More...
 
bool isZero () const
 Returns true if the length of the vector is within dEPSILON of 0. More...
 
bool inAABB (const vec3 &minv, const vec3 &maxv) const
 Returns true if the vector is within the axis-aligned bounding box defined by the given min and max corners with a 'dEPSILON' margin of error. More...
 
bool inOBB (const vec3 &center, const vec3 &hx, const vec3 &hy, const vec3 &hz) const
 Returns true if the vector is within the oriented bounding box defined by the given center position and half X/Y/Z dimension vectors. More...
 
bool inSphere (const vec3 &center, real radius) const
 Returns true if the vector's distance to `center' is less than or equal to `radius'+`dEPSILON'. More...
 
bool onPlane (const vec3 &planept, const vec3 &planenorm) const
 Returns true if the vector lies on the plane defined by the point `planept' and normal `planenorm'. More...
 
bool isInUnitCube (real margin=0.0) const
 Returns true if each component is on the interval [0,1]; this exact within a value of `margin' in the positive and negative directions. More...
 
bool isParallel (const vec3 &other) const
 Returns true if `other' is parallel with this vector, ie. they represent the same or opposite directions. More...
 
bool operator== (const vec3 &v) const
 Returns true if the components of `this' and `v' are within `dEPSILON' of one another. More...
 
bool operator!= (const vec3 &v) const
 Equals the inverse of ==. More...
 
bool operator< (const vec3 &v) const
 
bool operator> (const vec3 &v) const
 
int cmp (const vec3 &v) const
 
real angleTo (const vec3 &v) const
 Returns the angle between `this' and `v'. More...
 
vec3 planeNorm (const vec3 &v2, const vec3 &v3) const
 Returns the normal of a plane defined by `this', `v2', and `v3' winding clockwise. More...
 
vec3 planeNorm (const vec3 &v2, const vec3 &v3, const vec3 &farv) const
 Returns the normal of a plane defined by `this', `v2', and `v3' with `farv' defined as below the plane. More...
 
real planeDist (const vec3 &planept, const vec3 &planenorm) const
 Returns the distance from `this' to a plane defined by a point on the plane and the plane normal (positive if above plane, negative below) More...
 
vec3 planeProject (const vec3 &planept, const vec3 &planenorm) const
 Returns the projection of `this' on a plane defined by a point on the plane and the plane normal. More...
 
int planeOrder (const vec3 &planenorm, const vec3 &v1, const vec3 &v2) const
 Given a plane defined by this and `planenorm', returns the circular ordering of `v1' and `v2'. More...
 
real triArea (const vec3 &b, const vec3 &c) const
 Returns the area of a triangle defined by `this', `b', and `c'. More...
 
real lineDist (vec3 p1, vec3 p2) const
 Returns the cylindrical distance from `this' to the line segment `p1'->`p2', or -1 if p1==p2 or `this' isn't within a cylinder with p1->p2 as its centeline. More...
 
vec3 lerp (real val, const vec3 &v) const
 Linearly interpolate between `this' and `v'. More...
 
i32 hash () const
 

Static Public Member Functions

static int compX (const void *v1, const void *v2)
 
static int compY (const void *v1, const void *v2)
 
static int compZ (const void *v1, const void *v2)
 
static vec3 posInfinity ()
 
static vec3 negInfinity ()
 
static vec3 X ()
 Returns the X-axis unit vector. More...
 
static vec3 Y ()
 Returns the Y-axis unit vector. More...
 
static vec3 Z ()
 Returns the Z-axis unit vector. More...
 

Private Attributes

real _x
 
real _y
 
real _z
 

Friends

std::ostream & operator<< (std::ostream &out, const vec3 &v)
 

Detailed Description

The all-important 3-space vector type. Note the lack of virtual members implies no vtable pointer.

Constructor & Destructor Documentation

◆ vec3() [1/3]

vec3 ( real  val = 0)
inline

Construct a vector by setting all components to `val'.

◆ vec3() [2/3]

vec3 ( real  x,
real  y,
real  z = 0 
)
inline

Construct a vector with the given components.

◆ vec3() [3/3]

vec3 ( const vec3 v)
inline

Copy constructor.

Member Function Documentation

◆ abs()

vec3 abs ( ) const
inline

Return a vector with the absolute value of each component of `this'.

◆ angleTo()

real angleTo ( const vec3 v) const
inline

Returns the angle between `this' and `v'.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ clamp()

vec3 clamp ( const vec3 v1,
const vec3 v2 
) const
inline

Return a vector whose components are clamped within the AABB defined by the given vectors.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cmp()

int cmp ( const vec3 v) const
inline
Here is the call graph for this function:

◆ compX()

static int compX ( const void *  v1,
const void *  v2 
)
inlinestatic
Here is the caller graph for this function:

◆ compY()

static int compY ( const void *  v1,
const void *  v2 
)
inlinestatic

◆ compZ()

static int compZ ( const void *  v1,
const void *  v2 
)
inlinestatic

◆ cross()

vec3 cross ( const vec3 v) const
inline

Return the cross product of `this' and `v'.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ distTo()

real distTo ( const vec3 v) const
inline

Return the distance from `this' to `v'.

Here is the caller graph for this function:

◆ distToSq()

real distToSq ( const vec3 v) const
inline

Return the squared distance from `this' to `v'; this is faster than dist().

Here is the caller graph for this function:

◆ dot()

real dot ( const vec3 v) const
inline

Return the dot product of `this' and `v'.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fromCylindrical()

vec3 fromCylindrical ( ) const
inline

Returns an equivalent vector in cartesian coordinates, assuming `this' was in cylindrical coordinates.

◆ fromPolar()

vec3 fromPolar ( ) const
inline

Returns an equivalent vector in cartesian coordinates, assuming `this' was in polar coordinates.

◆ hash()

i32 hash ( ) const
inline

◆ inAABB()

bool inAABB ( const vec3 minv,
const vec3 maxv 
) const
inline

Returns true if the vector is within the axis-aligned bounding box defined by the given min and max corners with a 'dEPSILON' margin of error.

Here is the caller graph for this function:

◆ inOBB()

bool inOBB ( const vec3 center,
const vec3 hx,
const vec3 hy,
const vec3 hz 
) const
inline

Returns true if the vector is within the oriented bounding box defined by the given center position and half X/Y/Z dimension vectors.

Here is the call graph for this function:

◆ inSphere()

bool inSphere ( const vec3 center,
real  radius 
) const
inline

Returns true if the vector's distance to `center' is less than or equal to `radius'+`dEPSILON'.

◆ inv()

vec3 inv ( ) const
inline

Return a vector with each component of `this' inverted or 0 if already 0.

Here is the caller graph for this function:

◆ isInUnitCube()

bool isInUnitCube ( real  margin = 0.0) const
inline

Returns true if each component is on the interval [0,1]; this exact within a value of `margin' in the positive and negative directions.

Here is the caller graph for this function:

◆ isParallel()

bool isParallel ( const vec3 other) const
inline

Returns true if `other' is parallel with this vector, ie. they represent the same or opposite directions.

◆ isZero()

bool isZero ( ) const
inline

Returns true if the length of the vector is within dEPSILON of 0.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ len()

real len ( ) const
inline

Return the length of `this'.

Here is the caller graph for this function:

◆ lenSq()

real lenSq ( ) const
inline

Return the squared length of `this'; this is faster than len().

Here is the caller graph for this function:

◆ lerp()

vec3 lerp ( real  val,
const vec3 v 
) const
inline

Linearly interpolate between `this' and `v'.

Here is the call graph for this function:

◆ lineDist()

real lineDist ( vec3  p1,
vec3  p2 
) const
inline

Returns the cylindrical distance from `this' to the line segment `p1'->`p2', or -1 if p1==p2 or `this' isn't within a cylinder with p1->p2 as its centeline.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ negInfinity()

static vec3 negInfinity ( )
inlinestatic
Here is the caller graph for this function:

◆ norm()

vec3 norm ( ) const
inline

Return the normalized version of `this', or a zero vector if `this' is zero-length.

Here is the caller graph for this function:

◆ normThis()

void normThis ( )
inline

Normalizes `this', or do nothing if zero-length.

◆ onPlane()

bool onPlane ( const vec3 planept,
const vec3 planenorm 
) const
inline

Returns true if the vector lies on the plane defined by the point `planept' and normal `planenorm'.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator!=()

bool operator!= ( const vec3 v) const
inline

Equals the inverse of ==.

Here is the call graph for this function:

◆ operator*() [1/2]

vec3 operator* ( const vec3 v) const
inline
Here is the call graph for this function:

◆ operator*() [2/2]

vec3 operator* ( real  v) const
inline

◆ operator+() [1/2]

vec3 operator+ ( const vec3 v) const
inline
Here is the call graph for this function:

◆ operator+() [2/2]

vec3 operator+ ( real  v) const
inline

◆ operator-() [1/3]

vec3 operator- ( const vec3 v) const
inline
Here is the call graph for this function:

◆ operator-() [2/3]

vec3 operator- ( real  v) const
inline

◆ operator-() [3/3]

vec3 operator- ( ) const
inline

◆ operator/() [1/2]

vec3 operator/ ( const vec3 v) const
inline
Here is the call graph for this function:

◆ operator/() [2/2]

vec3 operator/ ( real  v) const
inline

◆ operator<()

bool operator< ( const vec3 v) const
inline
Here is the call graph for this function:

◆ operator==()

bool operator== ( const vec3 v) const
inline

Returns true if the components of `this' and `v' are within `dEPSILON' of one another.

Here is the call graph for this function:

◆ operator>()

bool operator> ( const vec3 v) const
inline
Here is the call graph for this function:

◆ planeDist()

real planeDist ( const vec3 planept,
const vec3 planenorm 
) const
inline

Returns the distance from `this' to a plane defined by a point on the plane and the plane normal (positive if above plane, negative below)

Here is the call graph for this function:
Here is the caller graph for this function:

◆ planeNorm() [1/2]

vec3 planeNorm ( const vec3 v2,
const vec3 v3 
) const
inline

Returns the normal of a plane defined by `this', `v2', and `v3' winding clockwise.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ planeNorm() [2/2]

vec3 planeNorm ( const vec3 v2,
const vec3 v3,
const vec3 farv 
) const
inline

Returns the normal of a plane defined by `this', `v2', and `v3' with `farv' defined as below the plane.

Here is the call graph for this function:

◆ planeOrder()

int planeOrder ( const vec3 planenorm,
const vec3 v1,
const vec3 v2 
) const
inline

Given a plane defined by this and `planenorm', returns the circular ordering of `v1' and `v2'.

Here is the caller graph for this function:

◆ planeProject()

vec3 planeProject ( const vec3 planept,
const vec3 planenorm 
) const
inline

Returns the projection of `this' on a plane defined by a point on the plane and the plane normal.

◆ posInfinity()

static vec3 posInfinity ( )
inlinestatic
Here is the caller graph for this function:

◆ setBuff()

void setBuff ( float *  v) const
inline
Here is the caller graph for this function:

◆ setMaxVals()

void setMaxVals ( const vec3 v)
inline

Set each component of `this' to maximum of its component and the equivalent in `v'.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setMinVals()

void setMinVals ( const vec3 v)
inline

Set each component of `this' to minimum of its component and the equivalent in `v'.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sign()

vec3 sign ( ) const
inline

Return a vector with each component of `this' replaced with 1 if positive otherwise -1.

◆ toCylindrical()

vec3 toCylindrical ( ) const
inline

Returns an equivalent vector in cylindrical coordinates, assuming `this' was in cartesian coordinates.

◆ toPolar()

vec3 toPolar ( ) const
inline

Returns an equivalent vector in polar coordinates, assuming `this' was in cartesian coordinates.

◆ triArea()

real triArea ( const vec3 b,
const vec3 c 
) const
inline

Returns the area of a triangle defined by `this', `b', and `c'.

Here is the call graph for this function:

◆ x() [1/2]

real x ( ) const
inline
Here is the caller graph for this function:

◆ x() [2/2]

real x ( real  v)
inline

◆ X()

static vec3 X ( )
inlinestatic

Returns the X-axis unit vector.

◆ y() [1/2]

real y ( ) const
inline
Here is the caller graph for this function:

◆ y() [2/2]

real y ( real  v)
inline

◆ Y()

static vec3 Y ( )
inlinestatic

Returns the Y-axis unit vector.

◆ z() [1/2]

real z ( ) const
inline
Here is the caller graph for this function:

◆ z() [2/2]

real z ( real  v)
inline

◆ Z()

static vec3 Z ( )
inlinestatic

Returns the Z-axis unit vector.

Friends And Related Function Documentation

◆ operator<<

std::ostream& operator<< ( std::ostream &  out,
const vec3 v 
)
friend

Member Data Documentation

◆ _x

real _x
private

◆ _y

real _y
private

◆ _z

real _z
private

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