From 828eed1984ff355c2122511c55b353ebd0d9c1fa Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 29 Dec 2013 18:37:14 +1100 Subject: [PATCH] AP_Math: allow vector3 and matrix3 objects to be used as arrays --- libraries/AP_Math/matrix3.h | 6 ++++++ libraries/AP_Math/vector3.h | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/libraries/AP_Math/matrix3.h b/libraries/AP_Math/matrix3.h index 34ddadb754..21618d1da3 100644 --- a/libraries/AP_Math/matrix3.h +++ b/libraries/AP_Math/matrix3.h @@ -125,6 +125,12 @@ public: return *this = *this / num; } + // allow a Matrix3 to be used as an array of vectors, 0 indexed + Vector3 & operator[](uint8_t i) { + Vector3 *_v = &a; + return _v[i]; + } + // multiplication by a vector Vector3 operator *(const Vector3 &v) const; diff --git a/libraries/AP_Math/vector3.h b/libraries/AP_Math/vector3.h index 83b31a6b90..403b62e50b 100644 --- a/libraries/AP_Math/vector3.h +++ b/libraries/AP_Math/vector3.h @@ -111,6 +111,12 @@ public: // uniform scaling Vector3 &operator /=(const T num); + // allow a vector3 to be used as an array, 0 indexed + T & operator[](uint8_t i) { + T *_v = &x; + return _v[i]; + } + // dot product T operator *(const Vector3 &v) const;