Merge pull request #502 from ey6es/gyroquat

Increase YAW_DECAY, remove roll from head camera, provide option for pitch/yaw scale (zero by default).
This commit is contained in:
ZappoMan 2013-06-07 09:17:11 -07:00
commit ece117e0b0
5 changed files with 20 additions and 8 deletions

View file

@ -26,6 +26,7 @@
#include <QColorDialog>
#include <QDialogButtonBox>
#include <QDesktopWidget>
#include <QDoubleSpinBox>
#include <QFormLayout>
#include <QGLWidget>
#include <QKeyEvent>
@ -311,11 +312,11 @@ void Application::paintGL() {
} else if (_myCamera.getMode() == CAMERA_MODE_FIRST_PERSON) {
_myCamera.setTightness(0.0f); // In first person, camera follows head exactly without delay
_myCamera.setTargetPosition(_myAvatar.getBallPosition(AVATAR_JOINT_HEAD_BASE));
_myCamera.setTargetRotation(_myAvatar.getHead().getWorldAlignedOrientation());
_myCamera.setTargetRotation(_myAvatar.getHead().getCameraOrientation(_headCameraPitchYawScale));
} else if (_myCamera.getMode() == CAMERA_MODE_THIRD_PERSON) {
_myCamera.setTargetPosition(_myAvatar.getHeadJointPosition());
_myCamera.setTargetRotation(_myAvatar.getHead().getWorldAlignedOrientation());
_myCamera.setTargetRotation(_myAvatar.getHead().getCameraOrientation(_headCameraPitchYawScale));
}
// Update camera position
@ -1026,6 +1027,10 @@ void Application::editPreferences() {
avatarURL->setMinimumWidth(400);
form->addRow("Avatar URL:", avatarURL);
QDoubleSpinBox* headCameraPitchYawScale = new QDoubleSpinBox();
headCameraPitchYawScale->setValue(_headCameraPitchYawScale);
form->addRow("Head Camera Pitch/Yaw Scale:", headCameraPitchYawScale);
QDialogButtonBox* buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
dialog.connect(buttons, SIGNAL(accepted()), SLOT(accept()));
dialog.connect(buttons, SIGNAL(rejected()), SLOT(reject()));
@ -1038,6 +1043,8 @@ void Application::editPreferences() {
_settings->setValue("avatarURL", url);
_myAvatar.getVoxels()->setVoxelURL(url);
sendAvatarVoxelURLMessage(url);
_headCameraPitchYawScale = headCameraPitchYawScale->value();
}
void Application::pair() {
@ -2537,15 +2544,19 @@ void Application::setAutosave(bool wantsAutosave) {
void Application::loadSettings(QSettings* set) {
if (!set) set = getSettings();
_headCameraPitchYawScale = set->value("headCameraPitchYawScale", 0.0f).toFloat();
scanMenuBar(&Application::loadAction, set);
getAvatar()->loadData(set);
getAvatar()->loadData(set);
}
void Application::saveSettings(QSettings* set) {
if (!set) set = getSettings();
set->setValue("headCameraPitchYawScale", _headCameraPitchYawScale);
scanMenuBar(&Application::saveAction, set);
getAvatar()->saveData(set);
set->sync();
}
void Application::importSettings() {

View file

@ -248,6 +248,7 @@ private:
int _headMouseX, _headMouseY;
bool _manualFirstPerson;
float _headCameraPitchYawScale;
HandControl _handControl;

View file

@ -314,10 +314,10 @@ glm::quat Head::getOrientation() const {
glm::vec3(_pitch, -_yaw, -_roll) : glm::vec3(_pitch, _yaw, _roll)));
}
glm::quat Head::getWorldAlignedOrientation () const {
glm::quat Head::getCameraOrientation (float pitchYawScale) const {
Avatar* owningAvatar = static_cast<Avatar*>(_owningAvatar);
return owningAvatar->getWorldAlignedOrientation() * glm::quat(glm::radians(_lookingInMirror ?
glm::vec3(_pitch, -_yaw, -_roll) : glm::vec3(_pitch, _yaw, _roll)));
return owningAvatar->getWorldAlignedOrientation() * glm::quat(glm::radians(glm::vec3(
_pitch * pitchYawScale, _yaw * pitchYawScale, 0.0f)));
}
void Head::renderHeadSphere() {

View file

@ -47,7 +47,7 @@ public:
void setRenderLookatVectors(bool onOff ) { _renderLookatVectors = onOff; }
glm::quat getOrientation() const;
glm::quat getWorldAlignedOrientation () const;
glm::quat getCameraOrientation (float pitchYawScale) const;
glm::vec3 getRightDirection() const { return getOrientation() * IDENTITY_RIGHT; }
glm::vec3 getUpDirection () const { return getOrientation() * IDENTITY_UP; }

View file

@ -264,7 +264,7 @@ void SerialInterface::readData(float deltaTime) {
1.0f / SENSOR_FUSION_SAMPLES);
// Without a compass heading, always decay estimated Yaw slightly
const float YAW_DECAY = 0.995;
const float YAW_DECAY = 0.999f;
glm::vec3 forward = estimatedRotation * glm::vec3(0.0f, 0.0f, -1.0f);
estimatedRotation = safeMix(glm::angleAxis(glm::degrees(atan2f(forward.x, -forward.z)),
glm::vec3(0.0f, 1.0f, 0.0f)) * estimatedRotation, estimatedRotation, YAW_DECAY);