FdkBaseLib 2.1.1
All Classes Namespaces Files Functions Variables Enumerations Enumerator Pages
fdk::Vec3< T > Class Template Reference

#include <Vec3.h>

Public Types

using value_type = T
 
using reference = T &
 
using const_reference = const T &
 

Public Member Functions

 Vec3 ()=default
 Default constructor leaves garbage in contents.
 
template<typename S >
 Vec3 (const Vec3< S > &b)
 Copy constructor supports type conversion.
 
template<typename S >
 Vec3 (const Vec3< S > &v, float n)
 Constructor that normalizes vector after copy if 'n' is > 0.
 
 Vec3 (T a)
 Constructor that sets all components to a single value.
 
 Vec3 (T a, T b)
 Constructors that set separate components, with default z=0.
 
 Vec3 (T a, T b, T c)
 
template<typename S >
 Vec3 (S *v)
 Constructor from an array of 3 numbers.
 
template<typename S >
 Vec3 (const S *v)
 
 Vec3 (const Vec2< T > &v, T vz=(T) 0)
 
 operator Vec3< fdk::half > () const
 Returns value as a specific type:
 
 operator Vec3< float > () const
 
 operator Vec3< double > () const
 
 operator Vec3< int > () const
 
Vec3< fdk::halfasVec3h () const
 
Vec3< float > asVec3f () const
 
Vec3< double > asVec3d () const
 
Vec3< int > asVec3i () const
 
T & operator[] (int n)
 
const T & operator[] (int n) const
 
T * array ()
 Returns a pointer to the first element.
 
const T * array () const
 
Vec2< T > xy () const
 
void set (T d)
 Set all components to a single value.
 
void set (T a, T b, T c)
 Set all components.
 
void setToZero ()
 Set components to 0.
 
void setToOne ()
 Set components to 1.
 
void clear ()
 Type-specific clear. Set all components to 0.
 
void append (fdk::Hash &hash) const
 Add this to a fdk::Hash object.
 
template<typename S >
Vec3 operator* (const Mat4< S > &m) const
 
template<typename S >
Vec3operator*= (const Mat4< S > &m)
 
template<typename S , std::enable_if_t< fdk::is_arithmetic< S >, bool > = true>
Vec3 operator* (S d) const
 
Vec3 operator* (const Vec3 &v) const
 
template<typename S , std::enable_if_t< fdk::is_arithmetic< S >, bool > = true>
Vec3operator*= (S d)
 
Vec3operator*= (const Vec3 &v)
 
template<typename S , std::enable_if_t< fdk::is_arithmetic< S >, bool > = true>
Vec3 operator/ (S d) const
 
Vec3 operator/ (const Vec3 &v) const
 
template<typename S , std::enable_if_t< fdk::is_arithmetic< S >, bool > = true>
Vec3operator/= (S d)
 
Vec3operator/= (const Vec3 &v)
 
template<typename S , std::enable_if_t< fdk::is_arithmetic< S >, bool > = true>
Vec3 operator+ (S d) const
 
Vec3 operator+ (const Vec3 &v) const
 
template<typename S , std::enable_if_t< fdk::is_arithmetic< S >, bool > = true>
Vec3operator+= (S d)
 
Vec3operator+= (const Vec3 &v)
 
template<typename S , std::enable_if_t< fdk::is_arithmetic< S >, bool > = true>
Vec3 operator- (S d) const
 
Vec3 operator- (const Vec3 &v) const
 
template<typename S , std::enable_if_t< fdk::is_arithmetic< S >, bool > = true>
Vec3operator-= (S d)
 
Vec3operator-= (const Vec3 &v)
 
Vec3 operator- () const
 
void negate ()
 
bool operator== (const Vec3 &v) const
 
bool operator!= (const Vec3 &v) const
 
template<typename S >
bool operator== (S d) const
 
template<typename S >
bool operator!= (S d) const
 
bool operator< (const Vec3 &v) const
 Fairly arbitrary operator so you can store these in ordered arrays.
 
length () const
 Also known as the absolute value or magnitude of the vector.
 
lengthSquared () const
 Same as this dot this, length() squared.
 
distanceBetween (const Vec3 &v) const
 Same as (this-v).length()
 
distanceSquared (const Vec3 &v) const
 Same as (this-v).lengthSquared()
 
distanceFromPlane (T A, T B, T C, T D) const
 Return the scalar distance to the plane defined by ABCD.
 
dot (const Vec3 &v) const
 Dot product. Twice the area of the triangle between the vectors.
 
Vec3 cross (const Vec3 &v) const
 Cross product. Returns a vector at right angles to the vectors.
 
normalize ()
 Change the vector to be unit length. Returns the original length.
 
Vec3 normalized () const
 
Vec3 reflect (const Vec3 &N) const
 Return a vector of this one reflected around a normal vector.
 
void faceForward (const Vec3 &N)
 Negate (flip) vector if it points in the opposite direction of N.
 
minimumComponent () const
 Returns the minimum element.
 
Vec3 minimum (const Vec3 &v) const
 
maximumComponent () const
 Returns the maximum element.
 
Vec3 maximum (const Vec3 &v) const
 
largestAxis () const
 Returns the absolute value of the largest element.
 
template<typename S >
Vec3< T > interpolateTo (const Vec3< T > &b, S t) const
 Linear-interpolate between this Vec3 and another at t, where t=0..1.
 
template<typename S >
Vec3< T > lerpClampedTo (const Vec3< T > &b, S t) const
 
template<typename S >
Vec3< T > lerpUnclapmedTo (const Vec3< T > &b, S t) const
 
Vec3 inverted () const
 
template<typename S >
Vec3 clamped (S min, S max) const
 
Vec3 clamped () const
 
void toRadians ()
 Convert to/from radians/degrees.
 
Vec3 asRadians () const
 
void toDegrees ()
 
Vec3 asDegrees () const
 
bool isZero () const
 
bool notZero () const
 
bool greaterThanZero () const
 
void roundIfNearlyZero (T threshold=std::numeric_limits< T >::epsilon())
 Round off each element if nearly one or zero within the type's epsilon default or user-provided threshold.
 
void roundIfNearlyOne (T threshold=std::numeric_limits< T >::epsilon())
 
void orientAroundNormal (Vec3 N, bool auto_flip=true)
 
void rotateAroundAxis (T angle, const Vec3 &axis)
 Rotate a vector by an angle around a center axis vector.
 
template<typename S >
Vec3< T > operator* (const Mat4< S > &m) const
 
template<typename S >
Vec3< T > & operator*= (const Mat4< S > &m)
 
template<typename S , std::enable_if_t< fdk::is_arithmetic< S >, bool > >
Vec3< T > & operator*= (S d)
 
template<typename S , std::enable_if_t< fdk::is_arithmetic< S >, bool > >
Vec3< T > & operator/= (S d)
 
template<typename S , std::enable_if_t< fdk::is_arithmetic< S >, bool > >
Vec3< T > & operator+= (S d)
 
template<typename S , std::enable_if_t< fdk::is_arithmetic< S >, bool > >
Vec3< T > & operator-= (S d)
 

Public Attributes

x
 
y
 
z
 the data
 

Static Public Attributes

static constexpr uint8_t kNumElements = 3
 
static constexpr uint8_t X = 0
 
static constexpr uint8_t Y = 1
 
static constexpr uint8_t Z = 2
 
static const Vec3 XAxis
 
static const Vec3 YAxis
 
static const Vec3 ZAxis
 

Detailed Description

template<typename T>
class fdk::Vec3< T >

3-component vector

Member Function Documentation

◆ normalized()

template<typename T >
Vec3< T > fdk::Vec3< T >::normalized
inline

Returns the normalized unit vector form of this vector. If this vector is null, then a null vector is returned.

◆ orientAroundNormal()

template<typename T >
void fdk::Vec3< T >::orientAroundNormal ( Vec3< T >  N,
bool  auto_flip = true 
)
inline

Orient vector relative to a normal's frame. The +Z axis of this vector is rotated to line up with the normal. If N.z is negative then the up orientation of the resulting vector is flipped to avoid the degenerate case where N.z gets near -1.0 and there's no rotation solution.

References fdk::Vec3< T >::z.

◆ rotateAroundAxis()

template<typename T >
void fdk::Vec3< T >::rotateAroundAxis ( angle,
const Vec3< T > &  axis 
)
inline

Rotate a vector by an angle around a center axis vector.

Rotate a vector by an angle around a center axis vector. ex. Nnew = rotateAroundAxis(dir, -acosf(N.z), Vec3f(N.y, -N.x, 0.0f));

References fdk::Vec3< T >::z.



©2024 The Foundry Visionmongers, Ltd. All Rights Reserved.
www.foundry.com