paysages: Started 3d explorer with OpenGL (WIP).
git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@241 b1fd45b6-86a6-48da-8261-f70d1f35bdcc
This commit is contained in:
parent
08ca1e5d59
commit
42bbb32b7a
7 changed files with 138 additions and 11 deletions
|
@ -1,16 +1,19 @@
|
||||||
#include "dialogwanderer.h"
|
#include "dialogwanderer.h"
|
||||||
|
|
||||||
#include <QGLWidget>
|
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
|
#include "widgetwanderer.h"
|
||||||
|
|
||||||
DialogWanderer::DialogWanderer(QWidget *parent):
|
DialogWanderer::DialogWanderer(QWidget* parent, CameraDefinition* camera):
|
||||||
QDialog(parent)
|
QDialog(parent)
|
||||||
{
|
{
|
||||||
setModal(true);
|
setModal(true);
|
||||||
setWindowTitle("Paysages 3D - Explore");
|
setWindowTitle("Paysages 3D - Explore");
|
||||||
setLayout(new QVBoxLayout());
|
setLayout(new QVBoxLayout());
|
||||||
|
|
||||||
|
layout()->addWidget(new WidgetWanderer(this, camera));
|
||||||
}
|
}
|
||||||
|
|
||||||
DialogWanderer::~DialogWanderer()
|
DialogWanderer::~DialogWanderer()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,12 +2,13 @@
|
||||||
#define _PAYSAGES_QT_DIALOGWANDERER_H_
|
#define _PAYSAGES_QT_DIALOGWANDERER_H_
|
||||||
|
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
|
#include "../lib_paysages/camera.h"
|
||||||
|
|
||||||
class DialogWanderer : public QDialog
|
class DialogWanderer : public QDialog
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit DialogWanderer(QWidget *parent);
|
explicit DialogWanderer(QWidget *parent, CameraDefinition* camera);
|
||||||
~DialogWanderer();
|
~DialogWanderer();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
#include "dialogwanderer.h"
|
#include "dialogwanderer.h"
|
||||||
|
|
||||||
#include "../lib_paysages/auto.h"
|
#include "../lib_paysages/auto.h"
|
||||||
|
#include "../lib_paysages/scenery.h"
|
||||||
#include "../lib_paysages/shared/functions.h"
|
#include "../lib_paysages/shared/functions.h"
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
|
@ -133,7 +134,11 @@ void MainWindow::quickPreview()
|
||||||
|
|
||||||
void MainWindow::explore3D()
|
void MainWindow::explore3D()
|
||||||
{
|
{
|
||||||
DialogWanderer* dialog = new DialogWanderer(this);
|
CameraDefinition camera;
|
||||||
|
|
||||||
|
sceneryGetCamera(&camera);
|
||||||
|
|
||||||
|
DialogWanderer* dialog = new DialogWanderer(this, &camera);
|
||||||
dialog->exec();
|
dialog->exec();
|
||||||
|
|
||||||
delete dialog;
|
delete dialog;
|
||||||
|
|
|
@ -3,10 +3,6 @@
|
||||||
|
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
|
|
||||||
namespace Ui {
|
|
||||||
class MainWindow;
|
|
||||||
}
|
|
||||||
|
|
||||||
class MainWindow : public QMainWindow
|
class MainWindow : public QMainWindow
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -25,4 +21,4 @@ public slots:
|
||||||
void explore3D();
|
void explore3D();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // _PAYSAGES_QT_MAINWINDOW_H_
|
#endif
|
||||||
|
|
|
@ -36,7 +36,8 @@ HEADERS += ../lib_paysages/shared/functions.h ../lib_paysages/shared/types.h \
|
||||||
inputnoise.h \
|
inputnoise.h \
|
||||||
mainwindow.h \
|
mainwindow.h \
|
||||||
preview.h \
|
preview.h \
|
||||||
tools.h
|
tools.h \
|
||||||
|
widgetwanderer.h
|
||||||
FORMS +=
|
FORMS +=
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
baseform.cpp \
|
baseform.cpp \
|
||||||
|
@ -58,4 +59,5 @@ SOURCES += \
|
||||||
inputint.cpp \
|
inputint.cpp \
|
||||||
inputnoise.cpp \
|
inputnoise.cpp \
|
||||||
mainwindow.cpp \
|
mainwindow.cpp \
|
||||||
preview.cpp
|
preview.cpp \
|
||||||
|
widgetwanderer.cpp
|
||||||
|
|
94
gui_qt/widgetwanderer.cpp
Normal file
94
gui_qt/widgetwanderer.cpp
Normal file
|
@ -0,0 +1,94 @@
|
||||||
|
#include "widgetwanderer.h"
|
||||||
|
|
||||||
|
#include <QGLWidget>
|
||||||
|
#include "../lib_paysages/scenery.h"
|
||||||
|
|
||||||
|
WidgetWanderer::WidgetWanderer(QWidget *parent, CameraDefinition* camera):
|
||||||
|
QGLWidget(parent)
|
||||||
|
{
|
||||||
|
setMinimumSize(400, 300);
|
||||||
|
|
||||||
|
this->camera = camera;
|
||||||
|
|
||||||
|
this->terrain = terrainCreateDefinition();
|
||||||
|
sceneryGetTerrain(&terrain);
|
||||||
|
|
||||||
|
this->water = waterCreateDefinition();
|
||||||
|
sceneryGetWater(&water);
|
||||||
|
}
|
||||||
|
|
||||||
|
void WidgetWanderer::initializeGL()
|
||||||
|
{
|
||||||
|
glClearColor(0.4, 0.7, 0.8, 0.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void WidgetWanderer::resizeGL(int w, int h)
|
||||||
|
{
|
||||||
|
double ratio = (double)h / (double)w;
|
||||||
|
|
||||||
|
glViewport(0, 0, (GLint)w, (GLint)h);
|
||||||
|
|
||||||
|
glMatrixMode(GL_PROJECTION);
|
||||||
|
glLoadIdentity();
|
||||||
|
glFrustum(-2.5, 2.5, -2.5 * ratio, 2.5 * ratio, 2.0, 1000.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void _pushTerrainVertex(TerrainDefinition* terrain, double x, double z)
|
||||||
|
{
|
||||||
|
glVertex3f(x, terrainGetHeight(terrain, x, z), z);
|
||||||
|
//glVertex3f(x, 1.0, z);
|
||||||
|
}
|
||||||
|
|
||||||
|
void WidgetWanderer::paintGL()
|
||||||
|
{
|
||||||
|
double x, z, step;
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
|
glFrontFace(GL_CCW);
|
||||||
|
glCullFace(GL_BACK);
|
||||||
|
glEnable(GL_CULL_FACE);
|
||||||
|
|
||||||
|
glDepthFunc(GL_LEQUAL);
|
||||||
|
glEnable(GL_DEPTH_TEST);
|
||||||
|
|
||||||
|
glLineWidth(1.0);
|
||||||
|
|
||||||
|
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||||
|
glColor3f(0.0, 0.0, 1.0);
|
||||||
|
glBegin(GL_QUADS);
|
||||||
|
glVertex3f(-500.0, water.height, -500.0);
|
||||||
|
glVertex3f(-500.0, water.height, 500.0);
|
||||||
|
glVertex3f(500.0, water.height, 500.0);
|
||||||
|
glVertex3f(500.0, water.height, -500.0);
|
||||||
|
glEnd();
|
||||||
|
|
||||||
|
step = 2.0;
|
||||||
|
for (x = -50.0; x < 50.0; x += step)
|
||||||
|
{
|
||||||
|
for (z = -50.0; z < 50.0; z += step)
|
||||||
|
{
|
||||||
|
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
||||||
|
glColor3f(0.0, 1.0, 0.0);
|
||||||
|
glBegin(GL_QUADS);
|
||||||
|
_pushTerrainVertex(&terrain, x, z);
|
||||||
|
_pushTerrainVertex(&terrain, x, z + step);
|
||||||
|
_pushTerrainVertex(&terrain, x + step, z + step);
|
||||||
|
_pushTerrainVertex(&terrain, x + step, z);
|
||||||
|
glEnd();
|
||||||
|
|
||||||
|
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||||
|
glColor3f(0.0, 0.5, 0.0);
|
||||||
|
glBegin(GL_QUADS);
|
||||||
|
_pushTerrainVertex(&terrain, x, z);
|
||||||
|
_pushTerrainVertex(&terrain, x, z + step);
|
||||||
|
_pushTerrainVertex(&terrain, x + step, z + step);
|
||||||
|
_pushTerrainVertex(&terrain, x + step, z);
|
||||||
|
glEnd();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
26
gui_qt/widgetwanderer.h
Normal file
26
gui_qt/widgetwanderer.h
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
#ifndef _PAYSAGES_QT_WIDGETWANDERER_H_
|
||||||
|
#define _PAYSAGES_QT_WIDGETWANDERER_H_
|
||||||
|
|
||||||
|
#include <QGLWidget>
|
||||||
|
#include "../lib_paysages/camera.h"
|
||||||
|
#include "../lib_paysages/terrain.h"
|
||||||
|
#include "../lib_paysages/water.h"
|
||||||
|
|
||||||
|
class WidgetWanderer : public QGLWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
WidgetWanderer(QWidget* parent, CameraDefinition* camera);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void initializeGL();
|
||||||
|
void resizeGL(int w, int h);
|
||||||
|
void paintGL();
|
||||||
|
|
||||||
|
private:
|
||||||
|
CameraDefinition* camera;
|
||||||
|
TerrainDefinition terrain;
|
||||||
|
WaterDefinition water;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in a new issue