NGL  6.5
The NCCA Graphics Library
ngl::Vec3 Class Reference

simple Vec3 encapsulates a 3 float object like glsl vec3 but not maths use the Vec3 class for maths and the asVec3 to return a vec3 More...

#include <Vec3.h>

+ Collaboration diagram for ngl::Vec3:

Public Member Functions

 Vec3 ()
 default ctor use default and set to (0.0f,0.0f,0.0f) as attributes are initialised More...
 
 Vec3 (const Vec3 &_v)=default
 copy ctor we have POD data so let the compiler do the work! More...
 
 Vec3 (Real _x, Real _y, Real _z) noexcept
 initialise the constructor from 3 floats More...
 
void set (Real _x, Real _y, Real _z) noexcept
 sets the Vec3 component from 3 values More...
 
void set (const Vec3 &_v) noexcept
 set from another Vec3 More...
 
void set (const Vec4 &_v) noexcept
 set from another Vec4 ( you may need to convert somtimes) More...
 
Real dot (const Vec3 &_b) const noexcept
 return this dotted with _b More...
 
void null () noexcept
 clears the Vec3 to 0,0,0 More...
 
Realoperator[] (size_t &_i) noexcept
 [] index operator to access the index component of the Vec3 More...
 
const Realoperator[] (size_t &_i) const noexcept
 [] index operator to access the index component of the Vec3 More...
 
void normalize () noexcept
 Normalize the vector using
$x=x/\sqrt{x^2+y^2+z^2} $
$y=y/\sqrt{x^2+y^2+z^2} $
$z=z/\sqrt{x^2+y^2+z^2} $. More...
 
Real inner (const Vec3 &_v) const noexcept
 calculate the inner product of this vector and vector passed in More...
 
Mat3 outer (const Vec3 &_v) const noexcept
 compute the outer product of this vector and vector (requested by PJ) More...
 
Real length () const noexcept
 returns the length of the vector More...
 
Real lengthSquared () const noexcept
 returns the length squared of the vector (no sqrt so quicker) More...
 
void operator+= (const Vec3 &_v) noexcept
 += operator add Vec3 v to current Vec3 More...
 
void operator-= (const Vec3 &_v) noexcept
 -= operator this-=v More...
 
Vec3 operator* (Real _i) const noexcept
 this * i for each element More...
 
Vec3 operator+ (const Vec3 &_v) const noexcept
 
  • operator add Vec3+Vec3
More...
 
Vec3 operator/ (Real _v) const noexcept
 divide Vec3 components by a scalar More...
 
void operator/= (Real _v) noexcept
 divide this Vec3 components by a scalar More...
 
void operator*= (Real _v) noexcept
 multiply this Vec3 components by a scalar More...
 
Vec3 operator- (const Vec3 &_v) const noexcept
 subtraction operator subtract vevtor-Vec3 More...
 
Vec3 operator* (const Vec3 &_v) const noexcept
 
  • operator mult vevtor*Vec3
More...
 
Vec3operator= (const Vec3 &_v)=default
 assignment operator set the current Vec3 to rhs More...
 
Vec3operator= (const Vec4 &_v) noexcept
 assignment operator set the current Vec4 to rhs More...
 
Vec3operator= (Real _v) noexcept
 assignment operator set the current Vec3 to rhs More...
 
Vec3 operator* (const Mat3 &_m) const noexcept
 operator to multiply a vector by a matrix More...
 
Vec3 operator- () const noexcept
 negate the Vec3 components More...
 
bool operator== (const Vec3 &_v) const noexcept
 check for equality uses FCompare (from Util.h) as float values More...
 
bool operator!= (const Vec3 &_v) const noexcept
 not equal check More...
 
Vec3 operator/ (const Vec3 &_v) const noexcept
 \ operator div Vec3/Vec3 More...
 
void cross (const Vec3 &_v1, const Vec3 &_v2) noexcept
 set the Vec3 as the cross product from 2 other Vec3 More...
 
Vec3 cross (const Vec3 &_b) const noexcept
 return the cross product of this cross with b More...
 
void clamp (float _min, float _max) noexcept
 clamp the vector values between _min and _max More...
 
void clamp (float _max) noexcept
 clamp the vector values between +/-_max More...
 
Vec3 reflect (const Vec3 &_n) const noexcept
 return the vector reflected with this and N More...
 
RealopenGL () noexcept
 accesor to the m_openGL array returns the address of the 0th element More...
 

Static Public Member Functions

static Vec3 up ()
 simple static method to return Y up vector More...
 
static Vec3 down ()
 simple static method to return Y down vector More...
 
static Vec3 left ()
 simple static method to return X left vector More...
 
static Vec3 right ()
 simple static method to return X right vector More...
 
static Vec3 in ()
 simple static method to return Z out vector More...
 
static Vec3 out ()
 simple static method to return Z in vector More...
 
static Vec3 zero ()
 simple static method to return zero vector More...
 

Public Attributes

union {
   struct {
      Real   m_x
 x component More...
 
      Real   m_y
 y component More...
 
      Real   m_z
 z component More...
 
   } 
 
   struct {
      Real   m_r
 r component More...
 
      Real   m_g
 g component More...
 
      Real   m_b
 b component More...
 
   } 
 
   std::array< Real, 3 >   m_openGL
 array of four floats mapped to the x,y,z,w components of the Vec3 useful for openGL fv data types this is mapped as a union to the following
m_x == m_openGL[0]
m_y == m_openGL[1]
m_z == m_openGL[2]
More...
 
}; 
 

Detailed Description

simple Vec3 encapsulates a 3 float object like glsl vec3 but not maths use the Vec3 class for maths and the asVec3 to return a vec3

Definition at line 51 of file Vec3.h.

Constructor & Destructor Documentation

ngl::Vec3::Vec3 ( )
inline

default ctor use default and set to (0.0f,0.0f,0.0f) as attributes are initialised

Definition at line 59 of file Vec3.h.

+ Here is the caller graph for this function:

ngl::Vec3::Vec3 ( const Vec3 _v)
default

copy ctor we have POD data so let the compiler do the work!

ngl::Vec3::Vec3 ( Real  _x,
Real  _y,
Real  _z 
)
inlinenoexcept

initialise the constructor from 3 floats

Parameters
[in]_xx value
[in]_yy value
[in]_zz value

Definition at line 70 of file Vec3.h.

Member Function Documentation

void ngl::Vec3::clamp ( float  _min,
float  _max 
)
noexcept

clamp the vector values between _min and _max

Parameters
[in]_minvalue
[in]_maxvalue

Definition at line 267 of file Vec3.cpp.

References m_x, m_y, and m_z.

void ngl::Vec3::clamp ( float  _max)
noexcept

clamp the vector values between +/-_max

Parameters
[in]_maxvalue

Definition at line 280 of file Vec3.cpp.

References m_x, m_y, and m_z.

void ngl::Vec3::cross ( const Vec3 _v1,
const Vec3 _v2 
)
noexcept

set the Vec3 as the cross product from 2 other Vec3

Parameters
[in]_v1the first vector
[in]_v2the second vector

Definition at line 187 of file Vec3.cpp.

References m_x, m_y, and m_z.

+ Here is the caller graph for this function:

Vec3 ngl::Vec3::cross ( const Vec3 _b) const
noexcept

return the cross product of this cross with b

Parameters
[in]_bthe vector cross this with
Returns
the result of this cross b

Definition at line 195 of file Vec3.cpp.

References m_x, m_y, m_z, and Vec3().

+ Here is the call graph for this function:

Real ngl::Vec3::dot ( const Vec3 _b) const
noexcept

return this dotted with _b

Parameters
[in]_bvector to dot current vector with
Returns
the dot product

Definition at line 55 of file Vec3.cpp.

+ Here is the caller graph for this function:

static Vec3 ngl::Vec3::down ( )
inlinestatic

simple static method to return Y down vector

Definition at line 278 of file Vec3.h.

static Vec3 ngl::Vec3::in ( )
inlinestatic

simple static method to return Z out vector

Definition at line 290 of file Vec3.h.

Real ngl::Vec3::inner ( const Vec3 _v) const
noexcept

calculate the inner product of this vector and vector passed in

Parameters
[in]_vthe vector to calculate inner product with
Returns
the inner product

Definition at line 216 of file Vec3.cpp.

References m_x, m_y, and m_z.

+ Here is the caller graph for this function:

static Vec3 ngl::Vec3::left ( )
inlinestatic

simple static method to return X left vector

Definition at line 282 of file Vec3.h.

Real ngl::Vec3::length ( ) const
noexcept

returns the length of the vector

Returns
$\sqrt{x^2+y^2+z^2} $

Definition at line 233 of file Vec3.cpp.

References m_x, m_y, and m_z.

+ Here is the caller graph for this function:

Real ngl::Vec3::lengthSquared ( ) const
noexcept

returns the length squared of the vector (no sqrt so quicker)

Returns
$x^2+y^2+z^2 $

Definition at line 240 of file Vec3.cpp.

References m_x, m_y, and m_z.

void ngl::Vec3::normalize ( )
noexcept

Normalize the vector using
$x=x/\sqrt{x^2+y^2+z^2} $
$y=y/\sqrt{x^2+y^2+z^2} $
$z=z/\sqrt{x^2+y^2+z^2} $.

Definition at line 206 of file Vec3.cpp.

References m_x, m_y, m_z, and NGL_ASSERT.

+ Here is the caller graph for this function:

void ngl::Vec3::null ( )
noexcept

clears the Vec3 to 0,0,0

Definition at line 60 of file Vec3.cpp.

References m_x, m_y, and m_z.

Real* ngl::Vec3::openGL ( )
inlinenoexcept

accesor to the m_openGL array returns the address of the 0th element

Definition at line 270 of file Vec3.h.

bool ngl::Vec3::operator!= ( const Vec3 _v) const
noexcept

not equal check

Parameters
[in]_vthe Vec3 to check against
Returns
true of false

Definition at line 142 of file Vec3.cpp.

References FCompare, m_x, m_y, and m_z.

Vec3 ngl::Vec3::operator* ( Real  _i) const
noexcept

this * i for each element

Parameters
[in]_ithe scalar to mult by
Returns
Vec3

Definition at line 163 of file Vec3.cpp.

References m_x, m_y, m_z, and Vec3().

+ Here is the call graph for this function:

Vec3 ngl::Vec3::operator* ( const Vec3 _v) const
noexcept

  • operator mult vevtor*Vec3

Parameters
[in]_vthe value to mult
Returns
new Vec3 this*v

Definition at line 151 of file Vec3.cpp.

References m_x, m_y, m_z, and Vec3().

+ Here is the call graph for this function:

Vec3 ngl::Vec3::operator* ( const Mat3 _m) const
noexcept

operator to multiply a vector by a matrix

Parameters
[in]_mthe matrix to multiply

Definition at line 246 of file Vec3.cpp.

References m_x, m_y, and m_z.

void ngl::Vec3::operator*= ( Real  _v)
noexcept

multiply this Vec3 components by a scalar

Parameters
[in]_vthe scalar to multiply by sets the Vec3 to Vec3 V(x*v,y*v,z*v,w)

Definition at line 100 of file Vec3.cpp.

References m_x, m_y, and m_z.

Vec3 ngl::Vec3::operator+ ( const Vec3 _v) const
noexcept

  • operator add Vec3+Vec3

Parameters
[in]&_vthe value to add
Returns
the Vec3 + v

Definition at line 121 of file Vec3.cpp.

References m_x, m_y, m_z, and Vec3().

+ Here is the call graph for this function:

void ngl::Vec3::operator+= ( const Vec3 _v)
noexcept

+= operator add Vec3 v to current Vec3

Parameters
[in]&_vVec3 to add

Definition at line 84 of file Vec3.cpp.

References m_x, m_y, and m_z.

Vec3 ngl::Vec3::operator- ( const Vec3 _v) const
noexcept

subtraction operator subtract vevtor-Vec3

Parameters
[in]&_vthe value to sub
Returns
this - v

Definition at line 127 of file Vec3.cpp.

References m_x, m_y, m_z, and Vec3().

+ Here is the call graph for this function:

Vec3 ngl::Vec3::operator- ( ) const
noexcept

negate the Vec3 components

Definition at line 77 of file Vec3.cpp.

References m_x, m_y, m_z, and Vec3().

+ Here is the call graph for this function:

void ngl::Vec3::operator-= ( const Vec3 _v)
noexcept

-= operator this-=v

Parameters
[in]&_vVec3 to subtract

Definition at line 107 of file Vec3.cpp.

References m_x, m_y, and m_z.

Vec3 ngl::Vec3::operator/ ( Real  _v) const
noexcept

divide Vec3 components by a scalar

Parameters
[in]_vthe scalar to divide by
Returns
a Vec3 V(x/v,y/v,z/v,w)

Definition at line 115 of file Vec3.cpp.

References m_x, m_y, m_z, and Vec3().

+ Here is the call graph for this function:

Vec3 ngl::Vec3::operator/ ( const Vec3 _v) const
noexcept

\ operator div Vec3/Vec3

Parameters
[in]_vthe value to div by
Returns
Vec3 / Vec3

Definition at line 157 of file Vec3.cpp.

References m_x, m_y, m_z, and Vec3().

+ Here is the call graph for this function:

void ngl::Vec3::operator/= ( Real  _v)
noexcept

divide this Vec3 components by a scalar

Parameters
[in]_vthe scalar to divide by sets the Vec3 to Vec3 V(x/v,y/v,z/v,w)

Definition at line 92 of file Vec3.cpp.

References m_x, m_y, m_z, and NGL_ASSERT.

Vec3& ngl::Vec3::operator= ( const Vec3 _v)
default

assignment operator set the current Vec3 to rhs

Parameters
[in]_vthe Vec3 to set
Returns
a new Vec3
Vec3 & ngl::Vec3::operator= ( const Vec4 _v)
noexcept

assignment operator set the current Vec4 to rhs

Parameters
[in]_vthe Vec3 to set
Returns
a new Vec3

Definition at line 179 of file Vec3.cpp.

References m_x, m_y, and m_z.

Vec3 & ngl::Vec3::operator= ( Real  _v)
noexcept

assignment operator set the current Vec3 to rhs

Parameters
[in]_vthe float to set
Returns
a new Vec3

Definition at line 169 of file Vec3.cpp.

References m_x, m_y, and m_z.

bool ngl::Vec3::operator== ( const Vec3 _v) const
noexcept

check for equality uses FCompare (from Util.h) as float values

Parameters
[in]_vthe Vec3 to check against
Returns
true or false

Definition at line 133 of file Vec3.cpp.

References FCompare, m_x, m_y, and m_z.

Real & ngl::Vec3::operator[] ( size_t &  _i)
noexcept

[] index operator to access the index component of the Vec3

Returns
this[x] as a Real

Definition at line 68 of file Vec3.cpp.

References m_x, and NGL_ASSERT.

const Real& ngl::Vec3::operator[] ( size_t &  _i) const
inlinenoexcept

[] index operator to access the index component of the Vec3

Returns
this[x] as a Real

Definition at line 108 of file Vec3.h.

References ngl::operator*(), and ngl::operator==().

+ Here is the call graph for this function:

static Vec3 ngl::Vec3::out ( )
inlinestatic

simple static method to return Z in vector

Definition at line 294 of file Vec3.h.

Mat3 ngl::Vec3::outer ( const Vec3 _v) const
noexcept

compute the outer product of this vector and vector (requested by PJ)

Parameters
[in]_vthe vector to calc against
Returns
a mat 3

Definition at line 223 of file Vec3.cpp.

References m_x, m_y, and m_z.

Vec3 ngl::Vec3::reflect ( const Vec3 _n) const
noexcept

return the vector reflected with this and N

Parameters
[in]_nthe normal vector
Returns
the reflection vector of this with N

Definition at line 260 of file Vec3.cpp.

References dot(), m_x, m_y, m_z, and Vec3().

+ Here is the call graph for this function:

static Vec3 ngl::Vec3::right ( )
inlinestatic

simple static method to return X right vector

Definition at line 286 of file Vec3.h.

void ngl::Vec3::set ( Real  _x,
Real  _y,
Real  _z 
)
noexcept

sets the Vec3 component from 3 values

Parameters
[in]_xthe x component
[in]_ythe y component
[in]_zthe z component

Definition at line 33 of file Vec3.cpp.

+ Here is the caller graph for this function:

void ngl::Vec3::set ( const Vec3 _v)
noexcept

set from another Vec3

Parameters
[in]_vthe Vec3 to set from

Definition at line 41 of file Vec3.cpp.

void ngl::Vec3::set ( const Vec4 _v)
noexcept

set from another Vec4 ( you may need to convert somtimes)

Parameters
[in]_vthe Vec4 to set from

Definition at line 47 of file Vec3.cpp.

static Vec3 ngl::Vec3::up ( )
inlinestatic

simple static method to return Y up vector

Definition at line 274 of file Vec3.h.

static Vec3 ngl::Vec3::zero ( )
inlinestatic

simple static method to return zero vector

Definition at line 298 of file Vec3.h.

Member Data Documentation

union { ... }
Note
I've made this public as some compilers automatically make the anonymous unions public whereas clang++ complains see this post http://jonmacey.blogspot.com/2011/03/anonymous-union-struct-weirdness.html
Real ngl::Vec3::m_b

b component

Definition at line 319 of file Vec3.h.

Real ngl::Vec3::m_g

g component

Definition at line 318 of file Vec3.h.

std::array<Real,3> ngl::Vec3::m_openGL

array of four floats mapped to the x,y,z,w components of the Vec3 useful for openGL fv data types this is mapped as a union to the following
m_x == m_openGL[0]
m_y == m_openGL[1]
m_z == m_openGL[2]

Definition at line 332 of file Vec3.h.

Real ngl::Vec3::m_r

r component

Definition at line 317 of file Vec3.h.

Real ngl::Vec3::m_x

x component

Definition at line 310 of file Vec3.h.

Real ngl::Vec3::m_y

y component

Definition at line 311 of file Vec3.h.

Real ngl::Vec3::m_z

z component

Definition at line 312 of file Vec3.h.


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