mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 09:48:44 +02:00
improving lookat behavior
This commit is contained in:
parent
7bb94ae8de
commit
c32d621d5f
4 changed files with 76 additions and 14 deletions
|
@ -20,6 +20,10 @@
|
||||||
#include <PacketHeaders.h>
|
#include <PacketHeaders.h>
|
||||||
#include <OculusManager.h>
|
#include <OculusManager.h>
|
||||||
|
|
||||||
|
//test
|
||||||
|
static glm::vec3 headLean(0.0f, 0.0f, 0.0f);
|
||||||
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
const bool BALLS_ON = false;
|
const bool BALLS_ON = false;
|
||||||
|
@ -51,6 +55,11 @@ const float PERIPERSONAL_RADIUS = 1.0f;
|
||||||
const float AVATAR_BRAKING_STRENGTH = 40.0f;
|
const float AVATAR_BRAKING_STRENGTH = 40.0f;
|
||||||
const float JOINT_TOUCH_RANGE = 0.0005f;
|
const float JOINT_TOUCH_RANGE = 0.0005f;
|
||||||
|
|
||||||
|
const float LEAN_SENSITIVITY = 0.15;
|
||||||
|
const float LEAN_MAX = 0.45;
|
||||||
|
const float LEAN_AVERAGING = 10.0;
|
||||||
|
const float HEAD_RATE_MAX = 50.f;
|
||||||
|
|
||||||
float skinColor [] = {1.0, 0.84, 0.66};
|
float skinColor [] = {1.0, 0.84, 0.66};
|
||||||
float darkSkinColor[] = {0.9, 0.78, 0.63};
|
float darkSkinColor[] = {0.9, 0.78, 0.63};
|
||||||
float lightBlue [] = {0.7, 0.8, 1.0 };
|
float lightBlue [] = {0.7, 0.8, 1.0 };
|
||||||
|
@ -134,16 +143,12 @@ void Avatar::updateHeadFromGyros(float deltaTime, SerialInterface* serialInterfa
|
||||||
_head.addRoll (measuredRollRate * deltaTime);
|
_head.addRoll (measuredRollRate * deltaTime);
|
||||||
|
|
||||||
// Update head lean distance based on accelerometer data
|
// Update head lean distance based on accelerometer data
|
||||||
const float LEAN_SENSITIVITY = 0.15;
|
|
||||||
const float LEAN_MAX = 0.45;
|
|
||||||
const float LEAN_AVERAGING = 10.0;
|
|
||||||
glm::vec3 headRotationRates(_head.getPitch(), _head.getYaw(), _head.getRoll());
|
glm::vec3 headRotationRates(_head.getPitch(), _head.getYaw(), _head.getRoll());
|
||||||
float headRateMax = 50.f;
|
|
||||||
|
|
||||||
|
|
||||||
glm::vec3 leaning = (serialInterface->getLastAcceleration() - serialInterface->getGravity())
|
glm::vec3 leaning = (serialInterface->getLastAcceleration() - serialInterface->getGravity())
|
||||||
* LEAN_SENSITIVITY
|
* LEAN_SENSITIVITY
|
||||||
* (1.f - fminf(glm::length(headRotationRates), headRateMax) / headRateMax);
|
* (1.f - fminf(glm::length(headRotationRates), HEAD_RATE_MAX) / HEAD_RATE_MAX);
|
||||||
leaning.y = 0.f;
|
leaning.y = 0.f;
|
||||||
if (glm::length(leaning) < LEAN_MAX) {
|
if (glm::length(leaning) < LEAN_MAX) {
|
||||||
_head.setLeanForward(_head.getLeanForward() * (1.f - LEAN_AVERAGING * deltaTime) +
|
_head.setLeanForward(_head.getLeanForward() * (1.f - LEAN_AVERAGING * deltaTime) +
|
||||||
|
@ -364,11 +369,27 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter) {
|
||||||
|
|
||||||
//apply the head lean values to the springy position...
|
//apply the head lean values to the springy position...
|
||||||
if (fabs(_head.getLeanSideways() + _head.getLeanForward()) > 0.0f) {
|
if (fabs(_head.getLeanSideways() + _head.getLeanForward()) > 0.0f) {
|
||||||
|
|
||||||
glm::vec3 headLean =
|
glm::vec3 headLean =
|
||||||
_orientation.getRight() * _head.getLeanSideways() +
|
_orientation.getRight() * _head.getLeanSideways() +
|
||||||
_orientation.getFront() * _head.getLeanForward();
|
_orientation.getFront() * _head.getLeanForward();
|
||||||
|
|
||||||
|
/*
|
||||||
|
glm::vec3 leanForce =
|
||||||
|
_orientation.getRight() * _head.getLeanSideways() +
|
||||||
|
_orientation.getFront() * _head.getLeanForward() * 10.0f;
|
||||||
|
|
||||||
|
float magnitude = 1.0f * deltaTime;
|
||||||
|
if (magnitude > 1.0f ) {
|
||||||
|
headLean = leanForce;
|
||||||
|
} else {
|
||||||
|
headLean += (leanForce - headLean ) * magnitude;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
// this is not a long-term solution, but it works ok for initial purposes of making the avatar lean
|
// 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;
|
_joint[ AVATAR_JOINT_TORSO ].springyPosition += headLean * 0.1f;
|
||||||
_joint[ AVATAR_JOINT_CHEST ].springyPosition += headLean * 0.4f;
|
_joint[ AVATAR_JOINT_CHEST ].springyPosition += headLean * 0.4f;
|
||||||
_joint[ AVATAR_JOINT_NECK_BASE ].springyPosition += headLean * 0.7f;
|
_joint[ AVATAR_JOINT_NECK_BASE ].springyPosition += headLean * 0.7f;
|
||||||
|
@ -388,14 +409,12 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// set head lookat position
|
// set head lookat position
|
||||||
if (_interactingOther) {
|
if ((_interactingOther)
|
||||||
_head.setLooking(true);
|
&& (_isMine)) {
|
||||||
|
|
||||||
if (_isMine) {
|
|
||||||
_head.setLookAtPosition(_interactingOther->getSpringyHeadPosition());
|
_head.setLookAtPosition(_interactingOther->getSpringyHeadPosition());
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
_head.setLooking(false);
|
_head.setLookAtPosition(glm::vec3(0.0f, 0.0f, 0.0f));
|
||||||
|
//_head.setLooking(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
_head.setBodyRotation (glm::vec3(_bodyPitch, _bodyYaw, _bodyRoll));
|
_head.setBodyRotation (glm::vec3(_bodyPitch, _bodyYaw, _bodyRoll));
|
||||||
|
|
|
@ -46,6 +46,7 @@ Head::Head() :
|
||||||
_returnSpringScale(1.0f),
|
_returnSpringScale(1.0f),
|
||||||
_bodyRotation(0.0f, 0.0f, 0.0f),
|
_bodyRotation(0.0f, 0.0f, 0.0f),
|
||||||
_headRotation(0.0f, 0.0f, 0.0f) {
|
_headRotation(0.0f, 0.0f, 0.0f) {
|
||||||
|
_lookingAtSomething = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Head::reset() {
|
void Head::reset() {
|
||||||
|
@ -99,6 +100,7 @@ void Head::simulate(float deltaTime, bool isMine) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
void Head::setLooking(bool looking) {
|
void Head::setLooking(bool looking) {
|
||||||
|
|
||||||
_lookingAtSomething = looking;
|
_lookingAtSomething = looking;
|
||||||
|
@ -111,8 +113,45 @@ void Head::setLooking(bool looking) {
|
||||||
_lookingAtSomething = false;
|
_lookingAtSomething = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
void Head::setLookAtPosition(const glm::vec3& lookAtPosition) {
|
||||||
|
|
||||||
|
_lookAtPosition = lookAtPosition;
|
||||||
|
|
||||||
|
if ( fabs(lookAtPosition.x + lookAtPosition.y + lookAtPosition.z) == 0.0 ) { // a lookatPosition of 0,0,0 signifies NOT looking
|
||||||
|
_lookingAtSomething = false;
|
||||||
|
} else {
|
||||||
|
_lookingAtSomething = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
glm::vec3 averageEyePosition = _leftEyePosition + (_rightEyePosition - _leftEyePosition ) * ONE_HALF;
|
||||||
|
glm::vec3 targetLookatAxis = glm::normalize(_lookAtPosition - averageEyePosition);
|
||||||
|
float dot = glm::dot(targetLookatAxis, _orientation.getFront());
|
||||||
|
if (dot < MINIMUM_EYE_ROTATION) {
|
||||||
|
_lookingAtSomething = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
if ( fabs(lookAtPosition.x + lookAtPosition.y + lookAtPosition.z) == 0.0 ) { // a lookatPosition of 0,0,0 signifies NOT looking
|
||||||
|
_lookingAtSomething = false;
|
||||||
|
} else {
|
||||||
|
glm::vec3 averageEyePosition = _leftEyePosition + (_rightEyePosition - _leftEyePosition ) * ONE_HALF;
|
||||||
|
glm::vec3 targetLookatAxis = glm::normalize(_lookAtPosition - averageEyePosition);
|
||||||
|
float dot = glm::dot(targetLookatAxis, _orientation.getFront());
|
||||||
|
if (dot < MINIMUM_EYE_ROTATION) {
|
||||||
|
_lookingAtSomething = false;
|
||||||
|
} else {
|
||||||
|
_lookAtPosition = lookAtPosition;
|
||||||
|
_lookingAtSomething = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Head::calculateGeometry(bool lookingInMirror) {
|
void Head::calculateGeometry(bool lookingInMirror) {
|
||||||
|
@ -405,6 +444,7 @@ void Head::renderEyeBalls() {
|
||||||
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);
|
||||||
glRotatef(180.0f, 0.0f, 1.0f, 0.0f); //adjust roll to correct after previous rotations
|
glRotatef(180.0f, 0.0f, 1.0f, 0.0f); //adjust roll to correct after previous rotations
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
//rotate the eyeball to aim straight ahead
|
//rotate the eyeball to aim straight ahead
|
||||||
|
|
|
@ -31,7 +31,7 @@ public:
|
||||||
void simulate(float deltaTime, bool isMine);
|
void simulate(float deltaTime, bool isMine);
|
||||||
void render(bool lookingInMirror);
|
void render(bool lookingInMirror);
|
||||||
|
|
||||||
void setLooking(bool looking);
|
//void setLooking(bool looking);
|
||||||
|
|
||||||
void setScale (float scale ) { _scale = scale; }
|
void setScale (float scale ) { _scale = scale; }
|
||||||
void setPosition (glm::vec3 position ) { _position = position; }
|
void setPosition (glm::vec3 position ) { _position = position; }
|
||||||
|
@ -44,6 +44,8 @@ public:
|
||||||
void setAudioLoudness (float audioLoudness ) { _audioLoudness = audioLoudness; }
|
void setAudioLoudness (float audioLoudness ) { _audioLoudness = audioLoudness; }
|
||||||
void setReturnToCenter (bool returnHeadToCenter) { _returnHeadToCenter = returnHeadToCenter; }
|
void setReturnToCenter (bool returnHeadToCenter) { _returnHeadToCenter = returnHeadToCenter; }
|
||||||
|
|
||||||
|
void setLookAtPosition (const glm::vec3& lookAtPosition); // overrides method in HeadData
|
||||||
|
|
||||||
const bool getReturnToCenter() const { return _returnHeadToCenter; } // Do you want head to try to return to center (depends on interface detected)
|
const bool getReturnToCenter() const { return _returnHeadToCenter; } // Do you want head to try to return to center (depends on interface detected)
|
||||||
float getAverageLoudness() {return _averageLoudness;};
|
float getAverageLoudness() {return _averageLoudness;};
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,7 @@ void HeadData::addRoll(float roll) {
|
||||||
setRoll(_roll + roll);
|
setRoll(_roll + roll);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void HeadData::addLean(float sideways, float forwards) {
|
void HeadData::addLean(float sideways, float forwards) {
|
||||||
// Add lean as impulse
|
// Add lean as impulse
|
||||||
_leanSideways += sideways;
|
_leanSideways += sideways;
|
||||||
|
|
Loading…
Reference in a new issue