CGVIS Utils
Loading...
Searching...
No Matches
Vec3t< T > Union Template Reference

#include <Vec3.h>

Public Member Functions

 Vec3t ()
 Default-construct to (0,0,0).
 Vec3t (T x, T y, T z)
 Construct from three component values.
 Vec3t (const Vec3t &other)
 Copy-construct from the same type.
 Vec3t (const Vec2t< T > &other, T z)
 Construct from a 2D vector and a z value.
template<typename U>
 Vec3t (const Vec3t< U > &other)
 Explicitly convert from another Vec3t with different component type.
template<typename U>
 Vec3t (const Vec2t< U > &other, T z)
 Explicitly convert from a 2D vector of a different type and a z value.
const std::string toString () const
 String representation "[x, y, z]".
Vec3t operator+ (const Vec3t &val) const
 Component-wise addition.
Vec3t operator- (const Vec3t &val) const
 Component-wise subtraction.
Vec3t operator* (const Vec3t &val) const
 Component-wise multiplication.
Vec3t operator/ (const Vec3t &val) const
 Component-wise division.
Vec3t operator* (const T &val) const
 Scalar multiplication.
Vec3t operator/ (const T &val) const
 Scalar division.
Vec3t operator+ (const T &val) const
 Add scalar to all components.
Vec3t operator- (const T &val) const
 Subtract scalar from all components.
bool operator== (const Vec3t &other) const
 Equality comparison (component-wise equality).
bool operator!= (const Vec3t &other) const
 Inequality comparison (component-wise inequality).
T length () const
 Euclidean length (magnitude).
T sqlength () const
 Squared length (avoids sqrt).
 operator T* (void)
 Implicit pointer conversion to raw component storage.
 operator const T * (void) const
 Implicit pointer conversion to raw component storage (const).

Static Public Member Functions

static float dot (const Vec3t &a, const Vec3t &b)
 Dot product of two vectors.
static Vec3t cross (const Vec3t &a, const Vec3t &b)
 Cross product of two vectors.
static Vec3t normalize (const Vec3t &a)
 Return the normalized (unit-length) version of a vector.
static Vec3t reflect (const Vec3t &a, const Vec3t &n)
 Reflect a vector about a unit normal.
static std::optional< Vec3t > refract (const Vec3t &a, const Vec3t &normal, const T IOR)
 Refract a vector through a surface with index-of-refraction ratio.
static Vec3t minV (const Vec3t &a, const Vec3t &b)
 Component-wise minimum of two vectors.
static Vec3t maxV (const Vec3t &a, const Vec3t &b)
 Component-wise maximum of two vectors.
static Vec3t< float > random ()
 Create a vector with components sampled from [0,1).
static Vec3t< float > randomPointInSphere ()
 Uniform random point inside the unit sphere.
static Vec3t< float > randomPointInHemisphere ()
 Uniform random point inside the upper unit hemisphere (z>=0).
static Vec3t< float > randomPointInDisc ()
 Uniform random point inside the unit disc on the xy-plane.
static Vec3t< float > randomUnitVector ()
 Uniform random unit vector on the sphere.
static Vec3t< float > clamp (const Vec3t &val, float minVal, float maxVal)
 Clamp each component to [minVal, maxVal].

Public Attributes

std::array< T, 3 > e
 Component storage and named aliases.
struct { 
   T   x 
   T   y 
   T   z 
}; 
 Cartesian aliases for components.
struct { 
   T   r 
   T   g 
   T   b 
}; 
 Color aliases for components.
Vec2t< T > xy
 2D view of the first two components.

Constructor & Destructor Documentation

◆ Vec3t() [1/6]

template<typename T>
Vec3t< T >::Vec3t ( )
inline

Default-construct to (0,0,0).

◆ Vec3t() [2/6]

template<typename T>
Vec3t< T >::Vec3t ( T x,
T y,
T z )
inline

Construct from three component values.

Parameters
xFirst component.
ySecond component.
zThird component.

◆ Vec3t() [3/6]

template<typename T>
Vec3t< T >::Vec3t ( const Vec3t< T > & other)
inline

Copy-construct from the same type.

Parameters
otherSource vector to copy.

◆ Vec3t() [4/6]

template<typename T>
Vec3t< T >::Vec3t ( const Vec2t< T > & other,
T z )
inline

Construct from a 2D vector and a z value.

Parameters
otherSource 2D vector for x and y.
zThird component.

◆ Vec3t() [5/6]

template<typename T>
template<typename U>
Vec3t< T >::Vec3t ( const Vec3t< U > & other)
inlineexplicit

Explicitly convert from another Vec3t with different component type.

Template Parameters
USource component type.
Parameters
otherSource vector to convert from.

◆ Vec3t() [6/6]

template<typename T>
template<typename U>
Vec3t< T >::Vec3t ( const Vec2t< U > & other,
T z )
inlineexplicit

Explicitly convert from a 2D vector of a different type and a z value.

Template Parameters
USource component type.
Parameters
otherSource 2D vector for x and y.
zThird component.

Member Function Documentation

◆ clamp()

template<typename T>
Vec3t< float > Vec3t< T >::clamp ( const Vec3t< T > & val,
float minVal,
float maxVal )
inlinestatic

Clamp each component to [minVal, maxVal].

Parameters
valInput vector.
minValLower bound.
maxValUpper bound.
Returns
New vector with components clamped to the given range.

◆ cross()

template<typename T>
Vec3t Vec3t< T >::cross ( const Vec3t< T > & a,
const Vec3t< T > & b )
inlinestatic

Cross product of two vectors.

Parameters
aFirst vector.
bSecond vector.
Returns
a × b.
Here is the caller graph for this function:

◆ dot()

template<typename T>
float Vec3t< T >::dot ( const Vec3t< T > & a,
const Vec3t< T > & b )
inlinestatic

Dot product of two vectors.

Parameters
aFirst vector.
bSecond vector.
Returns
a·b.
Here is the caller graph for this function:

◆ length()

template<typename T>
T Vec3t< T >::length ( ) const
inline

Euclidean length (magnitude).

Returns
sqrt(x*x + y*y + z*z).
Here is the caller graph for this function:

◆ maxV()

template<typename T>
Vec3t Vec3t< T >::maxV ( const Vec3t< T > & a,
const Vec3t< T > & b )
inlinestatic

Component-wise maximum of two vectors.

Parameters
aFirst vector.
bSecond vector.
Returns
{max(a.x,b.x), max(a.y,b.y), max(a.z,b.z)}.

◆ minV()

template<typename T>
Vec3t Vec3t< T >::minV ( const Vec3t< T > & a,
const Vec3t< T > & b )
inlinestatic

Component-wise minimum of two vectors.

Parameters
aFirst vector.
bSecond vector.
Returns
{min(a.x,b.x), min(a.y,b.y), min(a.z,b.z)}.

◆ normalize()

template<typename T>
Vec3t Vec3t< T >::normalize ( const Vec3t< T > & a)
inlinestatic

Return the normalized (unit-length) version of a vector.

Parameters
aInput vector.
Returns
a / |a| if |a| != 0, otherwise (0,0,0).
Here is the caller graph for this function:

◆ operator const T *()

template<typename T>
Vec3t< T >::operator const T * ( void ) const
inline

Implicit pointer conversion to raw component storage (const).

Returns
Pointer to first component (const overload).

◆ operator T*()

template<typename T>
Vec3t< T >::operator T* ( void )
inline

Implicit pointer conversion to raw component storage.

Returns
Pointer to first component (non-const overload).
Warning
Raw pointer exposes internal layout; use with care.

◆ operator!=()

template<typename T>
bool Vec3t< T >::operator!= ( const Vec3t< T > & other) const
inline

Inequality comparison (component-wise inequality).

Parameters
otherVector to compare against.
Returns
True if any component differs.

◆ operator*() [1/2]

template<typename T>
Vec3t Vec3t< T >::operator* ( const T & val) const
inline

Scalar multiplication.

Parameters
valScalar factor.
Returns
Result of this * val.

◆ operator*() [2/2]

template<typename T>
Vec3t Vec3t< T >::operator* ( const Vec3t< T > & val) const
inline

Component-wise multiplication.

Parameters
valVector to multiply component-wise.
Returns
Result of this * val.

◆ operator+() [1/2]

template<typename T>
Vec3t Vec3t< T >::operator+ ( const T & val) const
inline

Add scalar to all components.

Parameters
valScalar to add.
Returns
Result of this + val.

◆ operator+() [2/2]

template<typename T>
Vec3t Vec3t< T >::operator+ ( const Vec3t< T > & val) const
inline

Component-wise addition.

Parameters
valVector to add.
Returns
Result of this + val.

◆ operator-() [1/2]

template<typename T>
Vec3t Vec3t< T >::operator- ( const T & val) const
inline

Subtract scalar from all components.

Parameters
valScalar to subtract.
Returns
Result of this - val.

◆ operator-() [2/2]

template<typename T>
Vec3t Vec3t< T >::operator- ( const Vec3t< T > & val) const
inline

Component-wise subtraction.

Parameters
valVector to subtract.
Returns
Result of this - val.

◆ operator/() [1/2]

template<typename T>
Vec3t Vec3t< T >::operator/ ( const T & val) const
inline

Scalar division.

Parameters
valScalar divisor.
Returns
Result of this / val.

◆ operator/() [2/2]

template<typename T>
Vec3t Vec3t< T >::operator/ ( const Vec3t< T > & val) const
inline

Component-wise division.

Parameters
valVector to divide by component-wise.
Returns
Result of this / val.

◆ operator==()

template<typename T>
bool Vec3t< T >::operator== ( const Vec3t< T > & other) const
inline

Equality comparison (component-wise equality).

Parameters
otherVector to compare against.
Returns
True iff all components are equal.

◆ random()

template<typename T>
Vec3t< float > Vec3t< T >::random ( )
inlinestatic

Create a vector with components sampled from [0,1).

Returns
Random vector (x,y,z) in [0,1) each.
Note
Depends on a global/namespace-scope RNG named staticRand provided by Rand.h .

◆ randomPointInDisc()

template<typename T>
Vec3t< float > Vec3t< T >::randomPointInDisc ( )
inlinestatic

Uniform random point inside the unit disc on the xy-plane.

Returns
Random point with x^2 + y^2 <= 1 and z = 0.

◆ randomPointInHemisphere()

template<typename T>
Vec3t< float > Vec3t< T >::randomPointInHemisphere ( )
inlinestatic

Uniform random point inside the upper unit hemisphere (z>=0).

Returns
Random point with |p| <= 1 and z >= 0.

◆ randomPointInSphere()

template<typename T>
Vec3t< float > Vec3t< T >::randomPointInSphere ( )
inlinestatic

Uniform random point inside the unit sphere.

Returns
Random point with |p| <= 1.

◆ randomUnitVector()

template<typename T>
Vec3t< float > Vec3t< T >::randomUnitVector ( )
inlinestatic

Uniform random unit vector on the sphere.

Returns
Unit-length random direction.

◆ reflect()

template<typename T>
Vec3t Vec3t< T >::reflect ( const Vec3t< T > & a,
const Vec3t< T > & n )
inlinestatic

Reflect a vector about a unit normal.

Parameters
aIncident vector.
nUnit surface normal (assumed normalized).
Returns
Reflected vector r = a - 2(n·a)n.

◆ refract()

template<typename T>
std::optional< Vec3t > Vec3t< T >::refract ( const Vec3t< T > & a,
const Vec3t< T > & normal,
const T IOR )
inlinestatic

Refract a vector through a surface with index-of-refraction ratio.

Computes the transmitted direction using Snell's law. If total internal reflection occurs, returns an empty optional.

Parameters
aIncident vector (assumed pointing towards the surface).
normalSurface normal (assumed normalized, pointing away from surface).
IORIndex-of-refraction of the material (n_material / n_outside).
Returns
Transmitted direction if refraction is possible; otherwise empty.

◆ sqlength()

template<typename T>
T Vec3t< T >::sqlength ( ) const
inline

Squared length (avoids sqrt).

Returns
x*x + y*y + z*z.
Here is the caller graph for this function:

◆ toString()

template<typename T>
const std::string Vec3t< T >::toString ( ) const
inline

String representation "[x, y, z]".

Returns
A new std::string describing the vector.
Here is the caller graph for this function:

Member Data Documentation

◆ [struct]

struct { ... } Vec3t< T >

Cartesian aliases for components.

◆ [struct]

struct { ... } Vec3t< T >

Color aliases for components.

◆ b

template<typename T>
T Vec3t< T >::b

◆ e

template<typename T>
std::array<T, 3> Vec3t< T >::e

Component storage and named aliases.

Indexed access: e[0], e[1], e[2].

◆ g

template<typename T>
T Vec3t< T >::g

◆ r

template<typename T>
T Vec3t< T >::r

◆ x

template<typename T>
T Vec3t< T >::x

◆ xy

template<typename T>
Vec2t<T> Vec3t< T >::xy

2D view of the first two components.

◆ y

template<typename T>
T Vec3t< T >::y

◆ z

template<typename T>
T Vec3t< T >::z

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