{"action":"created","comment":{"url":"https://api.github.com/repos/highfidelity/hifi/pulls/comments/43579962","id":43579962,"diff_hunk":"@@ -0,0 +1,169 @@\n+//\n+//  SpatiallyNestable.cpp\n+//  libraries/shared/src/\n+//\n+//  Created by Seth Alves on 2015-10-18\n+//  Copyright 2015 High Fidelity, Inc.\n+//\n+//  Distributed under the Apache License, Version 2.0.\n+//  See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html\n+//\n+\n+#include \"DependencyManager.h\"\n+#include \"SpatiallyNestable.h\"\n+\n+// TODO -- make use of parent joint index\n+\n+Transform SpatiallyNestable::getParentTransform() const {\n+    Transform result;\n+    SpatiallyNestablePointer parent = getParentPointer();\n+    if (parent) {\n+        Transform parentTransform = parent->getTransform();\n+        result = parentTransform.setScale(1.0f);\n+    }\n+    return result;\n+}\n+\n+SpatiallyNestablePointer SpatiallyNestable::getParentPointer() const {\n+    SpatiallyNestablePointer parent = _parent.lock();\n+\n+    if (!parent && _parentID.isNull()) {\n+        // no parent\n+        return nullptr;\n+    }\n+\n+    SpatiallyNestableConstPointer constThisPointer = shared_from_this();\n+    SpatiallyNestablePointer thisPointer = std::const_pointer_cast<SpatiallyNestable>(constThisPointer); // ermahgerd !!!\n+\n+    if (parent && parent->getID() == _parentID) {\n+        // parent pointer is up-to-date\n+        if (!_parentKnowsMe) {\n+            parent->beParentOfChild(thisPointer);\n+            _parentKnowsMe = true;\n+        }\n+        return parent;\n+    }\n+\n+    if (parent) {\n+        // we have a parent pointer but our _parentID doesn't indicate this parent.\n+        parent->forgetChild(thisPointer);\n+        _parentKnowsMe = false;\n+        _parent.reset();\n+    }\n+\n+    // we have a _parentID but no parent pointer, or our parent pointer is to the wrong thing\n+    QSharedPointer<SpatialParentFinder> parentFinder = DependencyManager::get<SpatialParentFinder>();\n+    _parent = parentFinder->find(_parentID);\n+    parent = _parent.lock();\n+    if (parent) {\n+        parent->beParentOfChild(thisPointer);\n+        _parentKnowsMe = true;\n+    }\n+    return parent;\n+}\n+\n+void SpatiallyNestable::beParentOfChild(SpatiallyNestablePointer newChild) const {\n+    _children[newChild->getID()] = newChild;\n+}\n+\n+void SpatiallyNestable::forgetChild(SpatiallyNestablePointer newChild) const {\n+    _children.remove(newChild->getID());\n+}\n+\n+\n+void SpatiallyNestable::setParentID(const QUuid& parentID) {\n+    _parentID = parentID;\n+    _parentKnowsMe = false;\n+}\n+\n+const glm::vec3& SpatiallyNestable::getPosition() const {\n+    Transform parentTransformDescaled = getParentTransform();\n+    glm::mat4 parentMat;\n+    parentTransformDescaled.getMatrix(parentMat);\n+    glm::vec4 absPos = parentMat * glm::vec4(getLocalPosition(), 1.0f);\n+    _absolutePositionCache = glm::vec3(absPos);\n+    return _absolutePositionCache;\n+}\n+\n+void SpatiallyNestable::setPosition(const glm::vec3& position) {\n+    Transform parentTransform = getParentTransform();\n+    Transform myWorldTransform;\n+    Transform::mult(myWorldTransform, parentTransform, _transform);\n+    myWorldTransform.setTranslation(position);\n+    Transform::inverseMult(_transform, parentTransform, myWorldTransform);\n+}\n+\n+const glm::quat& SpatiallyNestable::getOrientation() const {\n+    Transform parentTransformDescaled = getParentTransform();\n+    _absoluteRotationCache = parentTransformDescaled.getRotation() * getLocalOrientation();\n+    return _absoluteRotationCache;\n+}\n+\n+void SpatiallyNestable::setOrientation(const glm::quat& orientation) {\n+    Transform parentTransform = getParentTransform();\n+    Transform myWorldTransform;\n+    Transform::mult(myWorldTransform, parentTransform, _transform);\n+    myWorldTransform.setRotation(orientation);\n+    Transform::inverseMult(_transform, parentTransform, myWorldTransform);\n+}\n+\n+const Transform& SpatiallyNestable::getTransform() const {\n+    Transform parentTransform = getParentTransform();\n+    Transform::mult(_worldTransformCache, parentTransform, _transform);\n+    return _worldTransformCache;\n+}\n+\n+void SpatiallyNestable::setTransform(const Transform& transform) {\n+    Transform parentTransform = getParentTransform();\n+    Transform::inverseMult(_transform, parentTransform, transform);\n+}\n+\n+const glm::vec3& SpatiallyNestable::getScale() const {\n+    return _transform.getScale();\n+}","path":"libraries/shared/src/SpatiallyNestable.cpp","position":153,"original_position":123,"commit_id":"74ade02bc631629465637a123f5151a28b3a48da","original_commit_id":"7b08d047b19598784cfa03c67d67329a6351724a","user":{"login":"jherico","id":1533642,"avatar_url":"https://avatars.githubusercontent.com/u/1533642?v=3","gravatar_id":"","url":"https://api.github.com/users/jherico","html_url":"https://github.com/jherico","followers_url":"https://api.github.com/users/jherico/followers","following_url":"https://api.github.com/users/jherico/following{/other_user}","gists_url":"https://api.github.com/users/jherico/gists{/gist_id}","starred_url":"https://api.github.com/users/jherico/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jherico/subscriptions","organizations_url":"https://api.github.com/users/jherico/orgs","repos_url":"https://api.github.com/users/jherico/repos","events_url":"https://api.github.com/users/jherico/events{/privacy}","received_events_url":"https://api.github.com/users/jherico/received_events","type":"User","site_admin":false},"body":"Why wouldn't we want scale to be propagated?  If I want to turn a house into a dollhouse by scaling the top level item, wouldn't I need that?","created_at":"2015-11-01T07:57:53Z","updated_at":"2015-11-01T07:57:53Z","html_url":"https://github.com/highfidelity/hifi/pull/6152#discussion_r43579962","pull_request_url":"https://api.github.com/repos/highfidelity/hifi/pulls/6152","_links":{"self":{"href":"https://api.github.com/repos/highfidelity/hifi/pulls/comments/43579962"},"html":{"href":"https://github.com/highfidelity/hifi/pull/6152#discussion_r43579962"},"pull_request":{"href":"https://api.github.com/repos/highfidelity/hifi/pulls/6152"}}},"pull_request":{"url":"https://api.github.com/repos/highfidelity/hifi/pulls/6152","id":48497492,"html_url":"https://github.com/highfidelity/hifi/pull/6152","diff_url":"https://github.com/highfidelity/hifi/pull/6152.diff","patch_url":"https://github.com/highfidelity/hifi/pull/6152.patch","issue_url":"https://api.github.com/repos/highfidelity/hifi/issues/6152","number":6152,"state":"open","locked":false,"title":"Do Not Merge -- Parents","user":{"login":"sethalves","id":1137072,"avatar_url":"https://avatars.githubusercontent.com/u/1137072?v=3","gravatar_id":"","url":"https://api.github.com/users/sethalves","html_url":"https://github.com/sethalves","followers_url":"https://api.github.com/users/sethalves/followers","following_url":"https://api.github.com/users/sethalves/following{/other_user}","gists_url":"https://api.github.com/users/sethalves/gists{/gist_id}","starred_url":"https://api.github.com/users/sethalves/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sethalves/subscriptions","organizations_url":"https://api.github.com/users/sethalves/orgs","repos_url":"https://api.github.com/users/sethalves/repos","events_url":"https://api.github.com/users/sethalves/events{/privacy}","received_events_url":"https://api.github.com/users/sethalves/received_events","type":"User","site_admin":false},"body":"- allow avatars and entities to have locations which are relative to something else","created_at":"2015-10-22T18:54:25Z","updated_at":"2015-11-01T07:57:53Z","closed_at":null,"merged_at":null,"merge_commit_sha":"7fc7d16ee4c6118be657ca72c21015479acb4322","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/highfidelity/hifi/pulls/6152/commits","review_comments_url":"https://api.github.com/repos/highfidelity/hifi/pulls/6152/comments","review_comment_url":"https://api.github.com/repos/highfidelity/hifi/pulls/comments{/number}","comments_url":"https://api.github.com/repos/highfidelity/hifi/issues/6152/comments","statuses_url":"https://api.github.com/repos/highfidelity/hifi/statuses/74ade02bc631629465637a123f5151a28b3a48da","head":{"label":"sethalves:parents","ref":"parents","sha":"74ade02bc631629465637a123f5151a28b3a48da","user":{"login":"sethalves","id":1137072,"avatar_url":"https://avatars.githubusercontent.com/u/1137072?v=3","gravatar_id":"","url":"https://api.github.com/users/sethalves","html_url":"https://github.com/sethalves","followers_url":"https://api.github.com/users/sethalves/followers","following_url":"https://api.github.com/users/sethalves/following{/other_user}","gists_url":"https://api.github.com/users/sethalves/gists{/gist_id}","starred_url":"https://api.github.com/users/sethalves/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sethalves/subscriptions","organizations_url":"https://api.github.com/users/sethalves/orgs","repos_url":"https://api.github.com/users/sethalves/repos","events_url":"https://api.github.com/users/sethalves/events{/privacy}","received_events_url":"https://api.github.com/users/sethalves/received_events","type":"User","site_admin":false},"repo":{"id":30046830,"name":"hifi","full_name":"sethalves/hifi","owner":{"login":"sethalves","id":1137072,"avatar_url":"https://avatars.githubusercontent.com/u/1137072?v=3","gravatar_id":"","url":"https://api.github.com/users/sethalves","html_url":"https://github.com/sethalves","followers_url":"https://api.github.com/users/sethalves/followers","following_url":"https://api.github.com/users/sethalves/following{/other_user}","gists_url":"https://api.github.com/users/sethalves/gists{/gist_id}","starred_url":"https://api.github.com/users/sethalves/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sethalves/subscriptions","organizations_url":"https://api.github.com/users/sethalves/orgs","repos_url":"https://api.github.com/users/sethalves/repos","events_url":"https://api.github.com/users/sethalves/events{/privacy}","received_events_url":"https://api.github.com/users/sethalves/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/sethalves/hifi","description":"Open, decentralized virtual worlds using sensors to control avatars and dynamically assigned devices as servers.  San Francisco based startup, we are hiring: http://highfidelity.io/jobs  Documentation at http://docs.highfidelity.io  Contribute by reporting bugs & doing jobs on http://worklist.net","fork":true,"url":"https://api.github.com/repos/sethalves/hifi","forks_url":"https://api.github.com/repos/sethalves/hifi/forks","keys_url":"https://api.github.com/repos/sethalves/hifi/keys{/key_id}","collaborators_url":"https://api.github.com/repos/sethalves/hifi/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/sethalves/hifi/teams","hooks_url":"https://api.github.com/repos/sethalves/hifi/hooks","issue_events_url":"https://api.github.com/repos/sethalves/hifi/issues/events{/number}","events_url":"https://api.github.com/repos/sethalves/hifi/events","assignees_url":"https://api.github.com/repos/sethalves/hifi/assignees{/user}","branches_url":"https://api.github.com/repos/sethalves/hifi/branches{/branch}","tags_url":"https://api.github.com/repos/sethalves/hifi/tags","blobs_url":"https://api.github.com/repos/sethalves/hifi/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/sethalves/hifi/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/sethalves/hifi/git/refs{/sha}","trees_url":"https://api.github.com/repos/sethalves/hifi/git/trees{/sha}","statuses_url":"https://api.github.com/repos/sethalves/hifi/statuses/{sha}","languages_url":"https://api.github.com/repos/sethalves/hifi/languages","stargazers_url":"https://api.github.com/repos/sethalves/hifi/stargazers","contributors_url":"https://api.github.com/repos/sethalves/hifi/contributors","subscribers_url":"https://api.github.com/repos/sethalves/hifi/subscribers","subscription_url":"https://api.github.com/repos/sethalves/hifi/subscription","commits_url":"https://api.github.com/repos/sethalves/hifi/commits{/sha}","git_commits_url":"https://api.github.com/repos/sethalves/hifi/git/commits{/sha}","comments_url":"https://api.github.com/repos/sethalves/hifi/comments{/number}","issue_comment_url":"https://api.github.com/repos/sethalves/hifi/issues/comments{/number}","contents_url":"https://api.github.com/repos/sethalves/hifi/contents/{+path}","compare_url":"https://api.github.com/repos/sethalves/hifi/compare/{base}...{head}","merges_url":"https://api.github.com/repos/sethalves/hifi/merges","archive_url":"https://api.github.com/repos/sethalves/hifi/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/sethalves/hifi/downloads","issues_url":"https://api.github.com/repos/sethalves/hifi/issues{/number}","pulls_url":"https://api.github.com/repos/sethalves/hifi/pulls{/number}","milestones_url":"https://api.github.com/repos/sethalves/hifi/milestones{/number}","notifications_url":"https://api.github.com/repos/sethalves/hifi/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/sethalves/hifi/labels{/name}","releases_url":"https://api.github.com/repos/sethalves/hifi/releases{/id}","created_at":"2015-01-29T23:37:31Z","updated_at":"2015-05-07T23:30:44Z","pushed_at":"2015-10-31T21:28:57Z","git_url":"git://github.com/sethalves/hifi.git","ssh_url":"git@github.com:sethalves/hifi.git","clone_url":"https://github.com/sethalves/hifi.git","svn_url":"https://github.com/sethalves/hifi","homepage":"","size":185006,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"highfidelity:master","ref":"master","sha":"bc07de389292e6f2be538b4eb9d35091d294d9c8","user":{"login":"highfidelity","id":1565370,"avatar_url":"https://avatars.githubusercontent.com/u/1565370?v=3","gravatar_id":"","url":"https://api.github.com/users/highfidelity","html_url":"https://github.com/highfidelity","followers_url":"https://api.github.com/users/highfidelity/followers","following_url":"https://api.github.com/users/highfidelity/following{/other_user}","gists_url":"https://api.github.com/users/highfidelity/gists{/gist_id}","starred_url":"https://api.github.com/users/highfidelity/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/highfidelity/subscriptions","organizations_url":"https://api.github.com/users/highfidelity/orgs","repos_url":"https://api.github.com/users/highfidelity/repos","events_url":"https://api.github.com/users/highfidelity/events{/privacy}","received_events_url":"https://api.github.com/users/highfidelity/received_events","type":"Organization","site_admin":false},"repo":{"id":5372872,"name":"hifi","full_name":"highfidelity/hifi","owner":{"login":"highfidelity","id":1565370,"avatar_url":"https://avatars.githubusercontent.com/u/1565370?v=3","gravatar_id":"","url":"https://api.github.com/users/highfidelity","html_url":"https://github.com/highfidelity","followers_url":"https://api.github.com/users/highfidelity/followers","following_url":"https://api.github.com/users/highfidelity/following{/other_user}","gists_url":"https://api.github.com/users/highfidelity/gists{/gist_id}","starred_url":"https://api.github.com/users/highfidelity/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/highfidelity/subscriptions","organizations_url":"https://api.github.com/users/highfidelity/orgs","repos_url":"https://api.github.com/users/highfidelity/repos","events_url":"https://api.github.com/users/highfidelity/events{/privacy}","received_events_url":"https://api.github.com/users/highfidelity/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/highfidelity/hifi","description":"Open source software for shared virtual worlds using HMDs and dynamically assigned devices as servers.  San Francisco based startup, we are hiring: http://highfidelity.com/jobs  Documentation at http://docs.highfidelity.com  Contribute by reporting bugs & doing jobs on http://worklist.net","fork":false,"url":"https://api.github.com/repos/highfidelity/hifi","forks_url":"https://api.github.com/repos/highfidelity/hifi/forks","keys_url":"https://api.github.com/repos/highfidelity/hifi/keys{/key_id}","collaborators_url":"https://api.github.com/repos/highfidelity/hifi/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/highfidelity/hifi/teams","hooks_url":"https://api.github.com/repos/highfidelity/hifi/hooks","issue_events_url":"https://api.github.com/repos/highfidelity/hifi/issues/events{/number}","events_url":"https://api.github.com/repos/highfidelity/hifi/events","assignees_url":"https://api.github.com/repos/highfidelity/hifi/assignees{/user}","branches_url":"https://api.github.com/repos/highfidelity/hifi/branches{/branch}","tags_url":"https://api.github.com/repos/highfidelity/hifi/tags","blobs_url":"https://api.github.com/repos/highfidelity/hifi/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/highfidelity/hifi/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/highfidelity/hifi/git/refs{/sha}","trees_url":"https://api.github.com/repos/highfidelity/hifi/git/trees{/sha}","statuses_url":"https://api.github.com/repos/highfidelity/hifi/statuses/{sha}","languages_url":"https://api.github.com/repos/highfidelity/hifi/languages","stargazers_url":"https://api.github.com/repos/highfidelity/hifi/stargazers","contributors_url":"https://api.github.com/repos/highfidelity/hifi/contributors","subscribers_url":"https://api.github.com/repos/highfidelity/hifi/subscribers","subscription_url":"https://api.github.com/repos/highfidelity/hifi/subscription","commits_url":"https://api.github.com/repos/highfidelity/hifi/commits{/sha}","git_commits_url":"https://api.github.com/repos/highfidelity/hifi/git/commits{/sha}","comments_url":"https://api.github.com/repos/highfidelity/hifi/comments{/number}","issue_comment_url":"https://api.github.com/repos/highfidelity/hifi/issues/comments{/number}","contents_url":"https://api.github.com/repos/highfidelity/hifi/contents/{+path}","compare_url":"https://api.github.com/repos/highfidelity/hifi/compare/{base}...{head}","merges_url":"https://api.github.com/repos/highfidelity/hifi/merges","archive_url":"https://api.github.com/repos/highfidelity/hifi/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/highfidelity/hifi/downloads","issues_url":"https://api.github.com/repos/highfidelity/hifi/issues{/number}","pulls_url":"https://api.github.com/repos/highfidelity/hifi/pulls{/number}","milestones_url":"https://api.github.com/repos/highfidelity/hifi/milestones{/number}","notifications_url":"https://api.github.com/repos/highfidelity/hifi/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/highfidelity/hifi/labels{/name}","releases_url":"https://api.github.com/repos/highfidelity/hifi/releases{/id}","created_at":"2012-08-10T18:26:22Z","updated_at":"2015-11-01T06:10:03Z","pushed_at":"2015-11-01T07:33:14Z","git_url":"git://github.com/highfidelity/hifi.git","ssh_url":"git@github.com:highfidelity/hifi.git","clone_url":"https://github.com/highfidelity/hifi.git","svn_url":"https://github.com/highfidelity/hifi","homepage":"","size":252164,"stargazers_count":319,"watchers_count":319,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":185,"mirror_url":null,"open_issues_count":54,"forks":185,"open_issues":54,"watchers":319,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/highfidelity/hifi/pulls/6152"},"html":{"href":"https://github.com/highfidelity/hifi/pull/6152"},"issue":{"href":"https://api.github.com/repos/highfidelity/hifi/issues/6152"},"comments":{"href":"https://api.github.com/repos/highfidelity/hifi/issues/6152/comments"},"review_comments":{"href":"https://api.github.com/repos/highfidelity/hifi/pulls/6152/comments"},"review_comment":{"href":"https://api.github.com/repos/highfidelity/hifi/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/highfidelity/hifi/pulls/6152/commits"},"statuses":{"href":"https://api.github.com/repos/highfidelity/hifi/statuses/74ade02bc631629465637a123f5151a28b3a48da"}}}}