summaryrefslogtreecommitdiffstats
path: root/wiimote_ir_smoothing/Vect3D.h
diff options
context:
space:
mode:
Diffstat (limited to 'wiimote_ir_smoothing/Vect3D.h')
-rw-r--r--wiimote_ir_smoothing/Vect3D.h48
1 files changed, 48 insertions, 0 deletions
diff --git a/wiimote_ir_smoothing/Vect3D.h b/wiimote_ir_smoothing/Vect3D.h
new file mode 100644
index 0000000..82659fc
--- /dev/null
+++ b/wiimote_ir_smoothing/Vect3D.h
@@ -0,0 +1,48 @@
+#ifndef VECT3D_H_
+
+#define VECT3D_H_
+
+#include <iostream>
+#include <sstream>
+
+typedef struct v3 //3d vector struct with overloaded operators
+{
+ double x,y,z;
+
+ inline v3() {x=y=z= 0.0;}
+ inline v3(double vx, double vy, double vz) { x=vx; y=vy; z=vz; }
+ inline v3(const v3 &v) {x=v.x; y=v.y; z=v.z;}
+
+ v3& operator=(const v3 &rhs) {x=rhs.x; y=rhs.y; z=rhs.z; return *this;}
+
+ inline v3& operator+=(const v3 &rhs) {x+=rhs.x; y+=rhs.y; z+=rhs.z; return *this;}
+ inline v3& operator-=(const v3 &rhs) {x-=rhs.x; y-=rhs.y; z-=rhs.z; return *this;}
+ inline v3& operator*=(const v3 &rhs) {x*=rhs.x; y*=rhs.y; z*=rhs.z; return *this;}
+ inline v3& operator/=(const v3 &rhs) {x/=rhs.x; y/=rhs.y; z/=rhs.z; return *this;}
+
+ //scalar mult/div
+ inline v3& operator*=(const double s) {x*=s; y*=s; z*=s; return *this;}
+ inline v3& operator/=(const double s) {x/=s; y/=s; z/=s; return *this;}
+
+ inline const v3 operator+(const v3 &rhs) const {v3 v(*this); return v+=rhs;}
+ inline const v3 operator-(const v3 &rhs) const {v3 v(*this); return v-=rhs;}
+ inline const v3 operator*(const v3 &rhs) const {v3 v(*this); return v*=rhs;}
+ inline const v3 operator/(const v3 &rhs) const {v3 v(*this); return v/=rhs;}
+
+ inline const v3 operator*(const double s) const {v3 v(*this); return v*=s;}
+ inline const v3 operator/(const double s) const {v3 v(*this); return v/=s;}
+} Vect3D_t;
+
+//scalar vector multiplication s * v
+inline const v3 operator*(const double s, const v3 &rhs) {return rhs*s;}
+
+//output stream operator for Vect3D_t (handy for printing)
+inline std::ostream& operator<<(std::ostream& os, const Vect3D_t& v )
+{
+ stringstream ss;
+ ss << fixed << setprecision(2) << "(" << v.x << ", " << v.y << ", " << v.z << ")";
+
+ return os << ss.str();
+}
+
+#endif //VECT3D_H_ \ No newline at end of file