From 8c71ed3f103b6106438d7633ff35e8cf5fa3eafa Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Thu, 18 Sep 2014 10:48:36 -0700 Subject: [PATCH] Improving headMove, added JS call for neckPosition --- examples/headMove.js | 29 +++++++++++++++++++++-------- interface/src/avatar/Avatar.cpp | 6 ++++++ interface/src/avatar/Avatar.h | 2 ++ interface/src/avatar/Head.cpp | 2 +- 4 files changed, 30 insertions(+), 9 deletions(-) diff --git a/examples/headMove.js b/examples/headMove.js index 359dfd8751..68a9a7833d 100644 --- a/examples/headMove.js +++ b/examples/headMove.js @@ -45,7 +45,7 @@ var maxVelocity = 1.25; var noFly = true; //var roomLimits = { xMin: 618, xMax: 635.5, zMin: 528, zMax: 552.5 }; -var roomLimits = { xMin: -1, xMax: 0, zMin: 0, zMax: 0 }; +var roomLimits = { xMin: 142.6, xMax: 153.7, zMin: 177.5, zMax: 192.0 }; function isInRoom(position) { var BUFFER = 2.0; @@ -71,19 +71,29 @@ function moveWithHead(deltaTime) { var deltaPitch = MyAvatar.getHeadDeltaPitch() - headStartDeltaPitch; var deltaRoll = MyAvatar.getHeadFinalRoll() - headStartRoll; var velocity = MyAvatar.getVelocity(); - var bodyLocalCurrentHeadVector = Vec3.subtract(MyAvatar.getHeadPosition(), MyAvatar.position); - bodyLocalCurrentHeadVector = Vec3.multiplyQbyV(Quat.angleAxis(-deltaYaw, {x:0, y: 1, z:0}), bodyLocalCurrentHeadVector); + var position = MyAvatar.position; + var neckPosition = MyAvatar.getNeckPosition(); + var bodyLocalCurrentHeadVector = Vec3.subtract(neckPosition, position); + //bodyLocalCurrentHeadVector = Vec3.multiplyQbyV(Quat.inverse(MyAvatar.orientation), bodyLocalCurrentHeadVector); var headDelta = Vec3.subtract(bodyLocalCurrentHeadVector, headStartPosition); - headDelta = Vec3.multiplyQbyV(Quat.inverse(Camera.getOrientation()), headDelta); + //headDelta = Vec3.multiplyQbyV(Quat.inverse(Camera.getOrientation()), headDelta); headDelta.y = 0.0; // Don't respond to any of the vertical component of head motion + if (Vec3.length(headDelta) > 0.005) { + Vec3.print("headDelta = ", headDelta); + Vec3.print("headStartPosition = ", headStartPosition); + Vec3.print("MyAvatar.position = ", position); + Vec3.print("MyAvatar.getNeckPosition() = ", neckPosition); + + } + // Thrust based on leaning forward and side-to-side var targetVelocity = {x:0.0, y:0.0, z:0.0}; if (Math.abs(headDelta.z) > HEAD_MOVE_DEAD_ZONE) { - targetVelocity = Vec3.multiply(zAxis, -headDelta.z * HEAD_VELOCITY_FWD_FACTOR); + targetVelocity = Vec3.multiply(zAxis, headDelta.z * HEAD_VELOCITY_FWD_FACTOR); } if (Math.abs(headDelta.x) > HEAD_STRAFE_DEAD_ZONE) { - var deltaVelocity = Vec3.multiply(xAxis, -headDelta.x * HEAD_VELOCITY_LEFT_FACTOR); + var deltaVelocity = Vec3.multiply(xAxis, headDelta.x * HEAD_VELOCITY_LEFT_FACTOR); targetVelocity = Vec3.sum(targetVelocity, deltaVelocity); } if (Math.abs(deltaYaw) > HEAD_ROTATE_DEAD_ZONE) { @@ -130,7 +140,10 @@ function moveWithHead(deltaTime) { Controller.keyPressEvent.connect(function(event) { if (event.text == "SPACE" && !movingWithHead) { movingWithHead = true; - headStartPosition = Vec3.subtract(MyAvatar.getHeadPosition(), MyAvatar.position); + Vec3.print("getNeckPosition() = ", MyAvatar.getNeckPosition()); + headStartPosition = Vec3.subtract(MyAvatar.getNeckPosition(), MyAvatar.position); + //headStartPosition = Vec3.multiplyQbyV(Quat.inverse(MyAvatar.orientation), headStartPosition); + Vec3.print("First HeadStartPosition = ", headStartPosition); headStartDeltaPitch = MyAvatar.getHeadDeltaPitch(); headStartFinalPitch = MyAvatar.getHeadFinalPitch(); headStartRoll = MyAvatar.getHeadFinalRoll(); @@ -138,7 +151,7 @@ Controller.keyPressEvent.connect(function(event) { // start with disabled motor -- it will be updated shortly MyAvatar.motorTimescale = VERY_LARGE_TIMESCALE; MyAvatar.motorVelocity = {x:0.0, y:0.0, z:0.0}; - MyAvatar.motorReferenceFrame = "camera"; // alternatives are: "avatar" and "world" + MyAvatar.motorReferenceFrame = "avatar"; // alternatives are: "avatar" and "world" } }); diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index b62c744fa2..bd05f7c4c0 100644 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -97,6 +97,12 @@ glm::vec3 Avatar::getChestPosition() const { return _skeletonModel.getNeckPosition(neckPosition) ? (_position + neckPosition) * 0.5f : _position; } +glm::vec3 Avatar::getNeckPosition() const { + glm::vec3 neckPosition; + return _skeletonModel.getNeckPosition(neckPosition) ? neckPosition : _position; +} + + glm::quat Avatar::getWorldAlignedOrientation () const { return computeRotationFromBodyToWorldUp() * getOrientation(); } diff --git a/interface/src/avatar/Avatar.h b/interface/src/avatar/Avatar.h index 921722504d..c449a0d1b9 100755 --- a/interface/src/avatar/Avatar.h +++ b/interface/src/avatar/Avatar.h @@ -154,6 +154,8 @@ public: Q_INVOKABLE void setJointModelPositionAndOrientation(int index, const glm::vec3 position, const glm::quat& rotation); Q_INVOKABLE void setJointModelPositionAndOrientation(const QString& name, const glm::vec3 position, const glm::quat& rotation); + + Q_INVOKABLE glm::vec3 getNeckPosition() const; Q_INVOKABLE glm::vec3 getVelocity() const { return _velocity; } Q_INVOKABLE glm::vec3 getAcceleration() const { return _acceleration; } diff --git a/interface/src/avatar/Head.cpp b/interface/src/avatar/Head.cpp index 3f0770428b..4c394377a3 100644 --- a/interface/src/avatar/Head.cpp +++ b/interface/src/avatar/Head.cpp @@ -90,7 +90,7 @@ void Head::simulate(float deltaTime, bool isMine, bool billboard) { _longTermAverageLoudness = glm::mix(_longTermAverageLoudness, _averageLoudness, glm::min(deltaTime / AUDIO_LONG_TERM_AVERAGING_SECS, 1.0f)); } float deltaLoudness = glm::max(0.0f, _averageLoudness - _longTermAverageLoudness); - qDebug() << "deltaLoudness: " << deltaLoudness; + //qDebug() << "deltaLoudness: " << deltaLoudness; if (!(_isFaceshiftConnected || billboard)) { // Update eye saccades