From 67cc5bd7f2e9d71446261ed7fd30060d4ca80f58 Mon Sep 17 00:00:00 2001 From: luiscuenca Date: Wed, 16 Jan 2019 10:52:34 -0700 Subject: [PATCH] Fix warnings and wrong shapes position for myAvatar --- interface/src/avatar/AvatarManager.cpp | 2 +- interface/src/avatar/DetailedMotionState.cpp | 19 ++++++++++++++----- interface/src/avatar/MyAvatar.cpp | 13 +------------ interface/src/avatar/MyAvatar.h | 2 -- interface/src/avatar/OtherAvatar.cpp | 7 +++++-- .../src/avatars-renderer/Avatar.cpp | 6 +++--- libraries/physics/src/PhysicsEngine.cpp | 5 +---- 7 files changed, 25 insertions(+), 29 deletions(-) diff --git a/interface/src/avatar/AvatarManager.cpp b/interface/src/avatar/AvatarManager.cpp index 80ffd32aff..53f8a0bc7f 100644 --- a/interface/src/avatar/AvatarManager.cpp +++ b/interface/src/avatar/AvatarManager.cpp @@ -689,7 +689,7 @@ RayToAvatarIntersectionResult AvatarManager::findRayIntersectionVector(const Pic auto &multiSpheres = avatar->getMultiSphereShapes(); if (multiSpheres.size() > 0) { std::vector boxHits; - for (auto i = 0; i < hit._boundJoints.size(); i++) { + for (size_t i = 0; i < hit._boundJoints.size(); i++) { assert(hit._boundJoints[i] < multiSpheres.size()); auto &mSphere = multiSpheres[hit._boundJoints[i]]; if (mSphere.isValid()) { diff --git a/interface/src/avatar/DetailedMotionState.cpp b/interface/src/avatar/DetailedMotionState.cpp index c08272184f..4d8e3d5ec7 100644 --- a/interface/src/avatar/DetailedMotionState.cpp +++ b/interface/src/avatar/DetailedMotionState.cpp @@ -20,7 +20,9 @@ DetailedMotionState::DetailedMotionState(AvatarPointer avatar, const btCollisionShape* shape, int jointIndex) : ObjectMotionState(shape), _avatar(avatar), _jointIndex(jointIndex) { assert(_avatar); - _otherAvatar = std::static_pointer_cast(_avatar); + if (!_avatar->isMyAvatar()) { + _otherAvatar = std::static_pointer_cast(_avatar); + } _type = MOTIONSTATE_TYPE_DETAILED; } @@ -60,12 +62,14 @@ PhysicsMotionType DetailedMotionState::computePhysicsMotionType() const { const btCollisionShape* DetailedMotionState::computeNewShape() { btCollisionShape* shape = nullptr; if (!_avatar->isMyAvatar()) { - if (_otherAvatar) { + if (_otherAvatar != nullptr) { shape = _otherAvatar->createCollisionShape(_jointIndex, _isBound, _boundJoints); } } else { std::shared_ptr myAvatar = std::static_pointer_cast(_avatar); - shape = myAvatar->getCharacterController()->createDetailedCollisionShapeForJoint(_jointIndex); + if (myAvatar) { + shape = myAvatar->getCharacterController()->createDetailedCollisionShapeForJoint(_jointIndex); + } } return shape; } @@ -111,8 +115,13 @@ float DetailedMotionState::getObjectAngularDamping() const { // virtual glm::vec3 DetailedMotionState::getObjectPosition() const { - auto bodyLOD = _otherAvatar->getBodyLOD(); - return bodyLOD == OtherAvatar::BodyLOD::Sphere ? _avatar->getFitBounds().calcCenter() : _avatar->getJointPosition(_jointIndex); + if (_otherAvatar != nullptr) { + auto bodyLOD = _otherAvatar->getBodyLOD(); + if (bodyLOD == OtherAvatar::BodyLOD::Sphere) { + return _avatar->getFitBounds().calcCenter(); + } + } + return _avatar->getJointPosition(_jointIndex); } // virtual diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 621fe1d479..670444baf0 100755 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -426,16 +426,6 @@ void MyAvatar::clearIKJointLimitHistory() { _skeletonModel->getRig().clearIKJointLimitHistory(); } -QVariantMap MyAvatar::getBoundingBox() { - QVariantMap bbox; - auto avatarBBox = getFitBounds(); - auto center = avatarBBox.calcCenter(); - auto dimensions = avatarBBox.getDimensions(); - bbox["center"] = vec3toVariant(center); - bbox["dimensions"] = vec3toVariant(dimensions); - return bbox; -} - void MyAvatar::reset(bool andRecenter, bool andReload, bool andHead) { assert(QThread::currentThread() == thread()); @@ -3073,9 +3063,8 @@ void MyAvatar::postUpdate(float deltaTime, const render::ScenePointer& scene) { if (_skeletonModel && _skeletonModel->isLoaded()) { const Rig& rig = _skeletonModel->getRig(); - const HFMModel& hfmModel = _skeletonModel->getHFMModel(); int jointCount = rig.getJointStateCount(); - if (jointCount == _multiSphereShapes.size()) { + if (jointCount == (int)_multiSphereShapes.size()) { int count = 0; for (int i = 0; i < jointCount; i++) { AnimPose jointPose; diff --git a/interface/src/avatar/MyAvatar.h b/interface/src/avatar/MyAvatar.h index 0cb5d04c02..f107a488a6 100644 --- a/interface/src/avatar/MyAvatar.h +++ b/interface/src/avatar/MyAvatar.h @@ -312,8 +312,6 @@ public: */ Q_INVOKABLE void clearIKJointLimitHistory(); // thread-safe - Q_INVOKABLE QVariantMap getBoundingBox(); - void update(float deltaTime); virtual void postUpdate(float deltaTime, const render::ScenePointer& scene) override; void preDisplaySide(const RenderArgs* renderArgs); diff --git a/interface/src/avatar/OtherAvatar.cpp b/interface/src/avatar/OtherAvatar.cpp index 67e577ad6b..53fc826fb0 100644 --- a/interface/src/avatar/OtherAvatar.cpp +++ b/interface/src/avatar/OtherAvatar.cpp @@ -123,7 +123,10 @@ int OtherAvatar::parseDataFromBuffer(const QByteArray& buffer) { btCollisionShape* OtherAvatar::createCollisionShape(int jointIndex, bool& isBound, std::vector& boundJoints) { ShapeInfo shapeInfo; isBound = false; - auto jointName = jointIndex > -1 && jointIndex < _multiSphereShapes.size() ? _multiSphereShapes[jointIndex].getJointName() : ""; + QString jointName = ""; + if (jointIndex > -1 && jointIndex < (int)_multiSphereShapes.size()) { + jointName = _multiSphereShapes[jointIndex].getJointName(); + } switch (_bodyLOD) { case BodyLOD::Sphere: shapeInfo.setSphere(0.5f * getFitBounds().getDimensions().y); @@ -241,7 +244,7 @@ bool OtherAvatar::shouldBeInPhysicsSimulation() const { bool OtherAvatar::needsPhysicsUpdate() const { constexpr uint32_t FLAGS_OF_INTEREST = Simulation::DIRTY_SHAPE | Simulation::DIRTY_MASS | Simulation::DIRTY_POSITION | Simulation::DIRTY_COLLISION_GROUP; - return (_needsReinsertion || _motionState && (bool)(_motionState->getIncomingDirtyFlags() & FLAGS_OF_INTEREST)); + return (_needsReinsertion || (_motionState && (bool)(_motionState->getIncomingDirtyFlags() & FLAGS_OF_INTEREST))); } void OtherAvatar::rebuildCollisionShape() { diff --git a/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp b/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp index 09cd7d5176..f2252b2aa3 100644 --- a/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp +++ b/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp @@ -1440,7 +1440,7 @@ void Avatar::computeMultiSphereShapes() { std::vector btPoints; int lineCount = (int)shapeInfo.debugLines.size(); btPoints.reserve(lineCount); - for (size_t j = 0; j < lineCount; j++) { + for (int j = 0; j < lineCount; j++) { const glm::vec3 &point = shapeInfo.debugLines[j]; auto rigPoint = scale * point; btVector3 btPoint = glmToBullet(rigPoint); @@ -1458,7 +1458,7 @@ void Avatar::computeMultiSphereShapes() { void Avatar::updateFitBoundingBox() { _fitBoundingBox = AABox(); - if (getJointCount() == _multiSphereShapes.size()) { + if (getJointCount() == (int)_multiSphereShapes.size()) { for (int i = 0; i < getJointCount(); i++) { auto &shape = _multiSphereShapes[i]; glm::vec3 jointPosition; @@ -1650,7 +1650,7 @@ void Avatar::computeShapeInfo(ShapeInfo& shapeInfo) { } void Avatar::computeDetailedShapeInfo(ShapeInfo& shapeInfo, int jointIndex) { - if (jointIndex > -1 && jointIndex < _multiSphereShapes.size()) { + if (jointIndex > -1 && jointIndex < (int)_multiSphereShapes.size()) { auto& data = _multiSphereShapes[jointIndex].getSpheresData(); std::vector positions; std::vector radiuses; diff --git a/libraries/physics/src/PhysicsEngine.cpp b/libraries/physics/src/PhysicsEngine.cpp index cb2823cdf1..a571a81109 100644 --- a/libraries/physics/src/PhysicsEngine.cpp +++ b/libraries/physics/src/PhysicsEngine.cpp @@ -327,10 +327,7 @@ void PhysicsEngine::processTransaction(PhysicsEngine::Transaction& transaction) } if (object->getMotionType() == MOTION_TYPE_STATIC && object->isActive()) { _activeStaticBodies.insert(object->getRigidBody()); - } - if (object->getType() == MOTIONSTATE_TYPE_AVATAR) { - _dynamicsWorld->updateSingleAabb(object->_body); - } + } } // activeStaticBodies have changed (in an Easy way) and need their Aabbs updated // but we've configured Bullet to NOT update them automatically (for improved performance)