A quick implementation of Quaternion and Vector classes for use with my MPU9150 library

Dependents:   cool_step_new cool_step_1 SML2

Fork of QuaternionMath by Chris Pepper

Revision:
8:08d9c0010cc0
Parent:
4:1ced03aa8c75
--- a/Vector3.h	Thu Mar 26 15:41:59 2015 +0000
+++ b/Vector3.h	Mon Apr 20 13:38:01 2015 +0000
@@ -6,24 +6,19 @@
 class Vector3
 {
 public:
-    Vector3() {
-        x = y = z = 0;
-    }
+    Vector3() : x(0.0f), y(0.0f), z(0.0f) {}
+
+    Vector3(float const _x, float const _y, float const _z)
+        : x(_x), y(_y), z(_z) {}
 
-    Vector3(float x, float y, float z) {
-        this->x = x;
-        this->y = y;
-        this->z = z;
-    }
-
-    void set(float x, float y, float z) {
-        this->x = x;
-        this->y = y;
-        this->z = z;
+    void set(float const _x, float const _y, float const _z) {
+        x = _x;
+        y = _y;
+        z = _z;
     }
 
     float length_squared() const {
-        return x*x + y*y + z*z;
+        return x * x + y * y + z * z;
     }
 
     float length() const {
@@ -31,10 +26,10 @@
     }
 
     void normalise() {
-        float len = length();
-        x = x/len;
-        y = y/len;
-        z = z/len;
+        float const len = length();
+        x = x / len;
+        y = y / len;
+        z = z / len;
     }
 
     Vector3 normalised() const {
@@ -42,70 +37,61 @@
     }
 
     float dot_product(const Vector3 &v) const {
-        return x*v.x + y*v.y + z*v.z;
+        return x * v.x + y * v.y + z * v.z;
     }
 
     Vector3 cross_product(const Vector3 &v) const {
-        Vector3 temp(y*v.z - z*v.y, z*v.x - x*v.z, x*v.y - y*v.x);
+        Vector3 temp(y * v.z - z * v.y, z * v.x - x * v.z, x * v.y - y * v.x);
         return temp;
     }
 
-    //operator overides
-    void operator ()(const float x, const float y, const float z) {
-        this->x = x;
-        this->y = y;
-        this->z = z;
+    // operator overides
+    void operator()(const float _x, const float _y, const float _z) {
+        x = _x;
+        y = _y;
+        z = _z;
     }
 
-    bool operator == (const Vector3 &v) const {
-        return (x==v.x && y==v.y && z==v.z);
+    bool operator==(const Vector3 &v) const {
+        return (x == v.x && y == v.y && z == v.z);
     }
 
-    bool operator != (const Vector3 &v) const {
-        return (x!=v.x || y!=v.y || z!=v.z);
+    bool operator!=(const Vector3 &v) const {
+        return (x != v.x || y != v.y || z != v.z);
     }
 
-    const Vector3 &operator = (const Vector3 &v) {
+    const Vector3 &operator=(const Vector3 &v) {
         x = v.x;
         y = v.y;
         z = v.z;
         return *this;
     }
 
-    const Vector3 operator - (void) const {
-        return Vector3(-x,-y,-z);
+    const Vector3 operator-(void) const {
+        return Vector3(-x, -y, -z);
     }
 
-    const Vector3 operator + (const Vector3 &v) const {
-        return Vector3(x+v.x, y+v.y, z+v.z);
-    }
-
-    const Vector3 operator - (const Vector3 &v) const {
-        return Vector3(x-v.x, y-v.y, z-v.z);
+    const Vector3 operator+(const Vector3 &v) const {
+        return Vector3(x + v.x, y + v.y, z + v.z);
     }
 
-    const Vector3 operator * (const float num) const {
-        Vector3 temp;
-        temp.x = x * num;
-        temp.y = y * num;
-        temp.z = z * num;
-        return temp;
+    const Vector3 operator-(const Vector3 &v) const {
+        return Vector3(x - v.x, y - v.y, z - v.z);
     }
 
-    const Vector3 operator / (const float num) const {
-        Vector3 temp;
-        temp.x = x / num;
-        temp.y = y / num;
-        temp.z = z / num;
-        return temp;
+    const Vector3 operator*(const float num) const {
+        return Vector3(x * num, y * num, z * num);
     }
 
-    float operator * (const Vector3 &v) const {
-        return x*v.x + y*v.y + z*v.z;
+    const Vector3 operator/(const float num) const {
+        return Vector3(x / num, y / num, z / num);
+    }
+
+    float operator*(const Vector3 &v) const {
+        return x * v.x + y * v.y + z * v.z;
     }
 
     float x, y, z;
-
 };
 
 #endif
\ No newline at end of file