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

simple Vector class for OpenGL graphics, contains overloaded operators for most math functions, including operators for manipulation by Point3 and Matrix has a simple union to allow data to be access as x,y,z,w or float[4] array More...

#include <Vec4.h>

+ Collaboration diagram for ngl::Vec4:

Public Member Functions

 Vec4 ()
 
 Vec4 (const Vec4 &_v)=default
 copy ctor More...
 
 Vec4 (const Vec3 &_v, float _w=1.0f) noexcept
 copy ctor More...
 
 Vec4 (Real _x, Real _y, Real _z, Real _w=1.0f) noexcept
 initialise the constructor from 3 or 4 Real More...
 
Real dot (const Vec4 &_b) const noexcept
 return this dotted with _b More...
 
void set (Real _x, Real _y, Real _z, Real _w=1.0) noexcept
 sets the vector component from 3 values More...
 
void set (const Vec4 &_v) noexcept
 set from another vector More...
 
void set (const Vec3 &_v) noexcept
 set from another vector More...
 
void null () noexcept
 clears the vector to 0,0,0,1 More...
 
Vec3 toVec3 () const noexcept
 get as a Vec3 for glsl etc More...
 
Vec2 toVec2 () const noexcept
 get as a Vec2 for glsl etc More...
 
Realoperator[] (int _i) noexcept
 [] index operator to access the index component of the vector More...
 
const Realoperator[] (int _i) const noexcept
 
Real length () const noexcept
 returns the length of the vector More...
 
Vec4normalize () 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...
 
void cross (const Vec4 &_v1, const Vec4 &_v2) noexcept
 set the vector as the cross product from 2 other vectors More...
 
Vec4 cross (const Vec4 &_b) const noexcept
 return the cross product of this cross with b More...
 
void operator+= (const Vec4 &_v) noexcept
 += operator add vector v to current vector More...
 
void operator-= (const Vec4 &_v) noexcept
 -= operator this-=v More...
 
Vec4 operator* (Real _i) const noexcept
 this * i for each element More...
 
Vec4 operator+ (const Vec4 &_v) const noexcept
 
  • operator add vector+vector
More...
 
Vec4 operator/ (Real _v) const noexcept
 divide vector components by a scalar More...
 
void operator/= (Real _v) noexcept
 divide this vector components by a scalar More...
 
void operator*= (Real _v) noexcept
 multiply this vector components by a scalar More...
 
Vec4 operator- (const Vec4 &_v) const noexcept
 subtraction operator subtract vevtor-vector More...
 
Vec4 operator* (const Vec4 &_v) const noexcept
 
  • operator mult vevtor*vector
More...
 
Vec4operator= (const Vec4 &_v) noexcept
 assignment operator set the current vector to rhs More...
 
Vec4operator= (const Vec3 &_v) noexcept
 assignment operator set the current vector to rhs More...
 
Vec4operator= (Real _v) noexcept
 assignment operator set the current vector to rhs More...
 
Vec4operator- () noexcept
 negate the vector components More...
 
bool operator== (const Vec4 &_v) const noexcept
 check for equality uses FCompare (from Util.h) as float values More...
 
bool operator!= (const Vec4 &_v) const noexcept
 not equal check More...
 
Vec4 operator/ (const Vec4 &_v) const noexcept
 \ operator div vector/vector More...
 
Real angleBetween (const Vec4 &_v) const noexcept
 calculate the angle between current vector and _v More...
 
Real inner (const Vec4 &_v) const noexcept
 calculate the inner product of this vector and vector passed in More...
 
Vec4 outer (const Vec4 &_v) const noexcept
 compute the outer product of this vector and vector More...
 
Real lengthSquared () const noexcept
 calculate the length squared of the vector More...
 
Vec4 operator* (const Mat4 &_m) const noexcept
 operator to multiply a vector by a matrix More...
 
RealopenGL () noexcept
 accesor to the m_openGL matrix returns the address of the 0th element More...
 

Static Public Member Functions

static Vec4 up ()
 
static Vec4 down ()
 
static Vec4 left ()
 
static Vec4 right ()
 
static Vec4 in ()
 
static Vec4 out ()
 
static Vec4 zero ()
 

Public Attributes

union {
   struct {
      Real   m_x
 x component More...
 
      Real   m_y
 y component More...
 
      Real   m_z
 z component More...
 
      Real   m_w
 w component 0 for vector 1 for point More...
 
   } 
 
   struct {
      Real   m_r
 r component More...
 
      Real   m_g
 g component More...
 
      Real   m_b
 b component More...
 
      Real   m_a
 a component More...
 
   } 
 
   std::array< Real, 4 >   m_openGL
 array of four floats mapped to the x,y,z,w components of the vector 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]
m_w == m_openGL[3]
More...
 
}; 
 

Friends

class Mat4
 
class VBOPrimitives
 
class Transformation
 
class Quaternion
 
class Obj
 

Detailed Description

simple Vector class for OpenGL graphics, contains overloaded operators for most math functions, including operators for manipulation by Point3 and Matrix has a simple union to allow data to be access as x,y,z,w or float[4] array

Definition at line 57 of file Vec4.h.

Constructor & Destructor Documentation

ngl::Vec4::Vec4 ( )
inline

Definition at line 67 of file Vec4.h.

+ Here is the caller graph for this function:

ngl::Vec4::Vec4 ( const Vec4 _v)
default

copy ctor

Parameters
[in]_vthe value to set
ngl::Vec4::Vec4 ( const Vec3 _v,
float  _w = 1.0f 
)
inlinenoexcept

copy ctor

Parameters
[in]_vthe value to set

Definition at line 77 of file Vec4.h.

ngl::Vec4::Vec4 ( Real  _x,
Real  _y,
Real  _z,
Real  _w = 1.0f 
)
inlinenoexcept

initialise the constructor from 3 or 4 Real

Parameters
[in]_xx value
[in]_yy value
[in]_zz value
[in]_w1.0f default so acts as a points

Definition at line 90 of file Vec4.h.

Member Function Documentation

Real ngl::Vec4::angleBetween ( const Vec4 _v) const
noexcept

calculate the angle between current vector and _v

Parameters
[in]_vthe vector to check
Returns
the angle between the two vectors in degrees

Definition at line 240 of file Vec4.cpp.

References dot(), and normalize().

+ Here is the call graph for this function:

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

set the vector as the cross product from 2 other vectors

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

Definition at line 110 of file Vec4.cpp.

References m_x, m_y, and m_z.

+ Here is the caller graph for this function:

Vec4 ngl::Vec4::cross ( const Vec4 _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 118 of file Vec4.cpp.

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

+ Here is the call graph for this function:

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

return this dotted with _b

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

Definition at line 35 of file Vec4.cpp.

+ Here is the caller graph for this function:

static Vec4 ngl::Vec4::down ( )
inlinestatic

Definition at line 300 of file Vec4.h.

static Vec4 ngl::Vec4::in ( )
inlinestatic

Definition at line 305 of file Vec4.h.

Real ngl::Vec4::inner ( const Vec4 _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 253 of file Vec4.cpp.

References m_x, m_y, and m_z.

static Vec4 ngl::Vec4::left ( )
inlinestatic

Definition at line 302 of file Vec4.h.

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

returns the length of the vector

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

Definition at line 83 of file Vec4.cpp.

References m_x, m_y, and m_z.

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

calculate the length squared of the vector

Returns
length squared

Definition at line 305 of file Vec4.cpp.

References m_x, m_y, and m_z.

Vec4 & ngl::Vec4::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 99 of file Vec4.cpp.

References m_x, m_y, m_z, and NGL_ASSERT.

+ Here is the caller graph for this function:

void ngl::Vec4::null ( )
noexcept

clears the vector to 0,0,0,1

Definition at line 67 of file Vec4.cpp.

References m_w, m_x, m_y, and m_z.

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

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

Definition at line 297 of file Vec4.h.

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

not equal check

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

Definition at line 198 of file Vec4.cpp.

References FCompare, m_x, m_y, and m_z.

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

this * i for each element

Parameters
[in]_ithe scalar to mult by
Returns
Vector

Definition at line 229 of file Vec4.cpp.

References m_w, m_x, m_y, m_z, and Vec4().

+ Here is the call graph for this function:

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

  • operator mult vevtor*vector

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

Definition at line 207 of file Vec4.cpp.

References m_w, m_x, m_y, m_z, and Vec4().

+ Here is the call graph for this function:

Vec4 ngl::Vec4::operator* ( const Mat4 _m) const
noexcept

operator to multiply a vector by a matrix

Parameters
[in]_mthe matrix to multiply

Definition at line 311 of file Vec4.cpp.

References m_w, m_x, m_y, and m_z.

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

multiply this vector components by a scalar

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

Definition at line 146 of file Vec4.cpp.

References m_x, m_y, and m_z.

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

  • operator add vector+vector

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

Definition at line 167 of file Vec4.cpp.

References m_w, m_x, m_y, m_z, and Vec4().

+ Here is the call graph for this function:

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

+= operator add vector v to current vector

Parameters
[in]&_vvector to add

Definition at line 130 of file Vec4.cpp.

References m_x, m_y, and m_z.

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

subtraction operator subtract vevtor-vector

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

Definition at line 178 of file Vec4.cpp.

References m_w, m_x, m_y, m_z, and Vec4().

+ Here is the call graph for this function:

Vec4 & ngl::Vec4::operator- ( )
noexcept

negate the vector components

Definition at line 90 of file Vec4.cpp.

References m_x, m_y, and m_z.

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

-= operator this-=v

Parameters
[in]&_vvector to subtract

Definition at line 153 of file Vec4.cpp.

References m_x, m_y, and m_z.

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

divide vector components by a scalar

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

Definition at line 161 of file Vec4.cpp.

References m_w, m_x, m_y, m_z, and Vec4().

+ Here is the call graph for this function:

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

\ operator div vector/vector

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

Definition at line 218 of file Vec4.cpp.

References m_w, m_x, m_y, m_z, and Vec4().

+ Here is the call graph for this function:

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

divide this vector components by a scalar

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

Definition at line 138 of file Vec4.cpp.

References m_x, m_y, m_z, and NGL_ASSERT.

Vec4 & ngl::Vec4::operator= ( const Vec4 _v)
noexcept

assignment operator set the current vector to rhs

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

Definition at line 274 of file Vec4.cpp.

References m_w, m_x, m_y, and m_z.

Vec4 & ngl::Vec4::operator= ( const Vec3 _v)
noexcept

assignment operator set the current vector to rhs

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

Definition at line 284 of file Vec4.cpp.

References m_w, m_x, m_y, and m_z.

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

assignment operator set the current vector to rhs

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

Definition at line 294 of file Vec4.cpp.

References m_w, m_x, m_y, and m_z.

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

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

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

Definition at line 189 of file Vec4.cpp.

References FCompare, m_x, m_y, and m_z.

Real & ngl::Vec4::operator[] ( int  _i)
noexcept

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

Returns
this[x] as a Real

Definition at line 76 of file Vec4.cpp.

References m_x, and NGL_ASSERT.

const Real& ngl::Vec4::operator[] ( int  _i) const
inlinenoexcept

Definition at line 139 of file Vec4.h.

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

+ Here is the call graph for this function:

static Vec4 ngl::Vec4::out ( )
inlinestatic

Definition at line 306 of file Vec4.h.

Vec4 ngl::Vec4::outer ( const Vec4 _v) const
noexcept

compute the outer product of this vector and vector

Parameters
[in]_vthe vector to calc against
Returns
a new vector

Definition at line 263 of file Vec4.cpp.

References m_w, m_x, m_y, m_z, and Vec4().

+ Here is the call graph for this function:

static Vec4 ngl::Vec4::right ( )
inlinestatic

Definition at line 303 of file Vec4.h.

void ngl::Vec4::set ( Real  _x,
Real  _y,
Real  _z,
Real  _w = 1.0 
)
noexcept

sets the vector component from 3 values

Parameters
[in]_xthe x component
[in]_ythe y component
[in]_zthe z component
[in]_wthe w component default to 1 for a point

Definition at line 41 of file Vec4.cpp.

+ Here is the caller graph for this function:

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

set from another vector

Parameters
[in]_vthe vector to set from

Definition at line 50 of file Vec4.cpp.

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

set from another vector

Parameters
[in]_vthe vector to set from

Definition at line 58 of file Vec4.cpp.

Vec2 ngl::Vec4::toVec2 ( ) const
inlinenoexcept

get as a Vec2 for glsl etc

Definition at line 133 of file Vec4.h.

Vec3 ngl::Vec4::toVec3 ( ) const
inlinenoexcept

get as a Vec3 for glsl etc

Definition at line 128 of file Vec4.h.

+ Here is the caller graph for this function:

static Vec4 ngl::Vec4::up ( )
inlinestatic

Definition at line 299 of file Vec4.h.

+ Here is the caller graph for this function:

static Vec4 ngl::Vec4::zero ( )
inlinestatic

Definition at line 308 of file Vec4.h.

Friends And Related Function Documentation

friend class Mat4
friend

Definition at line 60 of file Vec4.h.

friend class Obj
friend

Definition at line 64 of file Vec4.h.

friend class Quaternion
friend

Definition at line 63 of file Vec4.h.

friend class Transformation
friend

Definition at line 62 of file Vec4.h.

friend class VBOPrimitives
friend

Definition at line 61 of file Vec4.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::Vec4::m_a

a component

Definition at line 331 of file Vec4.h.

Real ngl::Vec4::m_b

b component

Definition at line 330 of file Vec4.h.

Real ngl::Vec4::m_g

g component

Definition at line 329 of file Vec4.h.

std::array<Real,4> ngl::Vec4::m_openGL

array of four floats mapped to the x,y,z,w components of the vector 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]
m_w == m_openGL[3]

Definition at line 342 of file Vec4.h.

Real ngl::Vec4::m_r

r component

Definition at line 328 of file Vec4.h.

Real ngl::Vec4::m_w

w component 0 for vector 1 for point

Definition at line 324 of file Vec4.h.

Real ngl::Vec4::m_x

x component

Definition at line 321 of file Vec4.h.

Real ngl::Vec4::m_y

y component

Definition at line 322 of file Vec4.h.

Real ngl::Vec4::m_z

z component

Definition at line 323 of file Vec4.h.


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