paysages : Water refactoring (WIP).

git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@528 b1fd45b6-86a6-48da-8261-f70d1f35bdcc
This commit is contained in:
Michaël Lemaire 2013-02-28 15:34:47 +00:00 committed by ThunderK
parent e8b3468038
commit 6521d44916
10 changed files with 136 additions and 60 deletions

1
TODO
View file

@ -1,4 +1,5 @@
Technology Preview 2 :
- Create a StandardPreviewClass (with renderer, updateData, changeView, getColor, choices and toggles).
- Replace terrain canvas editor by full sculpting editor.
=> Add a generation dialog, with fixed resolution.
=> Store local terrain modifications in fully dynamic canvas.

View file

@ -17,14 +17,12 @@ public:
_renderer->getCameraLocation = _getCameraLocation;
_textures = texturesCreateDefinition();
_water = waterCreateDefinition();
_atmosphere = (AtmosphereDefinition*)AtmosphereDefinitionClass.create();
_terrain = (TerrainDefinition*)TerrainDefinitionClass.create();
_water = (WaterDefinition*)WaterDefinitionClass.create();
_renderer->customData[0] = &_terrain;
_renderer->customData[1] = &_textures;
_renderer->customData[3] = &_water;
_renderer->customData[0] = &_textures;
addOsd(QString("geolocation"));
@ -35,16 +33,12 @@ public:
protected:
Color getColor(double x, double y)
{
Vector3 down = {0.0, -1.0, 0.0};
Vector3 location;
double height = _renderer->terrain->getHeight(_renderer, x, y, 1);
if (height < _water.height)
if (height < _water->height)
{
location.x = x;
location.y = _water.height;
location.z = y;
return waterGetColor(&_water, _renderer, location, down);
return _renderer->water->getResult(_renderer, x, y).final;
}
else
{
@ -57,7 +51,9 @@ protected:
void updateData()
{
sceneryGetTextures(&_textures);
sceneryGetWater(&_water);
sceneryGetWater(_water);
WaterRendererClass.bind(_renderer, _water);
sceneryGetAtmosphere(_atmosphere);
AtmosphereRendererClass.bind(_renderer, _atmosphere);
@ -69,13 +65,13 @@ protected:
private:
Renderer* _renderer;
TerrainDefinition* _terrain;
WaterDefinition _water;
WaterDefinition *_water;
TexturesDefinition _textures;
AtmosphereDefinition* _atmosphere;
static Color _applyTextures(Renderer* renderer, Vector3 location, double precision)
{
return texturesGetColor((TexturesDefinition*)(renderer->customData[1]), renderer, location.x, location.z, precision);
return texturesGetColor((TexturesDefinition*)(renderer->customData[0]), renderer, location.x, location.z, precision);
}
static Vector3 _getCameraLocation(Renderer*, Vector3 location)

View file

@ -3,6 +3,7 @@
#include <QColor>
#include <QSlider>
#include <math.h>
#include "../lib_paysages/tools/euclid.h"
#include "../lib_paysages/tools/lighting.h"
@ -64,13 +65,10 @@ public:
_background = 0;
_lighting_enabled = false;
_water = waterCreateDefinition();
_renderer = rendererCreate();
_renderer->atmosphere->getLightingStatus = _getLightingStatus;
_renderer->rayWalking = _rayWalking;
_renderer->customData[0] = &_water;
_renderer->customData[2] = this;
_renderer->customData[0] = this;
configScaling(10.0, 1000.0, 10.0, 250.0);
//configScrolling(-30.0, 30.0, 0.0, -20.0, 20.0, 0.0);
@ -83,7 +81,8 @@ public:
protected:
Color getColor(double x, double y)
{
Vector3 eye, look, location;
Vector3 eye, look;
double target_x, target_z;
// TODO Camera location
eye.x = 0.0;
@ -99,20 +98,19 @@ protected:
return _rayWalking(_renderer, eye, look, 0, 0, 0, 0).hit_color;
}
location.x = eye.x - look.x * eye.y / look.y;
location.y = 0.0;
location.z = eye.z - look.z * eye.y / look.y;
target_x = eye.x - look.x * eye.y / look.y;
target_z = eye.z - look.z * eye.y / look.y;
if (location.z > 0.0)
if (target_z > 0.0)
{
return _rayWalking(_renderer, eye, look, 0, 0, 0, 0).hit_color;
}
return waterGetColor(&_water, _renderer, location, look);
return _renderer->water->getResult(_renderer, target_x, target_z).final;
}
void updateData()
{
waterCopyDefinition(&_definition, &_water);
WaterRendererClass.bind(_renderer, _definition);
_water.height = 0.0;
}
void choiceChangeEvent(const QString& key, int position)
@ -139,7 +137,7 @@ private:
static RayCastingResult _rayWalking(Renderer* renderer, Vector3 location, Vector3 direction, int, int, int, int)
{
RayCastingResult result;
PreviewWaterColor* preview = (PreviewWaterColor*)renderer->customData[2];
PreviewWaterColor* preview = (PreviewWaterColor*)renderer->customData[0];
double x, y;
result.hit = 1;
@ -199,51 +197,51 @@ FormWater::FormWater(QWidget *parent):
addAutoPreset(tr("Lake surface"));
addAutoPreset(tr("Standard sea"));
_definition = waterCreateDefinition();
_definition = (WaterDefinition*)WaterDefinitionClass.create();
previewCoverage = new PreviewWaterCoverage(this);
previewColor = new PreviewWaterColor(this);
addPreview(previewCoverage, tr("Coverage preview"));
addPreview(previewColor, tr("Rendered preview"));
addInputDouble(tr("Height"), &_definition.height, -15.0, 15.0, 0.1, 1.0);
addInputMaterial(tr("Surface material"), &_definition.material);
addInputColor(tr("Depth color"), &_definition.depth_color);
addInputDouble(tr("Transparency"), &_definition.transparency, 0.0, 1.0, 0.001, 0.1);
addInputDouble(tr("Reflection"), &_definition.reflection, 0.0, 1.0, 0.001, 0.1);
addInputDouble(tr("Transparency distance"), &_definition.transparency_depth, 0.0, 20.0, 0.1, 1.0);
addInputDouble(tr("Light-through distance"), &_definition.lighting_depth, 0.0, 20.0, 0.1, 1.0);
addInputDouble(tr("Waves scaling"), &_definition.scaling, 0.02, 2.0, 0.02, 0.2);
addInputDouble(tr("Waves height"), &_definition.waves_height, 0.0, 2.0, 0.02, 0.2);
addInputDouble(tr("Waves detail"), &_definition.detail_height, 0.0, 0.3, 0.003, 0.03);
addInputDouble(tr("Waves turbulence"), &_definition.turbulence, 0.0, 0.5, 0.005, 0.05);
addInputDouble(tr("Foam coverage"), &_definition.foam_coverage, 0.0, 1.0, 0.01, 0.1);
addInputMaterial(tr("Foam material"), &_definition.foam_material);
addInputDouble(tr("Height"), &_definition->height, -15.0, 15.0, 0.1, 1.0);
addInputMaterial(tr("Surface material"), &_definition->material);
addInputColor(tr("Depth color"), &_definition->depth_color);
addInputDouble(tr("Transparency"), &_definition->transparency, 0.0, 1.0, 0.001, 0.1);
addInputDouble(tr("Reflection"), &_definition->reflection, 0.0, 1.0, 0.001, 0.1);
addInputDouble(tr("Transparency distance"), &_definition->transparency_depth, 0.0, 20.0, 0.1, 1.0);
addInputDouble(tr("Light-through distance"), &_definition->lighting_depth, 0.0, 20.0, 0.1, 1.0);
addInputDouble(tr("Waves scaling"), &_definition->scaling, 0.02, 2.0, 0.02, 0.2);
addInputDouble(tr("Waves height"), &_definition->waves_height, 0.0, 2.0, 0.02, 0.2);
addInputDouble(tr("Waves detail"), &_definition->detail_height, 0.0, 0.3, 0.003, 0.03);
addInputDouble(tr("Waves turbulence"), &_definition->turbulence, 0.0, 0.5, 0.005, 0.05);
addInputDouble(tr("Foam coverage"), &_definition->foam_coverage, 0.0, 1.0, 0.01, 0.1);
addInputMaterial(tr("Foam material"), &_definition->foam_material);
revertConfig();
}
void FormWater::revertConfig()
{
sceneryGetWater(&_definition);
sceneryGetWater(_definition);
BaseForm::revertConfig();
}
void FormWater::applyConfig()
{
scenerySetWater(&_definition);
scenerySetWater(_definition);
BaseForm::applyConfig();
}
void FormWater::configChangeEvent()
{
waterValidateDefinition(&_definition);
WaterDefinitionClass.validate(_definition);
BaseForm::configChangeEvent();
}
void FormWater::autoPresetSelected(int preset)
{
waterAutoPreset(&_definition, (WaterPreset)preset);
waterAutoPreset(_definition, (WaterPreset)preset);
BaseForm::autoPresetSelected(preset);
}

View file

@ -67,8 +67,6 @@ WidgetExplorer::WidgetExplorer(QWidget *parent, CameraDefinition* camera):
_base_camera = camera;
cameraCopyDefinition(camera, &_current_camera);
_water = waterCreateDefinition();
sceneryGetWater(&_water);
_textures = texturesCreateDefinition();
sceneryGetTextures(&_textures);
@ -76,7 +74,6 @@ WidgetExplorer::WidgetExplorer(QWidget *parent, CameraDefinition* camera):
_renderer->render_quality = 3;
_renderer->customData[1] = &_textures;
_renderer->customData[2] = _base_camera;
_renderer->customData[3] = &_water;
_renderer->applyTextures = _applyTextures;
_renderer->getCameraLocation = _getCameraLocation;
@ -99,7 +96,6 @@ WidgetExplorer::~WidgetExplorer()
{
delete _chunks[i];
}
waterDeleteDefinition(&_water);
rendererDelete(_renderer);
}
@ -110,7 +106,7 @@ void WidgetExplorer::startRendering()
double size = 400.0;
double chunksize = size / (double)chunks;
double start = -size / 2.0;
double water_height = _renderer->getWaterHeightInfo(_renderer).base_height;
double water_height = _renderer->water->getHeightInfo(_renderer).base_height;
for (int i = 0; i < chunks; i++)
{
for (int j = 0; j < chunks; j++)
@ -402,6 +398,7 @@ void WidgetExplorer::paintGL()
GLenum error_code;
QTime start_time;
double frame_time;
WaterDefinition* water = _renderer->water->definition;
cameraCopyDefinition(&_current_camera, &_renderer->render_camera);
cameraValidateDefinition(&_current_camera, 1);
@ -418,12 +415,12 @@ void WidgetExplorer::paintGL()
// Render water
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);
glVertex3f(_current_camera.location.x - 500.0, _water.height, _current_camera.location.z - 500.0);
glVertex3f(_current_camera.location.x - 500.0, _water.height, _current_camera.location.z + 500.0);
glVertex3f(_current_camera.location.x + 500.0, _water.height, _current_camera.location.z + 500.0);
glVertex3f(_current_camera.location.x + 500.0, _water.height, _current_camera.location.z - 500.0);
glVertex3f(_current_camera.location.x - 500.0, water->height, _current_camera.location.z - 500.0);
glVertex3f(_current_camera.location.x - 500.0, water->height, _current_camera.location.z + 500.0);
glVertex3f(_current_camera.location.x + 500.0, water->height, _current_camera.location.z + 500.0);
glVertex3f(_current_camera.location.x + 500.0, water->height, _current_camera.location.z - 500.0);
glEnd();
// Render chunks

View file

@ -4,7 +4,6 @@
#include <QGLWidget>
#include "baseexplorerchunk.h"
#include "../lib_paysages/camera.h"
#include "../lib_paysages/water.h"
#include "../lib_paysages/renderer.h"
#include "../lib_paysages/textures.h"
@ -48,7 +47,6 @@ private:
bool _alive;
QMutex _lock_chunks;
WaterDefinition _water;
TexturesDefinition _textures;
double _average_frame_time;

View file

@ -1,7 +1,7 @@
BUILDMODE = debug
BUILDPATH = ../build/${BUILDMODE}
OBJPATH = ./obj/${BUILDMODE}
SOURCES = $(wildcard *.c atmosphere/*.c clouds/*.c terrain/*.c water/*.c tools/*.c)
SOURCES = $(wildcard *.c atmosphere/*.c clouds/*.c terrain/*.c water/*.c tools/*.c shared/*.c)
OBJECTS = ${SOURCES:%.c=${OBJPATH}/%.o}
HEADERS = $(wildcard *.h atmosphere/*.h clouds/*.h terrain/*.h water/*.h tools/*.h shared/*.h)
RESULT = ${BUILDPATH}/libpaysages.so

View file

@ -0,0 +1,49 @@
#include "preview.h"
#include "renderer.h"
#include <stdlib.h>
#include "../renderer.h"
#include "../camera.h"
struct PreviewRenderer
{
Renderer* renderer;
};
static PreviewRenderer* _createRenderer()
{
PreviewRenderer* renderer;
renderer = (PreviewRenderer*)malloc(sizeof(PreviewRenderer));
renderer->renderer = rendererCreate();
return renderer;
}
static void _deleteRenderer(PreviewRenderer* renderer)
{
rendererDelete(renderer->renderer);
free(renderer);
}
static void _setCamera(PreviewRenderer* renderer, Vector3 location, Vector3 target)
{
cameraSetLocation(renderer->renderer->render_camera, location);
cameraSetTarget(renderer->renderer->render_camera, target);
}
PreviewClass previewCreateClass(FuncPreviewCustomizeRenderer customizeRenderer, FuncPreviewBindDefinition bindDefinition, FuncPreviewGetPixelColor getPixelColor)
{
PreviewClass result;
result.createRenderer = _createRenderer;
result.deleteRenderer = _deleteRenderer;
result.setCamera = _setCamera;
result.customizeRenderer = customizeRenderer;
result.bindDefinition = bindDefinition;
result.getPixelColor = getPixelColor;
return result;
}

View file

@ -0,0 +1,37 @@
#ifndef _PAYSAGES_SHARED_PREVIEW_H_
#define _PAYSAGES_SHARED_PREVIEW_H_
/*
* Preview management.
*/
#include "types.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct PreviewRenderer PreviewRenderer;
typedef void (*FuncPreviewCustomizeRenderer)(PreviewRenderer* preview_renderer, Renderer* renderer);
typedef void (*FuncPreviewBindDefinition)(PreviewRenderer* renderer, void* definition);
typedef Color (*FuncPreviewGetPixelColor)(PreviewRenderer* renderer, double x, double y, double scaling);
typedef struct {
PreviewRenderer* (*createRenderer)();
void (*deleteRenderer)(PreviewRenderer* renderer);
void (*setCamera)(PreviewRenderer* renderer, Vector3 location, Vector3 target);
FuncPreviewCustomizeRenderer customizeRenderer;
FuncPreviewBindDefinition bindDefinition;
FuncPreviewGetPixelColor getPixelColor;
} PreviewClass;
PreviewClass previewCreateClass(FuncPreviewCustomizeRenderer customizeRenderer, FuncPreviewBindDefinition bindDefinition, FuncPreviewGetPixelColor getPixelColor);
#ifdef __cplusplus
}
#endif
#endif

View file

@ -14,7 +14,7 @@ Color waterGetPreviewCoverage(Renderer* renderer, double x, double y, double sca
double height;
height = renderer->terrain->getHeight(renderer, x, y, 1);
if (height > renderer->water->definition.height)
if (height > renderer->water->definition->height)
{
return terrainGetPreviewColor(renderer, x, y, scaling);
}
@ -34,11 +34,11 @@ Color waterGetPreviewCoverage(Renderer* renderer, double x, double y, double sca
}
}
Renderer* waterCreatePreviewColorRenderer()
/*Renderer* waterCreatePreviewColorRenderer()
{
}
Color waterGetPreviewColor(Renderer* renderer, double x, double y, double scaling)
{
}
}*/

View file

@ -297,7 +297,7 @@ static void _bindRenderer(Renderer* renderer, WaterDefinition* definition)
lightingManagerRegisterFilter(renderer->lighting, (FuncLightingAlterLight)_alterLight, renderer);
}
StandardRenderer CloudsRendererClass = {
StandardRenderer WaterRendererClass = {
(FuncObjectCreate)_createRenderer,
(FuncObjectDelete)_deleteRenderer,
(FuncObjectBind)_bindRenderer