From 8e16bda7bbcacca801cd2ae1de3d717e0c7d4fd8 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Wed, 10 Feb 2016 16:40:50 -0800 Subject: [PATCH 1/9] start to clean up grab generated signals --- examples/controllers/handControllerGrab.js | 85 ++++++++-------------- examples/toybox/bow/bow.js | 62 +++++----------- 2 files changed, 48 insertions(+), 99 deletions(-) diff --git a/examples/controllers/handControllerGrab.js b/examples/controllers/handControllerGrab.js index 51814ad5d7..cc486802ff 100644 --- a/examples/controllers/handControllerGrab.js +++ b/examples/controllers/handControllerGrab.js @@ -333,13 +333,10 @@ function MyController(hand) { } }; - this.callEntityMethodOnGrabbed = function(entityMethodName, args) { + this.callEntityMethodOnGrabbed = function(entityMethodName) { // print("Entity Method: " + entityMethodName + ", hand: " + this.hand); - if (args.length > 0) { - Entities.callEntityMethod(this.grabbedEntity, entityMethodName, args); - } else { - Entities.callEntityMethod(this.grabbedEntity, entityMethodName); - } + Entities.callEntityMethod(this.grabbedEntity, entityMethodName, [JSON.stringify(this.hand), + JSON.stringify(MyAvatar.SessionUUID)]); } this.setState = function(newState) { @@ -1080,7 +1077,7 @@ function MyController(hand) { if (this.actionID !== null) { this.setState(STATE_CONTINUE_DISTANCE_HOLDING); this.activateEntity(this.grabbedEntity, grabbedProperties, false); - this.callSetupEntityMethods("startDistanceGrab"); + this.callEntityMethodOnGrabbed("startDistanceGrab"); } this.currentAvatarPosition = MyAvatar.position; @@ -1093,7 +1090,7 @@ function MyController(hand) { if (this.triggerSmoothedReleased()) { this.setState(STATE_RELEASE); if (this.isInitialGrab) { - this.callEntityMethodOnGrabbed("releaseGrab", []); + this.callEntityMethodOnGrabbed("releaseGrab"); } return; } @@ -1176,7 +1173,7 @@ function MyController(hand) { this.handPreviousRotation = handRotation; this.currentObjectRotation = Quat.multiply(handChange, this.currentObjectRotation); - this.callEntityMethodOnGrabbed("continueDistantGrab", []); + this.callEntityMethodOnGrabbed("continueDistantGrab"); var defaultMoveWithHeadData = { disableMoveWithHead: false @@ -1292,18 +1289,6 @@ function MyController(hand) { return projection }; - this.callSetupEntityMethods = function(entityMethodName) { - if (this.isInitialGrab) { - if (this.hand === RIGHT_HAND) { - this.callEntityMethodOnGrabbed("setRightHand", []); - } else { - this.callEntityMethodOnGrabbed("setLeftHand", []); - } - this.callEntityMethodOnGrabbed("setHand", [this.hand]); - this.callEntityMethodOnGrabbed(entityMethodName, [JSON.stringify(this.hand)]); - } - } - this.hasPresetOffsets = function() { var wearableData = getEntityCustomData('wearable', this.grabbedEntity, {joints: {}}); if ("joints" in wearableData) { @@ -1341,7 +1326,7 @@ function MyController(hand) { if (this.state == STATE_NEAR_GRABBING && this.triggerSmoothedReleased()) { this.setState(STATE_RELEASE); if (this.isInitialGrab) { - this.callEntityMethodOnGrabbed("releaseGrab", []); + this.callEntityMethodOnGrabbed("releaseGrab"); } return; } @@ -1410,7 +1395,7 @@ function MyController(hand) { })); } - this.callSetupEntityMethods(this.state == STATE_NEAR_GRABBING ? "startNearGrab" : "startEquip"); + this.callEntityMethodOnGrabbed(this.state == STATE_NEAR_GRABBING ? "startNearGrab" : "startEquip"); if (this.state == STATE_NEAR_GRABBING) { // near grabbing @@ -1429,7 +1414,7 @@ function MyController(hand) { if (this.state == STATE_CONTINUE_NEAR_GRABBING && this.triggerSmoothedReleased()) { this.setState(STATE_RELEASE); if (this.isInitialGrab) { - this.callEntityMethodOnGrabbed("releaseGrab", []); + this.callEntityMethodOnGrabbed("releaseGrab"); } return; } @@ -1439,15 +1424,15 @@ function MyController(hand) { } if (this.state == STATE_CONTINUE_EQUIP && this.bumperSqueezed()) { this.setState(STATE_WAITING_FOR_BUMPER_RELEASE); - this.callEntityMethodOnGrabbed("releaseEquip", [JSON.stringify(this.hand)]); + this.callEntityMethodOnGrabbed("releaseEquip"); return; } if (this.state == STATE_CONTINUE_NEAR_GRABBING && this.bumperSqueezed()) { this.setState(STATE_CONTINUE_EQUIP_BD); if (this.isInitialGrab) { - this.callEntityMethodOnGrabbed("releaseGrab", [JSON.stringify(this.hand)]); - this.callEntityMethodOnGrabbed("startEquip", [JSON.stringify(this.hand)]); + this.callEntityMethodOnGrabbed("releaseGrab"); } + this.callEntityMethodOnGrabbed("startEquip"); return; } @@ -1458,8 +1443,7 @@ function MyController(hand) { print("handControllerGrab -- autoreleasing held or equipped item because it is far from hand." + props.parentID + " " + vec3toStr(props.position)); this.setState(STATE_RELEASE); - this.callEntityMethodOnGrabbed(this.state == STATE_NEAR_GRABBING ? "releaseGrab" : "releaseEquip", - [JSON.stringify(this.hand)]); + this.callEntityMethodOnGrabbed(this.state == STATE_NEAR_GRABBING ? "releaseGrab" : "releaseEquip"); return; } @@ -1480,14 +1464,12 @@ function MyController(hand) { this.currentObjectTime = now; var grabData = getEntityCustomData(GRAB_USER_DATA_KEY, this.grabbedEntity, {}); + if (this.state === STATE_CONTINUE_EQUIP) { + this.callEntityMethodOnGrabbed("continueEquip"); + } if (this.isInitialGrab) { - if (this.state === STATE_CONTINUE_EQUIP) { - // this.callEntityMethodOnGrabbed("continueEquip", []); - Entities.callEntityMethod(this.grabbedEntity, "continueEquip"); - } if (this.state == STATE_CONTINUE_NEAR_GRABBING) { - // this.callEntityMethodOnGrabbed("continueNearGrab", []); - Entities.callEntityMethod(this.grabbedEntity, "continueNearGrab"); + this.callEntityMethodOnGrabbed("continueNearGrab"); } } @@ -1516,48 +1498,42 @@ function MyController(hand) { this.waitingForBumperRelease = function() { if (this.bumperReleased()) { this.setState(STATE_RELEASE); - var grabData = getEntityCustomData(GRAB_USER_DATA_KEY, this.grabbedEntity, {}); - if (this.isInitialGrab) { - // TODO -- only one of these should be sent - this.callEntityMethodOnGrabbed("releaseGrab", []); - this.callEntityMethodOnGrabbed("unequip", []); - } } }; this.nearTrigger = function() { if (this.triggerSmoothedReleased()) { this.setState(STATE_RELEASE); - this.callEntityMethodOnGrabbed("stopNearTrigger", []); + this.callEntityMethodOnGrabbed("stopNearTrigger"); return; } - this.callSetupEntityMethods("startNearTrigger"); + this.callEntityMethodOnGrabbed("startNearTrigger"); this.setState(STATE_CONTINUE_NEAR_TRIGGER); }; this.farTrigger = function() { if (this.triggerSmoothedReleased()) { this.setState(STATE_RELEASE); - this.callEntityMethodOnGrabbed("stopFarTrigger", []); + this.callEntityMethodOnGrabbed("stopFarTrigger"); return; } - this.callSetupEntityMethods("startFarTrigger"); + this.callEntityMethodOnGrabbed("startFarTrigger"); this.setState(STATE_CONTINUE_FAR_TRIGGER); }; this.continueNearTrigger = function() { if (this.triggerSmoothedReleased()) { this.setState(STATE_RELEASE); - this.callEntityMethodOnGrabbed("stopNearTrigger", []); + this.callEntityMethodOnGrabbed("stopNearTrigger"); return; } - this.callEntityMethodOnGrabbed("continueNearTrigger", []); + this.callEntityMethodOnGrabbed("continueNearTrigger"); }; this.continueFarTrigger = function() { if (this.triggerSmoothedReleased()) { this.setState(STATE_RELEASE); - this.callEntityMethodOnGrabbed("stopFarTrigger", []); + this.callEntityMethodOnGrabbed("stopFarTrigger"); return; } @@ -1573,7 +1549,7 @@ function MyController(hand) { this.lastPickTime = now; if (intersection.entityID != this.grabbedEntity) { this.setState(STATE_RELEASE); - this.callEntityMethodOnGrabbed("stopFarTrigger", []); + this.callEntityMethodOnGrabbed("stopFarTrigger"); return; } } @@ -1581,7 +1557,7 @@ function MyController(hand) { if (USE_ENTITY_LINES_FOR_MOVING === true) { this.lineOn(pickRay.origin, Vec3.multiply(pickRay.direction, LINE_LENGTH), NO_INTERSECT_COLOR); } - this.callEntityMethodOnGrabbed("continueFarTrigger", []); + this.callEntityMethodOnGrabbed("continueFarTrigger"); }; _this.allTouchedIDs = {}; @@ -1641,16 +1617,15 @@ function MyController(hand) { }; this.startTouch = function(entityID) { - this.callEntityMethodOnGrabbed("startTouch", []); + this.callEntityMethodOnGrabbed("startTouch"); }; this.continueTouch = function(entityID) { - // this.callEntityMethodOnGrabbed("continueTouch", []); - Entities.callEntityMethod(this.grabbedEntity, "continueTouch"); + this.callEntityMethodOnGrabbed("continueTouch"); }; this.stopTouch = function(entityID) { - this.callEntityMethodOnGrabbed("stopTouch", []); + this.callEntityMethodOnGrabbed("stopTouch"); }; this.release = function() { @@ -1819,7 +1794,7 @@ function MyController(hand) { this.grabbedEntity = loadedEntityID; this.activateEntity(this.grabbedEntity, loadedProps, true); this.isInitialGrab = true; - this.callSetupEntityMethods("startEquip"); + this.callEntityMethodOnGrabbed("startEquip"); this.setState(STATE_CONTINUE_EQUIP); } } diff --git a/examples/toybox/bow/bow.js b/examples/toybox/bow/bow.js index 489cc6341e..cd52a8ed5b 100644 --- a/examples/toybox/bow/bow.js +++ b/examples/toybox/bow/bow.js @@ -33,7 +33,8 @@ }; var ARROW_MODEL_URL = "http://hifi-content.s3.amazonaws.com/james/bow_and_arrow/models/newarrow_textured.fbx"; - var ARROW_COLLISION_HULL_URL = "http://hifi-content.s3.amazonaws.com/james/bow_and_arrow/models/newarrow_collision_hull.obj"; + var ARROW_COLLISION_HULL_URL = + "http://hifi-content.s3.amazonaws.com/james/bow_and_arrow/models/newarrow_collision_hull.obj"; var ARROW_DIMENSIONS = { x: 0.02, @@ -94,7 +95,6 @@ } Bow.prototype = { - isGrabbed: false, stringDrawn: false, aiming: false, arrowTipPosition: null, @@ -125,33 +125,13 @@ Entities.deleteEntity(this.arrow); }, - setLeftHand: function() { - if (this.isGrabbed === true) { - return false; - } - this.hand = 'left'; - }, - - setRightHand: function() { - if (this.isGrabbed === true) { - return false; - } - this.hand = 'right'; - }, - - startEquip: function() { + startEquip: function(hand, avatarID) { + this.hand = hand; print('START BOW GRAB') - if (this.isGrabbed === true) { - return false; - } - - this.isGrabbed = true; - - this.initialHand = this.hand; //disable the opposite hand in handControllerGrab.js by message - var handToDisable = this.initialHand === 'right' ? 'left' : 'right'; + var handToDisable = this.hand === 'right' ? 'left' : 'right'; Messages.sendMessage('Hifi-Hand-Disabler', handToDisable); var data = getEntityCustomData('grabbableKey', this.entityID, {}); @@ -159,7 +139,7 @@ setEntityCustomData('grabbableKey', this.entityID, data); }, - continueEquip: function() { + continueEquip: function(hand, avatarID) { this.deltaTime = checkInterval(); //debounce during debugging -- maybe we're updating too fast? @@ -188,25 +168,19 @@ this.checkStringHand(); }, - - releaseGrab: function() { + releaseEquip: function(hand, avatarID) { // print('RELEASE GRAB EVENT') - if (this.isGrabbed === true && this.hand === this.initialHand) { + Messages.sendMessage('Hifi-Hand-Disabler', "none") - Messages.sendMessage('Hifi-Hand-Disabler', "none") + this.stringDrawn = false; + this.deleteStrings(); - this.isGrabbed = false; - this.stringDrawn = false; - this.deleteStrings(); - - var data = getEntityCustomData('grabbableKey', this.entityID, {}); - data.grabbable = true; - setEntityCustomData('grabbableKey', this.entityID, data); - Entities.deleteEntity(this.arrow); - this.aiming = false; - this.hasArrowNotched = false; - - } + var data = getEntityCustomData('grabbableKey', this.entityID, {}); + data.grabbable = true; + setEntityCustomData('grabbableKey', this.entityID, data); + Entities.deleteEntity(this.arrow); + this.aiming = false; + this.hasArrowNotched = false; }, createArrow: function() { @@ -367,10 +341,10 @@ checkStringHand: function() { //invert the hands because our string will be held with the opposite hand of the first one we pick up the bow with var triggerLookup; - if (this.initialHand === 'left') { + if (this.hand === 'left') { triggerLookup = 1; this.getStringHandPosition = MyAvatar.getRightPalmPosition; - } else if (this.initialHand === 'right') { + } else if (this.hand === 'right') { this.getStringHandPosition = MyAvatar.getLeftPalmPosition; triggerLookup = 0; } From 1ae47b17f0181ab2a6137ab64fcf9bfd9605f02a Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Wed, 10 Feb 2016 16:41:35 -0800 Subject: [PATCH 2/9] size-cull parent entities by their queryAABox rather than their dimensions to avoid having the entity-server send a child but not the parent --- libraries/entities/src/EntityTreeElement.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libraries/entities/src/EntityTreeElement.cpp b/libraries/entities/src/EntityTreeElement.cpp index 1e798f2e0c..5ae3d562b6 100644 --- a/libraries/entities/src/EntityTreeElement.cpp +++ b/libraries/entities/src/EntityTreeElement.cpp @@ -313,7 +313,11 @@ OctreeElement::AppendState EntityTreeElement::appendElementData(OctreePacketData // pops to the next higher cell. So we want to check to see that the entity is large enough to be seen // before we consider including it. if (includeThisEntity) { - AABox entityBounds = entity->getAABox(success); + success = true; + // we can't cull a parent-entity by it's dimensions because the child may be larger. we need to + // avoid sending details about a child but not the parent. the parent's queryAACube should have + // been adjusted to encompase the queryAACube of the child. + AABox entityBounds = entity->hasChildren() ? AABox(entityCube) : entity->getAABox(success); if (!success) { // if this entity is a child of an avatar, the entity-server wont be able to determine its // AABox. If this happens, fall back to the queryAACube. From 3f922240d05eddbd02e52078cb6f5ac3c16312dd Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Wed, 10 Feb 2016 16:42:13 -0800 Subject: [PATCH 3/9] clean up handling of success flag and some debugging prints --- libraries/shared/src/SpatiallyNestable.cpp | 43 +++++++++++++++++++--- libraries/shared/src/SpatiallyNestable.h | 2 + 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/libraries/shared/src/SpatiallyNestable.cpp b/libraries/shared/src/SpatiallyNestable.cpp index 95e8f62d21..31654ca718 100644 --- a/libraries/shared/src/SpatiallyNestable.cpp +++ b/libraries/shared/src/SpatiallyNestable.cpp @@ -101,11 +101,13 @@ SpatiallyNestablePointer SpatiallyNestable::getParentPointer(bool& success) cons // we have a _parentID but no parent pointer, or our parent pointer was to the wrong thing QSharedPointer parentFinder = DependencyManager::get(); if (!parentFinder) { + qDebug() << "SpatiallyNestable::getParentPointer -- no parentFinder"; success = false; return nullptr; } _parent = parentFinder->find(parentID, success); if (!success) { + qDebug() << "parentFinder failed for " << parentID; return nullptr; } @@ -118,6 +120,7 @@ SpatiallyNestablePointer SpatiallyNestable::getParentPointer(bool& success) cons if (parent || parentID.isNull()) { success = true; } else { + qDebug() << "SpatiallyNestable::getParentPointer -- couldn't resolve parent: " << parentID; success = false; } @@ -392,9 +395,15 @@ void SpatiallyNestable::setOrientation(const glm::quat& orientation) { } glm::vec3 SpatiallyNestable::getVelocity(bool& success) const { - glm::vec3 parentVelocity = getParentVelocity(success); - Transform parentTransform = getParentTransform(success); glm::vec3 result; + glm::vec3 parentVelocity = getParentVelocity(success); + if (!success) { + return result; + } + Transform parentTransform = getParentTransform(success); + if (!success) { + return result; + } _velocityLock.withReadLock([&] { // TODO: take parent angularVelocity into account. result = parentVelocity + parentTransform.getRotation() * _velocity; @@ -431,16 +440,25 @@ void SpatiallyNestable::setVelocity(const glm::vec3& velocity) { glm::vec3 SpatiallyNestable::getParentVelocity(bool& success) const { glm::vec3 result; SpatiallyNestablePointer parent = getParentPointer(success); - if (success && parent) { + if (!success) { + return result; + } + if (parent) { result = parent->getVelocity(success); } return result; } glm::vec3 SpatiallyNestable::getAngularVelocity(bool& success) const { - glm::vec3 parentAngularVelocity = getParentAngularVelocity(success); - Transform parentTransform = getParentTransform(success); glm::vec3 result; + glm::vec3 parentAngularVelocity = getParentAngularVelocity(success); + if (!success) { + return result; + } + Transform parentTransform = getParentTransform(success); + if (!success) { + return result; + } _angularVelocityLock.withReadLock([&] { result = parentAngularVelocity + parentTransform.getRotation() * _angularVelocity; }); @@ -475,7 +493,10 @@ void SpatiallyNestable::setAngularVelocity(const glm::vec3& angularVelocity) { glm::vec3 SpatiallyNestable::getParentAngularVelocity(bool& success) const { glm::vec3 result; SpatiallyNestablePointer parent = getParentPointer(success); - if (success && parent) { + if (!success) { + return result; + } + if (parent) { result = parent->getAngularVelocity(success); } return result; @@ -672,6 +693,16 @@ QList SpatiallyNestable::getChildren() const { return children; } +bool SpatiallyNestable::hasChildren() const { + bool result = false; + _childrenLock.withReadLock([&] { + if (_children.size() > 0) { + result = true; + } + }); + return result; +} + const Transform SpatiallyNestable::getAbsoluteJointTransformInObjectFrame(int jointIndex) const { Transform jointTransformInObjectFrame; glm::vec3 position = getAbsoluteJointTranslationInObjectFrame(jointIndex); diff --git a/libraries/shared/src/SpatiallyNestable.h b/libraries/shared/src/SpatiallyNestable.h index 0c43aff20d..2a8976b38f 100644 --- a/libraries/shared/src/SpatiallyNestable.h +++ b/libraries/shared/src/SpatiallyNestable.h @@ -116,6 +116,8 @@ public: virtual void setLocalScale(const glm::vec3& scale); QList getChildren() const; + bool hasChildren() const; + NestableType getNestableType() const { return _nestableType; } // this object's frame From 3e71efcdbbe63c0b4cb099f8bf0f7c996b9bcff7 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Wed, 10 Feb 2016 18:21:44 -0800 Subject: [PATCH 4/9] all code that asks isMoving appears to mean relative to parent --- libraries/entities/src/EntityItem.cpp | 4 ---- libraries/entities/src/EntityItem.h | 1 - libraries/entities/src/EntitySimulation.cpp | 2 +- 3 files changed, 1 insertion(+), 6 deletions(-) diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index f496eaced4..7c5ba72096 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -993,10 +993,6 @@ void EntityItem::simulateKinematicMotion(float timeElapsed, bool setFlags) { } bool EntityItem::isMoving() const { - return hasVelocity() || hasAngularVelocity(); -} - -bool EntityItem::isMovingRelativeToParent() const { return hasLocalVelocity() || hasLocalAngularVelocity(); } diff --git a/libraries/entities/src/EntityItem.h b/libraries/entities/src/EntityItem.h index 55741823f1..a1e5257d29 100644 --- a/libraries/entities/src/EntityItem.h +++ b/libraries/entities/src/EntityItem.h @@ -345,7 +345,6 @@ public: void clearDirtyFlags(uint32_t mask = 0xffffffff) { _dirtyFlags &= ~mask; } bool isMoving() const; - bool isMovingRelativeToParent() const; bool isSimulated() const { return _simulated; } diff --git a/libraries/entities/src/EntitySimulation.cpp b/libraries/entities/src/EntitySimulation.cpp index a1f55a92a3..23e5b99337 100644 --- a/libraries/entities/src/EntitySimulation.cpp +++ b/libraries/entities/src/EntitySimulation.cpp @@ -254,7 +254,7 @@ void EntitySimulation::moveSimpleKinematics(const quint64& now) { SetOfEntities::iterator itemItr = _simpleKinematicEntities.begin(); while (itemItr != _simpleKinematicEntities.end()) { EntityItemPointer entity = *itemItr; - if (entity->isMovingRelativeToParent() && !entity->getPhysicsInfo()) { + if (entity->isMoving() && !entity->getPhysicsInfo()) { entity->simulate(now); _entitiesToSort.insert(entity); ++itemItr; From ecf22cd8b8835b71e0915d9ddac084c301d7d6c0 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Wed, 10 Feb 2016 18:22:20 -0800 Subject: [PATCH 5/9] update toybox toys to use changed grab entityMethod calls --- examples/controllers/handControllerGrab.js | 45 ++++++-------------- examples/toybox/bow/bow.js | 12 +++--- examples/toybox/bubblewand/wand.js | 3 +- examples/toybox/doll/doll.js | 22 ++++------ examples/toybox/flashlight/flashlight.js | 19 +++------ examples/toybox/ping_pong_gun/pingPongGun.js | 45 ++++++-------------- examples/toybox/pistol/pistol.js | 6 +-- examples/toybox/spray_paint/sprayPaintCan.js | 14 ++---- 8 files changed, 55 insertions(+), 111 deletions(-) diff --git a/examples/controllers/handControllerGrab.js b/examples/controllers/handControllerGrab.js index cc486802ff..e2f88ccb3b 100644 --- a/examples/controllers/handControllerGrab.js +++ b/examples/controllers/handControllerGrab.js @@ -334,9 +334,8 @@ function MyController(hand) { }; this.callEntityMethodOnGrabbed = function(entityMethodName) { - // print("Entity Method: " + entityMethodName + ", hand: " + this.hand); - Entities.callEntityMethod(this.grabbedEntity, entityMethodName, [JSON.stringify(this.hand), - JSON.stringify(MyAvatar.SessionUUID)]); + var args = [this.hand === RIGHT_HAND ? "right" : "left", MyAvatar.sessionUUID]; + Entities.callEntityMethod(this.grabbedEntity, entityMethodName, args); } this.setState = function(newState) { @@ -1089,9 +1088,7 @@ function MyController(hand) { this.continueDistanceHolding = function() { if (this.triggerSmoothedReleased()) { this.setState(STATE_RELEASE); - if (this.isInitialGrab) { - this.callEntityMethodOnGrabbed("releaseGrab"); - } + this.callEntityMethodOnGrabbed("releaseGrab"); return; } @@ -1325,9 +1322,7 @@ function MyController(hand) { if (this.state == STATE_NEAR_GRABBING && this.triggerSmoothedReleased()) { this.setState(STATE_RELEASE); - if (this.isInitialGrab) { - this.callEntityMethodOnGrabbed("releaseGrab"); - } + this.callEntityMethodOnGrabbed("releaseGrab"); return; } @@ -1413,9 +1408,7 @@ function MyController(hand) { this.continueNearGrabbing = function() { if (this.state == STATE_CONTINUE_NEAR_GRABBING && this.triggerSmoothedReleased()) { this.setState(STATE_RELEASE); - if (this.isInitialGrab) { - this.callEntityMethodOnGrabbed("releaseGrab"); - } + this.callEntityMethodOnGrabbed("releaseGrab"); return; } if (this.state == STATE_CONTINUE_EQUIP_BD && this.bumperReleased()) { @@ -1429,9 +1422,7 @@ function MyController(hand) { } if (this.state == STATE_CONTINUE_NEAR_GRABBING && this.bumperSqueezed()) { this.setState(STATE_CONTINUE_EQUIP_BD); - if (this.isInitialGrab) { - this.callEntityMethodOnGrabbed("releaseGrab"); - } + this.callEntityMethodOnGrabbed("releaseGrab"); this.callEntityMethodOnGrabbed("startEquip"); return; } @@ -1467,10 +1458,8 @@ function MyController(hand) { if (this.state === STATE_CONTINUE_EQUIP) { this.callEntityMethodOnGrabbed("continueEquip"); } - if (this.isInitialGrab) { - if (this.state == STATE_CONTINUE_NEAR_GRABBING) { - this.callEntityMethodOnGrabbed("continueNearGrab"); - } + if (this.state == STATE_CONTINUE_NEAR_GRABBING) { + this.callEntityMethodOnGrabbed("continueNearGrab"); } if (this.actionID && this.actionTimeout - now < ACTION_TTL_REFRESH * MSEC_PER_SEC) { @@ -1654,19 +1643,11 @@ function MyController(hand) { this.actionID = null; this.setState(STATE_OFF); - if (this.isInitialGrab) { - Messages.sendMessage('Hifi-Object-Manipulation', JSON.stringify({ - action: 'release', - grabbedEntity: this.grabbedEntity, - joint: this.hand === RIGHT_HAND ? "RightHand" : "LeftHand" - })); - } else { - Messages.sendMessage('Hifi-Object-Manipulation', JSON.stringify({ - action: 'shared-release', - grabbedEntity: this.grabbedEntity, - joint: this.hand === RIGHT_HAND ? "RightHand" : "LeftHand" - })); - } + Messages.sendMessage('Hifi-Object-Manipulation', JSON.stringify({ + action: 'release', + grabbedEntity: this.grabbedEntity, + joint: this.hand === RIGHT_HAND ? "RightHand" : "LeftHand" + })); this.grabbedEntity = null; }; diff --git a/examples/toybox/bow/bow.js b/examples/toybox/bow/bow.js index cd52a8ed5b..c947b59518 100644 --- a/examples/toybox/bow/bow.js +++ b/examples/toybox/bow/bow.js @@ -125,13 +125,13 @@ Entities.deleteEntity(this.arrow); }, - startEquip: function(hand, avatarID) { - this.hand = hand; - - print('START BOW GRAB') + startEquip: function(entityID, args) { + this.hand = args[0]; + avatarID = args[1]; //disable the opposite hand in handControllerGrab.js by message var handToDisable = this.hand === 'right' ? 'left' : 'right'; + print("disabling hand: " + handToDisable); Messages.sendMessage('Hifi-Hand-Disabler', handToDisable); var data = getEntityCustomData('grabbableKey', this.entityID, {}); @@ -139,7 +139,7 @@ setEntityCustomData('grabbableKey', this.entityID, data); }, - continueEquip: function(hand, avatarID) { + continueEquip: function(entityID, args) { this.deltaTime = checkInterval(); //debounce during debugging -- maybe we're updating too fast? @@ -168,7 +168,7 @@ this.checkStringHand(); }, - releaseEquip: function(hand, avatarID) { + releaseEquip: function(entityID, args) { // print('RELEASE GRAB EVENT') Messages.sendMessage('Hifi-Hand-Disabler', "none") diff --git a/examples/toybox/bubblewand/wand.js b/examples/toybox/bubblewand/wand.js index d0ef2871f8..379e94333f 100644 --- a/examples/toybox/bubblewand/wand.js +++ b/examples/toybox/bubblewand/wand.js @@ -119,7 +119,8 @@ //wait to make the bubbles collidable, so that they dont hit each other and the wand Script.setTimeout(this.addCollisionsToBubbleAfterCreation(this.currentBubble), lifetime / 2); - //release the bubble -- when we create a new bubble, it will carry on and this update loop will affect the new bubble + //release the bubble -- when we create a new bubble, it will carry on and this update loop will + // affect the new bubble this.createBubbleAtTipOfWand(); return; } else { diff --git a/examples/toybox/doll/doll.js b/examples/toybox/doll/doll.js index c7661af610..15c587ba4c 100644 --- a/examples/toybox/doll/doll.js +++ b/examples/toybox/doll/doll.js @@ -24,15 +24,11 @@ Doll.prototype = { audioInjector: null, isGrabbed: false, - setLeftHand: function() { - this.hand = 'left'; - }, - setRightHand: function() { - this.hand = 'right'; - }, + startNearGrab: function(entityID, args) { + this.hand = args[0]; + avatarID = args[1]; - startNearGrab: function() { Entities.editEntity(this.entityID, { animation: { url: "https://hifi-public.s3.amazonaws.com/models/Bboys/zombie_scream.fbx", @@ -53,18 +49,18 @@ this.startNearGrab(id, params); }, - continueNearGrab: function() { + continueNearGrab: function(entityID, args) { var props = Entities.getEntityProperties(this.entityID, ["position"]); var audioOptions = { position: props.position }; this.audioInjector.options = audioOptions; }, - continueEquip: function() { - this.continueNearGrab(); + continueEquip: function(entityID, args) { + this.continueNearGrab(entityID, args); }, - releaseGrab: function() { + releaseGrab: function(entityID, args) { if (this.isGrabbed === true && this.hand === this.initialHand) { this.audioInjector.stop(); Entities.editEntity(this.entityID, { @@ -79,8 +75,8 @@ this.isGrabbed = false; } }, - releaseEquip: function() { - this.releaseGrab(); + releaseEquip: function(entityID, args) { + this.releaseGrab(entityID, args); }, preload: function(entityID) { diff --git a/examples/toybox/flashlight/flashlight.js b/examples/toybox/flashlight/flashlight.js index 1a85af695d..19cbc422f4 100644 --- a/examples/toybox/flashlight/flashlight.js +++ b/examples/toybox/flashlight/flashlight.js @@ -77,15 +77,10 @@ whichHand: null, hasSpotlight: false, spotlight: null, - setRightHand: function() { - this.hand = 'RIGHT'; - }, - setLeftHand: function() { - this.hand = 'LEFT'; - }, + startNearGrab: function(entityID, args) { + this.hand = args[0]; - startNearGrab: function(entityID) { print("FLASHLIGHT startNearGrab"); if (!this.hasSpotlight) { @@ -161,11 +156,11 @@ this.changeLightWithTriggerPressure(this.whichHand); } }, - continueEquip: function() { - this.continueNearGrab(); + continueEquip: function(entityID, args) { + this.continueNearGrab(entityID, args); }, - releaseGrab: function() { + releaseGrab: function(entityID, args) { //delete the lights and reset state if (this.hasSpotlight) { Entities.deleteEntity(this.spotlight); @@ -177,8 +172,8 @@ this.lightOn = false; } }, - releaseEquip: function() { - this.releaseGrab(); + releaseEquip: function(entityID, args) { + this.releaseGrab(entityID, args); }, changeLightWithTriggerPressure: function(flashLightHand) { diff --git a/examples/toybox/ping_pong_gun/pingPongGun.js b/examples/toybox/ping_pong_gun/pingPongGun.js index bcb793746b..29eb2e3057 100644 --- a/examples/toybox/ping_pong_gun/pingPongGun.js +++ b/examples/toybox/ping_pong_gun/pingPongGun.js @@ -54,47 +54,26 @@ PingPongGun.prototype = { hand: null, - whichHand: null, gunTipPosition: null, canShoot: false, canShootTimeout: null, - setRightHand: function() { - this.hand = 1; + + startEquip: function(entityID, args) { + this.hand = args[0] == "left" ? 0 : 1; }, - setLeftHand: function() { - this.hand = 0; - }, - - startEquip: function() { - this.setWhichHand(); - }, - - setWhichHand: function() { - this.whichHand = this.hand; - }, - - continueEquip: function() { - if (this.whichHand === null) { - //only set the active hand once -- if we always read the current hand, our 'holding' hand will get overwritten - this.setWhichHand(); - } else { - if (this.canShootTimeout !== null) { - Script.clearTimeout(this.canShootTimeout); - } - this.checkTriggerPressure(this.whichHand); + continueEquip: function(entityID, args) { + if (this.canShootTimeout !== null) { + Script.clearTimeout(this.canShootTimeout); } + this.checkTriggerPressure(this.hand); }, - releaseEquip: function() { + releaseEquip: function(entityID, args) { var _this = this; - - if (this.whichHand === this.hand) { - this.whichHand = null; - this.canShootTimeout = Script.setTimeout(function() { - _this.canShoot = false; - }, 250); - } + this.canShootTimeout = Script.setTimeout(function() { + _this.canShoot = false; + }, 250); }, checkTriggerPressure: function(gunHand) { @@ -102,7 +81,7 @@ if (this.triggerValue < RELOAD_THRESHOLD) { // print('RELOAD'); this.canShoot = true; - } else if (this.triggerValue >= RELOAD_THRESHOLD && this.canShoot === true && this.hand === this.whichHand) { + } else if (this.triggerValue >= RELOAD_THRESHOLD && this.canShoot === true) { var gunProperties = Entities.getEntityProperties(this.entityID, ["position", "rotation"]); this.shootBall(gunProperties); this.canShoot = false; diff --git a/examples/toybox/pistol/pistol.js b/examples/toybox/pistol/pistol.js index 87e2f57780..99b7503cba 100644 --- a/examples/toybox/pistol/pistol.js +++ b/examples/toybox/pistol/pistol.js @@ -49,10 +49,10 @@ startEquip: function(id, params) { this.equipped = true; - this.hand = JSON.parse(params[0]); + this.hand = params[0] == "left" ? 0 : 1; }, - continueEquip: function() { + continueEquip: function(id, params) { if (!this.equipped) { return; } @@ -111,7 +111,7 @@ }); }, - unequip: function() { + releaseEquip: function(id, params) { this.hand = null; this.equipped = false; Overlays.editOverlay(this.laser, { diff --git a/examples/toybox/spray_paint/sprayPaintCan.js b/examples/toybox/spray_paint/sprayPaintCan.js index 60fd12b975..14e1f328f8 100644 --- a/examples/toybox/spray_paint/sprayPaintCan.js +++ b/examples/toybox/spray_paint/sprayPaintCan.js @@ -38,20 +38,12 @@ Controller.Standard.RT, ]; - this.setRightHand = function () { - this.hand = 1; - } - - this.setLeftHand = function () { - this.hand = 0; - } - - this.startNearGrab = function () { - this.whichHand = this.hand; + this.startNearGrab = function (entityID, args) { + this.hand = args[0] == "left" ? 0 : 1; } this.toggleWithTriggerPressure = function () { - this.triggerValue = Controller.getValue(TRIGGER_CONTROLS[this.whichHand]); + this.triggerValue = Controller.getValue(TRIGGER_CONTROLS[this.hand]); if (this.triggerValue < DISABLE_SPRAY_THRESHOLD && this.spraying === true) { this.spraying = false; this.disableStream(); From 3fe01ccf1037d91c221f429b6b42aec619066ccc Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Wed, 10 Feb 2016 18:32:05 -0800 Subject: [PATCH 6/9] cleanups --- libraries/entities/src/EntityTreeElement.cpp | 4 ++-- libraries/shared/src/SpatiallyNestable.cpp | 3 --- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/libraries/entities/src/EntityTreeElement.cpp b/libraries/entities/src/EntityTreeElement.cpp index 5ae3d562b6..932d041795 100644 --- a/libraries/entities/src/EntityTreeElement.cpp +++ b/libraries/entities/src/EntityTreeElement.cpp @@ -314,9 +314,9 @@ OctreeElement::AppendState EntityTreeElement::appendElementData(OctreePacketData // before we consider including it. if (includeThisEntity) { success = true; - // we can't cull a parent-entity by it's dimensions because the child may be larger. we need to + // we can't cull a parent-entity by its dimensions because the child may be larger. we need to // avoid sending details about a child but not the parent. the parent's queryAACube should have - // been adjusted to encompase the queryAACube of the child. + // been adjusted to encompass the queryAACube of the child. AABox entityBounds = entity->hasChildren() ? AABox(entityCube) : entity->getAABox(success); if (!success) { // if this entity is a child of an avatar, the entity-server wont be able to determine its diff --git a/libraries/shared/src/SpatiallyNestable.cpp b/libraries/shared/src/SpatiallyNestable.cpp index 31654ca718..557b25d9b2 100644 --- a/libraries/shared/src/SpatiallyNestable.cpp +++ b/libraries/shared/src/SpatiallyNestable.cpp @@ -101,13 +101,11 @@ SpatiallyNestablePointer SpatiallyNestable::getParentPointer(bool& success) cons // we have a _parentID but no parent pointer, or our parent pointer was to the wrong thing QSharedPointer parentFinder = DependencyManager::get(); if (!parentFinder) { - qDebug() << "SpatiallyNestable::getParentPointer -- no parentFinder"; success = false; return nullptr; } _parent = parentFinder->find(parentID, success); if (!success) { - qDebug() << "parentFinder failed for " << parentID; return nullptr; } @@ -120,7 +118,6 @@ SpatiallyNestablePointer SpatiallyNestable::getParentPointer(bool& success) cons if (parent || parentID.isNull()) { success = true; } else { - qDebug() << "SpatiallyNestable::getParentPointer -- couldn't resolve parent: " << parentID; success = false; } From 880aedd4445014799992b70601b8c5248b692d07 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Wed, 10 Feb 2016 19:01:25 -0800 Subject: [PATCH 7/9] update to track grab-script changes --- examples/attachedEntitiesManager.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/examples/attachedEntitiesManager.js b/examples/attachedEntitiesManager.js index b5d023c70c..7172b456be 100644 --- a/examples/attachedEntitiesManager.js +++ b/examples/attachedEntitiesManager.js @@ -120,10 +120,7 @@ function AttachedEntitiesManager() { parsedMessage.action === 'loaded') { // ignore } else if (parsedMessage.action === 'release') { - manager.checkIfWearable(parsedMessage.grabbedEntity, parsedMessage.joint) - // manager.saveAttachedEntities(); - } else if (parsedMessage.action === 'shared-release') { - manager.updateRelativeOffsets(parsedMessage.grabbedEntity); + manager.handleEntityRelease(parsedMessage.grabbedEntity, parsedMessage.joint) // manager.saveAttachedEntities(); } else if (parsedMessage.action === 'equip') { // manager.saveAttachedEntities(); @@ -145,7 +142,14 @@ function AttachedEntitiesManager() { return false; } - this.checkIfWearable = function(grabbedEntity, releasedFromJoint) { + this.handleEntityRelease = function(grabbedEntity, releasedFromJoint) { + // if this is still equipped, just rewrite the position information. + var grabData = getEntityCustomData('grabKey', entityID, {}); + if ("refCount" in grabData && grabData.refCount > 0) { + manager.updateRelativeOffsets(parsedMessage.grabbedEntity); + return; + } + var allowedJoints = getEntityCustomData('wearable', grabbedEntity, DEFAULT_WEARABLE_DATA).joints; var props = Entities.getEntityProperties(grabbedEntity, ["position", "parentID", "parentJointIndex"]); From 6a646f1c249b0d1b860c34bf7757cb9c009c4503 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Wed, 10 Feb 2016 19:01:41 -0800 Subject: [PATCH 8/9] put isMoving back and change all uses to isMovingRelativeToParent --- .../entities-renderer/src/RenderableModelEntityItem.cpp | 2 +- libraries/entities/src/EntityItem.cpp | 6 +++++- libraries/entities/src/EntityItem.h | 1 + libraries/entities/src/EntitySimulation.cpp | 6 +++--- libraries/physics/src/EntityMotionState.cpp | 6 +++--- libraries/physics/src/PhysicalEntitySimulation.cpp | 8 ++++---- 6 files changed, 17 insertions(+), 12 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index 84c53e05da..cc202dde37 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -412,7 +412,7 @@ void RenderableModelEntityItem::render(RenderArgs* args) { } }); - bool movingOrAnimating = isMoving() || isAnimatingSomething(); + bool movingOrAnimating = isMovingRelativeToParent() || isAnimatingSomething(); if ((movingOrAnimating || _needsInitialSimulation || _model->getTranslation() != getPosition() || diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index 7c5ba72096..bc1a848724 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -993,6 +993,10 @@ void EntityItem::simulateKinematicMotion(float timeElapsed, bool setFlags) { } bool EntityItem::isMoving() const { + return hasVelocity() || hasAngularVelocity(); +} + +bool EntityItem::isMovingRelativeToParent() const { return hasLocalVelocity() || hasLocalAngularVelocity(); } @@ -1558,7 +1562,7 @@ void EntityItem::computeCollisionGroupAndFinalMask(int16_t& group, int16_t& mask } else { if (_dynamic) { group = BULLET_COLLISION_GROUP_DYNAMIC; - } else if (isMoving() || hasActions()) { + } else if (isMovingRelativeToParent() || hasActions()) { group = BULLET_COLLISION_GROUP_KINEMATIC; } else { group = BULLET_COLLISION_GROUP_STATIC; diff --git a/libraries/entities/src/EntityItem.h b/libraries/entities/src/EntityItem.h index a1e5257d29..55741823f1 100644 --- a/libraries/entities/src/EntityItem.h +++ b/libraries/entities/src/EntityItem.h @@ -345,6 +345,7 @@ public: void clearDirtyFlags(uint32_t mask = 0xffffffff) { _dirtyFlags &= ~mask; } bool isMoving() const; + bool isMovingRelativeToParent() const; bool isSimulated() const { return _simulated; } diff --git a/libraries/entities/src/EntitySimulation.cpp b/libraries/entities/src/EntitySimulation.cpp index 23e5b99337..014ab33094 100644 --- a/libraries/entities/src/EntitySimulation.cpp +++ b/libraries/entities/src/EntitySimulation.cpp @@ -70,7 +70,7 @@ void EntitySimulation::prepareEntityForDelete(EntityItemPointer entity) { } void EntitySimulation::addEntityInternal(EntityItemPointer entity) { - if (entity->isMoving() && !entity->getPhysicsInfo()) { + if (entity->isMovingRelativeToParent() && !entity->getPhysicsInfo()) { QMutexLocker lock(&_mutex); _simpleKinematicEntities.insert(entity); } @@ -78,7 +78,7 @@ void EntitySimulation::addEntityInternal(EntityItemPointer entity) { void EntitySimulation::changeEntityInternal(EntityItemPointer entity) { QMutexLocker lock(&_mutex); - if (entity->isMoving() && !entity->getPhysicsInfo()) { + if (entity->isMovingRelativeToParent() && !entity->getPhysicsInfo()) { _simpleKinematicEntities.insert(entity); } else { _simpleKinematicEntities.remove(entity); @@ -254,7 +254,7 @@ void EntitySimulation::moveSimpleKinematics(const quint64& now) { SetOfEntities::iterator itemItr = _simpleKinematicEntities.begin(); while (itemItr != _simpleKinematicEntities.end()) { EntityItemPointer entity = *itemItr; - if (entity->isMoving() && !entity->getPhysicsInfo()) { + if (entity->isMovingRelativeToParent() && !entity->getPhysicsInfo()) { entity->simulate(now); _entitiesToSort.insert(entity); ++itemItr; diff --git a/libraries/physics/src/EntityMotionState.cpp b/libraries/physics/src/EntityMotionState.cpp index c798e07d52..8c0dab98db 100644 --- a/libraries/physics/src/EntityMotionState.cpp +++ b/libraries/physics/src/EntityMotionState.cpp @@ -158,12 +158,12 @@ PhysicsMotionType EntityMotionState::computePhysicsMotionType() const { } return MOTION_TYPE_DYNAMIC; } - return (_entity->isMoving() || _entity->hasActions()) ? MOTION_TYPE_KINEMATIC : MOTION_TYPE_STATIC; + return (_entity->isMovingRelativeToParent() || _entity->hasActions()) ? MOTION_TYPE_KINEMATIC : MOTION_TYPE_STATIC; } bool EntityMotionState::isMoving() const { assert(entityTreeIsLocked()); - return _entity && _entity->isMoving(); + return _entity && _entity->isMovingRelativeToParent(); } // This callback is invoked by the physics simulation in two cases: @@ -555,7 +555,7 @@ uint32_t EntityMotionState::getIncomingDirtyFlags() { } // we add DIRTY_MOTION_TYPE if the body's motion type disagrees with entity velocity settings int bodyFlags = _body->getCollisionFlags(); - bool isMoving = _entity->isMoving(); + bool isMoving = _entity->isMovingRelativeToParent(); if (((bodyFlags & btCollisionObject::CF_STATIC_OBJECT) && isMoving) || (bodyFlags & btCollisionObject::CF_KINEMATIC_OBJECT && !isMoving)) { dirtyFlags |= Simulation::DIRTY_MOTION_TYPE; diff --git a/libraries/physics/src/PhysicalEntitySimulation.cpp b/libraries/physics/src/PhysicalEntitySimulation.cpp index aaa706b370..4a70c248c6 100644 --- a/libraries/physics/src/PhysicalEntitySimulation.cpp +++ b/libraries/physics/src/PhysicalEntitySimulation.cpp @@ -51,7 +51,7 @@ void PhysicalEntitySimulation::addEntityInternal(EntityItemPointer entity) { if (!motionState) { _entitiesToAddToPhysics.insert(entity); } - } else if (entity->isMoving()) { + } else if (entity->isMovingRelativeToParent()) { _simpleKinematicEntities.insert(entity); } } @@ -98,7 +98,7 @@ void PhysicalEntitySimulation::changeEntityInternal(EntityItemPointer entity) { _physicalObjects.remove(motionState); _outgoingChanges.remove(motionState); _entitiesToRemoveFromPhysics.insert(entity); - if (entity->isMoving()) { + if (entity->isMovingRelativeToParent()) { _simpleKinematicEntities.insert(entity); } } else { @@ -109,7 +109,7 @@ void PhysicalEntitySimulation::changeEntityInternal(EntityItemPointer entity) { // Perhaps it's shape has changed and it can now be added? _entitiesToAddToPhysics.insert(entity); _simpleKinematicEntities.remove(entity); // just in case it's non-physical-kinematic - } else if (entity->isMoving()) { + } else if (entity->isMovingRelativeToParent()) { _simpleKinematicEntities.insert(entity); } else { _simpleKinematicEntities.remove(entity); // just in case it's non-physical-kinematic @@ -208,7 +208,7 @@ void PhysicalEntitySimulation::getObjectsToAddToPhysics(VectorOfMotionStates& re } else if (!entity->shouldBePhysical()) { // this entity should no longer be on the internal _entitiesToAddToPhysics entityItr = _entitiesToAddToPhysics.erase(entityItr); - if (entity->isMoving()) { + if (entity->isMovingRelativeToParent()) { _simpleKinematicEntities.insert(entity); } } else if (entity->isReadyToComputeShape()) { From ffce38769f621596a416635dff58a5fa9c202dba Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Wed, 10 Feb 2016 19:16:08 -0800 Subject: [PATCH 9/9] properties hold local velocities, not world-frame ones --- libraries/entities/src/EntityItem.cpp | 12 ++++++------ libraries/entities/src/EntityScriptingInterface.cpp | 8 ++++++-- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index bc1a848724..6936fee8a9 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -76,8 +76,8 @@ EntityItem::EntityItem(const EntityItemID& entityItemID) : _physicsInfo(nullptr), _simulated(false) { - setVelocity(ENTITY_ITEM_DEFAULT_VELOCITY); - setAngularVelocity(ENTITY_ITEM_DEFAULT_ANGULAR_VELOCITY); + setLocalVelocity(ENTITY_ITEM_DEFAULT_VELOCITY); + setLocalAngularVelocity(ENTITY_ITEM_DEFAULT_ANGULAR_VELOCITY); // explicitly set transform parts to set dirty flags used by batch rendering setScale(ENTITY_ITEM_DEFAULT_DIMENSIONS); quint64 now = usecTimestampNow(); @@ -244,8 +244,8 @@ OctreeElement::AppendState EntityItem::appendEntityData(OctreePacketData* packet APPEND_ENTITY_PROPERTY(PROP_SIMULATION_OWNER, _simulationOwner.toByteArray()); APPEND_ENTITY_PROPERTY(PROP_POSITION, getLocalPosition()); APPEND_ENTITY_PROPERTY(PROP_ROTATION, getLocalOrientation()); - APPEND_ENTITY_PROPERTY(PROP_VELOCITY, getVelocity()); - APPEND_ENTITY_PROPERTY(PROP_ANGULAR_VELOCITY, getAngularVelocity()); + APPEND_ENTITY_PROPERTY(PROP_VELOCITY, getLocalVelocity()); + APPEND_ENTITY_PROPERTY(PROP_ANGULAR_VELOCITY, getLocalAngularVelocity()); APPEND_ENTITY_PROPERTY(PROP_ACCELERATION, getAcceleration()); APPEND_ENTITY_PROPERTY(PROP_DIMENSIONS, getDimensions()); // NOTE: PROP_RADIUS obsolete @@ -1054,7 +1054,7 @@ EntityItemProperties EntityItem::getProperties(EntityPropertyFlags desiredProper COPY_ENTITY_PROPERTY_TO_PROPERTIES(dimensions, getDimensions); // NOTE: radius is obsolete COPY_ENTITY_PROPERTY_TO_PROPERTIES(rotation, getLocalOrientation); COPY_ENTITY_PROPERTY_TO_PROPERTIES(density, getDensity); - COPY_ENTITY_PROPERTY_TO_PROPERTIES(velocity, getVelocity); + COPY_ENTITY_PROPERTY_TO_PROPERTIES(velocity, getLocalVelocity); COPY_ENTITY_PROPERTY_TO_PROPERTIES(gravity, getGravity); COPY_ENTITY_PROPERTY_TO_PROPERTIES(acceleration, getAcceleration); COPY_ENTITY_PROPERTY_TO_PROPERTIES(damping, getDamping); @@ -1066,7 +1066,7 @@ EntityItemProperties EntityItem::getProperties(EntityPropertyFlags desiredProper COPY_ENTITY_PROPERTY_TO_PROPERTIES(scriptTimestamp, getScriptTimestamp); COPY_ENTITY_PROPERTY_TO_PROPERTIES(collisionSoundURL, getCollisionSoundURL); COPY_ENTITY_PROPERTY_TO_PROPERTIES(registrationPoint, getRegistrationPoint); - COPY_ENTITY_PROPERTY_TO_PROPERTIES(angularVelocity, getAngularVelocity); + COPY_ENTITY_PROPERTY_TO_PROPERTIES(angularVelocity, getLocalAngularVelocity); COPY_ENTITY_PROPERTY_TO_PROPERTIES(angularDamping, getAngularDamping); COPY_ENTITY_PROPERTY_TO_PROPERTIES(glowLevel, getGlowLevel); COPY_ENTITY_PROPERTY_TO_PROPERTIES(localRenderAlpha, getLocalRenderAlpha); diff --git a/libraries/entities/src/EntityScriptingInterface.cpp b/libraries/entities/src/EntityScriptingInterface.cpp index 802b21a23b..f3a25b2c9c 100644 --- a/libraries/entities/src/EntityScriptingInterface.cpp +++ b/libraries/entities/src/EntityScriptingInterface.cpp @@ -81,6 +81,8 @@ EntityItemProperties convertLocationToScriptSemantics(const EntityItemProperties entitySideProperties.getParentID(), entitySideProperties.getParentJointIndex(), success); + // TODO -- handle velocity and angularVelocity + scriptSideProperties.setPosition(worldPosition); scriptSideProperties.setRotation(worldRotation); @@ -94,6 +96,8 @@ EntityItemProperties convertLocationFromScriptSemantics(const EntityItemProperti EntityItemProperties entitySideProperties = scriptSideProperties; bool success; + // TODO -- handle velocity and angularVelocity + if (scriptSideProperties.localPositionChanged()) { entitySideProperties.setPosition(scriptSideProperties.getLocalPosition()); } else if (scriptSideProperties.positionChanged()) { @@ -128,14 +132,14 @@ QUuid EntityScriptingInterface::addEntity(const EntityItemProperties& properties auto newVelocity = propertiesWithSimID.getVelocity().length(); float cost = calculateCost(density * volume, 0, newVelocity); cost *= costMultiplier; - + if(cost > _currentAvatarEnergy) { return QUuid(); } else { //debit the avatar energy and continue emit debitEnergySource(cost); } - + EntityItemID id = EntityItemID(QUuid::createUuid()); // If we have a local entity tree set, then also update it.