paysages : Restored 3d explorer scrolling.

git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@326 b1fd45b6-86a6-48da-8261-f70d1f35bdcc
This commit is contained in:
Michaël Lemaire 2012-05-09 21:11:23 +00:00 committed by ThunderK
parent 44f88aaafb
commit fe3c08a522
6 changed files with 67 additions and 22 deletions

1
TODO
View file

@ -5,6 +5,7 @@ Technology Preview 2 :
- Compute shadows only once for all textures at a same location.
=> Add an intermediary light status (two pass lighting).
- Add layer sorting/naming.
- Add logarithmic sliders for some float values.
- Save GUI config (views, render params).
- Add an OSD ability on previews and use it for camera location and user landmarks.
- Add a material editor dialog.

View file

@ -10,13 +10,15 @@
#include "../lib_paysages/euclid.h"
#include "../lib_paysages/tools.h"
WandererChunk::WandererChunk(Renderer* renderer, double x, double z, double size)
WandererChunk::WandererChunk(Renderer* renderer, double x, double z, double size, int nbchunks)
{
_renderer = renderer;
_startx = x;
_startz = z;
_size = size;
_overall_step = size * (double)nbchunks;
_restart_needed = false;
priority = 0.0;
@ -63,11 +65,16 @@ void WandererChunk::render(QGLWidget* widget)
}
int tessellation_size = _tessellation_current_size;
int tessellation_inc = _tessellation_max_size / (double)tessellation_size;
double tsize = 1.0 / (double)_tessellation_max_size;
_lock_data.unlock();
if (tessellation_size == 0)
{
return;
}
int tessellation_inc = _tessellation_max_size / (double)tessellation_size;
for (int j = 0; j < _tessellation_max_size; j += tessellation_inc)
{
glBegin(GL_QUAD_STRIP);
@ -86,7 +93,32 @@ void WandererChunk::updatePriority(CameraDefinition* camera)
{
// Compute new priority
_lock_data.lock();
if (_tessellation_current_size == _tessellation_max_size && _texture_current_size == _texture_max_size)
if (camera->location.x > _startx + _overall_step * 0.5)
{
_startx += _overall_step;
_restart_needed = true;
}
if (camera->location.z > _startz + _overall_step * 0.5)
{
_startz += _overall_step;
_restart_needed = true;
}
if (camera->location.x < _startx - _overall_step * 0.5)
{
_startx -= _overall_step;
_restart_needed = true;
}
if (camera->location.z < _startz - _overall_step * 0.5)
{
_startz -= _overall_step;
_restart_needed = true;
}
if (_restart_needed || _texture_current_size <= 1)
{
priority = 1000.0;
}
else if (_tessellation_current_size == _tessellation_max_size && _texture_current_size == _texture_max_size)
{
priority = -1000.0;
}
@ -102,18 +134,18 @@ void WandererChunk::updatePriority(CameraDefinition* camera)
wanted_size = (int)ceil(120.0 - distance / 3.0);
priority = wanted_size - _texture_current_size;
if (_texture_current_size == 1)
{
priority += 100.0;
}
else if (distance < 15.0 && _texture_current_size < _texture_max_size)
/*else if (distance < 30.0 && _texture_current_size < _texture_max_size / 8)
{
priority += 75.0;
}
else if (distance < 30.0 && _texture_current_size < _texture_max_size / 2)
else if (distance < 15.0 && _texture_current_size < _texture_max_size)
{
priority += 50.0;
}
else if (distance < 30.0 && _texture_current_size < _texture_max_size / 2)
{
priority += 25.0;
}*/
if (!cameraIsBoxInView(camera, center, _size, _size, 40.0))
{
@ -125,6 +157,16 @@ void WandererChunk::updatePriority(CameraDefinition* camera)
bool WandererChunk::maintain()
{
if (_restart_needed)
{
_restart_needed = false;
_lock_data.lock();
_texture_current_size = 0;
_tessellation_current_size = 0;
_lock_data.unlock();
}
if (_tessellation_current_size < _tessellation_max_size || _texture_current_size < _texture_max_size)
{
// Improve heightmap resolution

View file

@ -9,7 +9,7 @@
class WandererChunk
{
public:
WandererChunk(Renderer* renderer, double x, double z, double size);
WandererChunk(Renderer* renderer, double x, double z, double size, int nbchunks);
~WandererChunk();
bool maintain();
@ -27,6 +27,8 @@ private:
double _startx;
double _startz;
double _size;
double _overall_step;
bool _restart_needed;
double* _tessellation;
int _tessellation_max_size;

View file

@ -98,22 +98,22 @@ WidgetWanderer::WidgetWanderer(QWidget *parent, CameraDefinition* camera):
_updated = false;
int chunks = 16;
double size = 150.0;
int chunks = 20;
double size = 200.0;
double chunksize = size / (double)chunks;
double start = -size / 2.0;
for (int i = 0; i < chunks; i++)
{
for (int j = 0; j < chunks; j++)
{
WandererChunk* chunk = new WandererChunk(&_renderer, start + chunksize * (double)i, start + chunksize * (double)j, chunksize);
WandererChunk* chunk = new WandererChunk(&_renderer, start + chunksize * (double)i, start + chunksize * (double)j, chunksize, chunks);
_chunks.append(chunk);
_updateQueue.append(chunk);
}
}
startThreads();
startTimer(1000);
startTimer(500);
_average_frame_time = 0.05;
_quality = 3;

View file

@ -81,7 +81,7 @@ void autoGenRealisticLandscape(int seed)
/* Water */
water = waterCreateDefinition();
water.height = 0.0;
water.height = -5.0;
water.transparency = 0.5;
water.reflection = 0.3;
water.transparency_depth = 6.0;
@ -141,7 +141,7 @@ void autoGenRealisticLandscape(int seed)
noiseGenerateBaseNoise(terrain.height_noise, 1048576);
noiseAddLevelsSimple(terrain.height_noise, 12, 1.0, 1.0);
terrain.height_factor = 12.0 / noiseGetMaxValue(terrain.height_noise);
terrain.scaling = 10.0;
terrain.scaling = 20.0;
scenerySetTerrain(&terrain);
terrainDeleteDefinition(&terrain);
@ -163,8 +163,8 @@ void autoGenRealisticLandscape(int seed)
texture->slope_range = 0.001;
texture->thickness_transparency = 0.0;
texture = texturesGetLayer(&textures, texturesAddLayer(&textures));
zoneAddHeightRangeQuick(texture->zone, 1.0, -1.0, 0.0, 3.0, 15.0);
zoneAddSlopeRangeQuick(texture->zone, 1.0, 0.0, 0.0, 0.1, 0.7);
zoneAddHeightRangeQuick(texture->zone, 1.0, -6.0, -5.0, 3.0, 15.0);
zoneAddSlopeRangeQuick(texture->zone, 1.0, 0.0, 0.0, 0.05, 0.4);
noiseGenerateBaseNoise(texture->bump_noise, 102400);
noiseAddLevelsSimple(texture->bump_noise, 5, 1.0, 0.4);
noiseAddLevelsSimple(texture->bump_noise, 2, 0.03, 0.08);

View file

@ -300,10 +300,10 @@ void cameraProjectToFragment(CameraDefinition* camera, Renderer* renderer, doubl
static inline void _updateBox(Vector3* point, double* xmin, double* xmax, double* ymin, double* ymax, double* zmax)
{
*xmin = MIN(*xmax, point->x);
*xmax = MAX(*xmin, point->x);
*ymin = MIN(*ymax, point->y);
*ymax = MAX(*ymin, point->y);
*xmin = MIN(*xmin, point->x);
*xmax = MAX(*xmax, point->x);
*ymin = MIN(*ymin, point->y);
*ymax = MAX(*ymax, point->y);
*zmax = MAX(*zmax, point->z);
}