diff options
Diffstat (limited to 'extern/solid/include/MT')
-rw-r--r-- | extern/solid/include/MT/Interval.h | 180 | ||||
-rw-r--r-- | extern/solid/include/MT/Matrix3x3.h | 380 | ||||
-rw-r--r-- | extern/solid/include/MT/Quaternion.h | 316 | ||||
-rw-r--r-- | extern/solid/include/MT/Transform.h | 189 | ||||
-rw-r--r-- | extern/solid/include/MT/Tuple3.h | 120 | ||||
-rw-r--r-- | extern/solid/include/MT/Tuple4.h | 112 | ||||
-rw-r--r-- | extern/solid/include/MT/Vector3.h | 283 |
7 files changed, 0 insertions, 1580 deletions
diff --git a/extern/solid/include/MT/Interval.h b/extern/solid/include/MT/Interval.h deleted file mode 100644 index c6ba2fc1681..00000000000 --- a/extern/solid/include/MT/Interval.h +++ /dev/null @@ -1,180 +0,0 @@ -/* - * SOLID - Software Library for Interference Detection - * - * Copyright (C) 2001-2003 Dtecta. All rights reserved. - * - * This library may be distributed under the terms of the Q Public License - * (QPL) as defined by Trolltech AS of Norway and appearing in the file - * LICENSE.QPL included in the packaging of this file. - * - * This library may be distributed and/or modified under the terms of the - * GNU General Public License (GPL) version 2 as published by the Free Software - * Foundation and appearing in the file LICENSE.GPL included in the - * packaging of this file. - * - * This library is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. - * - * Commercial use or any other use of this library not covered by either - * the QPL or the GPL requires an additional license from Dtecta. - * Please contact info@dtecta.com for enquiries about the terms of commercial - * use of this library. - */ - -#ifndef INTERVAL_H -#define INTERVAL_H - -#if defined (__sgi) -#include <assert.h> -#else -#include <cassert> -#endif - -#include <iostream> -#include <algorithm> - -namespace MT { - - template <typename Scalar> - class Interval { - public: - Interval() {} - - -#if _MSC_VER <= 1200 - explicit Interval(const Scalar& x) - : m_lb(x), m_ub(x) - {} - - - Interval(const Scalar& lb, const Scalar& ub) - : m_lb(lb), m_ub(ub) - { - assert(lb <= ub); - } -#else - template <typename Scalar2> - explicit Interval(const Scalar2& x) - : m_lb(x), m_ub(x) - {} - - template <typename Scalar2> - Interval(const Scalar2& lb, const Scalar2& ub) - : m_lb(lb), m_ub(ub) - { - assert(lb <= ub); - } - - template <typename Scalar2> - Interval(const Interval<Scalar2>& z) - { - *this = z; - } - - template <typename Scalar2> - Interval<Scalar>& operator=(const Interval<Scalar2>& z) - { - m_lb = Scalar(z.lower()); - m_ub = Scalar(z.upper()); - return *this; - } -#endif - - - - Scalar& lower() { return m_lb; } - const Scalar& lower() const { return m_lb; } - - Scalar& upper() { return m_ub; } - const Scalar& upper() const { return m_ub; } - - Scalar center() const { return (m_lb + m_ub) * Scalar(0.5); } - Scalar extent() const { return (m_ub - m_lb) * Scalar(0.5); } - - - protected: - Scalar m_lb, m_ub; - }; - - template <typename Scalar> - inline Interval<Scalar> - operator+(const Interval<Scalar>& z1, const Interval<Scalar>& z2) - { - return Interval<Scalar>(z1.lower() + z2.lower(), - z1.upper() + z2.upper()); - } - - template <typename Scalar> - inline Interval<Scalar> - operator-(const Interval<Scalar>& z1, const Interval<Scalar>& z2) - { - return Interval<Scalar>(z1.lower() - z2.upper(), - z1.upper() - z2.lower()); - } - - template <typename Scalar> - inline std::ostream& - operator<<(std::ostream& os, const Interval<Scalar>& z) - { - return os << '[' << z.lower() << ", " << z.upper() << ']'; - } - - template <typename Scalar> - inline Scalar - median(const Interval<Scalar>& z) - { - return (z.lower() + z.upper()) * Scalar(0.5); - } - - template <typename Scalar> - inline Scalar - width(const Interval<Scalar>& z) - { - return z.upper() - z.lower(); - } - - template <typename Scalar> - inline bool - overlap(const Interval<Scalar>& z1, const Interval<Scalar>& z2) - { - return z1.lower() <= z2.upper() && z2.lower() <= z1.upper(); - } - - template <typename Scalar> - inline bool - in(const Interval<Scalar>& z1, const Interval<Scalar>& z2) - { - return z2.lower() <= z1.lower() && z1.upper() <= z2.upper(); - } - - template <typename Scalar> - inline bool - in(Scalar x, const Interval<Scalar>& z) - { - return z.lower() <= x && x <= z.upper(); - } - - template <typename Scalar> - inline Interval<Scalar> - widen(const Interval<Scalar>& z, const Scalar& x) - { - return Interval<Scalar>(z.lower() - x, z.upper() + x); - } - - template<typename Scalar> - inline Interval<Scalar> - hull(const Interval<Scalar>& z1, const Interval<Scalar>& z2) - { - return Interval<Scalar>(GEN_min(z1.lower(), z2.lower()), - GEN_max(z1.upper(), z2.upper())); - } - - template<typename Scalar> - inline Interval<Scalar> - operator+(Scalar x, const Interval<Scalar>& z) - { - return Interval<Scalar>(x + z.lower(), x + z.upper()); - } -} - -#endif diff --git a/extern/solid/include/MT/Matrix3x3.h b/extern/solid/include/MT/Matrix3x3.h deleted file mode 100644 index 85e0d4cac84..00000000000 --- a/extern/solid/include/MT/Matrix3x3.h +++ /dev/null @@ -1,380 +0,0 @@ -/* - * SOLID - Software Library for Interference Detection - * - * Copyright (C) 2001-2003 Dtecta. All rights reserved. - * - * This library may be distributed under the terms of the Q Public License - * (QPL) as defined by Trolltech AS of Norway and appearing in the file - * LICENSE.QPL included in the packaging of this file. - * - * This library may be distributed and/or modified under the terms of the - * GNU General Public License (GPL) version 2 as published by the Free Software - * Foundation and appearing in the file LICENSE.GPL included in the - * packaging of this file. - * - * This library is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. - * - * Commercial use or any other use of this library not covered by either - * the QPL or the GPL requires an additional license from Dtecta. - * Please contact info@dtecta.com for enquiries about the terms of commercial - * use of this library. - */ - -#ifndef MATRIX3X3_H -#define MATRIX3X3_H - -#if defined (__sgi) -#include <assert.h> -#else -#include <cassert> -#endif - -#include "Vector3.h" -#include "Quaternion.h" - -namespace MT { - - // Row-major 3x3 matrix - - template <typename Scalar> - class Matrix3x3 { - public: - Matrix3x3() {} - - template <typename Scalar2> - explicit Matrix3x3(const Scalar2 *m) { setValue(m); } - - explicit Matrix3x3(const Quaternion<Scalar>& q) { setRotation(q); } - - template <typename Scalar2> - Matrix3x3(const Scalar2& yaw, const Scalar2& pitch, const Scalar2& roll) - { - setEuler(yaw, pitch, roll); - } - - template <typename Scalar2> - Matrix3x3(const Scalar2& xx, const Scalar2& xy, const Scalar2& xz, - const Scalar2& yx, const Scalar2& yy, const Scalar2& yz, - const Scalar2& zx, const Scalar2& zy, const Scalar2& zz) - { - setValue(xx, xy, xz, - yx, yy, yz, - zx, zy, zz); - } - - Vector3<Scalar>& operator[](int i) - { - assert(0 <= i && i < 3); - return m_el[i]; - } - - const Vector3<Scalar>& operator[](int i) const - { - assert(0 <= i && i < 3); - return m_el[i]; - } - - Matrix3x3<Scalar>& operator*=(const Matrix3x3<Scalar>& m); - - template <typename Scalar2> - void setValue(const Scalar2 *m) - { - m_el[0][0] = Scalar(m[0]); - m_el[1][0] = Scalar(m[1]); - m_el[2][0] = Scalar(m[2]); - m_el[0][1] = Scalar(m[4]); - m_el[1][1] = Scalar(m[5]); - m_el[2][1] = Scalar(m[6]); - m_el[0][2] = Scalar(m[8]); - m_el[1][2] = Scalar(m[9]); - m_el[2][2] = Scalar(m[10]); - } - - template <typename Scalar2> - void setValue(const Scalar2& xx, const Scalar2& xy, const Scalar2& xz, - const Scalar2& yx, const Scalar2& yy, const Scalar2& yz, - const Scalar2& zx, const Scalar2& zy, const Scalar2& zz) - { - m_el[0][0] = Scalar(xx); - m_el[0][1] = Scalar(xy); - m_el[0][2] = Scalar(xz); - m_el[1][0] = Scalar(yx); - m_el[1][1] = Scalar(yy); - m_el[1][2] = Scalar(yz); - m_el[2][0] = Scalar(zx); - m_el[2][1] = Scalar(zy); - m_el[2][2] = Scalar(zz); - } - - void setRotation(const Quaternion<Scalar>& q) - { - Scalar d = q.length2(); - assert(d != Scalar(0.0)); - Scalar s = Scalar(2.0) / d; - Scalar xs = q[0] * s, ys = q[1] * s, zs = q[2] * s; - Scalar wx = q[3] * xs, wy = q[3] * ys, wz = q[3] * zs; - Scalar xx = q[0] * xs, xy = q[0] * ys, xz = q[0] * zs; - Scalar yy = q[1] * ys, yz = q[1] * zs, zz = q[2] * zs; - setValue(Scalar(1.0) - (yy + zz), xy - wz, xz + wy, - xy + wz, Scalar(1.0) - (xx + zz), yz - wx, - xz - wy, yz + wx, Scalar(1.0) - (xx + yy)); - } - - template <typename Scalar2> - void setEuler(const Scalar2& yaw, const Scalar2& pitch, const Scalar2& roll) - { - Scalar cy(Scalar_traits<Scalar>::cos(yaw)); - Scalar sy(Scalar_traits<Scalar>::sin(yaw)); - Scalar cp(Scalar_traits<Scalar>::cos(pitch)); - Scalar sp(Scalar_traits<Scalar>::sin(pitch)); - Scalar cr(Scalar_traits<Scalar>::cos(roll)); - Scalar sr(Scalar_traits<Scalar>::sin(roll)); - Scalar cc = cy * cr; - Scalar cs = cy * sr; - Scalar sc = sy * cr; - Scalar ss = sy * sr; - setValue(cy * cp, -sc + sp * cs, ss - sp * cc, - sy * cp, cc + sp * ss, -cs + sp * sc, - -sp, cp * sr, cp * cr); - } - void setIdentity() - { - setValue(Scalar(1.0), Scalar(0.0), Scalar(0.0), - Scalar(0.0), Scalar(1.0), Scalar(0.0), - Scalar(0.0), Scalar(0.0), Scalar(1.0)); - } - - template <typename Scalar2> - void getValue(Scalar2 *m) const - { - m[0] = Scalar2(m_el[0][0]); - m[1] = Scalar2(m_el[1][0]); - m[2] = Scalar2(m_el[2][0]); - m[3] = Scalar2(0.0); - m[4] = Scalar2(m_el[0][1]); - m[5] = Scalar2(m_el[1][1]); - m[6] = Scalar2(m_el[2][1]); - m[7] = Scalar2(0.0); - m[8] = Scalar2(m_el[0][2]); - m[9] = Scalar2(m_el[1][2]); - m[10] = Scalar2(m_el[2][2]); - m[11] = Scalar2(0.0); - } - - void getRotation(Quaternion<Scalar>& q) const - { - Scalar trace = m_el[0][0] + m_el[1][1] + m_el[2][2]; - - if (trace > Scalar(0.0)) - { - Scalar s = Scalar_traits<Scalar>::sqrt(trace + Scalar(1.0)); - q[3] = s * Scalar(0.5); - s = Scalar(0.5) / s; - - q[0] = (m_el[2][1] - m_el[1][2]) * s; - q[1] = (m_el[0][2] - m_el[2][0]) * s; - q[2] = (m_el[1][0] - m_el[0][1]) * s; - } - else - { - int i = m_el[0][0] < m_el[1][1] ? - (m_el[1][1] < m_el[2][2] ? 2 : 1) : - (m_el[0][0] < m_el[2][2] ? 2 : 0); - int j = (i + 1) % 3; - int k = (i + 2) % 3; - - Scalar s = Scalar_traits<Scalar>::sqrt(m_el[i][i] - m_el[j][j] - m_el[k][k] + Scalar(1.0)); - q[i] = s * Scalar(0.5); - s = Scalar(0.5) / s; - - q[3] = (m_el[k][j] - m_el[j][k]) * s; - q[j] = (m_el[j][i] + m_el[i][j]) * s; - q[k] = (m_el[k][i] + m_el[i][k]) * s; - } - } - - - - template <typename Scalar2> - void getEuler(Scalar2& yaw, Scalar2& pitch, Scalar2& roll) const - { - pitch = Scalar2(Scalar_traits<Scalar>::asin(-m_el[2][0])); - if (pitch < Scalar_traits<Scalar2>::TwoTimesPi()) - { - if (pitch > Scalar_traits<Scalar2>::TwoTimesPi()) - { - yaw = Scalar2(Scalar_traits<Scalar>::atan2(m_el[1][0], m_el[0][0])); - roll = Scalar2(Scalar_traits<Scalar>::atan2(m_el[2][1], m_el[2][2])); - } - else - { - yaw = Scalar2(-Scalar_traits<Scalar>::atan2(-m_el[0][1], m_el[0][2])); - roll = Scalar2(0.0); - } - } - else - { - yaw = Scalar2(Scalar_traits<Scalar>::atan2(-m_el[0][1], m_el[0][2])); - roll = Scalar2(0.0); - } - } - - Vector3<Scalar> getScaling() const - { - return Vector3<Scalar>(m_el[0][0] * m_el[0][0] + m_el[1][0] * m_el[1][0] + m_el[2][0] * m_el[2][0], - m_el[0][1] * m_el[0][1] + m_el[1][1] * m_el[1][1] + m_el[2][1] * m_el[2][1], - m_el[0][2] * m_el[0][2] + m_el[1][2] * m_el[1][2] + m_el[2][2] * m_el[2][2]); - } - - - Matrix3x3<Scalar> scaled(const Vector3<Scalar>& s) const - { - return Matrix3x3<Scalar>(m_el[0][0] * s[0], m_el[0][1] * s[1], m_el[0][2] * s[2], - m_el[1][0] * s[0], m_el[1][1] * s[1], m_el[1][2] * s[2], - m_el[2][0] * s[0], m_el[2][1] * s[1], m_el[2][2] * s[2]); - } - - Scalar determinant() const; - Matrix3x3<Scalar> adjoint() const; - Matrix3x3<Scalar> absolute() const; - Matrix3x3<Scalar> transpose() const; - Matrix3x3<Scalar> inverse() const; - - Matrix3x3<Scalar> transposeTimes(const Matrix3x3<Scalar>& m) const; - Matrix3x3<Scalar> timesTranspose(const Matrix3x3<Scalar>& m) const; - - Scalar tdot(int c, const Vector3<Scalar>& v) const - { - return m_el[0][c] * v[0] + m_el[1][c] * v[1] + m_el[2][c] * v[2]; - } - - protected: - Scalar cofac(int r1, int c1, int r2, int c2) const - { - return m_el[r1][c1] * m_el[r2][c2] - m_el[r1][c2] * m_el[r2][c1]; - } - - Vector3<Scalar> m_el[3]; - }; - - template <typename Scalar> - inline std::ostream& - operator<<(std::ostream& os, const Matrix3x3<Scalar>& m) - { - return os << m[0] << std::endl << m[1] << std::endl << m[2] << std::endl; - } - - template <typename Scalar> - inline Matrix3x3<Scalar>& - Matrix3x3<Scalar>::operator*=(const Matrix3x3<Scalar>& m) - { - setValue(m.tdot(0, m_el[0]), m.tdot(1, m_el[0]), m.tdot(2, m_el[0]), - m.tdot(0, m_el[1]), m.tdot(1, m_el[1]), m.tdot(2, m_el[1]), - m.tdot(0, m_el[2]), m.tdot(1, m_el[2]), m.tdot(2, m_el[2])); - return *this; - } - - template <typename Scalar> - inline Scalar - Matrix3x3<Scalar>::determinant() const - { - return triple((*this)[0], (*this)[1], (*this)[2]); - } - - - template <typename Scalar> - inline Matrix3x3<Scalar> - Matrix3x3<Scalar>::absolute() const - { - return Matrix3x3<Scalar>( - Scalar_traits<Scalar>::abs(m_el[0][0]), Scalar_traits<Scalar>::abs(m_el[0][1]), Scalar_traits<Scalar>::abs(m_el[0][2]), - Scalar_traits<Scalar>::abs(m_el[1][0]), Scalar_traits<Scalar>::abs(m_el[1][1]), Scalar_traits<Scalar>::abs(m_el[1][2]), - Scalar_traits<Scalar>::abs(m_el[2][0]), Scalar_traits<Scalar>::abs(m_el[2][1]), Scalar_traits<Scalar>::abs(m_el[2][2])); - } - - template <typename Scalar> - inline Matrix3x3<Scalar> - Matrix3x3<Scalar>::transpose() const - { - return Matrix3x3<Scalar>(m_el[0][0], m_el[1][0], m_el[2][0], - m_el[0][1], m_el[1][1], m_el[2][1], - m_el[0][2], m_el[1][2], m_el[2][2]); - } - - template <typename Scalar> - inline Matrix3x3<Scalar> - Matrix3x3<Scalar>::adjoint() const - { - return Matrix3x3<Scalar>(cofac(1, 1, 2, 2), cofac(0, 2, 2, 1), cofac(0, 1, 1, 2), - cofac(1, 2, 2, 0), cofac(0, 0, 2, 2), cofac(0, 2, 1, 0), - cofac(1, 0, 2, 1), cofac(0, 1, 2, 0), cofac(0, 0, 1, 1)); - } - - template <typename Scalar> - inline Matrix3x3<Scalar> - Matrix3x3<Scalar>::inverse() const - { - Vector3<Scalar> co(cofac(1, 1, 2, 2), cofac(1, 2, 2, 0), cofac(1, 0, 2, 1)); - Scalar det = (*this)[0].dot(co); - assert(det != Scalar(0.0)); - Scalar s = Scalar(1.0) / det; - return Matrix3x3<Scalar>(co[0] * s, cofac(0, 2, 2, 1) * s, cofac(0, 1, 1, 2) * s, - co[1] * s, cofac(0, 0, 2, 2) * s, cofac(0, 2, 1, 0) * s, - co[2] * s, cofac(0, 1, 2, 0) * s, cofac(0, 0, 1, 1) * s); - } - - template <typename Scalar> - inline Matrix3x3<Scalar> - Matrix3x3<Scalar>::transposeTimes(const Matrix3x3<Scalar>& m) const - { - return Matrix3x3<Scalar>( - m_el[0][0] * m[0][0] + m_el[1][0] * m[1][0] + m_el[2][0] * m[2][0], - m_el[0][0] * m[0][1] + m_el[1][0] * m[1][1] + m_el[2][0] * m[2][1], - m_el[0][0] * m[0][2] + m_el[1][0] * m[1][2] + m_el[2][0] * m[2][2], - m_el[0][1] * m[0][0] + m_el[1][1] * m[1][0] + m_el[2][1] * m[2][0], - m_el[0][1] * m[0][1] + m_el[1][1] * m[1][1] + m_el[2][1] * m[2][1], - m_el[0][1] * m[0][2] + m_el[1][1] * m[1][2] + m_el[2][1] * m[2][2], - m_el[0][2] * m[0][0] + m_el[1][2] * m[1][0] + m_el[2][2] * m[2][0], - m_el[0][2] * m[0][1] + m_el[1][2] * m[1][1] + m_el[2][2] * m[2][1], - m_el[0][2] * m[0][2] + m_el[1][2] * m[1][2] + m_el[2][2] * m[2][2]); - } - - template <typename Scalar> - inline Matrix3x3<Scalar> - Matrix3x3<Scalar>::timesTranspose(const Matrix3x3<Scalar>& m) const - { - return Matrix3x3<Scalar>( - m_el[0].dot(m[0]), m_el[0].dot(m[1]), m_el[0].dot(m[2]), - m_el[1].dot(m[0]), m_el[1].dot(m[1]), m_el[1].dot(m[2]), - m_el[2].dot(m[0]), m_el[2].dot(m[1]), m_el[2].dot(m[2])); - - } - - template <typename Scalar> - inline Vector3<Scalar> - operator*(const Matrix3x3<Scalar>& m, const Vector3<Scalar>& v) - { - return Vector3<Scalar>(m[0].dot(v), m[1].dot(v), m[2].dot(v)); - } - - - template <typename Scalar> - inline Vector3<Scalar> - operator*(const Vector3<Scalar>& v, const Matrix3x3<Scalar>& m) - { - return Vector3<Scalar>(m.tdot(0, v), m.tdot(1, v), m.tdot(2, v)); - } - - template <typename Scalar> - inline Matrix3x3<Scalar> - operator*(const Matrix3x3<Scalar>& m1, const Matrix3x3<Scalar>& m2) - { - return Matrix3x3<Scalar>( - m2.tdot(0, m1[0]), m2.tdot(1, m1[0]), m2.tdot(2, m1[0]), - m2.tdot(0, m1[1]), m2.tdot(1, m1[1]), m2.tdot(2, m1[1]), - m2.tdot(0, m1[2]), m2.tdot(1, m1[2]), m2.tdot(2, m1[2])); - } -} - -#endif diff --git a/extern/solid/include/MT/Quaternion.h b/extern/solid/include/MT/Quaternion.h deleted file mode 100644 index a925f21cd5d..00000000000 --- a/extern/solid/include/MT/Quaternion.h +++ /dev/null @@ -1,316 +0,0 @@ -/* - * SOLID - Software Library for Interference Detection - * - * Copyright (C) 2001-2003 Dtecta. All rights reserved. - * - * This library may be distributed under the terms of the Q Public License - * (QPL) as defined by Trolltech AS of Norway and appearing in the file - * LICENSE.QPL included in the packaging of this file. - * - * This library may be distributed and/or modified under the terms of the - * GNU General Public License (GPL) version 2 as published by the Free Software - * Foundation and appearing in the file LICENSE.GPL included in the - * packaging of this file. - * - * This library is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. - * - * Commercial use or any other use of this library not covered by either - * the QPL or the GPL requires an additional license from Dtecta. - * Please contact info@dtecta.com for enquiries about the terms of commercial - * use of this library. - */ - -#ifndef QUATERNION_H -#define QUATERNION_H - -#if defined (__sgi) -#include <assert.h> -#else -#include <cassert> -#endif - -#include "Tuple4.h" -#include "Vector3.h" - -namespace MT { - - template <typename Scalar> - class Quaternion : public Tuple4<Scalar> { - public: - Quaternion() {} - - template <typename Scalar2> - explicit Quaternion(const Scalar2 *v) : Tuple4<Scalar>(v) {} - - template <typename Scalar2> - Quaternion(const Scalar2& x, const Scalar2& y, const Scalar2& z, const Scalar2& w) - : Tuple4<Scalar>(x, y, z, w) - {} - - Quaternion(const Vector3<Scalar>& axis, const Scalar& angle) - { - setRotation(axis, angle); - } - - template <typename Scalar2> - Quaternion(const Scalar2& yaw, const Scalar2& pitch, const Scalar2& roll) - { - setEuler(yaw, pitch, roll); - } - - void setRotation(const Vector3<Scalar>& axis, const Scalar& angle) - { - Scalar d = axis.length(); - assert(d != Scalar(0.0)); - Scalar s = Scalar_traits<Scalar>::sin(angle * Scalar(0.5)) / d; - setValue(axis[0] * s, axis[1] * s, axis[2] * s, - Scalar_traits<Scalar>::cos(angle * Scalar(0.5))); - } - - template <typename Scalar2> - void setEuler(const Scalar2& yaw, const Scalar2& pitch, const Scalar2& roll) - { - Scalar halfYaw = Scalar(yaw) * Scalar(0.5); - Scalar halfPitch = Scalar(pitch) * Scalar(0.5); - Scalar halfRoll = Scalar(roll) * Scalar(0.5); - Scalar cosYaw = Scalar_traits<Scalar>::cos(halfYaw); - Scalar sinYaw = Scalar_traits<Scalar>::sin(halfYaw); - Scalar cosPitch = Scalar_traits<Scalar>::cos(halfPitch); - Scalar sinPitch = Scalar_traits<Scalar>::sin(halfPitch); - Scalar cosRoll = Scalar_traits<Scalar>::cos(halfRoll); - Scalar sinRoll = Scalar_traits<Scalar>::sin(halfRoll); - setValue(cosRoll * sinPitch * cosYaw + sinRoll * cosPitch * sinYaw, - cosRoll * cosPitch * sinYaw - sinRoll * sinPitch * cosYaw, - sinRoll * cosPitch * cosYaw - cosRoll * sinPitch * sinYaw, - cosRoll * cosPitch * cosYaw + sinRoll * sinPitch * sinYaw); - } - - Quaternion<Scalar>& operator+=(const Quaternion<Scalar>& q) - { - this->m_co[0] += q[0]; this->m_co[1] += q[1]; this->m_co[2] += q[2]; this->m_co[3] += q[3]; - return *this; - } - - Quaternion<Scalar>& operator-=(const Quaternion<Scalar>& q) - { - this->m_co[0] -= q[0]; this->m_co[1] -= q[1]; this->m_co[2] -= q[2]; this->m_co[3] -= q[3]; - return *this; - } - - Quaternion<Scalar>& operator*=(const Scalar& s) - { - this->m_co[0] *= s; this->m_co[1] *= s; this->m_co[2] *= s; this->m_co[3] *= s; - return *this; - } - - Quaternion<Scalar>& operator/=(const Scalar& s) - { - assert(s != Scalar(0.0)); - return *this *= Scalar(1.0) / s; - } - - Quaternion<Scalar>& operator*=(const Quaternion<Scalar>& q) - { - setValue(this->m_co[3] * q[0] + this->m_co[0] * q[3] + this->m_co[1] * q[2] - this->m_co[2] * q[1], - this->m_co[3] * q[1] + this->m_co[1] * q[3] + this->m_co[2] * q[0] - this->m_co[0] * q[2], - this->m_co[3] * q[2] + this->m_co[2] * q[3] + this->m_co[0] * q[1] - this->m_co[1] * q[0], - this->m_co[3] * q[3] - this->m_co[0] * q[0] - this->m_co[1] * q[1] - this->m_co[2] * q[2]); - return *this; - } - - Scalar dot(const Quaternion<Scalar>& q) const - { - return this->m_co[0] * q[0] + this->m_co[1] * q[1] + this->m_co[2] * q[2] + this->m_co[3] * q[3]; - } - - Scalar length2() const - { - return dot(*this); - } - - Scalar length() const - { - return Scalar_traits<Scalar>::sqrt(length2()); - } - - Quaternion<Scalar>& normalize() - { - return *this /= length(); - } - - Quaternion<Scalar> normalized() const - { - return *this / length(); - } - - Scalar angle(const Quaternion<Scalar>& q) const - { - Scalar s = Scalar_traits<Scalar>::sqrt(length2() * q.length2()); - assert(s != Scalar(0.0)); - return Scalar_traits<Scalar>::acos(dot(q) / s); - } - - Quaternion<Scalar> conjugate() const - { - return Quaternion<Scalar>(-this->m_co[0], -this->m_co[1], -this->m_co[2], this->m_co[3]); - } - - Quaternion<Scalar> inverse() const - { - return conjugate / length2(); - } - - Quaternion<Scalar> slerp(const Quaternion<Scalar>& q, const Scalar& t) const - { - Scalar theta = angle(q); - if (theta != Scalar(0.0)) - { - Scalar d = Scalar(1.0) / Scalar_traits<Scalar>::sin(theta); - Scalar s0 = Scalar_traits<Scalar>::sin((Scalar(1.0) - t) * theta); - Scalar s1 = Scalar_traits<Scalar>::sin(t * theta); - return Quaternion<Scalar>((this->m_co[0] * s0 + q[0] * s1) * d, - (this->m_co[1] * s0 + q[1] * s1) * d, - (this->m_co[2] * s0 + q[2] * s1) * d, - (this->m_co[3] * s0 + q[3] * s1) * d); - } - else - { - return *this; - } - } - - static Quaternion<Scalar> random() - { - // From: "Uniform Random Rotations", Ken Shoemake, Graphics Gems III, - // pg. 124-132 - Scalar x0 = Scalar_traits<Scalar>::random(); - Scalar r1 = Scalar_traits<Scalar>::sqrt(Scalar(1.0) - x0); - Scalar r2 = Scalar_traits<Scalar>::sqrt(x0); - Scalar t1 = Scalar_traits<Scalar>::TwoTimesPi() * Scalar_traits<Scalar>::random(); - Scalar t2 = Scalar_traits<Scalar>::TwoTimesPi() * Scalar_traits<Scalar>::random(); - Scalar c1 = Scalar_traits<Scalar>::cos(t1); - Scalar s1 = Scalar_traits<Scalar>::sin(t1); - Scalar c2 = Scalar_traits<Scalar>::cos(t2); - Scalar s2 = Scalar_traits<Scalar>::sin(t2); - return Quaternion<Scalar>(s1 * r1, c1 * r1, s2 * r2, c2 * r2); - } - - }; - - template <typename Scalar> - inline Quaternion<Scalar> - operator+(const Quaternion<Scalar>& q1, const Quaternion<Scalar>& q2) - { - return Quaternion<Scalar>(q1[0] + q2[0], q1[1] + q2[1], q1[2] + q2[2], q1[3] + q2[3]); - } - - template <typename Scalar> - inline Quaternion<Scalar> - operator-(const Quaternion<Scalar>& q1, const Quaternion<Scalar>& q2) - { - return Quaternion<Scalar>(q1[0] - q2[0], q1[1] - q2[1], q1[2] - q2[2], q1[3] - q2[3]); - } - - template <typename Scalar> - inline Quaternion<Scalar> - operator-(const Quaternion<Scalar>& q) - { - return Quaternion<Scalar>(-q[0], -q[1], -q[2], -q[3]); - } - - template <typename Scalar> - inline Quaternion<Scalar> - operator*(const Quaternion<Scalar>& q, const Scalar& s) - { - return Quaternion<Scalar>(q[0] * s, q[1] * s, q[2] * s, q[3] * s); - } - - template <typename Scalar> - inline Quaternion<Scalar> - operator*(const Scalar& s, const Quaternion<Scalar>& q) - { - return q * s; - } - - template <typename Scalar> - inline Quaternion<Scalar> - operator*(const Quaternion<Scalar>& q1, const Quaternion<Scalar>& q2) { - return Quaternion<Scalar>(q1[3] * q2[0] + q1[0] * q2[3] + q1[1] * q2[2] - q1[2] * q2[1], - q1[3] * q2[1] + q1[1] * q2[3] + q1[2] * q2[0] - q1[0] * q2[2], - q1[3] * q2[2] + q1[2] * q2[3] + q1[0] * q2[1] - q1[1] * q2[0], - q1[3] * q2[3] - q1[0] * q2[0] - q1[1] * q2[1] - q1[2] * q2[2]); - } - - template <typename Scalar> - inline Quaternion<Scalar> - operator*(const Quaternion<Scalar>& q, const Vector3<Scalar>& w) - { - return Quaternion<Scalar>( q[3] * w[0] + q[1] * w[2] - q[2] * w[1], - q[3] * w[1] + q[2] * w[0] - q[0] * w[2], - q[3] * w[2] + q[0] * w[1] - q[1] * w[0], - -q[0] * w[0] - q[1] * w[1] - q[2] * w[2]); - } - - template <typename Scalar> - inline Quaternion<Scalar> - operator*(const Vector3<Scalar>& w, const Quaternion<Scalar>& q) - { - return Quaternion<Scalar>( w[0] * q[3] + w[1] * q[2] - w[2] * q[1], - w[1] * q[3] + w[2] * q[0] - w[0] * q[2], - w[2] * q[3] + w[0] * q[1] - w[1] * q[0], - -w[0] * q[0] - w[1] * q[1] - w[2] * q[2]); - } - - template <typename Scalar> - inline Scalar - dot(const Quaternion<Scalar>& q1, const Quaternion<Scalar>& q2) - { - return q1.dot(q2); - } - - template <typename Scalar> - inline Scalar - length2(const Quaternion<Scalar>& q) - { - return q.length2(); - } - - template <typename Scalar> - inline Scalar - length(const Quaternion<Scalar>& q) - { - return q.length(); - } - - template <typename Scalar> - inline Scalar - angle(const Quaternion<Scalar>& q1, const Quaternion<Scalar>& q2) - { - return q1.angle(q2); - } - - template <typename Scalar> - inline Quaternion<Scalar> - conjugate(const Quaternion<Scalar>& q) - { - return q.conjugate(); - } - - template <typename Scalar> - inline Quaternion<Scalar> - inverse(const Quaternion<Scalar>& q) - { - return q.inverse(); - } - - template <typename Scalar> - inline Quaternion<Scalar> - slerp(const Quaternion<Scalar>& q1, const Quaternion<Scalar>& q2, const Scalar& t) - { - return q1.slerp(q2, t); - } - -} - -#endif diff --git a/extern/solid/include/MT/Transform.h b/extern/solid/include/MT/Transform.h deleted file mode 100644 index b80dc1bc18b..00000000000 --- a/extern/solid/include/MT/Transform.h +++ /dev/null @@ -1,189 +0,0 @@ -/* - * SOLID - Software Library for Interference Detection - * - * Copyright (C) 2001-2003 Dtecta. All rights reserved. - * - * This library may be distributed under the terms of the Q Public License - * (QPL) as defined by Trolltech AS of Norway and appearing in the file - * LICENSE.QPL included in the packaging of this file. - * - * This library may be distributed and/or modified under the terms of the - * GNU General Public License (GPL) version 2 as published by the Free Software - * Foundation and appearing in the file LICENSE.GPL included in the - * packaging of this file. - * - * This library is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. - * - * Commercial use or any other use of this library not covered by either - * the QPL or the GPL requires an additional license from Dtecta. - * Please contact info@dtecta.com for enquiries about the terms of commercial - * use of this library. - */ - -#ifndef TRANSFORM_H -#define TRANSFORM_H - -#include "Vector3.h" -#include "Matrix3x3.h" - -namespace MT { - - template <typename Scalar> - class Transform { - enum { - TRANSLATION = 0x01, - ROTATION = 0x02, - RIGID = TRANSLATION | ROTATION, - SCALING = 0x04, - LINEAR = ROTATION | SCALING, - AFFINE = TRANSLATION | LINEAR - }; - - public: - Transform() {} - - template <typename Scalar2> - explicit Transform(const Scalar2 *m) { setValue(m); } - - explicit Transform(const Quaternion<Scalar>& q, - const Vector3<Scalar>& c = Vector3<Scalar>(Scalar(0), Scalar(0), Scalar(0))) - : m_basis(q), - m_origin(c), - m_type(RIGID) - {} - - explicit Transform(const Matrix3x3<Scalar>& b, - const Vector3<Scalar>& c = Vector3<Scalar>(Scalar(0), Scalar(0), Scalar(0)), - unsigned int type = AFFINE) - : m_basis(b), - m_origin(c), - m_type(type) - {} - - Vector3<Scalar> operator()(const Vector3<Scalar>& x) const - { - return Vector3<Scalar>(m_basis[0].dot(x) + m_origin[0], - m_basis[1].dot(x) + m_origin[1], - m_basis[2].dot(x) + m_origin[2]); - } - - Vector3<Scalar> operator*(const Vector3<Scalar>& x) const - { - return (*this)(x); - } - - Matrix3x3<Scalar>& getBasis() { return m_basis; } - const Matrix3x3<Scalar>& getBasis() const { return m_basis; } - - Vector3<Scalar>& getOrigin() { return m_origin; } - const Vector3<Scalar>& getOrigin() const { return m_origin; } - - Quaternion<Scalar> getRotation() const { return m_basis.getRotation(); } - template <typename Scalar2> - void setValue(const Scalar2 *m) - { - m_basis.setValue(m); - m_origin.setValue(&m[12]); - m_type = AFFINE; - } - - template <typename Scalar2> - void getValue(Scalar2 *m) const - { - m_basis.getValue(m); - m_origin.getValue(&m[12]); - m[15] = Scalar2(1.0); - } - - void setOrigin(const Vector3<Scalar>& origin) - { - m_origin = origin; - m_type |= TRANSLATION; - } - - void setBasis(const Matrix3x3<Scalar>& basis) - { - m_basis = basis; - m_type |= LINEAR; - } - - void setRotation(const Quaternion<Scalar>& q) - { - m_basis.setRotation(q); - m_type = (m_type & ~LINEAR) | ROTATION; - } - - void scale(const Vector3<Scalar>& scaling) - { - m_basis = m_basis.scaled(scaling); - m_type |= SCALING; - } - - void setIdentity() - { - m_basis.setIdentity(); - m_origin.setValue(Scalar(0.0), Scalar(0.0), Scalar(0.0)); - m_type = 0x0; - } - - bool isIdentity() const { return m_type == 0x0; } - - Transform<Scalar>& operator*=(const Transform<Scalar>& t) - { - m_origin += m_basis * t.m_origin; - m_basis *= t.m_basis; - m_type |= t.m_type; - return *this; - } - - Transform<Scalar> inverse() const - { - Matrix3x3<Scalar> inv = (m_type & SCALING) ? - m_basis.inverse() : - m_basis.transpose(); - - return Transform<Scalar>(inv, inv * -m_origin, m_type); - } - - Transform<Scalar> inverseTimes(const Transform<Scalar>& t) const; - - Transform<Scalar> operator*(const Transform<Scalar>& t) const; - - private: - - Matrix3x3<Scalar> m_basis; - Vector3<Scalar> m_origin; - unsigned int m_type; - }; - - - template <typename Scalar> - inline Transform<Scalar> - Transform<Scalar>::inverseTimes(const Transform<Scalar>& t) const - { - Vector3<Scalar> v = t.getOrigin() - m_origin; - if (m_type & SCALING) - { - Matrix3x3<Scalar> inv = m_basis.inverse(); - return Transform<Scalar>(inv * t.getBasis(), inv * v, - m_type | t.m_type); - } - else - { - return Transform<Scalar>(m_basis.transposeTimes(t.m_basis), - v * m_basis, m_type | t.m_type); - } - } - - template <typename Scalar> - inline Transform<Scalar> - Transform<Scalar>::operator*(const Transform<Scalar>& t) const - { - return Transform<Scalar>(m_basis * t.m_basis, - (*this)(t.m_origin), - m_type | t.m_type); - } -} - -#endif diff --git a/extern/solid/include/MT/Tuple3.h b/extern/solid/include/MT/Tuple3.h deleted file mode 100644 index 52ea33b7f58..00000000000 --- a/extern/solid/include/MT/Tuple3.h +++ /dev/null @@ -1,120 +0,0 @@ -/* - * SOLID - Software Library for Interference Detection - * - * Copyright (C) 2001-2003 Dtecta. All rights reserved. - * - * This library may be distributed under the terms of the Q Public License - * (QPL) as defined by Trolltech AS of Norway and appearing in the file - * LICENSE.QPL included in the packaging of this file. - * - * This library may be distributed and/or modified under the terms of the - * GNU General Public License (GPL) version 2 as published by the Free Software - * Foundation and appearing in the file LICENSE.GPL included in the - * packaging of this file. - * - * This library is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. - * - * Commercial use or any other use of this library not covered by either - * the QPL or the GPL requires an additional license from Dtecta. - * Please contact info@dtecta.com for enquiries about the terms of commercial - * use of this library. - */ - -#ifndef TUPLE3_H -#define TUPLE3_H - -#if defined (__sgi) -#include <assert.h> -#else -#include <cassert> -#endif - -#include <iostream> - -namespace MT { - - template <typename Scalar> - class Tuple3 { - public: - Tuple3() {} - - template <typename Scalar2> - explicit Tuple3(const Scalar2 *v) - { - setValue(v); - } - - template <typename Scalar2> - Tuple3(const Scalar2& x, const Scalar2& y, const Scalar2& z) - { - setValue(x, y, z); - } - - template <typename Scalar2> - Tuple3(const Tuple3<Scalar2>& t) - { - *this = t; - } - - template <typename Scalar2> - Tuple3<Scalar>& operator=(const Tuple3<Scalar2>& t) - { - m_co[0] = Scalar(t[0]); - m_co[1] = Scalar(t[1]); - m_co[2] = Scalar(t[2]); - return *this; - } - - operator Scalar *() { return m_co; } - operator const Scalar *() const { return m_co; } - - Scalar& operator[](int i) { return m_co[i]; } - const Scalar& operator[](int i) const { return m_co[i]; } - - Scalar& x() { return m_co[0]; } - const Scalar& x() const { return m_co[0]; } - - Scalar& y() { return m_co[1]; } - const Scalar& y() const { return m_co[1]; } - - Scalar& z() { return m_co[2]; } - const Scalar& z() const { return m_co[2]; } - - template <typename Scalar2> - void setValue(const Scalar2 *v) - { - m_co[0] = Scalar(v[0]); - m_co[1] = Scalar(v[1]); - m_co[2] = Scalar(v[2]); - } - - template <typename Scalar2> - void setValue(const Scalar2& x, const Scalar2& y, const Scalar2& z) - { - m_co[0] = Scalar(x); - m_co[1] = Scalar(y); - m_co[2] = Scalar(z); - } - - template <typename Scalar2> - void getValue(Scalar2 *v) const - { - v[0] = Scalar2(m_co[0]); - v[1] = Scalar2(m_co[1]); - v[2] = Scalar2(m_co[2]); - } - - protected: - Scalar m_co[3]; - }; - - template <typename Scalar> - inline std::ostream& - operator<<(std::ostream& os, const Tuple3<Scalar>& t) - { - return os << t[0] << ' ' << t[1] << ' ' << t[2]; - } -} - -#endif diff --git a/extern/solid/include/MT/Tuple4.h b/extern/solid/include/MT/Tuple4.h deleted file mode 100644 index 6930541271e..00000000000 --- a/extern/solid/include/MT/Tuple4.h +++ /dev/null @@ -1,112 +0,0 @@ -/* - * SOLID - Software Library for Interference Detection - * - * Copyright (C) 2001-2003 Dtecta. All rights reserved. - * - * This library may be distributed under the terms of the Q Public License - * (QPL) as defined by Trolltech AS of Norway and appearing in the file - * LICENSE.QPL included in the packaging of this file. - * - * This library may be distributed and/or modified under the terms of the - * GNU General Public License (GPL) version 2 as published by the Free Software - * Foundation and appearing in the file LICENSE.GPL included in the - * packaging of this file. - * - * This library is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. - * - * Commercial use or any other use of this library not covered by either - * the QPL or the GPL requires an additional license from Dtecta. - * Please contact info@dtecta.com for enquiries about the terms of commercial - * use of this library. - */ - -#ifndef TUPLE4_H -#define TUPLE4_H - -#if defined (__sgi) -#include <assert.h> -#else -#include <cassert> -#endif - -#include <iostream> - -namespace MT { - - template <typename Scalar> - class Tuple4 { - public: - Tuple4() {} - - template <typename Scalar2> - explicit Tuple4(const Scalar2 *v) - { - setValue(v); - } - - template <typename Scalar2> - Tuple4(const Scalar2& x, const Scalar2& y, const Scalar2& z, const Scalar2& w) - { - setValue(x, y, z, w); - } - - operator Scalar *() { return m_co; } - operator const Scalar *() const { return m_co; } - - Scalar& operator[](int i) { return m_co[i]; } - const Scalar& operator[](int i) const { return m_co[i]; } - - Scalar& x() { return m_co[0]; } - const Scalar& x() const { return m_co[0]; } - - Scalar& y() { return m_co[1]; } - const Scalar& y() const { return m_co[1]; } - - Scalar& z() { return m_co[2]; } - const Scalar& z() const { return m_co[2]; } - - Scalar& w() { return m_co[3]; } - const Scalar& w() const { return m_co[3]; } - - template <typename Scalar2> - void setValue(const Scalar2 *v) - { - m_co[0] = Scalar(v[0]); - m_co[1] = Scalar(v[1]); - m_co[2] = Scalar(v[2]); - m_co[3] = Scalar(v[3]); - } - - template <typename Scalar2> - void setValue(const Scalar2& x, const Scalar2& y, const Scalar2& z, const Scalar2& w) - { - m_co[0] = Scalar(x); - m_co[1] = Scalar(y); - m_co[2] = Scalar(z); - m_co[3] = Scalar(w); - } - - template <typename Scalar2> - void getValue(Scalar2 *v) const - { - v[0] = Scalar2(m_co[0]); - v[1] = Scalar2(m_co[1]); - v[2] = Scalar2(m_co[2]); - v[3] = Scalar2(m_co[3]); - } - - protected: - Scalar m_co[4]; - }; - - template <typename Scalar> - inline std::ostream& - operator<<(std::ostream& os, const Tuple4<Scalar>& t) - { - return os << t[0] << ' ' << t[1] << ' ' << t[2] << ' ' << t[3]; - } - -} - -#endif diff --git a/extern/solid/include/MT/Vector3.h b/extern/solid/include/MT/Vector3.h deleted file mode 100644 index b569c003f59..00000000000 --- a/extern/solid/include/MT/Vector3.h +++ /dev/null @@ -1,283 +0,0 @@ -/* - * SOLID - Software Library for Interference Detection - * - * Copyright (C) 2001-2003 Dtecta. All rights reserved. - * - * This library may be distributed under the terms of the Q Public License - * (QPL) as defined by Trolltech AS of Norway and appearing in the file - * LICENSE.QPL included in the packaging of this file. - * - * This library may be distributed and/or modified under the terms of the - * GNU General Public License (GPL) version 2 as published by the Free Software - * Foundation and appearing in the file LICENSE.GPL included in the - * packaging of this file. - * - * This library is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. - * - * Commercial use or any other use of this library not covered by either - * the QPL or the GPL requires an additional license from Dtecta. - * Please contact info@dtecta.com for enquiries about the terms of commercial - * use of this library. - */ - -#ifndef VECTOR3_H -#define VECTOR3_H - -#if defined (__sgi) -#include <assert.h> -#else -#include <cassert> -#endif - -#include "Tuple3.h" - -namespace MT { - - template <typename Scalar> - class Vector3 : public Tuple3<Scalar> { - public: - Vector3() {} - - template <typename Scalar2> - explicit Vector3(const Scalar2 *v) : Tuple3<Scalar>(v) {} - - template <typename Scalar2> - Vector3(const Scalar2& x, const Scalar2& y, const Scalar2& z) - : Tuple3<Scalar>(x, y, z) - {} - - Vector3<Scalar>& operator+=(const Vector3<Scalar>& v) - { - this->m_co[0] += v[0]; this->m_co[1] += v[1]; this->m_co[2] += v[2]; - return *this; - } - - Vector3<Scalar>& operator-=(const Vector3<Scalar>& v) - { - this->m_co[0] -= v[0]; this->m_co[1] -= v[1]; this->m_co[2] -= v[2]; - return *this; - } - - Vector3<Scalar>& operator*=(const Scalar& s) - { - this->m_co[0] *= s; this->m_co[1] *= s; this->m_co[2] *= s; - return *this; - } - - Vector3<Scalar>& operator/=(const Scalar& s) - { - assert(s != Scalar(0.0)); - return *this *= Scalar(1.0) / s; - } - - Scalar dot(const Vector3<Scalar>& v) const - { - return this->m_co[0] * v[0] + this->m_co[1] * v[1] + this->m_co[2] * v[2]; - } - - Scalar length2() const - { - return dot(*this); - } - - Scalar length() const - { - return Scalar_traits<Scalar>::sqrt(length2()); - } - - Scalar distance2(const Vector3<Scalar>& v) const - { - return (v - *this).length2(); - } - - Scalar distance(const Vector3<Scalar>& v) const - { - return (v - *this).length(); - } - - Vector3<Scalar>& normalize() - { - return *this /= length(); - } - - Vector3<Scalar> normalized() const - { - return *this / length(); - } - - Scalar angle(const Vector3<Scalar>& v) const - { - Scalar s = Scalar_traits<Scalar>::sqrt(length2() * v.length2()); - assert(s != Scalar(0.0)); - return Scalar_traits<Scalar>::acos(dot(v) / s); - } - - Vector3<Scalar> absolute() const - { - return Vector3<Scalar>(Scalar_traits<Scalar>::abs(this->m_co[0]), - Scalar_traits<Scalar>::abs(this->m_co[1]), - Scalar_traits<Scalar>::abs(this->m_co[2])); - } - - Vector3<Scalar> cross(const Vector3<Scalar>& v) const - { - return Vector3<Scalar>(this->m_co[1] * v[2] - this->m_co[2] * v[1], - this->m_co[2] * v[0] - this->m_co[0] * v[2], - this->m_co[0] * v[1] - this->m_co[1] * v[0]); - } - - Scalar triple(const Vector3<Scalar>& v1, const Vector3<Scalar>& v2) const - { - return this->m_co[0] * (v1[1] * v2[2] - v1[2] * v2[1]) + - this->m_co[1] * (v1[2] * v2[0] - v1[0] * v2[2]) + - this->m_co[2] * (v1[0] * v2[1] - v1[1] * v2[0]); - } - - int minAxis() const - { - return this->m_co[0] < this->m_co[1] ? (this->m_co[0] < this->m_co[2] ? 0 : 2) : (this->m_co[1] < this->m_co[2] ? 1 : 2); - } - - int maxAxis() const - { - return this->m_co[0] < this->m_co[1] ? (this->m_co[1] < this->m_co[2] ? 2 : 1) : (this->m_co[0] < this->m_co[2] ? 2 : 0); - } - - int furthestAxis() const - { - return absolute().minAxis(); - } - - int closestAxis() const - { - return absolute().maxAxis(); - } - - Vector3<Scalar> lerp(const Vector3<Scalar>& v, const Scalar& t) const - { - return Vector3<Scalar>(this->m_co[0] + (v[0] - this->m_co[0]) * t, - this->m_co[1] + (v[1] - this->m_co[1]) * t, - this->m_co[2] + (v[2] - this->m_co[2]) * t); - } - - static Vector3<Scalar> random() - { - Scalar z = Scalar(2.0) * Scalar_traits<Scalar>::random() - Scalar(1.0); - Scalar r = Scalar_traits<Scalar>::sqrt(Scalar(1.0) - z * z); - Scalar t = Scalar_traits<Scalar>::TwoTimesPi() * Scalar_traits<Scalar>::random(); - return Vector3<Scalar>(r * Scalar_traits<Scalar>::cos(t), - r * Scalar_traits<Scalar>::sin(t), - z); - } - }; - - template <typename Scalar> - inline Vector3<Scalar> - operator+(const Vector3<Scalar>& v1, const Vector3<Scalar>& v2) - { - return Vector3<Scalar>(v1[0] + v2[0], v1[1] + v2[1], v1[2] + v2[2]); - } - - template <typename Scalar> - inline Vector3<Scalar> - operator-(const Vector3<Scalar>& v1, const Vector3<Scalar>& v2) - { - return Vector3<Scalar>(v1[0] - v2[0], v1[1] - v2[1], v1[2] - v2[2]); - } - - template <typename Scalar> - inline Vector3<Scalar> - operator-(const Vector3<Scalar>& v) - { - return Vector3<Scalar>(-v[0], -v[1], -v[2]); - } - - template <typename Scalar> - inline Vector3<Scalar> - operator*(const Vector3<Scalar>& v, const Scalar& s) - { - return Vector3<Scalar>(v[0] * s, v[1] * s, v[2] * s); - } - - template <typename Scalar> - inline Vector3<Scalar> - operator*(const Scalar& s, const Vector3<Scalar>& v) - { - return v * s; - } - - template <typename Scalar> - inline Vector3<Scalar> - operator/(const Vector3<Scalar>& v, const Scalar& s) - { - assert(s != Scalar(0.0)); - return v * (Scalar(1.0) / s); - } - - template <typename Scalar> - inline Scalar - dot(const Vector3<Scalar>& v1, const Vector3<Scalar>& v2) - { - return v1.dot(v2); - } - - template <typename Scalar> - inline Scalar - length2(const Vector3<Scalar>& v) - { - return v.length2(); - } - - template <typename Scalar> - inline Scalar - length(const Vector3<Scalar>& v) - { - return v.length(); - } - - template <typename Scalar> - inline Scalar - distance2(const Vector3<Scalar>& v1, const Vector3<Scalar>& v2) - { - return v1.distance2(v2); - } - - template <typename Scalar> - inline Scalar - distance(const Vector3<Scalar>& v1, const Vector3<Scalar>& v2) - { - return v1.distance(v2); - } - - template <typename Scalar> - inline Scalar - angle(const Vector3<Scalar>& v1, const Vector3<Scalar>& v2) - { - return v1.angle(v2); - } - - template <typename Scalar> - inline Vector3<Scalar> - cross(const Vector3<Scalar>& v1, const Vector3<Scalar>& v2) - { - return v1.cross(v2); - } - - template <typename Scalar> - inline Scalar - triple(const Vector3<Scalar>& v1, const Vector3<Scalar>& v2, const Vector3<Scalar>& v3) - { - return v1.triple(v2, v3); - } - - template <typename Scalar> - inline Vector3<Scalar> - lerp(const Vector3<Scalar>& v1, const Vector3<Scalar>& v2, const Scalar& t) - { - return v1.lerp(v2, t); - } - -} - -#endif |