Ray Tracer
2020
|
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... | |
Transform & | operator= (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... | |
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.
Transform::Transform | ( | ) |
Transform::Transform | ( | const Transform & | transform | ) |
Transform::~Transform | ( | ) |
Transform destructor.
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.
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.
rx | The rotation in degrees. |
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.
ry | The rotation in degrees. |
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.
rz | The rotation in degrees. |
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.
s | The scaling factor to apply. |
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.
sx | The scaling factor to apply in the X-direction. |
sy | The scaling factor to apply in the Y-direction. |
sz | The scaling factor to apply in the Z-direction. |
void Transform::translate | ( | const Direction & | direction | ) |
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.
tx | The distance to move in the X-direction. |
ty | The distance to move in the Y-direction. |
tz | The distance to move in the Z-direction. |
|
private |
The 4x4 homogeneous transformation matrix.
|
private |
The 4x4 inverse transformation matrix.