From f88970f8fec7dce9865e4864d23ac58dd8f3cc44 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Thu, 11 Sep 2014 12:12:25 -0700 Subject: [PATCH 1/6] 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 From a022d4779284b33647fc8015da3f93bf6883a38a Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Thu, 11 Sep 2014 12:13:34 -0700 Subject: [PATCH 2/6] improve constness for operators on PropertyFlags<> --- libraries/shared/src/PropertyFlags.h | 52 ++++++++++++++-------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/libraries/shared/src/PropertyFlags.h b/libraries/shared/src/PropertyFlags.h index 9b21ff9f9f..846c4886b0 100644 --- a/libraries/shared/src/PropertyFlags.h +++ b/libraries/shared/src/PropertyFlags.h @@ -49,7 +49,7 @@ public: Enum lastFlag() const { return (Enum)_maxFlag; } void setHasProperty(Enum flag, bool value = true); - bool getHasProperty(Enum flag); + bool getHasProperty(Enum flag) const; QByteArray encode(); void decode(const QByteArray& fromEncoded); @@ -61,42 +61,42 @@ public: PropertyFlags& operator=(const PropertyFlags& other); - PropertyFlags& operator|=(PropertyFlags other); + PropertyFlags& operator|=(const PropertyFlags& other); PropertyFlags& operator|=(Enum flag); - PropertyFlags& operator&=(PropertyFlags other); + PropertyFlags& operator&=(const PropertyFlags& other); PropertyFlags& operator&=(Enum flag); - PropertyFlags& operator+=(PropertyFlags other); + PropertyFlags& operator+=(const PropertyFlags& other); PropertyFlags& operator+=(Enum flag); - PropertyFlags& operator-=(PropertyFlags other); + PropertyFlags& operator-=(const PropertyFlags& other); PropertyFlags& operator-=(Enum flag); - PropertyFlags& operator<<=(PropertyFlags other); + PropertyFlags& operator<<=(const PropertyFlags& other); PropertyFlags& operator<<=(Enum flag); - PropertyFlags operator|(PropertyFlags other) const; + PropertyFlags operator|(const PropertyFlags& other) const; PropertyFlags operator|(Enum flag) const; - PropertyFlags operator&(PropertyFlags other) const; + PropertyFlags operator&(const PropertyFlags& other) const; PropertyFlags operator&(Enum flag) const; - PropertyFlags operator+(PropertyFlags other) const; + PropertyFlags operator+(const PropertyFlags& other) const; PropertyFlags operator+(Enum flag) const; - PropertyFlags operator-(PropertyFlags other) const; + PropertyFlags operator-(const PropertyFlags& other) const; PropertyFlags operator-(Enum flag) const; - PropertyFlags operator<<(PropertyFlags other) const; + PropertyFlags operator<<(const PropertyFlags& other) const; PropertyFlags operator<<(Enum flag) const; // NOTE: due to the nature of the compact storage of these property flags, and the fact that the upper bound of the // enum is not know, these operators will only perform their bitwise operations on the set of properties that have // been previously set - PropertyFlags& operator^=(PropertyFlags other); + PropertyFlags& operator^=(const PropertyFlags& other); PropertyFlags& operator^=(Enum flag); - PropertyFlags operator^(PropertyFlags other) const; + PropertyFlags operator^(const PropertyFlags& other) const; PropertyFlags operator^(Enum flag) const; PropertyFlags operator~() const; @@ -146,7 +146,7 @@ template inline void PropertyFlags::setHasProperty(Enum fla } } -template inline bool PropertyFlags::getHasProperty(Enum flag) { +template inline bool PropertyFlags::getHasProperty(Enum flag) const { if (flag > _maxFlag) { return _trailingFlipped; // usually false } @@ -253,7 +253,7 @@ template inline PropertyFlags& PropertyFlags::operato return *this; } -template inline PropertyFlags& PropertyFlags::operator|=(PropertyFlags other) { +template inline PropertyFlags& PropertyFlags::operator|=(const PropertyFlags& other) { _flags |= other._flags; _maxFlag = std::max(_maxFlag, other._maxFlag); _minFlag = std::min(_minFlag, other._minFlag); @@ -268,7 +268,7 @@ template inline PropertyFlags& PropertyFlags::operato return *this; } -template inline PropertyFlags& PropertyFlags::operator&=(PropertyFlags other) { +template inline PropertyFlags& PropertyFlags::operator&=(const PropertyFlags& other) { _flags &= other._flags; shinkIfNeeded(); return *this; @@ -281,7 +281,7 @@ template inline PropertyFlags& PropertyFlags::operato return *this; } -template inline PropertyFlags& PropertyFlags::operator^=(PropertyFlags other) { +template inline PropertyFlags& PropertyFlags::operator^=(const PropertyFlags& other) { _flags ^= other._flags; shinkIfNeeded(); return *this; @@ -294,7 +294,7 @@ template inline PropertyFlags& PropertyFlags::operato return *this; } -template inline PropertyFlags& PropertyFlags::operator+=(PropertyFlags other) { +template inline PropertyFlags& PropertyFlags::operator+=(const PropertyFlags& other) { for(int flag = (int)other.firstFlag(); flag <= (int)other.lastFlag(); flag++) { if (other.getHasProperty((Enum)flag)) { setHasProperty((Enum)flag, true); @@ -308,7 +308,7 @@ template inline PropertyFlags& PropertyFlags::operato return *this; } -template inline PropertyFlags& PropertyFlags::operator-=(PropertyFlags other) { +template inline PropertyFlags& PropertyFlags::operator-=(const PropertyFlags& other) { for(int flag = (int)other.firstFlag(); flag <= (int)other.lastFlag(); flag++) { if (other.getHasProperty((Enum)flag)) { setHasProperty((Enum)flag, false); @@ -322,7 +322,7 @@ template inline PropertyFlags& PropertyFlags::operato return *this; } -template inline PropertyFlags& PropertyFlags::operator<<=(PropertyFlags other) { +template inline PropertyFlags& PropertyFlags::operator<<=(const PropertyFlags& other) { for(int flag = (int)other.firstFlag(); flag <= (int)other.lastFlag(); flag++) { if (other.getHasProperty((Enum)flag)) { setHasProperty((Enum)flag, true); @@ -336,7 +336,7 @@ template inline PropertyFlags& PropertyFlags::operato return *this; } -template inline PropertyFlags PropertyFlags::operator|(PropertyFlags other) const { +template inline PropertyFlags PropertyFlags::operator|(const PropertyFlags& other) const { PropertyFlags result(*this); result |= other; return result; @@ -349,7 +349,7 @@ template inline PropertyFlags PropertyFlags::operator return result; } -template inline PropertyFlags PropertyFlags::operator&(PropertyFlags other) const { +template inline PropertyFlags PropertyFlags::operator&(const PropertyFlags& other) const { PropertyFlags result(*this); result &= other; return result; @@ -362,7 +362,7 @@ template inline PropertyFlags PropertyFlags::operator return result; } -template inline PropertyFlags PropertyFlags::operator^(PropertyFlags other) const { +template inline PropertyFlags PropertyFlags::operator^(const PropertyFlags& other) const { PropertyFlags result(*this); result ^= other; return result; @@ -375,7 +375,7 @@ template inline PropertyFlags PropertyFlags::operator return result; } -template inline PropertyFlags PropertyFlags::operator+(PropertyFlags other) const { +template inline PropertyFlags PropertyFlags::operator+(const PropertyFlags& other) const { PropertyFlags result(*this); result += other; return result; @@ -387,7 +387,7 @@ template inline PropertyFlags PropertyFlags::operator return result; } -template inline PropertyFlags PropertyFlags::operator-(PropertyFlags other) const { +template inline PropertyFlags PropertyFlags::operator-(const PropertyFlags& other) const { PropertyFlags result(*this); result -= other; return result; @@ -399,7 +399,7 @@ template inline PropertyFlags PropertyFlags::operator return result; } -template inline PropertyFlags PropertyFlags::operator<<(PropertyFlags other) const { +template inline PropertyFlags PropertyFlags::operator<<(const PropertyFlags& other) const { PropertyFlags result(*this); result <<= other; return result; From ceb1740f381c3de55220d1b409c188e8e1a15472 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Thu, 11 Sep 2014 12:23:35 -0700 Subject: [PATCH 3/6] handy conversions between AABox, AACube, and Extents --- libraries/shared/src/AABox.cpp | 6 ++++++ libraries/shared/src/AABox.h | 2 ++ libraries/shared/src/AACube.cpp | 14 ++++++++++++++ libraries/shared/src/AACube.h | 5 ++++- 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/libraries/shared/src/AABox.cpp b/libraries/shared/src/AABox.cpp index 4c01801d5d..00e6db7d33 100644 --- a/libraries/shared/src/AABox.cpp +++ b/libraries/shared/src/AABox.cpp @@ -11,6 +11,7 @@ #include "AABox.h" #include "AACube.h" +#include "Extents.h" #include "GeometryUtil.h" #include "SharedUtil.h" @@ -19,6 +20,11 @@ AABox::AABox(const AACube& other) : _corner(other.getCorner()), _scale(other.getScale(), other.getScale(), other.getScale()) { } +AABox::AABox(const Extents& other) : + _corner(other.minimum), + _scale(other.maximum - other.minimum) { +} + AABox::AABox(const glm::vec3& corner, float size) : _corner(corner), _scale(size, size, size) { }; diff --git a/libraries/shared/src/AABox.h b/libraries/shared/src/AABox.h index 30ebc00afb..5e5cff4574 100644 --- a/libraries/shared/src/AABox.h +++ b/libraries/shared/src/AABox.h @@ -23,11 +23,13 @@ #include "StreamUtils.h" class AACube; +class Extents; class AABox { public: AABox(const AACube& other); + AABox(const Extents& other); AABox(const glm::vec3& corner, float size); AABox(const glm::vec3& corner, const glm::vec3& dimensions); AABox(); diff --git a/libraries/shared/src/AACube.cpp b/libraries/shared/src/AACube.cpp index bf8e972455..55940ba50b 100644 --- a/libraries/shared/src/AACube.cpp +++ b/libraries/shared/src/AACube.cpp @@ -9,11 +9,25 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +#include + #include "AABox.h" #include "AACube.h" +#include "Extents.h" #include "GeometryUtil.h" #include "SharedUtil.h" +AACube::AACube(const AABox& other) : + _corner(other.getCorner()), _scale(other.getLargestDimension()) { +} + +AACube::AACube(const Extents& other) : + _corner(other.minimum) +{ + glm::vec3 dimensions = other.maximum - other.minimum; + _scale = glm::max(dimensions.x, dimensions.y, dimensions.z); +} + AACube::AACube(const glm::vec3& corner, float size) : _corner(corner), _scale(size) { }; diff --git a/libraries/shared/src/AACube.h b/libraries/shared/src/AACube.h index 705c025d74..f56f2dee2e 100644 --- a/libraries/shared/src/AACube.h +++ b/libraries/shared/src/AACube.h @@ -1,6 +1,6 @@ // // AACube.h -// libraries/octree/src +// libraries/shared/src // // Created by Brad Hefta-Gaub on 04/11/13. // Copyright 2013 High Fidelity, Inc. @@ -22,10 +22,13 @@ #include "BoxBase.h" class AABox; +class Extents; class AACube { public: + AACube(const AABox& other); + AACube(const Extents& other); AACube(const glm::vec3& corner, float size); AACube(); ~AACube() {}; From 7db2930d9128a8f1f4cffaed6c5b3009b061c2b8 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Thu, 11 Sep 2014 12:29:47 -0700 Subject: [PATCH 4/6] remove calls to calculateRotatedExtents() use Extents.rotate() instead --- .../entities/RenderableModelEntityItem.cpp | 2 +- interface/src/ui/overlays/ModelOverlay.cpp | 2 +- libraries/entities/src/EntityTreeElement.cpp | 2 +- libraries/fbx/src/FBXReader.cpp | 37 ------------------- libraries/fbx/src/FBXReader.h | 2 - 5 files changed, 3 insertions(+), 42 deletions(-) diff --git a/interface/src/entities/RenderableModelEntityItem.cpp b/interface/src/entities/RenderableModelEntityItem.cpp index e2a710123e..03812904b5 100644 --- a/interface/src/entities/RenderableModelEntityItem.cpp +++ b/interface/src/entities/RenderableModelEntityItem.cpp @@ -144,7 +144,7 @@ void RenderableModelEntityItem::render(RenderArgs* args) { float depth = unRotatedExtents.z; Extents rotatedExtents = _model->getUnscaledMeshExtents(); - calculateRotatedExtents(rotatedExtents, rotation); + rotatedExtents.rotate(rotation); glm::vec3 rotatedSize = rotatedExtents.maximum - rotatedExtents.minimum; diff --git a/interface/src/ui/overlays/ModelOverlay.cpp b/interface/src/ui/overlays/ModelOverlay.cpp index b1d55de12a..8d89fe28f0 100644 --- a/interface/src/ui/overlays/ModelOverlay.cpp +++ b/interface/src/ui/overlays/ModelOverlay.cpp @@ -58,7 +58,7 @@ void ModelOverlay::render() { float depth = unRotatedExtents.z; Extents rotatedExtents = _model.getUnscaledMeshExtents(); - calculateRotatedExtents(rotatedExtents, _rotation); + rotatedExtents.rotate(_rotation); glm::vec3 rotatedSize = rotatedExtents.maximum - rotatedExtents.minimum; diff --git a/libraries/entities/src/EntityTreeElement.cpp b/libraries/entities/src/EntityTreeElement.cpp index 8f223abf7e..4dea9b271c 100644 --- a/libraries/entities/src/EntityTreeElement.cpp +++ b/libraries/entities/src/EntityTreeElement.cpp @@ -509,7 +509,7 @@ bool EntityTreeElement::findDetailedRayIntersection(const glm::vec3& origin, con Extents rotatedExtents = extents; - calculateRotatedExtents(rotatedExtents, entity->getRotation()); + rotatedExtents.rotate(entity->getRotation()); rotatedExtents.minimum += entity->getPosition(); rotatedExtents.maximum += entity->getPosition(); diff --git a/libraries/fbx/src/FBXReader.cpp b/libraries/fbx/src/FBXReader.cpp index 88888ac381..d81e297b24 100644 --- a/libraries/fbx/src/FBXReader.cpp +++ b/libraries/fbx/src/FBXReader.cpp @@ -2111,40 +2111,3 @@ FBXGeometry readSVO(const QByteArray& model) { return geometry; } - -void calculateRotatedExtents(Extents& extents, const glm::quat& rotation) { - glm::vec3 bottomLeftNear(extents.minimum.x, extents.minimum.y, extents.minimum.z); - glm::vec3 bottomRightNear(extents.maximum.x, extents.minimum.y, extents.minimum.z); - glm::vec3 bottomLeftFar(extents.minimum.x, extents.minimum.y, extents.maximum.z); - glm::vec3 bottomRightFar(extents.maximum.x, extents.minimum.y, extents.maximum.z); - glm::vec3 topLeftNear(extents.minimum.x, extents.maximum.y, extents.minimum.z); - glm::vec3 topRightNear(extents.maximum.x, extents.maximum.y, extents.minimum.z); - glm::vec3 topLeftFar(extents.minimum.x, extents.maximum.y, extents.maximum.z); - glm::vec3 topRightFar(extents.maximum.x, extents.maximum.y, extents.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; - - extents.minimum = glm::min(bottomLeftNearRotated, - glm::min(bottomRightNearRotated, - glm::min(bottomLeftFarRotated, - glm::min(bottomRightFarRotated, - glm::min(topLeftNearRotated, - glm::min(topRightNearRotated, - glm::min(topLeftFarRotated,topRightFarRotated))))))); - - extents.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/fbx/src/FBXReader.h b/libraries/fbx/src/FBXReader.h index e54e218a5b..48ac4fc81f 100644 --- a/libraries/fbx/src/FBXReader.h +++ b/libraries/fbx/src/FBXReader.h @@ -231,6 +231,4 @@ FBXGeometry readFBX(const QByteArray& model, const QVariantHash& mapping); /// Reads SVO geometry from the supplied model data. FBXGeometry readSVO(const QByteArray& model); -void calculateRotatedExtents(Extents& extents, const glm::quat& rotation); - #endif // hifi_FBXReader_h From 1d0ba52445d2b750ac7626c8bd05d6563a576e14 Mon Sep 17 00:00:00 2001 From: Craig Hansen-Sturm Date: Thu, 11 Sep 2014 17:15:49 -0700 Subject: [PATCH 5/6] implemented new audio panning object which implements constant power sin^2+cos^2=1 law --- interface/src/Audio.h | 1 + libraries/audio/src/AudioPan.cpp | 23 +++++ libraries/audio/src/AudioPan.h | 141 +++++++++++++++++++++++++++++++ 3 files changed, 165 insertions(+) create mode 100644 libraries/audio/src/AudioPan.cpp create mode 100644 libraries/audio/src/AudioPan.h diff --git a/interface/src/Audio.h b/interface/src/Audio.h index f73e0331de..f100c04684 100644 --- a/interface/src/Audio.h +++ b/interface/src/Audio.h @@ -26,6 +26,7 @@ #include "AudioSourceTone.h" #include "AudioSourceNoise.h" #include "AudioGain.h" +#include "AudioPan.h" #include "AudioFilter.h" #include "AudioFilterBank.h" diff --git a/libraries/audio/src/AudioPan.cpp b/libraries/audio/src/AudioPan.cpp new file mode 100644 index 0000000000..8f9b568b6a --- /dev/null +++ b/libraries/audio/src/AudioPan.cpp @@ -0,0 +1,23 @@ +// +// AudioSourceTone.cpp +// hifi +// +// Created by Craig Hansen-Sturm on 8/10/14. +// Copyright 2014 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 "AudioRingBuffer.h" +#include "AudioFormat.h" +#include "AudioBuffer.h" +#include "AudioPan.h" + +float32_t AudioPan::ONE_MINUS_EPSILON = 1.0f - EPSILON; +float32_t AudioPan::ZERO_PLUS_EPSILON = 0.0f + EPSILON; +float32_t AudioPan::ONE_HALF_MINUS_EPSILON = 0.5f - EPSILON; +float32_t AudioPan::ONE_HALF_PLUS_EPSILON = 0.5f + EPSILON; diff --git a/libraries/audio/src/AudioPan.h b/libraries/audio/src/AudioPan.h new file mode 100644 index 0000000000..85e739b255 --- /dev/null +++ b/libraries/audio/src/AudioPan.h @@ -0,0 +1,141 @@ +// +// AudioPan.h +// hifi +// +// Created by Craig Hansen-Sturm on 9/1/14. +// Copyright 2014 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_AudioPan_h +#define hifi_AudioPan_h + +class AudioPan +{ + float32_t _pan; + float32_t _gainLeft; + float32_t _gainRight; + + static float32_t ONE_MINUS_EPSILON; + static float32_t ZERO_PLUS_EPSILON; + static float32_t ONE_HALF_MINUS_EPSILON; + static float32_t ONE_HALF_PLUS_EPSILON; + + void updateCoefficients() { + + // implement constant power sin^2 + cos^2 = 1 panning law + + if (_pan >= ONE_MINUS_EPSILON) { // full right + _gainLeft = 0.0f; + _gainRight = 1.0f; + } + else if (_pan <= ZERO_PLUS_EPSILON) { // full left + _gainLeft = 1.0f; + _gainRight = 0.0f; + } + else if ((_pan >= ONE_HALF_MINUS_EPSILON) && (_pan <= ONE_HALF_PLUS_EPSILON)) { // center + _gainLeft = 1.0f / SQUARE_ROOT_OF_2; + _gainRight = 1.0f / SQUARE_ROOT_OF_2; + } + else { // intermediate cases + _gainLeft = cosf( TWO_PI * _pan ); + _gainRight = sinf( TWO_PI * _pan ); + } + } + +public: + AudioPan() { + initialize(); + } + + ~AudioPan() { + finalize(); + } + + void initialize() { + setParameters(0.5f); + } + + void finalize() { + } + + void reset() { + initialize(); + } + + void setParameters(const float32_t pan) { + // pan ranges between 0.0 and 1.0f inclusive. 0.5f is midpoint between full left and full right + _pan = std::min(std::max(pan, 0.0f), 1.0f); + updateCoefficients(); + } + + void getParameters(float32_t& pan) { + pan = _pan; + } + + void render(AudioBufferFloat32& frameBuffer) { + + if (frameBuffer.getChannelCount() != 2) { + return; + } + + float32_t** samples = frameBuffer.getFrameData(); + + bool frameAlignment16 = (frameBuffer.getFrameCount() & 0x0F) == 0; + if (frameAlignment16) { + + if (frameBuffer.getChannelCount() == 2) { + + for (uint16_t i = 0; i < frameBuffer.getFrameCount(); i += 16) { + samples[0][i + 0] *= _gainLeft; + samples[0][i + 1] *= _gainLeft; + samples[0][i + 2] *= _gainLeft; + samples[0][i + 3] *= _gainLeft; + samples[0][i + 4] *= _gainLeft; + samples[0][i + 5] *= _gainLeft; + samples[0][i + 6] *= _gainLeft; + samples[0][i + 7] *= _gainLeft; + samples[0][i + 8] *= _gainLeft; + samples[0][i + 9] *= _gainLeft; + samples[0][i + 10] *= _gainLeft; + samples[0][i + 11] *= _gainLeft; + samples[0][i + 12] *= _gainLeft; + samples[0][i + 13] *= _gainLeft; + samples[0][i + 14] *= _gainLeft; + samples[0][i + 15] *= _gainLeft; + samples[1][i + 0] *= _gainRight; + samples[1][i + 1] *= _gainRight; + samples[1][i + 2] *= _gainRight; + samples[1][i + 3] *= _gainRight; + samples[1][i + 4] *= _gainRight; + samples[1][i + 5] *= _gainRight; + samples[1][i + 6] *= _gainRight; + samples[1][i + 7] *= _gainRight; + samples[1][i + 8] *= _gainRight; + samples[1][i + 9] *= _gainRight; + samples[1][i + 10] *= _gainRight; + samples[1][i + 11] *= _gainRight; + samples[1][i + 12] *= _gainRight; + samples[1][i + 13] *= _gainRight; + samples[1][i + 14] *= _gainRight; + samples[1][i + 15] *= _gainRight; + } + } + else { + assert("unsupported channel format"); + } + } + else { + for (uint16_t i = 0; i < frameBuffer.getFrameCount(); i += 1) { + samples[0][i] *= _gainLeft; + samples[1][i] *= _gainRight; + } + } + } +}; + +#endif // AudioPan_h + + From ecae9d5e85d998333fcd9e3c3366d1c3cc50ff7d Mon Sep 17 00:00:00 2001 From: Craig Hansen-Sturm Date: Thu, 11 Sep 2014 17:20:15 -0700 Subject: [PATCH 6/6] compiler warnings --- interface/src/Application.cpp | 2 +- interface/src/Audio.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 273b66e4dc..4261858668 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -3370,7 +3370,7 @@ void Application::updateWindowTitle(){ #ifndef WIN32 // crashes with vs2013/win32 qDebug("Application title set to: %s", title.toStdString().c_str()); -#endif !WIN32 +#endif //!WIN32 _window->setWindowTitle(title); } diff --git a/interface/src/Audio.cpp b/interface/src/Audio.cpp index 9427ec0525..885df74d2b 100644 --- a/interface/src/Audio.cpp +++ b/interface/src/Audio.cpp @@ -102,9 +102,9 @@ Audio::Audio(QObject* parent) : _scopeOutputOffset(0), _framesPerScope(DEFAULT_FRAMES_PER_SCOPE), _samplesPerScope(NETWORK_SAMPLES_PER_FRAME * _framesPerScope), - _peqEnabled(false), _noiseSourceEnabled(false), _toneSourceEnabled(true), + _peqEnabled(false), _scopeInput(0), _scopeOutputLeft(0), _scopeOutputRight(0),