Ray Tracer  2020
Public Member Functions | Private Attributes | List of all members
Transform Class Reference

Class for Transform objects. More...

#include <Transform.h>

Public Member Functions

 Transform ()
 Default Transform constructor. More...
 
 Transform (const Transform &transform)
 Transform copy constructor. More...
 
 ~Transform ()
 Transform destructor. More...
 
Transformoperator= (const Transform &transform)
 Transform assignment operator. More...
 
Point apply (const Point &point) const
 Apply a transformation to a Point. More...
 
Direction apply (const Direction &direction) const
 Apply a transformation to a Direction. More...
 
Normal apply (const Normal &normal) const
 Apply a transformation to a Normal. More...
 
Ray apply (const Ray &ray) const
 Apply a transformation to a Ray. More...
 
Point applyInverse (const Point &point) const
 Apply an inverse transformation to a Point. More...
 
Direction applyInverse (const Direction &direction) const
 Apply an inverse transformation to a Direction. More...
 
Normal applyInverse (const Normal &normal) const
 Apply an inverse transformation to a Normal. More...
 
Ray applyInverse (const Ray &ray) const
 Apply an inverse transformation to a Ray. More...
 
void rotateX (double rx)
 Apply a rotation about the X-axis. More...
 
void rotateY (double ry)
 Apply a rotation about the Y-axis. More...
 
void rotateZ (double rz)
 Apply a rotation about the Z-axis. More...
 
void scale (double s)
 Apply a uniform scaling in all directions. More...
 
void scale (double sx, double sy, double sz)
 Apply a non-uniform scaling along the axes. More...
 
void translate (double tx, double ty, double tz)
 Shift along the X-, Y-, and Z-axes. More...
 
void translate (const Direction &direction)
 Shift along a Direction Vector. More...
 

Private Attributes

Matrix T_
 The 4x4 homogeneous transformation matrix. More...
 
Matrix Tinv_
 The 4x4 inverse transformation matrix. More...
 

Detailed Description

Class for Transform objects.

A Transform is essentially a 4x4 matrix which is applied to a Vector represented in homogeneous form. How the Transform is applied, however, depends on what the Vector represents. This is accounted for by having separate subclasses of Vector for Point, Normal, and Direction representations. The Transform can then be applied to any of these in the correct way.

A Transform is computed through a series of basic transformations, such as scaling or translation. As these are applied, an inverse transformation matrix is also computed, by applying geometrical reasoning to generate matrix inverses.

Constructor & Destructor Documentation

◆ Transform() [1/2]

Transform::Transform ( )

Default Transform constructor.

Creates a Transform with an identity transformation matrix.

◆ Transform() [2/2]

Transform::Transform ( const Transform transform)

Transform copy constructor.

Creates a Transform with an identity transformation matrix.

Parameters
transformThe Transform to copy to this.

◆ ~Transform()

Transform::~Transform ( )

Transform destructor.

Member Function Documentation

◆ apply() [1/4]

Direction Transform::apply ( const Direction direction) const

Apply a transformation to a Direction.

A Direction is transformed by applying the transformation matrix to a homogeneous vector with a 0 in the last co-ordinate. This prevents translations from being applied to Direction vectors.

Parameters
directionThe Direction to Transform.
Returns
The transformed Direction.

◆ apply() [2/4]

Normal Transform::apply ( const Normal normal) const

Apply a transformation to a Normal.

A Normal is transformed by applying the transposed inverse transformation matrix. As with ordinary Direction vectors, the homgeneous form is created with a 0 in the last co-ordinate to prevent translations from being applied. For discussion on why the normal transforms with the transposed inverse, see the lecture notes or Abnormal Normals by Eric Haines.

Parameters
normalThe Normal to Transform.
Returns
The transformed Normal.

◆ apply() [3/4]

Point Transform::apply ( const Point point) const

Apply a transformation to a Point.

A Point is transformed by applying the transformation matrix to a homogeneous vector with a 1 in the last co-ordinate.

Parameters
pointThe Point to Transform.
Returns
The transformed Point.

◆ apply() [4/4]

Ray Transform::apply ( const Ray ray) const

Apply a transformation to a Ray.

A Ray is a Point and a Direction, and both need to be transformed appropriately.

Parameters
rayThe Ray to Transform.
Returns
The transformed Ray.

◆ applyInverse() [1/4]

Direction Transform::applyInverse ( const Direction direction) const

Apply an inverse transformation to a Direction.

Parameters
directionThe Direction to Transform.
Returns
The transformed Direction.
See also
Transform::apply(const Direction&) const

◆ applyInverse() [2/4]

Normal Transform::applyInverse ( const Normal normal) const

Apply an inverse transformation to a Normal.

Parameters
normalThe Normal to Transform.
Returns
The transformed Normal.
See also
Transform::apply(const Normal&) const

◆ applyInverse() [3/4]

Point Transform::applyInverse ( const Point point) const

Apply an inverse transformation to a Point.

Parameters
pointThe Point to Transform.
Returns
The transformed Point.
See also
Transform::apply(const Point&) const

◆ applyInverse() [4/4]

Ray Transform::applyInverse ( const Ray ray) const

Apply an inverse transformation to a Ray.

Parameters
rayThe Ray to Transform.
Returns
The transformed Ray.
See also
Transform::apply(const Ray&) const

◆ operator=()

Transform & Transform::operator= ( const Transform transform)

Transform assignment operator.

Parameters
transformThe Transform to assign to this.
Returns
A reference to this to allow for chaining of assignment.

◆ rotateX()

void Transform::rotateX ( double  rx)

Apply a rotation about the X-axis.

Rotate by some angle (in degrees) about the X-axis. Following the right-handed co-ordinate convention, this is a rotation from the positive Y-axis towards the positive Z-axis.

Parameters
rxThe rotation in degrees.

◆ rotateY()

void Transform::rotateY ( double  ry)

Apply a rotation about the Y-axis.

Rotate by some angle (in degrees) about the Y-axis. Following the right-handed co-ordinate convention, this is a rotation from the positive Z-axis towards the positive X-axis.

Parameters
ryThe rotation in degrees.

◆ rotateZ()

void Transform::rotateZ ( double  rz)

Apply a rotation about the Z-axis.

Rotate by some angle (in degrees) about the Z-axis. Following the right-handed co-ordinate convention, this is a rotation from the positive X-axis towards the positive Y-axis.

Parameters
rzThe rotation in degrees.

◆ scale() [1/2]

void Transform::scale ( double  s)

Apply a uniform scaling in all directions.

Scale by some constant factor in all directions. If the scaling factor is greater than 1 it represents a magnification. Scaling factors less than 1 represent a reduction. Negative scaling factors are valid but cause a reflection as well as a scaling.

Parameters
sThe scaling factor to apply.

◆ scale() [2/2]

void Transform::scale ( double  sx,
double  sy,
double  sz 
)

Apply a non-uniform scaling along the axes.

Scale by different factors in the X-, Y-, and Z-directions. If a scaling factor is greater than 1 it represents a magnification. Scaling factors less than 1 represent a reduction. Negative scaling factors are valid but cause a reflection as well as a scaling.

Parameters
sxThe scaling factor to apply in the X-direction.
syThe scaling factor to apply in the Y-direction.
szThe scaling factor to apply in the Z-direction.

◆ translate() [1/2]

void Transform::translate ( const Direction direction)

Shift along a Direction Vector.

Parameters
directionThe Direction to move along.

◆ translate() [2/2]

void Transform::translate ( double  tx,
double  ty,
double  tz 
)

Shift along the X-, Y-, and Z-axes.

Shift by some distance along each of the X-, Y-, and Z- axes.

Parameters
txThe distance to move in the X-direction.
tyThe distance to move in the Y-direction.
tzThe distance to move in the Z-direction.

Member Data Documentation

◆ T_

Matrix Transform::T_
private

The 4x4 homogeneous transformation matrix.

◆ Tinv_

Matrix Transform::Tinv_
private

The 4x4 inverse transformation matrix.


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