Hermes
hermes::Transform Class Reference

Represents a 3-dimensional transformation. More...

Public Member Functions

HERMES_DEVICE_CALLABLE Transform ()
 Default constructor.
 
HERMES_DEVICE_CALLABLE Transform (const mat4 &mat)
 Constructs from matrix. More...
 
HERMES_DEVICE_CALLABLE Transform (const real_t mat[4][4])
 Constructs from array matrix. More...
 
HERMES_DEVICE_CALLABLE Transform (const bbox3 &bbox)
 Constructs from geometric box. More...
 
HERMES_DEVICE_CALLABLE bbox3 operator() (const bbox3 &b) const
 Applies this transform to geometric box. More...
 
HERMES_DEVICE_CALLABLE point3 operator() (const point2 &p) const
 Applies this transform to geometric point. More...
 
HERMES_DEVICE_CALLABLE point3 operator() (const point3 &p) const
 Applies this transform to geometric point. More...
 
HERMES_DEVICE_CALLABLE void operator() (const point3 &p, point3 *r) const
 Applies this transform to geometric point. More...
 
HERMES_DEVICE_CALLABLE vec3 operator() (const vec3 &v) const
 Applies this transform to geometric point. More...
 
HERMES_DEVICE_CALLABLE normal3 operator() (const normal3 &n) const
 Applies this transform to geometric normal. More...
 
HERMES_DEVICE_CALLABLE Ray3 operator() (const Ray3 &r)
 Applies this transform to geometric ray. More...
 
HERMES_DEVICE_CALLABLE void operator() (const Ray3 &r, Ray3 *ret) const
 Applies this transform to geometric ray. More...
 
HERMES_DEVICE_CALLABLE Transformoperator= (const Transform2 &t)
 Copy assign from 2d transform. More...
 
HERMES_DEVICE_CALLABLE Transform operator* (const Transform &t) const
 Applies this transform to t. More...
 
HERMES_DEVICE_CALLABLE point3 operator* (const point3 &p) const
 Applies this transform to geometric vector. More...
 
HERMES_DEVICE_CALLABLE bool operator== (const Transform &t) const
 
HERMES_DEVICE_CALLABLE bool operator!= (const Transform &t) const
 
HERMES_DEVICE_CALLABLE void reset ()
 Sets this transform back to identity.
 
HERMES_DEVICE_CALLABLE bool swapsHandedness () const
 Checks if this transform swaps coordinate system handedness. More...
 
HERMES_DEVICE_CALLABLE vec3 getTranslate () const
 Gets translation vector. More...
 
HERMES_DEVICE_CALLABLE bool isIdentity ()
 Checks if this transform is identity. More...
 
HERMES_DEVICE_CALLABLE void applyToPoint (const real_t *p, real_t *r, size_t d=3) const
 Applies transform to point (array) More...
 
HERMES_DEVICE_CALLABLE const real_tc_matrix () const
 Gets raw matrix pointer. More...
 
HERMES_DEVICE_CALLABLE const mat4matrix () const
 Gets transformation matrix.
 
HERMES_DEVICE_CALLABLE mat3 upperLeftMatrix () const
 Gets upper left matrix. More...
 
HERMES_DEVICE_CALLABLE const real_toperator[] (u32 row_index) const
 Gets transformation matrix row. More...
 
HERMES_DEVICE_CALLABLE real_toperator[] (u32 row_index)
 Gets transformation matrix row. More...
 
HERMES_DEVICE_CALLABLE bool hasNaNs () const
 Check for nans. More...
 

Static Public Member Functions

static HERMES_DEVICE_CALLABLE Transform lookAt (const point3 &eye, const point3 &target={0, 0, 0}, const vec3 &up={0, 1, 0}, transform_options options=transform_options::left_handed)
 Creates a Look At Transform. More...
 
static HERMES_DEVICE_CALLABLE Transform ortho (real_t left, real_t right, real_t bottom, real_t top, real_t near, real_t far, transform_options options=transform_options::left_handed)
 Creates an Orthographic Projection. More...
 
static HERMES_DEVICE_CALLABLE Transform perspective (real_t fovy_in_degrees, real_t aspect_ratio, real_t near, real_t far, transform_options options=transform_options::left_handed)
 Creates a Perspective Projection. More...
 
static HERMES_DEVICE_CALLABLE Transform scale (real_t x, real_t y, real_t z)
 Creates a scale transform. More...
 
static HERMES_DEVICE_CALLABLE Transform translate (const vec3 &d)
 Creates a translation transform. More...
 
static HERMES_DEVICE_CALLABLE Transform rotateX (real_t angle_in_radians)
 Creates a x-axis rotation transform. More...
 
static HERMES_DEVICE_CALLABLE Transform rotateY (real_t angle_in_radians)
 Creates a y-axis rotation transform. More...
 
static HERMES_DEVICE_CALLABLE Transform rotateZ (real_t angle_in_radians)
 Creates a z-axis rotation transform. More...
 
static HERMES_DEVICE_CALLABLE Transform rotate (real_t angle_in_radians, const vec3 &axis)
 Creates a arbitrary-axis rotation transform. More...
 
static HERMES_DEVICE_CALLABLE Transform alignVectors (const vec3 &a, const vec3 &b)
 Creates a transform that aligns vector a to vector b. More...
 
static MemoryDumper::RegionLayout memoryDumpLayout ()
 Gets memory layout. More...
 

Protected Attributes

mat4 m
 transformation matrix
 

Friends

HERMES_DEVICE_CALLABLE friend Transform inverse (const Transform &t)
 Computes inverse of a given transform. More...
 

Detailed Description

Represents a 3-dimensional transformation.

Constructor & Destructor Documentation

◆ Transform() [1/3]

HERMES_DEVICE_CALLABLE hermes::Transform::Transform ( const mat4 mat)

Constructs from matrix.

Parameters
mat

◆ Transform() [2/3]

HERMES_DEVICE_CALLABLE hermes::Transform::Transform ( const real_t  mat[4][4])
explicit

Constructs from array matrix.

Parameters
mat

◆ Transform() [3/3]

HERMES_DEVICE_CALLABLE hermes::Transform::Transform ( const bbox3 bbox)

Constructs from geometric box.

Parameters
bbox

Member Function Documentation

◆ alignVectors()

HERMES_DEVICE_CALLABLE Transform hermes::Transform::alignVectors ( const vec3 a,
const vec3 b 
)
static

Creates a transform that aligns vector a to vector b.

Parameters
asource vector
bdestination vector
Returns

◆ applyToPoint()

HERMES_DEVICE_CALLABLE void hermes::Transform::applyToPoint ( const real_t p,
real_t r,
size_t  d = 3 
) const
inline

Applies transform to point (array)

Parameters
p
r
d

◆ c_matrix()

HERMES_DEVICE_CALLABLE const real_t* hermes::Transform::c_matrix ( ) const
inline

Gets raw matrix pointer.

Returns

◆ getTranslate()

HERMES_DEVICE_CALLABLE vec3 hermes::Transform::getTranslate ( ) const
inline

Gets translation vector.

Returns

◆ hasNaNs()

HERMES_DEVICE_CALLABLE bool hermes::Transform::hasNaNs ( ) const
inline

Check for nans.

Returns

◆ isIdentity()

HERMES_DEVICE_CALLABLE bool hermes::Transform::isIdentity ( )
inline

Checks if this transform is identity.

Returns

◆ lookAt()

HERMES_DEVICE_CALLABLE Transform hermes::Transform::lookAt ( const point3 eye,
const point3 target = {0, 0, 0},
const vec3 up = {0, 1, 0},
transform_options  options = transform_options::left_handed 
)
static

Creates a Look At Transform.

Note
This transform is commonly used (in graphics) to orient a camera so it looks at a certain target position from its eye position. Given an up vector to define the camera orientation, a new coordinate basis consisting of three vectors {r, u, v} is defined. Where v = (eye - target) / ||eye - target|| r = -(v x up) / ||(v x up)|| u = v x r
The transform is then composed of a translation (to camera eye position) and a basis transform to align r with (1,0,0), u with (0,1,0) and v with (0,0,1). The final matrix is rx ry rz -dot(t, r) rx ry rz -dot(t, u) rx ry rz -dot(t, v) 0 0 0 1
Note that this transform is built on a left handed coordinate system.
Parameters
eye
target
up
options
Returns

◆ memoryDumpLayout()

static MemoryDumper::RegionLayout hermes::Transform::memoryDumpLayout ( )
inlinestatic

Gets memory layout.

Returns

◆ operator()() [1/8]

HERMES_DEVICE_CALLABLE bbox3 hermes::Transform::operator() ( const bbox3 b) const
inline

Applies this transform to geometric box.

Parameters
b
Returns

◆ operator()() [2/8]

HERMES_DEVICE_CALLABLE normal3 hermes::Transform::operator() ( const normal3 n) const
inline

Applies this transform to geometric normal.

Parameters
n
Returns

◆ operator()() [3/8]

HERMES_DEVICE_CALLABLE point3 hermes::Transform::operator() ( const point2 p) const
inline

Applies this transform to geometric point.

Parameters
p
Returns

◆ operator()() [4/8]

HERMES_DEVICE_CALLABLE point3 hermes::Transform::operator() ( const point3 p) const
inline

Applies this transform to geometric point.

Parameters
p
Returns

◆ operator()() [5/8]

HERMES_DEVICE_CALLABLE void hermes::Transform::operator() ( const point3 p,
point3 r 
) const
inline

Applies this transform to geometric point.

Parameters
p
r

◆ operator()() [6/8]

HERMES_DEVICE_CALLABLE Ray3 hermes::Transform::operator() ( const Ray3 r)
inline

Applies this transform to geometric ray.

Parameters
r
Returns

◆ operator()() [7/8]

HERMES_DEVICE_CALLABLE void hermes::Transform::operator() ( const Ray3 r,
Ray3 ret 
) const
inline

Applies this transform to geometric ray.

Parameters
r
ret

◆ operator()() [8/8]

HERMES_DEVICE_CALLABLE vec3 hermes::Transform::operator() ( const vec3 v) const
inline

Applies this transform to geometric point.

Parameters
v
Returns

◆ operator*() [1/2]

HERMES_DEVICE_CALLABLE point3 hermes::Transform::operator* ( const point3 p) const
inline

Applies this transform to geometric vector.

Parameters
p
Returns

◆ operator*() [2/2]

HERMES_DEVICE_CALLABLE Transform hermes::Transform::operator* ( const Transform t) const
inline

Applies this transform to t.

Parameters
t
Returns

◆ operator=()

HERMES_DEVICE_CALLABLE Transform& hermes::Transform::operator= ( const Transform2 t)
inline

Copy assign from 2d transform.

Parameters
t
Returns

◆ operator[]() [1/2]

HERMES_DEVICE_CALLABLE real_t* hermes::Transform::operator[] ( u32  row_index)
inline

Gets transformation matrix row.

Parameters
row_index
Returns

◆ operator[]() [2/2]

HERMES_DEVICE_CALLABLE const real_t* hermes::Transform::operator[] ( u32  row_index) const
inline

Gets transformation matrix row.

Parameters
row_index
Returns

◆ ortho()

HERMES_DEVICE_CALLABLE Transform hermes::Transform::ortho ( real_t  left,
real_t  right,
real_t  bottom,
real_t  top,
real_t  near,
real_t  far,
transform_options  options = transform_options::left_handed 
)
static

Creates an Orthographic Projection.

Note
In an orthographic projection, parallel lines remain parallel and objects maintain the same size regardless the distance.
This transform projects points into the cube (-1,-1,-1) x (1, 1, 1). It is also possible to choose to project to (-1,-1, 0) x (1, 1, 1) with the zero_to_one option.
The matrix takes the form: 2 / (r - l) 0 0 -(r + l) / (r - l) 0 2 / (t - b) 0 -(t + b) / (t - b) 0 0 2 / (f - n) -(f + n) / (f - n) 0 0 0 1
In the case of zero_to_one == true, the matrix becomes: 2 / (r - l) 0 0 -(r + l) / (r - l) 0 2 / (t - b) 0 -(t + b) / (t - b) 0 0 1 / (f - n) n / (f - n) 0 0 0 1
- Note that n > f. This function negates the values of near and far in case the given values are f > n. Because by default, this transform uses a left-handed coordinate system.
Parameters
left
right
bottom
top
near
far
options
Returns

◆ perspective()

HERMES_DEVICE_CALLABLE Transform hermes::Transform::perspective ( real_t  fovy_in_degrees,
real_t  aspect_ratio,
real_t  near,
real_t  far,
transform_options  options = transform_options::left_handed 
)
static

Creates a Perspective Projection.

Note
The perspective projection transforms the view frustrum (a pyramid truncated by a near plane and a far plane, both orthogonal to the view direction) into the cube (-1,-1,-1) x (1, 1, 1).
In a right-handed coordinate system when x points to the right, z points forward if y points downward and z points backwards if y points upwards.
In a left-handed coordinate system when x points to the right, z points forwards if y points upward and z points backward if y points downwards.
It is also possible to choose to project to (-1,-1, 0) x (1, 1, 1) with the zero_to_one option.
Parameters
fovy_in_degrees
aspect_ratio
near
far
options
Returns

◆ rotate()

HERMES_DEVICE_CALLABLE Transform hermes::Transform::rotate ( real_t  angle_in_radians,
const vec3 axis 
)
static

Creates a arbitrary-axis rotation transform.

Parameters
angle_in_radians
axis
Returns

◆ rotateX()

HERMES_DEVICE_CALLABLE Transform hermes::Transform::rotateX ( real_t  angle_in_radians)
static

Creates a x-axis rotation transform.

Parameters
angle_in_radians
Returns

◆ rotateY()

HERMES_DEVICE_CALLABLE Transform hermes::Transform::rotateY ( real_t  angle_in_radians)
static

Creates a y-axis rotation transform.

Parameters
angle_in_radians
Returns

◆ rotateZ()

HERMES_DEVICE_CALLABLE Transform hermes::Transform::rotateZ ( real_t  angle_in_radians)
static

Creates a z-axis rotation transform.

Parameters
angle_in_radians
Returns

◆ scale()

HERMES_DEVICE_CALLABLE Transform hermes::Transform::scale ( real_t  x,
real_t  y,
real_t  z 
)
static

Creates a scale transform.

Parameters
x
y
z
Returns

◆ swapsHandedness()

HERMES_DEVICE_CALLABLE bool hermes::Transform::swapsHandedness ( ) const

Checks if this transform swaps coordinate system handedness.

Returns
true if this transformation changes the coordinate system handedness

◆ translate()

HERMES_DEVICE_CALLABLE Transform hermes::Transform::translate ( const vec3 d)
static

Creates a translation transform.

Parameters
d
Returns

◆ upperLeftMatrix()

HERMES_DEVICE_CALLABLE mat3 hermes::Transform::upperLeftMatrix ( ) const
inline

Gets upper left matrix.

Returns

Friends And Related Function Documentation

◆ inverse

HERMES_DEVICE_CALLABLE friend Transform inverse ( const Transform t)
friend

Computes inverse of a given transform.

Parameters
t
Returns

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