Sensor Scol plugin
Multi platform sensors for handled devices
Vector3d.h
1//
2// Vector3d.h
3//
4
5#ifndef __CardboardSDK_iOS__Vector3d__
6#define __CardboardSDK_iOS__Vector3d__
7
9{
10 friend class Matrix3x3d;
11 friend class SO3Util;
12
13 public:
14 Vector3d();
15 Vector3d(double x, double y, double z);
16 Vector3d(const Vector3d &other);
17 void set(double x, double y, double z);
18 void setComponent(int i, double val);
19 void setZero();
20 void set(Vector3d other);
21 void scale(double s);
22 void normalize();
23 static double dot(Vector3d a, Vector3d b);
24 double length();
25 bool sameValues(Vector3d other);
26 static void add(Vector3d a, Vector3d b, Vector3d &result);
27 static void sub(Vector3d a, Vector3d b, Vector3d &result);
28 static void cross(Vector3d a, Vector3d b, Vector3d &result);
29 static void ortho(Vector3d v, Vector3d &result);
30 static int largestAbsComponent(Vector3d v);
31
32 inline double getX() const { return x; }
33 inline double getY() const { return y; }
34 inline double getZ() const { return z; }
35
36 Vector3d CrossProduct(Vector3d other)
37 {
38 return Vector3d(y * other.z - z * other.y, z * other.x - x * other.z, x * other.y - y * other.x);
39 }
40
41 Vector3d operator-()
42 {
43 return Vector3d(-x, -y, -z);
44 }
45
46 Vector3d operator+=(Vector3d other)
47 {
48 return Vector3d(x + other.x, y + other.y, z + other.z);
49 }
50
51 Vector3d operator-=(Vector3d other)
52 {
53 return Vector3d(x - other.x, y - other.y, z - other.z);
54 }
55
56 Vector3d operator*=(float scalar)
57 {
58 return Vector3d(x * scalar, y * scalar, z * scalar);
59 }
60
61 Vector3d operator/=(float scalar)
62 {
63 return Vector3d(x / scalar, y / scalar, z / scalar);
64 }
65
66 double x;
67 double y;
68 double z;
69};
70
71//-----------------------------------------------------------------------
72// Vector3 binary operators
73inline Vector3d operator+(Vector3d u, Vector3d v)
74{
75 return Vector3d(u.x + v.x, u.y + v.y, u.z + v.z);
76}
77
78inline Vector3d operator-(Vector3d u, Vector3d v)
79{
80 return u + (-v);
81}
82
83inline Vector3d operator*(Vector3d u, float scalar)
84{
85 return Vector3d(u.x * scalar, u.y * scalar, u.z * scalar);
86}
87
88inline Vector3d operator*(float scalar, Vector3d u)
89{
90 return Vector3d(u.x * scalar, u.y * scalar, u.z * scalar);
91}
92
93inline Vector3d operator/(Vector3d u, float scalar)
94{
95 return Vector3d(u.x / scalar, u.y / scalar, u.z / scalar);
96}
97
98#endif