mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 18:42:58 +02:00
move _lookAtPosition to HeadData class
This commit is contained in:
parent
257a1d1f2e
commit
de84b7803f
8 changed files with 29 additions and 26 deletions
|
@ -111,6 +111,11 @@ Avatar::Avatar(bool isMine) : _head() {
|
||||||
else { _balls = NULL; }
|
else { _balls = NULL; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Avatar::~Avatar() {
|
||||||
|
// if _balls is something that's sticking around other than Philip playing around it needs to be delete here too
|
||||||
|
_headData = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
void Avatar::reset() {
|
void Avatar::reset() {
|
||||||
_head.setYaw(0.0f);
|
_head.setYaw(0.0f);
|
||||||
_head.setRoll(0.0f);
|
_head.setRoll(0.0f);
|
||||||
|
@ -389,20 +394,19 @@ void Avatar::simulate(float deltaTime) {
|
||||||
// update head state
|
// update head state
|
||||||
_head.setPositionAndScale(_joint[AVATAR_JOINT_HEAD_BASE].springyPosition, _joint[AVATAR_JOINT_HEAD_BASE].radius);
|
_head.setPositionAndScale(_joint[AVATAR_JOINT_HEAD_BASE].springyPosition, _joint[AVATAR_JOINT_HEAD_BASE].radius);
|
||||||
|
|
||||||
setLookatPosition(glm::vec3(0.0f, 0.0f, 0.0f)); //default lookat position is 0,0,0
|
_head.setLookAtPosition(glm::vec3(0.0f, 0.0f, 0.0f)); //default lookat position is 0,0,0
|
||||||
|
|
||||||
if (_interactingOther) {
|
if (_interactingOther) {
|
||||||
_head.setLooking(true);
|
_head.setLooking(true);
|
||||||
|
|
||||||
if (_isMine) {
|
if (_isMine) {
|
||||||
setLookatPosition(_interactingOther->getSpringyHeadPosition());
|
_head.setLookAtPosition(_interactingOther->getSpringyHeadPosition());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
_head.setLooking(false);
|
_head.setLooking(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
_head.setBodyYaw(_bodyYaw);
|
_head.setBodyYaw(_bodyYaw);
|
||||||
_head.setLookatPosition(_lookatPosition);
|
|
||||||
_head.setAudioLoudness(_audioLoudness);
|
_head.setAudioLoudness(_audioLoudness);
|
||||||
_head.setSkinColor(glm::vec3(skinColor[0], skinColor[1], skinColor[2]));
|
_head.setSkinColor(glm::vec3(skinColor[0], skinColor[1], skinColor[2]));
|
||||||
_head.simulate(deltaTime, _isMine);
|
_head.simulate(deltaTime, _isMine);
|
||||||
|
@ -1328,12 +1332,6 @@ void Avatar::setHeadFromGyros(glm::vec3* eulerAngles, glm::vec3* angularVelocity
|
||||||
// absolute eulerAngles passed.
|
// absolute eulerAngles passed.
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
float const MAX_YAW = 90.f;
|
|
||||||
float const MIN_YAW = -90.f;
|
|
||||||
float const MAX_PITCH = 85.f;
|
|
||||||
float const MIN_PITCH = -85.f;
|
|
||||||
float const MAX_ROLL = 90.f;
|
|
||||||
float const MIN_ROLL = -90.f;
|
|
||||||
|
|
||||||
if (deltaTime == 0.f) {
|
if (deltaTime == 0.f) {
|
||||||
// On first sample, set head to absolute position
|
// On first sample, set head to absolute position
|
||||||
|
|
|
@ -77,6 +77,7 @@ enum AvatarJointID
|
||||||
class Avatar : public AvatarData {
|
class Avatar : public AvatarData {
|
||||||
public:
|
public:
|
||||||
Avatar(bool isMine);
|
Avatar(bool isMine);
|
||||||
|
~Avatar();
|
||||||
|
|
||||||
void reset();
|
void reset();
|
||||||
void updateHeadFromGyros(float frametime, SerialInterface * serialInterface, glm::vec3 * gravity);
|
void updateHeadFromGyros(float frametime, SerialInterface * serialInterface, glm::vec3 * gravity);
|
||||||
|
|
|
@ -45,7 +45,6 @@ Head::Head() :
|
||||||
_skinColor(0.0f, 0.0f, 0.0f),
|
_skinColor(0.0f, 0.0f, 0.0f),
|
||||||
_position(0.0f, 0.0f, 0.0f),
|
_position(0.0f, 0.0f, 0.0f),
|
||||||
_rotation(0.0f, 0.0f, 0.0f),
|
_rotation(0.0f, 0.0f, 0.0f),
|
||||||
_lookatPosition(0.0f, 0.0f, 0.0f),
|
|
||||||
_eyeballPitch(),
|
_eyeballPitch(),
|
||||||
_eyeballYaw(),
|
_eyeballYaw(),
|
||||||
_interBrowDistance(0.75f),
|
_interBrowDistance(0.75f),
|
||||||
|
@ -224,7 +223,7 @@ void Head::setLooking(bool looking) {
|
||||||
_lookingAtSomething = looking;
|
_lookingAtSomething = looking;
|
||||||
|
|
||||||
glm::vec3 averageEyePosition = _leftEyePosition + (_rightEyePosition - _leftEyePosition ) * ONE_HALF;
|
glm::vec3 averageEyePosition = _leftEyePosition + (_rightEyePosition - _leftEyePosition ) * ONE_HALF;
|
||||||
glm::vec3 targetLookatAxis = glm::normalize(_lookatPosition - averageEyePosition);
|
glm::vec3 targetLookatAxis = glm::normalize(_lookAtPosition - averageEyePosition);
|
||||||
|
|
||||||
float dot = glm::dot(targetLookatAxis, _orientation.getFront());
|
float dot = glm::dot(targetLookatAxis, _orientation.getFront());
|
||||||
if (dot < MINIMUM_EYE_ROTATION) {
|
if (dot < MINIMUM_EYE_ROTATION) {
|
||||||
|
@ -370,7 +369,7 @@ void Head::renderEyeBalls() {
|
||||||
if (_lookingAtSomething) {
|
if (_lookingAtSomething) {
|
||||||
|
|
||||||
//rotate the eyeball to aim towards the lookat position
|
//rotate the eyeball to aim towards the lookat position
|
||||||
glm::vec3 targetLookatAxis = glm::normalize(_lookatPosition - _leftEyePosition); // the lookat direction
|
glm::vec3 targetLookatAxis = glm::normalize(_lookAtPosition - _leftEyePosition); // the lookat direction
|
||||||
glm::vec3 rotationAxis = glm::cross(targetLookatAxis, IDENTITY_UP);
|
glm::vec3 rotationAxis = glm::cross(targetLookatAxis, IDENTITY_UP);
|
||||||
float angle = 180.0f - angleBetween(targetLookatAxis, IDENTITY_UP);
|
float angle = 180.0f - angleBetween(targetLookatAxis, IDENTITY_UP);
|
||||||
glRotatef(angle, rotationAxis.x, rotationAxis.y, rotationAxis.z);
|
glRotatef(angle, rotationAxis.x, rotationAxis.y, rotationAxis.z);
|
||||||
|
@ -414,7 +413,7 @@ void Head::renderEyeBalls() {
|
||||||
if (_lookingAtSomething) {
|
if (_lookingAtSomething) {
|
||||||
|
|
||||||
//rotate the eyeball to aim towards the lookat position
|
//rotate the eyeball to aim towards the lookat position
|
||||||
glm::vec3 targetLookatAxis = glm::normalize(_lookatPosition - _rightEyePosition);
|
glm::vec3 targetLookatAxis = glm::normalize(_lookAtPosition - _rightEyePosition);
|
||||||
glm::vec3 rotationAxis = glm::cross(targetLookatAxis, IDENTITY_UP);
|
glm::vec3 rotationAxis = glm::cross(targetLookatAxis, IDENTITY_UP);
|
||||||
float angle = 180.0f - angleBetween(targetLookatAxis, IDENTITY_UP);
|
float angle = 180.0f - angleBetween(targetLookatAxis, IDENTITY_UP);
|
||||||
glRotatef(angle, rotationAxis.x, rotationAxis.y, rotationAxis.z);
|
glRotatef(angle, rotationAxis.x, rotationAxis.y, rotationAxis.z);
|
||||||
|
|
|
@ -34,7 +34,6 @@ public:
|
||||||
void setPositionAndScale(glm::vec3 position, float scale);
|
void setPositionAndScale(glm::vec3 position, float scale);
|
||||||
void setNewTarget(float, float);
|
void setNewTarget(float, float);
|
||||||
|
|
||||||
void setLookatPosition (glm::vec3 lookatPosition ) { _lookatPosition = lookatPosition; }
|
|
||||||
void setGravity (glm::vec3 gravity ) { _gravity = gravity; }
|
void setGravity (glm::vec3 gravity ) { _gravity = gravity; }
|
||||||
void setSkinColor (glm::vec3 skinColor ) { _skinColor = skinColor; }
|
void setSkinColor (glm::vec3 skinColor ) { _skinColor = skinColor; }
|
||||||
void setBodyYaw (float bodyYaw ) { _bodyYaw = bodyYaw; }
|
void setBodyYaw (float bodyYaw ) { _bodyYaw = bodyYaw; }
|
||||||
|
@ -60,7 +59,6 @@ private:
|
||||||
glm::vec3 _skinColor;
|
glm::vec3 _skinColor;
|
||||||
glm::vec3 _position;
|
glm::vec3 _position;
|
||||||
glm::vec3 _rotation;
|
glm::vec3 _rotation;
|
||||||
glm::vec3 _lookatPosition;
|
|
||||||
glm::vec3 _leftEyePosition;
|
glm::vec3 _leftEyePosition;
|
||||||
glm::vec3 _rightEyePosition;
|
glm::vec3 _rightEyePosition;
|
||||||
float _eyeballPitch[2];
|
float _eyeballPitch[2];
|
||||||
|
|
|
@ -35,7 +35,6 @@ int unpackFloatAngleFromTwoByte(uint16_t* byteAnglePointer, float* destinationPo
|
||||||
|
|
||||||
AvatarData::AvatarData() :
|
AvatarData::AvatarData() :
|
||||||
_handPosition(0,0,0),
|
_handPosition(0,0,0),
|
||||||
_lookatPosition(0,0,0),
|
|
||||||
_bodyYaw(-90.0),
|
_bodyYaw(-90.0),
|
||||||
_bodyPitch(0.0),
|
_bodyPitch(0.0),
|
||||||
_bodyRoll(0.0),
|
_bodyRoll(0.0),
|
||||||
|
@ -97,8 +96,8 @@ int AvatarData::getBroadcastData(unsigned char* destinationBuffer) {
|
||||||
destinationBuffer += sizeof(float) * 3;
|
destinationBuffer += sizeof(float) * 3;
|
||||||
|
|
||||||
// Lookat Position
|
// Lookat Position
|
||||||
memcpy(destinationBuffer, &_lookatPosition, sizeof(_lookatPosition));
|
memcpy(destinationBuffer, &_headData->_lookAtPosition, sizeof(_headData->_lookAtPosition));
|
||||||
destinationBuffer += sizeof(_lookatPosition);
|
destinationBuffer += sizeof(_headData->_lookAtPosition);
|
||||||
|
|
||||||
// Hand State (0 = not grabbing, 1 = grabbing)
|
// Hand State (0 = not grabbing, 1 = grabbing)
|
||||||
memcpy(destinationBuffer, &_handState, sizeof(char));
|
memcpy(destinationBuffer, &_handState, sizeof(char));
|
||||||
|
@ -148,7 +147,10 @@ int AvatarData::getBroadcastData(unsigned char* destinationBuffer) {
|
||||||
// called on the other agents - assigns it to my views of the others
|
// called on the other agents - assigns it to my views of the others
|
||||||
int AvatarData::parseData(unsigned char* sourceBuffer, int numBytes) {
|
int AvatarData::parseData(unsigned char* sourceBuffer, int numBytes) {
|
||||||
|
|
||||||
//printf("AvatarData::parseData()\n");
|
// lazily allocate memory for HeadData in case we're not an Avatar instance
|
||||||
|
if (!_headData) {
|
||||||
|
_headData = new HeadData();
|
||||||
|
}
|
||||||
|
|
||||||
// increment to push past the packet header
|
// increment to push past the packet header
|
||||||
sourceBuffer += sizeof(PACKET_HEADER_HEAD_DATA);
|
sourceBuffer += sizeof(PACKET_HEADER_HEAD_DATA);
|
||||||
|
@ -188,8 +190,8 @@ int AvatarData::parseData(unsigned char* sourceBuffer, int numBytes) {
|
||||||
sourceBuffer += sizeof(float) * 3;
|
sourceBuffer += sizeof(float) * 3;
|
||||||
|
|
||||||
// Lookat Position
|
// Lookat Position
|
||||||
memcpy(&_lookatPosition, sourceBuffer, sizeof(_lookatPosition));
|
memcpy(&_headData->_lookAtPosition, sourceBuffer, sizeof(_headData->_lookAtPosition));
|
||||||
sourceBuffer += sizeof(_lookatPosition);
|
sourceBuffer += sizeof(_headData->_lookAtPosition);
|
||||||
|
|
||||||
// Hand State
|
// Hand State
|
||||||
memcpy(&_handState, sourceBuffer, sizeof(char));
|
memcpy(&_handState, sourceBuffer, sizeof(char));
|
||||||
|
|
|
@ -36,7 +36,6 @@ public:
|
||||||
|
|
||||||
void setPosition (const glm::vec3 position ) { _position = position; }
|
void setPosition (const glm::vec3 position ) { _position = position; }
|
||||||
void setHandPosition (const glm::vec3 handPosition ) { _handPosition = handPosition; }
|
void setHandPosition (const glm::vec3 handPosition ) { _handPosition = handPosition; }
|
||||||
void setLookatPosition(const glm::vec3 lookatPosition) { _lookatPosition = lookatPosition; }
|
|
||||||
|
|
||||||
int getBroadcastData(unsigned char* destinationBuffer);
|
int getBroadcastData(unsigned char* destinationBuffer);
|
||||||
int parseData(unsigned char* sourceBuffer, int numBytes);
|
int parseData(unsigned char* sourceBuffer, int numBytes);
|
||||||
|
@ -108,7 +107,6 @@ protected:
|
||||||
|
|
||||||
glm::vec3 _position;
|
glm::vec3 _position;
|
||||||
glm::vec3 _handPosition;
|
glm::vec3 _handPosition;
|
||||||
glm::vec3 _lookatPosition;
|
|
||||||
|
|
||||||
// Body rotation
|
// Body rotation
|
||||||
float _bodyYaw;
|
float _bodyYaw;
|
||||||
|
|
|
@ -8,12 +8,11 @@
|
||||||
|
|
||||||
#include "HeadData.h"
|
#include "HeadData.h"
|
||||||
|
|
||||||
#include <glm/glm.hpp>
|
|
||||||
|
|
||||||
HeadData::HeadData() :
|
HeadData::HeadData() :
|
||||||
_yaw(0.0f),
|
_yaw(0.0f),
|
||||||
_pitch(0.0f),
|
_pitch(0.0f),
|
||||||
_roll(0.0f)
|
_roll(0.0f),
|
||||||
|
_lookAtPosition(0.0f, 0.0f, 0.0f)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,8 @@
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
#include <glm/glm.hpp>
|
||||||
|
|
||||||
class HeadData {
|
class HeadData {
|
||||||
public:
|
public:
|
||||||
HeadData();
|
HeadData();
|
||||||
|
@ -27,10 +29,16 @@ public:
|
||||||
void addYaw(float yaw);
|
void addYaw(float yaw);
|
||||||
void addPitch(float pitch);
|
void addPitch(float pitch);
|
||||||
void addRoll(float roll);
|
void addRoll(float roll);
|
||||||
|
|
||||||
|
const glm::vec3& getLookAtPosition() const { return _lookAtPosition; }
|
||||||
|
void setLookAtPosition(const glm::vec3& lookAtPosition) { _lookAtPosition = lookAtPosition; }
|
||||||
|
|
||||||
|
friend class AvatarData;
|
||||||
protected:
|
protected:
|
||||||
float _yaw;
|
float _yaw;
|
||||||
float _pitch;
|
float _pitch;
|
||||||
float _roll;
|
float _roll;
|
||||||
|
glm::vec3 _lookAtPosition;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* defined(__hifi__HeadData__) */
|
#endif /* defined(__hifi__HeadData__) */
|
||||||
|
|
Loading…
Reference in a new issue