Ensure camera is above ground and water

This commit is contained in:
Michaël Lemaire 2013-11-14 21:05:12 +01:00
parent 2df3c90ffd
commit c1fd52b0db
7 changed files with 30 additions and 16 deletions

View file

@ -8,7 +8,7 @@
#include "CameraDefinition.h" #include "CameraDefinition.h"
#include "renderer.h" #include "renderer.h"
DialogExplorer::DialogExplorer(QWidget* parent, CameraDefinition* camera, bool camera_validable, Renderer* renderer) : QDialog(parent) DialogExplorer::DialogExplorer(QWidget* parent, CameraDefinition* camera, bool camera_validable, SoftwareRenderer* renderer) : QDialog(parent)
{ {
QWidget* panel; QWidget* panel;
QPushButton* button; QPushButton* button;

View file

@ -5,13 +5,11 @@
#include <QDialog> #include <QDialog>
class Renderer;
class DialogExplorer : public QDialog class DialogExplorer : public QDialog
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit DialogExplorer(QWidget *parent, CameraDefinition* camera, bool camera_validable=false, Renderer* renderer=0); explicit DialogExplorer(QWidget *parent, CameraDefinition* camera, bool camera_validable=false, SoftwareRenderer* renderer=0);
~DialogExplorer(); ~DialogExplorer();
protected slots: protected slots:

View file

@ -73,7 +73,7 @@ static AtmosphereResult _applyAerialPerspective(Renderer*, Vector3, Color base)
return result; return result;
} }
WidgetExplorer::WidgetExplorer(QWidget *parent, CameraDefinition* camera, Renderer* renderer) : WidgetExplorer::WidgetExplorer(QWidget *parent, CameraDefinition* camera, SoftwareRenderer* renderer) :
QGLWidget(parent) QGLWidget(parent)
{ {
setMinimumSize(400, 300); setMinimumSize(400, 300);
@ -405,8 +405,8 @@ void WidgetExplorer::paintGL()
double frame_time; double frame_time;
WaterDefinition* water = _renderer->water->definition; WaterDefinition* water = _renderer->water->definition;
_current_camera->copy(_renderer->render_camera); // Don't do this at each frame, only on camera change
// TODO Keep camera above ground _renderer->getScenery()->setCamera(_current_camera);
start_time = QTime::currentTime(); start_time = QTime::currentTime();

View file

@ -2,22 +2,19 @@
#define WIDGETEXPLORER_H #define WIDGETEXPLORER_H
#include "opengl_global.h" #include "opengl_global.h"
#include <QGLWidget>
#include <QMutex>
class Renderer; #include <QGLWidget>
#include <QMutex>
namespace paysages { namespace paysages {
namespace opengl { namespace opengl {
class OpenGLRenderer;
class BaseExplorerChunk;
class OPENGLSHARED_EXPORT WidgetExplorer : public QGLWidget class OPENGLSHARED_EXPORT WidgetExplorer : public QGLWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
WidgetExplorer(QWidget* parent, CameraDefinition* camera, Renderer* renderer=0); WidgetExplorer(QWidget* parent, CameraDefinition* camera, SoftwareRenderer* renderer=0);
~WidgetExplorer(); ~WidgetExplorer();
void performChunksMaintenance(); void performChunksMaintenance();
@ -45,7 +42,7 @@ private:
CameraDefinition* _base_camera; CameraDefinition* _base_camera;
OpenGLRenderer* _opengl_renderer; OpenGLRenderer* _opengl_renderer;
Renderer* _renderer; SoftwareRenderer* _renderer;
bool _renderer_created; bool _renderer_created;
bool _inited; bool _inited;
bool _updated; bool _updated;

View file

@ -14,6 +14,8 @@
namespace paysages { namespace paysages {
namespace opengl { namespace opengl {
class WidgetExplorer; class WidgetExplorer;
class OpenGLRenderer;
class BaseExplorerChunk;
} }
} }
using namespace paysages::opengl; using namespace paysages::opengl;

View file

@ -92,7 +92,9 @@ void Scenery::load(PackStream* stream)
void Scenery::validate() void Scenery::validate()
{ {
// TODO Ensure camera is above ground and water BaseDefinition::validate();
checkCameraAboveGround();
} }
void Scenery::autoPreset(int seed) void Scenery::autoPreset(int seed)
@ -128,6 +130,7 @@ void Scenery::getAtmosphere(AtmosphereDefinition* atmosphere)
void Scenery::setCamera(CameraDefinition* camera) void Scenery::setCamera(CameraDefinition* camera)
{ {
camera->copy(this->camera); camera->copy(this->camera);
checkCameraAboveGround();
} }
void Scenery::getCamera(CameraDefinition* camera) void Scenery::getCamera(CameraDefinition* camera)
@ -218,6 +221,18 @@ void Scenery::bindToRenderer(Renderer* renderer)
WaterRendererClass.bind(renderer, water); WaterRendererClass.bind(renderer, water);
} }
void Scenery::checkCameraAboveGround()
{
Vector3 camera_location = camera->getLocation();
double terrain_height = terrainGetInterpolatedHeight(terrain, camera_location.x, camera_location.z, 1, 1) + 0.5;
double water_height = terrainGetWaterHeight(terrain) + 0.5;
if (camera_location.y < water_height || camera_location.y < terrain_height)
{
double diff = ((water_height > terrain_height) ? water_height : terrain_height) - camera_location.y;
camera->setLocation(camera_location.add(Vector3(0.0, diff, 0.0)));
}
}
// Transitional C-API // Transitional C-API
void sceneryRenderFirstPass(Renderer* renderer) void sceneryRenderFirstPass(Renderer* renderer)

View file

@ -61,6 +61,8 @@ public:
void bindToRenderer(Renderer* renderer); void bindToRenderer(Renderer* renderer);
void checkCameraAboveGround();
private: private:
AtmosphereDefinition* atmosphere; AtmosphereDefinition* atmosphere;
CameraDefinition* camera; CameraDefinition* camera;