From db072ad4dc181eca5a1458656b130beb43f475bf Mon Sep 17 00:00:00 2001 From: 53hornet <53hornet@gmail.com> Date: Sat, 2 Feb 2019 23:33:15 -0500 Subject: Init. --- hw5/src/environmentMap.cpp | 79 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 hw5/src/environmentMap.cpp (limited to 'hw5/src/environmentMap.cpp') diff --git a/hw5/src/environmentMap.cpp b/hw5/src/environmentMap.cpp new file mode 100644 index 0000000..24c3492 --- /dev/null +++ b/hw5/src/environmentMap.cpp @@ -0,0 +1,79 @@ +/******************************************************************/ +/* 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 +#include "constants.h" +#include "environmentMap.h" + + +////////////////// +// Constructors // +////////////////// +environmentMap::environmentMap(const std::shared_ptr& map, const transformation3d& transform) +{ + _map = map; + _transform = transform; +} + + +environmentMap::environmentMap(const environmentMap& src) +{ + _map = src._map; + _transform = src._transform; +} + + +/////////////// +// Operators // +/////////////// +environmentMap environmentMap::operator=(const environmentMap& src) +{ + _assign(src); + return *this; +} + + +color environmentMap::operator()(const vec3d& direction) const +{ + // HW5: Implement this. Given a 'direction' return the corresponding + // texel from the _map. The environment map uses spherical coordinates + // for mapping a direction to a (phi, theta) pair (which are subsequently + // mapped to pixel coordinates. (x,y,z) = (cos(phi)*sin(theta), + // sin(phi)*sin(theta), cos(theta)). + // Modifies: nothing + // Returns: color + vec3d reflect_dir = _transform.inverseTransformDirection(direction); // invert + float phi = (acos(reflect_dir.z) + PI) / PI; // make positive, scale: 180 + float theta = atan2(reflect_dir.y, reflect_dir.x) / (2 * PI); // scale: 360 + return (*_map)(vec2d(theta, phi)); // return texel +} + + +/////////////////////// +// Protected Methods // +/////////////////////// +void environmentMap::_assign(const environmentMap& src) +{ + if(&src == this) return; + + _map = src._map; + _transform = src._transform; +} + + +void environmentMap::_swap(environmentMap& swp) +{ + std::swap(_map, swp._map); + swap(_transform, swp._transform); +} + + +void environmentMap::_print(std::ostream& s) const +{ + s << "Environment Map (" << *_map << ", " << _transform << ")"; +} -- cgit v1.2.3