Oficina Framework  1.3
Games Framework
vec3 Class Reference

A class representing a point in 3D space. More...

#include <OficinaTypes.hpp>

Public Member Functions

 vec3 ()
 Constructs class with null values. More...
 
 vec3 (float n)
 Constructs class with two equal values. More...
 
 vec3 (float X, float Y, float Z)
 Constructs class with two values. More...
 
vec3operator= (const vec3)
 
vec3operator= (const float)
 
const vec3 operator+ (const vec3)
 
const vec3 operator+ (const float)
 
vec3operator+= (const vec3)
 
vec3operator+= (const float)
 
const vec3 operator- (const vec3)
 
const vec3 operator- (const float)
 
vec3operator-= (const vec3)
 
vec3operator-= (const float)
 
const vec3 operator* (const vec3)
 
const vec3 operator* (const float)
 
vec3operator*= (const vec3)
 
vec3operator*= (const float)
 
const vec3 operator/ (const vec3)
 
const vec3 operator/ (const float)
 
vec3operator/= (const vec3)
 
vec3operator/= (const float)
 
bool operator> (const vec3)
 
bool operator> (const float)
 
bool operator< (const vec3)
 
bool operator< (const float)
 
bool operator>= (const vec3)
 
bool operator>= (const float)
 
bool operator<= (const vec3)
 
bool operator<= (const float)
 
bool operator== (const vec3)
 
bool operator== (const float)
 
bool operator!= (const vec3)
 
bool operator!= (const float)
 
vec3 getTruncated ()
 Returns a copy of this vec3 truncated to the nearest integer. More...
 
void truncate ()
 Truncates the coordinates of this. More...
 
float length ()
 Gets the magnitude (length) of this vector. More...
 
vec3 getNormalized ()
 Gets a normalized version of this vector. More...
 
void normalize ()
 Normalizes this vector. More...
 
void clamp (vec3 origin, vec3 end)
 Encloses this vector inside a box, with its edges described by two other vectors. More...
 
std::string toString ()
 Getsa string with the vec3 values. More...
 

Static Public Member Functions

static vec3 Zero ()
 Returns a vec3 with both coordinates having the value 0.0f. More...
 
static vec3 One ()
 Returns a vec3 with both coordinates having the value 1.0f. More...
 
static vec3 Up ()
 Returns a vec3 with coordinates indicating the Up direction. More...
 
static vec3 Down ()
 Returns a vec3 with coordinates indicating the Down direction. More...
 
static vec3 Left ()
 Returns a vec3 with coordinates indicating the Left direction. More...
 
static vec3 Right ()
 Returns a vec3 with coordinates indicating the Right direction. More...
 
static vec3 Front ()
 Returns a vec3 with coordinates indicating the Front direction. More...
 
static vec3 Back ()
 Returns a vec3 with coordinates indicating the Back direction. More...
 
static float distance (vec3 first, vec3 second)
 Calculates the distance between two vectors. More...
 
static float squareDistance (vec3 first, vec3 second)
 Calculates the square distance between two vectors. Useful if you don't want the Square Root operation to be executed on the value for performance reasons. More...
 

Public Attributes

union {
   struct {
      float   x
 X coordinate of point. More...
 
      float   y
 Y coordinate of point. More...
 
      float   z
 Z coordinate of point. More...
 
   } 
 
   struct {
      float   v [3]
 Array of coordinates of the point. More...
 
   } 
 
}; 
 

Friends

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

Detailed Description

A class representing a point in 3D space.

Constructor & Destructor Documentation

◆ vec3() [1/3]

vec3::vec3 ( )

Constructs class with null values.

◆ vec3() [2/3]

vec3::vec3 ( float  n)

Constructs class with two equal values.

Parameters
nValue to be given to coordinates.

◆ vec3() [3/3]

vec3::vec3 ( float  X,
float  Y,
float  Z 
)

Constructs class with two values.

Parameters
XValue to be given to x coordinate.
YValue to be given to y coordinate.
ZValue to be given to y coordinate.

Member Function Documentation

◆ Back()

static vec3 vec3::Back ( )
static

Returns a vec3 with coordinates indicating the Back direction.

Returns
A back-facing vec3.

◆ clamp()

void vec3::clamp ( vec3  origin,
vec3  end 
)

Encloses this vector inside a box, with its edges described by two other vectors.

Parameters
originMinimum values for the vector.
endMaximum values for the vector.
Warning
In case a single coordinate of origin is bigger than end's, the vector will not be clamped on that coordinate.

◆ distance()

static float vec3::distance ( vec3  first,
vec3  second 
)
static

Calculates the distance between two vectors.

Parameters
firstFirst vector.
secondSecond vector.
Returns
Distance value between the two desired points.

◆ Down()

static vec3 vec3::Down ( )
static

Returns a vec3 with coordinates indicating the Down direction.

Returns
A down-facing vec3.

◆ Front()

static vec3 vec3::Front ( )
static

Returns a vec3 with coordinates indicating the Front direction.

Returns
A front-facing vec3.

◆ getNormalized()

vec3 vec3::getNormalized ( )

Gets a normalized version of this vector.

Returns
A normalized vector.

◆ getTruncated()

vec3 vec3::getTruncated ( )

Returns a copy of this vec3 truncated to the nearest integer.

Returns
The truncated vec3 of this.

◆ Left()

static vec3 vec3::Left ( )
static

Returns a vec3 with coordinates indicating the Left direction.

Returns
A left-facing vec3.

◆ length()

float vec3::length ( )

Gets the magnitude (length) of this vector.

Returns
The magnitude of this vector.

◆ normalize()

void vec3::normalize ( )

Normalizes this vector.

◆ One()

static vec3 vec3::One ( )
static

Returns a vec3 with both coordinates having the value 1.0f.

Returns
An unitary-value vec3.

◆ operator!=() [1/2]

bool vec3::operator!= ( const vec3  )

◆ operator!=() [2/2]

bool vec3::operator!= ( const float  )

◆ operator*() [1/2]

const vec3 vec3::operator* ( const vec3  )

◆ operator*() [2/2]

const vec3 vec3::operator* ( const float  )

◆ operator*=() [1/2]

vec3& vec3::operator*= ( const vec3  )

◆ operator*=() [2/2]

vec3& vec3::operator*= ( const float  )

◆ operator+() [1/2]

const vec3 vec3::operator+ ( const vec3  )

◆ operator+() [2/2]

const vec3 vec3::operator+ ( const float  )

◆ operator+=() [1/2]

vec3& vec3::operator+= ( const vec3  )

◆ operator+=() [2/2]

vec3& vec3::operator+= ( const float  )

◆ operator-() [1/2]

const vec3 vec3::operator- ( const vec3  )

◆ operator-() [2/2]

const vec3 vec3::operator- ( const float  )

◆ operator-=() [1/2]

vec3& vec3::operator-= ( const vec3  )

◆ operator-=() [2/2]

vec3& vec3::operator-= ( const float  )

◆ operator/() [1/2]

const vec3 vec3::operator/ ( const vec3  )

◆ operator/() [2/2]

const vec3 vec3::operator/ ( const float  )

◆ operator/=() [1/2]

vec3& vec3::operator/= ( const vec3  )

◆ operator/=() [2/2]

vec3& vec3::operator/= ( const float  )

◆ operator<() [1/2]

bool vec3::operator< ( const vec3  )

◆ operator<() [2/2]

bool vec3::operator< ( const float  )

◆ operator<=() [1/2]

bool vec3::operator<= ( const vec3  )

◆ operator<=() [2/2]

bool vec3::operator<= ( const float  )

◆ operator=() [1/2]

vec3& vec3::operator= ( const vec3  )

◆ operator=() [2/2]

vec3& vec3::operator= ( const float  )

◆ operator==() [1/2]

bool vec3::operator== ( const vec3  )

◆ operator==() [2/2]

bool vec3::operator== ( const float  )

◆ operator>() [1/2]

bool vec3::operator> ( const vec3  )

◆ operator>() [2/2]

bool vec3::operator> ( const float  )

◆ operator>=() [1/2]

bool vec3::operator>= ( const vec3  )

◆ operator>=() [2/2]

bool vec3::operator>= ( const float  )

◆ Right()

static vec3 vec3::Right ( )
static

Returns a vec3 with coordinates indicating the Right direction.

Returns
A right-facing vec3.

◆ squareDistance()

static float vec3::squareDistance ( vec3  first,
vec3  second 
)
static

Calculates the square distance between two vectors. Useful if you don't want the Square Root operation to be executed on the value for performance reasons.

Parameters
firstFirst vector.
secondSecond vector.
Returns
Square distance value between the two desired points.

◆ toString()

std::string vec3::toString ( )

Getsa string with the vec3 values.

Returns
Values inside vec3, in format {x, y}.

◆ truncate()

void vec3::truncate ( )

Truncates the coordinates of this.

◆ Up()

static vec3 vec3::Up ( )
static

Returns a vec3 with coordinates indicating the Up direction.

Returns
An up-facing vec3.

◆ Zero()

static vec3 vec3::Zero ( )
static

Returns a vec3 with both coordinates having the value 0.0f.

Returns
A null-values vec3.

Friends And Related Function Documentation

◆ operator<<

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

Member Data Documentation

◆ @13

union { ... }

◆ v

float vec3::v[3]

Array of coordinates of the point.

◆ x

float vec3::x

X coordinate of point.

◆ y

float vec3::y

Y coordinate of point.

◆ z

float vec3::z

Z coordinate of point.


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