Merge pull request #3396 from ZappoMan/someCleanup

Some cleanup
This commit is contained in:
Craig Hansen-Sturm 2014-09-11 17:38:40 -07:00
commit ee0f8acaf4
12 changed files with 184 additions and 115 deletions

View file

@ -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;

View file

@ -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;

View file

@ -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();

View file

@ -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()) {
@ -2132,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)))))));
}

View file

@ -18,8 +18,10 @@
#include <QVariant>
#include <QVector>
#include <Extents.h>
#include <Shape.h>
#include <glm/glm.hpp>
#include <glm/gtc/quaternion.hpp>
@ -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:
@ -254,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

View file

@ -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) {
};

View file

@ -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();

View file

@ -9,11 +9,25 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include <glm/gtx/extented_min_max.hpp>
#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) {
};

View file

@ -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() {};

View file

@ -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 <glm/gtc/quaternion.hpp>
#include <glm/gtx/quaternion.hpp>
#include <glm/gtx/transform.hpp>
#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)))))));
}

View file

@ -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 <glm/glm.hpp>
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

View file

@ -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<typename Enum> inline void PropertyFlags<Enum>::setHasProperty(Enum fla
}
}
template<typename Enum> inline bool PropertyFlags<Enum>::getHasProperty(Enum flag) {
template<typename Enum> inline bool PropertyFlags<Enum>::getHasProperty(Enum flag) const {
if (flag > _maxFlag) {
return _trailingFlipped; // usually false
}
@ -253,7 +253,7 @@ template<typename Enum> inline PropertyFlags<Enum>& PropertyFlags<Enum>::operato
return *this;
}
template<typename Enum> inline PropertyFlags<Enum>& PropertyFlags<Enum>::operator|=(PropertyFlags other) {
template<typename Enum> inline PropertyFlags<Enum>& PropertyFlags<Enum>::operator|=(const PropertyFlags& other) {
_flags |= other._flags;
_maxFlag = std::max(_maxFlag, other._maxFlag);
_minFlag = std::min(_minFlag, other._minFlag);
@ -268,7 +268,7 @@ template<typename Enum> inline PropertyFlags<Enum>& PropertyFlags<Enum>::operato
return *this;
}
template<typename Enum> inline PropertyFlags<Enum>& PropertyFlags<Enum>::operator&=(PropertyFlags other) {
template<typename Enum> inline PropertyFlags<Enum>& PropertyFlags<Enum>::operator&=(const PropertyFlags& other) {
_flags &= other._flags;
shinkIfNeeded();
return *this;
@ -281,7 +281,7 @@ template<typename Enum> inline PropertyFlags<Enum>& PropertyFlags<Enum>::operato
return *this;
}
template<typename Enum> inline PropertyFlags<Enum>& PropertyFlags<Enum>::operator^=(PropertyFlags other) {
template<typename Enum> inline PropertyFlags<Enum>& PropertyFlags<Enum>::operator^=(const PropertyFlags& other) {
_flags ^= other._flags;
shinkIfNeeded();
return *this;
@ -294,7 +294,7 @@ template<typename Enum> inline PropertyFlags<Enum>& PropertyFlags<Enum>::operato
return *this;
}
template<typename Enum> inline PropertyFlags<Enum>& PropertyFlags<Enum>::operator+=(PropertyFlags other) {
template<typename Enum> inline PropertyFlags<Enum>& PropertyFlags<Enum>::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<typename Enum> inline PropertyFlags<Enum>& PropertyFlags<Enum>::operato
return *this;
}
template<typename Enum> inline PropertyFlags<Enum>& PropertyFlags<Enum>::operator-=(PropertyFlags other) {
template<typename Enum> inline PropertyFlags<Enum>& PropertyFlags<Enum>::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<typename Enum> inline PropertyFlags<Enum>& PropertyFlags<Enum>::operato
return *this;
}
template<typename Enum> inline PropertyFlags<Enum>& PropertyFlags<Enum>::operator<<=(PropertyFlags other) {
template<typename Enum> inline PropertyFlags<Enum>& PropertyFlags<Enum>::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<typename Enum> inline PropertyFlags<Enum>& PropertyFlags<Enum>::operato
return *this;
}
template<typename Enum> inline PropertyFlags<Enum> PropertyFlags<Enum>::operator|(PropertyFlags other) const {
template<typename Enum> inline PropertyFlags<Enum> PropertyFlags<Enum>::operator|(const PropertyFlags& other) const {
PropertyFlags result(*this);
result |= other;
return result;
@ -349,7 +349,7 @@ template<typename Enum> inline PropertyFlags<Enum> PropertyFlags<Enum>::operator
return result;
}
template<typename Enum> inline PropertyFlags<Enum> PropertyFlags<Enum>::operator&(PropertyFlags other) const {
template<typename Enum> inline PropertyFlags<Enum> PropertyFlags<Enum>::operator&(const PropertyFlags& other) const {
PropertyFlags result(*this);
result &= other;
return result;
@ -362,7 +362,7 @@ template<typename Enum> inline PropertyFlags<Enum> PropertyFlags<Enum>::operator
return result;
}
template<typename Enum> inline PropertyFlags<Enum> PropertyFlags<Enum>::operator^(PropertyFlags other) const {
template<typename Enum> inline PropertyFlags<Enum> PropertyFlags<Enum>::operator^(const PropertyFlags& other) const {
PropertyFlags result(*this);
result ^= other;
return result;
@ -375,7 +375,7 @@ template<typename Enum> inline PropertyFlags<Enum> PropertyFlags<Enum>::operator
return result;
}
template<typename Enum> inline PropertyFlags<Enum> PropertyFlags<Enum>::operator+(PropertyFlags other) const {
template<typename Enum> inline PropertyFlags<Enum> PropertyFlags<Enum>::operator+(const PropertyFlags& other) const {
PropertyFlags result(*this);
result += other;
return result;
@ -387,7 +387,7 @@ template<typename Enum> inline PropertyFlags<Enum> PropertyFlags<Enum>::operator
return result;
}
template<typename Enum> inline PropertyFlags<Enum> PropertyFlags<Enum>::operator-(PropertyFlags other) const {
template<typename Enum> inline PropertyFlags<Enum> PropertyFlags<Enum>::operator-(const PropertyFlags& other) const {
PropertyFlags result(*this);
result -= other;
return result;
@ -399,7 +399,7 @@ template<typename Enum> inline PropertyFlags<Enum> PropertyFlags<Enum>::operator
return result;
}
template<typename Enum> inline PropertyFlags<Enum> PropertyFlags<Enum>::operator<<(PropertyFlags other) const {
template<typename Enum> inline PropertyFlags<Enum> PropertyFlags<Enum>::operator<<(const PropertyFlags& other) const {
PropertyFlags result(*this);
result <<= other;
return result;