paysages : Camera refactoring.
git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@558 b1fd45b6-86a6-48da-8261-f70d1f35bdcc
This commit is contained in:
parent
a9c37d2ad5
commit
9a4cf159ee
32 changed files with 689 additions and 442 deletions
26
Makefile
26
Makefile
|
@ -1,19 +1,25 @@
|
||||||
BUILDMODE=debug
|
BUILDMODE=debug
|
||||||
BUILDPATH=./build/${BUILDMODE}
|
BUILDPATH=./build/${BUILDMODE}
|
||||||
|
CC=gcc
|
||||||
|
MAKE=make
|
||||||
|
|
||||||
|
ifneq (,$(COMPILER))
|
||||||
|
CC=$(COMPILER)
|
||||||
|
endif
|
||||||
|
|
||||||
all:
|
all:
|
||||||
@+cd src/rendering && make BUILDMODE=${BUILDMODE} PROJECT_PATH=${CURDIR}
|
@+cd src/rendering && $(MAKE) CC=${CC} BUILDMODE=${BUILDMODE} PROJECT_PATH=${CURDIR}
|
||||||
@+cd src/exploring && make BUILDMODE=${BUILDMODE} PROJECT_PATH=${CURDIR}
|
@+cd src/exploring && $(MAKE) CC=${CC} BUILDMODE=${BUILDMODE} PROJECT_PATH=${CURDIR}
|
||||||
@+cd src/controlling && make BUILDMODE=${BUILDMODE} PROJECT_PATH=${CURDIR}
|
@+cd src/controlling && $(MAKE) CC=${CC} BUILDMODE=${BUILDMODE} PROJECT_PATH=${CURDIR}
|
||||||
@+cd src/editing && qmake "BUILDMODE=${BUILDMODE}" "PROJECT_PATH=${CURDIR}" && make
|
@+cd src/editing && qmake "BUILDMODE=${BUILDMODE}" "PROJECT_PATH=${CURDIR}" && $(MAKE)
|
||||||
@+cd src/testing && make BUILDMODE=${BUILDMODE} PROJECT_PATH=${CURDIR}
|
@+cd src/testing && $(MAKE) CC=${CC} BUILDMODE=${BUILDMODE} PROJECT_PATH=${CURDIR}
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
cd src/rendering && make clean BUILDMODE=${BUILDMODE} PROJECT_PATH=${CURDIR}
|
cd src/rendering && $(MAKE) clean BUILDMODE=${BUILDMODE} PROJECT_PATH=${CURDIR}
|
||||||
cd src/exploring && make clean BUILDMODE=${BUILDMODE} PROJECT_PATH=${CURDIR}
|
cd src/exploring && $(MAKE) clean BUILDMODE=${BUILDMODE} PROJECT_PATH=${CURDIR}
|
||||||
cd src/controlling && make clean BUILDMODE=${BUILDMODE} PROJECT_PATH=${CURDIR}
|
cd src/controlling && $(MAKE) clean BUILDMODE=${BUILDMODE} PROJECT_PATH=${CURDIR}
|
||||||
cd src/editing && qmake "BUILDMODE=${BUILDMODE}" "PROJECT_PATH=${CURDIR}" && make clean
|
cd src/editing && qmake "BUILDMODE=${BUILDMODE}" "PROJECT_PATH=${CURDIR}" && $(MAKE) clean
|
||||||
cd src/testing && make clean BUILDMODE=${BUILDMODE} PROJECT_PATH=${CURDIR}
|
cd src/testing && $(MAKE) clean BUILDMODE=${BUILDMODE} PROJECT_PATH=${CURDIR}
|
||||||
rm -f ${BUILDPATH}/paysages-cli
|
rm -f ${BUILDPATH}/paysages-cli
|
||||||
rm -f ${BUILDPATH}/paysages-qt
|
rm -f ${BUILDPATH}/paysages-qt
|
||||||
rm -f ${BUILDPATH}/paysages-tests
|
rm -f ${BUILDPATH}/paysages-tests
|
||||||
|
|
|
@ -173,14 +173,13 @@ int main(int argc, char** argv)
|
||||||
scenerySetAtmosphere(atmo);
|
scenerySetAtmosphere(atmo);
|
||||||
AtmosphereDefinitionClass.destroy(atmo);
|
AtmosphereDefinitionClass.destroy(atmo);
|
||||||
|
|
||||||
CameraDefinition camera;
|
CameraDefinition* camera;
|
||||||
|
Vector3 step = {conf_camera_step_x, conf_camera_step_y, conf_camera_step_z};
|
||||||
camera = cameraCreateDefinition();
|
camera = cameraCreateDefinition();
|
||||||
sceneryGetCamera(&camera);
|
sceneryGetCamera(camera);
|
||||||
camera.location.x += conf_camera_step_x;
|
cameraSetLocation(camera, v3Add(cameraGetLocation(camera), step));
|
||||||
camera.location.y += conf_camera_step_y;
|
scenerySetCamera(camera);
|
||||||
camera.location.z += conf_camera_step_z;
|
cameraDeleteDefinition(camera);
|
||||||
scenerySetCamera(&camera);
|
|
||||||
cameraDeleteDefinition(&camera);
|
|
||||||
|
|
||||||
renderer = sceneryCreateStandardRenderer();
|
renderer = sceneryCreateStandardRenderer();
|
||||||
rendererSetPreviewCallbacks(renderer, NULL, NULL, _previewUpdate);
|
rendererSetPreviewCallbacks(renderer, NULL, NULL, _previewUpdate);
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
#include "rendering/tools/curve.h"
|
#include "rendering/tools/curve.h"
|
||||||
#include "rendering/tools/color.h"
|
#include "rendering/tools/color.h"
|
||||||
#include "rendering/tools/pack.h"
|
#include "rendering/tools/pack.h"
|
||||||
|
#include "rendering/tools/lighting.h"
|
||||||
#include "rendering/noise.h"
|
#include "rendering/noise.h"
|
||||||
#include "rendering/layers.h"
|
#include "rendering/layers.h"
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
#include "previewosd.h"
|
#include "previewosd.h"
|
||||||
#include "rendering/tools/pack.h"
|
#include "rendering/tools/pack.h"
|
||||||
|
#include "rendering/tools/color.h"
|
||||||
|
|
||||||
class _ContextChoice
|
class _ContextChoice
|
||||||
{
|
{
|
||||||
|
@ -27,7 +28,8 @@ public:
|
||||||
bool value;
|
bool value;
|
||||||
};
|
};
|
||||||
|
|
||||||
class BasePreview : public QWidget {
|
class BasePreview : public QWidget
|
||||||
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -136,12 +138,14 @@ private slots:
|
||||||
/*** Private section ***/
|
/*** Private section ***/
|
||||||
class PreviewChunk;
|
class PreviewChunk;
|
||||||
|
|
||||||
class PreviewDrawingThread : public QThread {
|
class PreviewDrawingThread : public QThread
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
PreviewDrawingThread();
|
PreviewDrawingThread();
|
||||||
void askStop();
|
void askStop();
|
||||||
|
|
||||||
static inline void usleep(int us) {
|
static inline void usleep(int us)
|
||||||
|
{
|
||||||
QThread::usleep(us);
|
QThread::usleep(us);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,7 +156,8 @@ private:
|
||||||
bool _running;
|
bool _running;
|
||||||
};
|
};
|
||||||
|
|
||||||
class PreviewDrawingManager {
|
class PreviewDrawingManager
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
PreviewDrawingManager();
|
PreviewDrawingManager();
|
||||||
void startThreads();
|
void startThreads();
|
||||||
|
|
|
@ -16,7 +16,7 @@ ExplorerChunkSky::ExplorerChunkSky(Renderer* renderer, double size, SkyboxOrient
|
||||||
|
|
||||||
void ExplorerChunkSky::onCameraEvent(CameraDefinition* camera)
|
void ExplorerChunkSky::onCameraEvent(CameraDefinition* camera)
|
||||||
{
|
{
|
||||||
_center = camera->location;
|
_center = cameraGetLocation(camera);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExplorerChunkSky::onRenderEvent(QGLWidget*)
|
void ExplorerChunkSky::onRenderEvent(QGLWidget*)
|
||||||
|
|
|
@ -84,30 +84,32 @@ bool ExplorerChunkTerrain::onMaintainEvent()
|
||||||
|
|
||||||
void ExplorerChunkTerrain::onCameraEvent(CameraDefinition* camera)
|
void ExplorerChunkTerrain::onCameraEvent(CameraDefinition* camera)
|
||||||
{
|
{
|
||||||
|
Vector3 camera_location = cameraGetLocation(camera);
|
||||||
|
|
||||||
// Handle position
|
// Handle position
|
||||||
_lock_data.lock();
|
_lock_data.lock();
|
||||||
if (camera->location.x > _startx + _overall_step * 0.5)
|
if (camera_location.x > _startx + _overall_step * 0.5)
|
||||||
{
|
{
|
||||||
_startx += _overall_step;
|
_startx += _overall_step;
|
||||||
askReset();
|
askReset();
|
||||||
}
|
}
|
||||||
if (camera->location.z > _startz + _overall_step * 0.5)
|
if (camera_location.z > _startz + _overall_step * 0.5)
|
||||||
{
|
{
|
||||||
_startz += _overall_step;
|
_startz += _overall_step;
|
||||||
askReset();
|
askReset();
|
||||||
}
|
}
|
||||||
if (camera->location.x < _startx - _overall_step * 0.5)
|
if (camera_location.x < _startx - _overall_step * 0.5)
|
||||||
{
|
{
|
||||||
_startx -= _overall_step;
|
_startx -= _overall_step;
|
||||||
askReset();
|
askReset();
|
||||||
}
|
}
|
||||||
if (camera->location.z < _startz - _overall_step * 0.5)
|
if (camera_location.z < _startz - _overall_step * 0.5)
|
||||||
{
|
{
|
||||||
_startz -= _overall_step;
|
_startz -= _overall_step;
|
||||||
askReset();
|
askReset();
|
||||||
}
|
}
|
||||||
|
|
||||||
_distance_to_camera = v3Norm(v3Sub(getCenter(), camera->location));
|
_distance_to_camera = v3Norm(v3Sub(getCenter(), camera_location));
|
||||||
|
|
||||||
_lock_data.unlock();
|
_lock_data.unlock();
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
class PreviewRenderLandscape : public BasePreview
|
class PreviewRenderLandscape : public BasePreview
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
PreviewRenderLandscape(QWidget* parent) : BasePreview(parent)
|
PreviewRenderLandscape(QWidget* parent) : BasePreview(parent)
|
||||||
{
|
{
|
||||||
_renderer = sceneryCreateStandardRenderer();
|
_renderer = sceneryCreateStandardRenderer();
|
||||||
|
@ -27,6 +28,7 @@ public:
|
||||||
configScrolling(-1000.0, 1000.0, 0.0, -1000.0, 1000.0, 0.0);
|
configScrolling(-1000.0, 1000.0, 0.0, -1000.0, 1000.0, 0.0);
|
||||||
}
|
}
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
Color getColor(double x, double y)
|
Color getColor(double x, double y)
|
||||||
{
|
{
|
||||||
Vector3 location;
|
Vector3 location;
|
||||||
|
@ -44,6 +46,7 @@ protected:
|
||||||
return _renderer->terrain->getFinalColor(_renderer, location, scaling);
|
return _renderer->terrain->getFinalColor(_renderer, location, scaling);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateData()
|
void updateData()
|
||||||
{
|
{
|
||||||
sceneryBindRenderer(_renderer);
|
sceneryBindRenderer(_renderer);
|
||||||
|
@ -54,6 +57,7 @@ protected:
|
||||||
CloudsRendererClass.bind(_renderer, _no_clouds);
|
CloudsRendererClass.bind(_renderer, _no_clouds);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void toggleChangeEvent(QString key, bool value)
|
void toggleChangeEvent(QString key, bool value)
|
||||||
{
|
{
|
||||||
if (key == "clouds")
|
if (key == "clouds")
|
||||||
|
@ -102,7 +106,7 @@ FormRender::FormRender(QWidget *parent) :
|
||||||
_preview_landscape = new PreviewRenderLandscape(this);
|
_preview_landscape = new PreviewRenderLandscape(this);
|
||||||
addPreview(_preview_landscape, QString(tr("Top-down preview")));
|
addPreview(_preview_landscape, QString(tr("Top-down preview")));
|
||||||
|
|
||||||
addInput(new InputCamera(this, tr("Camera"), &_camera));
|
addInput(new InputCamera(this, tr("Camera"), _camera));
|
||||||
addInputInt(tr("Quality"), &_params.quality, 1, 10, 1, 1);
|
addInputInt(tr("Quality"), &_params.quality, 1, 10, 1, 1);
|
||||||
addInputInt(tr("Image width"), &_params.width, 100, 2000, 10, 100);
|
addInputInt(tr("Image width"), &_params.width, 100, 2000, 10, 100);
|
||||||
addInputInt(tr("Image height"), &_params.height, 100, 1200, 10, 100);
|
addInputInt(tr("Image height"), &_params.height, 100, 1200, 10, 100);
|
||||||
|
@ -118,6 +122,7 @@ FormRender::FormRender(QWidget *parent) :
|
||||||
|
|
||||||
FormRender::~FormRender()
|
FormRender::~FormRender()
|
||||||
{
|
{
|
||||||
|
cameraDeleteDefinition(_camera);
|
||||||
if (_renderer_inited)
|
if (_renderer_inited)
|
||||||
{
|
{
|
||||||
rendererDelete(_renderer);
|
rendererDelete(_renderer);
|
||||||
|
@ -148,19 +153,19 @@ void FormRender::loadPack(PackStream* stream)
|
||||||
|
|
||||||
void FormRender::revertConfig()
|
void FormRender::revertConfig()
|
||||||
{
|
{
|
||||||
sceneryGetCamera(&_camera);
|
sceneryGetCamera(_camera);
|
||||||
BaseForm::revertConfig();
|
BaseForm::revertConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FormRender::applyConfig()
|
void FormRender::applyConfig()
|
||||||
{
|
{
|
||||||
scenerySetCamera(&_camera);
|
scenerySetCamera(_camera);
|
||||||
BaseForm::applyConfig();
|
BaseForm::applyConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FormRender::configChangeEvent()
|
void FormRender::configChangeEvent()
|
||||||
{
|
{
|
||||||
cameraValidateDefinition(&_camera, 1);
|
cameraValidateDefinition(_camera, 1);
|
||||||
BaseForm::configChangeEvent();
|
BaseForm::configChangeEvent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@ private slots:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
RenderParams _params;
|
RenderParams _params;
|
||||||
CameraDefinition _camera;
|
CameraDefinition* _camera;
|
||||||
Renderer* _renderer;
|
Renderer* _renderer;
|
||||||
bool _renderer_inited;
|
bool _renderer_inited;
|
||||||
BasePreview* _preview_landscape;
|
BasePreview* _preview_landscape;
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
class PreviewTexturesCoverage : public BasePreview
|
class PreviewTexturesCoverage : public BasePreview
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
PreviewTexturesCoverage(QWidget* parent, TexturesLayerDefinition* layer) : BasePreview(parent)
|
PreviewTexturesCoverage(QWidget* parent, TexturesLayerDefinition* layer) : BasePreview(parent)
|
||||||
{
|
{
|
||||||
_terrain = (TerrainDefinition*) TerrainDefinitionClass.create();
|
_terrain = (TerrainDefinition*) TerrainDefinitionClass.create();
|
||||||
|
@ -22,11 +23,13 @@ public:
|
||||||
configScaling(20.0, 500.0, 20.0, 50.0);
|
configScaling(20.0, 500.0, 20.0, 50.0);
|
||||||
configScrolling(-1000.0, 1000.0, 0.0, -1000.0, 1000.0, 0.0);
|
configScrolling(-1000.0, 1000.0, 0.0, -1000.0, 1000.0, 0.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
~PreviewTexturesCoverage()
|
~PreviewTexturesCoverage()
|
||||||
{
|
{
|
||||||
//TexturesDefinitionClass.destroy(_preview_layer);
|
//TexturesDefinitionClass.destroy(_preview_layer);
|
||||||
}
|
}
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
Color getColor(double x, double y)
|
Color getColor(double x, double y)
|
||||||
{
|
{
|
||||||
Vector3 location;
|
Vector3 location;
|
||||||
|
@ -37,6 +40,7 @@ protected:
|
||||||
//result.r = result.g = result.b = texturesGetLayerCoverage(_preview_layer, _renderer, location, this->scaling);
|
//result.r = result.g = result.b = texturesGetLayerCoverage(_preview_layer, _renderer, location, this->scaling);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateData()
|
void updateData()
|
||||||
{
|
{
|
||||||
sceneryGetTerrain(_terrain);
|
sceneryGetTerrain(_terrain);
|
||||||
|
@ -55,6 +59,7 @@ private:
|
||||||
class PreviewTexturesColor : public BasePreview
|
class PreviewTexturesColor : public BasePreview
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
PreviewTexturesColor(QWidget* parent, TexturesLayerDefinition* layer) : BasePreview(parent)
|
PreviewTexturesColor(QWidget* parent, TexturesLayerDefinition* layer) : BasePreview(parent)
|
||||||
{
|
{
|
||||||
_original_layer = layer;
|
_original_layer = layer;
|
||||||
|
@ -62,18 +67,20 @@ public:
|
||||||
|
|
||||||
_renderer = rendererCreate();
|
_renderer = rendererCreate();
|
||||||
_renderer->render_quality = 3;
|
_renderer->render_quality = 3;
|
||||||
_renderer->render_camera.location.x = 0.0;
|
|
||||||
_renderer->render_camera.location.y = 20.0;
|
Vector3 camera_location = {0.0, 20.0, 0.0};
|
||||||
_renderer->render_camera.location.z = 0.0;
|
cameraSetLocation(_renderer->render_camera, camera_location);
|
||||||
|
|
||||||
configScaling(0.01, 1.0, 0.01, 0.1);
|
configScaling(0.01, 1.0, 0.01, 0.1);
|
||||||
configScrolling(-1000.0, 1000.0, 0.0, -1000.0, 1000.0, 0.0);
|
configScrolling(-1000.0, 1000.0, 0.0, -1000.0, 1000.0, 0.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
~PreviewTexturesColor()
|
~PreviewTexturesColor()
|
||||||
{
|
{
|
||||||
//TexturesDefinitionClass.destroy(_preview_layer);
|
//TexturesDefinitionClass.destroy(_preview_layer);
|
||||||
}
|
}
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
Color getColor(double x, double y)
|
Color getColor(double x, double y)
|
||||||
{
|
{
|
||||||
Vector3 location;
|
Vector3 location;
|
||||||
|
@ -83,6 +90,7 @@ protected:
|
||||||
//return texturesGetLayerColor(_preview_layer, _renderer, location, this->scaling);
|
//return texturesGetLayerColor(_preview_layer, _renderer, location, this->scaling);
|
||||||
return COLOR_BLACK;
|
return COLOR_BLACK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateData()
|
void updateData()
|
||||||
{
|
{
|
||||||
//TexturesDefinitionClass.copy(_original_layer, _preview_layer);
|
//TexturesDefinitionClass.copy(_original_layer, _preview_layer);
|
||||||
|
|
|
@ -18,6 +18,7 @@ static WaterDefinition* _definition;
|
||||||
class PreviewWaterCoverage : public BasePreview
|
class PreviewWaterCoverage : public BasePreview
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
PreviewWaterCoverage(QWidget* parent) : BasePreview(parent)
|
PreviewWaterCoverage(QWidget* parent) : BasePreview(parent)
|
||||||
{
|
{
|
||||||
_renderer = waterCreatePreviewCoverageRenderer();
|
_renderer = waterCreatePreviewCoverageRenderer();
|
||||||
|
@ -30,10 +31,12 @@ public:
|
||||||
configScrolling(-1000.0, 1000.0, 0.0, -1000.0, 1000.0, 0.0);
|
configScrolling(-1000.0, 1000.0, 0.0, -1000.0, 1000.0, 0.0);
|
||||||
}
|
}
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
Color getColor(double x, double y)
|
Color getColor(double x, double y)
|
||||||
{
|
{
|
||||||
return waterGetPreviewCoverage(_renderer, x, y, scaling, _highlight_enabled ? 1 : 0);
|
return waterGetPreviewCoverage(_renderer, x, y, scaling, _highlight_enabled ? 1 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateData()
|
void updateData()
|
||||||
{
|
{
|
||||||
WaterRendererClass.bind(_renderer, _definition);
|
WaterRendererClass.bind(_renderer, _definition);
|
||||||
|
@ -44,6 +47,7 @@ protected:
|
||||||
TerrainRendererClass.bind(_renderer, terrain);
|
TerrainRendererClass.bind(_renderer, terrain);
|
||||||
TerrainDefinitionClass.destroy(terrain);
|
TerrainDefinitionClass.destroy(terrain);
|
||||||
}
|
}
|
||||||
|
|
||||||
void toggleChangeEvent(QString key, bool value)
|
void toggleChangeEvent(QString key, bool value)
|
||||||
{
|
{
|
||||||
if (key == "highlight")
|
if (key == "highlight")
|
||||||
|
@ -60,6 +64,7 @@ private:
|
||||||
class PreviewWaterColor : public BasePreview
|
class PreviewWaterColor : public BasePreview
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
PreviewWaterColor(QWidget* parent) : BasePreview(parent)
|
PreviewWaterColor(QWidget* parent) : BasePreview(parent)
|
||||||
{
|
{
|
||||||
_background = 0;
|
_background = 0;
|
||||||
|
@ -80,6 +85,7 @@ public:
|
||||||
int _background;
|
int _background;
|
||||||
bool _lighting_enabled;
|
bool _lighting_enabled;
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
Color getColor(double x, double y)
|
Color getColor(double x, double y)
|
||||||
{
|
{
|
||||||
Vector3 eye, look;
|
Vector3 eye, look;
|
||||||
|
@ -108,15 +114,19 @@ protected:
|
||||||
|
|
||||||
return _renderer->water->getResult(_renderer, target_x, target_z).final;
|
return _renderer->water->getResult(_renderer, target_x, target_z).final;
|
||||||
}
|
}
|
||||||
|
|
||||||
void cameraEvent()
|
void cameraEvent()
|
||||||
{
|
{
|
||||||
cameraSetLocation(&_renderer->render_camera, 0.0, scaling, -10.0 * scaling);
|
Vector3 camera_location = {0.0, scaling, -10.0 * scaling};
|
||||||
|
cameraSetLocation(_renderer->render_camera, camera_location);
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateData()
|
void updateData()
|
||||||
{
|
{
|
||||||
WaterRendererClass.bind(_renderer, _definition);
|
WaterRendererClass.bind(_renderer, _definition);
|
||||||
_renderer->water->definition->height = 0.0;
|
_renderer->water->definition->height = 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void choiceChangeEvent(const QString& key, int position)
|
void choiceChangeEvent(const QString& key, int position)
|
||||||
{
|
{
|
||||||
if (key == "bg")
|
if (key == "bg")
|
||||||
|
@ -125,6 +135,7 @@ protected:
|
||||||
redraw();
|
redraw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void toggleChangeEvent(QString key, bool value)
|
void toggleChangeEvent(QString key, bool value)
|
||||||
{
|
{
|
||||||
if (key == "light")
|
if (key == "light")
|
||||||
|
@ -187,6 +198,7 @@ private:
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _getLightingStatus(Renderer* renderer, LightStatus* status, Vector3, int)
|
static void _getLightingStatus(Renderer* renderer, LightStatus* status, Vector3, int)
|
||||||
{
|
{
|
||||||
LightDefinition light;
|
LightDefinition light;
|
||||||
|
|
|
@ -164,14 +164,14 @@ void MainWindow::refreshAll()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Refresh preview OSD
|
// Refresh preview OSD
|
||||||
CameraDefinition camera = cameraCreateDefinition();
|
CameraDefinition* camera = cameraCreateDefinition();
|
||||||
PreviewOsd* osd = PreviewOsd::getInstance(QString("geolocation"));
|
PreviewOsd* osd = PreviewOsd::getInstance(QString("geolocation"));
|
||||||
osd->clearItems();
|
osd->clearItems();
|
||||||
sceneryGetCamera(&camera);
|
sceneryGetCamera(camera);
|
||||||
PreviewOsdItem* item = osd->newItem(50, 50);
|
PreviewOsdItem* item = osd->newItem(50, 50);
|
||||||
item->drawCamera(&camera);
|
item->drawCamera(camera);
|
||||||
item->setToolTip(QString(tr("Camera")));
|
item->setToolTip(QString(tr("Camera")));
|
||||||
cameraDeleteDefinition(&camera);
|
cameraDeleteDefinition(camera);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::fileNew()
|
void MainWindow::fileNew()
|
||||||
|
@ -248,21 +248,24 @@ void MainWindow::quickPreview()
|
||||||
|
|
||||||
void MainWindow::explore3D()
|
void MainWindow::explore3D()
|
||||||
{
|
{
|
||||||
CameraDefinition camera;
|
CameraDefinition* camera;
|
||||||
int result;
|
int result;
|
||||||
|
|
||||||
sceneryGetCamera(&camera);
|
camera = cameraCreateDefinition();
|
||||||
|
sceneryGetCamera(camera);
|
||||||
|
|
||||||
DialogExplorer* dialog = new DialogExplorer(this, &camera, true);
|
DialogExplorer* dialog = new DialogExplorer(this, camera, true);
|
||||||
result = dialog->exec();
|
result = dialog->exec();
|
||||||
|
|
||||||
delete dialog;
|
delete dialog;
|
||||||
|
|
||||||
if (result == QDialog::Accepted)
|
if (result == QDialog::Accepted)
|
||||||
{
|
{
|
||||||
scenerySetCamera(&camera);
|
scenerySetCamera(camera);
|
||||||
refreshAll();
|
refreshAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cameraDeleteDefinition(camera);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::guiSaveCallback(PackStream* stream, void* data)
|
void MainWindow::guiSaveCallback(PackStream* stream, void* data)
|
||||||
|
|
|
@ -22,9 +22,8 @@ SmallMaterialPreview::SmallMaterialPreview(QWidget* parent, SurfaceMaterial* mat
|
||||||
_material = material;
|
_material = material;
|
||||||
|
|
||||||
_renderer = rendererCreate();
|
_renderer = rendererCreate();
|
||||||
_renderer->render_camera.location.x = 0.0;
|
Vector3 camera_location = {0.0, 0.0, 10.0};
|
||||||
_renderer->render_camera.location.x = 0.0;
|
cameraSetLocation(_renderer->render_camera, camera_location);
|
||||||
_renderer->render_camera.location.z = 10.0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SmallMaterialPreview::~SmallMaterialPreview()
|
SmallMaterialPreview::~SmallMaterialPreview()
|
||||||
|
|
|
@ -22,17 +22,19 @@ void PreviewOsdItem::setLocation(double x, double y)
|
||||||
|
|
||||||
void PreviewOsdItem::drawCamera(CameraDefinition* camera)
|
void PreviewOsdItem::drawCamera(CameraDefinition* camera)
|
||||||
{
|
{
|
||||||
|
Vector3 camera_location = cameraGetLocation(camera);
|
||||||
|
VectorSpherical camera_direction = cameraGetDirectionSpherical(camera);
|
||||||
int w2 = width() / 2;
|
int w2 = width() / 2;
|
||||||
int h2 = height() / 2;
|
int h2 = height() / 2;
|
||||||
|
|
||||||
_xlocation = camera->location.x;
|
_xlocation = camera_location.x;
|
||||||
_ylocation = camera->location.z;
|
_ylocation = camera_location.z;
|
||||||
|
|
||||||
QPainter painter(this);
|
QPainter painter(this);
|
||||||
painter.setPen(QPen(Qt::red, 2));
|
painter.setPen(QPen(Qt::red, 2));
|
||||||
painter.setRenderHints(QPainter::Antialiasing | QPainter::HighQualityAntialiasing, true);
|
painter.setRenderHints(QPainter::Antialiasing | QPainter::HighQualityAntialiasing, true);
|
||||||
painter.drawLine(w2, h2, w2 + w2 * cos(camera->yaw - M_PI_4), h2 - h2 * sin(camera->yaw - M_PI_4));
|
painter.drawLine(w2, h2, w2 + w2 * cos(camera_direction.phi - M_PI_4), h2 - h2 * sin(camera_direction.phi - M_PI_4));
|
||||||
painter.drawLine(w2, h2, w2 + w2 * cos(camera->yaw + M_PI_4), h2 - h2 * sin(camera->yaw + M_PI_4));
|
painter.drawLine(w2, h2, w2 + w2 * cos(camera_direction.phi + M_PI_4), h2 - h2 * sin(camera_direction.phi + M_PI_4));
|
||||||
}
|
}
|
||||||
|
|
||||||
void PreviewOsdItem::setToolTip(QString text)
|
void PreviewOsdItem::setToolTip(QString text)
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
class ChunkMaintenanceThread : public QThread
|
class ChunkMaintenanceThread : public QThread
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
ChunkMaintenanceThread(WidgetExplorer* wanderer)
|
ChunkMaintenanceThread(WidgetExplorer* wanderer)
|
||||||
{
|
{
|
||||||
_wanderer = wanderer;
|
_wanderer = wanderer;
|
||||||
|
@ -33,6 +34,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
void run()
|
void run()
|
||||||
{
|
{
|
||||||
while (_running)
|
while (_running)
|
||||||
|
@ -51,7 +53,7 @@ static QVector<ChunkMaintenanceThread*> _threads;
|
||||||
|
|
||||||
static Vector3 _getCameraLocation(Renderer* renderer, Vector3)
|
static Vector3 _getCameraLocation(Renderer* renderer, Vector3)
|
||||||
{
|
{
|
||||||
return ((CameraDefinition*)renderer->customData[2])->location;
|
return cameraGetLocation((CameraDefinition*) renderer->customData[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
static AtmosphereResult _applyAerialPerspective(Renderer*, Vector3, Color base)
|
static AtmosphereResult _applyAerialPerspective(Renderer*, Vector3, Color base)
|
||||||
|
@ -70,8 +72,9 @@ WidgetExplorer::WidgetExplorer(QWidget *parent, CameraDefinition* camera):
|
||||||
setMinimumSize(400, 300);
|
setMinimumSize(400, 300);
|
||||||
setFocusPolicy(Qt::StrongFocus);
|
setFocusPolicy(Qt::StrongFocus);
|
||||||
|
|
||||||
|
_current_camera = cameraCreateDefinition();
|
||||||
_base_camera = camera;
|
_base_camera = camera;
|
||||||
cameraCopyDefinition(camera, &_current_camera);
|
cameraCopyDefinition(camera, _current_camera);
|
||||||
|
|
||||||
_renderer = sceneryCreateStandardRenderer();
|
_renderer = sceneryCreateStandardRenderer();
|
||||||
_renderer->render_quality = 3;
|
_renderer->render_quality = 3;
|
||||||
|
@ -100,6 +103,7 @@ WidgetExplorer::~WidgetExplorer()
|
||||||
delete _chunks[i];
|
delete _chunks[i];
|
||||||
}
|
}
|
||||||
rendererDelete(_renderer);
|
rendererDelete(_renderer);
|
||||||
|
cameraDeleteDefinition(_current_camera);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WidgetExplorer::startRendering()
|
void WidgetExplorer::startRendering()
|
||||||
|
@ -199,13 +203,13 @@ void WidgetExplorer::performChunksMaintenance()
|
||||||
|
|
||||||
void WidgetExplorer::resetCamera()
|
void WidgetExplorer::resetCamera()
|
||||||
{
|
{
|
||||||
cameraCopyDefinition(_base_camera, &_current_camera);
|
cameraCopyDefinition(_base_camera, _current_camera);
|
||||||
updateGL();
|
updateGL();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WidgetExplorer::validateCamera()
|
void WidgetExplorer::validateCamera()
|
||||||
{
|
{
|
||||||
cameraCopyDefinition(&_current_camera, _base_camera);
|
cameraCopyDefinition(_current_camera, _base_camera);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WidgetExplorer::keyPressEvent(QKeyEvent* event)
|
void WidgetExplorer::keyPressEvent(QKeyEvent* event)
|
||||||
|
@ -228,32 +232,32 @@ void WidgetExplorer::keyPressEvent(QKeyEvent* event)
|
||||||
|
|
||||||
if (event->key() == Qt::Key_Up)
|
if (event->key() == Qt::Key_Up)
|
||||||
{
|
{
|
||||||
cameraStrafeForward(&_current_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(&_current_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(&_current_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(&_current_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(&_current_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(&_current_camera, -0.1 * factor);
|
cameraStrafeUp(_current_camera, -0.1 * factor);
|
||||||
updateGL();
|
updateGL();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -290,15 +294,15 @@ void WidgetExplorer::mouseMoveEvent(QMouseEvent* event)
|
||||||
|
|
||||||
if (event->buttons() & Qt::LeftButton)
|
if (event->buttons() & Qt::LeftButton)
|
||||||
{
|
{
|
||||||
cameraRotateYaw(&_current_camera, (double)(event->x() - _last_mouse_x) * factor * 0.1);
|
cameraRotateYaw(_current_camera, (double) (event->x() - _last_mouse_x) * factor * 0.1);
|
||||||
cameraRotatePitch(&_current_camera, (double)(event->y() - _last_mouse_y) * factor * 0.1);
|
cameraRotatePitch(_current_camera, (double) (event->y() - _last_mouse_y) * factor * 0.1);
|
||||||
updateGL();
|
updateGL();
|
||||||
event->accept();
|
event->accept();
|
||||||
}
|
}
|
||||||
else if (event->buttons() & Qt::RightButton)
|
else if (event->buttons() & Qt::RightButton)
|
||||||
{
|
{
|
||||||
cameraStrafeRight(&_current_camera, (double)(_last_mouse_x - event->x()) * factor);
|
cameraStrafeRight(_current_camera, (double) (_last_mouse_x - event->x()) * factor);
|
||||||
cameraStrafeUp(&_current_camera, (double)(event->y() - _last_mouse_y) * factor);
|
cameraStrafeUp(_current_camera, (double) (event->y() - _last_mouse_y) * factor);
|
||||||
updateGL();
|
updateGL();
|
||||||
event->accept();
|
event->accept();
|
||||||
}
|
}
|
||||||
|
@ -331,7 +335,7 @@ void WidgetExplorer::wheelEvent(QWheelEvent* event)
|
||||||
|
|
||||||
if (event->orientation() == Qt::Vertical)
|
if (event->orientation() == Qt::Vertical)
|
||||||
{
|
{
|
||||||
cameraStrafeForward(&_current_camera, (double)event->delta() * factor);
|
cameraStrafeForward(_current_camera, (double) event->delta() * factor);
|
||||||
updateGL();
|
updateGL();
|
||||||
}
|
}
|
||||||
event->accept();
|
event->accept();
|
||||||
|
@ -353,7 +357,7 @@ void WidgetExplorer::timerEvent(QTimerEvent*)
|
||||||
|
|
||||||
for (int i = 0; i < _chunks.count(); i++)
|
for (int i = 0; i < _chunks.count(); i++)
|
||||||
{
|
{
|
||||||
_chunks[i]->updatePriority(&_current_camera);
|
_chunks[i]->updatePriority(_current_camera);
|
||||||
}
|
}
|
||||||
_lock_chunks.lock();
|
_lock_chunks.lock();
|
||||||
qSort(_updateQueue.begin(), _updateQueue.end(), _cmpChunks);
|
qSort(_updateQueue.begin(), _updateQueue.end(), _cmpChunks);
|
||||||
|
@ -367,8 +371,8 @@ void WidgetExplorer::initializeGL()
|
||||||
|
|
||||||
void WidgetExplorer::resizeGL(int w, int h)
|
void WidgetExplorer::resizeGL(int w, int h)
|
||||||
{
|
{
|
||||||
cameraSetRenderSize(&_current_camera, w, h);
|
cameraSetRenderSize(_current_camera, w, h);
|
||||||
exploringSetViewPort(w, h, &_current_camera);
|
exploringSetViewPort(w, h, _current_camera);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WidgetExplorer::paintGL()
|
void WidgetExplorer::paintGL()
|
||||||
|
@ -378,14 +382,17 @@ void WidgetExplorer::paintGL()
|
||||||
double frame_time;
|
double frame_time;
|
||||||
WaterDefinition* water = _renderer->water->definition;
|
WaterDefinition* water = _renderer->water->definition;
|
||||||
|
|
||||||
cameraCopyDefinition(&_current_camera, &_renderer->render_camera);
|
cameraCopyDefinition(_current_camera, _renderer->render_camera);
|
||||||
cameraValidateDefinition(&_current_camera, 1);
|
cameraValidateDefinition(_current_camera, 1);
|
||||||
|
|
||||||
start_time = QTime::currentTime();
|
start_time = QTime::currentTime();
|
||||||
|
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
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);
|
Vector3 camera_location = cameraGetLocation(_current_camera);
|
||||||
|
Vector3 camera_target = cameraGetTarget(_current_camera);
|
||||||
|
Vector3 camera_up = cameraGetUpVector(_current_camera);
|
||||||
|
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);
|
||||||
|
|
||||||
// Background
|
// Background
|
||||||
glClearColor(0.0, 0.0, 0.0, 0.0);
|
glClearColor(0.0, 0.0, 0.0, 0.0);
|
||||||
|
@ -395,10 +402,10 @@ void WidgetExplorer::paintGL()
|
||||||
glDisable(GL_TEXTURE_2D);
|
glDisable(GL_TEXTURE_2D);
|
||||||
glColor3f(water->material.base.r, water->material.base.g, water->material.base.b);
|
glColor3f(water->material.base.r, water->material.base.g, water->material.base.b);
|
||||||
glBegin(GL_QUADS);
|
glBegin(GL_QUADS);
|
||||||
glVertex3f(_current_camera.location.x - 500.0, water->height, _current_camera.location.z - 500.0);
|
glVertex3f(camera_location.x - 500.0, water->height, camera_location.z - 500.0);
|
||||||
glVertex3f(_current_camera.location.x - 500.0, water->height, _current_camera.location.z + 500.0);
|
glVertex3f(camera_location.x - 500.0, water->height, camera_location.z + 500.0);
|
||||||
glVertex3f(_current_camera.location.x + 500.0, water->height, _current_camera.location.z + 500.0);
|
glVertex3f(camera_location.x + 500.0, water->height, camera_location.z + 500.0);
|
||||||
glVertex3f(_current_camera.location.x + 500.0, water->height, _current_camera.location.z - 500.0);
|
glVertex3f(camera_location.x + 500.0, water->height, camera_location.z - 500.0);
|
||||||
glEnd();
|
glEnd();
|
||||||
|
|
||||||
// Render chunks
|
// Render chunks
|
||||||
|
|
|
@ -34,7 +34,7 @@ private:
|
||||||
void startRendering();
|
void startRendering();
|
||||||
void stopRendering();
|
void stopRendering();
|
||||||
|
|
||||||
CameraDefinition _current_camera;
|
CameraDefinition* _current_camera;
|
||||||
CameraDefinition* _base_camera;
|
CameraDefinition* _base_camera;
|
||||||
|
|
||||||
Renderer* _renderer;
|
Renderer* _renderer;
|
||||||
|
|
|
@ -39,9 +39,10 @@ WidgetHeightMap::WidgetHeightMap(QWidget *parent, TerrainDefinition* terrain):
|
||||||
_top_camera = cameraCreateDefinition();
|
_top_camera = cameraCreateDefinition();
|
||||||
_temp_camera = cameraCreateDefinition();
|
_temp_camera = cameraCreateDefinition();
|
||||||
|
|
||||||
cameraSetLocation(&_current_camera, 0.0, 80.0, 20.0);
|
Vector3 camera_location = {0.0, 80.0, 20.0};
|
||||||
cameraSetTarget(&_current_camera, 0.0, 0.0, 0.0);
|
cameraSetLocation(_current_camera, camera_location);
|
||||||
cameraCopyDefinition(&_current_camera, &_top_camera);
|
cameraSetTarget(_current_camera, VECTOR_ZERO);
|
||||||
|
cameraCopyDefinition(_current_camera, _top_camera);
|
||||||
|
|
||||||
_brush_x = 0.0;
|
_brush_x = 0.0;
|
||||||
_brush_z = 0.0;
|
_brush_z = 0.0;
|
||||||
|
@ -55,6 +56,9 @@ WidgetHeightMap::WidgetHeightMap(QWidget *parent, TerrainDefinition* terrain):
|
||||||
|
|
||||||
WidgetHeightMap::~WidgetHeightMap()
|
WidgetHeightMap::~WidgetHeightMap()
|
||||||
{
|
{
|
||||||
|
cameraDeleteDefinition(_current_camera);
|
||||||
|
cameraDeleteDefinition(_top_camera);
|
||||||
|
cameraDeleteDefinition(_temp_camera);
|
||||||
rendererDelete(_renderer);
|
rendererDelete(_renderer);
|
||||||
noiseDeleteGenerator(_brush_noise);
|
noiseDeleteGenerator(_brush_noise);
|
||||||
delete[] _vertices;
|
delete[] _vertices;
|
||||||
|
@ -184,8 +188,12 @@ void WidgetHeightMap::timerEvent(QTimerEvent*)
|
||||||
double brush_strength;
|
double brush_strength;
|
||||||
TerrainBrush brush;
|
TerrainBrush brush;
|
||||||
|
|
||||||
brush.relative_x = _brush_x + _current_camera.target.x;
|
Vector3 camera_target = cameraGetTarget(_current_camera);
|
||||||
brush.relative_z = _brush_z + _current_camera.target.z;
|
double tx = camera_target.x;
|
||||||
|
double tz = camera_target.z;
|
||||||
|
|
||||||
|
brush.relative_x = _brush_x + tx;
|
||||||
|
brush.relative_z = _brush_z + tz;
|
||||||
brush.hard_radius = _brush_size * (1.0 - _brush_smoothing);
|
brush.hard_radius = _brush_size * (1.0 - _brush_smoothing);
|
||||||
brush.smoothed_size = _brush_size * _brush_smoothing;
|
brush.smoothed_size = _brush_size * _brush_smoothing;
|
||||||
brush.total_radius = brush.hard_radius + brush.smoothed_size;
|
brush.total_radius = brush.hard_radius + brush.smoothed_size;
|
||||||
|
@ -219,7 +227,12 @@ void WidgetHeightMap::timerEvent(QTimerEvent*)
|
||||||
updateGL();
|
updateGL();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Edge scrolling
|
// Move camera
|
||||||
|
if (cameraTransitionToAnother(_current_camera, _top_camera, 0.1))
|
||||||
|
{
|
||||||
|
updateGL();
|
||||||
|
}
|
||||||
|
|
||||||
// TODO Apply scrolling to vertex info and dirty only needed area
|
// TODO Apply scrolling to vertex info and dirty only needed area
|
||||||
/*double edge_length = 10.0;
|
/*double edge_length = 10.0;
|
||||||
if (_brush_x > HEIGHTMAP_RESOLUTION / 2.0 - edge_length)
|
if (_brush_x > HEIGHTMAP_RESOLUTION / 2.0 - edge_length)
|
||||||
|
@ -356,7 +369,10 @@ void WidgetHeightMap::paintGL()
|
||||||
// Place camera
|
// Place camera
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
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);
|
Vector3 camera_location = cameraGetLocation(_current_camera);
|
||||||
|
Vector3 camera_target = cameraGetTarget(_current_camera);
|
||||||
|
Vector3 camera_up = cameraGetUpVector(_current_camera);
|
||||||
|
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);
|
||||||
|
|
||||||
// Place lights
|
// Place lights
|
||||||
GLfloat light_position[] = {40.0, 40.0, 40.0, 0.0};
|
GLfloat light_position[] = {40.0, 40.0, 40.0, 0.0};
|
||||||
|
@ -369,6 +385,9 @@ void WidgetHeightMap::paintGL()
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
// Height map
|
// Height map
|
||||||
|
camera_target = cameraGetTarget(_current_camera);
|
||||||
|
double tx = camera_target.x;
|
||||||
|
double tz = camera_target.z;
|
||||||
for (int x = 0; x < rx - 1; x++)
|
for (int x = 0; x < rx - 1; x++)
|
||||||
{
|
{
|
||||||
glBegin(GL_QUAD_STRIP);
|
glBegin(GL_QUAD_STRIP);
|
||||||
|
@ -379,8 +398,8 @@ void WidgetHeightMap::paintGL()
|
||||||
_VertexInfo* vertex = _vertices + z * rx + x + dx;
|
_VertexInfo* vertex = _vertices + z * rx + x + dx;
|
||||||
double diff_x, diff_z, diff;
|
double diff_x, diff_z, diff;
|
||||||
|
|
||||||
diff_x = vertex->point.x - _current_camera.target.x - _brush_x;
|
diff_x = vertex->point.x - tx - _brush_x;
|
||||||
diff_z = vertex->point.z - _current_camera.target.z - _brush_z;
|
diff_z = vertex->point.z - tz - _brush_z;
|
||||||
diff = sqrt(diff_x * diff_x + diff_z * diff_z);
|
diff = sqrt(diff_x * diff_x + diff_z * diff_z);
|
||||||
if (diff > _brush_size)
|
if (diff > _brush_size)
|
||||||
{
|
{
|
||||||
|
@ -396,7 +415,7 @@ void WidgetHeightMap::paintGL()
|
||||||
}
|
}
|
||||||
glColor3f(0.8 + diff, vertex->painted ? 1.0 : 0.8, 0.8);
|
glColor3f(0.8 + diff, vertex->painted ? 1.0 : 0.8, 0.8);
|
||||||
glNormal3f(vertex->normal.x, vertex->normal.y, vertex->normal.z);
|
glNormal3f(vertex->normal.x, vertex->normal.y, vertex->normal.z);
|
||||||
glVertex3f(vertex->point.x - _current_camera.target.x, vertex->point.y, vertex->point.z - _current_camera.target.z);
|
glVertex3f(vertex->point.x - tx, vertex->point.y, vertex->point.z - tz);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
glEnd();
|
glEnd();
|
||||||
|
@ -426,14 +445,17 @@ void WidgetHeightMap::updateVertexInfo()
|
||||||
_memory_stats = terrainGetMemoryStats(_terrain);
|
_memory_stats = terrainGetMemoryStats(_terrain);
|
||||||
|
|
||||||
// Update positions
|
// Update positions
|
||||||
|
Vector3 camera_target = cameraGetTarget(_current_camera);
|
||||||
|
double tx = camera_target.x;
|
||||||
|
double tz = camera_target.z;
|
||||||
for (int x = 0; x < rx; x++)
|
for (int x = 0; x < rx; x++)
|
||||||
{
|
{
|
||||||
for (int z = 0; z < rz; z++)
|
for (int z = 0; z < rz; z++)
|
||||||
{
|
{
|
||||||
_VertexInfo* vertex = _vertices + z * rx + x;
|
_VertexInfo* vertex = _vertices + z * rx + x;
|
||||||
|
|
||||||
dx = _current_camera.target.x + x - rx / 2;
|
dx = tx + x - rx / 2;
|
||||||
dz = _current_camera.target.z + z - rz / 2;
|
dz = tz + z - rz / 2;
|
||||||
|
|
||||||
vertex->point.x = (double) dx;
|
vertex->point.x = (double) dx;
|
||||||
vertex->point.z = (double) dz;
|
vertex->point.z = (double) dz;
|
||||||
|
|
|
@ -72,9 +72,9 @@ private:
|
||||||
QDateTime _last_time;
|
QDateTime _last_time;
|
||||||
bool _mouse_moved;
|
bool _mouse_moved;
|
||||||
|
|
||||||
CameraDefinition _top_camera;
|
CameraDefinition* _top_camera;
|
||||||
CameraDefinition _temp_camera;
|
CameraDefinition* _temp_camera;
|
||||||
CameraDefinition _current_camera;
|
CameraDefinition* _current_camera;
|
||||||
|
|
||||||
double _brush_x;
|
double _brush_x;
|
||||||
double _brush_z;
|
double _brush_z;
|
||||||
|
|
|
@ -28,11 +28,14 @@ void exploringInit()
|
||||||
|
|
||||||
void exploringSetViewPort(int width, int height, CameraDefinition* camera)
|
void exploringSetViewPort(int width, int height, CameraDefinition* camera)
|
||||||
{
|
{
|
||||||
|
CameraPerspective perspective;
|
||||||
|
|
||||||
glViewport(0, 0, width, height);
|
glViewport(0, 0, width, height);
|
||||||
|
|
||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
gluPerspective(camera->yfov * 180.0 / M_PI, camera->xratio, camera->znear, camera->zfar);
|
perspective = cameraGetPerspective(camera);
|
||||||
|
gluPerspective(perspective.yfov * 180.0 / M_PI, perspective.xratio, perspective.znear, perspective.zfar);
|
||||||
|
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,20 +14,44 @@ typedef struct
|
||||||
|
|
||||||
#define MOUNTS_COUNT 11
|
#define MOUNTS_COUNT 11
|
||||||
static Mount MOUNTS[MOUNTS_COUNT] = {
|
static Mount MOUNTS[MOUNTS_COUNT] = {
|
||||||
{{2.0, 0.0, -6.0}, 4.0},
|
{
|
||||||
{{-1.5, 0.0, -8.0}, 4.0},
|
{2.0, 0.0, -6.0}, 4.0
|
||||||
{{3.0, 0.0, -10.0}, 6.0},
|
},
|
||||||
{{-8.0, 0.0, -15.0}, 6.0},
|
{
|
||||||
{{10.0, 0.0, -20.0}, 6.0},
|
{-1.5, 0.0, -8.0}, 4.0
|
||||||
{{-6.0, 0.0, -30.0}, 8.0},
|
},
|
||||||
{{15.0, 0.0, -40.0}, 8.0},
|
{
|
||||||
{{-20.0, 0.0, -50.0}, 8.0},
|
{3.0, 0.0, -10.0}, 6.0
|
||||||
{{10.0, 0.0, -60.0}, 10.0},
|
},
|
||||||
{{-5.0, 0.0, -80.0}, 10.0},
|
{
|
||||||
{{30.0, 0.0, -100.0}, 10.0},
|
{-8.0, 0.0, -15.0}, 6.0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
{10.0, 0.0, -20.0}, 6.0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
{-6.0, 0.0, -30.0}, 8.0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
{15.0, 0.0, -40.0}, 8.0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
{-20.0, 0.0, -50.0}, 8.0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
{10.0, 0.0, -60.0}, 10.0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
{-5.0, 0.0, -80.0}, 10.0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
{30.0, 0.0, -100.0}, 10.0
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
static SurfaceMaterial MOUNT_MATERIAL = {{0.4, 0.4, 0.4, 1.0}, 0.0, 0.0};
|
static SurfaceMaterial MOUNT_MATERIAL = {
|
||||||
|
{0.4, 0.4, 0.4, 1.0}, 0.0, 0.0
|
||||||
|
};
|
||||||
|
|
||||||
static inline int _rayIntersectsTriangle(Vector3 p, Vector3 d, Vector3 v0, Vector3 v1, Vector3 v2, Vector3* hit)
|
static inline int _rayIntersectsTriangle(Vector3 p, Vector3 d, Vector3 v0, Vector3 v1, Vector3 v2, Vector3* hit)
|
||||||
{
|
{
|
||||||
|
@ -147,10 +171,9 @@ Color atmosphereGetPreview(Renderer* renderer, double x, double y, double headin
|
||||||
Renderer* atmosphereCreatePreviewRenderer()
|
Renderer* atmosphereCreatePreviewRenderer()
|
||||||
{
|
{
|
||||||
Renderer* result = rendererCreate();
|
Renderer* result = rendererCreate();
|
||||||
|
Vector3 location = {0.0, 7.0, 0.0};
|
||||||
|
|
||||||
result->render_camera.location.x = 0.0;
|
cameraSetLocation(result->render_camera, location);
|
||||||
result->render_camera.location.y = 7.0;
|
|
||||||
result->render_camera.location.z = 0.0;
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,30 @@
|
||||||
#include "scenery.h"
|
#include "scenery.h"
|
||||||
#include "tools.h"
|
#include "tools.h"
|
||||||
|
|
||||||
|
struct CameraDefinition
|
||||||
|
{
|
||||||
|
Vector3 location;
|
||||||
|
double yaw;
|
||||||
|
double pitch;
|
||||||
|
double roll;
|
||||||
|
|
||||||
|
Vector3 target;
|
||||||
|
Vector3 forward;
|
||||||
|
Vector3 right;
|
||||||
|
Vector3 up;
|
||||||
|
|
||||||
|
double width;
|
||||||
|
double height;
|
||||||
|
CameraPerspective perspective;
|
||||||
|
double yfov;
|
||||||
|
double xratio;
|
||||||
|
double znear;
|
||||||
|
double zfar;
|
||||||
|
|
||||||
|
Matrix4 project;
|
||||||
|
Matrix4 unproject;
|
||||||
|
};
|
||||||
|
|
||||||
void cameraSave(PackStream* stream, CameraDefinition* camera)
|
void cameraSave(PackStream* stream, CameraDefinition* camera)
|
||||||
{
|
{
|
||||||
v3Save(stream, &camera->location);
|
v3Save(stream, &camera->location);
|
||||||
|
@ -24,32 +48,34 @@ void cameraLoad(PackStream* stream, CameraDefinition* camera)
|
||||||
cameraValidateDefinition(camera, 0);
|
cameraValidateDefinition(camera, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
CameraDefinition cameraCreateDefinition()
|
CameraDefinition* cameraCreateDefinition()
|
||||||
{
|
{
|
||||||
CameraDefinition definition;
|
CameraDefinition* definition;
|
||||||
|
|
||||||
definition.location.x = 0.0;
|
definition = malloc(sizeof (CameraDefinition));
|
||||||
definition.location.y = 0.0;
|
|
||||||
definition.location.z = 0.0;
|
|
||||||
definition.yaw = 0.0;
|
|
||||||
definition.pitch = 0.0;
|
|
||||||
definition.roll = 0.0;
|
|
||||||
|
|
||||||
definition.width = 1.0;
|
definition->location.x = 0.0;
|
||||||
definition.height = 1.0;
|
definition->location.y = 0.0;
|
||||||
definition.yfov = 1.57;
|
definition->location.z = 0.0;
|
||||||
definition.xratio = 1.0;
|
definition->yaw = 0.0;
|
||||||
definition.znear = 1.0;
|
definition->pitch = 0.0;
|
||||||
definition.zfar = 1000.0;
|
definition->roll = 0.0;
|
||||||
|
|
||||||
cameraValidateDefinition(&definition, 0);
|
definition->width = 1.0;
|
||||||
|
definition->height = 1.0;
|
||||||
|
definition->yfov = 1.57;
|
||||||
|
definition->xratio = 1.0;
|
||||||
|
definition->znear = 1.0;
|
||||||
|
definition->zfar = 1000.0;
|
||||||
|
|
||||||
|
cameraValidateDefinition(definition, 0);
|
||||||
|
|
||||||
return definition;
|
return definition;
|
||||||
}
|
}
|
||||||
|
|
||||||
void cameraDeleteDefinition(CameraDefinition* definition)
|
void cameraDeleteDefinition(CameraDefinition* definition)
|
||||||
{
|
{
|
||||||
UNUSED(definition);
|
free(definition);
|
||||||
}
|
}
|
||||||
|
|
||||||
void cameraCopyDefinition(CameraDefinition* source, CameraDefinition* destination)
|
void cameraCopyDefinition(CameraDefinition* source, CameraDefinition* destination)
|
||||||
|
@ -117,22 +143,61 @@ void cameraValidateDefinition(CameraDefinition* definition, int check_above)
|
||||||
definition->unproject = m4Inverse(definition->project);
|
definition->unproject = m4Inverse(definition->project);
|
||||||
}
|
}
|
||||||
|
|
||||||
void cameraSetLocation(CameraDefinition* camera, double x, double y, double z)
|
Vector3 cameraGetLocation(CameraDefinition* camera)
|
||||||
{
|
{
|
||||||
camera->location.x = x;
|
return camera->location;
|
||||||
camera->location.y = y;
|
}
|
||||||
camera->location.z = z;
|
|
||||||
|
Vector3 cameraGetTarget(CameraDefinition* camera)
|
||||||
|
{
|
||||||
|
return camera->target;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector3 cameraGetUpVector(CameraDefinition* camera)
|
||||||
|
{
|
||||||
|
return camera->up;
|
||||||
|
}
|
||||||
|
|
||||||
|
double cameraGetRoll(CameraDefinition* camera)
|
||||||
|
{
|
||||||
|
return camera->roll;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector3 cameraGetDirection(CameraDefinition* camera)
|
||||||
|
{
|
||||||
|
return camera->forward;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector3 cameraGetDirectionNormalized(CameraDefinition* camera)
|
||||||
|
{
|
||||||
|
return camera->forward;
|
||||||
|
}
|
||||||
|
|
||||||
|
VectorSpherical cameraGetDirectionSpherical(CameraDefinition* camera)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
CameraPerspective cameraGetPerspective(CameraDefinition* camera)
|
||||||
|
{
|
||||||
|
return camera->perspective;
|
||||||
|
}
|
||||||
|
|
||||||
|
void cameraSetLocation(CameraDefinition* camera, Vector3 location)
|
||||||
|
{
|
||||||
|
camera->location = location;
|
||||||
|
|
||||||
cameraValidateDefinition(camera, 0);
|
cameraValidateDefinition(camera, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void cameraSetTarget(CameraDefinition* camera, double x, double y, double z)
|
void cameraSetLocationCoords(CameraDefinition* camera, double x, double y, double z)
|
||||||
{
|
{
|
||||||
Vector3 forward, target;
|
Vector3 v = {x, y, z};
|
||||||
|
cameraSetLocation(camera, v);
|
||||||
|
}
|
||||||
|
|
||||||
target.x = x;
|
void cameraSetTarget(CameraDefinition* camera, Vector3 target)
|
||||||
target.y = y;
|
{
|
||||||
target.z = z;
|
Vector3 forward;
|
||||||
|
|
||||||
forward = v3Sub(target, camera->location);
|
forward = v3Sub(target, camera->location);
|
||||||
if (v3Norm(forward) < 0.0000001)
|
if (v3Norm(forward) < 0.0000001)
|
||||||
|
@ -156,12 +221,20 @@ void cameraSetTarget(CameraDefinition* camera, double x, double y, double z)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Guess angles */
|
/* Guess angles */
|
||||||
v3ToEuler(forward, &camera->yaw, &camera->pitch);
|
VectorSpherical spherical = v3ToSpherical(forward);
|
||||||
|
camera->yaw = spherical.phi;
|
||||||
|
camera->pitch = spherical.theta;
|
||||||
}
|
}
|
||||||
|
|
||||||
cameraValidateDefinition(camera, 0);
|
cameraValidateDefinition(camera, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void cameraSetTargetCoords(CameraDefinition* camera, double x, double y, double z)
|
||||||
|
{
|
||||||
|
Vector3 v = {x, y, z};
|
||||||
|
cameraSetTarget(camera, v);
|
||||||
|
}
|
||||||
|
|
||||||
void cameraSetRoll(CameraDefinition* camera, double angle)
|
void cameraSetRoll(CameraDefinition* camera, double angle)
|
||||||
{
|
{
|
||||||
camera->roll = angle;
|
camera->roll = angle;
|
||||||
|
@ -220,7 +293,7 @@ void cameraSetRenderSize(CameraDefinition* camera, int width, int height)
|
||||||
cameraValidateDefinition(camera, 0);
|
cameraValidateDefinition(camera, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3 cameraProject(CameraDefinition* camera, Renderer* renderer, Vector3 point)
|
Vector3 cameraProject(CameraDefinition* camera, Vector3 point)
|
||||||
{
|
{
|
||||||
point = m4Transform(camera->project, point);
|
point = m4Transform(camera->project, point);
|
||||||
if (point.z < 1.0)
|
if (point.z < 1.0)
|
||||||
|
@ -233,7 +306,7 @@ Vector3 cameraProject(CameraDefinition* camera, Renderer* renderer, Vector3 poin
|
||||||
return point;
|
return point;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3 cameraUnproject(CameraDefinition* camera, Renderer* renderer, Vector3 point)
|
Vector3 cameraUnproject(CameraDefinition* camera, Vector3 point)
|
||||||
{
|
{
|
||||||
point.x = (point.x / (0.5 * camera->width) - 1.0);
|
point.x = (point.x / (0.5 * camera->width) - 1.0);
|
||||||
point.y = -(point.y / (0.5 * camera->height) - 1.0);
|
point.y = -(point.y / (0.5 * camera->height) - 1.0);
|
||||||
|
@ -247,6 +320,7 @@ Vector3 cameraUnproject(CameraDefinition* camera, Renderer* renderer, Vector3 po
|
||||||
* @param col Color of the polygon.
|
* @param col Color of the polygon.
|
||||||
* @param callback Post-processing callback.
|
* @param callback Post-processing callback.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*void cameraPushOverlay(CameraDefinition* camera, Color col, f_RenderFragmentCallback callback)
|
/*void cameraPushOverlay(CameraDefinition* camera, Color col, f_RenderFragmentCallback callback)
|
||||||
{
|
{
|
||||||
Vertex v1, v2, v3, v4;
|
Vertex v1, v2, v3, v4;
|
||||||
|
@ -301,38 +375,45 @@ int cameraIsBoxInView(CameraDefinition* camera, Vector3 center, double xsize, do
|
||||||
center.x -= xsize / 2.0;
|
center.x -= xsize / 2.0;
|
||||||
center.y -= ysize / 2.0;
|
center.y -= ysize / 2.0;
|
||||||
center.z -= zsize / 2.0;
|
center.z -= zsize / 2.0;
|
||||||
projected = cameraProject(camera, NULL, center);
|
projected = cameraProject(camera, center);
|
||||||
xmin = xmax = projected.x;
|
xmin = xmax = projected.x;
|
||||||
ymin = ymax = projected.y;
|
ymin = ymax = projected.y;
|
||||||
zmax = projected.z;
|
zmax = projected.z;
|
||||||
|
|
||||||
center.x += xsize;
|
center.x += xsize;
|
||||||
projected = cameraProject(camera, NULL, center);
|
projected = cameraProject(camera, center);
|
||||||
_updateBox(&projected, &xmin, &xmax, &ymin, &ymax, &zmax);
|
_updateBox(&projected, &xmin, &xmax, &ymin, &ymax, &zmax);
|
||||||
|
|
||||||
center.z += zsize;
|
center.z += zsize;
|
||||||
projected = cameraProject(camera, NULL, center);
|
projected = cameraProject(camera, center);
|
||||||
_updateBox(&projected, &xmin, &xmax, &ymin, &ymax, &zmax);
|
_updateBox(&projected, &xmin, &xmax, &ymin, &ymax, &zmax);
|
||||||
|
|
||||||
center.x -= xsize;
|
center.x -= xsize;
|
||||||
projected = cameraProject(camera, NULL, center);
|
projected = cameraProject(camera, center);
|
||||||
_updateBox(&projected, &xmin, &xmax, &ymin, &ymax, &zmax);
|
_updateBox(&projected, &xmin, &xmax, &ymin, &ymax, &zmax);
|
||||||
|
|
||||||
center.y += ysize;
|
center.y += ysize;
|
||||||
projected = cameraProject(camera, NULL, center);
|
projected = cameraProject(camera, center);
|
||||||
_updateBox(&projected, &xmin, &xmax, &ymin, &ymax, &zmax);
|
_updateBox(&projected, &xmin, &xmax, &ymin, &ymax, &zmax);
|
||||||
|
|
||||||
center.x += xsize;
|
center.x += xsize;
|
||||||
projected = cameraProject(camera, NULL, center);
|
projected = cameraProject(camera, center);
|
||||||
_updateBox(&projected, &xmin, &xmax, &ymin, &ymax, &zmax);
|
_updateBox(&projected, &xmin, &xmax, &ymin, &ymax, &zmax);
|
||||||
|
|
||||||
center.z -= zsize;
|
center.z -= zsize;
|
||||||
projected = cameraProject(camera, NULL, center);
|
projected = cameraProject(camera, center);
|
||||||
_updateBox(&projected, &xmin, &xmax, &ymin, &ymax, &zmax);
|
_updateBox(&projected, &xmin, &xmax, &ymin, &ymax, &zmax);
|
||||||
|
|
||||||
center.x -= xsize;
|
center.x -= xsize;
|
||||||
projected = cameraProject(camera, NULL, center);
|
projected = cameraProject(camera, center);
|
||||||
_updateBox(&projected, &xmin, &xmax, &ymin, &ymax, &zmax);
|
_updateBox(&projected, &xmin, &xmax, &ymin, &ymax, &zmax);
|
||||||
|
|
||||||
return xmin <= camera->width && xmax >= 0.0 && ymin <= camera->height && ymax >= 0.0 && zmax >= camera->znear;
|
return xmin <= camera->width && xmax >= 0.0 && ymin <= camera->height && ymax >= 0.0 && zmax >= camera->znear;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int cameraTransitionToAnother(CameraDefinition* current, CameraDefinition* wanted, double factor)
|
||||||
|
{
|
||||||
|
current->location.z += factor;
|
||||||
|
cameraValidateDefinition(current, 0);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
|
@ -3,22 +3,43 @@
|
||||||
|
|
||||||
#include "tools/pack.h"
|
#include "tools/pack.h"
|
||||||
#include "tools/euclid.h"
|
#include "tools/euclid.h"
|
||||||
#include "renderer.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C"
|
||||||
|
{
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
typedef struct CameraDefinition CameraDefinition;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
double yfov;
|
||||||
|
double xratio;
|
||||||
|
double znear;
|
||||||
|
double zfar;
|
||||||
|
} CameraPerspective;
|
||||||
|
|
||||||
void cameraSave(PackStream* stream, CameraDefinition* camera);
|
void cameraSave(PackStream* stream, CameraDefinition* camera);
|
||||||
void cameraLoad(PackStream* stream, CameraDefinition* camera);
|
void cameraLoad(PackStream* stream, CameraDefinition* camera);
|
||||||
|
|
||||||
CameraDefinition cameraCreateDefinition();
|
CameraDefinition* cameraCreateDefinition();
|
||||||
void cameraDeleteDefinition(CameraDefinition* definition);
|
void cameraDeleteDefinition(CameraDefinition* definition);
|
||||||
void cameraCopyDefinition(CameraDefinition* source, CameraDefinition* destination);
|
void cameraCopyDefinition(CameraDefinition* source, CameraDefinition* destination);
|
||||||
void cameraValidateDefinition(CameraDefinition* definition, int check_above);
|
void cameraValidateDefinition(CameraDefinition* definition, int check_above);
|
||||||
|
|
||||||
void cameraSetLocation(CameraDefinition* camera, double x, double y, double z);
|
Vector3 cameraGetLocation(CameraDefinition* camera);
|
||||||
void cameraSetTarget(CameraDefinition* camera, double x, double y, double z);
|
Vector3 cameraGetTarget(CameraDefinition* camera);
|
||||||
|
Vector3 cameraGetUpVector(CameraDefinition* camera);
|
||||||
|
double cameraGetRoll(CameraDefinition* camera);
|
||||||
|
Vector3 cameraGetDirection(CameraDefinition* camera);
|
||||||
|
Vector3 cameraGetDirectionNormalized(CameraDefinition* camera);
|
||||||
|
VectorSpherical cameraGetDirectionSpherical(CameraDefinition* camera);
|
||||||
|
CameraPerspective cameraGetPerspective(CameraDefinition* camera);
|
||||||
|
|
||||||
|
void cameraSetLocation(CameraDefinition* camera, Vector3 location);
|
||||||
|
void cameraSetLocationCoords(CameraDefinition* camera, double x, double y, double z);
|
||||||
|
void cameraSetTarget(CameraDefinition* camera, Vector3 target);
|
||||||
|
void cameraSetTargetCoords(CameraDefinition* camera, double x, double y, double z);
|
||||||
void cameraSetRoll(CameraDefinition* camera, double angle);
|
void cameraSetRoll(CameraDefinition* camera, double angle);
|
||||||
|
|
||||||
void cameraStrafeForward(CameraDefinition* camera, double value);
|
void cameraStrafeForward(CameraDefinition* camera, double value);
|
||||||
|
@ -30,11 +51,13 @@ void cameraRotateRoll(CameraDefinition* camera, double value);
|
||||||
|
|
||||||
void cameraSetRenderSize(CameraDefinition* camera, int width, int height);
|
void cameraSetRenderSize(CameraDefinition* camera, int width, int height);
|
||||||
|
|
||||||
Vector3 cameraProject(CameraDefinition* camera, Renderer* renderer, Vector3 point);
|
Vector3 cameraProject(CameraDefinition* camera, Vector3 point);
|
||||||
Vector3 cameraUnproject(CameraDefinition* camera, Renderer* renderer, Vector3 point);
|
Vector3 cameraUnproject(CameraDefinition* camera, Vector3 point);
|
||||||
/*void cameraPushOverlay(CameraDefinition* camera, Color col, f_RenderFragmentCallback callback);*/
|
/*void cameraPushOverlay(CameraDefinition* camera, Color col, f_RenderFragmentCallback callback);*/
|
||||||
int cameraIsBoxInView(CameraDefinition* camera, Vector3 center, double xsize, double ysize, double zsize);
|
int cameraIsBoxInView(CameraDefinition* camera, Vector3 center, double xsize, double ysize, double zsize);
|
||||||
|
|
||||||
|
int cameraTransitionToAnother(CameraDefinition* current, CameraDefinition* wanted, double factor);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
|
|
||||||
#include "auto.h"
|
#include "auto.h"
|
||||||
#include "system.h"
|
#include "system.h"
|
||||||
#include "camera.h"
|
|
||||||
#include "scenery.h"
|
#include "scenery.h"
|
||||||
#include "render.h"
|
#include "render.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
@ -13,35 +12,13 @@
|
||||||
|
|
||||||
void paysagesInit()
|
void paysagesInit()
|
||||||
{
|
{
|
||||||
CameraDefinition camera;
|
|
||||||
|
|
||||||
systemInit();
|
systemInit();
|
||||||
openclInit();
|
openclInit();
|
||||||
|
|
||||||
sceneryInit();
|
sceneryInit();
|
||||||
renderInit();
|
renderInit();
|
||||||
|
|
||||||
camera = cameraCreateDefinition();
|
|
||||||
cameraSetLocation(&camera, -12.0, 5.0, 2.0);
|
|
||||||
cameraSetTarget(&camera, 0.0, 5.0, 0.0);
|
|
||||||
cameraRotateYaw(&camera, 1.0);
|
|
||||||
scenerySetCamera(&camera);
|
|
||||||
cameraDeleteDefinition(&camera);
|
|
||||||
|
|
||||||
autoGenRealisticLandscape(0);
|
autoGenRealisticLandscape(0);
|
||||||
|
|
||||||
// DEBUG
|
|
||||||
/*double last_height, height, x;
|
|
||||||
last_height = height = 0.0;
|
|
||||||
x = 0.0;
|
|
||||||
while (height <= 1.0 || height >= last_height || last_height < 0.1)
|
|
||||||
{
|
|
||||||
last_height = height;
|
|
||||||
height = terrainGetHeight(x, 0.0);
|
|
||||||
x += 0.1;
|
|
||||||
}
|
|
||||||
cameraSetLocation(x - 2.0, height, 0.0);
|
|
||||||
cameraSetTarget(x - 1.0, height, 0.0);*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void paysagesQuit()
|
void paysagesQuit()
|
||||||
|
|
|
@ -27,18 +27,20 @@ static Vector3 _getCameraLocation(Renderer* renderer, Vector3 target)
|
||||||
{
|
{
|
||||||
UNUSED(renderer);
|
UNUSED(renderer);
|
||||||
UNUSED(target);
|
UNUSED(target);
|
||||||
return renderer->render_camera.location;
|
return cameraGetLocation(renderer->render_camera);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Vector3 _getCameraDirection(Renderer* renderer, Vector3 target)
|
static Vector3 _getCameraDirection(Renderer* renderer, Vector3 target)
|
||||||
{
|
{
|
||||||
UNUSED(renderer);
|
UNUSED(renderer);
|
||||||
UNUSED(target);
|
UNUSED(target);
|
||||||
return renderer->render_camera.forward;
|
|
||||||
|
return cameraGetDirectionNormalized(renderer->render_camera);
|
||||||
}
|
}
|
||||||
|
|
||||||
static double _getPrecision(Renderer* renderer, Vector3 location)
|
static double _getPrecision(Renderer* renderer, Vector3 location)
|
||||||
{
|
{
|
||||||
|
|
||||||
UNUSED(renderer);
|
UNUSED(renderer);
|
||||||
UNUSED(location);
|
UNUSED(location);
|
||||||
return 0.0;
|
return 0.0;
|
||||||
|
@ -46,18 +48,21 @@ static double _getPrecision(Renderer* renderer, Vector3 location)
|
||||||
|
|
||||||
static Vector3 _projectPoint(Renderer* renderer, Vector3 point)
|
static Vector3 _projectPoint(Renderer* renderer, Vector3 point)
|
||||||
{
|
{
|
||||||
|
|
||||||
UNUSED(renderer);
|
UNUSED(renderer);
|
||||||
return point;
|
return point;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Vector3 _unprojectPoint(Renderer* renderer, Vector3 point)
|
static Vector3 _unprojectPoint(Renderer* renderer, Vector3 point)
|
||||||
{
|
{
|
||||||
|
|
||||||
UNUSED(renderer);
|
UNUSED(renderer);
|
||||||
return point;
|
return point;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _pushTriangle(Renderer* renderer, Vector3 v1, Vector3 v2, Vector3 v3, f_RenderFragmentCallback callback, void* callback_data)
|
static void _pushTriangle(Renderer* renderer, Vector3 v1, Vector3 v2, Vector3 v3, f_RenderFragmentCallback callback, void* callback_data)
|
||||||
{
|
{
|
||||||
|
|
||||||
Vector3 p1, p2, p3;
|
Vector3 p1, p2, p3;
|
||||||
|
|
||||||
p1 = renderer->projectPoint(renderer, v1);
|
p1 = renderer->projectPoint(renderer, v1);
|
||||||
|
@ -69,12 +74,14 @@ static void _pushTriangle(Renderer* renderer, Vector3 v1, Vector3 v2, Vector3 v3
|
||||||
|
|
||||||
static void _pushQuad(Renderer* renderer, Vector3 v1, Vector3 v2, Vector3 v3, Vector3 v4, f_RenderFragmentCallback callback, void* callback_data)
|
static void _pushQuad(Renderer* renderer, Vector3 v1, Vector3 v2, Vector3 v3, Vector3 v4, f_RenderFragmentCallback callback, void* callback_data)
|
||||||
{
|
{
|
||||||
|
|
||||||
renderer->pushTriangle(renderer, v2, v3, v1, callback, callback_data);
|
renderer->pushTriangle(renderer, v2, v3, v1, callback, callback_data);
|
||||||
renderer->pushTriangle(renderer, v4, v1, v3, callback, callback_data);
|
renderer->pushTriangle(renderer, v4, v1, v3, callback, callback_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _pushDisplacedTriangle(Renderer* renderer, Vector3 v1, Vector3 v2, Vector3 v3, Vector3 ov1, Vector3 ov2, Vector3 ov3, f_RenderFragmentCallback callback, void* callback_data)
|
static void _pushDisplacedTriangle(Renderer* renderer, Vector3 v1, Vector3 v2, Vector3 v3, Vector3 ov1, Vector3 ov2, Vector3 ov3, f_RenderFragmentCallback callback, void* callback_data)
|
||||||
{
|
{
|
||||||
|
|
||||||
Vector3 p1, p2, p3;
|
Vector3 p1, p2, p3;
|
||||||
|
|
||||||
p1 = renderer->projectPoint(renderer, v1);
|
p1 = renderer->projectPoint(renderer, v1);
|
||||||
|
@ -86,17 +93,20 @@ static void _pushDisplacedTriangle(Renderer* renderer, Vector3 v1, Vector3 v2, V
|
||||||
|
|
||||||
static void _pushDisplacedQuad(Renderer* renderer, Vector3 v1, Vector3 v2, Vector3 v3, Vector3 v4, Vector3 ov1, Vector3 ov2, Vector3 ov3, Vector3 ov4, f_RenderFragmentCallback callback, void* callback_data)
|
static void _pushDisplacedQuad(Renderer* renderer, Vector3 v1, Vector3 v2, Vector3 v3, Vector3 v4, Vector3 ov1, Vector3 ov2, Vector3 ov3, Vector3 ov4, f_RenderFragmentCallback callback, void* callback_data)
|
||||||
{
|
{
|
||||||
|
|
||||||
renderer->pushDisplacedTriangle(renderer, v2, v3, v1, ov2, ov3, ov1, callback, callback_data);
|
renderer->pushDisplacedTriangle(renderer, v2, v3, v1, ov2, ov3, ov1, callback, callback_data);
|
||||||
renderer->pushDisplacedTriangle(renderer, v4, v1, v3, ov4, ov1, ov3, callback, callback_data);
|
renderer->pushDisplacedTriangle(renderer, v4, v1, v3, ov4, ov1, ov3, callback, callback_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
static RayCastingResult _rayWalking(Renderer* renderer, Vector3 location, Vector3 direction, int terrain, int water, int sky, int clouds)
|
static RayCastingResult _rayWalking(Renderer* renderer, Vector3 location, Vector3 direction, int terrain, int water, int sky, int clouds)
|
||||||
{
|
{
|
||||||
|
|
||||||
return _RAYCASTING_NULL;
|
return _RAYCASTING_NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Color _applyLightingToSurface(Renderer* renderer, Vector3 location, Vector3 normal, SurfaceMaterial* material)
|
static Color _applyLightingToSurface(Renderer* renderer, Vector3 location, Vector3 normal, SurfaceMaterial* material)
|
||||||
{
|
{
|
||||||
|
|
||||||
LightStatus* light = lightingCreateStatus(renderer->lighting, location, renderer->getCameraLocation(renderer, location));
|
LightStatus* light = lightingCreateStatus(renderer->lighting, location, renderer->getCameraLocation(renderer, location));
|
||||||
renderer->atmosphere->getLightingStatus(renderer, light, normal, 0);
|
renderer->atmosphere->getLightingStatus(renderer, light, normal, 0);
|
||||||
Color result = lightingApplyStatus(light, normal, material);
|
Color result = lightingApplyStatus(light, normal, material);
|
||||||
|
@ -106,6 +116,7 @@ static Color _applyLightingToSurface(Renderer* renderer, Vector3 location, Vecto
|
||||||
|
|
||||||
static Color _applyMediumTraversal(Renderer* renderer, Vector3 location, Color color)
|
static Color _applyMediumTraversal(Renderer* renderer, Vector3 location, Color color)
|
||||||
{
|
{
|
||||||
|
|
||||||
color = renderer->atmosphere->applyAerialPerspective(renderer, location, color).final;
|
color = renderer->atmosphere->applyAerialPerspective(renderer, location, color).final;
|
||||||
color = renderer->clouds->getColor(renderer, color, renderer->getCameraLocation(renderer, location), location);
|
color = renderer->clouds->getColor(renderer, color, renderer->getCameraLocation(renderer, location), location);
|
||||||
return color;
|
return color;
|
||||||
|
@ -113,6 +124,7 @@ static Color _applyMediumTraversal(Renderer* renderer, Vector3 location, Color c
|
||||||
|
|
||||||
Renderer* rendererCreate()
|
Renderer* rendererCreate()
|
||||||
{
|
{
|
||||||
|
|
||||||
Renderer* result = malloc(sizeof (Renderer));
|
Renderer* result = malloc(sizeof (Renderer));
|
||||||
RenderParams params = {1, 1, 1, 5};
|
RenderParams params = {1, 1, 1, 5};
|
||||||
|
|
||||||
|
@ -156,6 +168,8 @@ Renderer* rendererCreate()
|
||||||
|
|
||||||
void rendererDelete(Renderer* renderer)
|
void rendererDelete(Renderer* renderer)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
cameraDeleteDefinition(renderer->render_camera);
|
||||||
lightingManagerDelete(renderer->lighting);
|
lightingManagerDelete(renderer->lighting);
|
||||||
|
|
||||||
AtmosphereRendererClass.destroy(renderer->atmosphere);
|
AtmosphereRendererClass.destroy(renderer->atmosphere);
|
||||||
|
@ -171,6 +185,7 @@ void rendererDelete(Renderer* renderer)
|
||||||
|
|
||||||
void rendererSetPreviewCallbacks(Renderer* renderer, RenderCallbackStart start, RenderCallbackDraw draw, RenderCallbackUpdate update)
|
void rendererSetPreviewCallbacks(Renderer* renderer, RenderCallbackStart start, RenderCallbackDraw draw, RenderCallbackUpdate update)
|
||||||
{
|
{
|
||||||
|
|
||||||
renderSetPreviewCallbacks(renderer->render_area, start, draw, update);
|
renderSetPreviewCallbacks(renderer->render_area, start, draw, update);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -189,7 +204,7 @@ void rendererStart(Renderer* renderer, RenderParams params)
|
||||||
renderer->render_interrupt = 0;
|
renderer->render_interrupt = 0;
|
||||||
renderer->render_progress = 0.0;
|
renderer->render_progress = 0.0;
|
||||||
|
|
||||||
cameraSetRenderSize(&renderer->render_camera, renderer->render_width, renderer->render_height);
|
cameraSetRenderSize(renderer->render_camera, renderer->render_width, renderer->render_height);
|
||||||
|
|
||||||
renderSetBackgroundColor(renderer->render_area, &COLOR_BLACK);
|
renderSetBackgroundColor(renderer->render_area, &COLOR_BLACK);
|
||||||
renderSetParams(renderer->render_area, params);
|
renderSetParams(renderer->render_area, params);
|
||||||
|
@ -205,6 +220,7 @@ void rendererStart(Renderer* renderer, RenderParams params)
|
||||||
|
|
||||||
if (++loops >= 10)
|
if (++loops >= 10)
|
||||||
{
|
{
|
||||||
|
|
||||||
renderUpdate(renderer->render_area);
|
renderUpdate(renderer->render_area);
|
||||||
loops = 0;
|
loops = 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,10 +7,12 @@
|
||||||
#include "terrain/public.h"
|
#include "terrain/public.h"
|
||||||
#include "textures/public.h"
|
#include "textures/public.h"
|
||||||
#include "water/public.h"
|
#include "water/public.h"
|
||||||
|
#include "camera.h"
|
||||||
#include "render.h"
|
#include "render.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C"
|
||||||
|
{
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct Renderer
|
struct Renderer
|
||||||
|
@ -19,7 +21,7 @@ struct Renderer
|
||||||
int render_quality;
|
int render_quality;
|
||||||
int render_width;
|
int render_width;
|
||||||
int render_height;
|
int render_height;
|
||||||
CameraDefinition render_camera;
|
CameraDefinition* render_camera;
|
||||||
|
|
||||||
/* Render related */
|
/* Render related */
|
||||||
RenderArea* render_area;
|
RenderArea* render_area;
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
#include "system.h"
|
#include "system.h"
|
||||||
|
|
||||||
static AtmosphereDefinition* _atmosphere;
|
static AtmosphereDefinition* _atmosphere;
|
||||||
static CameraDefinition _camera;
|
static CameraDefinition* _camera;
|
||||||
static CloudsDefinition* _clouds;
|
static CloudsDefinition* _clouds;
|
||||||
static TerrainDefinition* _terrain;
|
static TerrainDefinition* _terrain;
|
||||||
static TexturesDefinition* _textures;
|
static TexturesDefinition* _textures;
|
||||||
|
@ -34,7 +34,7 @@ void sceneryInit()
|
||||||
void sceneryQuit()
|
void sceneryQuit()
|
||||||
{
|
{
|
||||||
AtmosphereDefinitionClass.destroy(_atmosphere);
|
AtmosphereDefinitionClass.destroy(_atmosphere);
|
||||||
cameraDeleteDefinition(&_camera);
|
cameraDeleteDefinition(_camera);
|
||||||
CloudsDefinitionClass.destroy(_clouds);
|
CloudsDefinitionClass.destroy(_clouds);
|
||||||
TerrainDefinitionClass.destroy(_terrain);
|
TerrainDefinitionClass.destroy(_terrain);
|
||||||
TexturesDefinitionClass.destroy(_textures);
|
TexturesDefinitionClass.destroy(_textures);
|
||||||
|
@ -63,7 +63,7 @@ void scenerySave(PackStream* stream)
|
||||||
{
|
{
|
||||||
noiseSave(stream);
|
noiseSave(stream);
|
||||||
AtmosphereDefinitionClass.save(stream, _atmosphere);
|
AtmosphereDefinitionClass.save(stream, _atmosphere);
|
||||||
cameraSave(stream, &_camera);
|
cameraSave(stream, _camera);
|
||||||
CloudsDefinitionClass.save(stream, _clouds);
|
CloudsDefinitionClass.save(stream, _clouds);
|
||||||
TerrainDefinitionClass.save(stream, _terrain);
|
TerrainDefinitionClass.save(stream, _terrain);
|
||||||
TexturesDefinitionClass.save(stream, _textures);
|
TexturesDefinitionClass.save(stream, _textures);
|
||||||
|
@ -81,7 +81,7 @@ void sceneryLoad(PackStream* stream)
|
||||||
|
|
||||||
noiseLoad(stream);
|
noiseLoad(stream);
|
||||||
AtmosphereDefinitionClass.load(stream, _atmosphere);
|
AtmosphereDefinitionClass.load(stream, _atmosphere);
|
||||||
cameraLoad(stream, &_camera);
|
cameraLoad(stream, _camera);
|
||||||
CloudsDefinitionClass.load(stream, _clouds);
|
CloudsDefinitionClass.load(stream, _clouds);
|
||||||
TerrainDefinitionClass.load(stream, _terrain);
|
TerrainDefinitionClass.load(stream, _terrain);
|
||||||
TexturesDefinitionClass.load(stream, _textures);
|
TexturesDefinitionClass.load(stream, _textures);
|
||||||
|
@ -105,13 +105,13 @@ void sceneryGetAtmosphere(AtmosphereDefinition* atmosphere)
|
||||||
|
|
||||||
void scenerySetCamera(CameraDefinition* camera)
|
void scenerySetCamera(CameraDefinition* camera)
|
||||||
{
|
{
|
||||||
cameraCopyDefinition(camera, &_camera);
|
cameraCopyDefinition(camera, _camera);
|
||||||
cameraValidateDefinition(&_camera, 1);
|
cameraValidateDefinition(_camera, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sceneryGetCamera(CameraDefinition* camera)
|
void sceneryGetCamera(CameraDefinition* camera)
|
||||||
{
|
{
|
||||||
cameraCopyDefinition(&_camera, camera);
|
cameraCopyDefinition(_camera, camera);
|
||||||
}
|
}
|
||||||
|
|
||||||
void scenerySetClouds(CloudsDefinition* clouds)
|
void scenerySetClouds(CloudsDefinition* clouds)
|
||||||
|
@ -128,7 +128,7 @@ void scenerySetTerrain(TerrainDefinition* terrain)
|
||||||
{
|
{
|
||||||
TerrainDefinitionClass.copy(terrain, _terrain);
|
TerrainDefinitionClass.copy(terrain, _terrain);
|
||||||
|
|
||||||
cameraValidateDefinition(&_camera, 1);
|
cameraValidateDefinition(_camera, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sceneryGetTerrain(TerrainDefinition* terrain)
|
void sceneryGetTerrain(TerrainDefinition* terrain)
|
||||||
|
@ -140,7 +140,7 @@ void scenerySetTextures(TexturesDefinition* textures)
|
||||||
{
|
{
|
||||||
TexturesDefinitionClass.copy(textures, _textures);
|
TexturesDefinitionClass.copy(textures, _textures);
|
||||||
|
|
||||||
cameraValidateDefinition(&_camera, 1);
|
cameraValidateDefinition(_camera, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sceneryGetTextures(TexturesDefinition* textures)
|
void sceneryGetTextures(TexturesDefinition* textures)
|
||||||
|
@ -152,7 +152,7 @@ void scenerySetWater(WaterDefinition* water)
|
||||||
{
|
{
|
||||||
WaterDefinitionClass.copy(water, _water);
|
WaterDefinitionClass.copy(water, _water);
|
||||||
|
|
||||||
cameraValidateDefinition(&_camera, 1);
|
cameraValidateDefinition(_camera, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sceneryGetWater(WaterDefinition* water)
|
void sceneryGetWater(WaterDefinition* water)
|
||||||
|
@ -167,11 +167,6 @@ void sceneryRenderFirstPass(Renderer* renderer)
|
||||||
atmosphereRenderSkydome(renderer);
|
atmosphereRenderSkydome(renderer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/******* Standard renderer *********/
|
/******* Standard renderer *********/
|
||||||
static RayCastingResult _rayWalking(Renderer* renderer, Vector3 location, Vector3 direction, int terrain, int water, int sky, int clouds)
|
static RayCastingResult _rayWalking(Renderer* renderer, Vector3 location, Vector3 direction, int terrain, int water, int sky, int clouds)
|
||||||
{
|
{
|
||||||
|
@ -193,23 +188,23 @@ static RayCastingResult _rayWalking(Renderer* renderer, Vector3 location, Vector
|
||||||
|
|
||||||
static Vector3 _projectPoint(Renderer* renderer, Vector3 point)
|
static Vector3 _projectPoint(Renderer* renderer, Vector3 point)
|
||||||
{
|
{
|
||||||
return cameraProject(&renderer->render_camera, renderer, point);
|
return cameraProject(renderer->render_camera, point);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Vector3 _unprojectPoint(Renderer* renderer, Vector3 point)
|
static Vector3 _unprojectPoint(Renderer* renderer, Vector3 point)
|
||||||
{
|
{
|
||||||
return cameraUnproject(&renderer->render_camera, renderer, point);
|
return cameraUnproject(renderer->render_camera, point);
|
||||||
}
|
}
|
||||||
|
|
||||||
static double _getPrecision(Renderer* renderer, Vector3 location)
|
static double _getPrecision(Renderer* renderer, Vector3 location)
|
||||||
{
|
{
|
||||||
Vector3 projected;
|
Vector3 projected;
|
||||||
|
|
||||||
projected = cameraProject(&renderer->render_camera, renderer, location);
|
projected = cameraProject(renderer->render_camera, location);
|
||||||
projected.x += 1.0;
|
projected.x += 1.0;
|
||||||
//projected.y += 1.0;
|
//projected.y += 1.0;
|
||||||
|
|
||||||
return v3Norm(v3Sub(cameraUnproject(&renderer->render_camera, renderer, projected), location)); // / (double)render_quality;
|
return v3Norm(v3Sub(cameraUnproject(renderer->render_camera, projected), location)); // / (double)render_quality;
|
||||||
}
|
}
|
||||||
|
|
||||||
Renderer* sceneryCreateStandardRenderer()
|
Renderer* sceneryCreateStandardRenderer()
|
||||||
|
@ -218,7 +213,7 @@ Renderer* sceneryCreateStandardRenderer()
|
||||||
|
|
||||||
result = rendererCreate();
|
result = rendererCreate();
|
||||||
|
|
||||||
cameraCopyDefinition(&_camera, &result->render_camera);
|
cameraCopyDefinition(_camera, result->render_camera);
|
||||||
|
|
||||||
result->rayWalking = _rayWalking;
|
result->rayWalking = _rayWalking;
|
||||||
result->projectPoint = _projectPoint;
|
result->projectPoint = _projectPoint;
|
||||||
|
|
|
@ -27,8 +27,8 @@ static void _deleteRenderer(PreviewRenderer* renderer)
|
||||||
|
|
||||||
static void _setCamera(PreviewRenderer* renderer, Vector3 location, Vector3 target)
|
static void _setCamera(PreviewRenderer* renderer, Vector3 location, Vector3 target)
|
||||||
{
|
{
|
||||||
cameraSetLocation(&renderer->renderer->render_camera, location.x, location.y, location.z);
|
cameraSetLocation(renderer->renderer->render_camera, location);
|
||||||
cameraSetTarget(&renderer->renderer->render_camera, target.x, target.y, target.z);
|
cameraSetTarget(renderer->renderer->render_camera, target);
|
||||||
}
|
}
|
||||||
|
|
||||||
PreviewClass previewCreateClass(FuncPreviewCustomizeRenderer customizeRenderer, FuncPreviewBindDefinition bindDefinition, FuncPreviewGetPixelColor getPixelColor)
|
PreviewClass previewCreateClass(FuncPreviewCustomizeRenderer customizeRenderer, FuncPreviewBindDefinition bindDefinition, FuncPreviewGetPixelColor getPixelColor)
|
||||||
|
|
|
@ -25,29 +25,6 @@ typedef struct
|
||||||
double base_height;
|
double base_height;
|
||||||
} HeightInfo;
|
} HeightInfo;
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
Vector3 location;
|
|
||||||
double yaw;
|
|
||||||
double pitch;
|
|
||||||
double roll;
|
|
||||||
|
|
||||||
Vector3 target;
|
|
||||||
Vector3 forward;
|
|
||||||
Vector3 right;
|
|
||||||
Vector3 up;
|
|
||||||
|
|
||||||
double width;
|
|
||||||
double height;
|
|
||||||
double yfov;
|
|
||||||
double xratio;
|
|
||||||
double znear;
|
|
||||||
double zfar;
|
|
||||||
|
|
||||||
Matrix4 project;
|
|
||||||
Matrix4 unproject;
|
|
||||||
} CameraDefinition;
|
|
||||||
|
|
||||||
typedef void* (*FuncObjectCreate)();
|
typedef void* (*FuncObjectCreate)();
|
||||||
typedef void (*FuncObjectDelete)(void* object);
|
typedef void (*FuncObjectDelete)(void* object);
|
||||||
typedef void (*FuncObjectCopy)(void* source, void* destination);
|
typedef void (*FuncObjectCopy)(void* source, void* destination);
|
||||||
|
|
|
@ -102,10 +102,13 @@ Vector3 v3Cross(Vector3 v1, Vector3 v2)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void v3ToEuler(Vector3 v, double* heading, double* attitude)
|
VectorSpherical v3ToSpherical(Vector3 v)
|
||||||
{
|
{
|
||||||
*heading = euclidGet2DAngle(v.x, v.z);
|
VectorSpherical result;
|
||||||
*attitude = euclidGet2DAngle(sqrt(v.x * v.x + v.z * v.z), v.y);
|
result.phi = euclidGet2DAngle(v.x, v.z);
|
||||||
|
result.theta = euclidGet2DAngle(sqrt(v.x * v.x + v.z * v.z), v.y);
|
||||||
|
result.r = v3Norm(v);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void m4Save(PackStream* stream, Matrix4* m)
|
void m4Save(PackStream* stream, Matrix4* m)
|
||||||
|
|
|
@ -3,8 +3,36 @@
|
||||||
|
|
||||||
#include "pack.h"
|
#include "pack.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Cartesian coordinates (X, Y, Z) - right handed :
|
||||||
|
*
|
||||||
|
* Y (up)
|
||||||
|
* |
|
||||||
|
* |
|
||||||
|
* +----X
|
||||||
|
* /
|
||||||
|
* /
|
||||||
|
* Z
|
||||||
|
*
|
||||||
|
* Spherical coordinates (R, PHI, THETA) :
|
||||||
|
*
|
||||||
|
* R is the distance to origin
|
||||||
|
* PHI is typical azimuth
|
||||||
|
* THETA is elevation angle (not polar angle!)
|
||||||
|
*
|
||||||
|
* X=1 Y=0 Z=0 => PHI=0
|
||||||
|
* X=0 Y=0 Z=-1 => PHI=PI/2
|
||||||
|
* X=-1 Y=0 Z=0 => PHI=PI
|
||||||
|
* X=0 Y=0 Z=1 => PHI=3*PI/2
|
||||||
|
*
|
||||||
|
* X=1 Y=0 Z=0 => THETA=0
|
||||||
|
* X=0 Y=1 Z=0 => THETA=PI/2
|
||||||
|
* X=0 Y=-1 Z=0 => THETA=-PI/2
|
||||||
|
*/
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C"
|
||||||
|
{
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
|
@ -14,6 +42,13 @@ typedef struct
|
||||||
double z;
|
double z;
|
||||||
} Vector3;
|
} Vector3;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
double r;
|
||||||
|
double theta;
|
||||||
|
double phi;
|
||||||
|
} VectorSpherical;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
double a;
|
double a;
|
||||||
|
@ -53,7 +88,7 @@ double v3Norm(Vector3 v);
|
||||||
Vector3 v3Normalize(Vector3 v);
|
Vector3 v3Normalize(Vector3 v);
|
||||||
double v3Dot(Vector3 v1, Vector3 v2);
|
double v3Dot(Vector3 v1, Vector3 v2);
|
||||||
Vector3 v3Cross(Vector3 v1, Vector3 v2);
|
Vector3 v3Cross(Vector3 v1, Vector3 v2);
|
||||||
void v3ToEuler(Vector3 v, double* heading, double* attitude);
|
VectorSpherical v3ToSpherical(Vector3 v);
|
||||||
|
|
||||||
void m4Save(PackStream* stream, Matrix4* m);
|
void m4Save(PackStream* stream, Matrix4* m);
|
||||||
void m4Load(PackStream* stream, Matrix4* m);
|
void m4Load(PackStream* stream, Matrix4* m);
|
||||||
|
|
23
src/testing/camera.c
Normal file
23
src/testing/camera.c
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
#include "testing/common.h"
|
||||||
|
|
||||||
|
#include "rendering/camera.h"
|
||||||
|
|
||||||
|
#define _checkVector(_vector_, _x_, _y_, _z_) ck_assert_double_eq(_vector_.x, _x_);ck_assert_double_eq(_vector_.y, _y_);ck_assert_double_eq(_vector_.z, _z_)
|
||||||
|
|
||||||
|
START_TEST(test_camera_definition)
|
||||||
|
{
|
||||||
|
CameraDefinition* cam;
|
||||||
|
cam = cameraCreateDefinition();
|
||||||
|
|
||||||
|
cameraSetLocationCoords(cam, 0.0, 1.0, 1.0);
|
||||||
|
cameraSetTargetCoords(cam, 0.0, 0.0, 0.0);
|
||||||
|
|
||||||
|
_checkVector(cameraGetLocation(cam), 0.0, 1.0, 1.0);
|
||||||
|
_checkVector(cameraGetTarget(cam), 0.0, 1.0, 1.0);
|
||||||
|
|
||||||
|
cameraDeleteDefinition(cam);
|
||||||
|
}
|
||||||
|
END_TEST
|
||||||
|
|
||||||
|
TEST_CASE(camera, test_camera_definition)
|
||||||
|
|
|
@ -5,6 +5,7 @@ static inline int _Vector3_cmp(Vector3 v1, Vector3 v2)
|
||||||
{
|
{
|
||||||
return fabs(v1.x - v2.z) >= 0.00000000001 && fabs(v1.y - v2.y) >= 0.00000000001 && fabs(v1.z - v2.z) >= 0.00000000001;
|
return fabs(v1.x - v2.z) >= 0.00000000001 && fabs(v1.y - v2.y) >= 0.00000000001 && fabs(v1.z - v2.z) >= 0.00000000001;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void _Vector3_str(Vector3 v, char* buffer, int length)
|
static inline void _Vector3_str(Vector3 v, char* buffer, int length)
|
||||||
{
|
{
|
||||||
snprintf(buffer, length, "(%f,%f,%f)", v.x, v.y, v.z);
|
snprintf(buffer, length, "(%f,%f,%f)", v.x, v.y, v.z);
|
||||||
|
@ -36,27 +37,42 @@ START_TEST(test_euclid_angles)
|
||||||
ck_assert_double_eq(euclidGet2DAngle(-0.5, 0.5), 3.0 * M_PI_4);
|
ck_assert_double_eq(euclidGet2DAngle(-0.5, 0.5), 3.0 * M_PI_4);
|
||||||
ck_assert_double_eq(euclidGet2DAngle(-0.5, -0.5), 5.0 * M_PI_4);
|
ck_assert_double_eq(euclidGet2DAngle(-0.5, -0.5), 5.0 * M_PI_4);
|
||||||
}
|
}
|
||||||
|
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
START_TEST(test_vectors)
|
START_TEST(test_vectors)
|
||||||
{
|
{
|
||||||
Vector3 v1, v2, v3;
|
Vector3 v1, v2, v3;
|
||||||
double d1, d2;
|
|
||||||
|
|
||||||
/* Test scaling */
|
/* Test scaling */
|
||||||
v1.x = 0.0; v1.y = -4.3; v1.z = 8.2;
|
v1.x = 0.0;
|
||||||
v2.x = 0.0; v2.y = -8.6; v2.z = 16.4;
|
v1.y = -4.3;
|
||||||
v3.x = 0.0; v3.y = 2.15; v3.z = -4.1;
|
v1.z = 8.2;
|
||||||
|
v2.x = 0.0;
|
||||||
|
v2.y = -8.6;
|
||||||
|
v2.z = 16.4;
|
||||||
|
v3.x = 0.0;
|
||||||
|
v3.y = 2.15;
|
||||||
|
v3.z = -4.1;
|
||||||
ck_assert_generic_eq(Vector3, v3Scale(v1, 2.0), v2);
|
ck_assert_generic_eq(Vector3, v3Scale(v1, 2.0), v2);
|
||||||
ck_assert_generic_eq(Vector3, v3Scale(v1, -0.5), v3);
|
ck_assert_generic_eq(Vector3, v3Scale(v1, -0.5), v3);
|
||||||
|
}
|
||||||
|
|
||||||
/* Test euler angles */
|
END_TEST
|
||||||
|
|
||||||
|
START_TEST(test_vectors_spherical)
|
||||||
|
{
|
||||||
|
Vector3 v1;
|
||||||
|
VectorSpherical v2;
|
||||||
|
|
||||||
|
/* Test conversion to spherical */
|
||||||
v1.x = v1.y = v1.z = 0.5;
|
v1.x = v1.y = v1.z = 0.5;
|
||||||
v3ToEuler(v1, &d1, &d2);
|
v2 = v3ToSpherical(v1);
|
||||||
ck_assert_double_eq(d1, M_PI_4);
|
ck_assert_double_eq(v2.r, sqrt(0.5 * 0.5 + 0.5 * 0.5 + 0.5 * 0.5));
|
||||||
ck_assert_double_eq(d2, M_PI_2 - 0.955316618125);
|
ck_assert_double_eq(v2.phi, M_PI_4);
|
||||||
|
ck_assert_double_eq(v2.theta, M_PI_2 - 0.955316618125);
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
TEST_CASE(euclid, test_euclid_angles, test_vectors)
|
TEST_CASE(euclid, test_euclid_angles, test_vectors_spherical)
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
extern void test_euclid_case(Suite* s);
|
extern void test_euclid_case(Suite* s);
|
||||||
|
extern void test_camera_case(Suite* s);
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
|
@ -10,6 +11,7 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
/* TODO Find a way to automate this */
|
/* TODO Find a way to automate this */
|
||||||
test_euclid_case(s);
|
test_euclid_case(s);
|
||||||
|
test_camera_case(s);
|
||||||
|
|
||||||
SRunner *sr = srunner_create(s);
|
SRunner *sr = srunner_create(s);
|
||||||
srunner_run_all(sr, CK_NORMAL);
|
srunner_run_all(sr, CK_NORMAL);
|
||||||
|
|
Loading…
Reference in a new issue