2015-05-19 04:16:51 +00:00
|
|
|
/*
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
Open Asset Import Library (assimp)
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
2018-01-28 18:42:05 +00:00
|
|
|
Copyright (c) 2006-2018, assimp team
|
|
|
|
|
2017-05-09 17:57:36 +00:00
|
|
|
|
2015-05-19 04:16:51 +00:00
|
|
|
|
|
|
|
All rights reserved.
|
|
|
|
|
2015-05-19 04:17:45 +00:00
|
|
|
Redistribution and use of this software in source and binary forms,
|
|
|
|
with or without modification, are permitted provided that the following
|
2015-05-19 04:16:51 +00:00
|
|
|
conditions are met:
|
|
|
|
|
|
|
|
* Redistributions of source code must retain the above
|
|
|
|
copyright notice, this list of conditions and the
|
|
|
|
following disclaimer.
|
|
|
|
|
|
|
|
* Redistributions in binary form must reproduce the above
|
|
|
|
copyright notice, this list of conditions and the
|
|
|
|
following disclaimer in the documentation and/or other
|
|
|
|
materials provided with the distribution.
|
|
|
|
|
|
|
|
* Neither the name of the assimp team, nor the names of its
|
|
|
|
contributors may be used to endorse or promote products
|
|
|
|
derived from this software without specific prior
|
|
|
|
written permission of the assimp team.
|
|
|
|
|
2015-05-19 04:17:45 +00:00
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
2015-05-19 04:16:51 +00:00
|
|
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
2015-05-19 04:17:45 +00:00
|
|
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
2015-05-19 04:16:51 +00:00
|
|
|
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
2015-05-19 04:17:45 +00:00
|
|
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
2015-05-19 04:16:51 +00:00
|
|
|
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
2015-05-19 04:17:45 +00:00
|
|
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
2015-05-19 04:16:51 +00:00
|
|
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** @file vector3.inl
|
|
|
|
* @brief Inline implementation of aiVector3t<TReal> operators
|
|
|
|
*/
|
2016-07-11 18:56:38 +00:00
|
|
|
#pragma once
|
2015-05-19 04:16:51 +00:00
|
|
|
#ifndef AI_VECTOR3D_INL_INC
|
|
|
|
#define AI_VECTOR3D_INL_INC
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
#include "vector3.h"
|
|
|
|
|
|
|
|
#include <cmath>
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
/** Transformation of a vector by a 3x3 matrix */
|
|
|
|
template <typename TReal>
|
2018-01-01 19:57:59 +00:00
|
|
|
AI_FORCE_INLINE
|
|
|
|
aiVector3t<TReal> operator * (const aiMatrix3x3t<TReal>& pMatrix, const aiVector3t<TReal>& pVector) {
|
2015-05-19 04:18:29 +00:00
|
|
|
aiVector3t<TReal> res;
|
|
|
|
res.x = pMatrix.a1 * pVector.x + pMatrix.a2 * pVector.y + pMatrix.a3 * pVector.z;
|
|
|
|
res.y = pMatrix.b1 * pVector.x + pMatrix.b2 * pVector.y + pMatrix.b3 * pVector.z;
|
|
|
|
res.z = pMatrix.c1 * pVector.x + pMatrix.c2 * pVector.y + pMatrix.c3 * pVector.z;
|
|
|
|
return res;
|
2015-05-19 04:16:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
/** Transformation of a vector by a 4x4 matrix */
|
|
|
|
template <typename TReal>
|
2018-01-01 19:57:59 +00:00
|
|
|
AI_FORCE_INLINE
|
|
|
|
aiVector3t<TReal> operator * (const aiMatrix4x4t<TReal>& pMatrix, const aiVector3t<TReal>& pVector) {
|
2015-05-19 04:18:29 +00:00
|
|
|
aiVector3t<TReal> res;
|
|
|
|
res.x = pMatrix.a1 * pVector.x + pMatrix.a2 * pVector.y + pMatrix.a3 * pVector.z + pMatrix.a4;
|
|
|
|
res.y = pMatrix.b1 * pVector.x + pMatrix.b2 * pVector.y + pMatrix.b3 * pVector.z + pMatrix.b4;
|
|
|
|
res.z = pMatrix.c1 * pVector.x + pMatrix.c2 * pVector.y + pMatrix.c3 * pVector.z + pMatrix.c4;
|
|
|
|
return res;
|
2015-05-19 04:16:51 +00:00
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
template <typename TReal>
|
|
|
|
template <typename TOther>
|
|
|
|
aiVector3t<TReal>::operator aiVector3t<TOther> () const {
|
2015-05-19 04:18:29 +00:00
|
|
|
return aiVector3t<TOther>(static_cast<TOther>(x),static_cast<TOther>(y),static_cast<TOther>(z));
|
2015-05-19 04:16:51 +00:00
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
template <typename TReal>
|
2018-01-01 19:57:59 +00:00
|
|
|
AI_FORCE_INLINE
|
|
|
|
void aiVector3t<TReal>::Set( TReal pX, TReal pY, TReal pZ) {
|
|
|
|
x = pX;
|
|
|
|
y = pY;
|
|
|
|
z = pZ;
|
2015-05-19 04:16:51 +00:00
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
template <typename TReal>
|
2018-01-01 19:57:59 +00:00
|
|
|
AI_FORCE_INLINE
|
|
|
|
TReal aiVector3t<TReal>::SquareLength() const {
|
2015-05-19 04:18:29 +00:00
|
|
|
return x*x + y*y + z*z;
|
2015-05-19 04:16:51 +00:00
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
template <typename TReal>
|
2018-01-01 19:57:59 +00:00
|
|
|
AI_FORCE_INLINE
|
|
|
|
TReal aiVector3t<TReal>::Length() const {
|
2015-05-19 04:18:29 +00:00
|
|
|
return std::sqrt( SquareLength());
|
2015-05-19 04:16:51 +00:00
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
template <typename TReal>
|
2018-01-01 19:57:59 +00:00
|
|
|
AI_FORCE_INLINE
|
|
|
|
aiVector3t<TReal>& aiVector3t<TReal>::Normalize() {
|
|
|
|
*this /= Length();
|
|
|
|
|
|
|
|
return *this;
|
2015-05-19 04:16:51 +00:00
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
template <typename TReal>
|
2018-01-01 19:57:59 +00:00
|
|
|
AI_FORCE_INLINE
|
|
|
|
aiVector3t<TReal>& aiVector3t<TReal>::NormalizeSafe() {
|
2015-12-14 02:31:49 +00:00
|
|
|
TReal len = Length();
|
2018-01-01 19:57:59 +00:00
|
|
|
if ( len > static_cast< TReal >( 0 ) ) {
|
2015-12-14 02:37:27 +00:00
|
|
|
*this /= len;
|
2018-01-01 19:57:59 +00:00
|
|
|
}
|
2015-12-14 02:31:49 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
template <typename TReal>
|
2018-01-01 19:57:59 +00:00
|
|
|
AI_FORCE_INLINE
|
|
|
|
const aiVector3t<TReal>& aiVector3t<TReal>::operator += (const aiVector3t<TReal>& o) {
|
|
|
|
x += o.x;
|
|
|
|
y += o.y;
|
|
|
|
z += o.z;
|
|
|
|
|
|
|
|
return *this;
|
2015-05-19 04:16:51 +00:00
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
template <typename TReal>
|
2018-01-01 19:57:59 +00:00
|
|
|
AI_FORCE_INLINE
|
|
|
|
const aiVector3t<TReal>& aiVector3t<TReal>::operator -= (const aiVector3t<TReal>& o) {
|
|
|
|
x -= o.x;
|
|
|
|
y -= o.y;
|
|
|
|
z -= o.z;
|
|
|
|
|
|
|
|
return *this;
|
2015-05-19 04:16:51 +00:00
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
template <typename TReal>
|
2018-01-01 19:57:59 +00:00
|
|
|
AI_FORCE_INLINE
|
|
|
|
const aiVector3t<TReal>& aiVector3t<TReal>::operator *= (TReal f) {
|
|
|
|
x *= f;
|
|
|
|
y *= f;
|
|
|
|
z *= f;
|
|
|
|
|
|
|
|
return *this;
|
2015-05-19 04:16:51 +00:00
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
template <typename TReal>
|
2018-01-01 19:57:59 +00:00
|
|
|
AI_FORCE_INLINE
|
|
|
|
const aiVector3t<TReal>& aiVector3t<TReal>::operator /= (TReal f) {
|
|
|
|
const TReal invF = (TReal) 1.0 / f;
|
|
|
|
x *= invF;
|
|
|
|
y *= invF;
|
|
|
|
z *= invF;
|
|
|
|
|
|
|
|
return *this;
|
2015-05-19 04:16:51 +00:00
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
template <typename TReal>
|
2018-01-01 19:57:59 +00:00
|
|
|
AI_FORCE_INLINE
|
|
|
|
aiVector3t<TReal>& aiVector3t<TReal>::operator *= (const aiMatrix3x3t<TReal>& mat){
|
|
|
|
return (*this = mat * (*this));
|
2015-05-19 04:16:51 +00:00
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
template <typename TReal>
|
2018-01-01 19:57:59 +00:00
|
|
|
AI_FORCE_INLINE
|
|
|
|
aiVector3t<TReal>& aiVector3t<TReal>::operator *= (const aiMatrix4x4t<TReal>& mat){
|
|
|
|
return (*this = mat * (*this));
|
2015-05-19 04:16:51 +00:00
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
template <typename TReal>
|
2018-01-01 19:57:59 +00:00
|
|
|
AI_FORCE_INLINE
|
|
|
|
TReal aiVector3t<TReal>::operator[](unsigned int i) const {
|
2017-02-21 09:58:27 +00:00
|
|
|
switch (i) {
|
|
|
|
case 0:
|
|
|
|
return x;
|
|
|
|
case 1:
|
|
|
|
return y;
|
|
|
|
case 2:
|
|
|
|
return z;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return x;
|
2015-05-19 04:16:51 +00:00
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
template <typename TReal>
|
2018-01-01 19:57:59 +00:00
|
|
|
AI_FORCE_INLINE
|
|
|
|
TReal& aiVector3t<TReal>::operator[](unsigned int i) {
|
2017-02-21 09:58:27 +00:00
|
|
|
// return *(&x + i);
|
|
|
|
switch (i) {
|
|
|
|
case 0:
|
|
|
|
return x;
|
|
|
|
case 1:
|
|
|
|
return y;
|
|
|
|
case 2:
|
|
|
|
return z;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return x;
|
2015-05-19 04:16:51 +00:00
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
template <typename TReal>
|
2018-01-01 19:57:59 +00:00
|
|
|
AI_FORCE_INLINE
|
|
|
|
bool aiVector3t<TReal>::operator== (const aiVector3t<TReal>& other) const {
|
2015-05-19 04:18:29 +00:00
|
|
|
return x == other.x && y == other.y && z == other.z;
|
2015-05-19 04:16:51 +00:00
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
template <typename TReal>
|
2018-01-01 19:57:59 +00:00
|
|
|
AI_FORCE_INLINE
|
|
|
|
bool aiVector3t<TReal>::operator!= (const aiVector3t<TReal>& other) const {
|
2015-05-19 04:18:29 +00:00
|
|
|
return x != other.x || y != other.y || z != other.z;
|
2015-05-19 04:16:51 +00:00
|
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
template<typename TReal>
|
2018-01-01 19:57:59 +00:00
|
|
|
AI_FORCE_INLINE
|
|
|
|
bool aiVector3t<TReal>::Equal(const aiVector3t<TReal>& other, TReal epsilon) const {
|
2015-05-19 04:18:29 +00:00
|
|
|
return
|
|
|
|
std::abs(x - other.x) <= epsilon &&
|
|
|
|
std::abs(y - other.y) <= epsilon &&
|
|
|
|
std::abs(z - other.z) <= epsilon;
|
2015-05-19 04:16:51 +00:00
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
template <typename TReal>
|
2018-01-01 19:57:59 +00:00
|
|
|
AI_FORCE_INLINE
|
|
|
|
bool aiVector3t<TReal>::operator < (const aiVector3t<TReal>& other) const {
|
2015-05-19 04:18:29 +00:00
|
|
|
return x != other.x ? x < other.x : y != other.y ? y < other.y : z < other.z;
|
2015-05-19 04:16:51 +00:00
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
template <typename TReal>
|
2018-01-01 19:57:59 +00:00
|
|
|
AI_FORCE_INLINE
|
|
|
|
const aiVector3t<TReal> aiVector3t<TReal>::SymMul(const aiVector3t<TReal>& o) {
|
2015-05-19 04:18:29 +00:00
|
|
|
return aiVector3t<TReal>(x*o.x,y*o.y,z*o.z);
|
2015-05-19 04:16:51 +00:00
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// symmetric addition
|
|
|
|
template <typename TReal>
|
2018-01-01 19:57:59 +00:00
|
|
|
AI_FORCE_INLINE
|
|
|
|
aiVector3t<TReal> operator + (const aiVector3t<TReal>& v1, const aiVector3t<TReal>& v2) {
|
2015-05-19 04:18:29 +00:00
|
|
|
return aiVector3t<TReal>( v1.x + v2.x, v1.y + v2.y, v1.z + v2.z);
|
2015-05-19 04:16:51 +00:00
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// symmetric subtraction
|
|
|
|
template <typename TReal>
|
2018-01-01 19:57:59 +00:00
|
|
|
AI_FORCE_INLINE
|
|
|
|
aiVector3t<TReal> operator - (const aiVector3t<TReal>& v1, const aiVector3t<TReal>& v2) {
|
2015-05-19 04:18:29 +00:00
|
|
|
return aiVector3t<TReal>( v1.x - v2.x, v1.y - v2.y, v1.z - v2.z);
|
2015-05-19 04:16:51 +00:00
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// scalar product
|
|
|
|
template <typename TReal>
|
2018-01-01 19:57:59 +00:00
|
|
|
AI_FORCE_INLINE
|
|
|
|
TReal operator * (const aiVector3t<TReal>& v1, const aiVector3t<TReal>& v2) {
|
2015-05-19 04:18:29 +00:00
|
|
|
return v1.x*v2.x + v1.y*v2.y + v1.z*v2.z;
|
2015-05-19 04:16:51 +00:00
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// scalar multiplication
|
|
|
|
template <typename TReal>
|
2018-01-01 19:57:59 +00:00
|
|
|
AI_FORCE_INLINE
|
|
|
|
aiVector3t<TReal> operator * ( TReal f, const aiVector3t<TReal>& v) {
|
2015-05-19 04:18:29 +00:00
|
|
|
return aiVector3t<TReal>( f*v.x, f*v.y, f*v.z);
|
2015-05-19 04:16:51 +00:00
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// and the other way around
|
|
|
|
template <typename TReal>
|
2018-01-01 19:57:59 +00:00
|
|
|
AI_FORCE_INLINE
|
|
|
|
aiVector3t<TReal> operator * ( const aiVector3t<TReal>& v, TReal f) {
|
2015-05-19 04:18:29 +00:00
|
|
|
return aiVector3t<TReal>( f*v.x, f*v.y, f*v.z);
|
2015-05-19 04:16:51 +00:00
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// scalar division
|
|
|
|
template <typename TReal>
|
2018-01-01 19:57:59 +00:00
|
|
|
AI_FORCE_INLINE
|
|
|
|
aiVector3t<TReal> operator / ( const aiVector3t<TReal>& v, TReal f) {
|
2015-05-19 04:18:29 +00:00
|
|
|
return v * (1/f);
|
2015-05-19 04:16:51 +00:00
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// vector division
|
|
|
|
template <typename TReal>
|
2018-01-01 19:57:59 +00:00
|
|
|
AI_FORCE_INLINE
|
|
|
|
aiVector3t<TReal> operator / ( const aiVector3t<TReal>& v, const aiVector3t<TReal>& v2) {
|
2015-05-19 04:18:29 +00:00
|
|
|
return aiVector3t<TReal>(v.x / v2.x,v.y / v2.y,v.z / v2.z);
|
2015-05-19 04:16:51 +00:00
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// cross product
|
2018-01-01 19:57:59 +00:00
|
|
|
template<typename TReal>
|
|
|
|
AI_FORCE_INLINE
|
|
|
|
aiVector3t<TReal> operator ^ ( const aiVector3t<TReal>& v1, const aiVector3t<TReal>& v2) {
|
2015-05-19 04:18:29 +00:00
|
|
|
return aiVector3t<TReal>( v1.y*v2.z - v1.z*v2.y, v1.z*v2.x - v1.x*v2.z, v1.x*v2.y - v1.y*v2.x);
|
2015-05-19 04:16:51 +00:00
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// vector negation
|
2018-01-01 19:57:59 +00:00
|
|
|
template<typename TReal>
|
|
|
|
AI_FORCE_INLINE
|
|
|
|
aiVector3t<TReal> operator - ( const aiVector3t<TReal>& v) {
|
2015-05-19 04:18:29 +00:00
|
|
|
return aiVector3t<TReal>( -v.x, -v.y, -v.z);
|
2015-05-19 04:16:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#endif // __cplusplus
|
|
|
|
#endif // AI_VECTOR3D_INL_INC
|