From f88970f8fec7dce9865e4864d23ac58dd8f3cc44 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Thu, 11 Sep 2014 12:12:25 -0700 Subject: [PATCH] moved Extents to shared --- libraries/fbx/src/FBXReader.cpp | 21 --------- libraries/fbx/src/FBXReader.h | 27 +----------- libraries/shared/src/Extents.cpp | 74 ++++++++++++++++++++++++++++++++ libraries/shared/src/Extents.h | 53 +++++++++++++++++++++++ 4 files changed, 129 insertions(+), 46 deletions(-) create mode 100644 libraries/shared/src/Extents.cpp create mode 100644 libraries/shared/src/Extents.h diff --git a/libraries/fbx/src/FBXReader.cpp b/libraries/fbx/src/FBXReader.cpp index 6f87bcf1f8..88888ac381 100644 --- a/libraries/fbx/src/FBXReader.cpp +++ b/libraries/fbx/src/FBXReader.cpp @@ -33,27 +33,6 @@ using namespace std; -void Extents::reset() { - minimum = glm::vec3(FLT_MAX); - maximum = glm::vec3(-FLT_MAX); -} - -bool Extents::containsPoint(const glm::vec3& point) const { - return (point.x >= minimum.x && point.x <= maximum.x - && point.y >= minimum.y && point.y <= maximum.y - && point.z >= minimum.z && point.z <= maximum.z); -} - -void Extents::addExtents(const Extents& extents) { - minimum = glm::min(minimum, extents.minimum); - maximum = glm::max(maximum, extents.maximum); -} - -void Extents::addPoint(const glm::vec3& point) { - minimum = glm::min(minimum, point); - maximum = glm::max(maximum, point); -} - bool FBXMesh::hasSpecularTexture() const { foreach (const FBXMeshPart& part, parts) { if (!part.specularTexture.filename.isEmpty()) { diff --git a/libraries/fbx/src/FBXReader.h b/libraries/fbx/src/FBXReader.h index d07a33f3d4..e54e218a5b 100644 --- a/libraries/fbx/src/FBXReader.h +++ b/libraries/fbx/src/FBXReader.h @@ -18,8 +18,10 @@ #include #include +#include #include + #include #include @@ -35,31 +37,6 @@ extern const int NUM_FACESHIFT_BLENDSHAPES; /// The names of the joints in the Maya HumanIK rig, terminated with an empty string. extern const char* HUMANIK_JOINTS[]; -class Extents { -public: - /// set minimum and maximum to FLT_MAX and -FLT_MAX respectively - void reset(); - - /// \param extents another intance of extents - /// expand current limits to contain other extents - void addExtents(const Extents& extents); - - /// \param point new point to compare against existing limits - /// compare point to current limits and expand them if necessary to contain point - void addPoint(const glm::vec3& point); - - /// \param point - /// \return true if point is within current limits - bool containsPoint(const glm::vec3& point) const; - - /// \return whether or not the extents are empty - bool isEmpty() const { return minimum == maximum; } - bool isValid() const { return !((minimum == glm::vec3(FLT_MAX)) && (maximum == glm::vec3(-FLT_MAX))); } - - glm::vec3 minimum; - glm::vec3 maximum; -}; - /// A node within an FBX document. class FBXNode { public: diff --git a/libraries/shared/src/Extents.cpp b/libraries/shared/src/Extents.cpp new file mode 100644 index 0000000000..02e09bfa3c --- /dev/null +++ b/libraries/shared/src/Extents.cpp @@ -0,0 +1,74 @@ +// +// Extents.cpp +// libraries/shared/src +// +// Created by Andrzej Kapolka on 9/18/13. +// Moved to shared by Brad Hefta-Gaub on 9/11/14 +// Copyright 2013-2104 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#include +#include +#include + +#include "Extents.h" + +void Extents::reset() { + minimum = glm::vec3(FLT_MAX); + maximum = glm::vec3(-FLT_MAX); +} + +bool Extents::containsPoint(const glm::vec3& point) const { + return (point.x >= minimum.x && point.x <= maximum.x + && point.y >= minimum.y && point.y <= maximum.y + && point.z >= minimum.z && point.z <= maximum.z); +} + +void Extents::addExtents(const Extents& extents) { + minimum = glm::min(minimum, extents.minimum); + maximum = glm::max(maximum, extents.maximum); +} + +void Extents::addPoint(const glm::vec3& point) { + minimum = glm::min(minimum, point); + maximum = glm::max(maximum, point); +} + +void Extents::rotate(const glm::quat& rotation) { + glm::vec3 bottomLeftNear(minimum.x, minimum.y, minimum.z); + glm::vec3 bottomRightNear(maximum.x, minimum.y, minimum.z); + glm::vec3 bottomLeftFar(minimum.x, minimum.y, maximum.z); + glm::vec3 bottomRightFar(maximum.x, minimum.y, maximum.z); + glm::vec3 topLeftNear(minimum.x, maximum.y, minimum.z); + glm::vec3 topRightNear(maximum.x, maximum.y, minimum.z); + glm::vec3 topLeftFar(minimum.x, maximum.y, maximum.z); + glm::vec3 topRightFar(maximum.x, maximum.y, maximum.z); + + glm::vec3 bottomLeftNearRotated = rotation * bottomLeftNear; + glm::vec3 bottomRightNearRotated = rotation * bottomRightNear; + glm::vec3 bottomLeftFarRotated = rotation * bottomLeftFar; + glm::vec3 bottomRightFarRotated = rotation * bottomRightFar; + glm::vec3 topLeftNearRotated = rotation * topLeftNear; + glm::vec3 topRightNearRotated = rotation * topRightNear; + glm::vec3 topLeftFarRotated = rotation * topLeftFar; + glm::vec3 topRightFarRotated = rotation * topRightFar; + + minimum = glm::min(bottomLeftNearRotated, + glm::min(bottomRightNearRotated, + glm::min(bottomLeftFarRotated, + glm::min(bottomRightFarRotated, + glm::min(topLeftNearRotated, + glm::min(topRightNearRotated, + glm::min(topLeftFarRotated,topRightFarRotated))))))); + + maximum = glm::max(bottomLeftNearRotated, + glm::max(bottomRightNearRotated, + glm::max(bottomLeftFarRotated, + glm::max(bottomRightFarRotated, + glm::max(topLeftNearRotated, + glm::max(topRightNearRotated, + glm::max(topLeftFarRotated,topRightFarRotated))))))); +} diff --git a/libraries/shared/src/Extents.h b/libraries/shared/src/Extents.h new file mode 100644 index 0000000000..c0e68bd2b1 --- /dev/null +++ b/libraries/shared/src/Extents.h @@ -0,0 +1,53 @@ +// +// Extents.h +// libraries/shared/src +// +// Created by Andrzej Kapolka on 9/18/13. +// Moved to shared by Brad Hefta-Gaub on 9/11/14 +// Copyright 2013-2104 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#ifndef hifi_Extents_h +#define hifi_Extents_h + +#include + +class Extents { +public: + /// set minimum and maximum to FLT_MAX and -FLT_MAX respectively + void reset(); + + /// \param extents another intance of extents + /// expand current limits to contain other extents + void addExtents(const Extents& extents); + + /// \param point new point to compare against existing limits + /// compare point to current limits and expand them if necessary to contain point + void addPoint(const glm::vec3& point); + + /// \param point + /// \return true if point is within current limits + bool containsPoint(const glm::vec3& point) const; + + /// \return whether or not the extents are empty + bool isEmpty() const { return minimum == maximum; } + bool isValid() const { return !((minimum == glm::vec3(FLT_MAX)) && (maximum == glm::vec3(-FLT_MAX))); } + + /// rotate the extents around orign by rotation + void rotate(const glm::quat& rotation); + + /// \return new Extents which is original rotated around orign by rotation + Extents getRotated(const glm::quat& rotation) const { + Extents temp = { minimum, maximum }; + temp.rotate(rotation); + return temp; + } + + glm::vec3 minimum; + glm::vec3 maximum; +}; + +#endif // hifi_Extents_h \ No newline at end of file