mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-05 14:47:16 +02:00
Tweaks to improve mouse Yaw behavior.
This commit is contained in:
parent
a36d32e101
commit
b2709652b4
2 changed files with 28 additions and 7 deletions
|
@ -101,7 +101,9 @@ Avatar::Avatar(bool isMine) {
|
||||||
_sphere = NULL;
|
_sphere = NULL;
|
||||||
_handHoldingPosition = glm::vec3(0.0f, 0.0f, 0.0f);
|
_handHoldingPosition = glm::vec3(0.0f, 0.0f, 0.0f);
|
||||||
_distanceToNearestAvatar = std::numeric_limits<float>::max();
|
_distanceToNearestAvatar = std::numeric_limits<float>::max();
|
||||||
_gravity = glm::vec3(0.0f, -1.0f, 0.0f); // default
|
_gravity = glm::vec3(0.0f, -1.0f, 0.0f);
|
||||||
|
_cumulativeMouseYaw = 0.f;
|
||||||
|
_isMouseTurningRight = false;
|
||||||
|
|
||||||
initializeSkeleton();
|
initializeSkeleton();
|
||||||
|
|
||||||
|
@ -292,16 +294,33 @@ bool Avatar::getIsNearInteractingOther() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Avatar::updateFromMouse(int mouseX, int mouseY, int screenWidth, int screenHeight) {
|
void Avatar::updateFromMouse(int mouseX, int mouseY, int screenWidth, int screenHeight) {
|
||||||
// Update pitch and yaw based on mouse behavior
|
// Update yaw based on mouse behavior
|
||||||
const float MOUSE_MOVE_RADIUS = 0.25f;
|
const float MOUSE_MOVE_RADIUS = 0.25f;
|
||||||
const float MOUSE_ROTATE_SPEED = 7.5f;
|
const float MOUSE_ROTATE_SPEED = 7.5f;
|
||||||
|
const float MAX_YAW_TO_ADD = 180.f;
|
||||||
float mouseLocationX = (float)mouseX / (float)screenWidth - 0.5f;
|
float mouseLocationX = (float)mouseX / (float)screenWidth - 0.5f;
|
||||||
|
|
||||||
if (fabs(mouseLocationX) > MOUSE_MOVE_RADIUS) {
|
printLog("mouse %d, %d\n", mouseX, mouseY);
|
||||||
float mouseMag = (fabs(mouseLocationX) - MOUSE_MOVE_RADIUS) / (0.5f - MOUSE_MOVE_RADIUS) * MOUSE_ROTATE_SPEED;
|
|
||||||
setBodyYaw(getBodyYaw() - ((mouseLocationX > 0.f) ? mouseMag : -mouseMag));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if ((fabs(mouseLocationX) > MOUSE_MOVE_RADIUS) &&
|
||||||
|
(mouseX > 1) &&
|
||||||
|
(mouseX < screenWidth) &&
|
||||||
|
(mouseY > 1) &&
|
||||||
|
(mouseY < screenHeight)) {
|
||||||
|
float mouseYawAdd = (fabs(mouseLocationX) - MOUSE_MOVE_RADIUS) / (0.5f - MOUSE_MOVE_RADIUS) * MOUSE_ROTATE_SPEED;
|
||||||
|
bool rightTurning = (mouseLocationX > 0.f);
|
||||||
|
if (_isMouseTurningRight == rightTurning) {
|
||||||
|
_cumulativeMouseYaw += mouseYawAdd;
|
||||||
|
} else {
|
||||||
|
_cumulativeMouseYaw = 0;
|
||||||
|
_isMouseTurningRight = rightTurning;
|
||||||
|
}
|
||||||
|
if (_cumulativeMouseYaw < MAX_YAW_TO_ADD) {
|
||||||
|
setBodyYaw(getBodyYaw() - (rightTurning ? mouseYawAdd : -mouseYawAdd));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
_cumulativeMouseYaw = 0;
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -200,6 +200,8 @@ private:
|
||||||
glm::vec3 _mouseRayOrigin;
|
glm::vec3 _mouseRayOrigin;
|
||||||
glm::vec3 _mouseRayDirection;
|
glm::vec3 _mouseRayDirection;
|
||||||
glm::vec3 _cameraPosition;
|
glm::vec3 _cameraPosition;
|
||||||
|
float _cumulativeMouseYaw;
|
||||||
|
bool _isMouseTurningRight;
|
||||||
|
|
||||||
//AvatarJointID _jointTouched;
|
//AvatarJointID _jointTouched;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue