From 778bdec6d840ff7547cb65cb24fc639c7782fd29 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Thu, 6 Mar 2014 12:34:21 -0800 Subject: [PATCH] Model now knows its bounding radius --- interface/src/renderer/Model.cpp | 10 +++++++++- interface/src/renderer/Model.h | 6 +++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/interface/src/renderer/Model.cpp b/interface/src/renderer/Model.cpp index 5055b16c4d..7ef87eaa47 100644 --- a/interface/src/renderer/Model.cpp +++ b/interface/src/renderer/Model.cpp @@ -7,6 +7,7 @@ // #include +#include #include @@ -23,7 +24,8 @@ Model::Model(QObject* parent) : QObject(parent), _shapesAreDirty(true), _lodDistance(0.0f), - _pupilDilation(0.0f) { + _pupilDilation(0.0f), + _boundingRadius(0.f) { // we may have been created in the network thread, but we live in the main thread moveToThread(Application::getInstance()->thread()); } @@ -136,6 +138,7 @@ void Model::createCollisionShapes() { void Model::updateShapePositions() { if (_shapesAreDirty && _shapes.size() == _jointStates.size()) { + _boundingRadius = 0.f; float uniformScale = extractUniformScale(_scale); const FBXGeometry& geometry = _geometry->getFBXGeometry(); for (int i = 0; i < _jointStates.size(); i++) { @@ -145,7 +148,12 @@ void Model::updateShapePositions() { glm::vec3 worldPosition = extractTranslation(_jointStates[i].transform) + jointToShapeOffset + _translation; _shapes[i]->setPosition(worldPosition); _shapes[i]->setRotation(_jointStates[i].combinedRotation * joint.shapeRotation); + float distance2 = glm::distance2(worldPosition, _translation); + if (distance2 > _boundingRadius) { + _boundingRadius = distance2; + } } + _boundingRadius = sqrtf(_boundingRadius); _shapesAreDirty = false; } } diff --git a/interface/src/renderer/Model.h b/interface/src/renderer/Model.h index 4891c86779..88bfbfd3aa 100644 --- a/interface/src/renderer/Model.h +++ b/interface/src/renderer/Model.h @@ -172,6 +172,8 @@ public: /// Use the collision to affect the model void applyCollision(CollisionInfo& collision); + float getBoundingRadius() const { return _boundingRadius; } + protected: QSharedPointer _geometry; @@ -228,7 +230,7 @@ protected: /// Computes and returns the extended length of the limb terminating at the specified joint and starting at the joint's /// first free ancestor. float getLimbLength(int jointIndex) const; - + void applyRotationDelta(int jointIndex, const glm::quat& delta, bool constrain = true); private: @@ -257,6 +259,8 @@ private: QVector _blendedNormals; QVector _attachments; + + float _boundingRadius; static ProgramObject _program; static ProgramObject _normalMapProgram;