Model now knows its bounding radius

This commit is contained in:
Andrew Meadows 2014-03-06 12:34:21 -08:00
parent 831a8cf580
commit 778bdec6d8
2 changed files with 14 additions and 2 deletions

View file

@ -7,6 +7,7 @@
//
#include <glm/gtx/transform.hpp>
#include <glm/gtx/norm.hpp>
#include <GeometryUtil.h>
@ -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;
}
}

View file

@ -172,6 +172,8 @@ public:
/// Use the collision to affect the model
void applyCollision(CollisionInfo& collision);
float getBoundingRadius() const { return _boundingRadius; }
protected:
QSharedPointer<NetworkGeometry> _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<glm::vec3> _blendedNormals;
QVector<Model*> _attachments;
float _boundingRadius;
static ProgramObject _program;
static ProgramObject _normalMapProgram;