Scale collision picks relative to parent by adding and using more

specialized transform nodes.
This commit is contained in:
sabrina-shanman 2018-09-05 14:46:07 -07:00
parent 62344c106d
commit e8ce152687
7 changed files with 180 additions and 2 deletions

View file

@ -24,11 +24,13 @@
#include "CollisionPick.h"
#include "SpatialParentFinder.h"
#include "NestableTransformNode.h"
#include "PickTransformNode.h"
#include "MouseTransformNode.h"
#include "avatar/MyAvatarHeadTransformNode.h"
#include "avatar/AvatarManager.h"
#include "avatars-renderer/AvatarTransformNode.h"
#include "ui/overlays/OverlayTransformNode.h"
#include "EntityTransformNode.h"
#include <ScriptEngine.h>
@ -375,6 +377,16 @@ std::shared_ptr<TransformNode> PickScriptingInterface::createTransformNode(const
}
auto sharedNestablePointer = nestablePointer.lock();
if (success && sharedNestablePointer) {
NestableType nestableType = sharedNestablePointer->getNestableType();
if (nestableType == NestableType::Avatar) {
return std::make_shared<AvatarTransformNode>(std::static_pointer_cast<Avatar>(sharedNestablePointer), parentJointIndex);
}
if (nestableType == NestableType::Overlay) {
return std::make_shared<OverlayTransformNode>(std::static_pointer_cast<Base3DOverlay>(sharedNestablePointer), parentJointIndex);
}
if (nestableType == NestableType::Entity) {
return std::make_shared<EntityTransformNode>(std::static_pointer_cast<EntityItem>(sharedNestablePointer), parentJointIndex);
}
return std::make_shared<NestableTransformNode>(nestablePointer, parentJointIndex);
}
}
@ -394,7 +406,7 @@ std::shared_ptr<TransformNode> PickScriptingInterface::createTransformNode(const
} else if (!joint.isNull()) {
auto myAvatar = DependencyManager::get<AvatarManager>()->getMyAvatar();
int jointIndex = myAvatar->getJointIndex(joint);
return std::make_shared<NestableTransformNode>(myAvatar, jointIndex);
return std::make_shared<AvatarTransformNode>(myAvatar, jointIndex);
}
}

View file

@ -0,0 +1,30 @@
//
// Created by Sabrina Shanman 9/5/2018
// Copyright 2018 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 "OverlayTransformNode.h"
OverlayTransformNode::OverlayTransformNode(std::weak_ptr<Base3DOverlay> overlay, int jointIndex) :
_overlay(overlay),
_jointIndex(jointIndex)
{}
Transform OverlayTransformNode::getTransform() {
auto overlay = _overlay.lock();
if (!overlay) {
return Transform();
}
bool success;
Transform jointWorldTransform = overlay->getTransform(_jointIndex, success);
if (!success) {
jointWorldTransform = Transform();
}
jointWorldTransform.setScale(overlay->getBounds().getScale());
return jointWorldTransform;
}

View file

@ -0,0 +1,26 @@
//
// Created by Sabrina Shanman 9/5/2018
// Copyright 2018 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_OverlayTransformNode_h
#define hifi_OverlayTransformNode_h
#include "NestableTransformNode.h"
#include "Base3DOverlay.h"
// For 3D overlays only
class OverlayTransformNode : public TransformNode {
public:
OverlayTransformNode(std::weak_ptr<Base3DOverlay> overlay, int jointIndex);
Transform getTransform() override;
protected:
std::weak_ptr<Base3DOverlay> _overlay;
int _jointIndex;
};
#endif // hifi_OverlayTransformNode_h

View file

@ -0,0 +1,30 @@
//
// Created by Sabrina Shanman 9/5/2018
// Copyright 2018 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 "AvatarTransformNode.h"
AvatarTransformNode::AvatarTransformNode(AvatarWeakPointer avatar, int jointIndex) :
_avatar(avatar),
_jointIndex(jointIndex)
{}
Transform AvatarTransformNode::getTransform() {
auto avatar = _avatar.lock();
if (!avatar) {
return Transform();
}
bool success;
Transform jointWorldTransform = avatar->getTransform(_jointIndex, success);
if (!success) {
jointWorldTransform = Transform();
}
jointWorldTransform.setScale(avatar->scaleForChildren());
return jointWorldTransform;
}

View file

@ -0,0 +1,25 @@
//
// Created by Sabrina Shanman 9/5/2018
// Copyright 2018 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_AvatarTransformNode_h
#define hifi_AvatarTransformNode_h
#include "NestableTransformNode.h"
#include "Avatar.h"
class AvatarTransformNode : public TransformNode {
public:
AvatarTransformNode(AvatarWeakPointer avatar, int jointIndex);
Transform getTransform() override;
protected:
AvatarWeakPointer _avatar;
int _jointIndex;
};
#endif // hifi_AvatarTransformNode_h

View file

@ -0,0 +1,30 @@
//
// Created by Sabrina Shanman 9/5/2018
// Copyright 2018 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 "EntityTransformNode.h"
EntityTransformNode::EntityTransformNode(EntityItemWeakPointer entity, int jointIndex) :
_entity(entity),
_jointIndex(jointIndex)
{}
Transform EntityTransformNode::getTransform() {
auto entity = _entity.lock();
if (!entity) {
return Transform();
}
bool success;
Transform jointWorldTransform = entity->getTransform(_jointIndex, success);
if (!success) {
jointWorldTransform = Transform();
}
jointWorldTransform.setScale(entity->getScaledDimensions());
return jointWorldTransform;
}

View file

@ -0,0 +1,25 @@
//
// Created by Sabrina Shanman 9/5/2018
// Copyright 2018 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_EntityTransformNode_h
#define hifi_EntityTransformNode_h
#include "NestableTransformNode.h"
#include "EntityItem.h"
class EntityTransformNode : public TransformNode {
public:
EntityTransformNode(EntityItemWeakPointer entity, int jointIndex);
Transform getTransform() override;
protected:
EntityItemWeakPointer _entity;
int _jointIndex;
};
#endif // hifi_EntityTransformNode_h