From e8f4783beadc8f158dad398e819d6cc1b392e259 Mon Sep 17 00:00:00 2001
From: Philip Rosedale <philip@highfidelity.io>
Date: Mon, 26 Jan 2015 22:06:59 -0800
Subject: [PATCH] border, new size for blocks, smoother hydra grab action

---
 examples/blocks.js                      | 14 +++++++++-----
 examples/controllers/hydra/hydraGrab.js | 23 +++++++----------------
 2 files changed, 16 insertions(+), 21 deletions(-)

diff --git a/examples/blocks.js b/examples/blocks.js
index 69d4dbc4d4..30c2126096 100644
--- a/examples/blocks.js
+++ b/examples/blocks.js
@@ -9,11 +9,14 @@
 //  Distributed under the Apache License, Version 2.0.
 //  See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
 //
-var FLOOR_SIZE = 5.0;
+var FLOOR_SIZE = 7.5;
 var FLOOR_THICKNESS = 0.10;
 var EDGE_THICKESS = 0.25;
 var SCALE = 0.25; 
 
+var NUM_BLOCKS = 25; 
+var DROP_HEIGHT = SCALE * 8.0;
+
 var GRAVITY = -1.0;
 var LIFETIME = 6000;    
 var DAMPING = 0.50;
@@ -23,7 +26,7 @@ blockTypes.push({ x: 1, y: 1, z: 1, red: 255, green: 0, blue: 0 });
 blockTypes.push({ x: 1, y: 1, z: 2, red: 0, green: 255, blue: 0 });
 blockTypes.push({ x: 1, y: 2, z: 5, red: 0, green: 0, blue: 255 });
 blockTypes.push({ x: 1, y: 2, z: 2, red: 255, green: 255, blue: 0 });
-
+blockTypes.push({ x: 1, y: 1, z: 5, red: 0, green: 255, blue: 255 });
 
 var center = Vec3.sum(MyAvatar.position, Vec3.multiply(FLOOR_SIZE * 2.0, Quat.getFront(Camera.getOrientation())));
 
@@ -45,6 +48,7 @@ var edge1 = Entities.addEntity(
 	      	gravity: {  x: 0, y: 0, z: 0 },
 	        ignoreCollisions: false,
 	        visible: true,
+	        locked: true,
 	        lifetime: LIFETIME });
 
 var edge2 = Entities.addEntity(
@@ -55,6 +59,7 @@ var edge2 = Entities.addEntity(
 	      	gravity: {  x: 0, y: 0, z: 0 },
 	        ignoreCollisions: false,
 	        visible: true,
+	        locked: true,
 	        lifetime: LIFETIME });
 
 var edge3 = Entities.addEntity(
@@ -65,6 +70,7 @@ var edge3 = Entities.addEntity(
 	      	gravity: {  x: 0, y: 0, z: 0 },
 	        ignoreCollisions: false,
 	        visible: true,
+	        locked: true,
 	        lifetime: LIFETIME });
 
 var edge4 = Entities.addEntity(
@@ -75,11 +81,9 @@ var edge4 = Entities.addEntity(
 	      	gravity: {  x: 0, y: 0, z: 0 },
 	        ignoreCollisions: false,
 	        visible: true,
+	        locked: true,
 	        lifetime: LIFETIME });
 
-var NUM_BLOCKS = 20; 
-var DROP_HEIGHT = FLOOR_SIZE / 3;
-
 blocks = [];
 
 for (var i = 0; i < NUM_BLOCKS; i++) {
diff --git a/examples/controllers/hydra/hydraGrab.js b/examples/controllers/hydra/hydraGrab.js
index 5ba8613ad9..dc8cd14eaa 100644
--- a/examples/controllers/hydra/hydraGrab.js
+++ b/examples/controllers/hydra/hydraGrab.js
@@ -363,25 +363,16 @@ function controller(wichSide) {
             }
             var newPosition;
             var newRotation;
-  
-            var forward = Vec3.multiplyQbyV(MyAvatar.orientation, { x: 0, y: 0, z: -1 });
-            var d = Vec3.dot(forward, MyAvatar.position);
 
-            var factor1 = Vec3.dot(forward, this.positionAtGrab) - d;
-            var factor2 = Vec3.dot(forward, this.modelPositionAtGrab) - d;
-            var vector = Vec3.subtract(this.palmPosition, this.positionAtGrab);
-
-            if (factor2 < 0) {
-                factor2 = 0;
-            }
-            if (factor1 <= 0) {
-                factor1 = 1;
-                factor2 = 1;
+            var CONSTANT_SCALING_FACTOR = 5.0;
+            var MINIMUM_SCALING_DISTANCE = 2.0;
+            var distanceToModel = Vec3.length(Vec3.subtract(this.oldModelPosition, this.palmPosition));
+            if (distanceToModel < MINIMUM_SCALING_DISTANCE) {
+                distanceToModel = MINIMUM_SCALING_DISTANCE;
             }
 
-            newPosition = Vec3.sum(this.modelPositionAtGrab,
-                                   Vec3.multiply(vector,
-                                                 factor2 / factor1));
+            var deltaPalm = Vec3.multiply(distanceToModel * CONSTANT_SCALING_FACTOR, Vec3.subtract(this.palmPosition, this.oldPalmPosition));
+            newPosition = Vec3.sum(this.oldModelPosition, deltaPalm);
 
             newRotation = Quat.multiply(this.rotation,
                                         Quat.inverse(this.rotationAtGrab));