// // Created by Sabrina Shanman 8/14/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_NestableTransformNode_h #define hifi_NestableTransformNode_h #include "TransformNode.h" #include "SpatiallyNestable.h" template class BaseNestableTransformNode : public TransformNode { public: BaseNestableTransformNode(std::weak_ptr spatiallyNestable, int jointIndex) : _spatiallyNestable(spatiallyNestable), _jointIndex(jointIndex) { auto nestablePointer = _spatiallyNestable.lock(); if (nestablePointer) { glm::vec3 nestableDimensions = getActualScale(nestablePointer); _baseScale = glm::max(glm::vec3(0.001f), nestableDimensions); } } Transform getTransform() override { std::shared_ptr nestable = _spatiallyNestable.lock(); if (!nestable) { return Transform(); } bool success; Transform jointWorldTransform = nestable->getTransform(_jointIndex, success); if (!success) { return Transform(); } jointWorldTransform.setScale(getActualScale(nestable) / _baseScale); return jointWorldTransform; } glm::vec3 getActualScale(const std::shared_ptr& nestablePointer) const; protected: std::weak_ptr _spatiallyNestable; int _jointIndex; glm::vec3 _baseScale { 1.0f }; }; class NestableTransformNode : public BaseNestableTransformNode { public: NestableTransformNode(std::weak_ptr spatiallyNestable, int jointIndex) : BaseNestableTransformNode(spatiallyNestable, jointIndex) {}; }; #endif // hifi_NestableTransformNode_h