git subrepo clone --branch=sono6good https://github.com/essej/JUCE.git deps/juce
subrepo: subdir: "deps/juce" merged: "b13f9084e" upstream: origin: "https://github.com/essej/JUCE.git" branch: "sono6good" commit: "b13f9084e" git-subrepo: version: "0.4.3" origin: "https://github.com/ingydotnet/git-subrepo.git" commit: "2f68596"
This commit is contained in:
159
deps/juce/modules/juce_opengl/geometry/juce_Draggable3DOrientation.h
vendored
Normal file
159
deps/juce/modules/juce_opengl/geometry/juce_Draggable3DOrientation.h
vendored
Normal file
@ -0,0 +1,159 @@
|
||||
/*
|
||||
==============================================================================
|
||||
|
||||
This file is part of the JUCE library.
|
||||
Copyright (c) 2020 - Raw Material Software Limited
|
||||
|
||||
JUCE is an open source library subject to commercial or open-source
|
||||
licensing.
|
||||
|
||||
By using JUCE, you agree to the terms of both the JUCE 6 End-User License
|
||||
Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020).
|
||||
|
||||
End User License Agreement: www.juce.com/juce-6-licence
|
||||
Privacy Policy: www.juce.com/juce-privacy-policy
|
||||
|
||||
Or: You may also use this code under the terms of the GPL v3 (see
|
||||
www.gnu.org/licenses).
|
||||
|
||||
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
|
||||
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
|
||||
DISCLAIMED.
|
||||
|
||||
==============================================================================
|
||||
*/
|
||||
|
||||
namespace juce
|
||||
{
|
||||
|
||||
//==============================================================================
|
||||
/**
|
||||
Stores a 3D orientation, which can be rotated by dragging with the mouse.
|
||||
|
||||
@tags{OpenGL}
|
||||
*/
|
||||
class Draggable3DOrientation
|
||||
{
|
||||
public:
|
||||
using VectorType = Vector3D<float>;
|
||||
using QuaternionType = Quaternion<float>;
|
||||
|
||||
/** Creates a Draggable3DOrientation, initially set up to be aligned along the X axis. */
|
||||
Draggable3DOrientation (float objectRadius = 0.5f) noexcept
|
||||
: radius (jmax (0.1f, objectRadius)),
|
||||
quaternion (VectorType::xAxis(), 0)
|
||||
{
|
||||
}
|
||||
|
||||
/** Creates a Draggable3DOrientation from a user-supplied quaternion. */
|
||||
Draggable3DOrientation (const Quaternion<float>& quaternionToUse,
|
||||
float objectRadius = 0.5f) noexcept
|
||||
: radius (jmax (0.1f, objectRadius)),
|
||||
quaternion (quaternionToUse)
|
||||
{
|
||||
}
|
||||
|
||||
/** Resets the orientation, specifying the axis to align it along. */
|
||||
void reset (const VectorType& axis) noexcept
|
||||
{
|
||||
quaternion = QuaternionType (axis, 0);
|
||||
}
|
||||
|
||||
/** Sets the viewport area within which mouse-drag positions will occur.
|
||||
You'll need to set this rectangle before calling mouseDown. The centre of the
|
||||
rectangle is assumed to be the centre of the object that will be rotated, and
|
||||
the size of the rectangle will be used to scale the object radius - see setRadius().
|
||||
*/
|
||||
void setViewport (Rectangle<int> newArea) noexcept
|
||||
{
|
||||
area = newArea;
|
||||
}
|
||||
|
||||
/** Sets the size of the rotated object, as a proportion of the viewport's size.
|
||||
@see setViewport
|
||||
*/
|
||||
void setRadius (float newRadius) noexcept
|
||||
{
|
||||
radius = jmax (0.1f, newRadius);
|
||||
}
|
||||
|
||||
/** Begins a mouse-drag operation.
|
||||
You must call this before any calls to mouseDrag(). The position that is supplied
|
||||
will be treated as being relative to the centre of the rectangle passed to setViewport().
|
||||
*/
|
||||
template <typename Type>
|
||||
void mouseDown (Point<Type> mousePos) noexcept
|
||||
{
|
||||
lastMouse = mousePosToProportion (mousePos.toFloat());
|
||||
}
|
||||
|
||||
/** Continues a mouse-drag operation.
|
||||
After calling mouseDown() to begin a drag sequence, you can call this method
|
||||
to continue it.
|
||||
*/
|
||||
template <typename Type>
|
||||
void mouseDrag (Point<Type> mousePos) noexcept
|
||||
{
|
||||
auto oldPos = projectOnSphere (lastMouse);
|
||||
lastMouse = mousePosToProportion (mousePos.toFloat());
|
||||
auto newPos = projectOnSphere (lastMouse);
|
||||
|
||||
quaternion *= rotationFromMove (oldPos, newPos);
|
||||
}
|
||||
|
||||
/** Returns the matrix that should be used to apply the current orientation.
|
||||
@see applyToOpenGLMatrix
|
||||
*/
|
||||
Matrix3D<float> getRotationMatrix() const noexcept
|
||||
{
|
||||
return quaternion.getRotationMatrix();
|
||||
}
|
||||
|
||||
/** Provides direct access to the quaternion. */
|
||||
QuaternionType& getQuaternion() noexcept
|
||||
{
|
||||
return quaternion;
|
||||
}
|
||||
|
||||
private:
|
||||
Rectangle<int> area;
|
||||
float radius;
|
||||
QuaternionType quaternion;
|
||||
Point<float> lastMouse;
|
||||
|
||||
Point<float> mousePosToProportion (Point<float> mousePos) const noexcept
|
||||
{
|
||||
auto scale = jmin (area.getWidth(), area.getHeight()) / 2;
|
||||
|
||||
// You must call setViewport() to give this object a valid window size before
|
||||
// calling any of the mouse input methods!
|
||||
jassert (scale > 0);
|
||||
|
||||
return { (mousePos.x - (float) area.getCentreX()) / (float) scale,
|
||||
((float) area.getCentreY() - mousePos.y) / (float) scale };
|
||||
}
|
||||
|
||||
VectorType projectOnSphere (Point<float> pos) const noexcept
|
||||
{
|
||||
auto radiusSquared = radius * radius;
|
||||
auto xySquared = pos.x * pos.x + pos.y * pos.y;
|
||||
|
||||
return { pos.x, pos.y,
|
||||
xySquared < radiusSquared * 0.5f ? std::sqrt (radiusSquared - xySquared)
|
||||
: (radiusSquared / (2.0f * std::sqrt (xySquared))) };
|
||||
}
|
||||
|
||||
QuaternionType rotationFromMove (const VectorType& from, const VectorType& to) const noexcept
|
||||
{
|
||||
auto rotationAxis = (to ^ from);
|
||||
|
||||
if (rotationAxis.lengthIsBelowEpsilon())
|
||||
rotationAxis = VectorType::xAxis();
|
||||
|
||||
auto d = jlimit (-1.0f, 1.0f, (from - to).length() / (2.0f * radius));
|
||||
|
||||
return QuaternionType::fromAngle (2.0f * std::asin (d), rotationAxis);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace juce
|
154
deps/juce/modules/juce_opengl/geometry/juce_Matrix3D.h
vendored
Normal file
154
deps/juce/modules/juce_opengl/geometry/juce_Matrix3D.h
vendored
Normal file
@ -0,0 +1,154 @@
|
||||
/*
|
||||
==============================================================================
|
||||
|
||||
This file is part of the JUCE library.
|
||||
Copyright (c) 2020 - Raw Material Software Limited
|
||||
|
||||
JUCE is an open source library subject to commercial or open-source
|
||||
licensing.
|
||||
|
||||
By using JUCE, you agree to the terms of both the JUCE 6 End-User License
|
||||
Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020).
|
||||
|
||||
End User License Agreement: www.juce.com/juce-6-licence
|
||||
Privacy Policy: www.juce.com/juce-privacy-policy
|
||||
|
||||
Or: You may also use this code under the terms of the GPL v3 (see
|
||||
www.gnu.org/licenses).
|
||||
|
||||
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
|
||||
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
|
||||
DISCLAIMED.
|
||||
|
||||
==============================================================================
|
||||
*/
|
||||
|
||||
namespace juce
|
||||
{
|
||||
|
||||
//==============================================================================
|
||||
/**
|
||||
A 4x4 3D transformation matrix.
|
||||
|
||||
@see Vector3D, Quaternion, AffineTransform
|
||||
|
||||
@tags{OpenGL}
|
||||
*/
|
||||
template <typename Type>
|
||||
class Matrix3D
|
||||
{
|
||||
public:
|
||||
/** Creates an identity matrix. */
|
||||
Matrix3D() noexcept
|
||||
{
|
||||
mat[0] = Type (1); mat[1] = 0; mat[2] = 0; mat[3] = 0;
|
||||
mat[4] = 0; mat[5] = Type (1); mat[6] = 0; mat[7] = 0;
|
||||
mat[8] = 0; mat[9] = 0; mat[10] = Type (1); mat[11] = 0;
|
||||
mat[12] = 0; mat[13] = 0; mat[14] = 0; mat[15] = Type (1);
|
||||
}
|
||||
|
||||
/** Creates a copy of another matrix. */
|
||||
Matrix3D (const Matrix3D& other) noexcept
|
||||
{
|
||||
memcpy (mat, other.mat, sizeof (mat));
|
||||
}
|
||||
|
||||
/** Copies another matrix. */
|
||||
Matrix3D& operator= (const Matrix3D& other) noexcept
|
||||
{
|
||||
memcpy (mat, other.mat, sizeof (mat));
|
||||
return *this;
|
||||
}
|
||||
|
||||
/** Creates a matrix from its raw 4x4 values. */
|
||||
Matrix3D (Type m00, Type m10, Type m20, Type m30,
|
||||
Type m01, Type m11, Type m21, Type m31,
|
||||
Type m02, Type m12, Type m22, Type m32,
|
||||
Type m03, Type m13, Type m23, Type m33) noexcept
|
||||
{
|
||||
mat[0] = m00; mat[1] = m10; mat[2] = m20; mat[3] = m30;
|
||||
mat[4] = m01; mat[5] = m11; mat[6] = m21; mat[7] = m31;
|
||||
mat[8] = m02; mat[9] = m12; mat[10] = m22; mat[11] = m32;
|
||||
mat[12] = m03; mat[13] = m13; mat[14] = m23; mat[15] = m33;
|
||||
}
|
||||
|
||||
/** Creates a matrix from an array of 16 raw values. */
|
||||
Matrix3D (const Type* values) noexcept
|
||||
{
|
||||
memcpy (mat, values, sizeof (mat));
|
||||
}
|
||||
|
||||
/** Creates a matrix from a 2D affine transform. */
|
||||
Matrix3D (const AffineTransform& transform) noexcept
|
||||
{
|
||||
mat[0] = transform.mat00; mat[1] = transform.mat10; mat[2] = 0; mat[3] = 0;
|
||||
mat[4] = transform.mat01; mat[5] = transform.mat11; mat[6] = 0; mat[7] = 0;
|
||||
mat[8] = 0; mat[9] = 0; mat[10] = Type (1); mat[11] = 0;
|
||||
mat[12] = transform.mat02; mat[13] = transform.mat12; mat[14] = 0; mat[15] = Type (1);
|
||||
}
|
||||
|
||||
/** Creates a matrix from a 3D vector translation. */
|
||||
Matrix3D (Vector3D<Type> vector) noexcept
|
||||
{
|
||||
mat[0] = Type (1); mat[1] = 0; mat[2] = 0; mat[3] = 0;
|
||||
mat[4] = 0; mat[5] = Type (1); mat[6] = 0; mat[7] = 0;
|
||||
mat[8] = 0; mat[9] = 0; mat[10] = Type (1); mat[11] = 0;
|
||||
mat[12] = vector.x; mat[13] = vector.y; mat[14] = vector.z; mat[15] = Type (1);
|
||||
}
|
||||
|
||||
/** Returns a new matrix from the given frustum values. */
|
||||
static Matrix3D fromFrustum (Type left, Type right, Type bottom, Type top, Type nearDistance, Type farDistance) noexcept
|
||||
{
|
||||
return { (Type (2) * nearDistance) / (right - left), 0, 0, 0,
|
||||
0, (Type (2) * nearDistance) / (top - bottom), 0, 0,
|
||||
(right + left) / (right - left), (top + bottom) / (top - bottom), -(farDistance + nearDistance) / (farDistance - nearDistance), Type (-1),
|
||||
0, 0, -(Type (2) * farDistance * nearDistance) / (farDistance - nearDistance), 0 };
|
||||
}
|
||||
|
||||
/** Returns a matrix which will apply a rotation through the Y, X and Z angles specified by a vector. */
|
||||
static Matrix3D rotation (Vector3D<Type> eulerAngleRadians) noexcept
|
||||
{
|
||||
auto cx = std::cos (eulerAngleRadians.x), sx = std::sin (eulerAngleRadians.x),
|
||||
cy = std::cos (eulerAngleRadians.y), sy = std::sin (eulerAngleRadians.y),
|
||||
cz = std::cos (eulerAngleRadians.z), sz = std::sin (eulerAngleRadians.z);
|
||||
|
||||
return { (cy * cz) + (sx * sy * sz), cx * sz, (cy * sx * sz) - (cz * sy), 0,
|
||||
(cz * sx * sy) - (cy * sz), cx * cz, (cy * cz * sx) + (sy * sz), 0,
|
||||
cx * sy, -sx, cx * cy, 0,
|
||||
0, 0, 0, Type (1) };
|
||||
}
|
||||
|
||||
/** Multiplies this matrix by another. */
|
||||
Matrix3D& operator*= (const Matrix3D& other) noexcept
|
||||
{
|
||||
return *this = *this * other;
|
||||
}
|
||||
|
||||
/** Multiplies this matrix by another, and returns the result. */
|
||||
Matrix3D operator* (const Matrix3D& other) const noexcept
|
||||
{
|
||||
auto&& m2 = other.mat;
|
||||
|
||||
return { mat[0] * m2[0] + mat[1] * m2[4] + mat[2] * m2[8] + mat[3] * m2[12],
|
||||
mat[0] * m2[1] + mat[1] * m2[5] + mat[2] * m2[9] + mat[3] * m2[13],
|
||||
mat[0] * m2[2] + mat[1] * m2[6] + mat[2] * m2[10] + mat[3] * m2[14],
|
||||
mat[0] * m2[3] + mat[1] * m2[7] + mat[2] * m2[11] + mat[3] * m2[15],
|
||||
mat[4] * m2[0] + mat[5] * m2[4] + mat[6] * m2[8] + mat[7] * m2[12],
|
||||
mat[4] * m2[1] + mat[5] * m2[5] + mat[6] * m2[9] + mat[7] * m2[13],
|
||||
mat[4] * m2[2] + mat[5] * m2[6] + mat[6] * m2[10] + mat[7] * m2[14],
|
||||
mat[4] * m2[3] + mat[5] * m2[7] + mat[6] * m2[11] + mat[7] * m2[15],
|
||||
mat[8] * m2[0] + mat[9] * m2[4] + mat[10] * m2[8] + mat[11] * m2[12],
|
||||
mat[8] * m2[1] + mat[9] * m2[5] + mat[10] * m2[9] + mat[11] * m2[13],
|
||||
mat[8] * m2[2] + mat[9] * m2[6] + mat[10] * m2[10] + mat[11] * m2[14],
|
||||
mat[8] * m2[3] + mat[9] * m2[7] + mat[10] * m2[11] + mat[11] * m2[15],
|
||||
mat[12] * m2[0] + mat[13] * m2[4] + mat[14] * m2[8] + mat[15] * m2[12],
|
||||
mat[12] * m2[1] + mat[13] * m2[5] + mat[14] * m2[9] + mat[15] * m2[13],
|
||||
mat[12] * m2[2] + mat[13] * m2[6] + mat[14] * m2[10] + mat[15] * m2[14],
|
||||
mat[12] * m2[3] + mat[13] * m2[7] + mat[14] * m2[11] + mat[15] * m2[15] };
|
||||
}
|
||||
|
||||
/** The 4x4 matrix values. These are stored in the standard OpenGL order. */
|
||||
Type mat[16];
|
||||
};
|
||||
|
||||
} // namespace juce
|
98
deps/juce/modules/juce_opengl/geometry/juce_Quaternion.h
vendored
Normal file
98
deps/juce/modules/juce_opengl/geometry/juce_Quaternion.h
vendored
Normal file
@ -0,0 +1,98 @@
|
||||
/*
|
||||
==============================================================================
|
||||
|
||||
This file is part of the JUCE library.
|
||||
Copyright (c) 2020 - Raw Material Software Limited
|
||||
|
||||
JUCE is an open source library subject to commercial or open-source
|
||||
licensing.
|
||||
|
||||
By using JUCE, you agree to the terms of both the JUCE 6 End-User License
|
||||
Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020).
|
||||
|
||||
End User License Agreement: www.juce.com/juce-6-licence
|
||||
Privacy Policy: www.juce.com/juce-privacy-policy
|
||||
|
||||
Or: You may also use this code under the terms of the GPL v3 (see
|
||||
www.gnu.org/licenses).
|
||||
|
||||
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
|
||||
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
|
||||
DISCLAIMED.
|
||||
|
||||
==============================================================================
|
||||
*/
|
||||
|
||||
namespace juce
|
||||
{
|
||||
|
||||
//==============================================================================
|
||||
/**
|
||||
Holds a quaternion (a 3D vector and a scalar value).
|
||||
|
||||
@tags{OpenGL}
|
||||
*/
|
||||
template <typename Type>
|
||||
class Quaternion
|
||||
{
|
||||
public:
|
||||
Quaternion() noexcept : scalar() {}
|
||||
Quaternion (const Quaternion& other) noexcept : vector (other.vector), scalar (other.scalar) {}
|
||||
Quaternion (Vector3D<Type> vectorPart, Type scalarPart) noexcept : vector (vectorPart), scalar (scalarPart) {}
|
||||
Quaternion (Type x, Type y, Type z, Type w) noexcept : vector (x, y, z), scalar (w) {}
|
||||
|
||||
/** Creates a quaternion from an angle and an axis. */
|
||||
static Quaternion fromAngle (Type angle, Vector3D<Type> axis) noexcept
|
||||
{
|
||||
return Quaternion (axis.normalised() * std::sin (angle / (Type) 2), std::cos (angle / (Type) 2));
|
||||
}
|
||||
|
||||
Quaternion& operator= (Quaternion other) noexcept
|
||||
{
|
||||
vector = other.vector;
|
||||
scalar = other.scalar;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Quaternion& operator*= (Quaternion other) noexcept
|
||||
{
|
||||
const Type oldScalar (scalar);
|
||||
scalar = (scalar * other.scalar) - (vector * other.vector);
|
||||
vector = (other.vector * oldScalar) + (vector * other.scalar) + (vector ^ other.vector);
|
||||
return *this;
|
||||
}
|
||||
|
||||
Type length() const noexcept { return std::sqrt (normal()); }
|
||||
Type normal() const noexcept { return scalar * scalar + vector.lengthSquared(); }
|
||||
|
||||
Quaternion normalised() const noexcept
|
||||
{
|
||||
const Type len (length());
|
||||
jassert (len > 0);
|
||||
return Quaternion (vector / len, scalar / len);
|
||||
}
|
||||
|
||||
/** Returns the matrix that will perform the rotation specified by this quaternion. */
|
||||
Matrix3D<Type> getRotationMatrix() const noexcept
|
||||
{
|
||||
const Type norm (normal());
|
||||
const Type s (norm > 0 ? ((Type) 2) / norm : 0);
|
||||
const Type xs (s * vector.x), ys (s * vector.y), zs (s * vector.z);
|
||||
const Type wx (xs * scalar), wy (ys * scalar), wz (zs * scalar);
|
||||
const Type xx (xs * vector.x), xy (ys * vector.x), xz (zs * vector.x);
|
||||
const Type yy (ys * vector.y), yz (zs * vector.y), zz (zs * vector.z);
|
||||
|
||||
return Matrix3D<Type> (((Type) 1) - (yy + zz), xy - wz, xz + wy, 0,
|
||||
xy + wz, ((Type) 1) - (xx+ zz), yz - wx, 0,
|
||||
xz - wy, yz + wx, ((Type) 1) - (xx + yy), 0,
|
||||
0, 0, 0, (Type) 1);
|
||||
}
|
||||
|
||||
/** The vector part of the quaternion. */
|
||||
Vector3D<Type> vector;
|
||||
|
||||
/** The scalar part of the quaternion. */
|
||||
Type scalar;
|
||||
};
|
||||
|
||||
} // namespace juce
|
83
deps/juce/modules/juce_opengl/geometry/juce_Vector3D.h
vendored
Normal file
83
deps/juce/modules/juce_opengl/geometry/juce_Vector3D.h
vendored
Normal file
@ -0,0 +1,83 @@
|
||||
/*
|
||||
==============================================================================
|
||||
|
||||
This file is part of the JUCE library.
|
||||
Copyright (c) 2020 - Raw Material Software Limited
|
||||
|
||||
JUCE is an open source library subject to commercial or open-source
|
||||
licensing.
|
||||
|
||||
By using JUCE, you agree to the terms of both the JUCE 6 End-User License
|
||||
Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020).
|
||||
|
||||
End User License Agreement: www.juce.com/juce-6-licence
|
||||
Privacy Policy: www.juce.com/juce-privacy-policy
|
||||
|
||||
Or: You may also use this code under the terms of the GPL v3 (see
|
||||
www.gnu.org/licenses).
|
||||
|
||||
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
|
||||
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
|
||||
DISCLAIMED.
|
||||
|
||||
==============================================================================
|
||||
*/
|
||||
|
||||
namespace juce
|
||||
{
|
||||
|
||||
//==============================================================================
|
||||
/**
|
||||
A three-coordinate vector.
|
||||
|
||||
@tags{OpenGL}
|
||||
*/
|
||||
template <typename Type>
|
||||
class Vector3D
|
||||
{
|
||||
public:
|
||||
Vector3D() noexcept : x(), y(), z() {}
|
||||
Vector3D (Type xValue, Type yValue, Type zValue) noexcept : x (xValue), y (yValue), z (zValue) {}
|
||||
Vector3D (const Vector3D& other) noexcept : x (other.x), y (other.y), z (other.z) {}
|
||||
Vector3D& operator= (Vector3D other) noexcept { x = other.x; y = other.y; z = other.z; return *this; }
|
||||
|
||||
/** Returns a vector that lies along the X axis. */
|
||||
static Vector3D xAxis() noexcept { return { (Type) 1, 0, 0 }; }
|
||||
/** Returns a vector that lies along the Y axis. */
|
||||
static Vector3D yAxis() noexcept { return { 0, (Type) 1, 0 }; }
|
||||
/** Returns a vector that lies along the Z axis. */
|
||||
static Vector3D zAxis() noexcept { return { 0, 0, (Type) 1 }; }
|
||||
|
||||
Vector3D& operator+= (Vector3D other) noexcept { x += other.x; y += other.y; z += other.z; return *this; }
|
||||
Vector3D& operator-= (Vector3D other) noexcept { x -= other.x; y -= other.y; z -= other.z; return *this; }
|
||||
Vector3D& operator*= (Type scaleFactor) noexcept { x *= scaleFactor; y *= scaleFactor; z *= scaleFactor; return *this; }
|
||||
Vector3D& operator/= (Type scaleFactor) noexcept { x /= scaleFactor; y /= scaleFactor; z /= scaleFactor; return *this; }
|
||||
|
||||
Vector3D operator+ (Vector3D other) const noexcept { return { x + other.x, y + other.y, z + other.z }; }
|
||||
Vector3D operator- (Vector3D other) const noexcept { return { x - other.x, y - other.y, z - other.z }; }
|
||||
Vector3D operator* (Type scaleFactor) const noexcept { return { x * scaleFactor, y * scaleFactor, z * scaleFactor }; }
|
||||
Vector3D operator/ (Type scaleFactor) const noexcept { return { x / scaleFactor, y / scaleFactor, z / scaleFactor }; }
|
||||
Vector3D operator-() const noexcept { return { -x, -y, -z }; }
|
||||
|
||||
/** Returns the dot-product of these two vectors. */
|
||||
Type operator* (Vector3D other) const noexcept { return x * other.x + y * other.y + z * other.z; }
|
||||
|
||||
/** Returns the cross-product of these two vectors. */
|
||||
Vector3D operator^ (Vector3D other) const noexcept { return { y * other.z - z * other.y, z * other.x - x * other.z, x * other.y - y * other.x }; }
|
||||
|
||||
Type length() const noexcept { return std::sqrt (lengthSquared()); }
|
||||
Type lengthSquared() const noexcept { return x * x + y * y + z * z; }
|
||||
|
||||
Vector3D normalised() const noexcept { return *this / length(); }
|
||||
|
||||
/** Returns true if the vector is practically equal to the origin. */
|
||||
bool lengthIsBelowEpsilon() const noexcept
|
||||
{
|
||||
auto epsilon = std::numeric_limits<Type>::epsilon();
|
||||
return ! (x < -epsilon || x > epsilon || y < -epsilon || y > epsilon || z < -epsilon || z > epsilon);
|
||||
}
|
||||
|
||||
Type x, y, z;
|
||||
};
|
||||
|
||||
} // namespace juce
|
Reference in New Issue
Block a user