From 394985ef4538b8c3c3f968cb4bc66cde02035eea Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Wed, 14 May 2014 11:52:01 -0700 Subject: [PATCH 1/5] Switched to Halo gun in gun.js, work in progress on hydraMove to add flying --- examples/gun.js | 5 +-- examples/hydraMove.js | 98 ++++++++++++++++++++++++------------------- 2 files changed, 56 insertions(+), 47 deletions(-) diff --git a/examples/gun.js b/examples/gun.js index e404ae1d4d..a5c0ee83e0 100644 --- a/examples/gun.js +++ b/examples/gun.js @@ -39,7 +39,7 @@ var impactSound = new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-pub var targetHitSound = new Sound("http://highfidelity-public.s3-us-west-1.amazonaws.com/sounds/Space%20Invaders/hit.raw"); var targetLaunchSound = new Sound("http://highfidelity-public.s3-us-west-1.amazonaws.com/sounds/Space%20Invaders/shoot.raw"); -var gunModel = "http://highfidelity-public.s3-us-west-1.amazonaws.com/models/attachments/Raygun2.fst"; +var gunModel = "http://public.highfidelity.io/models/attachments/HaloGun.fst"; var audioOptions = new AudioInjectionOptions(); audioOptions.volume = 0.9; @@ -199,7 +199,7 @@ function playLoadSound() { Audio.playSound(loadSound, audioOptions); } -MyAvatar.attach(gunModel, "RightHand", {x: -0.02, y: -.14, z: 0.07}, Quat.fromPitchYawRollDegrees(-70, -151, 72), 0.20); +//MyAvatar.attach(gunModel, "RightHand", {x: -0.02, y: -.14, z: 0.07}, Quat.fromPitchYawRollDegrees(-70, -151, 72), 0.20); MyAvatar.attach(gunModel, "LeftHand", {x: -0.02, y: -.14, z: 0.07}, Quat.fromPitchYawRollDegrees(-70, -151, 72), 0.20); // Give a bit of time to load before playing sound @@ -320,7 +320,6 @@ function scriptEnding() { Overlays.deleteOverlay(reticle); Overlays.deleteOverlay(text); MyAvatar.detachOne(gunModel); - MyAvatar.detachOne(gunModel); } Particles.particleCollisionWithVoxel.connect(particleCollisionWithVoxel); diff --git a/examples/hydraMove.js b/examples/hydraMove.js index ad0eeddfca..638e5fe226 100644 --- a/examples/hydraMove.js +++ b/examples/hydraMove.js @@ -50,6 +50,13 @@ var LEFT_BUTTON_4 = 4; var RIGHT_PALM = 2; var RIGHT_BUTTON_4 = 10; + +function printVector(text, v, decimals) { + print(text + " " + v.x.toFixed(decimals) + ", " + v.y.toFixed(decimals) + ", " + v.z.toFixed(decimals)); +} + +var debug = true; + // Used by handleGrabBehavior() for managing the grab position changes function getAndResetGrabDelta() { var HAND_GRAB_SCALE_DISTANCE = 2.0; @@ -60,24 +67,12 @@ function getAndResetGrabDelta() { return result; } -// Used by handleGrabBehavior() for managing the grab velocity feature -function getAndResetGrabDeltaVelocity() { - var HAND_GRAB_SCALE_VELOCITY = 50.0; - var delta = Vec3.multiply(grabDeltaVelocity, (MyAvatar.scale * HAND_GRAB_SCALE_VELOCITY)); - grabDeltaVelocity = { x: 0, y: 0, z: 0}; - var avatarRotation = MyAvatar.orientation; - var result = Quat.multiply(avatarRotation, Vec3.multiply(delta, -1)); - return result; -} - -// Used by handleGrabBehavior() for managing the grab rotation feature -function getAndResetGrabRotation() { +function getGrabRotation() { var quatDiff = Quat.multiply(grabCurrentRotation, Quat.inverse(grabStartRotation)); - grabStartRotation = grabCurrentRotation; return quatDiff; } -// handles all the grab related behavior: position (crawl), velocity (flick), and rotate (twist) +// When move button is pressed, process results function handleGrabBehavior(deltaTime) { // check for and handle grab behaviors grabbingWithRightHand = Controller.isButtonPressed(RIGHT_BUTTON_4); @@ -88,9 +83,12 @@ function handleGrabBehavior(deltaTime) { if (grabbingWithRightHand && !wasGrabbingWithRightHand) { // Just starting grab, capture starting rotation grabStartRotation = Controller.getSpatialControlRawRotation(RIGHT_PALM); + grabStartPosition = Controller.getSpatialControlPosition(RIGHT_PALM); + if (debug) printVector("start position", grabStartPosition, 3); } if (grabbingWithRightHand) { - grabDelta = Vec3.sum(grabDelta, Vec3.multiply(Controller.getSpatialControlVelocity(RIGHT_PALM), deltaTime)); + //grabDelta = Vec3.sum(grabDelta, Vec3.multiply(Controller.getSpatialControlVelocity(RIGHT_PALM), deltaTime)); + grabDelta = Vec3.subtract(Controller.getSpatialControlPosition(RIGHT_PALM), grabStartPosition); grabCurrentRotation = Controller.getSpatialControlRawRotation(RIGHT_PALM); } if (!grabbingWithRightHand && wasGrabbingWithRightHand) { @@ -102,10 +100,13 @@ function handleGrabBehavior(deltaTime) { if (grabbingWithLeftHand && !wasGrabbingWithLeftHand) { // Just starting grab, capture starting rotation grabStartRotation = Controller.getSpatialControlRawRotation(LEFT_PALM); + grabStartPosition = Controller.getSpatialControlPosition(LEFT_PALM); + if (debug) printVector("start position", grabStartPosition, 3); } if (grabbingWithLeftHand) { - grabDelta = Vec3.sum(grabDelta, Vec3.multiply(Controller.getSpatialControlVelocity(LEFT_PALM), deltaTime)); + //grabDelta = Vec3.sum(grabDelta, Vec3.multiply(Controller.getSpatialControlVelocity(LEFT_PALM), deltaTime)); + grabDelta = Vec3.subtract(Controller.getSpatialControlPosition(LEFT_PALM), grabStartPosition); grabCurrentRotation = Controller.getSpatialControlRawRotation(LEFT_PALM); } if (!grabbingWithLeftHand && wasGrabbingWithLeftHand) { @@ -119,44 +120,53 @@ function handleGrabBehavior(deltaTime) { if (grabbing) { - // move position - var moveFromGrab = getAndResetGrabDelta(); - if (Vec3.length(moveFromGrab) > EPSILON) { - MyAvatar.position = Vec3.sum(MyAvatar.position, moveFromGrab); - velocity = { x: 0, y: 0, z: 0}; - } - - // add some rotation... - var deltaRotation = getAndResetGrabRotation(); - var GRAB_CONTROLLER_TURN_SCALING = 0.5; - var euler = Vec3.multiply(Quat.safeEulerAngles(deltaRotation), GRAB_CONTROLLER_TURN_SCALING); + var headOrientation = MyAvatar.headOrientation; + var front = Quat.getFront(headOrientation); + var right = Quat.getRight(headOrientation); + var up = Quat.getUp(headOrientation); - // Adjust body yaw by yaw from controller - var orientation = Quat.multiply(Quat.angleAxis(-euler.y, {x:0, y: 1, z:0}), MyAvatar.orientation); + //grabDelta = Quat.multiply(headOrientation, grabDelta); + //grabDelta = Quat.multiply(Camera.getOrientation(), grabDelta); + grabDelta = Vec3.multiplyQbyV(MyAvatar.orientation, Vec3.multiply(grabDelta, -1)); + + if (debug) { + printVector("grabDelta: ", grabDelta, 3); + } + + var THRUST_GRAB_SCALING = 0.0; + + var thrustFront = Vec3.multiply(front, MyAvatar.scale * grabDelta.z * THRUST_GRAB_SCALING * deltaTime); + MyAvatar.addThrust(thrustFront); + var thrustRight = Vec3.multiply(right, MyAvatar.scale * grabDelta.x * THRUST_GRAB_SCALING * deltaTime); + MyAvatar.addThrust(thrustRight); + var thrustUp = Vec3.multiply(up, MyAvatar.scale * grabDelta.y * THRUST_GRAB_SCALING * deltaTime); + MyAvatar.addThrust(thrustUp); + + + // add some rotation... + var deltaRotation = getGrabRotation(); + var GRAB_CONTROLLER_PITCH_SCALING = 2.5; + var GRAB_CONTROLLER_YAW_SCALING = 2.5; + var GRAB_CONTROLLER_ROLL_SCALING = 2.5; + var euler = Quat.safeEulerAngles(deltaRotation); + + // Adjust body yaw by roll from controller + var orientation = Quat.multiply(Quat.angleAxis(((euler.y * GRAB_CONTROLLER_YAW_SCALING) + + (euler.z * GRAB_CONTROLLER_ROLL_SCALING)) * deltaTime, {x:0, y: 1, z:0}), MyAvatar.orientation); MyAvatar.orientation = orientation; // Adjust head pitch from controller - MyAvatar.headPitch = MyAvatar.headPitch - euler.x; + MyAvatar.headPitch = MyAvatar.headPitch + (euler.x * GRAB_CONTROLLER_PITCH_SCALING * deltaTime); + + // Add some camera roll proportional to the rate of turn (so it feels like an airplane or roller coaster) + } - // add some velocity... - if (stoppedGrabbing) { - velocity = Vec3.sum(velocity, getAndResetGrabDeltaVelocity()); - } - - // handle residual velocity - if(Vec3.length(velocity) > EPSILON) { - MyAvatar.position = Vec3.sum(MyAvatar.position, Vec3.multiply(velocity, deltaTime)); - // damp velocity - velocity = Vec3.multiply(velocity, damping); - } - - wasGrabbingWithRightHand = grabbingWithRightHand; wasGrabbingWithLeftHand = grabbingWithLeftHand; } -// Main update function that handles flying and grabbing behaviort +// Update for joysticks and move button function flyWithHydra(deltaTime) { var thrustJoystickPosition = Controller.getJoystickPosition(THRUST_CONTROLLER); From 85b94ff71cf6681a4704f85b10bdd723dfb9ec89 Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Fri, 16 May 2014 09:20:15 -0700 Subject: [PATCH 2/5] added dead zone to pitch in hydra move, animated models show up where you are --- examples/animatedModelExample.js | 10 +++++----- examples/hydraMove.js | 24 ++++++++++++++++-------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/examples/animatedModelExample.js b/examples/animatedModelExample.js index 5199eb419f..3fb4ae8bd4 100644 --- a/examples/animatedModelExample.js +++ b/examples/animatedModelExample.js @@ -21,9 +21,9 @@ var roll = 0.0; var rotation = Quat.fromPitchYawRollDegrees(pitch, yaw, roll) var originalProperties = { - position: { x: 10, - y: 0, - z: 0 }, + position: { x: MyAvatar.position.x, + y: MyAvatar.position.y, + z: MyAvatar.position.z }, radius : 1, @@ -58,9 +58,9 @@ function moveModel(deltaTime) { if (animationFPS == 30) { animationFPS = 10; } else if (animationFPS == 10) { - animationFPS = 60; + animationFPS = 10; } else if (animationFPS == 60) { - animationFPS = 30; + animationFPS = 10; } print("animationFPS=" + animationFPS); isPlaying = true; diff --git a/examples/hydraMove.js b/examples/hydraMove.js index 638e5fe226..3a11fa0b5e 100644 --- a/examples/hydraMove.js +++ b/examples/hydraMove.js @@ -145,20 +145,28 @@ function handleGrabBehavior(deltaTime) { // add some rotation... var deltaRotation = getGrabRotation(); - var GRAB_CONTROLLER_PITCH_SCALING = 2.5; - var GRAB_CONTROLLER_YAW_SCALING = 2.5; - var GRAB_CONTROLLER_ROLL_SCALING = 2.5; + var PITCH_SCALING = 2.0; + var PITCH_DEAD_ZONE = 2.0; + var YAW_SCALING = 2.0; + var ROLL_SCALING = 2.0; + var euler = Quat.safeEulerAngles(deltaRotation); + print("dx: " + euler.x); + // Adjust body yaw by roll from controller - var orientation = Quat.multiply(Quat.angleAxis(((euler.y * GRAB_CONTROLLER_YAW_SCALING) + - (euler.z * GRAB_CONTROLLER_ROLL_SCALING)) * deltaTime, {x:0, y: 1, z:0}), MyAvatar.orientation); + var orientation = Quat.multiply(Quat.angleAxis(((euler.y * YAW_SCALING) + + (euler.z * ROLL_SCALING)) * deltaTime, {x:0, y: 1, z:0}), MyAvatar.orientation); MyAvatar.orientation = orientation; // Adjust head pitch from controller - MyAvatar.headPitch = MyAvatar.headPitch + (euler.x * GRAB_CONTROLLER_PITCH_SCALING * deltaTime); - - // Add some camera roll proportional to the rate of turn (so it feels like an airplane or roller coaster) + var pitch = 0.0; + if (Math.abs(euler.x) > PITCH_DEAD_ZONE) { + pitch = (euler.x < 0.0) ? (euler.x + PITCH_DEAD_ZONE) : (euler.x - PITCH_DEAD_ZONE); + } + MyAvatar.headPitch = MyAvatar.headPitch + (pitch * PITCH_SCALING * deltaTime); + + // TODO: Add some camera roll proportional to the rate of turn (so it feels like an airplane or roller coaster) } From 25f1e180f504c87c3a1ef704d30b24f8eb82fa51 Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Fri, 16 May 2014 09:34:54 -0700 Subject: [PATCH 3/5] revert test change --- examples/animatedModelExample.js | 4 ++-- examples/bot.js | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/examples/animatedModelExample.js b/examples/animatedModelExample.js index 3fb4ae8bd4..70e40140eb 100644 --- a/examples/animatedModelExample.js +++ b/examples/animatedModelExample.js @@ -56,11 +56,11 @@ function moveModel(deltaTime) { if (count % adjustFPSEveryWhile == 0) { if (animationFPS == 30) { - animationFPS = 10; + animationFPS = 30; } else if (animationFPS == 10) { animationFPS = 10; } else if (animationFPS == 60) { - animationFPS = 10; + animationFPS = 60; } print("animationFPS=" + animationFPS); isPlaying = true; diff --git a/examples/bot.js b/examples/bot.js index f7a0429c53..e42d234abf 100644 --- a/examples/bot.js +++ b/examples/bot.js @@ -25,7 +25,7 @@ function printVector(string, vector) { } var CHANCE_OF_MOVING = 0.005; -var CHANCE_OF_SOUND = 0.000; +var CHANCE_OF_SOUND = 0.005; var CHANCE_OF_HEAD_TURNING = 0.05; var CHANCE_OF_BIG_MOVE = 0.1; var CHANCE_OF_WAVING = 0.009; @@ -41,11 +41,11 @@ var isWaving = false; var waveFrequency = 0.0; var waveAmplitude = 0.0; -var X_MIN = 20.0; -var X_MAX = 25.0; -var Z_MIN = 20.0; -var Z_MAX = 25.0; -var Y_PELVIS = 2.5; +var X_MIN = 5.0; +var X_MAX = 15.0; +var Z_MIN = 5.0; +var Z_MAX = 15.0; +var Y_PELVIS = 1.0; var SPINE_JOINT_NUMBER = 13; var SHOULDER_JOINT_NUMBER = 17; var ELBOW_JOINT_NUMBER = 18; From 4532c934199b7a0292c4a58ef18cb5dba952c60b Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Fri, 16 May 2014 09:36:55 -0700 Subject: [PATCH 4/5] debug off --- examples/hydraMove.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/examples/hydraMove.js b/examples/hydraMove.js index 3a11fa0b5e..9465bd9447 100644 --- a/examples/hydraMove.js +++ b/examples/hydraMove.js @@ -55,7 +55,7 @@ function printVector(text, v, decimals) { print(text + " " + v.x.toFixed(decimals) + ", " + v.y.toFixed(decimals) + ", " + v.z.toFixed(decimals)); } -var debug = true; +var debug = false; // Used by handleGrabBehavior() for managing the grab position changes function getAndResetGrabDelta() { @@ -151,8 +151,6 @@ function handleGrabBehavior(deltaTime) { var ROLL_SCALING = 2.0; var euler = Quat.safeEulerAngles(deltaRotation); - - print("dx: " + euler.x); // Adjust body yaw by roll from controller var orientation = Quat.multiply(Quat.angleAxis(((euler.y * YAW_SCALING) + From 5dcd942e8e562872ed949d074951a7d7a890caa5 Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Fri, 16 May 2014 09:44:03 -0700 Subject: [PATCH 5/5] removed dead code --- examples/hydraMove.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/examples/hydraMove.js b/examples/hydraMove.js index 9465bd9447..ff71316886 100644 --- a/examples/hydraMove.js +++ b/examples/hydraMove.js @@ -87,7 +87,6 @@ function handleGrabBehavior(deltaTime) { if (debug) printVector("start position", grabStartPosition, 3); } if (grabbingWithRightHand) { - //grabDelta = Vec3.sum(grabDelta, Vec3.multiply(Controller.getSpatialControlVelocity(RIGHT_PALM), deltaTime)); grabDelta = Vec3.subtract(Controller.getSpatialControlPosition(RIGHT_PALM), grabStartPosition); grabCurrentRotation = Controller.getSpatialControlRawRotation(RIGHT_PALM); } @@ -105,7 +104,6 @@ function handleGrabBehavior(deltaTime) { } if (grabbingWithLeftHand) { - //grabDelta = Vec3.sum(grabDelta, Vec3.multiply(Controller.getSpatialControlVelocity(LEFT_PALM), deltaTime)); grabDelta = Vec3.subtract(Controller.getSpatialControlPosition(LEFT_PALM), grabStartPosition); grabCurrentRotation = Controller.getSpatialControlRawRotation(LEFT_PALM); } @@ -125,9 +123,7 @@ function handleGrabBehavior(deltaTime) { var right = Quat.getRight(headOrientation); var up = Quat.getUp(headOrientation); - //grabDelta = Quat.multiply(headOrientation, grabDelta); - //grabDelta = Quat.multiply(Camera.getOrientation(), grabDelta); - grabDelta = Vec3.multiplyQbyV(MyAvatar.orientation, Vec3.multiply(grabDelta, -1)); + grabDelta = Vec3.multiplyQbyV(MyAvatar.orientation, Vec3.multiply(grabDelta, -1)); if (debug) { printVector("grabDelta: ", grabDelta, 3);