Axmol Engine 2.4.0-258ceca
Loading...
Searching...
No Matches
Vec4 Class Reference

Defines 4-element floating point vector. More...

#include <Vec4.h>

Public Member Functions

constexpr Vec4 ()
 Constructs a new vector initialized to all zeros.
 
constexpr Vec4 (float xx, float yy, float zz, float ww)
 Constructs a new vector initialized to the specified values.
 
constexpr Vec4 (const float *array)
 Constructs a new vector from the values in the specified array.
 
constexpr Vec4 (const Vec4 &p1, const Vec4 &p2)
 Constructs a vector that describes the direction between the specified points.
 
bool isZero () const
 Indicates whether this vector contains all zeros.
 
bool isOne () const
 Indicates whether this vector contains all ones.
 
void clamp (const Vec4 &min, const Vec4 &max)
 Clamps this vector within the specified range.
 
float distance (const Vec4 &v) const
 Returns the distance between this vector and v.
 
float distanceSquared (const Vec4 &v) const
 Returns the squared distance between this vector and v.
 
float dot (const Vec4 &v) const
 Returns the dot product of this vector and the specified vector.
 
float length () const
 Computes the length of this vector.
 
float lengthSquared () const
 Returns the squared length of this vector.
 
void normalize ()
 Normalizes this vector.
 
Vec4 getNormalized () const
 Get the normalized vector.
 
constexpr void setDirection (const Vec4 &p1, const Vec4 &p2)
 Sets this vector to the directional vector between the specified points.
 

Static Public Member Functions

static Vec4 fromColor (unsigned int color)
 Creates a new vector from an integer interpreted as an RGBA value.
 
static float angle (const Vec4 &v1, const Vec4 &v2)
 Returns the angle (in radians) between the specified vectors.
 
static void add (const Vec4 &v1, const Vec4 &v2, Vec4 *dst)
 Adds the specified vectors and stores the result in dst.
 
static void clamp (const Vec4 &v, const Vec4 &min, const Vec4 &max, Vec4 *dst)
 Clamps the specified vector within the specified range and returns it in dst.
 
static float dot (const Vec4 &v1, const Vec4 &v2)
 Returns the dot product between the specified vectors.
 
static void subtract (const Vec4 &v1, const Vec4 &v2, Vec4 *dst)
 Subtracts the specified vectors and stores the result in dst.
 

Static Public Attributes

static const Vec4 ZERO = Vec4(0.0f, 0.0f, 0.0f, 0.0f)
 equals to Vec4(0,0,0,0)
 
static const Vec4 ONE = Vec4(1.0f, 1.0f, 1.0f, 1.0f)
 equals to Vec4(1,1,1,1)
 
static const Vec4 UNIT_X = Vec4(1.0f, 0.0f, 0.0f, 0.0f)
 equals to Vec4(1,0,0,0)
 
static const Vec4 UNIT_Y = Vec4(0.0f, 1.0f, 0.0f, 0.0f)
 equals to Vec4(0,1,0,0)
 
static const Vec4 UNIT_Z = Vec4(0.0f, 0.0f, 1.0f, 0.0f)
 equals to Vec4(0,0,1,0)
 
static const Vec4 UNIT_W = Vec4(0.0f, 0.0f, 0.0f, 1.0f)
 equals to Vec4(0,0,0,1)
 

Detailed Description

Defines 4-element floating point vector.

Constructor & Destructor Documentation

◆ Vec4() [1/3]

Vec4 ( float xx,
float yy,
float zz,
float ww )
inlineconstexpr

Constructs a new vector initialized to the specified values.

Parameters
xxThe x coordinate.
yyThe y coordinate.
zzThe z coordinate.
wwThe w coordinate.

◆ Vec4() [2/3]

Vec4 ( const float * array)
inlineexplicitconstexpr

Constructs a new vector from the values in the specified array.

Parameters
arrayAn array containing the elements of the vector in the order x, y, z, w.

◆ Vec4() [3/3]

Vec4 ( const Vec4 & p1,
const Vec4 & p2 )
inlineconstexpr

Constructs a vector that describes the direction between the specified points.

Parameters
p1The first point.
p2The second point.

Member Function Documentation

◆ fromColor()

static Vec4 fromColor ( unsigned int color)
static

Creates a new vector from an integer interpreted as an RGBA value.

E.g. 0xff0000ff represents opaque red or the vector (1, 0, 0, 1).

Parameters
colorThe integer to interpret as an RGBA value.
Returns
A vector corresponding to the interpreted RGBA color.

◆ isZero()

bool isZero ( ) const

Indicates whether this vector contains all zeros.

Returns
true if this vector contains all zeros, false otherwise.

◆ isOne()

bool isOne ( ) const

Indicates whether this vector contains all ones.

Returns
true if this vector contains all ones, false otherwise.

◆ angle()

static float angle ( const Vec4 & v1,
const Vec4 & v2 )
static

Returns the angle (in radians) between the specified vectors.

Parameters
v1The first vector.
v2The second vector.
Returns
The angle between the two vectors (in radians).

◆ add()

static void add ( const Vec4 & v1,
const Vec4 & v2,
Vec4 * dst )
static

Adds the specified vectors and stores the result in dst.

Parameters
v1The first vector.
v2The second vector.
dstA vector to store the result in.

◆ clamp() [1/2]

void clamp ( const Vec4 & min,
const Vec4 & max )

Clamps this vector within the specified range.

Parameters
minThe minimum value.
maxThe maximum value.

◆ clamp() [2/2]

static void clamp ( const Vec4 & v,
const Vec4 & min,
const Vec4 & max,
Vec4 * dst )
static

Clamps the specified vector within the specified range and returns it in dst.

Parameters
vThe vector to clamp.
minThe minimum value.
maxThe maximum value.
dstA vector to store the result in.

◆ distance()

float distance ( const Vec4 & v) const

Returns the distance between this vector and v.

Parameters
vThe other vector.
Returns
The distance between this vector and v.
See also
distanceSquared

◆ distanceSquared()

float distanceSquared ( const Vec4 & v) const

Returns the squared distance between this vector and v.

When it is not necessary to get the exact distance between two vectors (for example, when simply comparing the distance between different vectors), it is advised to use this method instead of distance.

Parameters
vThe other vector.
Returns
The squared distance between this vector and v.
See also
distance

◆ dot() [1/2]

float dot ( const Vec4 & v) const

Returns the dot product of this vector and the specified vector.

Parameters
vThe vector to compute the dot product with.
Returns
The dot product.

◆ dot() [2/2]

static float dot ( const Vec4 & v1,
const Vec4 & v2 )
static

Returns the dot product between the specified vectors.

Parameters
v1The first vector.
v2The second vector.
Returns
The dot product between the vectors.

◆ length()

float length ( ) const

Computes the length of this vector.

Returns
The length of the vector.
See also
lengthSquared

◆ lengthSquared()

float lengthSquared ( ) const

Returns the squared length of this vector.

When it is not necessary to get the exact length of a vector (for example, when simply comparing the lengths of different vectors), it is advised to use this method instead of length.

Returns
The squared length of the vector.
See also
length

◆ normalize()

void normalize ( )

Normalizes this vector.

This method normalizes this Vec4 so that it is of unit length (in other words, the length of the vector after calling this method will be 1.0f). If the vector already has unit length or if the length of the vector is zero, this method does nothing.

Returns
This vector, after the normalization occurs.

◆ setDirection()

void setDirection ( const Vec4 & p1,
const Vec4 & p2 )
inlineconstexpr

Sets this vector to the directional vector between the specified points.

Parameters
p1The first point.
p2The second point.

◆ subtract()

static void subtract ( const Vec4 & v1,
const Vec4 & v2,
Vec4 * dst )
static

Subtracts the specified vectors and stores the result in dst.

The resulting vector is computed as (v1 - v2).

Parameters
v1The first vector.
v2The second vector.
dstThe destination vector.

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