Added camera FOV control (and better initial fov)

This commit is contained in:
Michaël Lemaire 2013-12-30 14:59:42 +01:00 committed by Michael Lemaire
parent 134158c33a
commit eb795b0f83
6 changed files with 39 additions and 1 deletions

View file

@ -17,7 +17,7 @@ CameraDefinition::CameraDefinition():
width = 1.0; width = 1.0;
height = 1.0; height = 1.0;
perspective.yfov = 1.57; perspective.yfov = 1.0;
perspective.xratio = 1.0; perspective.xratio = 1.0;
perspective.znear = 1.0; perspective.znear = 1.0;
perspective.zfar = 1000.0; perspective.zfar = 1000.0;
@ -32,6 +32,7 @@ void CameraDefinition::save(PackStream* stream) const
stream->write(&direction.phi); stream->write(&direction.phi);
stream->write(&direction.theta); stream->write(&direction.theta);
stream->write(&roll); stream->write(&roll);
stream->write(&perspective.yfov);
} }
void CameraDefinition::load(PackStream* stream) void CameraDefinition::load(PackStream* stream)
@ -41,6 +42,7 @@ void CameraDefinition::load(PackStream* stream)
stream->read(&direction.phi); stream->read(&direction.phi);
stream->read(&direction.theta); stream->read(&direction.theta);
stream->read(&roll); stream->read(&roll);
stream->read(&perspective.yfov);
validate(); validate();
} }
@ -53,6 +55,8 @@ void CameraDefinition::copy(BaseDefinition* _destination) const
destination->direction = direction; destination->direction = direction;
destination->roll = roll; destination->roll = roll;
destination->perspective = perspective;
destination->validate(); destination->validate();
} }
@ -143,6 +147,13 @@ void CameraDefinition::setZoomToTarget(double zoom)
validate(); validate();
} }
void CameraDefinition::setFov(double fov)
{
perspective.yfov = fov;
validate();
}
void CameraDefinition::strafeForward(double value) void CameraDefinition::strafeForward(double value)
{ {
location = location.add(forward.scale(value)); location = location.add(forward.scale(value));

View file

@ -48,6 +48,7 @@ public:
void setTargetCoords(double x, double y, double z); void setTargetCoords(double x, double y, double z);
void setRoll(double angle); void setRoll(double angle);
void setZoomToTarget(double zoom); void setZoomToTarget(double zoom);
void setFov(double fov);
void strafeForward(double value); void strafeForward(double value);
void strafeRight(double value); void strafeRight(double value);

View file

@ -4,6 +4,7 @@
#include <QPushButton> #include <QPushButton>
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QLabel> #include <QLabel>
#include <QSlider>
#include "WidgetExplorer.h" #include "WidgetExplorer.h"
#include "DesktopScenery.h" #include "DesktopScenery.h"
#include "CameraDefinition.h" #include "CameraDefinition.h"
@ -12,6 +13,7 @@ DialogExplorer::DialogExplorer(QWidget* parent, CameraDefinition* camera, bool c
{ {
QWidget* panel; QWidget* panel;
QPushButton* button; QPushButton* button;
QLabel* label;
setModal(true); setModal(true);
setWindowTitle(tr("Paysages 3D - Explore")); setWindowTitle(tr("Paysages 3D - Explore"));
@ -29,6 +31,16 @@ DialogExplorer::DialogExplorer(QWidget* parent, CameraDefinition* camera, bool c
panel->setLayout(new QVBoxLayout()); panel->setLayout(new QVBoxLayout());
panel->setMaximumWidth(230); panel->setMaximumWidth(230);
label = new QLabel(tr("Field of vision"), panel);
label->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
panel->layout()->addWidget(label);
QSlider* slider = new QSlider(Qt::Horizontal, panel);
slider->setRange(0, 1000);
slider->setValue((int)(1000.0 * (camera->getPerspective().yfov - 0.7) / 1.0));
slider->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
connect(slider, SIGNAL(valueChanged(int)), this, SLOT(fovChanged(int)));
panel->layout()->addWidget(slider);
panel->layout()->addWidget(new QLabel(tr("COMMANDS\n\nLeft click : Look around\nRight click : Pan (adjust framing)\nWheel : Move forward/backward\nHold SHIFT : Faster\nHold CTRL : Slower"), panel)); panel->layout()->addWidget(new QLabel(tr("COMMANDS\n\nLeft click : Look around\nRight click : Pan (adjust framing)\nWheel : Move forward/backward\nHold SHIFT : Faster\nHold CTRL : Slower"), panel));
button = new QPushButton(tr("Reset camera"), panel); button = new QPushButton(tr("Reset camera"), panel);
@ -61,3 +73,8 @@ void DialogExplorer::validateCamera()
accept(); accept();
} }
void DialogExplorer::fovChanged(int value)
{
_wanderer->setCameraFov(0.7 + 1.0 * ((double)value) / 1000.0);
}

View file

@ -14,6 +14,7 @@ public:
protected slots: protected slots:
void validateCamera(); void validateCamera();
void fovChanged(int value);
private: private:
WidgetExplorer* _wanderer; WidgetExplorer* _wanderer;

View file

@ -43,6 +43,12 @@ WidgetExplorer::~WidgetExplorer()
delete _renderer; delete _renderer;
} }
void WidgetExplorer::setCameraFov(double fov)
{
_current_camera->setFov(fov);
updateGL();
}
void WidgetExplorer::resetCamera() void WidgetExplorer::resetCamera()
{ {
_base_camera->copy(_current_camera); _base_camera->copy(_current_camera);

View file

@ -15,6 +15,8 @@ public:
WidgetExplorer(QWidget* parent, CameraDefinition* camera, Scenery* scenery); WidgetExplorer(QWidget* parent, CameraDefinition* camera, Scenery* scenery);
~WidgetExplorer(); ~WidgetExplorer();
void setCameraFov(double fov);
public slots: public slots:
void resetCamera(); void resetCamera();
void validateCamera(); void validateCamera();