Ray Tracer
2020
|
Class to store colour information. More...
#include <Colour.h>
Public Member Functions | |
Colour () | |
Colour default constructor. More... | |
Colour (double r, double g, double b) | |
Colour constructor. More... | |
Colour (const Colour &colour) | |
Colour copy constructor. More... | |
~Colour () | |
Colour destructor. More... | |
Colour & | operator= (const Colour &colour) |
Colour assignment operator. More... | |
Colour | operator- () const |
Colour unary negation. More... | |
Colour & | operator+= (const Colour &colour) |
Colour addition-assignment operator. More... | |
Colour & | operator-= (const Colour &colour) |
Colour subtraction-assignment operator. More... | |
Colour & | operator*= (const Colour &colour) |
Colour multiplication-assignment operator. More... | |
Colour & | operator*= (double s) |
Colour-scalar multiplication-assignment operator. More... | |
Colour & | operator/= (double s) |
Colour-scalar division-assignment operator. More... | |
void | clip () |
Enforce bounds on Colour components. More... | |
Public Attributes | |
double | red |
The red component of the Colour. More... | |
double | green |
The green component of the Colour. More... | |
double | blue |
The blue component of the Colour. More... | |
Related Functions | |
(Note that these are not member functions.) | |
Colour | operator+ (const Colour &lhs, const Colour &rhs) |
Colour addition. More... | |
Colour | operator- (const Colour &lhs, const Colour &rhs) |
Colour subtraction. More... | |
Colour | operator* (const Colour &lhs, const Colour &rhs) |
Colour multiplication. More... | |
Colour | operator* (double s, const Colour &colour) |
Scalar-Colour multiplication. More... | |
Colour | operator* (const Colour &colour, double s) |
Colour-scalar multiplication. More... | |
Colour | operator/ (const Colour &colour, double s) |
Colour-scalar division. More... | |
Class to store colour information.
Colours are an important aspect of Material objects, and the basic quanitity that a ray tracer comptues for a ray. Colours are represented as RGB triples, with values in the range [0,1]. Note that during computation, Colour values may go outside of the range [0,1]. Because of this, these bounds are not enforced. However Colours can be brought back into this range with the clip() method.
Colour objects also have basic arithmetic operators defined on them. These are applied independently to each component. This is an important distinction from Vector and Matrix objects, which have particular rules for arithmetic (particularly multiplication).
Colour::Colour | ( | ) |
Colour default constructor.
Creates a new colour with all values set to 0 (black).
Colour::Colour | ( | double | r, |
double | g, | ||
double | b | ||
) |
Colour::Colour | ( | const Colour & | colour | ) |
Colour::~Colour | ( | ) |
Colour destructor.
void Colour::clip | ( | ) |
Colour & Colour::operator*= | ( | double | s | ) |
Colour-scalar multiplication-assignment operator.
Multiply a Colour by a scalar in place.
s | The scalar to multiply this by. |
this
, to allow chaining of assignment. Colour Colour::operator- | ( | ) | const |
Colour & Colour::operator/= | ( | double | s | ) |
Colour-scalar division-assignment operator.
Divide a Colour by a scalar in place.
s | The scalar to divide this by. |
this
, to allow chaining of assignment. Colour multiplication.
Given two Colours, (R1, G1, B1) and (R2, G2, B2), their product is (R1*R2, G1*G2, B1*B2). Note that this is different from the usual Vector dot and cross products.
lhs | The Colour on the left hand side of the * operator. |
rhs | The Colour on the right hand side of the * operator. |
double Colour::blue |
The blue component of the Colour.
double Colour::green |
The green component of the Colour.
double Colour::red |
The red component of the Colour.