mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-04 08:13:13 +02:00
Treat pitchFromTouch more like yawFromTouch, persist mouse pitch.
This commit is contained in:
parent
60f5681a76
commit
91b38313be
5 changed files with 23 additions and 17 deletions
|
@ -2192,10 +2192,8 @@ void Application::updateHandAndTouch(float deltaTime) {
|
|||
float TOUCH_YAW_SCALE = -0.25f;
|
||||
float TOUCH_PITCH_SCALE = -12.5f;
|
||||
float FIXED_TOUCH_TIMESTEP = 0.016f;
|
||||
const float MAX_PITCH = 90.0f;
|
||||
_yawFromTouch += ((_touchAvgX - _lastTouchAvgX) * TOUCH_YAW_SCALE * FIXED_TOUCH_TIMESTEP);
|
||||
_pitchFromTouch = glm::clamp(_pitchFromTouch + (_touchAvgY - _lastTouchAvgY) * TOUCH_PITCH_SCALE *
|
||||
FIXED_TOUCH_TIMESTEP, -MAX_PITCH, MAX_PITCH);
|
||||
_pitchFromTouch += ((_touchAvgY - _lastTouchAvgY) * TOUCH_PITCH_SCALE * FIXED_TOUCH_TIMESTEP);
|
||||
_lastTouchAvgX = _touchAvgX;
|
||||
_lastTouchAvgY = _touchAvgY;
|
||||
}
|
||||
|
@ -2447,8 +2445,12 @@ void Application::updateAvatar(float deltaTime) {
|
|||
* glm::quat(glm::vec3(0, _yawFromTouch, 0)));
|
||||
_yawFromTouch = 0.f;
|
||||
|
||||
// apply pitch from touch
|
||||
_myAvatar.getHead().setMousePitch(_myAvatar.getHead().getMousePitch() + _pitchFromTouch);
|
||||
_pitchFromTouch = 0.0f;
|
||||
|
||||
// Update my avatar's state from gyros and/or webcam
|
||||
_myAvatar.updateFromGyrosAndOrWebcam(_pitchFromTouch, Menu::getInstance()->isOptionChecked(MenuOption::TurnWithHead));
|
||||
_myAvatar.updateFromGyrosAndOrWebcam(Menu::getInstance()->isOptionChecked(MenuOption::TurnWithHead));
|
||||
|
||||
// Update head mouse from faceshift if active
|
||||
if (_faceshift.isActive()) {
|
||||
|
@ -2504,8 +2506,8 @@ void Application::updateAvatar(float deltaTime) {
|
|||
float yaw, pitch, roll;
|
||||
OculusManager::getEulerAngles(yaw, pitch, roll);
|
||||
|
||||
_myAvatar.getHead().setYaw(yaw + _yawFromTouch);
|
||||
_myAvatar.getHead().setPitch(pitch + _pitchFromTouch);
|
||||
_myAvatar.getHead().setYaw(yaw);
|
||||
_myAvatar.getHead().setPitch(pitch);
|
||||
_myAvatar.getHead().setRoll(roll);
|
||||
}
|
||||
|
||||
|
|
|
@ -109,6 +109,7 @@ void Head::init() {
|
|||
|
||||
void Head::reset() {
|
||||
_yaw = _pitch = _roll = 0.0f;
|
||||
_mousePitch = 0.0f;
|
||||
_leanForward = _leanSideways = 0.0f;
|
||||
|
||||
if (USING_PHYSICAL_MOHAWK) {
|
||||
|
@ -325,6 +326,10 @@ void Head::setScale (float scale) {
|
|||
}
|
||||
}
|
||||
|
||||
void Head::setMousePitch(float mousePitch) {
|
||||
const float MAX_PITCH = 90.0f;
|
||||
_mousePitch = glm::clamp(mousePitch, -MAX_PITCH, MAX_PITCH);
|
||||
}
|
||||
|
||||
void Head::createMohawk() {
|
||||
srand(time(NULL));
|
||||
|
|
|
@ -58,7 +58,7 @@ public:
|
|||
void setRenderLookatVectors(bool onOff) { _renderLookatVectors = onOff; }
|
||||
|
||||
float getMousePitch() const { return _mousePitch; }
|
||||
void setMousePitch(float mousePitch) { _mousePitch = mousePitch; }
|
||||
void setMousePitch(float mousePitch);
|
||||
|
||||
glm::quat getOrientation() const;
|
||||
glm::quat getCameraOrientation () const;
|
||||
|
|
|
@ -43,7 +43,6 @@ MyAvatar::MyAvatar(Node* owningNode) :
|
|||
_mousePressed(false),
|
||||
_bodyPitchDelta(0.0f),
|
||||
_bodyRollDelta(0.0f),
|
||||
_mousePitchDelta(0.0f),
|
||||
_shouldJump(false),
|
||||
_gravity(0.0f, -1.0f, 0.0f),
|
||||
_distanceToNearestAvatar(std::numeric_limits<float>::max()),
|
||||
|
@ -373,13 +372,12 @@ void MyAvatar::simulate(float deltaTime, Transmitter* transmitter) {
|
|||
const float MAX_PITCH = 90.0f;
|
||||
|
||||
// Update avatar head rotation with sensor data
|
||||
void MyAvatar::updateFromGyrosAndOrWebcam(float pitchFromTouch, bool turnWithHead) {
|
||||
void MyAvatar::updateFromGyrosAndOrWebcam(bool turnWithHead) {
|
||||
Faceshift* faceshift = Application::getInstance()->getFaceshift();
|
||||
SerialInterface* gyros = Application::getInstance()->getSerialHeadSensor();
|
||||
Webcam* webcam = Application::getInstance()->getWebcam();
|
||||
glm::vec3 estimatedPosition, estimatedRotation;
|
||||
|
||||
float combinedPitch = glm::clamp(pitchFromTouch + _mousePitchDelta, -MAX_PITCH, MAX_PITCH);
|
||||
if (faceshift->isActive()) {
|
||||
estimatedPosition = faceshift->getHeadTranslation();
|
||||
estimatedRotation = safeEulerAngles(faceshift->getHeadRotation());
|
||||
|
@ -400,8 +398,7 @@ void MyAvatar::updateFromGyrosAndOrWebcam(float pitchFromTouch, bool turnWithHea
|
|||
|
||||
} else {
|
||||
if (!_leadingAvatar) {
|
||||
_head.setMousePitch(combinedPitch);
|
||||
_head.setPitch(combinedPitch);
|
||||
_head.setPitch(_head.getMousePitch());
|
||||
}
|
||||
_head.getVideoFace().clearFrame();
|
||||
|
||||
|
@ -413,7 +410,6 @@ void MyAvatar::updateFromGyrosAndOrWebcam(float pitchFromTouch, bool turnWithHea
|
|||
_head.setLeanForward(glm::mix(_head.getLeanForward(), 0.0f, RESTORE_RATE));
|
||||
return;
|
||||
}
|
||||
_head.setMousePitch(combinedPitch);
|
||||
|
||||
if (webcam->isActive()) {
|
||||
estimatedPosition = webcam->getEstimatedPosition();
|
||||
|
@ -572,6 +568,8 @@ void MyAvatar::saveData(QSettings* settings) {
|
|||
settings->setValue("bodyPitch", _bodyPitch);
|
||||
settings->setValue("bodyRoll", _bodyRoll);
|
||||
|
||||
settings->setValue("mousePitch", _head.getMousePitch());
|
||||
|
||||
settings->setValue("position_x", _position.x);
|
||||
settings->setValue("position_y", _position.y);
|
||||
settings->setValue("position_z", _position.z);
|
||||
|
@ -592,6 +590,9 @@ void MyAvatar::loadData(QSettings* settings) {
|
|||
_bodyYaw = loadSetting(settings, "bodyYaw", 0.0f);
|
||||
_bodyPitch = loadSetting(settings, "bodyPitch", 0.0f);
|
||||
_bodyRoll = loadSetting(settings, "bodyRoll", 0.0f);
|
||||
|
||||
_head.setMousePitch(loadSetting(settings, "mousePitch", 0.0f));
|
||||
|
||||
_position.x = loadSetting(settings, "position_x", 0.0f);
|
||||
_position.y = loadSetting(settings, "position_y", 0.0f);
|
||||
_position.z = loadSetting(settings, "position_z", 0.0f);
|
||||
|
@ -743,8 +744,7 @@ void MyAvatar::updateThrust(float deltaTime, Transmitter * transmitter) {
|
|||
_thrust -= _driveKeys[DOWN] * _scale * THRUST_MAG_DOWN * _thrustMultiplier * deltaTime * up;
|
||||
_bodyYawDelta -= _driveKeys[ROT_RIGHT] * YAW_MAG * deltaTime;
|
||||
_bodyYawDelta += _driveKeys[ROT_LEFT] * YAW_MAG * deltaTime;
|
||||
_mousePitchDelta = min(_mousePitchDelta + _driveKeys[ROT_UP] * PITCH_MAG * deltaTime, MAX_PITCH);
|
||||
_mousePitchDelta = max(_mousePitchDelta - _driveKeys[ROT_DOWN] * PITCH_MAG * deltaTime, -MAX_PITCH);
|
||||
_head.setMousePitch(_head.getMousePitch() + (_driveKeys[ROT_UP] - _driveKeys[ROT_DOWN]) * PITCH_MAG * deltaTime);
|
||||
|
||||
// If thrust keys are being held down, slowly increase thrust to allow reaching great speeds
|
||||
if (_driveKeys[FWD] || _driveKeys[BACK] || _driveKeys[RIGHT] || _driveKeys[LEFT] || _driveKeys[UP] || _driveKeys[DOWN]) {
|
||||
|
|
|
@ -19,7 +19,7 @@ public:
|
|||
|
||||
void reset();
|
||||
void simulate(float deltaTime, Transmitter* transmitter);
|
||||
void updateFromGyrosAndOrWebcam(float pitchFromTouch, bool turnWithHead);
|
||||
void updateFromGyrosAndOrWebcam(bool turnWithHead);
|
||||
void render(bool forceRenderHead, bool renderAvatarBalls);
|
||||
void renderScreenTint(ScreenTintLayer layer);
|
||||
|
||||
|
@ -66,7 +66,6 @@ private:
|
|||
bool _mousePressed;
|
||||
float _bodyPitchDelta;
|
||||
float _bodyRollDelta;
|
||||
float _mousePitchDelta;
|
||||
bool _shouldJump;
|
||||
float _driveKeys[MAX_DRIVE_KEYS];
|
||||
glm::vec3 _gravity;
|
||||
|
|
Loading…
Reference in a new issue