paysages: Now using wanderer for camera selection.
git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@244 b1fd45b6-86a6-48da-8261-f70d1f35bdcc
This commit is contained in:
parent
d484e0271a
commit
f3a0a72da2
12 changed files with 218 additions and 33 deletions
|
@ -11,13 +11,14 @@
|
|||
#include <QGridLayout>
|
||||
#include <QLabel>
|
||||
|
||||
BaseForm::BaseForm(QWidget* parent) :
|
||||
QWidget(parent)
|
||||
BaseForm::BaseForm(QWidget* parent, bool auto_apply) : QWidget(parent)
|
||||
{
|
||||
QWidget* hwidget;
|
||||
QVBoxLayout* vlayout;
|
||||
QHBoxLayout* hlayout;
|
||||
|
||||
this->auto_apply = auto_apply;
|
||||
|
||||
vlayout = new QVBoxLayout();
|
||||
hlayout = new QHBoxLayout();
|
||||
|
||||
|
@ -50,18 +51,31 @@ BaseForm::BaseForm(QWidget* parent) :
|
|||
button_revert = addButton("Revert");
|
||||
button_revert->setEnabled(false);
|
||||
connect(button_revert, SIGNAL(clicked()), this, SLOT(revertConfig()));
|
||||
|
||||
if (auto_apply)
|
||||
{
|
||||
button_apply->hide();
|
||||
button_revert->hide();
|
||||
}
|
||||
}
|
||||
|
||||
void BaseForm::configChangeEvent()
|
||||
{
|
||||
if (auto_apply)
|
||||
{
|
||||
applyConfig();
|
||||
}
|
||||
else
|
||||
{
|
||||
button_apply->setEnabled(true);
|
||||
button_revert->setEnabled(true);
|
||||
}
|
||||
|
||||
QList<Preview*> list_previews = previews->findChildren<Preview*>("_form_preview_");
|
||||
for (int i = 0; i < list_previews.size(); i++)
|
||||
{
|
||||
list_previews[i]->redraw();
|
||||
}
|
||||
|
||||
button_apply->setEnabled(true);
|
||||
button_revert->setEnabled(true);
|
||||
}
|
||||
|
||||
void BaseForm::revertConfig()
|
||||
|
@ -80,7 +94,9 @@ void BaseForm::revertConfig()
|
|||
|
||||
void BaseForm::applyConfig()
|
||||
{
|
||||
revertConfig();
|
||||
button_apply->setEnabled(false);
|
||||
button_revert->setEnabled(false);
|
||||
|
||||
emit(configApplied());
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ class BaseForm:public QWidget
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
BaseForm(QWidget* parent);
|
||||
BaseForm(QWidget* parent, bool auto_apply=false);
|
||||
|
||||
signals:
|
||||
void configApplied();
|
||||
|
@ -36,6 +36,7 @@ protected:
|
|||
void addInputNoise(QString label, NoiseGenerator* value);
|
||||
|
||||
private:
|
||||
bool auto_apply;
|
||||
QWidget* previews;
|
||||
QWidget* form;
|
||||
QWidget* buttons;
|
||||
|
|
|
@ -1,21 +1,53 @@
|
|||
#include "dialogwanderer.h"
|
||||
|
||||
#include <QWidget>
|
||||
#include <QPushButton>
|
||||
#include <QVBoxLayout>
|
||||
#include "widgetwanderer.h"
|
||||
|
||||
DialogWanderer::DialogWanderer(QWidget* parent, CameraDefinition* camera):
|
||||
QDialog(parent)
|
||||
DialogWanderer::DialogWanderer(QWidget* parent, CameraDefinition* camera, bool camera_validable) : QDialog(parent)
|
||||
{
|
||||
QWidget* panel;
|
||||
QPushButton* button;
|
||||
|
||||
setModal(true);
|
||||
setWindowTitle("Paysages 3D - Explore");
|
||||
setLayout(new QVBoxLayout());
|
||||
setLayout(new QHBoxLayout());
|
||||
|
||||
layout()->addWidget(new WidgetWanderer(this, camera));
|
||||
_wanderer = new WidgetWanderer(this, camera);
|
||||
layout()->addWidget(_wanderer);
|
||||
|
||||
resize(700, 530);
|
||||
panel = new QWidget(this);
|
||||
panel->setLayout(new QVBoxLayout());
|
||||
panel->setMaximumWidth(200);
|
||||
|
||||
button = new QPushButton("Reset camera", panel);
|
||||
panel->layout()->addWidget(button);
|
||||
QObject::connect(button, SIGNAL(clicked()), _wanderer, SLOT(resetCamera()));
|
||||
|
||||
if (camera_validable)
|
||||
{
|
||||
button = new QPushButton("Validate as render camera", panel);
|
||||
panel->layout()->addWidget(button);
|
||||
QObject::connect(button, SIGNAL(clicked()), this, SLOT(validateCamera()));
|
||||
}
|
||||
|
||||
button = new QPushButton("Close", panel);
|
||||
panel->layout()->addWidget(button);
|
||||
QObject::connect(button, SIGNAL(clicked()), this, SLOT(reject()));
|
||||
|
||||
layout()->addWidget(panel);
|
||||
|
||||
resize(900, 600);
|
||||
}
|
||||
|
||||
DialogWanderer::~DialogWanderer()
|
||||
{
|
||||
}
|
||||
|
||||
void DialogWanderer::validateCamera()
|
||||
{
|
||||
_wanderer->validateCamera();
|
||||
reject();
|
||||
}
|
||||
|
||||
|
|
|
@ -2,14 +2,21 @@
|
|||
#define _PAYSAGES_QT_DIALOGWANDERER_H_
|
||||
|
||||
#include <QDialog>
|
||||
#include "widgetwanderer.h"
|
||||
#include "../lib_paysages/camera.h"
|
||||
|
||||
class DialogWanderer : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit DialogWanderer(QWidget *parent, CameraDefinition* camera);
|
||||
explicit DialogWanderer(QWidget *parent, CameraDefinition* camera, bool camera_validable);
|
||||
~DialogWanderer();
|
||||
|
||||
protected slots:
|
||||
void validateCamera();
|
||||
|
||||
private:
|
||||
WidgetWanderer* _wanderer;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -2,20 +2,24 @@
|
|||
|
||||
#include <QFileDialog>
|
||||
#include <QMessageBox>
|
||||
|
||||
#include "dialogrender.h"
|
||||
#include "inputcamera.h"
|
||||
#include "../lib_paysages/render.h"
|
||||
#include "../lib_paysages/scenery.h"
|
||||
#include "../lib_paysages/shared/functions.h"
|
||||
|
||||
/**************** Form ****************/
|
||||
FormRender::FormRender(QWidget *parent) :
|
||||
BaseForm(parent),
|
||||
_quality(5),
|
||||
_width(800),
|
||||
_height(600)
|
||||
BaseForm(parent, true)
|
||||
{
|
||||
QPushButton* button;
|
||||
|
||||
_quality = 5;
|
||||
_width = 800;
|
||||
_height = 600;
|
||||
_camera = cameraCreateDefinition();
|
||||
|
||||
addInput(new InputCamera(this, "Camera", &_camera));
|
||||
addInputInt("Quality", &_quality, 1, 10, 1, 1);
|
||||
addInputInt("Image width", &_width, 100, 2000, 10, 100);
|
||||
addInputInt("Image height", &_height, 100, 2000, 10, 100);
|
||||
|
@ -30,6 +34,24 @@ FormRender::FormRender(QWidget *parent) :
|
|||
revertConfig();
|
||||
}
|
||||
|
||||
void FormRender::revertConfig()
|
||||
{
|
||||
sceneryGetCamera(&_camera);
|
||||
BaseForm::revertConfig();
|
||||
}
|
||||
|
||||
void FormRender::applyConfig()
|
||||
{
|
||||
scenerySetCamera(&_camera);
|
||||
BaseForm::applyConfig();
|
||||
}
|
||||
|
||||
void FormRender::configChangeEvent()
|
||||
{
|
||||
cameraValidateDefinition(&_camera);
|
||||
BaseForm::configChangeEvent();
|
||||
}
|
||||
|
||||
void FormRender::startRender()
|
||||
{
|
||||
DialogRender* dialog = new DialogRender(this);
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#define _PAYSAGES_QT_FORMRENDER_H_
|
||||
|
||||
#include "baseform.h"
|
||||
#include "../lib_paysages/camera.h"
|
||||
|
||||
class FormRender : public BaseForm
|
||||
{
|
||||
|
@ -10,6 +11,13 @@ class FormRender : public BaseForm
|
|||
public:
|
||||
explicit FormRender(QWidget *parent = 0);
|
||||
|
||||
public slots:
|
||||
virtual void revertConfig();
|
||||
virtual void applyConfig();
|
||||
|
||||
protected slots:
|
||||
virtual void configChangeEvent();
|
||||
|
||||
private slots:
|
||||
void startRender();
|
||||
void showRender();
|
||||
|
@ -19,6 +27,7 @@ private:
|
|||
int _quality;
|
||||
int _width;
|
||||
int _height;
|
||||
CameraDefinition _camera;
|
||||
};
|
||||
|
||||
#endif // _PAYSAGES_QT_FORMRENDER_H_
|
||||
|
|
50
gui_qt/inputcamera.cpp
Normal file
50
gui_qt/inputcamera.cpp
Normal file
|
@ -0,0 +1,50 @@
|
|||
#include "inputcamera.h"
|
||||
|
||||
#include <QLabel>
|
||||
#include <QPushButton>
|
||||
#include <QPainter>
|
||||
#include <QColorDialog>
|
||||
|
||||
#include "dialogwanderer.h"
|
||||
|
||||
#include "../lib_paysages/shared/functions.h"
|
||||
|
||||
InputCamera::InputCamera(QWidget* form, QString label, CameraDefinition* value):BaseInput(form, label)
|
||||
{
|
||||
_value = value;
|
||||
|
||||
_preview = new QWidget(form);
|
||||
|
||||
_control = new QPushButton("Edit", form);
|
||||
_control->setMaximumWidth(150);
|
||||
|
||||
connect((QPushButton*)_control, SIGNAL(clicked()), this, SLOT(editCamera()));
|
||||
}
|
||||
|
||||
void InputCamera::updatePreview()
|
||||
{
|
||||
//_preview->update();
|
||||
|
||||
BaseInput::updatePreview();
|
||||
}
|
||||
|
||||
void InputCamera::applyValue()
|
||||
{
|
||||
BaseInput::applyValue();
|
||||
}
|
||||
|
||||
void InputCamera::revert()
|
||||
{
|
||||
BaseInput::revert();
|
||||
}
|
||||
|
||||
void InputCamera::editCamera()
|
||||
{
|
||||
DialogWanderer* dialog = new DialogWanderer(_control, _value, true);
|
||||
dialog->exec();
|
||||
|
||||
delete dialog;
|
||||
|
||||
// TODO Only if camera was edited
|
||||
applyValue();
|
||||
}
|
28
gui_qt/inputcamera.h
Normal file
28
gui_qt/inputcamera.h
Normal file
|
@ -0,0 +1,28 @@
|
|||
#ifndef _PAYSAGES_QT_INPUTCAMERA_H_
|
||||
#define _PAYSAGES_QT_INPUTCAMERA_H_
|
||||
|
||||
#include <QWidget>
|
||||
#include "baseinput.h"
|
||||
|
||||
#include "../lib_paysages/camera.h"
|
||||
|
||||
class InputCamera:public BaseInput
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
InputCamera(QWidget* form, QString label, CameraDefinition* value);
|
||||
|
||||
public slots:
|
||||
virtual void updatePreview();
|
||||
virtual void applyValue();
|
||||
virtual void revert();
|
||||
|
||||
private slots:
|
||||
void editCamera();
|
||||
|
||||
private:
|
||||
CameraDefinition* _value;
|
||||
};
|
||||
|
||||
#endif // _PAYSAGES_QT_INPUTNOISE_H_
|
|
@ -138,7 +138,7 @@ void MainWindow::explore3D()
|
|||
|
||||
sceneryGetCamera(&camera);
|
||||
|
||||
DialogWanderer* dialog = new DialogWanderer(this, &camera);
|
||||
DialogWanderer* dialog = new DialogWanderer(this, &camera, false);
|
||||
dialog->exec();
|
||||
|
||||
delete dialog;
|
||||
|
|
|
@ -29,6 +29,7 @@ HEADERS += ../lib_paysages/shared/functions.h ../lib_paysages/shared/types.h \
|
|||
formterrain.h \
|
||||
formtextures.h \
|
||||
formwater.h \
|
||||
inputcamera.h \
|
||||
inputcolor.h \
|
||||
inputcolorgradation.h \
|
||||
inputdouble.h \
|
||||
|
@ -53,6 +54,7 @@ SOURCES += \
|
|||
formterrain.cpp \
|
||||
formtextures.cpp \
|
||||
formwater.cpp \
|
||||
inputcamera.cpp \
|
||||
inputcolor.cpp \
|
||||
inputcolorgradation.cpp \
|
||||
inputdouble.cpp \
|
||||
|
|
|
@ -11,7 +11,8 @@ WidgetWanderer::WidgetWanderer(QWidget *parent, CameraDefinition* camera):
|
|||
setMinimumSize(400, 300);
|
||||
setFocusPolicy(Qt::StrongFocus);
|
||||
|
||||
cameraCopyDefinition(camera, &this->camera);
|
||||
_base_camera = camera;
|
||||
cameraCopyDefinition(camera, &_current_camera);
|
||||
|
||||
this->terrain = terrainCreateDefinition();
|
||||
sceneryGetTerrain(&terrain);
|
||||
|
@ -23,6 +24,17 @@ WidgetWanderer::WidgetWanderer(QWidget *parent, CameraDefinition* camera):
|
|||
last_mouse_y = 0;
|
||||
}
|
||||
|
||||
void WidgetWanderer::resetCamera()
|
||||
{
|
||||
cameraCopyDefinition(_base_camera, &_current_camera);
|
||||
updateGL();
|
||||
}
|
||||
|
||||
void WidgetWanderer::validateCamera()
|
||||
{
|
||||
cameraCopyDefinition(&_current_camera, _base_camera);
|
||||
}
|
||||
|
||||
void WidgetWanderer::keyPressEvent(QKeyEvent* event)
|
||||
{
|
||||
double factor;
|
||||
|
@ -43,32 +55,32 @@ void WidgetWanderer::keyPressEvent(QKeyEvent* event)
|
|||
|
||||
if (event->key() == Qt::Key_Up)
|
||||
{
|
||||
cameraStrafeForward(&camera, 0.1 * factor);
|
||||
cameraStrafeForward(&_current_camera, 0.1 * factor);
|
||||
updateGL();
|
||||
}
|
||||
else if (event->key() == Qt::Key_Down)
|
||||
{
|
||||
cameraStrafeForward(&camera, -0.1 * factor);
|
||||
cameraStrafeForward(&_current_camera, -0.1 * factor);
|
||||
updateGL();
|
||||
}
|
||||
else if (event->key() == Qt::Key_Right)
|
||||
{
|
||||
cameraStrafeRight(&camera, 0.1 * factor);
|
||||
cameraStrafeRight(&_current_camera, 0.1 * factor);
|
||||
updateGL();
|
||||
}
|
||||
else if (event->key() == Qt::Key_Left)
|
||||
{
|
||||
cameraStrafeRight(&camera, -0.1 * factor);
|
||||
cameraStrafeRight(&_current_camera, -0.1 * factor);
|
||||
updateGL();
|
||||
}
|
||||
else if (event->key() == Qt::Key_PageUp)
|
||||
{
|
||||
cameraStrafeUp(&camera, 0.1 * factor);
|
||||
cameraStrafeUp(&_current_camera, 0.1 * factor);
|
||||
updateGL();
|
||||
}
|
||||
else if (event->key() == Qt::Key_PageDown)
|
||||
{
|
||||
cameraStrafeUp(&camera, -0.1 * factor);
|
||||
cameraStrafeUp(&_current_camera, -0.1 * factor);
|
||||
updateGL();
|
||||
}
|
||||
else
|
||||
|
@ -105,14 +117,14 @@ void WidgetWanderer::mouseMoveEvent(QMouseEvent* event)
|
|||
|
||||
if (event->buttons() & Qt::LeftButton)
|
||||
{
|
||||
cameraStrafeRight(&camera, (double)(last_mouse_x - event->x()) * factor);
|
||||
cameraStrafeUp(&camera, (double)(event->y() - last_mouse_y) * factor);
|
||||
cameraStrafeRight(&_current_camera, (double)(last_mouse_x - event->x()) * factor);
|
||||
cameraStrafeUp(&_current_camera, (double)(event->y() - last_mouse_y) * factor);
|
||||
updateGL();
|
||||
event->accept();
|
||||
}
|
||||
else if (event->buttons() & Qt::RightButton)
|
||||
{
|
||||
cameraRotateYaw(&camera, (double)(event->x() - last_mouse_x) * factor * 0.1);
|
||||
cameraRotateYaw(&_current_camera, (double)(event->x() - last_mouse_x) * factor * 0.1);
|
||||
updateGL();
|
||||
event->accept();
|
||||
}
|
||||
|
@ -145,7 +157,7 @@ void WidgetWanderer::wheelEvent(QWheelEvent* event)
|
|||
|
||||
if (event->orientation() == Qt::Vertical)
|
||||
{
|
||||
cameraStrafeForward(&camera, (double)event->delta() * factor);
|
||||
cameraStrafeForward(&_current_camera, (double)event->delta() * factor);
|
||||
updateGL();
|
||||
|
||||
}
|
||||
|
@ -255,7 +267,7 @@ void WidgetWanderer::paintGL()
|
|||
{
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
gluLookAt(camera.location.x, camera.location.y, camera.location.z, camera.target.x, camera.target.y, camera.target.z, camera.up.x, camera.up.y, camera.up.z);
|
||||
gluLookAt(_current_camera.location.x, _current_camera.location.y, _current_camera.location.z, _current_camera.target.x, _current_camera.target.y, _current_camera.target.z, _current_camera.up.x, _current_camera.up.y, _current_camera.up.z);
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
|
@ -268,5 +280,5 @@ void WidgetWanderer::paintGL()
|
|||
glVertex3f(500.0, water.height, -500.0);
|
||||
glEnd();
|
||||
|
||||
_renderTerrain(&terrain, &camera, 3);
|
||||
_renderTerrain(&terrain, &_current_camera, 3);
|
||||
}
|
||||
|
|
|
@ -12,6 +12,10 @@ class WidgetWanderer : public QGLWidget
|
|||
public:
|
||||
WidgetWanderer(QWidget* parent, CameraDefinition* camera);
|
||||
|
||||
public slots:
|
||||
void resetCamera();
|
||||
void validateCamera();
|
||||
|
||||
protected:
|
||||
void keyPressEvent(QKeyEvent* event);
|
||||
void mousePressEvent(QMouseEvent* event);
|
||||
|
@ -23,7 +27,9 @@ protected:
|
|||
void paintGL();
|
||||
|
||||
private:
|
||||
CameraDefinition camera;
|
||||
CameraDefinition _current_camera;
|
||||
CameraDefinition* _base_camera;
|
||||
|
||||
TerrainDefinition terrain;
|
||||
WaterDefinition water;
|
||||
|
||||
|
|
Loading…
Reference in a new issue