From a80e77ff80602161ac937fe8818fcb98a5fd6659 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Tue, 5 Jan 2016 11:01:00 -0800 Subject: [PATCH 01/13] Squeezing bumper while distance grabbing now brings object to your hand --- examples/controllers/handControllerGrab.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/examples/controllers/handControllerGrab.js b/examples/controllers/handControllerGrab.js index bb1dc2d7aa..6a3475f1a3 100644 --- a/examples/controllers/handControllerGrab.js +++ b/examples/controllers/handControllerGrab.js @@ -1119,12 +1119,15 @@ function MyController(hand) { var grabbedProperties = Entities.getEntityProperties(this.grabbedEntity, GRABBABLE_PROPERTIES); var grabbableData = getEntityCustomData(GRABBABLE_DATA_KEY, this.grabbedEntity, DEFAULT_GRABBABLE_DATA); - if (this.state == STATE_CONTINUE_DISTANCE_HOLDING && this.bumperSqueezed() && - typeof grabbableData.spatialKey !== 'undefined') { + if (this.state == STATE_CONTINUE_DISTANCE_HOLDING && this.bumperSqueezed()) { var saveGrabbedID = this.grabbedEntity; this.release(); this.setState(STATE_EQUIP); this.grabbedEntity = saveGrabbedID; + + if (typeof grabbableData.spatialKey === 'undefined') { + Entities.editEntity(this.grabbedEntity, {position: handPosition}); + } return; } From 882ec9fe80e6efa09e6c9adc107e21d293382076 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Tue, 5 Jan 2016 16:24:15 -0800 Subject: [PATCH 02/13] Using offset from intersection point to center of object for insta-grab --- examples/controllers/handControllerGrab.js | 226 ++++++++++++--------- 1 file changed, 125 insertions(+), 101 deletions(-) diff --git a/examples/controllers/handControllerGrab.js b/examples/controllers/handControllerGrab.js index 6a3475f1a3..14bb17fcac 100644 --- a/examples/controllers/handControllerGrab.js +++ b/examples/controllers/handControllerGrab.js @@ -40,6 +40,7 @@ var DISTANCE_HOLDING_RADIUS_FACTOR = 3.5; // multiplied by distance between hand var DISTANCE_HOLDING_ACTION_TIMEFRAME = 0.1; // how quickly objects move to their new position var DISTANCE_HOLDING_ROTATION_EXAGGERATION_FACTOR = 2.0; // object rotates this much more than hand did var MOVE_WITH_HEAD = true; // experimental head-controll of distantly held objects +FAR_TO_NEAR_GRAB_OFFSET_PADDING_FACTOR = 1.5; var NO_INTERSECT_COLOR = { red: 10, @@ -579,9 +580,9 @@ function MyController(hand) { }; - this.renewParticleBeamLifetime = function(){ - var props = Entities.getEntityProperties(this.particleBeam,"age"); - Entities.editEntity(this.particleBeam,{ + this.renewParticleBeamLifetime = function() { + var props = Entities.getEntityProperties(this.particleBeam, "age"); + Entities.editEntity(this.particleBeam, { lifetime: TEMPORARY_PARTICLE_BEAM_LIFETIME + props.age // renew lifetime }) } @@ -853,11 +854,12 @@ function MyController(hand) { // the ray is intersecting something we can move. this.intersectionDistance = Vec3.distance(pickRay.origin, intersection.intersection); - + this.intersectionPoint = intersection.intersection; var grabbableData = getEntityCustomData(GRABBABLE_DATA_KEY, intersection.entityID, DEFAULT_GRABBABLE_DATA); var defaultDisableNearGrabData = { disableNearGrab: false }; + //sometimes we want things to stay right where they are when we let go. var disableNearGrabData = getEntityCustomData('handControllerKey', intersection.entityID, defaultDisableNearGrabData); @@ -911,6 +913,11 @@ function MyController(hand) { this.setState(STATE_EQUIP); return; } else if ((this.state == STATE_SEARCHING) && this.triggerSmoothedGrab()) { + if (!grabbableData.spatialKey) { + var position = Entities.getEntityProperties(this.grabbedEntity, "position").position; + this.temporaryPositionOffset = Vec3.subtract(position, this.intersectionPoint); + this.temporaryPositionOffset = Vec3.multiply(this.temporaryPositionOffset, FAR_TO_NEAR_GRAB_OFFSET_PADDING_FACTOR); + } this.setState(STATE_DISTANCE_HOLDING); return; } @@ -1124,10 +1131,6 @@ function MyController(hand) { this.release(); this.setState(STATE_EQUIP); this.grabbedEntity = saveGrabbedID; - - if (typeof grabbableData.spatialKey === 'undefined') { - Entities.editEntity(this.grabbedEntity, {position: handPosition}); - } return; } @@ -1260,131 +1263,143 @@ function MyController(hand) { this.handleSpotlight(this.grabbedEntity); } - Entities.updateAction(this.grabbedEntity, this.actionID, { + var success = Entities.updateAction(this.grabbedEntity, this.actionID, { targetPosition: targetPosition, linearTimeScale: DISTANCE_HOLDING_ACTION_TIMEFRAME, targetRotation: this.currentObjectRotation, angularTimeScale: DISTANCE_HOLDING_ACTION_TIMEFRAME, ttl: ACTION_TTL }); + if (success) { + this.actionTimeout = now + (ACTION_TTL * MSEC_PER_SEC); + } else { + print("continueDistanceHolding -- updateAction failed"); + } + }; + + this.setupHoldAction = function() { + this.actionID = Entities.addAction("hold", this.grabbedEntity, { + hand: this.hand === RIGHT_HAND ? "right" : "left", + timeScale: NEAR_GRABBING_ACTION_TIMEFRAME, + relativePosition: this.offsetPosition, + relativeRotation: this.offsetRotation, + ttl: ACTION_TTL, + kinematic: NEAR_GRABBING_KINEMATIC, + kinematicSetVelocity: true, + ignoreIK: this.ignoreIK + }); + if (this.actionID === NULL_ACTION_ID) { + this.actionID = null; + return false; + } + var now = Date.now(); this.actionTimeout = now + (ACTION_TTL * MSEC_PER_SEC); - + return true; }; this.projectVectorAlongAxis = function(position, axisStart, axisEnd) { - var aPrime = Vec3.subtract(position, axisStart); + var aPrime = Vec3.subtract(position, axisStart); - var bPrime = Vec3.subtract(axisEnd, axisStart); + var bPrime = Vec3.subtract(axisEnd, axisStart); - var bPrimeMagnitude = Vec3.length(bPrime); + var bPrimeMagnitude = Vec3.length(bPrime); - var dotProduct = Vec3.dot(aPrime, bPrime); + var dotProduct = Vec3.dot(aPrime, bPrime); - var scalar = dotProduct / bPrimeMagnitude; + var scalar = dotProduct / bPrimeMagnitude; - if (scalar < 0) { - scalar = 0; - } + if (scalar < 0) { + scalar = 0; + } - if (scalar > 1) { - scalar = 1; - } + if (scalar > 1) { + scalar = 1; + } - var projection = Vec3.sum(axisStart, Vec3.multiply(scalar, Vec3.normalize(bPrime))); + var projection = Vec3.sum(axisStart, Vec3.multiply(scalar, Vec3.normalize(bPrime))); - return projection + return projection - }, + }; - this.nearGrabbing = function() { - var now = Date.now(); - var grabbableData = getEntityCustomData(GRABBABLE_DATA_KEY, this.grabbedEntity, DEFAULT_GRABBABLE_DATA); + this.nearGrabbing = function() { + var now = Date.now(); + var grabbableData = getEntityCustomData(GRABBABLE_DATA_KEY, this.grabbedEntity, DEFAULT_GRABBABLE_DATA); - if (this.state == STATE_NEAR_GRABBING && this.triggerSmoothedReleased()) { - this.setState(STATE_RELEASE); - Entities.callEntityMethod(this.grabbedEntity, "releaseGrab"); - return; - } + if (this.state == STATE_NEAR_GRABBING && this.triggerSmoothedReleased()) { + this.setState(STATE_RELEASE); + Entities.callEntityMethod(this.grabbedEntity, "releaseGrab"); + return; + } - this.lineOff(); - this.overlayLineOff(); + this.lineOff(); + this.overlayLineOff(); - var grabbedProperties = Entities.getEntityProperties(this.grabbedEntity, GRABBABLE_PROPERTIES); - this.activateEntity(this.grabbedEntity, grabbedProperties); - if (grabbedProperties.collisionsWillMove && NEAR_GRABBING_KINEMATIC) { - Entities.editEntity(this.grabbedEntity, { - collisionsWillMove: false - }); - } - - var handRotation = this.getHandRotation(); - var handPosition = this.getHandPosition(); - - var grabbableData = getEntityCustomData(GRABBABLE_DATA_KEY, this.grabbedEntity, DEFAULT_GRABBABLE_DATA); - - if (this.state != STATE_NEAR_GRABBING && grabbableData.spatialKey) { - // if an object is "equipped" and has a spatialKey, use it. - this.ignoreIK = grabbableData.spatialKey.ignoreIK ? grabbableData.spatialKey.ignoreIK : false; - this.offsetPosition = getSpatialOffsetPosition(this.hand, grabbableData.spatialKey); - this.offsetRotation = getSpatialOffsetRotation(this.hand, grabbableData.spatialKey); - } else { - this.ignoreIK = false; - - var objectRotation = grabbedProperties.rotation; - this.offsetRotation = Quat.multiply(Quat.inverse(handRotation), objectRotation); - - var currentObjectPosition = grabbedProperties.position; - var offset = Vec3.subtract(currentObjectPosition, handPosition); - this.offsetPosition = Vec3.multiplyQbyV(Quat.inverse(Quat.multiply(handRotation, this.offsetRotation)), offset); - } - - this.actionID = NULL_ACTION_ID; - this.actionID = Entities.addAction("hold", this.grabbedEntity, { - hand: this.hand === RIGHT_HAND ? "right" : "left", - timeScale: NEAR_GRABBING_ACTION_TIMEFRAME, - relativePosition: this.offsetPosition, - relativeRotation: this.offsetRotation, - ttl: ACTION_TTL, - kinematic: NEAR_GRABBING_KINEMATIC, - kinematicSetVelocity: true, - ignoreIK: this.ignoreIK + var grabbedProperties = Entities.getEntityProperties(this.grabbedEntity, GRABBABLE_PROPERTIES); + this.activateEntity(this.grabbedEntity, grabbedProperties); + if (grabbedProperties.collisionsWillMove && NEAR_GRABBING_KINEMATIC) { + Entities.editEntity(this.grabbedEntity, { + collisionsWillMove: false }); - if (this.actionID === NULL_ACTION_ID) { - this.actionID = null; - } else { - this.actionTimeout = now + (ACTION_TTL * MSEC_PER_SEC); - if (this.state == STATE_NEAR_GRABBING) { - this.setState(STATE_CONTINUE_NEAR_GRABBING); - } else { - // equipping - Entities.callEntityMethod(this.grabbedEntity, "startEquip", [JSON.stringify(this.hand)]); - this.startHandGrasp(); + } - this.setState(STATE_CONTINUE_EQUIP_BD); - } + var handRotation = this.getHandRotation(); + var handPosition = this.getHandPosition(); - if (this.hand === RIGHT_HAND) { - Entities.callEntityMethod(this.grabbedEntity, "setRightHand"); - } else { - Entities.callEntityMethod(this.grabbedEntity, "setLeftHand"); - } + var grabbableData = getEntityCustomData(GRABBABLE_DATA_KEY, this.grabbedEntity, DEFAULT_GRABBABLE_DATA); - Entities.callEntityMethod(this.grabbedEntity, "setHand", [this.hand]); + if (this.state != STATE_NEAR_GRABBING && grabbableData.spatialKey) { + // if an object is "equipped" and has a spatialKey, use it. + this.ignoreIK = grabbableData.spatialKey.ignoreIK ? grabbableData.spatialKey.ignoreIK : false; + this.offsetPosition = getSpatialOffsetPosition(this.hand, grabbableData.spatialKey); + this.offsetRotation = getSpatialOffsetRotation(this.hand, grabbableData.spatialKey); + } else { + this.ignoreIK = false; - Entities.callEntityMethod(this.grabbedEntity, "startNearGrab"); + var objectRotation = grabbedProperties.rotation; + this.offsetRotation = Quat.multiply(Quat.inverse(handRotation), objectRotation); + var currentObjectPosition = grabbedProperties.position; + var offset = Vec3.subtract(currentObjectPosition, handPosition); + this.offsetPosition = Vec3.multiplyQbyV(Quat.inverse(Quat.multiply(handRotation, this.offsetRotation)), offset); + if (this.state != STATE_NEAR_GRABBING) { + this.offsetPosition = this.temporaryPositionOffset; } + } - this.currentHandControllerTipPosition = - (this.hand === RIGHT_HAND) ? MyAvatar.rightHandTipPosition : MyAvatar.leftHandTipPosition; + if (!this.setupHoldAction()) { + return; + } - this.currentObjectTime = Date.now(); - }; + if (this.state == STATE_NEAR_GRABBING) { + this.setState(STATE_CONTINUE_NEAR_GRABBING); + } else { + // equipping + Entities.callEntityMethod(this.grabbedEntity, "startEquip", [JSON.stringify(this.hand)]); + this.startHandGrasp(); + + this.setState(STATE_CONTINUE_EQUIP_BD); + } + + if (this.hand === RIGHT_HAND) { + Entities.callEntityMethod(this.grabbedEntity, "setRightHand"); + } else { + Entities.callEntityMethod(this.grabbedEntity, "setLeftHand"); + } + + Entities.callEntityMethod(this.grabbedEntity, "setHand", [this.hand]); + Entities.callEntityMethod(this.grabbedEntity, "startNearGrab"); + + this.currentHandControllerTipPosition = + (this.hand === RIGHT_HAND) ? MyAvatar.rightHandTipPosition : MyAvatar.leftHandTipPosition; + + this.currentObjectTime = Date.now(); + }; this.continueNearGrabbing = function() { if (this.state == STATE_CONTINUE_NEAR_GRABBING && this.triggerSmoothedReleased()) { @@ -1429,7 +1444,7 @@ function MyController(hand) { if (this.actionTimeout - now < ACTION_TTL_REFRESH * MSEC_PER_SEC) { // if less than a 5 seconds left, refresh the actions ttl - Entities.updateAction(this.grabbedEntity, this.actionID, { + var success = Entities.updateAction(this.grabbedEntity, this.actionID, { hand: this.hand === RIGHT_HAND ? "right" : "left", timeScale: NEAR_GRABBING_ACTION_TIMEFRAME, relativePosition: this.offsetPosition, @@ -1439,7 +1454,13 @@ function MyController(hand) { kinematicSetVelocity: true, ignoreIK: this.ignoreIK }); - this.actionTimeout = now + (ACTION_TTL * MSEC_PER_SEC); + if (success) { + this.actionTimeout = now + (ACTION_TTL * MSEC_PER_SEC); + } else { + print("continueNearGrabbing -- updateAction failed"); + Entities.deleteAction(this.grabbedEntity, this.actionID); + this.setupHoldAction(); + } } }; @@ -1486,7 +1507,7 @@ function MyController(hand) { return; } } else { - Entities.updateAction(this.grabbedEntity, this.equipSpringID, { + var success = Entities.updateAction(this.grabbedEntity, this.equipSpringID, { targetPosition: targetPosition, linearTimeScale: EQUIP_SPRING_TIMEFRAME, targetRotation: targetRotation, @@ -1494,6 +1515,9 @@ function MyController(hand) { ttl: ACTION_TTL, ignoreIK: ignoreIK }); + if (!success) { + print("pullTowardEquipPosition -- updateActionfailed"); + } } if (Vec3.distance(grabbedProperties.position, targetPosition) < EQUIP_SPRING_SHUTOFF_DISTANCE) { @@ -1883,8 +1907,8 @@ Script.update.connect(update); // we can't create the search system on-demand since it takes some time for the particles to reach their entire length. // thus the system cannot have a fixed lifetime. this loop updates the lifetimes and will stop updating if a user crashes. -if(USE_PARTICLE_BEAM_FOR_SEARCHING===true || USE_PARTICLE_BEAM_FOR_MOVING ===true){ -Script.update.connect(renewParticleBeamLifetimes) +if (USE_PARTICLE_BEAM_FOR_SEARCHING === true || USE_PARTICLE_BEAM_FOR_MOVING === true) { + Script.update.connect(renewParticleBeamLifetimes) } var sinceLastParticleLifetimeUpdate = 0; From 8c7c436ef20ac48aa28b8afc40d393b18125c6de Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Tue, 5 Jan 2016 16:54:18 -0800 Subject: [PATCH 03/13] fix --- examples/grab.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/examples/grab.js b/examples/grab.js index 1637e1bcf2..cb0723b8eb 100644 --- a/examples/grab.js +++ b/examples/grab.js @@ -309,7 +309,7 @@ Grabber.prototype.computeNewGrabPlane = function() { } Grabber.prototype.pressEvent = function(event) { - if (!event.isLeftButton) { + if (event.isLeftButton!==true ||event.isRightButton===true || event.isMiddleButton===true) { return; } @@ -374,7 +374,11 @@ Grabber.prototype.pressEvent = function(event) { //Audio.playSound(grabSound, { position: entityProperties.position, volume: VOLUME }); } -Grabber.prototype.releaseEvent = function() { +Grabber.prototype.releaseEvent = function(event) { + if (event.isLeftButton!==true ||event.isRightButton===true || event.isMiddleButton===true) { + return; + } + if (this.isGrabbing) { this.deactivateEntity(this.entityID); this.isGrabbing = false From 2435e160a8f255b3687cb83d29da247270d9096b Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Tue, 5 Jan 2016 16:56:24 -0800 Subject: [PATCH 04/13] only emit collision events if you're the owner --- .../src/EntityTreeRenderer.cpp | 39 ++++++++++++++----- .../src/EntityTreeRenderer.h | 3 ++ 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/libraries/entities-renderer/src/EntityTreeRenderer.cpp b/libraries/entities-renderer/src/EntityTreeRenderer.cpp index 0bb0de1ce0..07d9031f41 100644 --- a/libraries/entities-renderer/src/EntityTreeRenderer.cpp +++ b/libraries/entities-renderer/src/EntityTreeRenderer.cpp @@ -717,11 +717,11 @@ void EntityTreeRenderer::checkAndCallPreload(const EntityItemID& entityID, const } } -void EntityTreeRenderer::playEntityCollisionSound(const QUuid& myNodeID, EntityTreePointer entityTree, - const EntityItemID& id, const Collision& collision) { +bool EntityTreeRenderer::isCollisionOwner(const QUuid& myNodeID, EntityTreePointer entityTree, + const EntityItemID& id, const Collision& collision) { EntityItemPointer entity = entityTree->findEntityByEntityItemID(id); if (!entity) { - return; + return false; } QUuid simulatorID = entity->getSimulatorID(); if (simulatorID.isNull()) { @@ -730,14 +730,30 @@ void EntityTreeRenderer::playEntityCollisionSound(const QUuid& myNodeID, EntityT const EntityItemID& otherID = (id == collision.idA) ? collision.idB : collision.idA; EntityItemPointer otherEntity = entityTree->findEntityByEntityItemID(otherID); if (!otherEntity) { - return; + return false; } simulatorID = otherEntity->getSimulatorID(); } if (simulatorID.isNull() || (simulatorID != myNodeID)) { - return; // Only one injector per simulation, please. + return false; } + + return true; +} + +void EntityTreeRenderer::playEntityCollisionSound(const QUuid& myNodeID, EntityTreePointer entityTree, + const EntityItemID& id, const Collision& collision) { + + if (!isCollisionOwner(myNodeID, entityTree, id, collision)) { + return; + } + + EntityItemPointer entity = entityTree->findEntityByEntityItemID(id); + if (!entity) { + return; + } + const QString& collisionSoundURL = entity->getCollisionSoundURL(); if (collisionSoundURL.isEmpty()) { return; @@ -796,10 +812,15 @@ void EntityTreeRenderer::entityCollisionWithEntity(const EntityItemID& idA, cons playEntityCollisionSound(myNodeID, entityTree, idB, collision); // And now the entity scripts - emit collisionWithEntity(idA, idB, collision); - _entitiesScriptEngine->callEntityScriptMethod(idA, "collisionWithEntity", idB, collision); - emit collisionWithEntity(idB, idA, collision); - _entitiesScriptEngine->callEntityScriptMethod(idB, "collisionWithEntity", idA, collision); + if (isCollisionOwner(myNodeID, entityTree, idA, collision)) { + emit collisionWithEntity(idA, idB, collision); + _entitiesScriptEngine->callEntityScriptMethod(idA, "collisionWithEntity", idB, collision); + } + + if (isCollisionOwner(myNodeID, entityTree, idA, collision)) { + emit collisionWithEntity(idB, idA, collision); + _entitiesScriptEngine->callEntityScriptMethod(idB, "collisionWithEntity", idA, collision); + } } void EntityTreeRenderer::updateEntityRenderStatus(bool shouldRenderEntities) { diff --git a/libraries/entities-renderer/src/EntityTreeRenderer.h b/libraries/entities-renderer/src/EntityTreeRenderer.h index 2c205336c0..e2cd4fc2dd 100644 --- a/libraries/entities-renderer/src/EntityTreeRenderer.h +++ b/libraries/entities-renderer/src/EntityTreeRenderer.h @@ -148,6 +148,9 @@ private: bool _wantScripts; ScriptEngine* _entitiesScriptEngine; + bool isCollisionOwner(const QUuid& myNodeID, EntityTreePointer entityTree, + const EntityItemID& id, const Collision& collision); + void playEntityCollisionSound(const QUuid& myNodeID, EntityTreePointer entityTree, const EntityItemID& id, const Collision& collision); From 096ab44311c04f10217f8d8d4b5623d5e17e64ef Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Wed, 6 Jan 2016 11:01:31 -0800 Subject: [PATCH 05/13] fix network version number --- libraries/networking/src/udt/PacketHeaders.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/networking/src/udt/PacketHeaders.cpp b/libraries/networking/src/udt/PacketHeaders.cpp index f7b60c347c..43f4b5dcc9 100644 --- a/libraries/networking/src/udt/PacketHeaders.cpp +++ b/libraries/networking/src/udt/PacketHeaders.cpp @@ -41,7 +41,7 @@ PacketVersion versionForPacketType(PacketType packetType) { case PacketType::EntityAdd: case PacketType::EntityEdit: case PacketType::EntityData: - return VERSION_MODEL_ENTITIES_JOINTS_ON_WIRE; + return VERSION_ENTITITES_HAVE_QUERY_BOX; case PacketType::AvatarData: case PacketType::BulkAvatarData: return static_cast(AvatarMixerPacketVersion::SoftAttachmentSupport); From b8b113844f33b2b162395687b2c576e0abac0e21 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Wed, 6 Jan 2016 11:22:58 -0800 Subject: [PATCH 06/13] reduced avatar max fly speed from 300 to 30 --- interface/src/avatar/MyAvatar.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 60e35b4b52..98b09d6c59 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -64,7 +64,7 @@ const float MIN_AVATAR_SPEED = 0.05f; // speed is set to zero below this // TODO: normalize avatar speed for standard avatar size, then scale all motion logic // to properly follow avatar size. -float MAX_AVATAR_SPEED = 300.0f; +float MAX_AVATAR_SPEED = 30.0f; float MAX_KEYBOARD_MOTOR_SPEED = MAX_AVATAR_SPEED; float DEFAULT_KEYBOARD_MOTOR_TIMESCALE = 0.25f; float MIN_SCRIPTED_MOTOR_TIMESCALE = 0.005f; From edc132efcee885233409567dd9a3c3bfb6e8b4d3 Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Wed, 6 Jan 2016 12:53:57 -0800 Subject: [PATCH 07/13] fix warning --- libraries/octree/src/OctreePacketData.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/octree/src/OctreePacketData.cpp b/libraries/octree/src/OctreePacketData.cpp index a7f142defe..5380aaa6ce 100644 --- a/libraries/octree/src/OctreePacketData.cpp +++ b/libraries/octree/src/OctreePacketData.cpp @@ -699,7 +699,7 @@ int OctreePacketData::unpackDataFromBytes(const unsigned char *dataBytes, QVecto dataBytes += unpackOrientationQuatFromBytes(dataBytes, result[i]); } - return (dataBytes - start) + sizeof(uint16_t); + return (dataBytes - start) + (int)sizeof(uint16_t); } int OctreePacketData::unpackDataFromBytes(const unsigned char* dataBytes, QVector& result) { @@ -728,7 +728,7 @@ int OctreePacketData::unpackDataFromBytes(const unsigned char* dataBytes, QVecto bit = (bit + 1) % BITS_IN_BYTE; } - return (dataBytes - start) + sizeof(uint16_t); + return (dataBytes - start) + (int)sizeof(uint16_t); } int OctreePacketData::unpackDataFromBytes(const unsigned char* dataBytes, QByteArray& result) { From a5f618ef3356f996d4710747998b765ab01bd437 Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Wed, 6 Jan 2016 12:54:14 -0800 Subject: [PATCH 08/13] include debug log in collision example --- examples/entityScripts/changeColorOnCollision.js | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/entityScripts/changeColorOnCollision.js b/examples/entityScripts/changeColorOnCollision.js index 69a14f4b52..59a8bd9700 100644 --- a/examples/entityScripts/changeColorOnCollision.js +++ b/examples/entityScripts/changeColorOnCollision.js @@ -16,5 +16,6 @@ this.collisionWithEntity = function(myID, otherID, collisionInfo) { Entities.editEntity(myID, { color: { red: getRandomInt(128,255), green: getRandomInt(128,255), blue: getRandomInt(128,255)} }); + print("collisionWithEntity() myID:" + myID + ", otherID:" + otherID); }; }) \ No newline at end of file From d4e039ea7afb9f61391e6e0335b290b1ea554811 Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Wed, 6 Jan 2016 13:00:50 -0800 Subject: [PATCH 09/13] include debug log in collision example --- examples/entityScripts/changeColorOnCollision.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/examples/entityScripts/changeColorOnCollision.js b/examples/entityScripts/changeColorOnCollision.js index 59a8bd9700..26349a3e09 100644 --- a/examples/entityScripts/changeColorOnCollision.js +++ b/examples/entityScripts/changeColorOnCollision.js @@ -17,5 +17,11 @@ this.collisionWithEntity = function(myID, otherID, collisionInfo) { Entities.editEntity(myID, { color: { red: getRandomInt(128,255), green: getRandomInt(128,255), blue: getRandomInt(128,255)} }); print("collisionWithEntity() myID:" + myID + ", otherID:" + otherID); + print(" collisionInfo.type:" + collisionInfo.type); + print(" collisionInfo.idA:" + collisionInfo.idA); + print(" collisionInfo.idB:" + collisionInfo.idA); + Vec3.print(" collisionInfo.penetration:", collisionInfo.penetration); + Vec3.print(" collisionInfo.contactPoint:", collisionInfo.contactPoint); + Vec3.print(" collisionInfo.velocityChange:", collisionInfo.velocityChange); }; }) \ No newline at end of file From 6ac8d081dc823328b9aa858728232466fa55eba6 Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Wed, 6 Jan 2016 13:02:07 -0800 Subject: [PATCH 10/13] include debug log in collision example --- examples/entityScripts/changeColorOnCollision.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/entityScripts/changeColorOnCollision.js b/examples/entityScripts/changeColorOnCollision.js index 26349a3e09..f0fff4e7a3 100644 --- a/examples/entityScripts/changeColorOnCollision.js +++ b/examples/entityScripts/changeColorOnCollision.js @@ -19,7 +19,7 @@ print("collisionWithEntity() myID:" + myID + ", otherID:" + otherID); print(" collisionInfo.type:" + collisionInfo.type); print(" collisionInfo.idA:" + collisionInfo.idA); - print(" collisionInfo.idB:" + collisionInfo.idA); + print(" collisionInfo.idB:" + collisionInfo.idB); Vec3.print(" collisionInfo.penetration:", collisionInfo.penetration); Vec3.print(" collisionInfo.contactPoint:", collisionInfo.contactPoint); Vec3.print(" collisionInfo.velocityChange:", collisionInfo.velocityChange); From cb03eda6d1309c416168784734132ce222adec1b Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Wed, 6 Jan 2016 13:37:26 -0800 Subject: [PATCH 11/13] Instant far to near grabbing now works by using the bumper, or equip, button --- examples/controllers/handControllerGrab.js | 26 ++++++++++++---------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/examples/controllers/handControllerGrab.js b/examples/controllers/handControllerGrab.js index 16b91c8369..148d6a7a4a 100644 --- a/examples/controllers/handControllerGrab.js +++ b/examples/controllers/handControllerGrab.js @@ -40,7 +40,7 @@ var DISTANCE_HOLDING_RADIUS_FACTOR = 3.5; // multiplied by distance between hand var DISTANCE_HOLDING_ACTION_TIMEFRAME = 0.1; // how quickly objects move to their new position var DISTANCE_HOLDING_ROTATION_EXAGGERATION_FACTOR = 2.0; // object rotates this much more than hand did var MOVE_WITH_HEAD = true; // experimental head-controll of distantly held objects -FAR_TO_NEAR_GRAB_OFFSET_PADDING_FACTOR = 1.5; +var FAR_TO_NEAR_GRAB_PADDING_FACTOR = 1.2; var NO_INTERSECT_COLOR = { red: 10, @@ -854,12 +854,11 @@ function MyController(hand) { // the ray is intersecting something we can move. this.intersectionDistance = Vec3.distance(pickRay.origin, intersection.intersection); - this.intersectionPoint = intersection.intersection; + var grabbableData = getEntityCustomData(GRABBABLE_DATA_KEY, intersection.entityID, DEFAULT_GRABBABLE_DATA); var defaultDisableNearGrabData = { disableNearGrab: false }; - //sometimes we want things to stay right where they are when we let go. var disableNearGrabData = getEntityCustomData('handControllerKey', intersection.entityID, defaultDisableNearGrabData); @@ -906,18 +905,20 @@ function MyController(hand) { if (intersection.properties.collisionsWillMove && !intersection.properties.locked) { // the hand is far from the intersected object. go into distance-holding mode this.grabbedEntity = intersection.entityID; - if (typeof grabbableData.spatialKey !== 'undefined' && this.state == STATE_EQUIP_SEARCHING) { + if (this.state == STATE_EQUIP_SEARCHING) { // if a distance pick in equip mode hits something with a spatialKey, equip it // TODO use STATE_EQUIP_SPRING here once it works right. // this.setState(STATE_EQUIP_SPRING); + if (typeof grabbableData.spatialKey === 'undefined') { + // We want to give a temporary position offset to this object so it is pulled close to hand + var intersectionPointToCenterDistance = Vec3.length(Vec3.subtract(intersection.intersection, intersection.properties.position)); + this.temporaryPositionOffset = Vec3.normalize(Vec3.subtract(intersection.properties.position, handPosition)); + this.temporaryPositionOffset = Vec3.multiply(this.temporaryPositionOffset, intersectionPointToCenterDistance * FAR_TO_NEAR_GRAB_PADDING_FACTOR); + + } this.setState(STATE_EQUIP); return; } else if ((this.state == STATE_SEARCHING) && this.triggerSmoothedGrab()) { - if (!grabbableData.spatialKey) { - var position = Entities.getEntityProperties(this.grabbedEntity, "position").position; - this.temporaryPositionOffset = Vec3.subtract(position, this.intersectionPoint); - this.temporaryPositionOffset = Vec3.multiply(this.temporaryPositionOffset, FAR_TO_NEAR_GRAB_OFFSET_PADDING_FACTOR); - } this.setState(STATE_DISTANCE_HOLDING); return; } @@ -1126,7 +1127,8 @@ function MyController(hand) { var grabbedProperties = Entities.getEntityProperties(this.grabbedEntity, GRABBABLE_PROPERTIES); var grabbableData = getEntityCustomData(GRABBABLE_DATA_KEY, this.grabbedEntity, DEFAULT_GRABBABLE_DATA); - if (this.state == STATE_CONTINUE_DISTANCE_HOLDING && this.bumperSqueezed()) { + if (this.state == STATE_CONTINUE_DISTANCE_HOLDING && this.bumperSqueezed() && + typeof grabbableData.spatialKey !== 'undefined') { var saveGrabbedID = this.grabbedEntity; this.release(); this.setState(STATE_EQUIP); @@ -1367,12 +1369,12 @@ function MyController(hand) { var currentObjectPosition = grabbedProperties.position; var offset = Vec3.subtract(currentObjectPosition, handPosition); this.offsetPosition = Vec3.multiplyQbyV(Quat.inverse(Quat.multiply(handRotation, this.offsetRotation)), offset); - if (this.state != STATE_NEAR_GRABBING) { + if (this.temporaryPositionOffset) { this.offsetPosition = this.temporaryPositionOffset; } } - + if (!this.setupHoldAction()) { return; } From 67f4c250fdd7e4e04012596bcab871926d44db48 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Wed, 6 Jan 2016 14:59:31 -0800 Subject: [PATCH 12/13] Search sphere goes away on far to near grab --- examples/controllers/handControllerGrab.js | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/controllers/handControllerGrab.js b/examples/controllers/handControllerGrab.js index 148d6a7a4a..7700001cc5 100644 --- a/examples/controllers/handControllerGrab.js +++ b/examples/controllers/handControllerGrab.js @@ -917,6 +917,7 @@ function MyController(hand) { } this.setState(STATE_EQUIP); + this.turnOffVisualizations(); return; } else if ((this.state == STATE_SEARCHING) && this.triggerSmoothedGrab()) { this.setState(STATE_DISTANCE_HOLDING); From 1f6e45d135effafe574782812beb0d122338bb45 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Wed, 6 Jan 2016 15:10:53 -0800 Subject: [PATCH 13/13] Fix for close grab jumping --- examples/controllers/handControllerGrab.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/controllers/handControllerGrab.js b/examples/controllers/handControllerGrab.js index 7700001cc5..bab356ee2c 100644 --- a/examples/controllers/handControllerGrab.js +++ b/examples/controllers/handControllerGrab.js @@ -1370,7 +1370,7 @@ function MyController(hand) { var currentObjectPosition = grabbedProperties.position; var offset = Vec3.subtract(currentObjectPosition, handPosition); this.offsetPosition = Vec3.multiplyQbyV(Quat.inverse(Quat.multiply(handRotation, this.offsetRotation)), offset); - if (this.temporaryPositionOffset) { + if (this.temporaryPositionOffset && this.state != STATE_NEAR_GRABBING) { this.offsetPosition = this.temporaryPositionOffset; } }