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:
Michaël Lemaire 2012-01-27 23:01:21 +00:00 committed by ThunderK
parent d484e0271a
commit f3a0a72da2
12 changed files with 218 additions and 33 deletions

View file

@ -11,13 +11,14 @@
#include <QGridLayout> #include <QGridLayout>
#include <QLabel> #include <QLabel>
BaseForm::BaseForm(QWidget* parent) : BaseForm::BaseForm(QWidget* parent, bool auto_apply) : QWidget(parent)
QWidget(parent)
{ {
QWidget* hwidget; QWidget* hwidget;
QVBoxLayout* vlayout; QVBoxLayout* vlayout;
QHBoxLayout* hlayout; QHBoxLayout* hlayout;
this->auto_apply = auto_apply;
vlayout = new QVBoxLayout(); vlayout = new QVBoxLayout();
hlayout = new QHBoxLayout(); hlayout = new QHBoxLayout();
@ -50,18 +51,31 @@ BaseForm::BaseForm(QWidget* parent) :
button_revert = addButton("Revert"); button_revert = addButton("Revert");
button_revert->setEnabled(false); button_revert->setEnabled(false);
connect(button_revert, SIGNAL(clicked()), this, SLOT(revertConfig())); connect(button_revert, SIGNAL(clicked()), this, SLOT(revertConfig()));
if (auto_apply)
{
button_apply->hide();
button_revert->hide();
}
} }
void BaseForm::configChangeEvent() 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_"); QList<Preview*> list_previews = previews->findChildren<Preview*>("_form_preview_");
for (int i = 0; i < list_previews.size(); i++) for (int i = 0; i < list_previews.size(); i++)
{ {
list_previews[i]->redraw(); list_previews[i]->redraw();
} }
button_apply->setEnabled(true);
button_revert->setEnabled(true);
} }
void BaseForm::revertConfig() void BaseForm::revertConfig()
@ -80,7 +94,9 @@ void BaseForm::revertConfig()
void BaseForm::applyConfig() void BaseForm::applyConfig()
{ {
revertConfig(); button_apply->setEnabled(false);
button_revert->setEnabled(false);
emit(configApplied()); emit(configApplied());
} }

View file

@ -13,7 +13,7 @@ class BaseForm:public QWidget
Q_OBJECT Q_OBJECT
public: public:
BaseForm(QWidget* parent); BaseForm(QWidget* parent, bool auto_apply=false);
signals: signals:
void configApplied(); void configApplied();
@ -36,6 +36,7 @@ protected:
void addInputNoise(QString label, NoiseGenerator* value); void addInputNoise(QString label, NoiseGenerator* value);
private: private:
bool auto_apply;
QWidget* previews; QWidget* previews;
QWidget* form; QWidget* form;
QWidget* buttons; QWidget* buttons;

View file

@ -1,21 +1,53 @@
#include "dialogwanderer.h" #include "dialogwanderer.h"
#include <QWidget>
#include <QPushButton>
#include <QVBoxLayout> #include <QVBoxLayout>
#include "widgetwanderer.h" #include "widgetwanderer.h"
DialogWanderer::DialogWanderer(QWidget* parent, CameraDefinition* camera): DialogWanderer::DialogWanderer(QWidget* parent, CameraDefinition* camera, bool camera_validable) : QDialog(parent)
QDialog(parent)
{ {
QWidget* panel;
QPushButton* button;
setModal(true); setModal(true);
setWindowTitle("Paysages 3D - Explore"); 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() DialogWanderer::~DialogWanderer()
{ {
} }
void DialogWanderer::validateCamera()
{
_wanderer->validateCamera();
reject();
}

View file

@ -2,14 +2,21 @@
#define _PAYSAGES_QT_DIALOGWANDERER_H_ #define _PAYSAGES_QT_DIALOGWANDERER_H_
#include <QDialog> #include <QDialog>
#include "widgetwanderer.h"
#include "../lib_paysages/camera.h" #include "../lib_paysages/camera.h"
class DialogWanderer : public QDialog class DialogWanderer : public QDialog
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit DialogWanderer(QWidget *parent, CameraDefinition* camera); explicit DialogWanderer(QWidget *parent, CameraDefinition* camera, bool camera_validable);
~DialogWanderer(); ~DialogWanderer();
protected slots:
void validateCamera();
private:
WidgetWanderer* _wanderer;
}; };
#endif #endif

View file

@ -2,20 +2,24 @@
#include <QFileDialog> #include <QFileDialog>
#include <QMessageBox> #include <QMessageBox>
#include "dialogrender.h" #include "dialogrender.h"
#include "inputcamera.h"
#include "../lib_paysages/render.h" #include "../lib_paysages/render.h"
#include "../lib_paysages/scenery.h"
#include "../lib_paysages/shared/functions.h" #include "../lib_paysages/shared/functions.h"
/**************** Form ****************/ /**************** Form ****************/
FormRender::FormRender(QWidget *parent) : FormRender::FormRender(QWidget *parent) :
BaseForm(parent), BaseForm(parent, true)
_quality(5),
_width(800),
_height(600)
{ {
QPushButton* button; QPushButton* button;
_quality = 5;
_width = 800;
_height = 600;
_camera = cameraCreateDefinition();
addInput(new InputCamera(this, "Camera", &_camera));
addInputInt("Quality", &_quality, 1, 10, 1, 1); addInputInt("Quality", &_quality, 1, 10, 1, 1);
addInputInt("Image width", &_width, 100, 2000, 10, 100); addInputInt("Image width", &_width, 100, 2000, 10, 100);
addInputInt("Image height", &_height, 100, 2000, 10, 100); addInputInt("Image height", &_height, 100, 2000, 10, 100);
@ -30,6 +34,24 @@ FormRender::FormRender(QWidget *parent) :
revertConfig(); 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() void FormRender::startRender()
{ {
DialogRender* dialog = new DialogRender(this); DialogRender* dialog = new DialogRender(this);

View file

@ -2,6 +2,7 @@
#define _PAYSAGES_QT_FORMRENDER_H_ #define _PAYSAGES_QT_FORMRENDER_H_
#include "baseform.h" #include "baseform.h"
#include "../lib_paysages/camera.h"
class FormRender : public BaseForm class FormRender : public BaseForm
{ {
@ -10,6 +11,13 @@ class FormRender : public BaseForm
public: public:
explicit FormRender(QWidget *parent = 0); explicit FormRender(QWidget *parent = 0);
public slots:
virtual void revertConfig();
virtual void applyConfig();
protected slots:
virtual void configChangeEvent();
private slots: private slots:
void startRender(); void startRender();
void showRender(); void showRender();
@ -19,6 +27,7 @@ private:
int _quality; int _quality;
int _width; int _width;
int _height; int _height;
CameraDefinition _camera;
}; };
#endif // _PAYSAGES_QT_FORMRENDER_H_ #endif // _PAYSAGES_QT_FORMRENDER_H_

50
gui_qt/inputcamera.cpp Normal file
View 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
View 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_

View file

@ -138,7 +138,7 @@ void MainWindow::explore3D()
sceneryGetCamera(&camera); sceneryGetCamera(&camera);
DialogWanderer* dialog = new DialogWanderer(this, &camera); DialogWanderer* dialog = new DialogWanderer(this, &camera, false);
dialog->exec(); dialog->exec();
delete dialog; delete dialog;

View file

@ -29,6 +29,7 @@ HEADERS += ../lib_paysages/shared/functions.h ../lib_paysages/shared/types.h \
formterrain.h \ formterrain.h \
formtextures.h \ formtextures.h \
formwater.h \ formwater.h \
inputcamera.h \
inputcolor.h \ inputcolor.h \
inputcolorgradation.h \ inputcolorgradation.h \
inputdouble.h \ inputdouble.h \
@ -53,6 +54,7 @@ SOURCES += \
formterrain.cpp \ formterrain.cpp \
formtextures.cpp \ formtextures.cpp \
formwater.cpp \ formwater.cpp \
inputcamera.cpp \
inputcolor.cpp \ inputcolor.cpp \
inputcolorgradation.cpp \ inputcolorgradation.cpp \
inputdouble.cpp \ inputdouble.cpp \

View file

@ -11,7 +11,8 @@ WidgetWanderer::WidgetWanderer(QWidget *parent, CameraDefinition* camera):
setMinimumSize(400, 300); setMinimumSize(400, 300);
setFocusPolicy(Qt::StrongFocus); setFocusPolicy(Qt::StrongFocus);
cameraCopyDefinition(camera, &this->camera); _base_camera = camera;
cameraCopyDefinition(camera, &_current_camera);
this->terrain = terrainCreateDefinition(); this->terrain = terrainCreateDefinition();
sceneryGetTerrain(&terrain); sceneryGetTerrain(&terrain);
@ -23,6 +24,17 @@ WidgetWanderer::WidgetWanderer(QWidget *parent, CameraDefinition* camera):
last_mouse_y = 0; 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) void WidgetWanderer::keyPressEvent(QKeyEvent* event)
{ {
double factor; double factor;
@ -43,32 +55,32 @@ void WidgetWanderer::keyPressEvent(QKeyEvent* event)
if (event->key() == Qt::Key_Up) if (event->key() == Qt::Key_Up)
{ {
cameraStrafeForward(&camera, 0.1 * factor); cameraStrafeForward(&_current_camera, 0.1 * factor);
updateGL(); updateGL();
} }
else if (event->key() == Qt::Key_Down) else if (event->key() == Qt::Key_Down)
{ {
cameraStrafeForward(&camera, -0.1 * factor); cameraStrafeForward(&_current_camera, -0.1 * factor);
updateGL(); updateGL();
} }
else if (event->key() == Qt::Key_Right) else if (event->key() == Qt::Key_Right)
{ {
cameraStrafeRight(&camera, 0.1 * factor); cameraStrafeRight(&_current_camera, 0.1 * factor);
updateGL(); updateGL();
} }
else if (event->key() == Qt::Key_Left) else if (event->key() == Qt::Key_Left)
{ {
cameraStrafeRight(&camera, -0.1 * factor); cameraStrafeRight(&_current_camera, -0.1 * factor);
updateGL(); updateGL();
} }
else if (event->key() == Qt::Key_PageUp) else if (event->key() == Qt::Key_PageUp)
{ {
cameraStrafeUp(&camera, 0.1 * factor); cameraStrafeUp(&_current_camera, 0.1 * factor);
updateGL(); updateGL();
} }
else if (event->key() == Qt::Key_PageDown) else if (event->key() == Qt::Key_PageDown)
{ {
cameraStrafeUp(&camera, -0.1 * factor); cameraStrafeUp(&_current_camera, -0.1 * factor);
updateGL(); updateGL();
} }
else else
@ -105,14 +117,14 @@ void WidgetWanderer::mouseMoveEvent(QMouseEvent* event)
if (event->buttons() & Qt::LeftButton) if (event->buttons() & Qt::LeftButton)
{ {
cameraStrafeRight(&camera, (double)(last_mouse_x - event->x()) * factor); cameraStrafeRight(&_current_camera, (double)(last_mouse_x - event->x()) * factor);
cameraStrafeUp(&camera, (double)(event->y() - last_mouse_y) * factor); cameraStrafeUp(&_current_camera, (double)(event->y() - last_mouse_y) * factor);
updateGL(); updateGL();
event->accept(); event->accept();
} }
else if (event->buttons() & Qt::RightButton) 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(); updateGL();
event->accept(); event->accept();
} }
@ -145,7 +157,7 @@ void WidgetWanderer::wheelEvent(QWheelEvent* event)
if (event->orientation() == Qt::Vertical) if (event->orientation() == Qt::Vertical)
{ {
cameraStrafeForward(&camera, (double)event->delta() * factor); cameraStrafeForward(&_current_camera, (double)event->delta() * factor);
updateGL(); updateGL();
} }
@ -255,7 +267,7 @@ void WidgetWanderer::paintGL()
{ {
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
glLoadIdentity(); 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); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
@ -268,5 +280,5 @@ void WidgetWanderer::paintGL()
glVertex3f(500.0, water.height, -500.0); glVertex3f(500.0, water.height, -500.0);
glEnd(); glEnd();
_renderTerrain(&terrain, &camera, 3); _renderTerrain(&terrain, &_current_camera, 3);
} }

View file

@ -12,6 +12,10 @@ class WidgetWanderer : public QGLWidget
public: public:
WidgetWanderer(QWidget* parent, CameraDefinition* camera); WidgetWanderer(QWidget* parent, CameraDefinition* camera);
public slots:
void resetCamera();
void validateCamera();
protected: protected:
void keyPressEvent(QKeyEvent* event); void keyPressEvent(QKeyEvent* event);
void mousePressEvent(QMouseEvent* event); void mousePressEvent(QMouseEvent* event);
@ -23,7 +27,9 @@ protected:
void paintGL(); void paintGL();
private: private:
CameraDefinition camera; CameraDefinition _current_camera;
CameraDefinition* _base_camera;
TerrainDefinition terrain; TerrainDefinition terrain;
WaterDefinition water; WaterDefinition water;