Fix warnings and wrong shapes position for myAvatar

This commit is contained in:
luiscuenca 2019-01-16 10:52:34 -07:00
parent a7f143dbce
commit 67cc5bd7f2
7 changed files with 25 additions and 29 deletions

View file

@ -689,7 +689,7 @@ RayToAvatarIntersectionResult AvatarManager::findRayIntersectionVector(const Pic
auto &multiSpheres = avatar->getMultiSphereShapes(); auto &multiSpheres = avatar->getMultiSphereShapes();
if (multiSpheres.size() > 0) { if (multiSpheres.size() > 0) {
std::vector<MyCharacterController::RayAvatarResult> boxHits; std::vector<MyCharacterController::RayAvatarResult> 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()); assert(hit._boundJoints[i] < multiSpheres.size());
auto &mSphere = multiSpheres[hit._boundJoints[i]]; auto &mSphere = multiSpheres[hit._boundJoints[i]];
if (mSphere.isValid()) { if (mSphere.isValid()) {

View file

@ -20,7 +20,9 @@
DetailedMotionState::DetailedMotionState(AvatarPointer avatar, const btCollisionShape* shape, int jointIndex) : DetailedMotionState::DetailedMotionState(AvatarPointer avatar, const btCollisionShape* shape, int jointIndex) :
ObjectMotionState(shape), _avatar(avatar), _jointIndex(jointIndex) { ObjectMotionState(shape), _avatar(avatar), _jointIndex(jointIndex) {
assert(_avatar); assert(_avatar);
_otherAvatar = std::static_pointer_cast<OtherAvatar>(_avatar); if (!_avatar->isMyAvatar()) {
_otherAvatar = std::static_pointer_cast<OtherAvatar>(_avatar);
}
_type = MOTIONSTATE_TYPE_DETAILED; _type = MOTIONSTATE_TYPE_DETAILED;
} }
@ -60,12 +62,14 @@ PhysicsMotionType DetailedMotionState::computePhysicsMotionType() const {
const btCollisionShape* DetailedMotionState::computeNewShape() { const btCollisionShape* DetailedMotionState::computeNewShape() {
btCollisionShape* shape = nullptr; btCollisionShape* shape = nullptr;
if (!_avatar->isMyAvatar()) { if (!_avatar->isMyAvatar()) {
if (_otherAvatar) { if (_otherAvatar != nullptr) {
shape = _otherAvatar->createCollisionShape(_jointIndex, _isBound, _boundJoints); shape = _otherAvatar->createCollisionShape(_jointIndex, _isBound, _boundJoints);
} }
} else { } else {
std::shared_ptr<MyAvatar> myAvatar = std::static_pointer_cast<MyAvatar>(_avatar); std::shared_ptr<MyAvatar> myAvatar = std::static_pointer_cast<MyAvatar>(_avatar);
shape = myAvatar->getCharacterController()->createDetailedCollisionShapeForJoint(_jointIndex); if (myAvatar) {
shape = myAvatar->getCharacterController()->createDetailedCollisionShapeForJoint(_jointIndex);
}
} }
return shape; return shape;
} }
@ -111,8 +115,13 @@ float DetailedMotionState::getObjectAngularDamping() const {
// virtual // virtual
glm::vec3 DetailedMotionState::getObjectPosition() const { glm::vec3 DetailedMotionState::getObjectPosition() const {
auto bodyLOD = _otherAvatar->getBodyLOD(); if (_otherAvatar != nullptr) {
return bodyLOD == OtherAvatar::BodyLOD::Sphere ? _avatar->getFitBounds().calcCenter() : _avatar->getJointPosition(_jointIndex); auto bodyLOD = _otherAvatar->getBodyLOD();
if (bodyLOD == OtherAvatar::BodyLOD::Sphere) {
return _avatar->getFitBounds().calcCenter();
}
}
return _avatar->getJointPosition(_jointIndex);
} }
// virtual // virtual

View file

@ -426,16 +426,6 @@ void MyAvatar::clearIKJointLimitHistory() {
_skeletonModel->getRig().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) { void MyAvatar::reset(bool andRecenter, bool andReload, bool andHead) {
assert(QThread::currentThread() == thread()); assert(QThread::currentThread() == thread());
@ -3073,9 +3063,8 @@ void MyAvatar::postUpdate(float deltaTime, const render::ScenePointer& scene) {
if (_skeletonModel && _skeletonModel->isLoaded()) { if (_skeletonModel && _skeletonModel->isLoaded()) {
const Rig& rig = _skeletonModel->getRig(); const Rig& rig = _skeletonModel->getRig();
const HFMModel& hfmModel = _skeletonModel->getHFMModel();
int jointCount = rig.getJointStateCount(); int jointCount = rig.getJointStateCount();
if (jointCount == _multiSphereShapes.size()) { if (jointCount == (int)_multiSphereShapes.size()) {
int count = 0; int count = 0;
for (int i = 0; i < jointCount; i++) { for (int i = 0; i < jointCount; i++) {
AnimPose jointPose; AnimPose jointPose;

View file

@ -312,8 +312,6 @@ public:
*/ */
Q_INVOKABLE void clearIKJointLimitHistory(); // thread-safe Q_INVOKABLE void clearIKJointLimitHistory(); // thread-safe
Q_INVOKABLE QVariantMap getBoundingBox();
void update(float deltaTime); void update(float deltaTime);
virtual void postUpdate(float deltaTime, const render::ScenePointer& scene) override; virtual void postUpdate(float deltaTime, const render::ScenePointer& scene) override;
void preDisplaySide(const RenderArgs* renderArgs); void preDisplaySide(const RenderArgs* renderArgs);

View file

@ -123,7 +123,10 @@ int OtherAvatar::parseDataFromBuffer(const QByteArray& buffer) {
btCollisionShape* OtherAvatar::createCollisionShape(int jointIndex, bool& isBound, std::vector<int>& boundJoints) { btCollisionShape* OtherAvatar::createCollisionShape(int jointIndex, bool& isBound, std::vector<int>& boundJoints) {
ShapeInfo shapeInfo; ShapeInfo shapeInfo;
isBound = false; 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) { switch (_bodyLOD) {
case BodyLOD::Sphere: case BodyLOD::Sphere:
shapeInfo.setSphere(0.5f * getFitBounds().getDimensions().y); shapeInfo.setSphere(0.5f * getFitBounds().getDimensions().y);
@ -241,7 +244,7 @@ bool OtherAvatar::shouldBeInPhysicsSimulation() const {
bool OtherAvatar::needsPhysicsUpdate() const { bool OtherAvatar::needsPhysicsUpdate() const {
constexpr uint32_t FLAGS_OF_INTEREST = Simulation::DIRTY_SHAPE | Simulation::DIRTY_MASS | Simulation::DIRTY_POSITION | Simulation::DIRTY_COLLISION_GROUP; 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() { void OtherAvatar::rebuildCollisionShape() {

View file

@ -1440,7 +1440,7 @@ void Avatar::computeMultiSphereShapes() {
std::vector<btVector3> btPoints; std::vector<btVector3> btPoints;
int lineCount = (int)shapeInfo.debugLines.size(); int lineCount = (int)shapeInfo.debugLines.size();
btPoints.reserve(lineCount); 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]; const glm::vec3 &point = shapeInfo.debugLines[j];
auto rigPoint = scale * point; auto rigPoint = scale * point;
btVector3 btPoint = glmToBullet(rigPoint); btVector3 btPoint = glmToBullet(rigPoint);
@ -1458,7 +1458,7 @@ void Avatar::computeMultiSphereShapes() {
void Avatar::updateFitBoundingBox() { void Avatar::updateFitBoundingBox() {
_fitBoundingBox = AABox(); _fitBoundingBox = AABox();
if (getJointCount() == _multiSphereShapes.size()) { if (getJointCount() == (int)_multiSphereShapes.size()) {
for (int i = 0; i < getJointCount(); i++) { for (int i = 0; i < getJointCount(); i++) {
auto &shape = _multiSphereShapes[i]; auto &shape = _multiSphereShapes[i];
glm::vec3 jointPosition; glm::vec3 jointPosition;
@ -1650,7 +1650,7 @@ void Avatar::computeShapeInfo(ShapeInfo& shapeInfo) {
} }
void Avatar::computeDetailedShapeInfo(ShapeInfo& shapeInfo, int jointIndex) { 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(); auto& data = _multiSphereShapes[jointIndex].getSpheresData();
std::vector<glm::vec3> positions; std::vector<glm::vec3> positions;
std::vector<btScalar> radiuses; std::vector<btScalar> radiuses;

View file

@ -327,10 +327,7 @@ void PhysicsEngine::processTransaction(PhysicsEngine::Transaction& transaction)
} }
if (object->getMotionType() == MOTION_TYPE_STATIC && object->isActive()) { if (object->getMotionType() == MOTION_TYPE_STATIC && object->isActive()) {
_activeStaticBodies.insert(object->getRigidBody()); _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 // 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) // but we've configured Bullet to NOT update them automatically (for improved performance)