2012-06-08 12:54:57 +00:00
|
|
|
#include "widgetexplorer.h"
|
2012-01-27 14:47:08 +00:00
|
|
|
|
|
|
|
#include <QGLWidget>
|
2012-01-27 16:01:34 +00:00
|
|
|
#include <QKeyEvent>
|
2012-01-30 13:10:16 +00:00
|
|
|
#include <QTime>
|
2012-01-27 17:21:57 +00:00
|
|
|
#include <math.h>
|
2012-04-27 20:05:33 +00:00
|
|
|
#include <GL/glu.h>
|
2012-05-08 14:07:47 +00:00
|
|
|
#include <QThread>
|
2012-01-27 14:47:08 +00:00
|
|
|
#include "../lib_paysages/scenery.h"
|
2013-01-19 22:42:50 +00:00
|
|
|
#include "../lib_paysages/tools/euclid.h"
|
2013-04-16 14:57:14 +00:00
|
|
|
#include "../exploring/main.h"
|
2012-06-08 12:28:46 +00:00
|
|
|
#include "explorerchunkterrain.h"
|
2012-06-08 15:28:29 +00:00
|
|
|
#include "explorerchunksky.h"
|
|
|
|
#include "tools.h"
|
2012-05-08 14:07:47 +00:00
|
|
|
|
|
|
|
class ChunkMaintenanceThread:public QThread
|
|
|
|
{
|
|
|
|
public:
|
2012-06-08 12:54:57 +00:00
|
|
|
ChunkMaintenanceThread(WidgetExplorer* wanderer)
|
2012-05-08 14:07:47 +00:00
|
|
|
{
|
|
|
|
_wanderer = wanderer;
|
|
|
|
_running = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void askStop()
|
|
|
|
{
|
|
|
|
_running = false;
|
|
|
|
}
|
2012-12-09 17:49:28 +00:00
|
|
|
|
2012-05-08 14:07:47 +00:00
|
|
|
static inline void usleep(unsigned long us)
|
|
|
|
{
|
|
|
|
QThread::usleep(us);
|
|
|
|
}
|
2012-12-09 17:49:28 +00:00
|
|
|
|
2012-05-08 14:07:47 +00:00
|
|
|
protected:
|
|
|
|
void run()
|
|
|
|
{
|
|
|
|
while (_running)
|
|
|
|
{
|
|
|
|
_wanderer->performChunksMaintenance();
|
|
|
|
QThread::usleep(10000);
|
|
|
|
}
|
|
|
|
}
|
2012-12-09 17:49:28 +00:00
|
|
|
|
2012-05-08 14:07:47 +00:00
|
|
|
private:
|
|
|
|
bool _running;
|
2012-06-08 12:54:57 +00:00
|
|
|
WidgetExplorer* _wanderer;
|
2012-05-08 14:07:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static QVector<ChunkMaintenanceThread*> _threads;
|
2012-01-27 14:47:08 +00:00
|
|
|
|
2013-02-05 21:25:30 +00:00
|
|
|
static Vector3 _getCameraLocation(Renderer* renderer, Vector3)
|
|
|
|
{
|
|
|
|
return ((CameraDefinition*)renderer->customData[2])->location;
|
|
|
|
}
|
|
|
|
|
2013-04-03 20:37:29 +00:00
|
|
|
static AtmosphereResult _applyAerialPerspective(Renderer*, Vector3, Color base)
|
|
|
|
{
|
|
|
|
AtmosphereResult result;
|
|
|
|
atmosphereInitResult(&result);
|
|
|
|
result.base = base;
|
|
|
|
result.final = base;
|
|
|
|
atmosphereUpdateResult(&result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2012-06-08 12:54:57 +00:00
|
|
|
WidgetExplorer::WidgetExplorer(QWidget *parent, CameraDefinition* camera):
|
2012-01-27 14:47:08 +00:00
|
|
|
QGLWidget(parent)
|
|
|
|
{
|
|
|
|
setMinimumSize(400, 300);
|
2012-01-27 16:01:34 +00:00
|
|
|
setFocusPolicy(Qt::StrongFocus);
|
2012-01-27 14:47:08 +00:00
|
|
|
|
2012-01-27 23:01:21 +00:00
|
|
|
_base_camera = camera;
|
|
|
|
cameraCopyDefinition(camera, &_current_camera);
|
2012-01-27 14:47:08 +00:00
|
|
|
|
2012-11-25 21:53:01 +00:00
|
|
|
_renderer = sceneryCreateStandardRenderer();
|
2013-01-20 15:07:45 +00:00
|
|
|
_renderer->render_quality = 3;
|
2013-02-05 21:25:30 +00:00
|
|
|
_renderer->customData[2] = _base_camera;
|
|
|
|
_renderer->getCameraLocation = _getCameraLocation;
|
2013-04-03 20:37:29 +00:00
|
|
|
_renderer->atmosphere->applyAerialPerspective = _applyAerialPerspective;
|
2013-03-07 14:07:12 +00:00
|
|
|
lightingManagerDisableSpecularity(_renderer->lighting);
|
2012-12-09 17:49:28 +00:00
|
|
|
|
2013-01-31 14:02:17 +00:00
|
|
|
_inited = false;
|
2012-05-08 14:07:47 +00:00
|
|
|
_updated = false;
|
2012-01-27 14:47:08 +00:00
|
|
|
|
2013-01-31 14:02:17 +00:00
|
|
|
_average_frame_time = 0.05;
|
|
|
|
_quality = 3;
|
|
|
|
_last_mouse_x = 0;
|
|
|
|
_last_mouse_y = 0;
|
|
|
|
|
|
|
|
startTimer(500);
|
|
|
|
}
|
|
|
|
|
|
|
|
WidgetExplorer::~WidgetExplorer()
|
|
|
|
{
|
|
|
|
stopRendering();
|
|
|
|
|
|
|
|
for (int i = 0; i < _chunks.count(); i++)
|
|
|
|
{
|
|
|
|
delete _chunks[i];
|
|
|
|
}
|
|
|
|
rendererDelete(_renderer);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WidgetExplorer::startRendering()
|
|
|
|
{
|
2012-06-08 15:28:29 +00:00
|
|
|
// Add terrain
|
2012-05-09 21:11:23 +00:00
|
|
|
int chunks = 20;
|
2013-02-05 21:25:30 +00:00
|
|
|
double size = 400.0;
|
2012-06-17 09:40:40 +00:00
|
|
|
double chunksize = size / (double)chunks;
|
|
|
|
double start = -size / 2.0;
|
2013-02-28 15:34:47 +00:00
|
|
|
double water_height = _renderer->water->getHeightInfo(_renderer).base_height;
|
2012-05-08 12:07:15 +00:00
|
|
|
for (int i = 0; i < chunks; i++)
|
|
|
|
{
|
|
|
|
for (int j = 0; j < chunks; j++)
|
|
|
|
{
|
2013-02-05 21:25:30 +00:00
|
|
|
ExplorerChunkTerrain* chunk = new ExplorerChunkTerrain(_renderer, start + chunksize * (double)i, start + chunksize * (double)j, chunksize, chunks, water_height);
|
2012-05-08 14:07:47 +00:00
|
|
|
_chunks.append(chunk);
|
|
|
|
_updateQueue.append(chunk);
|
2012-05-08 12:07:15 +00:00
|
|
|
}
|
|
|
|
}
|
2012-12-09 17:49:28 +00:00
|
|
|
|
2012-06-08 15:28:29 +00:00
|
|
|
// Add skybox
|
2013-01-18 10:31:13 +00:00
|
|
|
for (int orientation = 0; orientation < 5; orientation++)
|
2012-06-08 15:28:29 +00:00
|
|
|
{
|
2013-01-20 15:07:45 +00:00
|
|
|
ExplorerChunkSky* chunk = new ExplorerChunkSky(_renderer, 500.0, (SkyboxOrientation)orientation);
|
2012-06-08 15:28:29 +00:00
|
|
|
_chunks.append(chunk);
|
|
|
|
_updateQueue.append(chunk);
|
|
|
|
}
|
2012-05-08 14:07:47 +00:00
|
|
|
|
2013-01-31 14:02:17 +00:00
|
|
|
// Start rendering workers
|
2012-05-08 14:07:47 +00:00
|
|
|
int nbcore;
|
|
|
|
_alive = true;
|
2012-12-09 17:49:28 +00:00
|
|
|
|
2012-05-09 11:39:03 +00:00
|
|
|
nbcore = QThread::idealThreadCount();
|
2012-05-08 14:07:47 +00:00
|
|
|
if (nbcore < 1)
|
|
|
|
{
|
|
|
|
nbcore = 1;
|
|
|
|
}
|
2012-12-09 17:49:28 +00:00
|
|
|
|
2012-05-08 14:07:47 +00:00
|
|
|
for (int i = 0; i < nbcore; i++)
|
|
|
|
{
|
|
|
|
_threads.append(new ChunkMaintenanceThread(this));
|
|
|
|
}
|
|
|
|
for (int i = 0; i < _threads.count(); i++)
|
|
|
|
{
|
|
|
|
_threads[i]->start();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-31 14:02:17 +00:00
|
|
|
void WidgetExplorer::stopRendering()
|
2012-05-08 14:07:47 +00:00
|
|
|
{
|
|
|
|
for (int i = 0; i < _threads.count(); i++)
|
|
|
|
{
|
|
|
|
_threads[i]->askStop();
|
|
|
|
}
|
|
|
|
_alive = false;
|
|
|
|
for (int i = 0; i < _threads.count(); i++)
|
|
|
|
{
|
|
|
|
_threads[i]->wait();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-08 12:28:46 +00:00
|
|
|
bool _cmpChunks(const BaseExplorerChunk* c1, const BaseExplorerChunk* c2)
|
2012-05-08 22:03:39 +00:00
|
|
|
{
|
2012-05-09 16:26:07 +00:00
|
|
|
return c1->priority > c2->priority;
|
2012-05-08 22:03:39 +00:00
|
|
|
}
|
|
|
|
|
2012-06-08 12:54:57 +00:00
|
|
|
void WidgetExplorer::performChunksMaintenance()
|
2012-05-08 14:07:47 +00:00
|
|
|
{
|
2012-06-08 12:28:46 +00:00
|
|
|
BaseExplorerChunk* chunk;
|
2012-12-09 17:49:28 +00:00
|
|
|
|
2012-05-08 14:07:47 +00:00
|
|
|
_lock_chunks.lock();
|
|
|
|
if (_updateQueue.count() > 0)
|
|
|
|
{
|
|
|
|
chunk = _updateQueue.takeFirst();
|
|
|
|
_lock_chunks.unlock();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_lock_chunks.unlock();
|
|
|
|
return;
|
|
|
|
}
|
2012-12-09 17:49:28 +00:00
|
|
|
|
2012-05-09 11:39:03 +00:00
|
|
|
if (chunk->maintain())
|
2012-05-08 14:07:47 +00:00
|
|
|
{
|
|
|
|
if (!_alive)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
_updated = true;
|
|
|
|
}
|
2012-12-09 17:49:28 +00:00
|
|
|
|
2012-05-08 14:07:47 +00:00
|
|
|
_lock_chunks.lock();
|
|
|
|
_updateQueue.append(chunk);
|
|
|
|
_lock_chunks.unlock();
|
|
|
|
}
|
|
|
|
|
2012-06-08 12:54:57 +00:00
|
|
|
void WidgetExplorer::resetCamera()
|
2012-01-27 23:01:21 +00:00
|
|
|
{
|
|
|
|
cameraCopyDefinition(_base_camera, &_current_camera);
|
|
|
|
updateGL();
|
|
|
|
}
|
|
|
|
|
2012-06-08 12:54:57 +00:00
|
|
|
void WidgetExplorer::validateCamera()
|
2012-01-27 23:01:21 +00:00
|
|
|
{
|
|
|
|
cameraCopyDefinition(&_current_camera, _base_camera);
|
|
|
|
}
|
|
|
|
|
2012-06-08 12:54:57 +00:00
|
|
|
void WidgetExplorer::keyPressEvent(QKeyEvent* event)
|
2012-01-27 16:01:34 +00:00
|
|
|
{
|
2012-06-17 09:40:40 +00:00
|
|
|
double factor;
|
2012-01-27 16:01:34 +00:00
|
|
|
|
2012-04-22 17:12:39 +00:00
|
|
|
if (event->modifiers() & Qt::ControlModifier)
|
2012-01-27 16:01:34 +00:00
|
|
|
{
|
|
|
|
factor = 0.1;
|
|
|
|
}
|
2012-04-22 17:12:39 +00:00
|
|
|
else if (event->modifiers() & Qt::ShiftModifier)
|
2012-01-27 16:01:34 +00:00
|
|
|
{
|
|
|
|
factor = 10.0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
factor = 1.0;
|
|
|
|
}
|
2012-01-27 17:21:57 +00:00
|
|
|
factor *= 3.0;
|
2012-01-27 16:01:34 +00:00
|
|
|
|
|
|
|
if (event->key() == Qt::Key_Up)
|
|
|
|
{
|
2012-01-27 23:01:21 +00:00
|
|
|
cameraStrafeForward(&_current_camera, 0.1 * factor);
|
2012-01-27 16:01:34 +00:00
|
|
|
updateGL();
|
|
|
|
}
|
|
|
|
else if (event->key() == Qt::Key_Down)
|
|
|
|
{
|
2012-01-27 23:01:21 +00:00
|
|
|
cameraStrafeForward(&_current_camera, -0.1 * factor);
|
2012-01-27 16:01:34 +00:00
|
|
|
updateGL();
|
|
|
|
}
|
|
|
|
else if (event->key() == Qt::Key_Right)
|
|
|
|
{
|
2012-01-27 23:01:21 +00:00
|
|
|
cameraStrafeRight(&_current_camera, 0.1 * factor);
|
2012-01-27 16:01:34 +00:00
|
|
|
updateGL();
|
|
|
|
}
|
|
|
|
else if (event->key() == Qt::Key_Left)
|
|
|
|
{
|
2012-01-27 23:01:21 +00:00
|
|
|
cameraStrafeRight(&_current_camera, -0.1 * factor);
|
2012-01-27 16:01:34 +00:00
|
|
|
updateGL();
|
|
|
|
}
|
|
|
|
else if (event->key() == Qt::Key_PageUp)
|
|
|
|
{
|
2012-01-27 23:01:21 +00:00
|
|
|
cameraStrafeUp(&_current_camera, 0.1 * factor);
|
2012-01-27 16:01:34 +00:00
|
|
|
updateGL();
|
|
|
|
}
|
|
|
|
else if (event->key() == Qt::Key_PageDown)
|
|
|
|
{
|
2012-01-27 23:01:21 +00:00
|
|
|
cameraStrafeUp(&_current_camera, -0.1 * factor);
|
2012-01-27 16:01:34 +00:00
|
|
|
updateGL();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
QGLWidget::keyPressEvent(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-08 12:54:57 +00:00
|
|
|
void WidgetExplorer::mousePressEvent(QMouseEvent* event)
|
2012-01-27 16:01:34 +00:00
|
|
|
{
|
2012-05-08 12:07:15 +00:00
|
|
|
_last_mouse_x = event->x();
|
|
|
|
_last_mouse_y = event->y();
|
2012-01-27 16:01:34 +00:00
|
|
|
|
|
|
|
event->ignore();
|
|
|
|
}
|
|
|
|
|
2012-06-08 12:54:57 +00:00
|
|
|
void WidgetExplorer::mouseMoveEvent(QMouseEvent* event)
|
2012-01-27 16:01:34 +00:00
|
|
|
{
|
2012-06-17 09:40:40 +00:00
|
|
|
double factor;
|
2012-01-27 16:01:34 +00:00
|
|
|
|
2012-04-22 17:12:39 +00:00
|
|
|
if (event->modifiers() & Qt::ControlModifier)
|
2012-01-27 16:01:34 +00:00
|
|
|
{
|
|
|
|
factor = 0.01;
|
|
|
|
}
|
2012-04-22 17:12:39 +00:00
|
|
|
else if (event->modifiers() & Qt::ShiftModifier)
|
2012-01-27 16:01:34 +00:00
|
|
|
{
|
|
|
|
factor = 1.0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
factor = 0.1;
|
|
|
|
}
|
|
|
|
factor *= 0.2;
|
|
|
|
|
|
|
|
if (event->buttons() & Qt::LeftButton)
|
|
|
|
{
|
2012-06-17 09:40:40 +00:00
|
|
|
cameraRotateYaw(&_current_camera, (double)(event->x() - _last_mouse_x) * factor * 0.1);
|
|
|
|
cameraRotatePitch(&_current_camera, (double)(event->y() - _last_mouse_y) * factor * 0.1);
|
2012-01-27 16:01:34 +00:00
|
|
|
updateGL();
|
|
|
|
event->accept();
|
|
|
|
}
|
2012-01-27 17:21:57 +00:00
|
|
|
else if (event->buttons() & Qt::RightButton)
|
|
|
|
{
|
2012-06-17 09:40:40 +00:00
|
|
|
cameraStrafeRight(&_current_camera, (double)(_last_mouse_x - event->x()) * factor);
|
|
|
|
cameraStrafeUp(&_current_camera, (double)(event->y() - _last_mouse_y) * factor);
|
2012-01-27 17:21:57 +00:00
|
|
|
updateGL();
|
|
|
|
event->accept();
|
|
|
|
}
|
2012-01-27 16:01:34 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
event->ignore();
|
|
|
|
}
|
|
|
|
|
2012-05-08 12:07:15 +00:00
|
|
|
_last_mouse_x = event->x();
|
|
|
|
_last_mouse_y = event->y();
|
2012-01-27 16:01:34 +00:00
|
|
|
}
|
|
|
|
|
2012-06-08 12:54:57 +00:00
|
|
|
void WidgetExplorer::wheelEvent(QWheelEvent* event)
|
2012-01-27 16:01:34 +00:00
|
|
|
{
|
2012-06-17 09:40:40 +00:00
|
|
|
double factor;
|
2012-01-27 16:01:34 +00:00
|
|
|
|
2012-04-22 17:12:39 +00:00
|
|
|
if (event->modifiers() & Qt::ControlModifier)
|
2012-01-27 16:01:34 +00:00
|
|
|
{
|
|
|
|
factor = 0.01;
|
|
|
|
}
|
2012-04-22 17:12:39 +00:00
|
|
|
else if (event->modifiers() & Qt::ShiftModifier)
|
2012-01-27 16:01:34 +00:00
|
|
|
{
|
|
|
|
factor = 1.0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
factor = 0.1;
|
|
|
|
}
|
2012-01-27 17:21:57 +00:00
|
|
|
factor *= 0.03;
|
2012-01-27 16:01:34 +00:00
|
|
|
|
|
|
|
if (event->orientation() == Qt::Vertical)
|
|
|
|
{
|
2012-06-17 09:40:40 +00:00
|
|
|
cameraStrafeForward(&_current_camera, (double)event->delta() * factor);
|
2012-01-27 16:01:34 +00:00
|
|
|
updateGL();
|
|
|
|
}
|
|
|
|
event->accept();
|
2012-01-27 14:47:08 +00:00
|
|
|
}
|
|
|
|
|
2013-01-16 14:26:46 +00:00
|
|
|
void WidgetExplorer::timerEvent(QTimerEvent*)
|
2012-05-08 14:07:47 +00:00
|
|
|
{
|
2013-01-31 14:02:17 +00:00
|
|
|
if (!_inited)
|
|
|
|
{
|
|
|
|
_inited = true;
|
|
|
|
startRendering();
|
|
|
|
}
|
|
|
|
|
2012-05-08 14:07:47 +00:00
|
|
|
if (_updated)
|
|
|
|
{
|
|
|
|
_updated = false;
|
|
|
|
updateGL();
|
|
|
|
}
|
2012-12-09 17:49:28 +00:00
|
|
|
|
2012-05-09 11:39:03 +00:00
|
|
|
for (int i = 0; i < _chunks.count(); i++)
|
|
|
|
{
|
2012-05-09 16:26:07 +00:00
|
|
|
_chunks[i]->updatePriority(&_current_camera);
|
2012-05-09 11:39:03 +00:00
|
|
|
}
|
|
|
|
_lock_chunks.lock();
|
|
|
|
qSort(_updateQueue.begin(), _updateQueue.end(), _cmpChunks);
|
|
|
|
_lock_chunks.unlock();
|
2012-05-08 14:07:47 +00:00
|
|
|
}
|
|
|
|
|
2012-06-08 12:54:57 +00:00
|
|
|
void WidgetExplorer::initializeGL()
|
2012-01-27 14:47:08 +00:00
|
|
|
{
|
2013-04-16 14:57:14 +00:00
|
|
|
exploringInit();
|
2012-01-27 14:47:08 +00:00
|
|
|
}
|
|
|
|
|
2012-06-08 12:54:57 +00:00
|
|
|
void WidgetExplorer::resizeGL(int w, int h)
|
2012-01-27 14:47:08 +00:00
|
|
|
{
|
2012-01-31 11:20:52 +00:00
|
|
|
cameraSetRenderSize(&_current_camera, w, h);
|
2013-04-16 14:57:14 +00:00
|
|
|
exploringSetViewPort(w, h, &_current_camera);
|
2012-01-27 17:21:57 +00:00
|
|
|
}
|
|
|
|
|
2012-06-08 12:54:57 +00:00
|
|
|
void WidgetExplorer::paintGL()
|
2012-01-27 17:21:57 +00:00
|
|
|
{
|
2012-06-08 15:28:29 +00:00
|
|
|
GLenum error_code;
|
2012-01-30 13:10:16 +00:00
|
|
|
QTime start_time;
|
2012-06-17 09:40:40 +00:00
|
|
|
double frame_time;
|
2013-02-28 15:34:47 +00:00
|
|
|
WaterDefinition* water = _renderer->water->definition;
|
2012-12-09 17:49:28 +00:00
|
|
|
|
2013-02-05 21:25:30 +00:00
|
|
|
cameraCopyDefinition(&_current_camera, &_renderer->render_camera);
|
2012-01-29 11:34:49 +00:00
|
|
|
cameraValidateDefinition(&_current_camera, 1);
|
2012-12-09 17:49:28 +00:00
|
|
|
|
2012-01-30 13:10:16 +00:00
|
|
|
start_time = QTime::currentTime();
|
2012-12-09 17:49:28 +00:00
|
|
|
|
2012-01-27 14:47:08 +00:00
|
|
|
glMatrixMode(GL_MODELVIEW);
|
|
|
|
glLoadIdentity();
|
2012-01-27 23:01:21 +00:00
|
|
|
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);
|
2012-01-27 14:47:08 +00:00
|
|
|
|
2012-05-08 14:07:47 +00:00
|
|
|
// Background
|
2012-11-25 21:53:01 +00:00
|
|
|
glClearColor(0.0, 0.0, 0.0, 0.0);
|
2012-01-27 14:47:08 +00:00
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
2012-05-08 14:07:47 +00:00
|
|
|
|
2012-05-08 12:07:15 +00:00
|
|
|
// Render water
|
|
|
|
glDisable(GL_TEXTURE_2D);
|
2013-02-28 15:34:47 +00:00
|
|
|
glColor3f(water->material.base.r, water->material.base.g, water->material.base.b);
|
2012-01-27 14:47:08 +00:00
|
|
|
glBegin(GL_QUADS);
|
2013-02-28 15:34:47 +00:00
|
|
|
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);
|
2012-01-27 14:47:08 +00:00
|
|
|
glEnd();
|
|
|
|
|
2012-06-08 15:28:29 +00:00
|
|
|
// Render chunks
|
2012-05-08 12:07:15 +00:00
|
|
|
glEnable(GL_TEXTURE_2D);
|
|
|
|
for (int i = 0; i < _chunks.count(); i++)
|
|
|
|
{
|
2012-05-08 14:07:47 +00:00
|
|
|
glColor3f(1.0, 1.0, 1.0);
|
2012-05-08 12:07:15 +00:00
|
|
|
_chunks[i]->render(this);
|
|
|
|
}
|
2012-12-09 17:49:28 +00:00
|
|
|
|
2012-06-17 09:40:40 +00:00
|
|
|
frame_time = 0.001 * (double)start_time.msecsTo(QTime::currentTime());
|
2012-12-09 17:49:28 +00:00
|
|
|
|
2012-05-08 12:07:15 +00:00
|
|
|
_average_frame_time = _average_frame_time * 0.8 + frame_time * 0.2;
|
2012-01-30 13:10:16 +00:00
|
|
|
//printf("%d %f\n", quality, average_frame_time);
|
2012-12-09 17:49:28 +00:00
|
|
|
|
2012-05-08 12:07:15 +00:00
|
|
|
if (_average_frame_time > 0.1 && _quality > 1)
|
2012-01-30 13:10:16 +00:00
|
|
|
{
|
2012-05-08 12:07:15 +00:00
|
|
|
_quality--;
|
2012-01-30 13:10:16 +00:00
|
|
|
}
|
2012-05-08 12:07:15 +00:00
|
|
|
if (_average_frame_time < 0.04 && _quality < 10)
|
2012-01-30 13:10:16 +00:00
|
|
|
{
|
2012-05-08 12:07:15 +00:00
|
|
|
_quality++;
|
2012-01-30 13:10:16 +00:00
|
|
|
}
|
2012-12-09 17:49:28 +00:00
|
|
|
|
2013-01-31 14:02:17 +00:00
|
|
|
// Messages
|
|
|
|
if (!_inited)
|
|
|
|
{
|
|
|
|
glColor3f(0.0, 0.0, 0.0);
|
|
|
|
renderText(6, height() - 10, tr("Please wait while loading scene..."));
|
|
|
|
glColor3f(1.0, 1.0, 1.0);
|
|
|
|
renderText(5, height() - 9, tr("Please wait while loading scene..."));
|
|
|
|
}
|
|
|
|
|
2012-06-08 15:28:29 +00:00
|
|
|
while ((error_code = glGetError()) != GL_NO_ERROR)
|
|
|
|
{
|
|
|
|
logDebug(QString("[OpenGL] ERROR : ") + (const char*)gluErrorString(error_code));
|
|
|
|
}
|
2012-01-27 14:47:08 +00:00
|
|
|
}
|