Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
Vec3 Class Reference

#include <Vec3.h>

Public Types

using Type = Vec4::Type
 
using ArgType = Vec3Arg
 

Public Member Functions

 Vec3 ()=default
 Constructor. More...
 
 Vec3 (const Vec3 &inRHS)=default
 
Vec3operator= (const Vec3 &inRHS)=default
 
JPH_INLINE Vec3 (Vec4Arg inRHS)
 
JPH_INLINE Vec3 (Type inRHS)
 
JPH_INLINE Vec3 (const Float3 &inV)
 Load 3 floats from memory. More...
 
JPH_INLINE Vec3 (float inX, float inY, float inZ)
 Create a vector from 3 components. More...
 
JPH_INLINE float GetX () const
 Get individual components. More...
 
JPH_INLINE float GetY () const
 
JPH_INLINE float GetZ () const
 
JPH_INLINE void SetX (float inX)
 Set individual components. More...
 
JPH_INLINE void SetY (float inY)
 
JPH_INLINE void SetZ (float inZ)
 
JPH_INLINE void Set (float inX, float inY, float inZ)
 Set all components. More...
 
JPH_INLINE float operator[] (uint inCoordinate) const
 Get float component by index. More...
 
JPH_INLINE void SetComponent (uint inCoordinate, float inValue)
 Set float component by index. More...
 
JPH_INLINE bool operator== (Vec3Arg inV2) const
 Comparison. More...
 
JPH_INLINE bool operator!= (Vec3Arg inV2) const
 
JPH_INLINE bool IsClose (Vec3Arg inV2, float inMaxDistSq=1.0e-12f) const
 Test if two vectors are close. More...
 
JPH_INLINE bool IsNearZero (float inMaxDistSq=1.0e-12f) const
 Test if vector is near zero. More...
 
JPH_INLINE bool IsNormalized (float inTolerance=1.0e-6f) const
 Test if vector is normalized. More...
 
JPH_INLINE bool IsNaN () const
 Test if vector contains NaN elements. More...
 
JPH_INLINE Vec3 operator* (Vec3Arg inV2) const
 Multiply two float vectors (component wise) More...
 
JPH_INLINE Vec3 operator* (float inV2) const
 Multiply vector with float. More...
 
JPH_INLINE Vec3 operator/ (float inV2) const
 Divide vector by float. More...
 
JPH_INLINE Vec3operator*= (float inV2)
 Multiply vector with float. More...
 
JPH_INLINE Vec3operator*= (Vec3Arg inV2)
 Multiply vector with vector. More...
 
JPH_INLINE Vec3operator/= (float inV2)
 Divide vector by float. More...
 
JPH_INLINE Vec3 operator+ (Vec3Arg inV2) const
 Add two float vectors (component wise) More...
 
JPH_INLINE Vec3operator+= (Vec3Arg inV2)
 Add two float vectors (component wise) More...
 
JPH_INLINE Vec3 operator- () const
 Negate. More...
 
JPH_INLINE Vec3 operator- (Vec3Arg inV2) const
 Subtract two float vectors (component wise) More...
 
JPH_INLINE Vec3operator-= (Vec3Arg inV2)
 Add two float vectors (component wise) More...
 
JPH_INLINE Vec3 operator/ (Vec3Arg inV2) const
 Divide (component wise) More...
 
template<uint32 SwizzleX, uint32 SwizzleY, uint32 SwizzleZ>
JPH_INLINE Vec3 Swizzle () const
 Swizzle the elements in inV. More...
 
JPH_INLINE Vec4 SplatX () const
 Replicate the X component to all components. More...
 
JPH_INLINE Vec4 SplatY () const
 Replicate the Y component to all components. More...
 
JPH_INLINE Vec4 SplatZ () const
 Replicate the Z component to all components. More...
 
JPH_INLINE int GetLowestComponentIndex () const
 Get index of component with lowest value. More...
 
JPH_INLINE int GetHighestComponentIndex () const
 Get index of component with highest value. More...
 
JPH_INLINE Vec3 Abs () const
 Return the absolute value of each of the components. More...
 
JPH_INLINE Vec3 Reciprocal () const
 Reciprocal vector (1 / value) for each of the components. More...
 
JPH_INLINE Vec3 Cross (Vec3Arg inV2) const
 Cross product. More...
 
JPH_INLINE Vec3 DotV (Vec3Arg inV2) const
 Dot product, returns the dot product in X, Y and Z components. More...
 
JPH_INLINE Vec4 DotV4 (Vec3Arg inV2) const
 Dot product, returns the dot product in X, Y, Z and W components. More...
 
JPH_INLINE float Dot (Vec3Arg inV2) const
 Dot product. More...
 
JPH_INLINE float LengthSq () const
 Squared length of vector. More...
 
JPH_INLINE float Length () const
 Length of vector. More...
 
JPH_INLINE Vec3 Normalized () const
 Normalize vector. More...
 
JPH_INLINE Vec3 NormalizedOr (Vec3Arg inZeroValue) const
 Normalize vector or return inZeroValue if the length of the vector is zero. More...
 
JPH_INLINE void StoreFloat3 (Float3 *outV) const
 Store 3 floats to memory. More...
 
JPH_INLINE UVec4 ToInt () const
 Convert each component from a float to an int. More...
 
JPH_INLINE UVec4 ReinterpretAsInt () const
 Reinterpret Vec3 as a UVec4 (doesn't change the bits) More...
 
JPH_INLINE float ReduceMin () const
 Get the minimum of X, Y and Z. More...
 
JPH_INLINE float ReduceMax () const
 Get the maximum of X, Y and Z. More...
 
JPH_INLINE Vec3 Sqrt () const
 Component wise square root. More...
 
JPH_INLINE Vec3 GetNormalizedPerpendicular () const
 Get normalized vector that is perpendicular to this vector. More...
 
JPH_INLINE Vec3 GetSign () const
 Get vector that contains the sign of each element (returns 1.0f if positive, -1.0f if negative) More...
 
JPH_INLINE void CheckW () const
 Internal helper function that checks that W is equal to Z, so e.g. dividing by it should not generate div by 0. More...
 
template<uint32 SwizzleX, uint32 SwizzleY, uint32 SwizzleZ>
Vec3 Swizzle () const
 

Static Public Member Functions

static JPH_INLINE Vec3 sZero ()
 Vector with all zeros. More...
 
static JPH_INLINE Vec3 sNaN ()
 Vector with all NaN's. More...
 
static JPH_INLINE Vec3 sAxisX ()
 Vectors with the principal axis. More...
 
static JPH_INLINE Vec3 sAxisY ()
 
static JPH_INLINE Vec3 sAxisZ ()
 
static JPH_INLINE Vec3 sReplicate (float inV)
 Replicate inV across all components. More...
 
static JPH_INLINE Vec3 sLoadFloat3Unsafe (const Float3 &inV)
 Load 3 floats from memory (reads 32 bits extra which it doesn't use) More...
 
static JPH_INLINE Vec3 sMin (Vec3Arg inV1, Vec3Arg inV2)
 Return the minimum value of each of the components. More...
 
static JPH_INLINE Vec3 sMax (Vec3Arg inV1, Vec3Arg inV2)
 Return the maximum of each of the components. More...
 
static JPH_INLINE Vec3 sClamp (Vec3Arg inV, Vec3Arg inMin, Vec3Arg inMax)
 Clamp a vector between min and max (component wise) More...
 
static JPH_INLINE UVec4 sEquals (Vec3Arg inV1, Vec3Arg inV2)
 Equals (component wise) More...
 
static JPH_INLINE UVec4 sLess (Vec3Arg inV1, Vec3Arg inV2)
 Less than (component wise) More...
 
static JPH_INLINE UVec4 sLessOrEqual (Vec3Arg inV1, Vec3Arg inV2)
 Less than or equal (component wise) More...
 
static JPH_INLINE UVec4 sGreater (Vec3Arg inV1, Vec3Arg inV2)
 Greater than (component wise) More...
 
static JPH_INLINE UVec4 sGreaterOrEqual (Vec3Arg inV1, Vec3Arg inV2)
 Greater than or equal (component wise) More...
 
static JPH_INLINE Vec3 sFusedMultiplyAdd (Vec3Arg inMul1, Vec3Arg inMul2, Vec3Arg inAdd)
 Calculates inMul1 * inMul2 + inAdd. More...
 
static JPH_INLINE Vec3 sSelect (Vec3Arg inV1, Vec3Arg inV2, UVec4Arg inControl)
 Component wise select, returns inV1 when highest bit of inControl = 0 and inV2 when highest bit of inControl = 1. More...
 
static JPH_INLINE Vec3 sOr (Vec3Arg inV1, Vec3Arg inV2)
 Logical or (component wise) More...
 
static JPH_INLINE Vec3 sXor (Vec3Arg inV1, Vec3Arg inV2)
 Logical xor (component wise) More...
 
static JPH_INLINE Vec3 sAnd (Vec3Arg inV1, Vec3Arg inV2)
 Logical and (component wise) More...
 
static JPH_INLINE Vec3 sUnitSpherical (float inTheta, float inPhi)
 
template<class Random >
static Vec3 sRandom (Random &inRandom)
 Get random unit vector. More...
 
static JPH_INLINE Type sFixW (Type inValue)
 Internal helper function that ensures that the Z component is replicated to the W component to prevent divisions by zero. More...
 

Public Attributes

union {
   Type   mValue
 
   float   mF32 [4]
 
}; 
 

Static Public Attributes

static JPH_EXPORT const std::vector< Vec3sUnitSphere
 A set of vectors uniformly spanning the surface of a unit sphere, usable for debug purposes. More...
 

Friends

JPH_INLINE Vec3 operator* (float inV1, Vec3Arg inV2)
 Multiply vector with float. More...
 
ostream & operator<< (ostream &inStream, Vec3Arg inV)
 To String. More...
 

Detailed Description

3 component vector (stored as 4 vectors). Note that we keep the 4th component the same as the 3rd component to avoid divisions by zero when JPH_FLOATING_POINT_EXCEPTIONS_ENABLED defined

Member Typedef Documentation

◆ ArgType

◆ Type

Constructor & Destructor Documentation

◆ Vec3() [1/6]

Vec3::Vec3 ( )
default

Constructor.

Intentionally not initialized for performance reasons

◆ Vec3() [2/6]

Vec3::Vec3 ( const Vec3 inRHS)
default

◆ Vec3() [3/6]

Vec3::Vec3 ( Vec4Arg  inRHS)
explicit

◆ Vec3() [4/6]

JPH_INLINE Vec3::Vec3 ( Type  inRHS)
inline

◆ Vec3() [5/6]

Vec3::Vec3 ( const Float3 inV)
explicit

Load 3 floats from memory.

◆ Vec3() [6/6]

Vec3::Vec3 ( float  inX,
float  inY,
float  inZ 
)

Create a vector from 3 components.

Member Function Documentation

◆ Abs()

Vec3 Vec3::Abs ( ) const

Return the absolute value of each of the components.

◆ CheckW()

JPH_INLINE void Vec3::CheckW ( ) const

Internal helper function that checks that W is equal to Z, so e.g. dividing by it should not generate div by 0.

◆ Cross()

Vec3 Vec3::Cross ( Vec3Arg  inV2) const

Cross product.

◆ Dot()

float Vec3::Dot ( Vec3Arg  inV2) const

Dot product.

◆ DotV()

Vec3 Vec3::DotV ( Vec3Arg  inV2) const

Dot product, returns the dot product in X, Y and Z components.

◆ DotV4()

Vec4 Vec3::DotV4 ( Vec3Arg  inV2) const

Dot product, returns the dot product in X, Y, Z and W components.

◆ GetHighestComponentIndex()

int Vec3::GetHighestComponentIndex ( ) const

Get index of component with highest value.

◆ GetLowestComponentIndex()

int Vec3::GetLowestComponentIndex ( ) const

Get index of component with lowest value.

◆ GetNormalizedPerpendicular()

Vec3 Vec3::GetNormalizedPerpendicular ( ) const

Get normalized vector that is perpendicular to this vector.

◆ GetSign()

Vec3 Vec3::GetSign ( ) const

Get vector that contains the sign of each element (returns 1.0f if positive, -1.0f if negative)

◆ GetX()

JPH_INLINE float Vec3::GetX ( ) const
inline

Get individual components.

◆ GetY()

JPH_INLINE float Vec3::GetY ( ) const
inline

◆ GetZ()

JPH_INLINE float Vec3::GetZ ( ) const
inline

◆ IsClose()

bool Vec3::IsClose ( Vec3Arg  inV2,
float  inMaxDistSq = 1.0e-12f 
) const

Test if two vectors are close.

◆ IsNaN()

bool Vec3::IsNaN ( ) const

Test if vector contains NaN elements.

◆ IsNearZero()

bool Vec3::IsNearZero ( float  inMaxDistSq = 1.0e-12f) const

Test if vector is near zero.

◆ IsNormalized()

bool Vec3::IsNormalized ( float  inTolerance = 1.0e-6f) const

Test if vector is normalized.

◆ Length()

float Vec3::Length ( ) const

Length of vector.

◆ LengthSq()

float Vec3::LengthSq ( ) const

Squared length of vector.

◆ Normalized()

Vec3 Vec3::Normalized ( ) const

Normalize vector.

◆ NormalizedOr()

Vec3 Vec3::NormalizedOr ( Vec3Arg  inZeroValue) const

Normalize vector or return inZeroValue if the length of the vector is zero.

◆ operator!=()

JPH_INLINE bool Vec3::operator!= ( Vec3Arg  inV2) const
inline

◆ operator*() [1/2]

Vec3 Vec3::operator* ( float  inV2) const

Multiply vector with float.

◆ operator*() [2/2]

Vec3 Vec3::operator* ( Vec3Arg  inV2) const

Multiply two float vectors (component wise)

◆ operator*=() [1/2]

Vec3 & Vec3::operator*= ( float  inV2)

Multiply vector with float.

◆ operator*=() [2/2]

Vec3 & Vec3::operator*= ( Vec3Arg  inV2)

Multiply vector with vector.

◆ operator+()

Vec3 Vec3::operator+ ( Vec3Arg  inV2) const

Add two float vectors (component wise)

◆ operator+=()

Vec3 & Vec3::operator+= ( Vec3Arg  inV2)

Add two float vectors (component wise)

◆ operator-() [1/2]

Vec3 Vec3::operator- ( ) const

Negate.

◆ operator-() [2/2]

Vec3 Vec3::operator- ( Vec3Arg  inV2) const

Subtract two float vectors (component wise)

◆ operator-=()

Vec3 & Vec3::operator-= ( Vec3Arg  inV2)

Add two float vectors (component wise)

◆ operator/() [1/2]

Vec3 Vec3::operator/ ( float  inV2) const

Divide vector by float.

◆ operator/() [2/2]

Vec3 Vec3::operator/ ( Vec3Arg  inV2) const

Divide (component wise)

◆ operator/=()

Vec3 & Vec3::operator/= ( float  inV2)

Divide vector by float.

◆ operator=()

Vec3 & Vec3::operator= ( const Vec3 inRHS)
default

◆ operator==()

bool Vec3::operator== ( Vec3Arg  inV2) const

Comparison.

◆ operator[]()

JPH_INLINE float Vec3::operator[] ( uint  inCoordinate) const
inline

Get float component by index.

◆ Reciprocal()

Vec3 Vec3::Reciprocal ( ) const

Reciprocal vector (1 / value) for each of the components.

◆ ReduceMax()

float Vec3::ReduceMax ( ) const

Get the maximum of X, Y and Z.

◆ ReduceMin()

float Vec3::ReduceMin ( ) const

Get the minimum of X, Y and Z.

◆ ReinterpretAsInt()

UVec4 Vec3::ReinterpretAsInt ( ) const

Reinterpret Vec3 as a UVec4 (doesn't change the bits)

◆ sAnd()

Vec3 Vec3::sAnd ( Vec3Arg  inV1,
Vec3Arg  inV2 
)
static

Logical and (component wise)

◆ sAxisX()

static JPH_INLINE Vec3 Vec3::sAxisX ( )
inlinestatic

Vectors with the principal axis.

◆ sAxisY()

static JPH_INLINE Vec3 Vec3::sAxisY ( )
inlinestatic

◆ sAxisZ()

static JPH_INLINE Vec3 Vec3::sAxisZ ( )
inlinestatic

◆ sClamp()

Vec3 Vec3::sClamp ( Vec3Arg  inV,
Vec3Arg  inMin,
Vec3Arg  inMax 
)
static

Clamp a vector between min and max (component wise)

◆ sEquals()

UVec4 Vec3::sEquals ( Vec3Arg  inV1,
Vec3Arg  inV2 
)
static

Equals (component wise)

◆ Set()

JPH_INLINE void Vec3::Set ( float  inX,
float  inY,
float  inZ 
)
inline

Set all components.

◆ SetComponent()

JPH_INLINE void Vec3::SetComponent ( uint  inCoordinate,
float  inValue 
)
inline

Set float component by index.

◆ SetX()

JPH_INLINE void Vec3::SetX ( float  inX)
inline

Set individual components.

◆ SetY()

JPH_INLINE void Vec3::SetY ( float  inY)
inline

◆ SetZ()

JPH_INLINE void Vec3::SetZ ( float  inZ)
inline

◆ sFixW()

static JPH_INLINE Type Vec3::sFixW ( Type  inValue)
static

Internal helper function that ensures that the Z component is replicated to the W component to prevent divisions by zero.

◆ sFusedMultiplyAdd()

Vec3 Vec3::sFusedMultiplyAdd ( Vec3Arg  inMul1,
Vec3Arg  inMul2,
Vec3Arg  inAdd 
)
static

Calculates inMul1 * inMul2 + inAdd.

◆ sGreater()

UVec4 Vec3::sGreater ( Vec3Arg  inV1,
Vec3Arg  inV2 
)
static

Greater than (component wise)

◆ sGreaterOrEqual()

UVec4 Vec3::sGreaterOrEqual ( Vec3Arg  inV1,
Vec3Arg  inV2 
)
static

Greater than or equal (component wise)

◆ sLess()

UVec4 Vec3::sLess ( Vec3Arg  inV1,
Vec3Arg  inV2 
)
static

Less than (component wise)

◆ sLessOrEqual()

UVec4 Vec3::sLessOrEqual ( Vec3Arg  inV1,
Vec3Arg  inV2 
)
static

Less than or equal (component wise)

◆ sLoadFloat3Unsafe()

Vec3 Vec3::sLoadFloat3Unsafe ( const Float3 inV)
static

Load 3 floats from memory (reads 32 bits extra which it doesn't use)

◆ sMax()

Vec3 Vec3::sMax ( Vec3Arg  inV1,
Vec3Arg  inV2 
)
static

Return the maximum of each of the components.

◆ sMin()

Vec3 Vec3::sMin ( Vec3Arg  inV1,
Vec3Arg  inV2 
)
static

Return the minimum value of each of the components.

◆ sNaN()

Vec3 Vec3::sNaN ( )
static

Vector with all NaN's.

◆ sOr()

Vec3 Vec3::sOr ( Vec3Arg  inV1,
Vec3Arg  inV2 
)
static

Logical or (component wise)

◆ SplatX()

Vec4 Vec3::SplatX ( ) const

Replicate the X component to all components.

◆ SplatY()

Vec4 Vec3::SplatY ( ) const

Replicate the Y component to all components.

◆ SplatZ()

Vec4 Vec3::SplatZ ( ) const

Replicate the Z component to all components.

◆ Sqrt()

Vec3 Vec3::Sqrt ( ) const

Component wise square root.

◆ sRandom()

template<class Random >
Vec3 Vec3::sRandom ( Random &  inRandom)
inlinestatic

Get random unit vector.

◆ sReplicate()

Vec3 Vec3::sReplicate ( float  inV)
static

Replicate inV across all components.

◆ sSelect()

Vec3 Vec3::sSelect ( Vec3Arg  inV1,
Vec3Arg  inV2,
UVec4Arg  inControl 
)
static

Component wise select, returns inV1 when highest bit of inControl = 0 and inV2 when highest bit of inControl = 1.

◆ StoreFloat3()

void Vec3::StoreFloat3 ( Float3 outV) const

Store 3 floats to memory.

◆ sUnitSpherical()

Vec3 Vec3::sUnitSpherical ( float  inTheta,
float  inPhi 
)
static

Get unit vector given spherical coordinates inTheta \(\in [0, \pi]\) is angle between vector and z-axis inPhi \(\in [0, 2 \pi]\) is the angle in the xy-plane starting from the x axis and rotating counter clockwise around the z-axis

◆ Swizzle() [1/2]

template<uint32 SwizzleX, uint32 SwizzleY, uint32 SwizzleZ>
JPH_INLINE Vec3 Vec3::Swizzle ( ) const

Swizzle the elements in inV.

◆ Swizzle() [2/2]

template<uint32 SwizzleX, uint32 SwizzleY, uint32 SwizzleZ>
Vec3 Vec3::Swizzle ( ) const

◆ sXor()

Vec3 Vec3::sXor ( Vec3Arg  inV1,
Vec3Arg  inV2 
)
static

Logical xor (component wise)

◆ sZero()

Vec3 Vec3::sZero ( )
static

Vector with all zeros.

◆ ToInt()

UVec4 Vec3::ToInt ( ) const

Convert each component from a float to an int.

Friends And Related Function Documentation

◆ operator*

JPH_INLINE Vec3 operator* ( float  inV1,
Vec3Arg  inV2 
)
friend

Multiply vector with float.

◆ operator<<

ostream & operator<< ( ostream &  inStream,
Vec3Arg  inV 
)
friend

To String.

Member Data Documentation

◆ 

union { ... } Vec3::@17

◆ mF32

float Vec3::mF32[4]

◆ mValue

Type Vec3::mValue

◆ sUnitSphere

const std::vector< Vec3 > Vec3::sUnitSphere
static
Initial value:
= []() {
const int level = 3;
std::unordered_set<Vec3> verts;
verts.insert(Vec3::sAxisX());
verts.insert(-Vec3::sAxisX());
verts.insert(Vec3::sAxisY());
verts.insert(-Vec3::sAxisY());
verts.insert(Vec3::sAxisZ());
verts.insert(-Vec3::sAxisZ());
sCreateVertices(verts, Vec3::sAxisX(), Vec3::sAxisY(), Vec3::sAxisZ(), level);
sCreateVertices(verts, -Vec3::sAxisX(), Vec3::sAxisY(), Vec3::sAxisZ(), level);
sCreateVertices(verts, Vec3::sAxisX(), -Vec3::sAxisY(), Vec3::sAxisZ(), level);
sCreateVertices(verts, -Vec3::sAxisX(), -Vec3::sAxisY(), Vec3::sAxisZ(), level);
sCreateVertices(verts, Vec3::sAxisX(), Vec3::sAxisY(), -Vec3::sAxisZ(), level);
sCreateVertices(verts, -Vec3::sAxisX(), Vec3::sAxisY(), -Vec3::sAxisZ(), level);
sCreateVertices(verts, Vec3::sAxisX(), -Vec3::sAxisY(), -Vec3::sAxisZ(), level);
sCreateVertices(verts, -Vec3::sAxisX(), -Vec3::sAxisY(), -Vec3::sAxisZ(), level);
return std::vector<Vec3>(verts.begin(), verts.end());
}()
static JPH_INLINE Vec3 sAxisX()
Vectors with the principal axis.
Definition: Vec3.h:52
static JPH_INLINE Vec3 sAxisY()
Definition: Vec3.h:53
static JPH_INLINE Vec3 sAxisZ()
Definition: Vec3.h:54

A set of vectors uniformly spanning the surface of a unit sphere, usable for debug purposes.


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