diff options
Diffstat (limited to 'hw6/src/surfaceSample.cpp')
-rw-r--r-- | hw6/src/surfaceSample.cpp | 118 |
1 files changed, 118 insertions, 0 deletions
diff --git a/hw6/src/surfaceSample.cpp b/hw6/src/surfaceSample.cpp new file mode 100644 index 0000000..464c969 --- /dev/null +++ b/hw6/src/surfaceSample.cpp @@ -0,0 +1,118 @@ +/******************************************************************/ +/* This file is part of the homework assignments for CSCI-427/527 */ +/* at The College of William & Mary and authored by Pieter Peers. */ +/* No part of this file, whether altered or in original form, can */ +/* be distributed or used outside the context of CSCI-427/527 */ +/* without consent of either the College of William & Mary or */ +/* Pieter Peers. */ +/******************************************************************/ +#include <cmath> +#include "surfaceSample.h" + +////////////////// +// Constructors // +////////////////// +surfaceSample::surfaceSample(void) +{ + _position = vec3d(); + _normal = vec3d(); + _pdf = 0.0f; +} + + +surfaceSample::surfaceSample(const vec3d& position, const vec3d& normal, const float pdf) +{ + _position = position; + _normal = normal; + _pdf = std::max(pdf, 0.0f); +} + + +surfaceSample::surfaceSample(const surfaceSample& ss) +{ + _position = ss._position; + _normal = ss._normal; + _pdf = ss._pdf; +} + + +/////////////// +// Operators // +/////////////// +surfaceSample& surfaceSample::operator=(const surfaceSample& ss) +{ + _assign(ss); + return *this; +} + + +surfaceSample surfaceSample::operator*(float pdf) const +{ + return surfaceSample(_position, _normal, _pdf * pdf); +} + + +surfaceSample& surfaceSample::operator*=(float pdf) +{ + _pdf *= pdf; + return *this; +} + + +//////////////// +// Inspectors // +//////////////// +const vec3d& surfaceSample::position(void) const +{ + return _position; +} + + +const vec3d& surfaceSample::normal(void) const +{ + return _normal; +} + + +float surfaceSample::pdf(void) const +{ + return _pdf; +} + + +///////////// +// Methods // +///////////// +surfaceSample& surfaceSample::transform(const transformation3d& t) +{ + _position = t.transformPoint(_position); + _normal = t.transformNormal(_normal); + return *this; +} + + +surfaceSample& surfaceSample::inverseTransform(const transformation3d& t) +{ + _position = t.inverseTransformPoint(_position); + _normal = t.inverseTransformNormal(_normal); + return *this; +} + + +///////////////////// +// Private Methods // +///////////////////// +void surfaceSample::_swap(surfaceSample& s) +{ + swap(_position, s._position); + swap(_normal, s._normal); + std::swap(_pdf, s._pdf); +} + + +void surfaceSample::_assign(const surfaceSample& s) +{ + _position = s._position; + _normal = s._normal; + _pdf = s._pdf; +} |