From 324a01dca171fac5550383da32241b796c6a56a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Thu, 31 Jan 2013 15:10:11 +0000 Subject: [PATCH] paysages : Added custom camera location on renderer for top-down previews. git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@514 b1fd45b6-86a6-48da-8261-f70d1f35bdcc --- gui_qt/explorerchunksky.cpp | 2 +- gui_qt/formrender.cpp | 9 ++++++--- gui_qt/formterrain.cpp | 2 +- gui_qt/formtextures.cpp | 8 ++++---- gui_qt/formwater.cpp | 3 ++- gui_qt/previewmaterial.cpp | 8 ++++---- gui_qt/widgetexplorer.cpp | 1 - lib_paysages/atmosphere/basic.c | 2 +- lib_paysages/atmosphere/bruneton.c | 2 +- lib_paysages/atmosphere/main.c | 9 +++++---- lib_paysages/atmosphere/preview.c | 6 +++--- lib_paysages/atmosphere/raster.c | 19 +++++++++++-------- lib_paysages/clouds/tools.c | 2 +- lib_paysages/renderer.c | 30 +++++++++++++++++++++++++----- lib_paysages/renderer.h | 3 ++- lib_paysages/scenery.c | 1 - lib_paysages/terrain/main.c | 5 ++++- lib_paysages/terrain/preview.c | 13 ++++++++++--- lib_paysages/terrain/raster.c | 5 +++-- lib_paysages/water.c | 10 ++++++---- 20 files changed, 90 insertions(+), 50 deletions(-) diff --git a/gui_qt/explorerchunksky.cpp b/gui_qt/explorerchunksky.cpp index 6fffa19..1f079ac 100644 --- a/gui_qt/explorerchunksky.cpp +++ b/gui_qt/explorerchunksky.cpp @@ -16,7 +16,7 @@ ExplorerChunkSky::ExplorerChunkSky(Renderer* renderer, double size, SkyboxOrient void ExplorerChunkSky::onRenderEvent(QGLWidget*) { double size = _box_size; - Vector3 camera = renderer()->camera_location; + Vector3 camera = renderer()->getCameraLocation(renderer(), VECTOR_ZERO); glBegin(GL_QUADS); switch(_orientation) diff --git a/gui_qt/formrender.cpp b/gui_qt/formrender.cpp index e85ac3d..fff21bb 100644 --- a/gui_qt/formrender.cpp +++ b/gui_qt/formrender.cpp @@ -16,9 +16,7 @@ public: { _renderer = rendererCreate(); _renderer->applyTextures = _applyTextures; - _renderer->camera_location.x = 0.0; - _renderer->camera_location.y = 50.0; - _renderer->camera_location.z = 0.0; + _renderer->getCameraLocation = _getCameraLocation; _textures = texturesCreateDefinition(); _water = waterCreateDefinition(); @@ -82,6 +80,11 @@ private: return texturesGetColor((TexturesDefinition*)(renderer->customData[1]), renderer, location.x, location.z, precision); } + static Vector3 _getCameraLocation(Renderer* renderer, Vector3 location) + { + return v3Add(location, v3Scale(VECTOR_UP, 50.0)); + } + static Color _applyAerialPerspective(Renderer*, Vector3, Color base) { return base; diff --git a/gui_qt/formterrain.cpp b/gui_qt/formterrain.cpp index 6eb5b54..593695c 100644 --- a/gui_qt/formterrain.cpp +++ b/gui_qt/formterrain.cpp @@ -18,7 +18,7 @@ public: addOsd(QString("geolocation")); - configScaling(0.5, 200.0, 3.0, 50.0); + configScaling(20.0, 1000.0, 20.0, 50.0); configScrolling(-1000.0, 1000.0, 0.0, -1000.0, 1000.0, 0.0); } protected: diff --git a/gui_qt/formtextures.cpp b/gui_qt/formtextures.cpp index cecb501..b2664b6 100644 --- a/gui_qt/formtextures.cpp +++ b/gui_qt/formtextures.cpp @@ -27,7 +27,7 @@ public: addOsd(QString("geolocation")); - configScaling(0.5, 200.0, 1.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); } ~PreviewTexturesCoverage() @@ -70,9 +70,9 @@ public: _renderer = rendererCreate(); _renderer->render_quality = 3; - _renderer->camera_location.x = 0.0; - _renderer->camera_location.y = 20.0; - _renderer->camera_location.z = 0.0; + _renderer->render_camera.location.x = 0.0; + _renderer->render_camera.location.y = 20.0; + _renderer->render_camera.location.z = 0.0; _zone = zoneCreate(); diff --git a/gui_qt/formwater.cpp b/gui_qt/formwater.cpp index 07b5615..6241a1f 100644 --- a/gui_qt/formwater.cpp +++ b/gui_qt/formwater.cpp @@ -27,7 +27,7 @@ public: addOsd(QString("geolocation")); addToggle("highlight", tr("Coverage highlight"), true); - configScaling(0.5, 200.0, 3.0, 50.0); + configScaling(20.0, 1000.0, 20.0, 50.0); configScrolling(-1000.0, 1000.0, 0.0, -1000.0, 1000.0, 0.0); } protected: @@ -117,6 +117,7 @@ protected: { Vector3 eye, look, location; + // TODO Camera location eye.x = 0.0; eye.y = scaling; eye.z = -10.0 * scaling; diff --git a/gui_qt/previewmaterial.cpp b/gui_qt/previewmaterial.cpp index 535d2d8..6252c13 100644 --- a/gui_qt/previewmaterial.cpp +++ b/gui_qt/previewmaterial.cpp @@ -22,9 +22,9 @@ SmallMaterialPreview::SmallMaterialPreview(QWidget* parent, SurfaceMaterial* mat _material = material; _renderer = rendererCreate(); - _renderer->camera_location.x = 0.0; - _renderer->camera_location.x = 0.0; - _renderer->camera_location.z = 10.0; + _renderer->render_camera.location.x = 0.0; + _renderer->render_camera.location.x = 0.0; + _renderer->render_camera.location.z = 10.0; } SmallMaterialPreview::~SmallMaterialPreview() @@ -56,7 +56,7 @@ Color SmallMaterialPreview::getColor(double x, double y) } point = v3Normalize(point); - color = lightingApplyOneLight(&_light, _renderer->camera_location, point, point, _material); + color = lightingApplyOneLight(&_light, _renderer->getCameraLocation(_renderer, point), point, point, _material); if (dist > 0.95) { color.a = (1.0 - dist) / 0.05; diff --git a/gui_qt/widgetexplorer.cpp b/gui_qt/widgetexplorer.cpp index e71161d..b581b1e 100644 --- a/gui_qt/widgetexplorer.cpp +++ b/gui_qt/widgetexplorer.cpp @@ -397,7 +397,6 @@ void WidgetExplorer::paintGL() double frame_time; cameraValidateDefinition(&_current_camera, 1); - _renderer->camera_location = _current_camera.location; start_time = QTime::currentTime(); diff --git a/lib_paysages/atmosphere/basic.c b/lib_paysages/atmosphere/basic.c index 1d8230b..7bad9ce 100644 --- a/lib_paysages/atmosphere/basic.c +++ b/lib_paysages/atmosphere/basic.c @@ -6,7 +6,7 @@ Color basicApplyAerialPerspective(Renderer* renderer, Vector3 location, Color base) { - Vector3 direction = v3Sub(location, renderer->camera_location); + Vector3 direction = v3Sub(location, renderer->getCameraLocation(renderer, location)); double distance = v3Norm(direction); AtmosphereDefinition* definition = renderer->atmosphere->definition; double near = 10.0 - definition->humidity * 10.0; diff --git a/lib_paysages/atmosphere/bruneton.c b/lib_paysages/atmosphere/bruneton.c index 3f16488..3b0b5e2 100644 --- a/lib_paysages/atmosphere/bruneton.c +++ b/lib_paysages/atmosphere/bruneton.c @@ -1166,7 +1166,7 @@ Color brunetonGetSkyColor(AtmosphereDefinition* definition, Vector3 eye, Vector3 Color brunetonApplyAerialPerspective(Renderer* renderer, Vector3 location, Color base) { - Vector3 eye = renderer->camera_location; + Vector3 eye = renderer->getCameraLocation(renderer, location); Vector3 sun_position = v3Scale(renderer->atmosphere->getSunDirection(renderer), SUN_DISTANCE); double yoffset = GROUND_OFFSET - renderer->getWaterHeightInfo(renderer).base_height; diff --git a/lib_paysages/atmosphere/main.c b/lib_paysages/atmosphere/main.c index 5611d0e..4ae1c2b 100644 --- a/lib_paysages/atmosphere/main.c +++ b/lib_paysages/atmosphere/main.c @@ -120,10 +120,11 @@ static Color _fakeGetSkyColor(Renderer* renderer, Vector3 direction) static Color _getSkyColor(Renderer* renderer, Vector3 direction) { AtmosphereDefinition* definition; - Vector3 sun_direction, sun_position; + Vector3 sun_direction, sun_position, camera_location; Color sky_color, sun_color; definition = renderer->atmosphere->definition; + camera_location = renderer->getCameraLocation(renderer, VECTOR_ZERO); sun_direction = renderer->atmosphere->getSunDirection(renderer); direction = v3Normalize(direction); @@ -133,10 +134,10 @@ static Color _getSkyColor(Renderer* renderer, Vector3 direction) switch (definition->model) { case ATMOSPHERE_MODEL_BRUNETON: - sky_color = brunetonGetSkyColor(definition, renderer->camera_location, direction, sun_position); + sky_color = brunetonGetSkyColor(definition, camera_location, direction, sun_position); break; case ATMOSPHERE_MODEL_PREETHAM: - sky_color = preethamGetSkyColor(definition, renderer->camera_location, direction, sun_position); + sky_color = preethamGetSkyColor(definition, camera_location, direction, sun_position); break; default: sky_color = COLOR_BLUE; @@ -145,7 +146,7 @@ static Color _getSkyColor(Renderer* renderer, Vector3 direction) /* Get sun shape */ double sun_radius = definition->sun_radius * SUN_RADIUS_SCALED; Vector3 hit1, hit2; - int hits = euclidRayIntersectSphere(renderer->camera_location, direction, sun_position, sun_radius, &hit1, &hit2); + int hits = euclidRayIntersectSphere(camera_location, direction, sun_position, sun_radius, &hit1, &hit2); if (hits > 1) { double dist = v3Norm(v3Sub(hit2, hit1)) / sun_radius; /* distance between intersection points (relative to radius) */ diff --git a/lib_paysages/atmosphere/preview.c b/lib_paysages/atmosphere/preview.c index afb2187..e15268e 100644 --- a/lib_paysages/atmosphere/preview.c +++ b/lib_paysages/atmosphere/preview.c @@ -148,9 +148,9 @@ Renderer* atmosphereCreatePreviewRenderer() { Renderer* result = rendererCreate(); - result->camera_location.x = 0.0; - result->camera_location.y = 7.0; - result->camera_location.z = 0.0; + result->render_camera.location.x = 0.0; + result->render_camera.location.y = 7.0; + result->render_camera.location.z = 0.0; return result; } diff --git a/lib_paysages/atmosphere/raster.c b/lib_paysages/atmosphere/raster.c index 432a603..32a741d 100644 --- a/lib_paysages/atmosphere/raster.c +++ b/lib_paysages/atmosphere/raster.c @@ -8,16 +8,17 @@ static Color _postProcessFragment(Renderer* renderer, Vector3 location, void* data) { - Vector3 direction; + Vector3 camera_location, direction; Color result; UNUSED(data); - direction = v3Sub(location, renderer->camera_location); + camera_location = renderer->getCameraLocation(renderer, location); + direction = v3Sub(location, camera_location); /* TODO Don't compute result->color if it's fully covered by clouds */ result = renderer->atmosphere->getSkyColor(renderer, v3Normalize(direction)); - result = renderer->clouds->getColor(renderer, result, renderer->camera_location, v3Add(renderer->camera_location, v3Scale(direction, 10.0))); + result = renderer->clouds->getColor(renderer, result, camera_location, v3Add(camera_location, v3Scale(direction, 10.0))); return result; } @@ -29,13 +30,15 @@ void atmosphereRenderSkydome(Renderer* renderer) double step_i, step_j; double current_i, current_j; Vector3 vertex1, vertex2, vertex3, vertex4; - Vector3 direction; + Vector3 camera_location, direction; res_i = renderer->render_quality * 40; res_j = renderer->render_quality * 20; step_i = M_PI * 2.0 / (double)res_i; step_j = M_PI / (double)res_j; + camera_location = renderer->getCameraLocation(renderer, VECTOR_ZERO); + for (j = 0; j < res_j; j++) { if (!renderer->addRenderProgress(renderer, 0.0)) @@ -52,22 +55,22 @@ void atmosphereRenderSkydome(Renderer* renderer) direction.x = SPHERE_SIZE * cos(current_i) * cos(current_j); direction.y = SPHERE_SIZE * sin(current_j); direction.z = SPHERE_SIZE * sin(current_i) * cos(current_j); - vertex1 = v3Add(renderer->camera_location, direction); + vertex1 = v3Add(camera_location, direction); direction.x = SPHERE_SIZE * cos(current_i + step_i) * cos(current_j); direction.y = SPHERE_SIZE * sin(current_j); direction.z = SPHERE_SIZE * sin(current_i + step_i) * cos(current_j); - vertex2 = v3Add(renderer->camera_location, direction); + vertex2 = v3Add(camera_location, direction); direction.x = SPHERE_SIZE * cos(current_i + step_i) * cos(current_j + step_j); direction.y = SPHERE_SIZE * sin(current_j + step_j); direction.z = SPHERE_SIZE * sin(current_i + step_i) * cos(current_j + step_j); - vertex3 = v3Add(renderer->camera_location, direction); + vertex3 = v3Add(camera_location, direction); direction.x = SPHERE_SIZE * cos(current_i) * cos(current_j + step_j); direction.y = SPHERE_SIZE * sin(current_j + step_j); direction.z = SPHERE_SIZE * sin(current_i) * cos(current_j + step_j); - vertex4 = v3Add(renderer->camera_location, direction); + vertex4 = v3Add(camera_location, direction); /* TODO Triangles at poles */ renderer->pushQuad(renderer, vertex1, vertex4, vertex3, vertex2, _postProcessFragment, NULL); diff --git a/lib_paysages/clouds/tools.c b/lib_paysages/clouds/tools.c index 49c9295..4e65514 100644 --- a/lib_paysages/clouds/tools.c +++ b/lib_paysages/clouds/tools.c @@ -245,7 +245,7 @@ static Color _applyLayerLighting(CloudsLayerDefinition* definition, Renderer* re return renderer->applyLightingToSurface(renderer, location, normal, &definition->material); - lighting = lightingCreateStatus(renderer->lighting, location, renderer->camera_location); + lighting = lightingCreateStatus(renderer->lighting, location, renderer->getCameraLocation(renderer, location)); renderer->atmosphere->getLightingStatus(renderer, lighting, normal, 0); col1 = lightingApplyStatus(lighting, normal, &definition->material); col2 = lightingApplyStatus(lighting, v3Scale(normal, -1.0), &definition->material); diff --git a/lib_paysages/renderer.c b/lib_paysages/renderer.c index a83118d..4ee006c 100644 --- a/lib_paysages/renderer.c +++ b/lib_paysages/renderer.c @@ -4,9 +4,10 @@ #include "system.h" #include "render.h" #include "scenery.h" +#include "tools.h" -RayCastingResult _RAYCASTING_NULL = {0}; -HeightInfo _WATER_HEIGHT_INFO = {0.0, 0.0, 0.0}; +static RayCastingResult _RAYCASTING_NULL = {0}; +static HeightInfo _WATER_HEIGHT_INFO = {0.0, 0.0, 0.0}; static void* _renderFirstPass(void* data) { @@ -19,21 +20,40 @@ static void* _renderFirstPass(void* data) static int _addRenderProgress(Renderer* renderer, double progress) { + UNUSED(progress); return !renderer->render_interrupt; } +static Vector3 _getCameraLocation(Renderer* renderer, Vector3 target) +{ + UNUSED(renderer); + UNUSED(target); + return renderer->render_camera.location; +} + +static Vector3 _getCameraDirection(Renderer* renderer, Vector3 target) +{ + UNUSED(renderer); + UNUSED(target); + return renderer->render_camera.forward; +} + static double _getPrecision(Renderer* renderer, Vector3 location) { + UNUSED(renderer); + UNUSED(location); return 0.0; } static Vector3 _projectPoint(Renderer* renderer, Vector3 point) { + UNUSED(renderer); return point; } static Vector3 _unprojectPoint(Renderer* renderer, Vector3 point) { + UNUSED(renderer); return point; } @@ -71,7 +91,7 @@ static Color _applyTextures(Renderer* renderer, Vector3 location, double precisi Color _applyLightingToSurface(Renderer* renderer, Vector3 location, Vector3 normal, SurfaceMaterial* material) { - LightStatus* light = lightingCreateStatus(renderer->lighting, location, renderer->camera_location); + LightStatus* light = lightingCreateStatus(renderer->lighting, location, renderer->getCameraLocation(renderer, location)); renderer->atmosphere->getLightingStatus(renderer, light, normal, 0); Color result = lightingApplyStatus(light, normal, material); lightingDeleteStatus(light); @@ -90,12 +110,13 @@ Renderer* rendererCreate() result->render_progress = 0.0; result->is_rendering = 0; result->render_camera = cameraCreateDefinition(); - result->camera_location = result->render_camera.location; result->render_area = renderCreateArea(); renderSetParams(result->render_area, params); result->addRenderProgress = _addRenderProgress; + result->getCameraLocation = _getCameraLocation; + result->getCameraDirection = _getCameraDirection; result->getPrecision = _getPrecision; result->projectPoint = _projectPoint; result->unprojectPoint = _unprojectPoint; @@ -151,7 +172,6 @@ void rendererStart(Renderer* renderer, RenderParams params) renderer->render_progress = 0.0; cameraSetRenderSize(&renderer->render_camera, renderer->render_width, renderer->render_height); - renderer->camera_location = renderer->render_camera.location; renderSetBackgroundColor(renderer->render_area, &COLOR_BLACK); renderSetParams(renderer->render_area, params); diff --git a/lib_paysages/renderer.h b/lib_paysages/renderer.h index 8a364de..edbd834 100644 --- a/lib_paysages/renderer.h +++ b/lib_paysages/renderer.h @@ -18,13 +18,14 @@ struct Renderer int render_width; int render_height; CameraDefinition render_camera; - Vector3 camera_location; /* Render related */ RenderArea* render_area; double render_progress; int render_interrupt; int is_rendering; + Vector3 (*getCameraLocation)(Renderer* renderer, Vector3 target); + Vector3 (*getCameraDirection)(Renderer* renderer, Vector3 target); double (*getPrecision)(Renderer* renderer, Vector3 location); Vector3 (*projectPoint)(Renderer* renderer, Vector3 point); Vector3 (*unprojectPoint)(Renderer* renderer, Vector3 point); diff --git a/lib_paysages/scenery.c b/lib_paysages/scenery.c index b18e492..98b965f 100644 --- a/lib_paysages/scenery.c +++ b/lib_paysages/scenery.c @@ -231,7 +231,6 @@ Renderer* sceneryCreateStandardRenderer() result = rendererCreate(); cameraCopyDefinition(&_camera, &result->render_camera); - result->camera_location = _camera.location; result->rayWalking = _rayWalking; result->getWaterHeightInfo = _getWaterHeightInfo; diff --git a/lib_paysages/terrain/main.c b/lib_paysages/terrain/main.c index 5e94ea0..15c7547 100644 --- a/lib_paysages/terrain/main.c +++ b/lib_paysages/terrain/main.c @@ -110,6 +110,9 @@ static double _getHeight(Renderer* renderer, double x, double z, int with_painti static Color _fakeGetFinalColor(Renderer* renderer, Vector3 location, double precision) { + UNUSED(renderer); + UNUSED(location); + UNUSED(precision); return COLOR_GREEN; } @@ -121,7 +124,7 @@ static Color _getFinalColor(Renderer* renderer, Vector3 location, double precisi /* TODO Factorize this in scenery renderer */ color = renderer->atmosphere->applyAerialPerspective(renderer, location, color); - color = renderer->clouds->getColor(renderer, color, renderer->camera_location, location); + color = renderer->clouds->getColor(renderer, color, renderer->getCameraLocation(renderer, location), location); return color; } diff --git a/lib_paysages/terrain/preview.c b/lib_paysages/terrain/preview.c index 4a7d999..65067c9 100644 --- a/lib_paysages/terrain/preview.c +++ b/lib_paysages/terrain/preview.c @@ -49,16 +49,23 @@ static void _getLightingStatus(Renderer* renderer, LightStatus* status, Vector3 lightingPushLight(status, &light); } +static Vector3 _getCameraLocation(Renderer* renderer, Vector3 location) +{ + UNUSED(renderer); + location.x -= 10.0; + location.y += 15.0; + location.z += 10.0; + return location; +} + Renderer* terrainCreatePreviewRenderer() { Renderer* result = rendererCreate(); result->render_quality = 3; result->applyTextures = _applyTextures; + result->getCameraLocation = _getCameraLocation; result->atmosphere->getLightingStatus = _getLightingStatus; - result->camera_location.x = 0.0; - result->camera_location.y = 50.0; - result->camera_location.z = 0.0; if (!_inited) { diff --git a/lib_paysages/terrain/raster.c b/lib_paysages/terrain/raster.c index a31e19a..f91b103 100644 --- a/lib_paysages/terrain/raster.c +++ b/lib_paysages/terrain/raster.c @@ -47,8 +47,9 @@ static void _renderQuad(TerrainDefinition* definition, Renderer* renderer, doubl void terrainRenderSurface(Renderer* renderer) { int chunk_factor, chunk_count, i; - double cx = renderer->camera_location.x; - double cz = renderer->camera_location.z; + Vector3 cam = renderer->getCameraLocation(renderer, VECTOR_ZERO); + double cx = cam.x; + double cz = cam.z; double min_chunk_size, visible_chunk_size; double radius_int, radius_ext, chunk_size; double water_height; diff --git a/lib_paysages/water.c b/lib_paysages/water.c index af0dfbb..4401722 100644 --- a/lib_paysages/water.c +++ b/lib_paysages/water.c @@ -356,7 +356,7 @@ WaterResult waterGetColorDetail(WaterDefinition* definition, Renderer* renderer, color = renderer->applyLightingToSurface(renderer, location, normal, &material); color = renderer->atmosphere->applyAerialPerspective(renderer, location, color); - color = renderer->clouds->getColor(renderer, color, renderer->camera_location, location); + color = renderer->clouds->getColor(renderer, color, renderer->getCameraLocation(renderer, location), location); result.base = definition->material.base; result.final = color; @@ -371,13 +371,14 @@ Color waterGetColor(WaterDefinition* definition, Renderer* renderer, Vector3 loc static Color _postProcessFragment(Renderer* renderer, Vector3 location, void* data) { - return waterGetColor((WaterDefinition*)data, renderer, location, v3Sub(location, renderer->camera_location)); + return waterGetColor((WaterDefinition*)data, renderer, location, v3Sub(location, renderer->getCameraLocation(renderer, location))); } static Vector3 _getFirstPassVertex(WaterDefinition* definition, double x, double z, double precision) { Vector3 result; + UNUSED(precision); result.x = x; result.y = _getHeight(definition, x, z); result.z = z; @@ -400,8 +401,9 @@ static void _renderQuad(WaterDefinition* definition, Renderer* renderer, double void waterRender(WaterDefinition* definition, Renderer* renderer) { int chunk_factor, chunk_count, i; - double cx = renderer->camera_location.x; - double cz = renderer->camera_location.z; + Vector3 cam = renderer->getCameraLocation(renderer, VECTOR_ZERO); + double cx = cam.x; + double cz = cam.z; double radius_int, radius_ext, base_chunk_size, chunk_size; base_chunk_size = 2.0 / (double)renderer->render_quality;