aboutsummaryrefslogtreecommitdiff
path: root/examples/ChainedPanelsAuroraDemo/Vector.h
diff options
context:
space:
mode:
authorKosso <kosso1@gmail.com>2020-09-13 15:56:29 +0100
committerKosso <kosso1@gmail.com>2020-09-13 15:56:29 +0100
commit0e4e9738b6ecbffa260cc8e5e8e4c4d9f1bf6499 (patch)
treeff2a812bd892cef0ec792b583df3fbab07d67f2b /examples/ChainedPanelsAuroraDemo/Vector.h
parenta3aedaefb1326c5781646a8a51c5d83e61dc0a57 (diff)
Kosso: Updated Aurora demo for chained virtual displays. Added a better Fire demo. Removed some old Aurora demos which just didn't work and saves some memory.
Diffstat (limited to 'examples/ChainedPanelsAuroraDemo/Vector.h')
-rw-r--r--examples/ChainedPanelsAuroraDemo/Vector.h169
1 files changed, 169 insertions, 0 deletions
diff --git a/examples/ChainedPanelsAuroraDemo/Vector.h b/examples/ChainedPanelsAuroraDemo/Vector.h
new file mode 100644
index 0000000..8acbadc
--- /dev/null
+++ b/examples/ChainedPanelsAuroraDemo/Vector.h
@@ -0,0 +1,169 @@
+/*
+ * Aurora: https://github.com/pixelmatix/aurora
+ * Copyright (c) 2014 Jason Coon
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
+ * this software and associated documentation files (the "Software"), to deal in
+ * the Software without restriction, including without limitation the rights to
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+ * the Software, and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+ * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+ * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef Vector_H
+#define Vector_H
+
+template <class T>
+class Vector2 {
+public:
+ T x, y;
+
+ Vector2() :x(0), y(0) {}
+ Vector2(T x, T y) : x(x), y(y) {}
+ Vector2(const Vector2& v) : x(v.x), y(v.y) {}
+
+ Vector2& operator=(const Vector2& v) {
+ x = v.x;
+ y = v.y;
+ return *this;
+ }
+
+ bool isEmpty() {
+ return x == 0 && y == 0;
+ }
+
+ bool operator==(Vector2& v) {
+ return x == v.x && y == v.y;
+ }
+
+ bool operator!=(Vector2& v) {
+ return !(x == y);
+ }
+
+ Vector2 operator+(Vector2& v) {
+ return Vector2(x + v.x, y + v.y);
+ }
+ Vector2 operator-(Vector2& v) {
+ return Vector2(x - v.x, y - v.y);
+ }
+
+ Vector2& operator+=(Vector2& v) {
+ x += v.x;
+ y += v.y;
+ return *this;
+ }
+ Vector2& operator-=(Vector2& v) {
+ x -= v.x;
+ y -= v.y;
+ return *this;
+ }
+
+ Vector2 operator+(double s) {
+ return Vector2(x + s, y + s);
+ }
+ Vector2 operator-(double s) {
+ return Vector2(x - s, y - s);
+ }
+ Vector2 operator*(double s) {
+ return Vector2(x * s, y * s);
+ }
+ Vector2 operator/(double s) {
+ return Vector2(x / s, y / s);
+ }
+
+ Vector2& operator+=(double s) {
+ x += s;
+ y += s;
+ return *this;
+ }
+ Vector2& operator-=(double s) {
+ x -= s;
+ y -= s;
+ return *this;
+ }
+ Vector2& operator*=(double s) {
+ x *= s;
+ y *= s;
+ return *this;
+ }
+ Vector2& operator/=(double s) {
+ x /= s;
+ y /= s;
+ return *this;
+ }
+
+ void set(T x, T y) {
+ this->x = x;
+ this->y = y;
+ }
+
+ void rotate(double deg) {
+ double theta = deg / 180.0 * M_PI;
+ double c = cos(theta);
+ double s = sin(theta);
+ double tx = x * c - y * s;
+ double ty = x * s + y * c;
+ x = tx;
+ y = ty;
+ }
+
+ Vector2& normalize() {
+ if (length() == 0) return *this;
+ *this *= (1.0 / length());
+ return *this;
+ }
+
+ float dist(Vector2 v) const {
+ Vector2 d(v.x - x, v.y - y);
+ return d.length();
+ }
+ float length() const {
+ return sqrt(x * x + y * y);
+ }
+
+ float mag() const {
+ return length();
+ }
+
+ float magSq() {
+ return (x * x + y * y);
+ }
+
+ void truncate(double length) {
+ double angle = atan2f(y, x);
+ x = length * cos(angle);
+ y = length * sin(angle);
+ }
+
+ Vector2 ortho() const {
+ return Vector2(y, -x);
+ }
+
+ static float dot(Vector2 v1, Vector2 v2) {
+ return v1.x * v2.x + v1.y * v2.y;
+ }
+ static float cross(Vector2 v1, Vector2 v2) {
+ return (v1.x * v2.y) - (v1.y * v2.x);
+ }
+
+ void limit(float max) {
+ if (magSq() > max*max) {
+ normalize();
+ *this *= max;
+ }
+ }
+};
+
+typedef Vector2<float> PVector;
+
+#endif