summaryrefslogtreecommitdiff
path: root/hw2/include/mat3d.h
diff options
context:
space:
mode:
Diffstat (limited to 'hw2/include/mat3d.h')
-rw-r--r--hw2/include/mat3d.h112
1 files changed, 112 insertions, 0 deletions
diff --git a/hw2/include/mat3d.h b/hw2/include/mat3d.h
new file mode 100644
index 0000000..e70ece4
--- /dev/null
+++ b/hw2/include/mat3d.h
@@ -0,0 +1,112 @@
+/******************************************************************/
+/* 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. */
+/******************************************************************/
+#ifndef _MAT3D_H_
+#define _MAT3D_H_
+
+#include <array>
+#include <ostream>
+
+#include "vec3d.h"
+
+class mat3d {
+ public:
+ /////////////
+ // Typedef //
+ /////////////
+ typedef float value_type;
+ typedef value_type& reference;
+ typedef const value_type& const_reference;
+ typedef std::array<value_type,9>::iterator iterator;
+ typedef std::array<value_type,9>::const_iterator const_iterator;
+ typedef std::size_t difference;
+ typedef std::size_t size_type;
+
+ /////////////////
+ // Constructor //
+ /////////////////
+ mat3d(void); // all elements are set to 0
+ explicit mat3d(value_type diag); // all elements are set to 0, the diagonal elements are set to 'diag'
+ mat3d(const vec3d& X, const vec3d& Y, const vec3d& Z); // set columns to X, Y, and Z
+ mat3d(const mat3d& m); // copy constructor
+
+ ////////////////
+ // Inspectors //
+ ////////////////
+ static size_type width(void) { return 3; }
+ static size_type height(void) { return 3; }
+ static size_type size(void) { return 9; }
+
+ iterator begin(void);
+ const_iterator begin(void) const;
+ iterator end(void);
+ const_iterator end(void) const;
+
+ //////////////
+ // Mutators //
+ //////////////
+ void clear(value_type value=0.0f);
+ void setDiagonal(value_type value=1.0f);
+
+ mat3d& transpose(void);
+
+ ///////////////
+ // Operators //
+ ///////////////
+ mat3d& operator=(const mat3d& m);
+
+ reference operator()(size_type row, size_type col);
+ const_reference operator()(size_type row, size_type col) const;
+
+ mat3d operator+(const mat3d& m) const;
+ mat3d operator-(const mat3d& m) const;
+ mat3d operator*(const mat3d& m) const;
+ vec3d operator*(const vec3d& v) const;
+ mat3d operator*(value_type scale) const;
+ mat3d operator/(value_type scale) const;
+
+ mat3d& operator+=(const mat3d& m);
+ mat3d& operator-=(const mat3d& m);
+ mat3d& operator*=(const mat3d& m);
+ mat3d& operator*=(value_type scale);
+ mat3d& operator/=(value_type scale);
+
+ /////////////
+ // Friends //
+ /////////////
+ friend void swap(mat3d& a, mat3d& b) { a._swap(b); }
+
+ friend vec3d operator*(const vec3d& v, const mat3d& m) { return m._premultiply(v); }
+ friend mat3d operator*(value_type scale, const mat3d& m) { return (m * scale); }
+
+ friend mat3d transpose(mat3d& m) { mat3d n(m); return n.transpose(); }
+
+ friend std::ostream& operator<<(std::ostream& s, const mat3d& m)
+ {
+ s << "[[" << m(0,0) << ", " << m(0,1) << ", " << m(0,2) << "],[";
+ s << m(1,0) << ", " << m(1,1) << ", " << m(1,2) << "],[";
+ s << m(2,0) << ", " << m(2,1) << ", " << m(2,2) << "]]";
+ return s;
+ }
+
+ private:
+ /////////////////////
+ // Private Methods //
+ /////////////////////
+ void _swap(mat3d& m);
+ void _assign(const mat3d& m);
+
+ vec3d _premultiply(const vec3d& v) const;
+
+ //////////////////////////
+ // Private Data Members //
+ //////////////////////////
+ std::array<value_type, 9> _data;
+};
+
+#endif /* _MAT3D_H_ */