diff options
author | 53hornet <53hornet@gmail.com> | 2019-02-02 23:33:15 -0500 |
---|---|---|
committer | 53hornet <53hornet@gmail.com> | 2019-02-02 23:33:15 -0500 |
commit | db072ad4dc181eca5a1458656b130beb43f475bf (patch) | |
tree | a3c03c7f5497cb70503e2486662fa85cfb53415a /hw6/src/lightSample.cpp | |
download | csci427-db072ad4dc181eca5a1458656b130beb43f475bf.tar.xz csci427-db072ad4dc181eca5a1458656b130beb43f475bf.zip |
Diffstat (limited to 'hw6/src/lightSample.cpp')
-rw-r--r-- | hw6/src/lightSample.cpp | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/hw6/src/lightSample.cpp b/hw6/src/lightSample.cpp new file mode 100644 index 0000000..cfe4ee5 --- /dev/null +++ b/hw6/src/lightSample.cpp @@ -0,0 +1,120 @@ +/******************************************************************/ +/* 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 "lightSample.h" + + +////////////////// +// Constructors // +////////////////// +lightSample::lightSample(const vec3d& direction, + const color& emittance, + float distance, + float pdf, + float foreshortening) +{ + float length = direction.length(); + _direction = (length < EPSILON) ? vec3d(0.0f, 0.0f, 0.0f) : direction / length; + _emittance = emittance; + _distance = distance; + _pdf = std::max(pdf, 0.0f); + _foreshortening = std::max(foreshortening, 0.0f); +} + + +lightSample::lightSample(const lightSample& ls) +{ + _direction = ls._direction; + _emittance = ls._emittance; + _distance = ls._distance; + _pdf = ls._pdf; + _foreshortening = ls._foreshortening; +} + + +/////////////// +// Operators // +/////////////// +lightSample& lightSample::operator=(const lightSample& ls) +{ + _assign(ls); + return(*this); +} + + +const color& lightSample::operator()(void) const +{ + return _emittance; +} + + +//////////////// +// Inspectors // +//////////////// +const vec3d& lightSample::directionToPoint(void) const +{ + return _direction; +} + + +vec3d lightSample::directionToLight(void) const +{ + return -_direction; +} + + +const color& lightSample::emittance(void) const +{ + return _emittance; +} + + +float lightSample::distance(void) const +{ + return _distance; +} + + +float lightSample::pdf(void) const +{ + return _pdf; +} + + +float lightSample::foreshortening(void) const +{ + return _foreshortening; +} + + +///////////////////// +// Private Methods // +///////////////////// +void lightSample::_assign(const lightSample& ls) +{ + // sanity check + if(&ls == this) return; + + // copy + _direction = ls._direction; + _emittance = ls._emittance; + _distance = ls._distance; + _pdf = ls._pdf; + _foreshortening = ls._foreshortening; +} + + +void lightSample::_swap(lightSample& ls) +{ + swap(_direction, ls._direction); + swap(_emittance, ls._emittance); + std::swap(_distance, ls._distance); + std::swap(_pdf, ls._pdf); + std::swap(_foreshortening, ls._foreshortening); +} |