summaryrefslogtreecommitdiff
path: root/hw6/src/environmentMap.cpp
diff options
context:
space:
mode:
author53hornet <53hornet@gmail.com>2019-02-02 23:33:15 -0500
committer53hornet <53hornet@gmail.com>2019-02-02 23:33:15 -0500
commitdb072ad4dc181eca5a1458656b130beb43f475bf (patch)
treea3c03c7f5497cb70503e2486662fa85cfb53415a /hw6/src/environmentMap.cpp
downloadcsci427-master.tar.xz
csci427-master.zip
Diffstat (limited to 'hw6/src/environmentMap.cpp')
-rw-r--r--hw6/src/environmentMap.cpp79
1 files changed, 79 insertions, 0 deletions
diff --git a/hw6/src/environmentMap.cpp b/hw6/src/environmentMap.cpp
new file mode 100644
index 0000000..896d78e
--- /dev/null
+++ b/hw6/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 <cmath>
+#include "constants.h"
+#include "environmentMap.h"
+
+
+//////////////////
+// Constructors //
+//////////////////
+environmentMap::environmentMap(const std::shared_ptr<const texture_base>& 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
+{
+ // normalize & apply transformation
+ vec3d dir = _transform.inverseTransformDirection(normalize(direction));
+
+ // compute spherical coordinates
+ float theta = acos(dir.z);
+ float phi = atan2(dir.y, dir.x);
+
+ if(phi < 0.0f) phi += 2.0f * PI;
+
+ // get texel
+ return _map->operator()(vec2d(0.5f * phi / PI, theta / PI));
+}
+
+
+///////////////////////
+// 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 << ")";
+}