From 84ca2dcb321c68f53c651929945c4d9fce148595 Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Fri, 12 Apr 2013 16:12:31 -0700 Subject: [PATCH 1/2] added get avatar bone --- interface/src/Head.cpp | 70 ++++++++++++++++++++++++++++++++++-------- interface/src/Head.h | 4 ++- interface/src/Util.h | 2 +- 3 files changed, 61 insertions(+), 15 deletions(-) diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index 600dc3f0ca..1a70ba9a13 100644 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -95,7 +95,6 @@ Head::Head() { usingSprings = false; springForce = 6.0f; - springToBodyTightness = 4.0f; springVelocityDecay = 16.0f; hand = new Hand(glm::vec3(skinColor[0], skinColor[1], skinColor[2])); @@ -782,23 +781,27 @@ void Head::setHandMovement( glm::vec3 movement ) { void Head::initializeAvatar() { - //avatar.position = glm::vec3( 0.0, 0.0, 0.0 ); avatar.velocity = glm::vec3( 0.0, 0.0, 0.0 ); avatar.thrust = glm::vec3( 0.0, 0.0, 0.0 ); avatar.orientation.setToIdentity(); closestOtherAvatar = 0; - bodyYaw = -90.0; - bodyPitch = 0.0; - bodyRoll = 0.0; - - bodyYawDelta = 0.0; + bodyYaw = -90.0; + bodyPitch = 0.0; + bodyRoll = 0.0; + bodyYawDelta = 0.0; for (int b=0; b 0.0f ) { glm::vec3 springDirection = springVector / length; - float force = ( length - avatar.bone[b].length ) * springForce * deltaTime; + float force = ( length - avatar.bone[b].length ) * springForce * deltaTime; avatar.bone[ b ].springyVelocity -= springDirection * force; avatar.bone[ avatar.bone[b].parent ].springyVelocity += springDirection * force; } - avatar.bone[b].springyVelocity += ( avatar.bone[b].position - avatar.bone[b].springyPosition ) * springToBodyTightness * deltaTime; - + avatar.bone[b].springyVelocity += ( avatar.bone[b].position - avatar.bone[b].springyPosition ) * + avatar.bone[b].springBodyTightness * deltaTime; + float decay = 1.0 - springVelocityDecay * deltaTime; if ( decay > 0.0 ) { @@ -1000,6 +1039,11 @@ glm::vec3 Head::getHeadLookatDirectionUp() { ); } +glm::vec3 Head::getBonePosition( AvatarBones b ) +{ + return avatar.bone[b].position; +} + glm::vec3 Head::getHeadLookatDirectionRight() { return glm::vec3 ( diff --git a/interface/src/Head.h b/interface/src/Head.h index 2cda9a1af6..eeaa4ebee0 100644 --- a/interface/src/Head.h +++ b/interface/src/Head.h @@ -109,6 +109,7 @@ struct AvatarBone glm::vec3 defaultPosePosition; // the parent relative position when the avatar is in the "T-pose" glm::vec3 springyPosition; // used for special effects (a 'flexible' variant of position) glm::dvec3 springyVelocity; // used for special effects ( the velocity of the springy position) + float springBodyTightness; // how tightly (0 to 1) the springy position tries to stay on the position float yaw; // the yaw Euler angle of the bone rotation off the parent float pitch; // the pitch Euler angle of the bone rotation off the parent float roll; // the roll Euler angle of the bone rotation off the parent @@ -159,6 +160,7 @@ class Head : public AgentData { glm::vec3 getHeadLookatDirectionUp(); glm::vec3 getHeadLookatDirectionRight(); glm::vec3 getHeadPosition(); + glm::vec3 getBonePosition( AvatarBones b ); glm::vec3 getBodyPosition(); void render(int faceToFace, int isMine); @@ -254,7 +256,7 @@ class Head : public AgentData { float springVelocityDecay; float springForce; - float springToBodyTightness; + //float springToBodyTightness; int eyeContact; eyeContactTargets eyeContactTarget; diff --git a/interface/src/Util.h b/interface/src/Util.h index 0e0121e2da..5a6f6a96d6 100644 --- a/interface/src/Util.h +++ b/interface/src/Util.h @@ -24,7 +24,7 @@ static const double ONE_THIRD = 0.3333333; static const double PIE = 3.14159265359; static const double PI_TIMES_TWO = 3.14159265359 * 2.0; static const double PI_OVER_180 = 3.14159265359 / 180.0; -static const double EPSILON = 0.00001; //smallish number - used as margin of error for some values +static const double EPSILON = 0.00001; //smallish number - used as margin of error for some computations static const double SQUARE_ROOT_OF_2 = sqrt(2); static const double SQUARE_ROOT_OF_3 = sqrt(3); static const double METER = 1.0; From 6ddebd523cf2eeca02963ac2d122119fffa9b387 Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Fri, 12 Apr 2013 16:52:31 -0700 Subject: [PATCH 2/2] cleaned up Orientation calls to right, up, front --- interface/src/Head.cpp | 40 +++++++++++++++++------------------ interface/src/Orientation.cpp | 13 +++++++++--- interface/src/Orientation.h | 16 ++++++-------- 3 files changed, 36 insertions(+), 33 deletions(-) diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index 1a70ba9a13..37185d6442 100644 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -353,27 +353,27 @@ void Head::simulate(float deltaTime) { //notice that the z values from avatar.orientation are flipped to accommodate different coordinate system if (driveKeys[FWD]) { - glm::vec3 front( avatar.orientation.getFront().x, avatar.orientation.getFront().y, avatar.orientation.getFront().z ); + glm::vec3 front( avatar.orientation.front.x, avatar.orientation.front.y, avatar.orientation.front.z ); avatar.thrust += front * THRUST_MAG; } if (driveKeys[BACK]) { - glm::vec3 front( avatar.orientation.getFront().x, avatar.orientation.getFront().y, avatar.orientation.getFront().z ); + glm::vec3 front( avatar.orientation.front.x, avatar.orientation.front.y, avatar.orientation.front.z ); avatar.thrust -= front * THRUST_MAG; } if (driveKeys[RIGHT]) { - glm::vec3 right( avatar.orientation.getRight().x, avatar.orientation.getRight().y, avatar.orientation.getRight().z ); + glm::vec3 right( avatar.orientation.right.x, avatar.orientation.right.y, avatar.orientation.right.z ); avatar.thrust -= right * THRUST_MAG; } if (driveKeys[LEFT]) { - glm::vec3 right( avatar.orientation.getRight().x, avatar.orientation.getRight().y, avatar.orientation.getRight().z ); + glm::vec3 right( avatar.orientation.right.x, avatar.orientation.right.y, avatar.orientation.right.z ); avatar.thrust += right * THRUST_MAG; } if (driveKeys[UP]) { - glm::vec3 up( avatar.orientation.getUp().x, avatar.orientation.getUp().y, avatar.orientation.getUp().z ); + glm::vec3 up( avatar.orientation.up.x, avatar.orientation.up.y, avatar.orientation.up.z ); avatar.thrust += up * THRUST_MAG; } if (driveKeys[DOWN]) { - glm::vec3 up( avatar.orientation.getUp().x, avatar.orientation.getUp().y, avatar.orientation.getUp().z ); + glm::vec3 up( avatar.orientation.up.x, avatar.orientation.up.y, avatar.orientation.up.z ); avatar.thrust -= up * THRUST_MAG; } if (driveKeys[ROT_RIGHT]) { @@ -573,7 +573,7 @@ void Head::render(int faceToFace, int isMine) { void Head::renderOrientationDirections( glm::vec3 position, Orientation orientation, float size ) { - glm::vec3 pRight = position + orientation.getRight () * size; + glm::vec3 pRight = position + orientation.right * size; glm::vec3 pUp = position + orientation.getUp () * size; glm::vec3 pFront = position + orientation.getFront () * size; @@ -1024,18 +1024,18 @@ float Head::getBodyYaw() { glm::vec3 Head::getHeadLookatDirection() { return glm::vec3 ( - avatar.orientation.getFront().x, - avatar.orientation.getFront().y, - avatar.orientation.getFront().z + avatar.orientation.front.x, + avatar.orientation.front.y, + avatar.orientation.front.z ); } glm::vec3 Head::getHeadLookatDirectionUp() { return glm::vec3 ( - avatar.orientation.getUp().x, - avatar.orientation.getUp().y, - avatar.orientation.getUp().z + avatar.orientation.up.x, + avatar.orientation.up.y, + avatar.orientation.up.z ); } @@ -1047,9 +1047,9 @@ glm::vec3 Head::getBonePosition( AvatarBones b ) glm::vec3 Head::getHeadLookatDirectionRight() { return glm::vec3 ( - avatar.orientation.getRight().x, - avatar.orientation.getRight().y, - avatar.orientation.getRight().z + avatar.orientation.right.x, + avatar.orientation.right.y, + avatar.orientation.right.z ); } @@ -1077,9 +1077,9 @@ void Head::updateHandMovement() { glm::vec3 transformedHandMovement; transformedHandMovement - = avatar.orientation.getRight() * -movedHandOffset.x - + avatar.orientation.getUp() * -movedHandOffset.y - + avatar.orientation.getFront() * -movedHandOffset.y * 0.4; + = avatar.orientation.right * -movedHandOffset.x + + avatar.orientation.up * -movedHandOffset.y + + avatar.orientation.front * -movedHandOffset.y * 0.4; //if holding hands, add a pull to the hand... if ( usingSprings ) { @@ -1123,7 +1123,7 @@ void Head::updateHandMovement() { //----------------------------------------------------------------------------- glm::vec3 newElbowPosition = avatar.bone[ AVATAR_BONE_RIGHT_SHOULDER ].position; newElbowPosition += armVector * (float)ONE_HALF; - glm::vec3 perpendicular = glm::cross( avatar.orientation.getFront(), armVector ); + glm::vec3 perpendicular = glm::cross( avatar.orientation.front, armVector ); newElbowPosition += perpendicular * ( 1.0 - ( avatar.maxArmLength / distance ) ) * ONE_HALF; avatar.bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].position = newElbowPosition; diff --git a/interface/src/Orientation.cpp b/interface/src/Orientation.cpp index 439538ce8a..6545c2b806 100755 --- a/interface/src/Orientation.cpp +++ b/interface/src/Orientation.cpp @@ -1,3 +1,10 @@ +//----------------------------------------------------------- +// +// Created by Jeffrey Ventrella +// Copyright (c) 2013 High Fidelity, Inc. All rights reserved. +// +//----------------------------------------------------------- + #include "Orientation.h" #include "Util.h" @@ -16,9 +23,9 @@ void Orientation::setToIdentity() { void Orientation::set( Orientation o ) { - right = o.getRight(); - up = o.getUp(); - front = o.getFront(); + right = o.right; + up = o.up; + front = o.front; } diff --git a/interface/src/Orientation.h b/interface/src/Orientation.h index 77771b785c..ae209a5f47 100755 --- a/interface/src/Orientation.h +++ b/interface/src/Orientation.h @@ -1,7 +1,7 @@ //----------------------------------------------------------- // -// Created by Jeffrey Ventrella and added as a utility -// class for High Fidelity Code base, April 2013 +// Created by Jeffrey Ventrella +// Copyright (c) 2013 High Fidelity, Inc. All rights reserved. // //----------------------------------------------------------- @@ -20,14 +20,6 @@ enum Axis class Orientation { -private: - - glm::vec3 right; - glm::vec3 up; - glm::vec3 front; - - //void verifyValidOrientation(); - public: Orientation(); @@ -38,6 +30,10 @@ public: void set( Orientation ); void setToIdentity(); + glm::vec3 right; + glm::vec3 up; + glm::vec3 front; + glm::vec3 getRight() { return right; } glm::vec3 getUp() { return up; } glm::vec3 getFront() { return front; }