mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-14 00:14:18 +00:00
Added Animated App template and examples
This commit is contained in:
parent
fefcf7aca6
commit
ff6520a89a
1141 changed files with 438491 additions and 94 deletions
|
|
@ -0,0 +1,157 @@
|
|||
/*
|
||||
==============================================================================
|
||||
|
||||
This file is part of the JUCE library.
|
||||
Copyright (c) 2013 - Raw Material Software Ltd.
|
||||
|
||||
Permission is granted to use this software under the terms of either:
|
||||
a) the GPL v2 (or any later version)
|
||||
b) the Affero GPL v3
|
||||
|
||||
Details of these licenses can be found at: www.gnu.org/licenses
|
||||
|
||||
JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
To release a closed-source product which uses JUCE, commercial licenses are
|
||||
available: visit www.juce.com for more information.
|
||||
|
||||
==============================================================================
|
||||
*/
|
||||
|
||||
#ifndef JUCE_DRAGGABLE3DORIENTATION_H_INCLUDED
|
||||
#define JUCE_DRAGGABLE3DORIENTATION_H_INCLUDED
|
||||
|
||||
|
||||
//==============================================================================
|
||||
/**
|
||||
Stores a 3D orientation, which can be rotated by dragging with the mouse.
|
||||
*/
|
||||
class Draggable3DOrientation
|
||||
{
|
||||
public:
|
||||
typedef Vector3D<GLfloat> VectorType;
|
||||
typedef Quaternion<GLfloat> QuaternionType;
|
||||
|
||||
/** 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<GLfloat>& 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 (const 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
|
||||
{
|
||||
const VectorType oldPos (projectOnSphere (lastMouse));
|
||||
lastMouse = mousePosToProportion (mousePos.toFloat());
|
||||
const VectorType newPos (projectOnSphere (lastMouse));
|
||||
|
||||
quaternion *= rotationFromMove (oldPos, newPos);
|
||||
}
|
||||
|
||||
/** Returns the matrix that should be used to apply the current orientation.
|
||||
@see applyToOpenGLMatrix
|
||||
*/
|
||||
Matrix3D<GLfloat> 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 (const Point<float> mousePos) const noexcept
|
||||
{
|
||||
const int 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 Point<float> ((mousePos.x - area.getCentreX()) / scale,
|
||||
(area.getCentreY() - mousePos.y) / scale);
|
||||
}
|
||||
|
||||
VectorType projectOnSphere (const Point<float> pos) const noexcept
|
||||
{
|
||||
const GLfloat radiusSquared = radius * radius;
|
||||
const GLfloat xySquared = pos.x * pos.x + pos.y * pos.y;
|
||||
|
||||
return VectorType (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
|
||||
{
|
||||
VectorType rotationAxis (to ^ from);
|
||||
|
||||
if (rotationAxis.lengthIsBelowEpsilon())
|
||||
rotationAxis = VectorType::xAxis();
|
||||
|
||||
const GLfloat d = jlimit (-1.0f, 1.0f, (from - to).length() / (2.0f * radius));
|
||||
|
||||
return QuaternionType::fromAngle (2.0f * std::asin (d), rotationAxis);
|
||||
}
|
||||
};
|
||||
|
||||
#endif // JUCE_DRAGGABLE3DORIENTATION_H_INCLUDED
|
||||
|
|
@ -0,0 +1,154 @@
|
|||
/*
|
||||
==============================================================================
|
||||
|
||||
This file is part of the JUCE library.
|
||||
Copyright (c) 2013 - Raw Material Software Ltd.
|
||||
|
||||
Permission is granted to use this software under the terms of either:
|
||||
a) the GPL v2 (or any later version)
|
||||
b) the Affero GPL v3
|
||||
|
||||
Details of these licenses can be found at: www.gnu.org/licenses
|
||||
|
||||
JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
To release a closed-source product which uses JUCE, commercial licenses are
|
||||
available: visit www.juce.com for more information.
|
||||
|
||||
==============================================================================
|
||||
*/
|
||||
|
||||
#ifndef JUCE_MATRIX3D_H_INCLUDED
|
||||
#define JUCE_MATRIX3D_H_INCLUDED
|
||||
|
||||
//==============================================================================
|
||||
/**
|
||||
A 4x4 3D transformation matrix.
|
||||
|
||||
@see Vector3D, Quaternion, AffineTransform
|
||||
*/
|
||||
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 (const Type& m00, const Type& m10, const Type& m20, const Type& m30,
|
||||
const Type& m01, const Type& m11, const Type& m21, const Type& m31,
|
||||
const Type& m02, const Type& m12, const Type& m22, const Type& m32,
|
||||
const Type& m03, const Type& m13, const Type& m23, const 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 frustrum values. */
|
||||
static Matrix3D fromFrustum (Type left, Type right, Type bottom, Type top, Type nearDistance, Type farDistance) noexcept
|
||||
{
|
||||
return Matrix3D ((2.0f * nearDistance) / (right - left), 0.0f, 0.0f, 0.0f,
|
||||
0.0f, (2.0f * nearDistance) / (top - bottom), 0.0f, 0.0f,
|
||||
(right + left) / (right - left), (top + bottom) / (top - bottom), -(farDistance + nearDistance) / (farDistance - nearDistance), -1.0f,
|
||||
0.0f, 0.0f, -(2.0f * farDistance * nearDistance) / (farDistance - nearDistance), 0.0f);
|
||||
}
|
||||
|
||||
/** 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
|
||||
{
|
||||
const Type* const m2 = other.mat;
|
||||
|
||||
return Matrix3D (mat[0] * m2[0] + mat[4] * m2[1] + mat[8] * m2[2] + mat[12] * m2[3],
|
||||
mat[1] * m2[0] + mat[5] * m2[1] + mat[9] * m2[2] + mat[13] * m2[3],
|
||||
mat[2] * m2[0] + mat[6] * m2[1] + mat[10] * m2[2] + mat[14] * m2[3],
|
||||
mat[3] * m2[0] + mat[7] * m2[1] + mat[11] * m2[2] + mat[15] * m2[3],
|
||||
mat[0] * m2[4] + mat[4] * m2[5] + mat[8] * m2[6] + mat[12] * m2[7],
|
||||
mat[1] * m2[4] + mat[5] * m2[5] + mat[9] * m2[6] + mat[13] * m2[7],
|
||||
mat[2] * m2[4] + mat[6] * m2[5] + mat[10] * m2[6] + mat[14] * m2[7],
|
||||
mat[3] * m2[4] + mat[7] * m2[5] + mat[11] * m2[6] + mat[15] * m2[7],
|
||||
mat[0] * m2[8] + mat[4] * m2[9] + mat[8] * m2[10] + mat[12] * m2[11],
|
||||
mat[1] * m2[8] + mat[5] * m2[9] + mat[9] * m2[10] + mat[13] * m2[11],
|
||||
mat[2] * m2[8] + mat[6] * m2[9] + mat[10] * m2[10] + mat[14] * m2[11],
|
||||
mat[3] * m2[8] + mat[7] * m2[9] + mat[11] * m2[10] + mat[15] * m2[11],
|
||||
mat[0] * m2[12] + mat[4] * m2[13] + mat[8] * m2[14] + mat[12] * m2[15],
|
||||
mat[1] * m2[12] + mat[5] * m2[13] + mat[9] * m2[14] + mat[13] * m2[15],
|
||||
mat[2] * m2[12] + mat[6] * m2[13] + mat[10] * m2[14] + mat[14] * m2[15],
|
||||
mat[3] * m2[12] + mat[7] * m2[13] + mat[11] * m2[14] + mat[15] * m2[15]);
|
||||
}
|
||||
|
||||
/** Returns a copy of this matrix after rotation through the Y, X and then Z angles
|
||||
specified by the vector.
|
||||
*/
|
||||
Matrix3D rotated (Vector3D<Type> eulerAngleRadians) const noexcept
|
||||
{
|
||||
const Type 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 Matrix3D ((cy * cz) + (sx * sy * sz), cx * sz, (cy * sx * sz) - (cz * sy), 0.0f,
|
||||
(cz * sx * sy) - (cy * sz), cx * cz, (cy * cz * sx) + (sy * sz), 0.0f,
|
||||
cx * sy, -sx, cx * cy, 0.0f,
|
||||
0.0f, 0.0f, 0.0f, 1.0f);
|
||||
}
|
||||
|
||||
/** The 4x4 matrix values. These are stored in the standard OpenGL order. */
|
||||
Type mat[16];
|
||||
};
|
||||
|
||||
|
||||
#endif // JUCE_MATRIX3D_H_INCLUDED
|
||||
|
|
@ -0,0 +1,99 @@
|
|||
/*
|
||||
==============================================================================
|
||||
|
||||
This file is part of the JUCE library.
|
||||
Copyright (c) 2013 - Raw Material Software Ltd.
|
||||
|
||||
Permission is granted to use this software under the terms of either:
|
||||
a) the GPL v2 (or any later version)
|
||||
b) the Affero GPL v3
|
||||
|
||||
Details of these licenses can be found at: www.gnu.org/licenses
|
||||
|
||||
JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
To release a closed-source product which uses JUCE, commercial licenses are
|
||||
available: visit www.juce.com for more information.
|
||||
|
||||
==============================================================================
|
||||
*/
|
||||
|
||||
#ifndef JUCE_QUATERNION_H_INCLUDED
|
||||
#define JUCE_QUATERNION_H_INCLUDED
|
||||
|
||||
#include "juce_Vector3D.h"
|
||||
#include "juce_Matrix3D.h"
|
||||
|
||||
//==============================================================================
|
||||
/**
|
||||
Holds a quaternion (a 3D vector and a scalar value).
|
||||
*/
|
||||
template <typename Type>
|
||||
class Quaternion
|
||||
{
|
||||
public:
|
||||
Quaternion() noexcept : scalar() {}
|
||||
Quaternion (const Quaternion& other) noexcept : vector (other.vector), scalar (other.scalar) {}
|
||||
Quaternion (const Vector3D<Type>& vectorPart, const Type& scalarPart) noexcept : vector (vectorPart), scalar (scalarPart) {}
|
||||
Quaternion (const Type& x, const Type& y, const Type& z, const Type& w) noexcept : vector (x, y, z), scalar (w) {}
|
||||
|
||||
/** Creates a quaternion from an angle and an axis. */
|
||||
static Quaternion fromAngle (const Type& angle, const Vector3D<Type>& axis) noexcept
|
||||
{
|
||||
return Quaternion (axis.normalised() * std::sin (angle / (Type) 2), std::cos (angle / (Type) 2));
|
||||
}
|
||||
|
||||
Quaternion& operator= (const Quaternion& other) noexcept
|
||||
{
|
||||
vector = other.vector;
|
||||
scalar = other.scalar;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Quaternion& operator*= (const 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;
|
||||
};
|
||||
|
||||
|
||||
#endif // JUCE_QUATERNION_H_INCLUDED
|
||||
|
|
@ -0,0 +1,81 @@
|
|||
/*
|
||||
==============================================================================
|
||||
|
||||
This file is part of the JUCE library.
|
||||
Copyright (c) 2013 - Raw Material Software Ltd.
|
||||
|
||||
Permission is granted to use this software under the terms of either:
|
||||
a) the GPL v2 (or any later version)
|
||||
b) the Affero GPL v3
|
||||
|
||||
Details of these licenses can be found at: www.gnu.org/licenses
|
||||
|
||||
JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
To release a closed-source product which uses JUCE, commercial licenses are
|
||||
available: visit www.juce.com for more information.
|
||||
|
||||
==============================================================================
|
||||
*/
|
||||
|
||||
#ifndef JUCE_VECTOR3D_H_INCLUDED
|
||||
#define JUCE_VECTOR3D_H_INCLUDED
|
||||
|
||||
//==============================================================================
|
||||
/**
|
||||
A three-coordinate vector.
|
||||
*/
|
||||
template <typename Type>
|
||||
class Vector3D
|
||||
{
|
||||
public:
|
||||
Vector3D() noexcept : x(), y(), z() {}
|
||||
Vector3D (const Type& xValue, const Type& yValue, const 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= (const 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 Vector3D ((Type) 1, 0, 0); }
|
||||
/** Returns a vector that lies along the Y axis. */
|
||||
static Vector3D yAxis() noexcept { return Vector3D (0, (Type) 1, 0); }
|
||||
/** Returns a vector that lies along the Z axis. */
|
||||
static Vector3D zAxis() noexcept { return Vector3D (0, 0, (Type) 1); }
|
||||
|
||||
Vector3D& operator+= (const Vector3D& other) noexcept { x += other.x; y += other.y; z += other.z; return *this; }
|
||||
Vector3D& operator-= (const Vector3D& other) noexcept { x -= other.x; y -= other.y; z -= other.z; return *this; }
|
||||
Vector3D& operator*= (const Type& scaleFactor) noexcept { x *= scaleFactor; y *= scaleFactor; z *= scaleFactor; return *this; }
|
||||
Vector3D& operator/= (const Type& scaleFactor) noexcept { x /= scaleFactor; y /= scaleFactor; z /= scaleFactor; return *this; }
|
||||
|
||||
Vector3D operator+ (const Vector3D& other) const noexcept { return Vector3D (x + other.x, y + other.y, z + other.z); }
|
||||
Vector3D operator- (const Vector3D& other) const noexcept { return Vector3D (x - other.x, y - other.y, z - other.z); }
|
||||
Vector3D operator* (const Type& scaleFactor) const noexcept { return Vector3D (x * scaleFactor, y * scaleFactor, z * scaleFactor); }
|
||||
Vector3D operator/ (const Type& scaleFactor) const noexcept { return Vector3D (x / scaleFactor, y / scaleFactor, z / scaleFactor); }
|
||||
Vector3D operator-() const noexcept { return Vector3D (-x, -y, -z); }
|
||||
|
||||
/** Returns the dot-product of these two vectors. */
|
||||
Type operator* (const Vector3D& other) const noexcept { return x * other.x + y * other.y + z * other.z; }
|
||||
|
||||
/** Returns the cross-product of these two vectors. */
|
||||
Vector3D operator^ (const Vector3D& other) const noexcept { return Vector3D (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
|
||||
{
|
||||
const Type epsilon (std::numeric_limits<Type>::epsilon());
|
||||
return ! (x < -epsilon || x > epsilon || y < -epsilon || y > epsilon || z < -epsilon || z > epsilon);
|
||||
}
|
||||
|
||||
Type x, y, z;
|
||||
};
|
||||
|
||||
|
||||
#endif // JUCE_VECTOR3D_H_INCLUDED
|
||||
Loading…
Add table
Add a link
Reference in a new issue