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 "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;
QPushButton* button;

View file

@ -5,13 +5,11 @@
#include <QDialog>
class Renderer;
class DialogExplorer : public QDialog
{
Q_OBJECT
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();
protected slots:

View file

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

View file

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

View file

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

View file

@ -92,7 +92,9 @@ void Scenery::load(PackStream* stream)
void Scenery::validate()
{
// TODO Ensure camera is above ground and water
BaseDefinition::validate();
checkCameraAboveGround();
}
void Scenery::autoPreset(int seed)
@ -128,6 +130,7 @@ void Scenery::getAtmosphere(AtmosphereDefinition* atmosphere)
void Scenery::setCamera(CameraDefinition* camera)
{
camera->copy(this->camera);
checkCameraAboveGround();
}
void Scenery::getCamera(CameraDefinition* camera)
@ -218,6 +221,18 @@ void Scenery::bindToRenderer(Renderer* renderer)
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
void sceneryRenderFirstPass(Renderer* renderer)

View file

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