/** * Copyright (c) 2014-present, Facebook, Inc. * All rights reserved. * * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. */ #ifndef FBX2GLTF_MATHFU_H #define FBX2GLTF_MATHFU_H #include #include #include #include #include /** * All the mathfu:: implementations of our core data types. */ template struct Bounds { mathfu::Vector min; mathfu::Vector max; bool initialized = false; void Clear() { min = mathfu::Vector(); max = mathfu::Vector(); initialized = false; } void AddPoint(const mathfu::Vector &p) { if (initialized) { for (int ii = 0; ii < d; ii ++) { min(ii) = std::min(min(ii), p(ii)); max(ii) = std::max(max(ii), p(ii)); } } else { min = p; max = p; initialized = true; } } }; typedef mathfu::Vector Vec4i; typedef mathfu::Matrix Mat4i; typedef mathfu::Vector Vec2f; typedef mathfu::Vector Vec3f; typedef mathfu::Vector Vec4f; typedef mathfu::Matrix Mat2f; typedef mathfu::Matrix Mat3f; typedef mathfu::Matrix Mat4f; typedef mathfu::Quaternion Quatf; typedef Bounds Boundsf; template static inline std::vector toStdVec(const mathfu::Vector &vec) { std::vector result(d); for (int ii = 0; ii < d; ii ++) { result[ii] = vec[ii]; } return result; } template std::vector toStdVec(const mathfu::Quaternion &quat) { return std::vector { quat.vector()[0], quat.vector()[1], quat.vector()[2], quat.scalar() }; } static inline Vec3f toVec3f(const FbxVector4 &v) { return Vec3f((float) v[0], (float) v[1], (float) v[2]); } static inline Vec4f toVec4f(const FbxVector4 &v) { return Vec4f((float) v[0], (float) v[1], (float) v[2], (float) v[3]); } static inline Mat4f toMat4f(const FbxAMatrix &m) { auto result = Mat4f(); for (int row = 0; row < 4; row ++) { for (int col = 0; col < 4; col ++) { result(row, col) = (float) m[row][col]; } } return result; } static inline Quatf toQuatf(const FbxQuaternion &q) { return Quatf((float) q[3], (float) q[0], (float) q[1], (float) q[2]); } #endif //FBX2GLTF_MATHFU_H