summaryrefslogtreecommitdiff
path: root/hw6/src/coordinateTransform.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'hw6/src/coordinateTransform.cpp')
-rw-r--r--hw6/src/coordinateTransform.cpp67
1 files changed, 67 insertions, 0 deletions
diff --git a/hw6/src/coordinateTransform.cpp b/hw6/src/coordinateTransform.cpp
new file mode 100644
index 0000000..29e19f4
--- /dev/null
+++ b/hw6/src/coordinateTransform.cpp
@@ -0,0 +1,67 @@
+/******************************************************************/
+/* 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 "coordinateTransform.h"
+
+//////////////////
+// Constructors //
+//////////////////
+coordinateTransformation::coordinateTransformation(void)
+{
+ // do nothing
+}
+
+
+coordinateTransformation::coordinateTransformation(const vec3d& normal)
+{
+ // normal == Z axis
+ vec3d X, Y, Z = normalize(normal);
+
+ // select Y axis
+ if(fabs(Z.x) < fabs(Z.y) && fabs(Z.x) < fabs(Z.z))
+ Y = normalize(vec3d(0.0f, Z.z, -Z.y));
+ else if(fabs(Z.y) < fabs(Z.z))
+ Y = normalize(vec3d(Z.z, 0.0f, -Z.x));
+ else
+ Y = normalize(vec3d(Z.y, -Z.x, 0.0f));
+
+ // create other axis
+ X = Y.cross(Z).normalize();
+
+ // copy
+ _transformation = mat3d(X, Y, Z);
+ _inverseTransformation = transpose(_transformation);
+
+ // Done.
+}
+
+
+coordinateTransformation::coordinateTransformation(const vec3d& normal, const vec3d& axis)
+{
+ // normal == Z axis
+ vec3d Z = normalize(normal);
+
+ // create other axis
+ vec3d axis_normalized = normalize(axis);
+ vec3d Y = Z.cross(axis_normalized).normalize();
+ vec3d X = Y.cross(Z).normalize();
+
+ // copy
+ _transformation = mat3d(X, Y, Z);
+ _inverseTransformation = transpose(_transformation);
+
+ // Done.
+}
+
+
+coordinateTransformation::coordinateTransformation(const vec3d& X, const vec3d& Y, const vec3d& Z)
+{
+ // trust user to provide an orthogonal set of vectors.
+ _transformation = mat3d(X, Y, Z);
+ _inverseTransformation = transpose(_transformation);
+}