mirror of
https://github.com/lubosz/overte.git
synced 2025-04-24 18:23:22 +02:00
Merge pull request #363 from birarda/head-changes
move lean sideways and lean forwards to the head data class
This commit is contained in:
commit
6392bb0045
8 changed files with 41 additions and 60 deletions
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -39,8 +39,6 @@ vector<unsigned char> 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
|
||||
//
|
||||
|
|
|
@ -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:
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
|
@ -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__) */
|
||||
|
|
Loading…
Reference in a new issue