CGVIS Utils
Loading...
Searching...
No Matches
Vec3.h File Reference

3D vector template with arithmetic, geometry helpers, and RNG utilities. More...

#include <ostream>
#include <sstream>
#include <string>
#include <array>
#include <cmath>
#include <optional>
#include "Rand.h"
#include "Vec2.h"
Include dependency graph for Vec3.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

union  Vec3t< T >

Typedefs

typedef Vec3t< float > Vec3
 3D float vector (x,y,z).
typedef Vec3t< int32_t > Vec3i
 3D 32-bit signed integer vector (x,y,z).
typedef Vec3t< uint32_t > Vec3ui
 3D 32-bit unsigned integer vector (x,y,z).

Functions

template<typename T>
std::ostream & operator<< (std::ostream &os, const Vec3t< T > &v)
 Stream insertion for string representation of a vector.
template<typename T>
Vec3t< T > operator* (float scalar, const Vec3t< T > &vec)
 Scalar multiplication with scalar on the left.

Detailed Description

3D vector template with arithmetic, geometry helpers, and RNG utilities.

This header defines a compact 3D vector type template, Vec3t<T>, that stores three components and exposes multiple alias views (x/y/z and r/g/b as well as an xy sub-vector). It provides arithmetic operators, length helpers, and common geometric operations (dot, cross, reflect, refract) useful in graphics and simulation code.

Note
The implementation uses a union with multiple member layouts (an std::array, two structs for aliases, and a 2D sub-vector). This is intentional for ergonomic access. Access only one active view at a time.

Typedef Documentation

◆ Vec3

typedef Vec3t<float> Vec3

3D float vector (x,y,z).

◆ Vec3i

typedef Vec3t<int32_t> Vec3i

3D 32-bit signed integer vector (x,y,z).

◆ Vec3ui

typedef Vec3t<uint32_t> Vec3ui

3D 32-bit unsigned integer vector (x,y,z).

Function Documentation

◆ operator*()

template<typename T>
Vec3t< T > operator* ( float scalar,
const Vec3t< T > & vec )

Scalar multiplication with scalar on the left.

Template Parameters
TComponent type of vector.
Parameters
scalarScalar factor.
vecVector to multiply.
Returns
Result of vec * scalar.

◆ operator<<()

template<typename T>
std::ostream & operator<< ( std::ostream & os,
const Vec3t< T > & v )

Stream insertion for string representation of a vector.

Template Parameters
TComponent type.
Parameters
osOutput stream.
vVector to print.
Returns
Reference to the output stream.
Here is the call graph for this function: