From 564244ddd371cdc0a4cf9cbcb3a184c1fb360eb5 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 20 May 2013 17:13:40 -0700 Subject: [PATCH] move _leanSideways and _leanForwards to HeadData --- interface/src/Avatar.cpp | 40 ++++++---------------------- interface/src/Avatar.h | 3 --- interface/src/Head.cpp | 11 +++++--- interface/src/Head.h | 3 +-- libraries/avatars/src/AvatarData.cpp | 16 +++++------ libraries/avatars/src/AvatarData.h | 9 ------- libraries/avatars/src/HeadData.cpp | 10 ++++++- libraries/avatars/src/HeadData.h | 9 +++++++ 8 files changed, 41 insertions(+), 60 deletions(-) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index d4e6ae0a8b..d789f3751a 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -118,10 +118,7 @@ Avatar::~Avatar() { } void Avatar::reset() { - _head.setYaw(0.0f); - _head.setRoll(0.0f); - _head.setPitch(0.0f); - _head.leanForward = _head.leanSideways = 0; + _head.reset(); } // Update avatar head rotation with sensor data @@ -153,13 +150,11 @@ void Avatar::updateHeadFromGyros(float deltaTime, SerialInterface* serialInterfa * (1.f - fminf(glm::length(headRotationRates), headRateMax) / headRateMax); leaning.y = 0.f; if (glm::length(leaning) < LEAN_MAX) { - _head.leanForward = _head.leanForward * (1.f - LEAN_AVERAGING * deltaTime) + - (LEAN_AVERAGING * deltaTime) * leaning.z * LEAN_SENSITIVITY; - _head.leanSideways = _head.leanSideways * (1.f - LEAN_AVERAGING * deltaTime) + - (LEAN_AVERAGING * deltaTime) * leaning.x * LEAN_SENSITIVITY; + _head.setLeanForward(_head.getLeanForward() * (1.f - LEAN_AVERAGING * deltaTime) + + (LEAN_AVERAGING * deltaTime) * leaning.z * LEAN_SENSITIVITY); + _head.setLeanSideways(_head.getLeanSideways() * (1.f - LEAN_AVERAGING * deltaTime) + + (LEAN_AVERAGING * deltaTime) * leaning.x * LEAN_SENSITIVITY); } - setHeadLeanSideways(_head.leanSideways); - setHeadLeanForward(_head.leanForward); } float Avatar::getAbsoluteHeadYaw() const { @@ -170,20 +165,6 @@ float Avatar::getAbsoluteHeadPitch() const { return _bodyPitch + _head.getPitch(); } -void Avatar::addLean(float x, float z) { - //Add lean as impulse - _head.leanSideways += x; - _head.leanForward += z; -} - -void Avatar::setLeanForward(float dist){ - _head.leanForward = dist; -} - -void Avatar::setLeanSideways(float dist){ - _head.leanSideways = dist; -} - void Avatar::setMousePressed(bool mousePressed) { _mousePressed = mousePressed; } @@ -361,17 +342,12 @@ void Avatar::simulate(float deltaTime) { _head.setPitch(_head.getPitch() * (1.f - acceleration * ACCELERATION_PITCH_DECAY * deltaTime)); } - // Get head position data from network for other people - if (!_isMine) { - _head.leanSideways = getHeadLeanSideways(); - _head.leanForward = getHeadLeanForward(); - } //apply the head lean values to the springy position... - if (fabs(_head.leanSideways + _head.leanForward) > 0.0f) { + if (fabs(_head.getLeanSideways() + _head.getLeanForward()) > 0.0f) { glm::vec3 headLean = - _orientation.getRight() * _head.leanSideways + - _orientation.getFront() * _head.leanForward; + _orientation.getRight() * _head.getLeanSideways() + + _orientation.getFront() * _head.getLeanForward(); // this is not a long-term solution, but it works ok for initial purposes of making the avatar lean _joint[ AVATAR_JOINT_TORSO ].springyPosition += headLean * 0.1f; diff --git a/interface/src/Avatar.h b/interface/src/Avatar.h index 5e2ce0fd47..3832fa1902 100644 --- a/interface/src/Avatar.h +++ b/interface/src/Avatar.h @@ -93,9 +93,6 @@ public: float getAbsoluteHeadYaw() const; float getAbsoluteHeadPitch() const; - void setLeanForward(float dist); - void setLeanSideways(float dist); - void addLean(float x, float z); glm::vec3 getApproximateEyePosition(); const glm::vec3& getHeadPosition() const ; // get the position of the avatar's rigid body head const glm::vec3& getSpringyHeadPosition() const ; // get the springy position of the avatar's head diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index c59dd9ac1d..4b1be7f51e 100644 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -39,8 +39,6 @@ vector irisTexture; Head::Head() : yawRate(0.0f), noise(0.0f), - leanForward(0.0f), - leanSideways(0.0f), _audioLoudness(0.0f), _skinColor(0.0f, 0.0f, 0.0f), _position(0.0f, 0.0f, 0.0f), @@ -83,6 +81,11 @@ void Head::setNewTarget(float pitch, float yaw) { _yawTarget = yaw; } +void Head::reset() { + _yaw = _pitch = _roll = 0.0f; + _leanForward = _leanSideways = 0.0f; +} + void Head::simulate(float deltaTime, bool isMine) { //generate orientation directions based on Euler angles... @@ -115,8 +118,8 @@ void Head::simulate(float deltaTime, bool isMine) { _roll *= 1.f - (HEAD_MOTION_DECAY * deltaTime); } - leanForward *= (1.f - HEAD_MOTION_DECAY * 30 * deltaTime); - leanSideways *= (1.f - HEAD_MOTION_DECAY * 30 * deltaTime); + _leanForward *= (1.f - HEAD_MOTION_DECAY * 30 * deltaTime); + _leanSideways *= (1.f - HEAD_MOTION_DECAY * 30 * deltaTime); // Update where the avatar's eyes are // diff --git a/interface/src/Head.h b/interface/src/Head.h index a731a7b87e..c192980349 100644 --- a/interface/src/Head.h +++ b/interface/src/Head.h @@ -27,6 +27,7 @@ class Head : public HeadData { public: Head(); + void reset(); void simulate(float deltaTime, bool isMine); void render(bool lookingInMirror); @@ -49,8 +50,6 @@ public: //some public members (left-over from pulling Head out of Avatar - I may see about privatizing these later). float yawRate; float noise; - float leanForward; - float leanSideways; private: diff --git a/libraries/avatars/src/AvatarData.cpp b/libraries/avatars/src/AvatarData.cpp index 8c6f4fb894..fb97052151 100644 --- a/libraries/avatars/src/AvatarData.cpp +++ b/libraries/avatars/src/AvatarData.cpp @@ -38,8 +38,6 @@ AvatarData::AvatarData() : _bodyYaw(-90.0), _bodyPitch(0.0), _bodyRoll(0.0), - _headLeanSideways(0), - _headLeanForward(0), _audioLoudness(0), _handState(0), _cameraPosition(0,0,0), @@ -85,10 +83,10 @@ int AvatarData::getBroadcastData(unsigned char* destinationBuffer) { destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, _headData->_roll); // Head lean X,Z (head lateral and fwd/back motion relative to torso) - memcpy(destinationBuffer, &_headLeanSideways, sizeof(float)); - destinationBuffer += sizeof(float); - memcpy(destinationBuffer, &_headLeanForward, sizeof(float)); - destinationBuffer += sizeof(float); + memcpy(destinationBuffer, &_headData->_leanSideways, sizeof(_headData->_leanSideways)); + destinationBuffer += sizeof(_headData->_leanSideways); + memcpy(destinationBuffer, &_headData->_leanForward, sizeof(_headData->_leanForward)); + destinationBuffer += sizeof(_headData->_leanForward); // Hand Position memcpy(destinationBuffer, &_handPosition, sizeof(float) * 3); @@ -179,10 +177,10 @@ int AvatarData::parseData(unsigned char* sourceBuffer, int numBytes) { _headData->setRoll(headRoll); // Head position relative to pelvis - memcpy(&_headLeanSideways, sourceBuffer, sizeof(float)); - sourceBuffer += sizeof(float); - memcpy(&_headLeanForward, sourceBuffer, sizeof(float)); + memcpy(&_headData->_leanSideways, sourceBuffer, sizeof(_headData->_leanSideways)); sourceBuffer += sizeof(float); + memcpy(&_headData->_leanForward, sourceBuffer, sizeof(_headData->_leanForward)); + sourceBuffer += sizeof(_headData->_leanForward); // Hand Position memcpy(&_handPosition, sourceBuffer, sizeof(float) * 3); diff --git a/libraries/avatars/src/AvatarData.h b/libraries/avatars/src/AvatarData.h index e3621095d3..8924b5f937 100644 --- a/libraries/avatars/src/AvatarData.h +++ b/libraries/avatars/src/AvatarData.h @@ -47,12 +47,6 @@ public: void setBodyPitch(float bodyPitch) { _bodyPitch = bodyPitch; } float getBodyRoll() const {return _bodyRoll; } void setBodyRoll(float bodyRoll) { _bodyRoll = bodyRoll; } - - // Head vector deflection from pelvix in X,Z - void setHeadLeanSideways(float s) {_headLeanSideways = s; }; - float getHeadLeanSideways() const { return _headLeanSideways; }; - void setHeadLeanForward(float f) {_headLeanForward = f; }; - float getHeadLeanForward() const { return _headLeanForward; }; // Hand State void setHandState(char s) { _handState = s; }; @@ -112,9 +106,6 @@ protected: float _bodyYaw; float _bodyPitch; float _bodyRoll; - - float _headLeanSideways; - float _headLeanForward; // Audio loudness (used to drive facial animation) float _audioLoudness; diff --git a/libraries/avatars/src/HeadData.cpp b/libraries/avatars/src/HeadData.cpp index bc400b96bb..e7d6cee46a 100644 --- a/libraries/avatars/src/HeadData.cpp +++ b/libraries/avatars/src/HeadData.cpp @@ -12,7 +12,9 @@ HeadData::HeadData() : _yaw(0.0f), _pitch(0.0f), _roll(0.0f), - _lookAtPosition(0.0f, 0.0f, 0.0f) + _lookAtPosition(0.0f, 0.0f, 0.0f), + _leanSideways(0.0f), + _leanForward(0.0f) { } @@ -27,4 +29,10 @@ void HeadData::addPitch(float pitch) { void HeadData::addRoll(float roll) { setRoll(_roll + roll); +} + +void HeadData::addLean(float sideways, float forwards) { + // Add lean as impulse + _leanSideways += sideways; + _leanForward += forwards; } \ No newline at end of file diff --git a/libraries/avatars/src/HeadData.h b/libraries/avatars/src/HeadData.h index 7da3085fe7..8c9e99e6d9 100644 --- a/libraries/avatars/src/HeadData.h +++ b/libraries/avatars/src/HeadData.h @@ -24,6 +24,12 @@ class HeadData { public: HeadData(); + float getLeanSideways() const { return _leanSideways; } + void setLeanSideways(float leanSideways) { _leanSideways = leanSideways; } + + float getLeanForward() const { return _leanForward; } + void setLeanForward(float leanForward) { _leanForward = leanForward; } + float getYaw() const { return _yaw; } void setYaw(float yaw) { _yaw = glm::clamp(yaw, MIN_HEAD_YAW, MAX_HEAD_YAW); } @@ -36,6 +42,7 @@ public: void addYaw(float yaw); void addPitch(float pitch); void addRoll(float roll); + void addLean(float sideways, float forwards); const glm::vec3& getLookAtPosition() const { return _lookAtPosition; } void setLookAtPosition(const glm::vec3& lookAtPosition) { _lookAtPosition = lookAtPosition; } @@ -46,6 +53,8 @@ protected: float _pitch; float _roll; glm::vec3 _lookAtPosition; + float _leanSideways; + float _leanForward; }; #endif /* defined(__hifi__HeadData__) */