Rear view zoom level

new zoom icons
save and restore state from settings
display zoomed out rear view when selected
This commit is contained in:
stojce 2013-10-29 20:51:14 +01:00
parent e106514af0
commit a14242632a
6 changed files with 100 additions and 31 deletions

Binary file not shown.

After

(image error) Size: 4.7 KiB

Binary file not shown.

After

(image error) Size: 4.3 KiB

View file

@ -89,6 +89,8 @@ const int MIRROR_VIEW_TOP_PADDING = 5;
const int MIRROR_VIEW_LEFT_PADDING = 10;
const int MIRROR_VIEW_WIDTH = 265;
const int MIRROR_VIEW_HEIGHT = 215;
const float MAX_ZOOM_DISTANCE = 0.3f;
const float MIN_ZOOM_DISTANCE = 2.0f;
void messageHandler(QtMsgType type, const QMessageLogContext& context, const QString &message) {
fprintf(stdout, "%s", message.toLocal8Bit().constData());
@ -384,7 +386,7 @@ void Application::paintGL() {
} else if (_myCamera.getMode() == CAMERA_MODE_MIRROR) {
_myCamera.setTightness(0.0f);
_myCamera.setDistance(0.3f);
_myCamera.setDistance(MAX_ZOOM_DISTANCE);
_myCamera.setTargetPosition(_myAvatar.getHead().calculateAverageEyePosition());
_myCamera.setTargetRotation(_myAvatar.getWorldAlignedOrientation() * glm::quat(glm::vec3(0.0f, PIf, 0.0f)));
}
@ -434,8 +436,15 @@ void Application::paintGL() {
_glowEffect.render();
if (Menu::getInstance()->isOptionChecked(MenuOption::Mirror)) {
_mirrorCamera.setDistance(0.3f);
_mirrorCamera.setTargetPosition(_myAvatar.getHead().calculateAverageEyePosition());
if (_rearMirrorTools->getZoomLevel() == BODY) {
_mirrorCamera.setDistance(MIN_ZOOM_DISTANCE);
_mirrorCamera.setTargetPosition(_myAvatar.getChestJointPosition());
} else { // HEAD zoom level
_mirrorCamera.setDistance(MAX_ZOOM_DISTANCE);
_mirrorCamera.setTargetPosition(_myAvatar.getHead().calculateAverageEyePosition());
}
_mirrorCamera.setTargetRotation(_myAvatar.getWorldAlignedOrientation() * glm::quat(glm::vec3(0.0f, PIf, 0.0f)));
_mirrorCamera.update(1.0f/_fps);
@ -1322,8 +1331,8 @@ void Application::terminate() {
// close(serial_fd);
LeapManager::terminate();
Menu::getInstance()->saveSettings();
_rearMirrorTools->saveSettings(_settings);
_settings->sync();
if (_enableNetworkThread) {
@ -1719,7 +1728,7 @@ void Application::init() {
_audio.init(_glWidget);
_rearMirrorTools = new RearMirrorTools(_glWidget, _mirrorViewRect);
_rearMirrorTools = new RearMirrorTools(_glWidget, _mirrorViewRect, _settings);
connect(_rearMirrorTools, SIGNAL(closeView()), SLOT(closeMirrorView()));
connect(_rearMirrorTools, SIGNAL(restoreView()), SLOT(restoreMirrorView()));
connect(_rearMirrorTools, SIGNAL(shrinkView()), SLOT(shrinkMirrorView()));

View file

@ -150,6 +150,7 @@ public:
SkeletonModel& getSkeletonModel() { return _skeletonModel; }
float getHeadYawRate() const { return _head.yawRate; }
const glm::vec3& getHeadJointPosition() const { return _skeleton.joint[ AVATAR_JOINT_HEAD_BASE ].position; }
const glm::vec3& getChestJointPosition() const { return _skeleton.joint[ AVATAR_JOINT_CHEST ].position; }
float getScale() const { return _scale; }
const glm::vec3& getVelocity() const { return _velocity; }
Head& getHead() { return _head; }

View file

@ -6,48 +6,81 @@
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
#include "RearMirrorTools.h"
#include "Util.h"
#include <SharedUtil.h>
#include <QMouseEvent>
const int ICON_SIZE = 16;
const char SETTINGS_GROUP_NAME[] = "Rear View Tools";
const char ZOOM_LEVEL_SETTINGS[] = "ZoomLevel";
const int ICON_SIZE = 20;
const int ICON_PADDING = 5;
const int MID_ICON_PADDING = 70;
RearMirrorTools::RearMirrorTools(QGLWidget* parent, QRect& bounds) : _parent(parent), _bounds(bounds), _windowed(false), _fullScreen(false) {
RearMirrorTools::RearMirrorTools(QGLWidget* parent, QRect& bounds, QSettings* settings) :
_parent(parent),
_bounds(bounds),
_windowed(false),
_fullScreen(false)
{
_zoomLevel = HEAD,
switchToResourcesParentIfRequired();
_closeTextureId = _parent->bindTexture(QImage("./resources/images/close.png"));
_resetTextureId = _parent->bindTexture(QImage("./resources/images/reset.png"));
_zoomHeadTextureId = _parent->bindTexture(QImage("./resources/images/head.png"));
_zoomBodyTextureId = _parent->bindTexture(QImage("./resources/images/body.png"));
_shrinkIconRect = QRect(ICON_PADDING, ICON_PADDING, ICON_SIZE, ICON_SIZE);
_closeIconRect = QRect(_bounds.left() + ICON_PADDING, _bounds.top() + ICON_PADDING, ICON_SIZE, ICON_SIZE);
_resetIconRect = QRect(_bounds.width() - ICON_SIZE - ICON_PADDING, _bounds.top() + ICON_PADDING, ICON_SIZE, ICON_SIZE);
_bodyZoomIconRect = QRect(_bounds.width() - MID_ICON_PADDING - ICON_SIZE, _bounds.bottom() - ICON_PADDING - ICON_SIZE, ICON_SIZE, ICON_SIZE);
_headZoomIconRect = QRect(_bounds.left() + MID_ICON_PADDING, _bounds.bottom() - ICON_PADDING - ICON_SIZE, ICON_SIZE, ICON_SIZE);
settings->beginGroup(SETTINGS_GROUP_NAME);
_zoomLevel = loadSetting(settings, ZOOM_LEVEL_SETTINGS, 0) == HEAD ? HEAD : BODY;
settings->endGroup();
};
void RearMirrorTools::render(bool fullScreen) {
if (fullScreen) {
_fullScreen = true;
displayIcon(_parent->geometry(), ICON_PADDING, ICON_PADDING, _closeTextureId);
displayIcon(_parent->geometry(), _shrinkIconRect, _closeTextureId);
} else {
// render rear view tools if mouse is in the bounds
QPoint mousePosition = _parent->mapFromGlobal(QCursor::pos());
_windowed = _bounds.contains(mousePosition.x(), mousePosition.y());
if (_windowed) {
displayIcon(_bounds, _bounds.left() + ICON_PADDING, _bounds.top() + ICON_PADDING, _closeTextureId);
displayIcon(_bounds, _bounds.width() - ICON_SIZE - ICON_PADDING, _bounds.top() + ICON_PADDING, _resetTextureId);
displayIcon(_bounds, _closeIconRect, _closeTextureId);
displayIcon(_bounds, _resetIconRect, _resetTextureId);
displayIcon(_bounds, _headZoomIconRect, _zoomHeadTextureId, _zoomLevel == HEAD);
displayIcon(_bounds, _bodyZoomIconRect, _zoomBodyTextureId, _zoomLevel == BODY);
}
}
}
bool RearMirrorTools::mousePressEvent(int x, int y) {
if (_windowed) {
QRect closeIconRect = QRect(_bounds.left() + ICON_PADDING, _bounds.top() + ICON_PADDING, ICON_SIZE, ICON_SIZE);
if (closeIconRect.contains(x, y)) {
if (_closeIconRect.contains(x, y)) {
_windowed = false;
emit closeView();
return true;
}
QRect resetIconRect = QRect(_bounds.width() - ICON_SIZE - ICON_PADDING, _bounds.top() + ICON_PADDING, ICON_SIZE, ICON_SIZE);
if (resetIconRect.contains(x, y)) {
if (_resetIconRect.contains(x, y)) {
emit resetView();
return true;
}
if (_headZoomIconRect.contains(x, y)) {
_zoomLevel = HEAD;
return true;
}
if (_bodyZoomIconRect.contains(x, y)) {
_zoomLevel = BODY;
return true;
}
if (_bounds.contains(x, y)) {
_windowed = false;
emit restoreView();
@ -56,8 +89,7 @@ bool RearMirrorTools::mousePressEvent(int x, int y) {
}
if (_fullScreen) {
QRect shrinkIconRect = QRect(ICON_PADDING, ICON_PADDING, ICON_SIZE, ICON_SIZE);
if (shrinkIconRect.contains(x, y)) {
if (_shrinkIconRect.contains(x, y)) {
_fullScreen = false;
emit shrinkView();
return true;
@ -66,10 +98,14 @@ bool RearMirrorTools::mousePressEvent(int x, int y) {
return false;
}
void RearMirrorTools::displayIcon(QRect bounds, int left, int top, GLuint textureId) {
void RearMirrorTools::saveSettings(QSettings* settings) {
settings->beginGroup(SETTINGS_GROUP_NAME);
settings->setValue(ZOOM_LEVEL_SETTINGS, _zoomLevel);
settings->endGroup();
}
void RearMirrorTools::displayIcon(QRect bounds, QRect iconBounds, GLuint textureId, bool selected) {
int twp = ICON_SIZE + top;
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
@ -78,23 +114,28 @@ void RearMirrorTools::displayIcon(QRect bounds, int left, int top, GLuint textur
glDisable(GL_DEPTH_TEST);
glDisable(GL_LIGHTING);
glEnable(GL_TEXTURE_2D);
glColor3f(1, 1, 1);
if (selected) {
glColor3f(1, 1, 0);
} else {
glColor3f(1, 1, 1);
}
glBindTexture(GL_TEXTURE_2D, textureId);
glBegin(GL_QUADS);
{
glTexCoord2f(0, 0);
glVertex2f(left, top);
glTexCoord2f(1, 0);
glVertex2f(ICON_SIZE + left, top);
glTexCoord2f(1, 1);
glVertex2f(ICON_SIZE + left, twp);
glVertex2f(iconBounds.left(), iconBounds.bottom());
glTexCoord2f(0, 1);
glVertex2f(left, twp);
glVertex2f(iconBounds.left(), iconBounds.top());
glTexCoord2f(1, 1);
glVertex2f(iconBounds.right(), iconBounds.top());
glTexCoord2f(1, 0);
glVertex2f(iconBounds.right(), iconBounds.bottom());
}
glEnd();
glPopMatrix();

View file

@ -12,13 +12,21 @@
#include "InterfaceConfig.h"
#include <QGLWidget>
#include <QSettings>
enum ZoomLevel {
HEAD,
BODY
};
class RearMirrorTools : public QObject {
Q_OBJECT
public:
RearMirrorTools(QGLWidget* parent, QRect& bounds);
RearMirrorTools(QGLWidget* parent, QRect& bounds, QSettings* settings);
void render(bool fullScreen);
bool mousePressEvent(int x, int y);
ZoomLevel getZoomLevel() { return _zoomLevel; }
void saveSettings(QSettings* settings);
signals:
void closeView();
@ -31,10 +39,20 @@ private:
QRect _bounds;
GLuint _closeTextureId;
GLuint _resetTextureId;
GLuint _zoomBodyTextureId;
GLuint _zoomHeadTextureId;
ZoomLevel _zoomLevel;
QRect _closeIconRect;
QRect _resetIconRect;
QRect _shrinkIconRect;
QRect _headZoomIconRect;
QRect _bodyZoomIconRect;
bool _windowed;
bool _fullScreen;
void displayIcon(QRect bounds, int left, int top, GLuint textureId);
void displayIcon(QRect bounds, QRect iconBounds, GLuint textureId, bool selected = false);
};
#endif /* defined(__hifi__RearMirrorTools__) */