mirror of
https://github.com/overte-org/overte.git
synced 2025-08-04 01:43:27 +02:00
added quicker follow code and added head to rotate calculation
This commit is contained in:
parent
456b8bf2a9
commit
1e3ca6f902
3 changed files with 38 additions and 18 deletions
|
@ -3797,7 +3797,7 @@ void MyAvatar::lateUpdatePalms() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static const float FOLLOW_TIME = 0.5f;
|
static const float FOLLOW_TIME = 0.1f;
|
||||||
|
|
||||||
MyAvatar::FollowHelper::FollowHelper() {
|
MyAvatar::FollowHelper::FollowHelper() {
|
||||||
deactivate();
|
deactivate();
|
||||||
|
@ -3902,8 +3902,13 @@ bool MyAvatar::FollowHelper::shouldActivateHorizontalCG(MyAvatar& myAvatar) cons
|
||||||
glm::vec3 defaultHeadPosition = myAvatar.getAbsoluteDefaultJointTranslationInObjectFrame(myAvatar.getJointIndex("Head"));
|
glm::vec3 defaultHeadPosition = myAvatar.getAbsoluteDefaultJointTranslationInObjectFrame(myAvatar.getJointIndex("Head"));
|
||||||
glm::vec3 currentHeadPosition = currentHeadPose.getTranslation();
|
glm::vec3 currentHeadPosition = currentHeadPose.getTranslation();
|
||||||
float anatomicalHeadToHipsDistance = glm::length(defaultHeadPosition - defaultHipsPosition);
|
float anatomicalHeadToHipsDistance = glm::length(defaultHeadPosition - defaultHipsPosition);
|
||||||
|
//if (!isActive(Horizontal) &&
|
||||||
|
// (glm::length(currentHeadPosition - defaultHipsPosition) > (anatomicalHeadToHipsDistance + DEFAULT_AVATAR_SPINE_STRETCH_LIMIT))) {
|
||||||
|
// myAvatar.setResetMode(true);
|
||||||
|
// stepDetected = true;
|
||||||
|
//}
|
||||||
if (!isActive(Horizontal) &&
|
if (!isActive(Horizontal) &&
|
||||||
(glm::length(currentHeadPosition - defaultHipsPosition) > (anatomicalHeadToHipsDistance + DEFAULT_AVATAR_SPINE_STRETCH_LIMIT))) {
|
(glm::length(currentHeadPosition - defaultHipsPosition) > (anatomicalHeadToHipsDistance + (DEFAULT_AVATAR_SPINE_STRETCH_LIMIT * anatomicalHeadToHipsDistance * myAvatar.getAvatarScale())))) {
|
||||||
myAvatar.setResetMode(true);
|
myAvatar.setResetMode(true);
|
||||||
stepDetected = true;
|
stepDetected = true;
|
||||||
}
|
}
|
||||||
|
@ -3925,10 +3930,15 @@ void MyAvatar::FollowHelper::prePhysicsUpdate(MyAvatar& myAvatar, const glm::mat
|
||||||
|
|
||||||
if (myAvatar.getHMDLeanRecenterEnabled() &&
|
if (myAvatar.getHMDLeanRecenterEnabled() &&
|
||||||
qApp->getCamera().getMode() != CAMERA_MODE_MIRROR) {
|
qApp->getCamera().getMode() != CAMERA_MODE_MIRROR) {
|
||||||
if (!isActive(Rotation) && (shouldActivateRotation(myAvatar, desiredBodyMatrix, currentBodyMatrix) || hasDriveInput)) {
|
if (!isActive(Rotation) && getForceActivateRotation()) {
|
||||||
activate(Rotation);
|
activate(Rotation);
|
||||||
myAvatar.setHeadControllerFacingMovingAverage(myAvatar._headControllerFacing);
|
myAvatar.setHeadControllerFacingMovingAverage(myAvatar._headControllerFacing);
|
||||||
|
setForceActivateRotation(false);
|
||||||
}
|
}
|
||||||
|
//if (!isActive(Rotation) && (shouldActivateRotation(myAvatar, desiredBodyMatrix, currentBodyMatrix) || hasDriveInput)) {
|
||||||
|
// activate(Rotation);
|
||||||
|
// myAvatar.setHeadControllerFacingMovingAverage(myAvatar._headControllerFacing);
|
||||||
|
//}
|
||||||
if (myAvatar.getCenterOfGravityModelEnabled()) {
|
if (myAvatar.getCenterOfGravityModelEnabled()) {
|
||||||
if (!isActive(Horizontal) && (shouldActivateHorizontalCG(myAvatar) || hasDriveInput)) {
|
if (!isActive(Horizontal) && (shouldActivateHorizontalCG(myAvatar) || hasDriveInput)) {
|
||||||
activate(Horizontal);
|
activate(Horizontal);
|
||||||
|
@ -3937,11 +3947,6 @@ void MyAvatar::FollowHelper::prePhysicsUpdate(MyAvatar& myAvatar, const glm::mat
|
||||||
myAvatar.setHeadControllerFacingMovingAverage(myAvatar._headControllerFacing);
|
myAvatar.setHeadControllerFacingMovingAverage(myAvatar._headControllerFacing);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!isActive(Rotation) && getForceActivateRotation()) {
|
|
||||||
activate(Rotation);
|
|
||||||
myAvatar.setHeadControllerFacingMovingAverage(myAvatar._headControllerFacing);
|
|
||||||
setForceActivateRotation(false);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (!isActive(Horizontal) && (shouldActivateHorizontal(myAvatar, desiredBodyMatrix, currentBodyMatrix) || hasDriveInput)) {
|
if (!isActive(Horizontal) && (shouldActivateHorizontal(myAvatar, desiredBodyMatrix, currentBodyMatrix) || hasDriveInput)) {
|
||||||
activate(Horizontal);
|
activate(Horizontal);
|
||||||
|
|
|
@ -34,7 +34,7 @@ const float DEFAULT_HANDS_ANGULAR_VELOCITY_STEPPING_THRESHOLD = 3.3f;
|
||||||
const float DEFAULT_HEAD_VELOCITY_STEPPING_THRESHOLD = 0.18f;
|
const float DEFAULT_HEAD_VELOCITY_STEPPING_THRESHOLD = 0.18f;
|
||||||
const float DEFAULT_HEAD_PITCH_STEPPING_TOLERANCE = 7.0f;
|
const float DEFAULT_HEAD_PITCH_STEPPING_TOLERANCE = 7.0f;
|
||||||
const float DEFAULT_HEAD_ROLL_STEPPING_TOLERANCE = 7.0f;
|
const float DEFAULT_HEAD_ROLL_STEPPING_TOLERANCE = 7.0f;
|
||||||
const float DEFAULT_AVATAR_SPINE_STRETCH_LIMIT = 0.07f;
|
const float DEFAULT_AVATAR_SPINE_STRETCH_LIMIT = 0.05f;
|
||||||
const float DEFAULT_AVATAR_FORWARD_DAMPENING_FACTOR = 0.5f;
|
const float DEFAULT_AVATAR_FORWARD_DAMPENING_FACTOR = 0.5f;
|
||||||
const float DEFAULT_AVATAR_LATERAL_DAMPENING_FACTOR = 2.0f;
|
const float DEFAULT_AVATAR_LATERAL_DAMPENING_FACTOR = 2.0f;
|
||||||
const float DEFAULT_AVATAR_HIPS_MASS = 40.0f;
|
const float DEFAULT_AVATAR_HIPS_MASS = 40.0f;
|
||||||
|
|
|
@ -259,7 +259,7 @@ function limitAngle(angle) {
|
||||||
return (angle + 180) % 360 - 180;
|
return (angle + 180) % 360 - 180;
|
||||||
}
|
}
|
||||||
|
|
||||||
function computeHandAzimuths() {
|
function computeHandAzimuths(timeElapsed) {
|
||||||
var leftHand = currentStateReadings.lhandPose.translation;
|
var leftHand = currentStateReadings.lhandPose.translation;
|
||||||
var rightHand = currentStateReadings.rhandPose.translation;
|
var rightHand = currentStateReadings.rhandPose.translation;
|
||||||
var head = currentStateReadings.headPose.translation;
|
var head = currentStateReadings.headPose.translation;
|
||||||
|
@ -272,8 +272,9 @@ function computeHandAzimuths() {
|
||||||
var avatarZAxis = { x: 0.0, y: 0.0, z: 1.0 };
|
var avatarZAxis = { x: 0.0, y: 0.0, z: 1.0 };
|
||||||
var hipToLHand = Quat.lookAtSimple({ x: 0, y: 0, z: 0 }, lHandMinusHead);
|
var hipToLHand = Quat.lookAtSimple({ x: 0, y: 0, z: 0 }, lHandMinusHead);
|
||||||
var hipToRHand = Quat.lookAtSimple({ x: 0, y: 0, z: 0 }, rHandMinusHead);
|
var hipToRHand = Quat.lookAtSimple({ x: 0, y: 0, z: 0 }, rHandMinusHead);
|
||||||
hipToLHandAverage = Quat.slerp(hipToLHandAverage, hipToLHand, AVERAGING_RATE);
|
var tau = timeElapsed / filterLengthProperty.value;
|
||||||
hipToRHandAverage = Quat.slerp(hipToRHandAverage, hipToRHand, AVERAGING_RATE);
|
hipToLHandAverage = Quat.slerp(hipToLHandAverage, hipToLHand, tau);
|
||||||
|
hipToRHandAverage = Quat.slerp(hipToRHandAverage, hipToRHand, tau);
|
||||||
|
|
||||||
// var angleToLeft = limitAngle(Quat.safeEulerAngles(hipToLHandAverage).y);
|
// var angleToLeft = limitAngle(Quat.safeEulerAngles(hipToLHandAverage).y);
|
||||||
// var angleToRight = limitAngle(Quat.safeEulerAngles(hipToRHandAverage).y);
|
// var angleToRight = limitAngle(Quat.safeEulerAngles(hipToRHandAverage).y);
|
||||||
|
@ -283,11 +284,7 @@ function computeHandAzimuths() {
|
||||||
// limit the angle because we are flipped by 180, fix this tomorrow.
|
// limit the angle because we are flipped by 180, fix this tomorrow.
|
||||||
// print(leftRightMidpointAverage/180.0);
|
// print(leftRightMidpointAverage/180.0);
|
||||||
// print("threshold value " + angleThresholdProperty.value);
|
// print("threshold value " + angleThresholdProperty.value);
|
||||||
// get it into radians too!!
|
|
||||||
if ((Math.abs(leftRightMidpointAverage/180.0) * Math.PI) > angleThresholdProperty.value) {
|
|
||||||
print("recenter the feet under the head");
|
|
||||||
MyAvatar.triggerRotationRecenter();
|
|
||||||
}
|
|
||||||
|
|
||||||
var raySpineRotation = Quat.fromVec3Degrees({ x: 0, y: leftRightMidpointAverage, z: 0 });
|
var raySpineRotation = Quat.fromVec3Degrees({ x: 0, y: leftRightMidpointAverage, z: 0 });
|
||||||
var zAxisSpineRotation = Vec3.multiplyQbyV(raySpineRotation, { x: 0, y: 0, z: -1 });
|
var zAxisSpineRotation = Vec3.multiplyQbyV(raySpineRotation, { x: 0, y: 0, z: -1 });
|
||||||
|
@ -295,6 +292,22 @@ function computeHandAzimuths() {
|
||||||
DebugDraw.drawRay(MyAvatar.position, Vec3.sum(MyAvatar.position, zAxisWorldSpace), { x: 1, y: 0, z: 0, w: 1 });
|
DebugDraw.drawRay(MyAvatar.position, Vec3.sum(MyAvatar.position, zAxisWorldSpace), { x: 1, y: 0, z: 0, w: 1 });
|
||||||
|
|
||||||
//print(leftRightMidpoint);
|
//print(leftRightMidpoint);
|
||||||
|
|
||||||
|
var headPoseRigSpace = Quat.multiply(CHANGE_OF_BASIS_ROTATION, currentStateReadings.head.rotation);
|
||||||
|
headPoseAverageOrientation = Quat.slerp(headPoseAverageOrientation, headPoseRigSpace, tau);
|
||||||
|
var headPoseAverageEulers = Quat.safeEulerAngles(headPoseAverageOrientation);
|
||||||
|
|
||||||
|
// get it into radians too!!
|
||||||
|
// average head and hands 50/50
|
||||||
|
print("hands azimuth " + leftRightMidpointAverage + " head azimuth " + headPoseAverageEulers.y)
|
||||||
|
var headPlusHands = (leftRightMidpointAverage + headPoseAverageEulers.y) / 2.0;
|
||||||
|
if ((Math.abs(headPlusHands / 180.0) * Math.PI) > angleThresholdProperty.value) {
|
||||||
|
print("recenter the feet under the head");
|
||||||
|
MyAvatar.triggerRotationRecenter();
|
||||||
|
hipToLHandAverage = { x: 0, y: 0, z: 0, w: 1 };
|
||||||
|
hipToRHandAverage = { x: 0, y: 0, z: 0, w: 1 };
|
||||||
|
headPoseAverageOrientation = { x: 0, y: 0, z: 0, w: 1 };
|
||||||
|
}
|
||||||
|
|
||||||
return Quat.fromVec3Degrees({ x: 0, y: leftRightMidpoint, z: 0 });
|
return Quat.fromVec3Degrees({ x: 0, y: leftRightMidpoint, z: 0 });
|
||||||
|
|
||||||
|
@ -309,7 +322,9 @@ function update(dt) {
|
||||||
|
|
||||||
//print(JSON.stringify(currentStateReadings.head));
|
//print(JSON.stringify(currentStateReadings.head));
|
||||||
|
|
||||||
var latestSpineRotation = computeHandAzimuths();
|
|
||||||
|
|
||||||
|
var latestSpineRotation = computeHandAzimuths(dt);
|
||||||
|
|
||||||
spine2Rotation = latestSpineRotation;
|
spine2Rotation = latestSpineRotation;
|
||||||
var spine2Pos = MyAvatar.getAbsoluteJointTranslationInObjectFrame(MyAvatar.getJointIndex("Spine2"));
|
var spine2Pos = MyAvatar.getAbsoluteJointTranslationInObjectFrame(MyAvatar.getJointIndex("Spine2"));
|
||||||
|
|
Loading…
Reference in a new issue