summaryrefslogtreecommitdiffstats
path: root/wiimote_ir_smoothing/Vect3D.h
blob: 82659fcf8d3dc72cd997611015d9d34173661f2f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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_