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
|
||||
BUILDPATH=./build/${BUILDMODE}
|
||||
CC=gcc
|
||||
MAKE=make
|
||||
|
||||
ifneq (,$(COMPILER))
|
||||
CC=$(COMPILER)
|
||||
endif
|
||||
|
||||
all:
|
||||
@+cd src/rendering && make BUILDMODE=${BUILDMODE} PROJECT_PATH=${CURDIR}
|
||||
@+cd src/exploring && make BUILDMODE=${BUILDMODE} PROJECT_PATH=${CURDIR}
|
||||
@+cd src/controlling && make BUILDMODE=${BUILDMODE} PROJECT_PATH=${CURDIR}
|
||||
@+cd src/editing && qmake "BUILDMODE=${BUILDMODE}" "PROJECT_PATH=${CURDIR}" && make
|
||||
@+cd src/testing && make BUILDMODE=${BUILDMODE} PROJECT_PATH=${CURDIR}
|
||||
@+cd src/rendering && $(MAKE) CC=${CC} BUILDMODE=${BUILDMODE} PROJECT_PATH=${CURDIR}
|
||||
@+cd src/exploring && $(MAKE) CC=${CC} 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/testing && $(MAKE) CC=${CC} BUILDMODE=${BUILDMODE} PROJECT_PATH=${CURDIR}
|
||||
|
||||
clean:
|
||||
cd src/rendering && 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/editing && qmake "BUILDMODE=${BUILDMODE}" "PROJECT_PATH=${CURDIR}" && make clean
|
||||
cd src/testing && 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/controlling && $(MAKE) clean BUILDMODE=${BUILDMODE} PROJECT_PATH=${CURDIR}
|
||||
cd src/editing && qmake "BUILDMODE=${BUILDMODE}" "PROJECT_PATH=${CURDIR}" && $(MAKE) clean
|
||||
cd src/testing && $(MAKE) clean BUILDMODE=${BUILDMODE} PROJECT_PATH=${CURDIR}
|
||||
rm -f ${BUILDPATH}/paysages-cli
|
||||
rm -f ${BUILDPATH}/paysages-qt
|
||||
rm -f ${BUILDPATH}/paysages-tests
|
||||
|
|
|
@ -173,14 +173,13 @@ int main(int argc, char** argv)
|
|||
scenerySetAtmosphere(atmo);
|
||||
AtmosphereDefinitionClass.destroy(atmo);
|
||||
|
||||
CameraDefinition camera;
|
||||
CameraDefinition* camera;
|
||||
Vector3 step = {conf_camera_step_x, conf_camera_step_y, conf_camera_step_z};
|
||||
camera = cameraCreateDefinition();
|
||||
sceneryGetCamera(&camera);
|
||||
camera.location.x += conf_camera_step_x;
|
||||
camera.location.y += conf_camera_step_y;
|
||||
camera.location.z += conf_camera_step_z;
|
||||
scenerySetCamera(&camera);
|
||||
cameraDeleteDefinition(&camera);
|
||||
sceneryGetCamera(camera);
|
||||
cameraSetLocation(camera, v3Add(cameraGetLocation(camera), step));
|
||||
scenerySetCamera(camera);
|
||||
cameraDeleteDefinition(camera);
|
||||
|
||||
renderer = sceneryCreateStandardRenderer();
|
||||
rendererSetPreviewCallbacks(renderer, NULL, NULL, _previewUpdate);
|
||||
|
|
|
@ -12,15 +12,16 @@
|
|||
#include "rendering/tools/curve.h"
|
||||
#include "rendering/tools/color.h"
|
||||
#include "rendering/tools/pack.h"
|
||||
#include "rendering/tools/lighting.h"
|
||||
#include "rendering/noise.h"
|
||||
#include "rendering/layers.h"
|
||||
|
||||
class BaseForm:public QWidget
|
||||
class BaseForm : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
BaseForm(QWidget* parent, bool auto_apply=false, bool with_layers=false);
|
||||
BaseForm(QWidget* parent, bool auto_apply = false, bool with_layers = false);
|
||||
void hideButtons();
|
||||
virtual void savePack(PackStream* stream);
|
||||
virtual void loadPack(PackStream* stream);
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include <QHash>
|
||||
#include "previewosd.h"
|
||||
#include "rendering/tools/pack.h"
|
||||
#include "rendering/tools/color.h"
|
||||
|
||||
class _ContextChoice
|
||||
{
|
||||
|
@ -27,7 +28,8 @@ public:
|
|||
bool value;
|
||||
};
|
||||
|
||||
class BasePreview : public QWidget {
|
||||
class BasePreview : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
@ -136,12 +138,14 @@ private slots:
|
|||
/*** Private section ***/
|
||||
class PreviewChunk;
|
||||
|
||||
class PreviewDrawingThread : public QThread {
|
||||
class PreviewDrawingThread : public QThread
|
||||
{
|
||||
public:
|
||||
PreviewDrawingThread();
|
||||
void askStop();
|
||||
|
||||
static inline void usleep(int us) {
|
||||
static inline void usleep(int us)
|
||||
{
|
||||
QThread::usleep(us);
|
||||
}
|
||||
|
||||
|
@ -152,7 +156,8 @@ private:
|
|||
bool _running;
|
||||
};
|
||||
|
||||
class PreviewDrawingManager {
|
||||
class PreviewDrawingManager
|
||||
{
|
||||
public:
|
||||
PreviewDrawingManager();
|
||||
void startThreads();
|
||||
|
|
|
@ -16,7 +16,7 @@ ExplorerChunkSky::ExplorerChunkSky(Renderer* renderer, double size, SkyboxOrient
|
|||
|
||||
void ExplorerChunkSky::onCameraEvent(CameraDefinition* camera)
|
||||
{
|
||||
_center = camera->location;
|
||||
_center = cameraGetLocation(camera);
|
||||
}
|
||||
|
||||
void ExplorerChunkSky::onRenderEvent(QGLWidget*)
|
||||
|
@ -25,68 +25,68 @@ void ExplorerChunkSky::onRenderEvent(QGLWidget*)
|
|||
Vector3 camera = _center;
|
||||
|
||||
glBegin(GL_QUADS);
|
||||
switch(_orientation)
|
||||
switch (_orientation)
|
||||
{
|
||||
case SKYBOX_NORTH:
|
||||
glTexCoord2d(0.0, 0.0);
|
||||
glVertex3d(camera.x - size, camera.y + size, camera.z - size);
|
||||
glTexCoord2d(0.0, 1.0);
|
||||
glVertex3d(camera.x - size, camera.y - size, camera.z - size);
|
||||
glTexCoord2d(1.0, 1.0);
|
||||
glVertex3d(camera.x + size, camera.y - size, camera.z - size);
|
||||
glTexCoord2d(1.0, 0.0);
|
||||
glVertex3d(camera.x + size, camera.y + size, camera.z - size);
|
||||
break;
|
||||
case SKYBOX_SOUTH:
|
||||
glTexCoord2d(0.0, 0.0);
|
||||
glVertex3d(camera.x + size, camera.y + size, camera.z + size);
|
||||
glTexCoord2d(0.0, 1.0);
|
||||
glVertex3d(camera.x + size, camera.y - size, camera.z + size);
|
||||
glTexCoord2d(1.0, 1.0);
|
||||
glVertex3d(camera.x - size, camera.y - size, camera.z + size);
|
||||
glTexCoord2d(1.0, 0.0);
|
||||
glVertex3d(camera.x - size, camera.y + size, camera.z + size);
|
||||
break;
|
||||
case SKYBOX_EAST:
|
||||
glTexCoord2d(0.0, 0.0);
|
||||
glVertex3d(camera.x + size, camera.y + size, camera.z - size);
|
||||
glTexCoord2d(0.0, 1.0);
|
||||
glVertex3d(camera.x + size, camera.y - size, camera.z - size);
|
||||
glTexCoord2d(1.0, 1.0);
|
||||
glVertex3d(camera.x + size, camera.y - size, camera.z + size);
|
||||
glTexCoord2d(1.0, 0.0);
|
||||
glVertex3d(camera.x + size, camera.y + size, camera.z + size);
|
||||
break;
|
||||
case SKYBOX_WEST:
|
||||
glTexCoord2d(0.0, 0.0);
|
||||
glVertex3d(camera.x - size, camera.y + size, camera.z + size);
|
||||
glTexCoord2d(0.0, 1.0);
|
||||
glVertex3d(camera.x - size, camera.y - size, camera.z + size);
|
||||
glTexCoord2d(1.0, 1.0);
|
||||
glVertex3d(camera.x - size, camera.y - size, camera.z - size);
|
||||
glTexCoord2d(1.0, 0.0);
|
||||
glVertex3d(camera.x - size, camera.y + size, camera.z - size);
|
||||
break;
|
||||
case SKYBOX_TOP:
|
||||
glTexCoord2d(0.0, 0.0);
|
||||
glVertex3d(camera.x - size, camera.y + size, camera.z + size);
|
||||
glTexCoord2d(0.0, 1.0);
|
||||
glVertex3d(camera.x - size, camera.y + size, camera.z - size);
|
||||
glTexCoord2d(1.0, 1.0);
|
||||
glVertex3d(camera.x + size, camera.y + size, camera.z - size);
|
||||
glTexCoord2d(1.0, 0.0);
|
||||
glVertex3d(camera.x + size, camera.y + size, camera.z + size);
|
||||
break;
|
||||
case SKYBOX_BOTTOM:
|
||||
/*glTexCoord2d(0.0, 0.0);
|
||||
glVertex3d(camera.x - size, camera.y - size, camera.z - size);
|
||||
glTexCoord2d(0.0, 1.0);
|
||||
glVertex3d(camera.x - size, camera.y - size, camera.z + size);
|
||||
glTexCoord2d(1.0, 1.0);
|
||||
glVertex3d(camera.x + size, camera.y - size, camera.z + size);
|
||||
glTexCoord2d(1.0, 0.0);
|
||||
glVertex3d(camera.x + size, camera.y - size, camera.z - size);*/
|
||||
break;
|
||||
case SKYBOX_NORTH:
|
||||
glTexCoord2d(0.0, 0.0);
|
||||
glVertex3d(camera.x - size, camera.y + size, camera.z - size);
|
||||
glTexCoord2d(0.0, 1.0);
|
||||
glVertex3d(camera.x - size, camera.y - size, camera.z - size);
|
||||
glTexCoord2d(1.0, 1.0);
|
||||
glVertex3d(camera.x + size, camera.y - size, camera.z - size);
|
||||
glTexCoord2d(1.0, 0.0);
|
||||
glVertex3d(camera.x + size, camera.y + size, camera.z - size);
|
||||
break;
|
||||
case SKYBOX_SOUTH:
|
||||
glTexCoord2d(0.0, 0.0);
|
||||
glVertex3d(camera.x + size, camera.y + size, camera.z + size);
|
||||
glTexCoord2d(0.0, 1.0);
|
||||
glVertex3d(camera.x + size, camera.y - size, camera.z + size);
|
||||
glTexCoord2d(1.0, 1.0);
|
||||
glVertex3d(camera.x - size, camera.y - size, camera.z + size);
|
||||
glTexCoord2d(1.0, 0.0);
|
||||
glVertex3d(camera.x - size, camera.y + size, camera.z + size);
|
||||
break;
|
||||
case SKYBOX_EAST:
|
||||
glTexCoord2d(0.0, 0.0);
|
||||
glVertex3d(camera.x + size, camera.y + size, camera.z - size);
|
||||
glTexCoord2d(0.0, 1.0);
|
||||
glVertex3d(camera.x + size, camera.y - size, camera.z - size);
|
||||
glTexCoord2d(1.0, 1.0);
|
||||
glVertex3d(camera.x + size, camera.y - size, camera.z + size);
|
||||
glTexCoord2d(1.0, 0.0);
|
||||
glVertex3d(camera.x + size, camera.y + size, camera.z + size);
|
||||
break;
|
||||
case SKYBOX_WEST:
|
||||
glTexCoord2d(0.0, 0.0);
|
||||
glVertex3d(camera.x - size, camera.y + size, camera.z + size);
|
||||
glTexCoord2d(0.0, 1.0);
|
||||
glVertex3d(camera.x - size, camera.y - size, camera.z + size);
|
||||
glTexCoord2d(1.0, 1.0);
|
||||
glVertex3d(camera.x - size, camera.y - size, camera.z - size);
|
||||
glTexCoord2d(1.0, 0.0);
|
||||
glVertex3d(camera.x - size, camera.y + size, camera.z - size);
|
||||
break;
|
||||
case SKYBOX_TOP:
|
||||
glTexCoord2d(0.0, 0.0);
|
||||
glVertex3d(camera.x - size, camera.y + size, camera.z + size);
|
||||
glTexCoord2d(0.0, 1.0);
|
||||
glVertex3d(camera.x - size, camera.y + size, camera.z - size);
|
||||
glTexCoord2d(1.0, 1.0);
|
||||
glVertex3d(camera.x + size, camera.y + size, camera.z - size);
|
||||
glTexCoord2d(1.0, 0.0);
|
||||
glVertex3d(camera.x + size, camera.y + size, camera.z + size);
|
||||
break;
|
||||
case SKYBOX_BOTTOM:
|
||||
/*glTexCoord2d(0.0, 0.0);
|
||||
glVertex3d(camera.x - size, camera.y - size, camera.z - size);
|
||||
glTexCoord2d(0.0, 1.0);
|
||||
glVertex3d(camera.x - size, camera.y - size, camera.z + size);
|
||||
glTexCoord2d(1.0, 1.0);
|
||||
glVertex3d(camera.x + size, camera.y - size, camera.z + size);
|
||||
glTexCoord2d(1.0, 0.0);
|
||||
glVertex3d(camera.x + size, camera.y - size, camera.z - size);*/
|
||||
break;
|
||||
}
|
||||
glEnd();
|
||||
}
|
||||
|
@ -103,38 +103,38 @@ Color ExplorerChunkSky::getTextureColor(double x, double y)
|
|||
x -= 0.5;
|
||||
y -= 0.5;
|
||||
|
||||
switch(_orientation)
|
||||
switch (_orientation)
|
||||
{
|
||||
case SKYBOX_NORTH:
|
||||
location.x = x;
|
||||
location.y = -y;
|
||||
location.z = -0.5;
|
||||
break;
|
||||
case SKYBOX_SOUTH:
|
||||
location.x = -x;
|
||||
location.y = -y;
|
||||
location.z = 0.5;
|
||||
break;
|
||||
case SKYBOX_EAST:
|
||||
location.x = 0.5;
|
||||
location.y = -y;
|
||||
location.z = x;
|
||||
break;
|
||||
case SKYBOX_WEST:
|
||||
location.x = -0.5;
|
||||
location.y = -y;
|
||||
location.z = -x;
|
||||
break;
|
||||
case SKYBOX_TOP:
|
||||
location.x = x;
|
||||
location.y = 0.5;
|
||||
location.z = -y;
|
||||
break;
|
||||
case SKYBOX_BOTTOM:
|
||||
location.x = x;
|
||||
location.y = -0.5;
|
||||
location.z = y;
|
||||
break;
|
||||
case SKYBOX_NORTH:
|
||||
location.x = x;
|
||||
location.y = -y;
|
||||
location.z = -0.5;
|
||||
break;
|
||||
case SKYBOX_SOUTH:
|
||||
location.x = -x;
|
||||
location.y = -y;
|
||||
location.z = 0.5;
|
||||
break;
|
||||
case SKYBOX_EAST:
|
||||
location.x = 0.5;
|
||||
location.y = -y;
|
||||
location.z = x;
|
||||
break;
|
||||
case SKYBOX_WEST:
|
||||
location.x = -0.5;
|
||||
location.y = -y;
|
||||
location.z = -x;
|
||||
break;
|
||||
case SKYBOX_TOP:
|
||||
location.x = x;
|
||||
location.y = 0.5;
|
||||
location.z = -y;
|
||||
break;
|
||||
case SKYBOX_BOTTOM:
|
||||
location.x = x;
|
||||
location.y = -0.5;
|
||||
location.z = y;
|
||||
break;
|
||||
}
|
||||
location = v3Normalize(location);
|
||||
if (location.y < 0.0)
|
||||
|
|
|
@ -9,7 +9,7 @@ ExplorerChunkTerrain::ExplorerChunkTerrain(Renderer* renderer, double x, double
|
|||
_startx = x;
|
||||
_startz = z;
|
||||
_size = size;
|
||||
_overall_step = size * (double)nbchunks;
|
||||
_overall_step = size * (double) nbchunks;
|
||||
|
||||
_distance_to_camera = 0.0;
|
||||
|
||||
|
@ -19,7 +19,7 @@ ExplorerChunkTerrain::ExplorerChunkTerrain(Renderer* renderer, double x, double
|
|||
_tessellation_max_size = 32;
|
||||
_tessellation = new double[(_tessellation_max_size + 1) * (_tessellation_max_size + 1)];
|
||||
_tessellation_current_size = 0;
|
||||
_tessellation_step = _size / (double)_tessellation_max_size;
|
||||
_tessellation_step = _size / (double) _tessellation_max_size;
|
||||
|
||||
setMaxTextureSize(128);
|
||||
|
||||
|
@ -55,7 +55,7 @@ bool ExplorerChunkTerrain::onMaintainEvent()
|
|||
{
|
||||
if (_tessellation_current_size == 0 || i % old_tessellation_inc != 0 || j % old_tessellation_inc != 0)
|
||||
{
|
||||
double height = renderer->terrain->getHeight(renderer, _startx + _tessellation_step * (double)i, _startz + _tessellation_step * (double)j, 1);
|
||||
double height = renderer->terrain->getHeight(renderer, _startx + _tessellation_step * (double) i, _startz + _tessellation_step * (double) j, 1);
|
||||
if (height >= _water_height)
|
||||
{
|
||||
_overwater = true;
|
||||
|
@ -84,30 +84,32 @@ bool ExplorerChunkTerrain::onMaintainEvent()
|
|||
|
||||
void ExplorerChunkTerrain::onCameraEvent(CameraDefinition* camera)
|
||||
{
|
||||
Vector3 camera_location = cameraGetLocation(camera);
|
||||
|
||||
// Handle position
|
||||
_lock_data.lock();
|
||||
if (camera->location.x > _startx + _overall_step * 0.5)
|
||||
if (camera_location.x > _startx + _overall_step * 0.5)
|
||||
{
|
||||
_startx += _overall_step;
|
||||
askReset();
|
||||
}
|
||||
if (camera->location.z > _startz + _overall_step * 0.5)
|
||||
if (camera_location.z > _startz + _overall_step * 0.5)
|
||||
{
|
||||
_startz += _overall_step;
|
||||
askReset();
|
||||
}
|
||||
if (camera->location.x < _startx - _overall_step * 0.5)
|
||||
if (camera_location.x < _startx - _overall_step * 0.5)
|
||||
{
|
||||
_startx -= _overall_step;
|
||||
askReset();
|
||||
}
|
||||
if (camera->location.z < _startz - _overall_step * 0.5)
|
||||
if (camera_location.z < _startz - _overall_step * 0.5)
|
||||
{
|
||||
_startz -= _overall_step;
|
||||
askReset();
|
||||
}
|
||||
|
||||
_distance_to_camera = v3Norm(v3Sub(getCenter(), camera->location));
|
||||
_distance_to_camera = v3Norm(v3Sub(getCenter(), camera_location));
|
||||
|
||||
_lock_data.unlock();
|
||||
}
|
||||
|
@ -116,7 +118,7 @@ void ExplorerChunkTerrain::onRenderEvent(QGLWidget*)
|
|||
{
|
||||
_lock_data.lock();
|
||||
int tessellation_size = _tessellation_current_size;
|
||||
double tsize = 1.0 / (double)_tessellation_max_size;
|
||||
double tsize = 1.0 / (double) _tessellation_max_size;
|
||||
_lock_data.unlock();
|
||||
|
||||
if (tessellation_size <= 1 or not _overwater)
|
||||
|
@ -124,16 +126,16 @@ void ExplorerChunkTerrain::onRenderEvent(QGLWidget*)
|
|||
return;
|
||||
}
|
||||
|
||||
int tessellation_inc = _tessellation_max_size / (double)tessellation_size;
|
||||
int tessellation_inc = _tessellation_max_size / (double) tessellation_size;
|
||||
for (int j = 0; j < _tessellation_max_size; j += tessellation_inc)
|
||||
{
|
||||
glBegin(GL_QUAD_STRIP);
|
||||
for (int i = 0; i <= _tessellation_max_size; i += tessellation_inc)
|
||||
{
|
||||
glTexCoord2d(tsize * (double)i, tsize * (double)j);
|
||||
glVertex3d(_startx + _tessellation_step * (double)i, _tessellation[j * (_tessellation_max_size + 1) + i], _startz + _tessellation_step * (double)j);
|
||||
glTexCoord2d(tsize * (double)i, tsize * (double)(j + tessellation_inc));
|
||||
glVertex3d(_startx + _tessellation_step * (double)i, _tessellation[(j + tessellation_inc) * (_tessellation_max_size + 1) + i], _startz + _tessellation_step * (double)(j + tessellation_inc));
|
||||
glTexCoord2d(tsize * (double) i, tsize * (double) j);
|
||||
glVertex3d(_startx + _tessellation_step * (double) i, _tessellation[j * (_tessellation_max_size + 1) + i], _startz + _tessellation_step * (double) j);
|
||||
glTexCoord2d(tsize * (double) i, tsize * (double) (j + tessellation_inc));
|
||||
glVertex3d(_startx + _tessellation_step * (double) i, _tessellation[(j + tessellation_inc) * (_tessellation_max_size + 1) + i], _startz + _tessellation_step * (double) (j + tessellation_inc));
|
||||
}
|
||||
glEnd();
|
||||
}
|
||||
|
@ -155,7 +157,7 @@ double ExplorerChunkTerrain::getDisplayedSizeHint(CameraDefinition* camera)
|
|||
{
|
||||
distance = _distance_to_camera;
|
||||
distance = distance < 0.1 ? 0.1 : distance;
|
||||
return (int)ceil(120.0 - distance / 1.5);
|
||||
return (int) ceil(120.0 - distance / 1.5);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -7,16 +7,17 @@
|
|||
#include "rendering/scenery.h"
|
||||
|
||||
/**************** Previews ****************/
|
||||
class PreviewRenderLandscape:public BasePreview
|
||||
class PreviewRenderLandscape : public BasePreview
|
||||
{
|
||||
public:
|
||||
PreviewRenderLandscape(QWidget* parent):BasePreview(parent)
|
||||
|
||||
PreviewRenderLandscape(QWidget* parent) : BasePreview(parent)
|
||||
{
|
||||
_renderer = sceneryCreateStandardRenderer();
|
||||
_renderer->getCameraLocation = _getCameraLocation;
|
||||
lightingManagerDisableSpecularity(_renderer->lighting);
|
||||
|
||||
_no_clouds = (CloudsDefinition*)CloudsDefinitionClass.create();
|
||||
_no_clouds = (CloudsDefinition*) CloudsDefinitionClass.create();
|
||||
_clouds_enabled = true;
|
||||
|
||||
addOsd(QString("geolocation"));
|
||||
|
@ -27,6 +28,7 @@ public:
|
|||
configScrolling(-1000.0, 1000.0, 0.0, -1000.0, 1000.0, 0.0);
|
||||
}
|
||||
protected:
|
||||
|
||||
Color getColor(double x, double y)
|
||||
{
|
||||
Vector3 location;
|
||||
|
@ -44,6 +46,7 @@ protected:
|
|||
return _renderer->terrain->getFinalColor(_renderer, location, scaling);
|
||||
}
|
||||
}
|
||||
|
||||
void updateData()
|
||||
{
|
||||
sceneryBindRenderer(_renderer);
|
||||
|
@ -54,6 +57,7 @@ protected:
|
|||
CloudsRendererClass.bind(_renderer, _no_clouds);
|
||||
}
|
||||
}
|
||||
|
||||
void toggleChangeEvent(QString key, bool value)
|
||||
{
|
||||
if (key == "clouds")
|
||||
|
@ -85,7 +89,7 @@ private:
|
|||
|
||||
/**************** Form ****************/
|
||||
FormRender::FormRender(QWidget *parent) :
|
||||
BaseForm(parent, true)
|
||||
BaseForm(parent, true)
|
||||
{
|
||||
QPushButton* button;
|
||||
|
||||
|
@ -102,7 +106,7 @@ FormRender::FormRender(QWidget *parent) :
|
|||
_preview_landscape = new PreviewRenderLandscape(this);
|
||||
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("Image width"), &_params.width, 100, 2000, 10, 100);
|
||||
addInputInt(tr("Image height"), &_params.height, 100, 1200, 10, 100);
|
||||
|
@ -118,6 +122,7 @@ FormRender::FormRender(QWidget *parent) :
|
|||
|
||||
FormRender::~FormRender()
|
||||
{
|
||||
cameraDeleteDefinition(_camera);
|
||||
if (_renderer_inited)
|
||||
{
|
||||
rendererDelete(_renderer);
|
||||
|
@ -148,19 +153,19 @@ void FormRender::loadPack(PackStream* stream)
|
|||
|
||||
void FormRender::revertConfig()
|
||||
{
|
||||
sceneryGetCamera(&_camera);
|
||||
sceneryGetCamera(_camera);
|
||||
BaseForm::revertConfig();
|
||||
}
|
||||
|
||||
void FormRender::applyConfig()
|
||||
{
|
||||
scenerySetCamera(&_camera);
|
||||
scenerySetCamera(_camera);
|
||||
BaseForm::applyConfig();
|
||||
}
|
||||
|
||||
void FormRender::configChangeEvent()
|
||||
{
|
||||
cameraValidateDefinition(&_camera, 1);
|
||||
cameraValidateDefinition(_camera, 1);
|
||||
BaseForm::configChangeEvent();
|
||||
}
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ private slots:
|
|||
|
||||
private:
|
||||
RenderParams _params;
|
||||
CameraDefinition _camera;
|
||||
CameraDefinition* _camera;
|
||||
Renderer* _renderer;
|
||||
bool _renderer_inited;
|
||||
BasePreview* _preview_landscape;
|
||||
|
|
|
@ -4,12 +4,13 @@
|
|||
#include "tools.h"
|
||||
|
||||
/**************** Previews ****************/
|
||||
class PreviewTexturesCoverage:public BasePreview
|
||||
class PreviewTexturesCoverage : public BasePreview
|
||||
{
|
||||
public:
|
||||
PreviewTexturesCoverage(QWidget* parent, TexturesLayerDefinition* layer):BasePreview(parent)
|
||||
|
||||
PreviewTexturesCoverage(QWidget* parent, TexturesLayerDefinition* layer) : BasePreview(parent)
|
||||
{
|
||||
_terrain = (TerrainDefinition*)TerrainDefinitionClass.create();
|
||||
_terrain = (TerrainDefinition*) TerrainDefinitionClass.create();
|
||||
|
||||
_renderer = rendererCreate();
|
||||
_renderer->render_quality = 3;
|
||||
|
@ -22,11 +23,13 @@ public:
|
|||
configScaling(20.0, 500.0, 20.0, 50.0);
|
||||
configScrolling(-1000.0, 1000.0, 0.0, -1000.0, 1000.0, 0.0);
|
||||
}
|
||||
|
||||
~PreviewTexturesCoverage()
|
||||
{
|
||||
//TexturesDefinitionClass.destroy(_preview_layer);
|
||||
}
|
||||
protected:
|
||||
|
||||
Color getColor(double x, double y)
|
||||
{
|
||||
Vector3 location;
|
||||
|
@ -37,6 +40,7 @@ protected:
|
|||
//result.r = result.g = result.b = texturesGetLayerCoverage(_preview_layer, _renderer, location, this->scaling);
|
||||
return result;
|
||||
}
|
||||
|
||||
void updateData()
|
||||
{
|
||||
sceneryGetTerrain(_terrain);
|
||||
|
@ -52,28 +56,31 @@ private:
|
|||
TerrainDefinition* _terrain;
|
||||
};
|
||||
|
||||
class PreviewTexturesColor:public BasePreview
|
||||
class PreviewTexturesColor : public BasePreview
|
||||
{
|
||||
public:
|
||||
PreviewTexturesColor(QWidget* parent, TexturesLayerDefinition* layer):BasePreview(parent)
|
||||
|
||||
PreviewTexturesColor(QWidget* parent, TexturesLayerDefinition* layer) : BasePreview(parent)
|
||||
{
|
||||
_original_layer = layer;
|
||||
//_preview_layer = (TexturesLayerDefinition*)TexturesDefinitionClass.create();
|
||||
|
||||
_renderer = rendererCreate();
|
||||
_renderer->render_quality = 3;
|
||||
_renderer->render_camera.location.x = 0.0;
|
||||
_renderer->render_camera.location.y = 20.0;
|
||||
_renderer->render_camera.location.z = 0.0;
|
||||
|
||||
Vector3 camera_location = {0.0, 20.0, 0.0};
|
||||
cameraSetLocation(_renderer->render_camera, camera_location);
|
||||
|
||||
configScaling(0.01, 1.0, 0.01, 0.1);
|
||||
configScrolling(-1000.0, 1000.0, 0.0, -1000.0, 1000.0, 0.0);
|
||||
}
|
||||
|
||||
~PreviewTexturesColor()
|
||||
{
|
||||
//TexturesDefinitionClass.destroy(_preview_layer);
|
||||
}
|
||||
protected:
|
||||
|
||||
Color getColor(double x, double y)
|
||||
{
|
||||
Vector3 location;
|
||||
|
@ -83,6 +90,7 @@ protected:
|
|||
//return texturesGetLayerColor(_preview_layer, _renderer, location, this->scaling);
|
||||
return COLOR_BLACK;
|
||||
}
|
||||
|
||||
void updateData()
|
||||
{
|
||||
//TexturesDefinitionClass.copy(_original_layer, _preview_layer);
|
||||
|
@ -94,16 +102,16 @@ private:
|
|||
};
|
||||
|
||||
/**************** Form ****************/
|
||||
FormTextures::FormTextures(QWidget *parent):
|
||||
BaseFormLayer(parent)
|
||||
FormTextures::FormTextures(QWidget *parent) :
|
||||
BaseFormLayer(parent)
|
||||
{
|
||||
addAutoPreset(tr("Rock"));
|
||||
addAutoPreset(tr("Grass"));
|
||||
addAutoPreset(tr("Sand"));
|
||||
addAutoPreset(tr("Snow"));
|
||||
|
||||
_definition = (TexturesDefinition*)TexturesDefinitionClass.create();
|
||||
_layer = (TexturesLayerDefinition*)texturesGetLayerType().callback_create();
|
||||
_definition = (TexturesDefinition*) TexturesDefinitionClass.create();
|
||||
_layer = (TexturesLayerDefinition*) texturesGetLayerType().callback_create();
|
||||
|
||||
_previewCoverage = new PreviewTexturesCoverage(this, _layer);
|
||||
_previewColor = new PreviewTexturesColor(this, _layer);
|
||||
|
@ -143,16 +151,16 @@ void FormTextures::applyConfig()
|
|||
|
||||
void FormTextures::layerReadCurrentFrom(void* layer_definition)
|
||||
{
|
||||
texturesGetLayerType().callback_copy((TexturesLayerDefinition*)layer_definition, _layer);
|
||||
texturesGetLayerType().callback_copy((TexturesLayerDefinition*) layer_definition, _layer);
|
||||
}
|
||||
|
||||
void FormTextures::layerWriteCurrentTo(void* layer_definition)
|
||||
{
|
||||
texturesGetLayerType().callback_copy(_layer, (TexturesLayerDefinition*)layer_definition);
|
||||
texturesGetLayerType().callback_copy(_layer, (TexturesLayerDefinition*) layer_definition);
|
||||
}
|
||||
|
||||
void FormTextures::autoPresetSelected(int preset)
|
||||
{
|
||||
texturesLayerAutoPreset(_layer, (TexturesLayerPreset)preset);
|
||||
texturesLayerAutoPreset(_layer, (TexturesLayerPreset) preset);
|
||||
BaseForm::autoPresetSelected(preset);
|
||||
}
|
||||
|
|
|
@ -15,10 +15,11 @@
|
|||
static WaterDefinition* _definition;
|
||||
|
||||
/**************** Previews ****************/
|
||||
class PreviewWaterCoverage:public BasePreview
|
||||
class PreviewWaterCoverage : public BasePreview
|
||||
{
|
||||
public:
|
||||
PreviewWaterCoverage(QWidget* parent):BasePreview(parent)
|
||||
|
||||
PreviewWaterCoverage(QWidget* parent) : BasePreview(parent)
|
||||
{
|
||||
_renderer = waterCreatePreviewCoverageRenderer();
|
||||
_highlight_enabled = true;
|
||||
|
@ -30,20 +31,23 @@ public:
|
|||
configScrolling(-1000.0, 1000.0, 0.0, -1000.0, 1000.0, 0.0);
|
||||
}
|
||||
protected:
|
||||
|
||||
Color getColor(double x, double y)
|
||||
{
|
||||
return waterGetPreviewCoverage(_renderer, x, y, scaling, _highlight_enabled ? 1 : 0);
|
||||
}
|
||||
|
||||
void updateData()
|
||||
{
|
||||
WaterRendererClass.bind(_renderer, _definition);
|
||||
|
||||
// TODO Do this only on full refresh
|
||||
TerrainDefinition* terrain = (TerrainDefinition*)TerrainDefinitionClass.create();
|
||||
TerrainDefinition* terrain = (TerrainDefinition*) TerrainDefinitionClass.create();
|
||||
sceneryGetTerrain(terrain);
|
||||
TerrainRendererClass.bind(_renderer, terrain);
|
||||
TerrainDefinitionClass.destroy(terrain);
|
||||
}
|
||||
|
||||
void toggleChangeEvent(QString key, bool value)
|
||||
{
|
||||
if (key == "highlight")
|
||||
|
@ -57,10 +61,11 @@ private:
|
|||
bool _highlight_enabled;
|
||||
};
|
||||
|
||||
class PreviewWaterColor:public BasePreview
|
||||
class PreviewWaterColor : public BasePreview
|
||||
{
|
||||
public:
|
||||
PreviewWaterColor(QWidget* parent):BasePreview(parent)
|
||||
|
||||
PreviewWaterColor(QWidget* parent) : BasePreview(parent)
|
||||
{
|
||||
_background = 0;
|
||||
_lighting_enabled = false;
|
||||
|
@ -80,6 +85,7 @@ public:
|
|||
int _background;
|
||||
bool _lighting_enabled;
|
||||
protected:
|
||||
|
||||
Color getColor(double x, double y)
|
||||
{
|
||||
Vector3 eye, look;
|
||||
|
@ -108,15 +114,19 @@ protected:
|
|||
|
||||
return _renderer->water->getResult(_renderer, target_x, target_z).final;
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
WaterRendererClass.bind(_renderer, _definition);
|
||||
_renderer->water->definition->height = 0.0;
|
||||
}
|
||||
|
||||
void choiceChangeEvent(const QString& key, int position)
|
||||
{
|
||||
if (key == "bg")
|
||||
|
@ -125,6 +135,7 @@ protected:
|
|||
redraw();
|
||||
}
|
||||
}
|
||||
|
||||
void toggleChangeEvent(QString key, bool value)
|
||||
{
|
||||
if (key == "light")
|
||||
|
@ -140,7 +151,7 @@ private:
|
|||
static RayCastingResult _rayWalking(Renderer* renderer, Vector3 location, Vector3 direction, int, int, int, int)
|
||||
{
|
||||
RayCastingResult result;
|
||||
PreviewWaterColor* preview = (PreviewWaterColor*)renderer->customData[0];
|
||||
PreviewWaterColor* preview = (PreviewWaterColor*) renderer->customData[0];
|
||||
double x, y;
|
||||
|
||||
result.hit = 1;
|
||||
|
@ -157,7 +168,7 @@ private:
|
|||
switch (preview->_background)
|
||||
{
|
||||
case 1:
|
||||
result.hit_color = (((int)ceil(x * 0.2) % 2 == 0) ^ ((int)ceil(y * 0.2 - 0.5) % 2 == 0)) ? COLOR_WHITE : COLOR_BLACK;
|
||||
result.hit_color = (((int) ceil(x * 0.2) % 2 == 0) ^ ((int) ceil(y * 0.2 - 0.5) % 2 == 0)) ? COLOR_WHITE : COLOR_BLACK;
|
||||
break;
|
||||
case 2:
|
||||
result.hit_color = (y * 0.1 > x * 0.03 + sin(x - M_PI_2)) ? COLOR_WHITE : COLOR_BLACK;
|
||||
|
@ -187,10 +198,11 @@ private:
|
|||
|
||||
return result;
|
||||
}
|
||||
|
||||
static void _getLightingStatus(Renderer* renderer, LightStatus* status, Vector3, int)
|
||||
{
|
||||
LightDefinition light;
|
||||
PreviewWaterColor* preview = (PreviewWaterColor*)renderer->customData[0];
|
||||
PreviewWaterColor* preview = (PreviewWaterColor*) renderer->customData[0];
|
||||
light.color = COLOR_WHITE;
|
||||
light.direction.x = 0.0;
|
||||
light.direction.y = -0.4794;
|
||||
|
@ -209,13 +221,13 @@ private:
|
|||
};
|
||||
|
||||
/**************** Form ****************/
|
||||
FormWater::FormWater(QWidget *parent):
|
||||
BaseForm(parent)
|
||||
FormWater::FormWater(QWidget *parent) :
|
||||
BaseForm(parent)
|
||||
{
|
||||
addAutoPreset(tr("Lake surface"));
|
||||
addAutoPreset(tr("Standard sea"));
|
||||
|
||||
_definition = (WaterDefinition*)WaterDefinitionClass.create();
|
||||
_definition = (WaterDefinition*) WaterDefinitionClass.create();
|
||||
|
||||
previewCoverage = new PreviewWaterCoverage(this);
|
||||
previewColor = new PreviewWaterColor(this);
|
||||
|
@ -259,7 +271,7 @@ void FormWater::configChangeEvent()
|
|||
|
||||
void FormWater::autoPresetSelected(int preset)
|
||||
{
|
||||
waterAutoPreset(_definition, (WaterPreset)preset);
|
||||
waterAutoPreset(_definition, (WaterPreset) preset);
|
||||
BaseForm::autoPresetSelected(preset);
|
||||
}
|
||||
|
||||
|
|
|
@ -164,14 +164,14 @@ void MainWindow::refreshAll()
|
|||
}
|
||||
|
||||
// Refresh preview OSD
|
||||
CameraDefinition camera = cameraCreateDefinition();
|
||||
CameraDefinition* camera = cameraCreateDefinition();
|
||||
PreviewOsd* osd = PreviewOsd::getInstance(QString("geolocation"));
|
||||
osd->clearItems();
|
||||
sceneryGetCamera(&camera);
|
||||
sceneryGetCamera(camera);
|
||||
PreviewOsdItem* item = osd->newItem(50, 50);
|
||||
item->drawCamera(&camera);
|
||||
item->drawCamera(camera);
|
||||
item->setToolTip(QString(tr("Camera")));
|
||||
cameraDeleteDefinition(&camera);
|
||||
cameraDeleteDefinition(camera);
|
||||
}
|
||||
|
||||
void MainWindow::fileNew()
|
||||
|
@ -248,31 +248,34 @@ void MainWindow::quickPreview()
|
|||
|
||||
void MainWindow::explore3D()
|
||||
{
|
||||
CameraDefinition camera;
|
||||
CameraDefinition* camera;
|
||||
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();
|
||||
|
||||
delete dialog;
|
||||
|
||||
if (result == QDialog::Accepted)
|
||||
{
|
||||
scenerySetCamera(&camera);
|
||||
scenerySetCamera(camera);
|
||||
refreshAll();
|
||||
}
|
||||
|
||||
cameraDeleteDefinition(camera);
|
||||
}
|
||||
|
||||
void MainWindow::guiSaveCallback(PackStream* stream, void* data)
|
||||
{
|
||||
((MainWindow*)data)->guiSave(stream);
|
||||
((MainWindow*) data)->guiSave(stream);
|
||||
}
|
||||
|
||||
void MainWindow::guiLoadCallback(PackStream* stream, void* data)
|
||||
{
|
||||
((MainWindow*)data)->guiLoad(stream);
|
||||
((MainWindow*) data)->guiLoad(stream);
|
||||
}
|
||||
|
||||
void MainWindow::guiSave(PackStream* stream)
|
||||
|
|
|
@ -22,9 +22,8 @@ SmallMaterialPreview::SmallMaterialPreview(QWidget* parent, SurfaceMaterial* mat
|
|||
_material = material;
|
||||
|
||||
_renderer = rendererCreate();
|
||||
_renderer->render_camera.location.x = 0.0;
|
||||
_renderer->render_camera.location.x = 0.0;
|
||||
_renderer->render_camera.location.z = 10.0;
|
||||
Vector3 camera_location = {0.0, 0.0, 10.0};
|
||||
cameraSetLocation(_renderer->render_camera, camera_location);
|
||||
}
|
||||
|
||||
SmallMaterialPreview::~SmallMaterialPreview()
|
||||
|
@ -74,20 +73,20 @@ void SmallMaterialPreview::paintEvent(QPaintEvent*)
|
|||
|
||||
if (width > height)
|
||||
{
|
||||
factor = 2.0 / (double)height;
|
||||
factor = 2.0 / (double) height;
|
||||
}
|
||||
else
|
||||
{
|
||||
factor = 2.0 / (double)width;
|
||||
factor = 2.0 / (double) width;
|
||||
}
|
||||
dx = factor * (double)width / 2.0;
|
||||
dy = factor * (double)height / 2.0;
|
||||
dx = factor * (double) width / 2.0;
|
||||
dy = factor * (double) height / 2.0;
|
||||
|
||||
for (int x = 0; x < width; x++)
|
||||
{
|
||||
for (int y = 0; y < height; y++)
|
||||
{
|
||||
painter.setPen(colorToQColor(getColor((double)x * factor - dx, (double)y * factor - dy)));
|
||||
painter.setPen(colorToQColor(getColor((double) x * factor - dx, (double) y * factor - dy)));
|
||||
painter.drawPoint(x, y);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,17 +22,19 @@ void PreviewOsdItem::setLocation(double x, double y)
|
|||
|
||||
void PreviewOsdItem::drawCamera(CameraDefinition* camera)
|
||||
{
|
||||
Vector3 camera_location = cameraGetLocation(camera);
|
||||
VectorSpherical camera_direction = cameraGetDirectionSpherical(camera);
|
||||
int w2 = width() / 2;
|
||||
int h2 = height() / 2;
|
||||
|
||||
_xlocation = camera->location.x;
|
||||
_ylocation = camera->location.z;
|
||||
|
||||
|
||||
_xlocation = camera_location.x;
|
||||
_ylocation = camera_location.z;
|
||||
|
||||
QPainter painter(this);
|
||||
painter.setPen(QPen(Qt::red, 2));
|
||||
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->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_direction.phi + M_PI_4), h2 - h2 * sin(camera_direction.phi + M_PI_4));
|
||||
}
|
||||
|
||||
void PreviewOsdItem::setToolTip(QString text)
|
||||
|
@ -87,7 +89,7 @@ void PreviewOsd::clearItems()
|
|||
}
|
||||
_items.clear();
|
||||
}
|
||||
|
||||
|
||||
PreviewOsdItem* PreviewOsd::newItem(int width, int height)
|
||||
{
|
||||
PreviewOsdItem* item = new PreviewOsdItem(width, height);
|
||||
|
@ -106,12 +108,12 @@ PreviewOsdItem* PreviewOsd::newItem(QImage image)
|
|||
void PreviewOsd::apply(QImage* mask, double xoffset, double yoffset, double scaling)
|
||||
{
|
||||
QPainter painter(mask);
|
||||
|
||||
|
||||
for (int i = 0; i < _items.size(); i++)
|
||||
{
|
||||
PreviewOsdItem* item = _items[i];
|
||||
int x = (int)(mask->width() / 2 - (xoffset - item->xlocation()) / scaling - item->width() / 2);
|
||||
int y = (int)(mask->height() / 2 - (yoffset - item->ylocation()) / scaling - item->height() / 2);
|
||||
int x = (int) (mask->width() / 2 - (xoffset - item->xlocation()) / scaling - item->width() / 2);
|
||||
int y = (int) (mask->height() / 2 - (yoffset - item->ylocation()) / scaling - item->height() / 2);
|
||||
painter.drawImage(x, y, *item);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,9 +13,10 @@
|
|||
#include "explorerchunksky.h"
|
||||
#include "tools.h"
|
||||
|
||||
class ChunkMaintenanceThread:public QThread
|
||||
class ChunkMaintenanceThread : public QThread
|
||||
{
|
||||
public:
|
||||
|
||||
ChunkMaintenanceThread(WidgetExplorer* wanderer)
|
||||
{
|
||||
_wanderer = wanderer;
|
||||
|
@ -33,6 +34,7 @@ public:
|
|||
}
|
||||
|
||||
protected:
|
||||
|
||||
void run()
|
||||
{
|
||||
while (_running)
|
||||
|
@ -51,7 +53,7 @@ static QVector<ChunkMaintenanceThread*> _threads;
|
|||
|
||||
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)
|
||||
|
@ -64,14 +66,15 @@ static AtmosphereResult _applyAerialPerspective(Renderer*, Vector3, Color base)
|
|||
return result;
|
||||
}
|
||||
|
||||
WidgetExplorer::WidgetExplorer(QWidget *parent, CameraDefinition* camera):
|
||||
QGLWidget(parent)
|
||||
WidgetExplorer::WidgetExplorer(QWidget *parent, CameraDefinition* camera) :
|
||||
QGLWidget(parent)
|
||||
{
|
||||
setMinimumSize(400, 300);
|
||||
setFocusPolicy(Qt::StrongFocus);
|
||||
|
||||
_current_camera = cameraCreateDefinition();
|
||||
_base_camera = camera;
|
||||
cameraCopyDefinition(camera, &_current_camera);
|
||||
cameraCopyDefinition(camera, _current_camera);
|
||||
|
||||
_renderer = sceneryCreateStandardRenderer();
|
||||
_renderer->render_quality = 3;
|
||||
|
@ -100,6 +103,7 @@ WidgetExplorer::~WidgetExplorer()
|
|||
delete _chunks[i];
|
||||
}
|
||||
rendererDelete(_renderer);
|
||||
cameraDeleteDefinition(_current_camera);
|
||||
}
|
||||
|
||||
void WidgetExplorer::startRendering()
|
||||
|
@ -107,14 +111,14 @@ void WidgetExplorer::startRendering()
|
|||
// Add terrain
|
||||
int chunks = 20;
|
||||
double size = 400.0;
|
||||
double chunksize = size / (double)chunks;
|
||||
double chunksize = size / (double) chunks;
|
||||
double start = -size / 2.0;
|
||||
double water_height = _renderer->water->getHeightInfo(_renderer).base_height;
|
||||
for (int i = 0; i < chunks; i++)
|
||||
{
|
||||
for (int j = 0; j < chunks; j++)
|
||||
{
|
||||
ExplorerChunkTerrain* chunk = new ExplorerChunkTerrain(_renderer, start + chunksize * (double)i, start + chunksize * (double)j, chunksize, chunks, water_height);
|
||||
ExplorerChunkTerrain* chunk = new ExplorerChunkTerrain(_renderer, start + chunksize * (double) i, start + chunksize * (double) j, chunksize, chunks, water_height);
|
||||
_chunks.append(chunk);
|
||||
_updateQueue.append(chunk);
|
||||
}
|
||||
|
@ -123,7 +127,7 @@ void WidgetExplorer::startRendering()
|
|||
// Add skybox
|
||||
for (int orientation = 0; orientation < 5; orientation++)
|
||||
{
|
||||
ExplorerChunkSky* chunk = new ExplorerChunkSky(_renderer, 500.0, (SkyboxOrientation)orientation);
|
||||
ExplorerChunkSky* chunk = new ExplorerChunkSky(_renderer, 500.0, (SkyboxOrientation) orientation);
|
||||
_chunks.append(chunk);
|
||||
_updateQueue.append(chunk);
|
||||
}
|
||||
|
@ -199,13 +203,13 @@ void WidgetExplorer::performChunksMaintenance()
|
|||
|
||||
void WidgetExplorer::resetCamera()
|
||||
{
|
||||
cameraCopyDefinition(_base_camera, &_current_camera);
|
||||
cameraCopyDefinition(_base_camera, _current_camera);
|
||||
updateGL();
|
||||
}
|
||||
|
||||
void WidgetExplorer::validateCamera()
|
||||
{
|
||||
cameraCopyDefinition(&_current_camera, _base_camera);
|
||||
cameraCopyDefinition(_current_camera, _base_camera);
|
||||
}
|
||||
|
||||
void WidgetExplorer::keyPressEvent(QKeyEvent* event)
|
||||
|
@ -228,32 +232,32 @@ void WidgetExplorer::keyPressEvent(QKeyEvent* event)
|
|||
|
||||
if (event->key() == Qt::Key_Up)
|
||||
{
|
||||
cameraStrafeForward(&_current_camera, 0.1 * factor);
|
||||
cameraStrafeForward(_current_camera, 0.1 * factor);
|
||||
updateGL();
|
||||
}
|
||||
else if (event->key() == Qt::Key_Down)
|
||||
{
|
||||
cameraStrafeForward(&_current_camera, -0.1 * factor);
|
||||
cameraStrafeForward(_current_camera, -0.1 * factor);
|
||||
updateGL();
|
||||
}
|
||||
else if (event->key() == Qt::Key_Right)
|
||||
{
|
||||
cameraStrafeRight(&_current_camera, 0.1 * factor);
|
||||
cameraStrafeRight(_current_camera, 0.1 * factor);
|
||||
updateGL();
|
||||
}
|
||||
else if (event->key() == Qt::Key_Left)
|
||||
{
|
||||
cameraStrafeRight(&_current_camera, -0.1 * factor);
|
||||
cameraStrafeRight(_current_camera, -0.1 * factor);
|
||||
updateGL();
|
||||
}
|
||||
else if (event->key() == Qt::Key_PageUp)
|
||||
{
|
||||
cameraStrafeUp(&_current_camera, 0.1 * factor);
|
||||
cameraStrafeUp(_current_camera, 0.1 * factor);
|
||||
updateGL();
|
||||
}
|
||||
else if (event->key() == Qt::Key_PageDown)
|
||||
{
|
||||
cameraStrafeUp(&_current_camera, -0.1 * factor);
|
||||
cameraStrafeUp(_current_camera, -0.1 * factor);
|
||||
updateGL();
|
||||
}
|
||||
else
|
||||
|
@ -290,15 +294,15 @@ void WidgetExplorer::mouseMoveEvent(QMouseEvent* event)
|
|||
|
||||
if (event->buttons() & Qt::LeftButton)
|
||||
{
|
||||
cameraRotateYaw(&_current_camera, (double)(event->x() - _last_mouse_x) * factor * 0.1);
|
||||
cameraRotatePitch(&_current_camera, (double)(event->y() - _last_mouse_y) * 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);
|
||||
updateGL();
|
||||
event->accept();
|
||||
}
|
||||
else if (event->buttons() & Qt::RightButton)
|
||||
{
|
||||
cameraStrafeRight(&_current_camera, (double)(_last_mouse_x - event->x()) * factor);
|
||||
cameraStrafeUp(&_current_camera, (double)(event->y() - _last_mouse_y) * factor);
|
||||
cameraStrafeRight(_current_camera, (double) (_last_mouse_x - event->x()) * factor);
|
||||
cameraStrafeUp(_current_camera, (double) (event->y() - _last_mouse_y) * factor);
|
||||
updateGL();
|
||||
event->accept();
|
||||
}
|
||||
|
@ -331,7 +335,7 @@ void WidgetExplorer::wheelEvent(QWheelEvent* event)
|
|||
|
||||
if (event->orientation() == Qt::Vertical)
|
||||
{
|
||||
cameraStrafeForward(&_current_camera, (double)event->delta() * factor);
|
||||
cameraStrafeForward(_current_camera, (double) event->delta() * factor);
|
||||
updateGL();
|
||||
}
|
||||
event->accept();
|
||||
|
@ -353,7 +357,7 @@ void WidgetExplorer::timerEvent(QTimerEvent*)
|
|||
|
||||
for (int i = 0; i < _chunks.count(); i++)
|
||||
{
|
||||
_chunks[i]->updatePriority(&_current_camera);
|
||||
_chunks[i]->updatePriority(_current_camera);
|
||||
}
|
||||
_lock_chunks.lock();
|
||||
qSort(_updateQueue.begin(), _updateQueue.end(), _cmpChunks);
|
||||
|
@ -367,8 +371,8 @@ void WidgetExplorer::initializeGL()
|
|||
|
||||
void WidgetExplorer::resizeGL(int w, int h)
|
||||
{
|
||||
cameraSetRenderSize(&_current_camera, w, h);
|
||||
exploringSetViewPort(w, h, &_current_camera);
|
||||
cameraSetRenderSize(_current_camera, w, h);
|
||||
exploringSetViewPort(w, h, _current_camera);
|
||||
}
|
||||
|
||||
void WidgetExplorer::paintGL()
|
||||
|
@ -378,14 +382,17 @@ void WidgetExplorer::paintGL()
|
|||
double frame_time;
|
||||
WaterDefinition* water = _renderer->water->definition;
|
||||
|
||||
cameraCopyDefinition(&_current_camera, &_renderer->render_camera);
|
||||
cameraValidateDefinition(&_current_camera, 1);
|
||||
cameraCopyDefinition(_current_camera, _renderer->render_camera);
|
||||
cameraValidateDefinition(_current_camera, 1);
|
||||
|
||||
start_time = QTime::currentTime();
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
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
|
||||
glClearColor(0.0, 0.0, 0.0, 0.0);
|
||||
|
@ -395,10 +402,10 @@ void WidgetExplorer::paintGL()
|
|||
glDisable(GL_TEXTURE_2D);
|
||||
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(camera_location.x - 500.0, water->height, camera_location.z - 500.0);
|
||||
glVertex3f(camera_location.x - 500.0, water->height, camera_location.z + 500.0);
|
||||
glVertex3f(camera_location.x + 500.0, water->height, camera_location.z + 500.0);
|
||||
glVertex3f(camera_location.x + 500.0, water->height, camera_location.z - 500.0);
|
||||
glEnd();
|
||||
|
||||
// Render chunks
|
||||
|
@ -409,7 +416,7 @@ void WidgetExplorer::paintGL()
|
|||
_chunks[i]->render(this);
|
||||
}
|
||||
|
||||
frame_time = 0.001 * (double)start_time.msecsTo(QTime::currentTime());
|
||||
frame_time = 0.001 * (double) start_time.msecsTo(QTime::currentTime());
|
||||
|
||||
_average_frame_time = _average_frame_time * 0.8 + frame_time * 0.2;
|
||||
//printf("%d %f\n", quality, average_frame_time);
|
||||
|
@ -434,6 +441,6 @@ void WidgetExplorer::paintGL()
|
|||
|
||||
while ((error_code = glGetError()) != GL_NO_ERROR)
|
||||
{
|
||||
logDebug(QString("[OpenGL] ERROR : ") + (const char*)gluErrorString(error_code));
|
||||
logDebug(QString("[OpenGL] ERROR : ") + (const char*) gluErrorString(error_code));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ private:
|
|||
void startRendering();
|
||||
void stopRendering();
|
||||
|
||||
CameraDefinition _current_camera;
|
||||
CameraDefinition* _current_camera;
|
||||
CameraDefinition* _base_camera;
|
||||
|
||||
Renderer* _renderer;
|
||||
|
|
|
@ -9,8 +9,8 @@
|
|||
|
||||
#define HEIGHTMAP_RESOLUTION 256
|
||||
|
||||
WidgetHeightMap::WidgetHeightMap(QWidget *parent, TerrainDefinition* terrain):
|
||||
QGLWidget(parent)
|
||||
WidgetHeightMap::WidgetHeightMap(QWidget *parent, TerrainDefinition* terrain) :
|
||||
QGLWidget(parent)
|
||||
{
|
||||
setMinimumSize(500, 500);
|
||||
setFocusPolicy(Qt::StrongFocus);
|
||||
|
@ -39,9 +39,10 @@ WidgetHeightMap::WidgetHeightMap(QWidget *parent, TerrainDefinition* terrain):
|
|||
_top_camera = cameraCreateDefinition();
|
||||
_temp_camera = cameraCreateDefinition();
|
||||
|
||||
cameraSetLocation(&_current_camera, 0.0, 80.0, 20.0);
|
||||
cameraSetTarget(&_current_camera, 0.0, 0.0, 0.0);
|
||||
cameraCopyDefinition(&_current_camera, &_top_camera);
|
||||
Vector3 camera_location = {0.0, 80.0, 20.0};
|
||||
cameraSetLocation(_current_camera, camera_location);
|
||||
cameraSetTarget(_current_camera, VECTOR_ZERO);
|
||||
cameraCopyDefinition(_current_camera, _top_camera);
|
||||
|
||||
_brush_x = 0.0;
|
||||
_brush_z = 0.0;
|
||||
|
@ -55,6 +56,9 @@ WidgetHeightMap::WidgetHeightMap(QWidget *parent, TerrainDefinition* terrain):
|
|||
|
||||
WidgetHeightMap::~WidgetHeightMap()
|
||||
{
|
||||
cameraDeleteDefinition(_current_camera);
|
||||
cameraDeleteDefinition(_top_camera);
|
||||
cameraDeleteDefinition(_temp_camera);
|
||||
rendererDelete(_renderer);
|
||||
noiseDeleteGenerator(_brush_noise);
|
||||
delete[] _vertices;
|
||||
|
@ -171,7 +175,7 @@ void WidgetHeightMap::mouseMoveEvent(QMouseEvent* event)
|
|||
void WidgetHeightMap::timerEvent(QTimerEvent*)
|
||||
{
|
||||
QDateTime new_time = QDateTime::currentDateTime();
|
||||
double duration = 0.001 * (double)_last_time.msecsTo(new_time);
|
||||
double duration = 0.001 * (double) _last_time.msecsTo(new_time);
|
||||
_last_time = new_time;
|
||||
|
||||
if (not underMouse())
|
||||
|
@ -184,8 +188,12 @@ void WidgetHeightMap::timerEvent(QTimerEvent*)
|
|||
double brush_strength;
|
||||
TerrainBrush brush;
|
||||
|
||||
brush.relative_x = _brush_x + _current_camera.target.x;
|
||||
brush.relative_z = _brush_z + _current_camera.target.z;
|
||||
Vector3 camera_target = cameraGetTarget(_current_camera);
|
||||
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.smoothed_size = _brush_size * _brush_smoothing;
|
||||
brush.total_radius = brush.hard_radius + brush.smoothed_size;
|
||||
|
@ -194,24 +202,24 @@ void WidgetHeightMap::timerEvent(QTimerEvent*)
|
|||
|
||||
switch (_brush_mode)
|
||||
{
|
||||
case HEIGHTMAP_BRUSH_RAISE:
|
||||
terrainBrushElevation(_terrain->height_map, &brush, brush_strength * _last_brush_action * 20.0);
|
||||
break;
|
||||
case HEIGHTMAP_BRUSH_SMOOTH:
|
||||
if (_last_brush_action < 0)
|
||||
{
|
||||
terrainBrushSmooth(_terrain->height_map, &brush, brush_strength * 0.1);
|
||||
}
|
||||
else
|
||||
{
|
||||
terrainBrushAddNoise(_terrain->height_map, &brush, _brush_noise, brush_strength * 10.0);
|
||||
}
|
||||
break;
|
||||
case HEIGHTMAP_BRUSH_RESTORE:
|
||||
terrainBrushReset(_terrain->height_map, &brush, brush_strength);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
case HEIGHTMAP_BRUSH_RAISE:
|
||||
terrainBrushElevation(_terrain->height_map, &brush, brush_strength * _last_brush_action * 20.0);
|
||||
break;
|
||||
case HEIGHTMAP_BRUSH_SMOOTH:
|
||||
if (_last_brush_action < 0)
|
||||
{
|
||||
terrainBrushSmooth(_terrain->height_map, &brush, brush_strength * 0.1);
|
||||
}
|
||||
else
|
||||
{
|
||||
terrainBrushAddNoise(_terrain->height_map, &brush, _brush_noise, brush_strength * 10.0);
|
||||
}
|
||||
break;
|
||||
case HEIGHTMAP_BRUSH_RESTORE:
|
||||
terrainBrushReset(_terrain->height_map, &brush, brush_strength);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO Only mark dirty the updated area
|
||||
|
@ -219,7 +227,12 @@ void WidgetHeightMap::timerEvent(QTimerEvent*)
|
|||
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
|
||||
/*double edge_length = 10.0;
|
||||
if (_brush_x > HEIGHTMAP_RESOLUTION / 2.0 - edge_length)
|
||||
|
@ -260,8 +273,8 @@ void WidgetHeightMap::initializeGL()
|
|||
{
|
||||
glClearColor(0.0, 0.0, 0.0, 0.0);
|
||||
|
||||
GLfloat light_diffuse[] = { 0.75, 0.74, 0.7, 1.0 };
|
||||
GLfloat light_specular[] = { 0.0, 0.0, 0.0, 0.0 };
|
||||
GLfloat light_diffuse[] = {0.75, 0.74, 0.7, 1.0};
|
||||
GLfloat light_specular[] = {0.0, 0.0, 0.0, 0.0};
|
||||
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
|
||||
glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
|
||||
light_diffuse[0] = 0.3;
|
||||
|
@ -335,9 +348,9 @@ void WidgetHeightMap::paintGL()
|
|||
glGetDoublev(GL_PROJECTION_MATRIX, projection);
|
||||
glGetIntegerv(GL_VIEWPORT, viewport);
|
||||
|
||||
winX = (float)_last_mouse_x;
|
||||
winY = (float)height() - (float)_last_mouse_y;
|
||||
glReadPixels(_last_mouse_x, (int)winY, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &winZ);
|
||||
winX = (float) _last_mouse_x;
|
||||
winY = (float) height() - (float) _last_mouse_y;
|
||||
glReadPixels(_last_mouse_x, (int) winY, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &winZ);
|
||||
|
||||
if (winZ > 0.0 && winZ < 1000.0)
|
||||
{
|
||||
|
@ -356,10 +369,13 @@ void WidgetHeightMap::paintGL()
|
|||
// Place camera
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
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
|
||||
GLfloat light_position[] = { 40.0, 40.0, 40.0, 0.0 };
|
||||
GLfloat light_position[] = {40.0, 40.0, 40.0, 0.0};
|
||||
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
|
||||
light_position[0] = -40.0;
|
||||
light_position[2] = -60.0;
|
||||
|
@ -369,6 +385,9 @@ void WidgetHeightMap::paintGL()
|
|||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
// 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++)
|
||||
{
|
||||
glBegin(GL_QUAD_STRIP);
|
||||
|
@ -379,8 +398,8 @@ void WidgetHeightMap::paintGL()
|
|||
_VertexInfo* vertex = _vertices + z * rx + x + dx;
|
||||
double diff_x, diff_z, diff;
|
||||
|
||||
diff_x = vertex->point.x - _current_camera.target.x - _brush_x;
|
||||
diff_z = vertex->point.z - _current_camera.target.z - _brush_z;
|
||||
diff_x = vertex->point.x - tx - _brush_x;
|
||||
diff_z = vertex->point.z - tz - _brush_z;
|
||||
diff = sqrt(diff_x * diff_x + diff_z * diff_z);
|
||||
if (diff > _brush_size)
|
||||
{
|
||||
|
@ -396,20 +415,20 @@ void WidgetHeightMap::paintGL()
|
|||
}
|
||||
glColor3f(0.8 + diff, vertex->painted ? 1.0 : 0.8, 0.8);
|
||||
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();
|
||||
}
|
||||
|
||||
// Time stats
|
||||
frame_time = 0.001 * (double)start_time.msecsTo(QTime::currentTime());
|
||||
frame_time = 0.001 * (double) start_time.msecsTo(QTime::currentTime());
|
||||
_average_frame_time = _average_frame_time * 0.8 + frame_time * 0.2;
|
||||
//printf("%d %f\n", quality, average_frame_time);
|
||||
|
||||
while ((error_code = glGetError()) != GL_NO_ERROR)
|
||||
{
|
||||
logDebug(QString("[OpenGL] ERROR : ") + (const char*)gluErrorString(error_code));
|
||||
logDebug(QString("[OpenGL] ERROR : ") + (const char*) gluErrorString(error_code));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -426,17 +445,20 @@ void WidgetHeightMap::updateVertexInfo()
|
|||
_memory_stats = terrainGetMemoryStats(_terrain);
|
||||
|
||||
// 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 z = 0; z < rz; z++)
|
||||
{
|
||||
_VertexInfo* vertex = _vertices + z * rx + x;
|
||||
|
||||
dx = _current_camera.target.x + x - rx / 2;
|
||||
dz = _current_camera.target.z + z - rz / 2;
|
||||
dx = tx + x - rx / 2;
|
||||
dz = tz + z - rz / 2;
|
||||
|
||||
vertex->point.x = (double)dx;
|
||||
vertex->point.z = (double)dz;
|
||||
vertex->point.x = (double) dx;
|
||||
vertex->point.z = (double) dz;
|
||||
|
||||
vertex->point.y = terrainGetGridHeight(_terrain, dx, dz, 1);
|
||||
|
||||
|
|
|
@ -72,9 +72,9 @@ private:
|
|||
QDateTime _last_time;
|
||||
bool _mouse_moved;
|
||||
|
||||
CameraDefinition _top_camera;
|
||||
CameraDefinition _temp_camera;
|
||||
CameraDefinition _current_camera;
|
||||
CameraDefinition* _top_camera;
|
||||
CameraDefinition* _temp_camera;
|
||||
CameraDefinition* _current_camera;
|
||||
|
||||
double _brush_x;
|
||||
double _brush_z;
|
||||
|
|
|
@ -28,11 +28,14 @@ void exploringInit()
|
|||
|
||||
void exploringSetViewPort(int width, int height, CameraDefinition* camera)
|
||||
{
|
||||
CameraPerspective perspective;
|
||||
|
||||
glViewport(0, 0, width, height);
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -14,20 +14,44 @@ typedef struct
|
|||
|
||||
#define MOUNTS_COUNT 11
|
||||
static Mount MOUNTS[MOUNTS_COUNT] = {
|
||||
{{2.0, 0.0, -6.0}, 4.0},
|
||||
{{-1.5, 0.0, -8.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},
|
||||
{{-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},
|
||||
{
|
||||
{2.0, 0.0, -6.0}, 4.0
|
||||
},
|
||||
{
|
||||
{-1.5, 0.0, -8.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
|
||||
},
|
||||
{
|
||||
{-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)
|
||||
{
|
||||
|
@ -147,10 +171,9 @@ Color atmosphereGetPreview(Renderer* renderer, double x, double y, double headin
|
|||
Renderer* atmosphereCreatePreviewRenderer()
|
||||
{
|
||||
Renderer* result = rendererCreate();
|
||||
Vector3 location = {0.0, 7.0, 0.0};
|
||||
|
||||
result->render_camera.location.x = 0.0;
|
||||
result->render_camera.location.y = 7.0;
|
||||
result->render_camera.location.z = 0.0;
|
||||
cameraSetLocation(result->render_camera, location);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -6,6 +6,30 @@
|
|||
#include "scenery.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)
|
||||
{
|
||||
v3Save(stream, &camera->location);
|
||||
|
@ -24,32 +48,34 @@ void cameraLoad(PackStream* stream, CameraDefinition* camera)
|
|||
cameraValidateDefinition(camera, 0);
|
||||
}
|
||||
|
||||
CameraDefinition cameraCreateDefinition()
|
||||
CameraDefinition* cameraCreateDefinition()
|
||||
{
|
||||
CameraDefinition definition;
|
||||
CameraDefinition* definition;
|
||||
|
||||
definition.location.x = 0.0;
|
||||
definition.location.y = 0.0;
|
||||
definition.location.z = 0.0;
|
||||
definition.yaw = 0.0;
|
||||
definition.pitch = 0.0;
|
||||
definition.roll = 0.0;
|
||||
definition = malloc(sizeof (CameraDefinition));
|
||||
|
||||
definition.width = 1.0;
|
||||
definition.height = 1.0;
|
||||
definition.yfov = 1.57;
|
||||
definition.xratio = 1.0;
|
||||
definition.znear = 1.0;
|
||||
definition.zfar = 1000.0;
|
||||
definition->location.x = 0.0;
|
||||
definition->location.y = 0.0;
|
||||
definition->location.z = 0.0;
|
||||
definition->yaw = 0.0;
|
||||
definition->pitch = 0.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;
|
||||
}
|
||||
|
||||
void cameraDeleteDefinition(CameraDefinition* definition)
|
||||
{
|
||||
UNUSED(definition);
|
||||
free(definition);
|
||||
}
|
||||
|
||||
void cameraCopyDefinition(CameraDefinition* source, CameraDefinition* destination)
|
||||
|
@ -117,22 +143,61 @@ void cameraValidateDefinition(CameraDefinition* definition, int check_above)
|
|||
definition->unproject = m4Inverse(definition->project);
|
||||
}
|
||||
|
||||
void cameraSetLocation(CameraDefinition* camera, double x, double y, double z)
|
||||
Vector3 cameraGetLocation(CameraDefinition* camera)
|
||||
{
|
||||
camera->location.x = x;
|
||||
camera->location.y = y;
|
||||
camera->location.z = z;
|
||||
return camera->location;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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;
|
||||
target.y = y;
|
||||
target.z = z;
|
||||
void cameraSetTarget(CameraDefinition* camera, Vector3 target)
|
||||
{
|
||||
Vector3 forward;
|
||||
|
||||
forward = v3Sub(target, camera->location);
|
||||
if (v3Norm(forward) < 0.0000001)
|
||||
|
@ -156,12 +221,20 @@ void cameraSetTarget(CameraDefinition* camera, double x, double y, double z)
|
|||
else
|
||||
{
|
||||
/* Guess angles */
|
||||
v3ToEuler(forward, &camera->yaw, &camera->pitch);
|
||||
VectorSpherical spherical = v3ToSpherical(forward);
|
||||
camera->yaw = spherical.phi;
|
||||
camera->pitch = spherical.theta;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
camera->roll = angle;
|
||||
|
@ -220,7 +293,7 @@ void cameraSetRenderSize(CameraDefinition* camera, int width, int height)
|
|||
cameraValidateDefinition(camera, 0);
|
||||
}
|
||||
|
||||
Vector3 cameraProject(CameraDefinition* camera, Renderer* renderer, Vector3 point)
|
||||
Vector3 cameraProject(CameraDefinition* camera, Vector3 point)
|
||||
{
|
||||
point = m4Transform(camera->project, point);
|
||||
if (point.z < 1.0)
|
||||
|
@ -233,7 +306,7 @@ Vector3 cameraProject(CameraDefinition* camera, Renderer* renderer, Vector3 poin
|
|||
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.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 callback Post-processing callback.
|
||||
*/
|
||||
|
||||
/*void cameraPushOverlay(CameraDefinition* camera, Color col, f_RenderFragmentCallback callback)
|
||||
{
|
||||
Vertex v1, v2, v3, v4;
|
||||
|
@ -301,38 +375,45 @@ int cameraIsBoxInView(CameraDefinition* camera, Vector3 center, double xsize, do
|
|||
center.x -= xsize / 2.0;
|
||||
center.y -= ysize / 2.0;
|
||||
center.z -= zsize / 2.0;
|
||||
projected = cameraProject(camera, NULL, center);
|
||||
projected = cameraProject(camera, center);
|
||||
xmin = xmax = projected.x;
|
||||
ymin = ymax = projected.y;
|
||||
zmax = projected.z;
|
||||
|
||||
center.x += xsize;
|
||||
projected = cameraProject(camera, NULL, center);
|
||||
projected = cameraProject(camera, center);
|
||||
_updateBox(&projected, &xmin, &xmax, &ymin, &ymax, &zmax);
|
||||
|
||||
center.z += zsize;
|
||||
projected = cameraProject(camera, NULL, center);
|
||||
projected = cameraProject(camera, center);
|
||||
_updateBox(&projected, &xmin, &xmax, &ymin, &ymax, &zmax);
|
||||
|
||||
center.x -= xsize;
|
||||
projected = cameraProject(camera, NULL, center);
|
||||
projected = cameraProject(camera, center);
|
||||
_updateBox(&projected, &xmin, &xmax, &ymin, &ymax, &zmax);
|
||||
|
||||
center.y += ysize;
|
||||
projected = cameraProject(camera, NULL, center);
|
||||
projected = cameraProject(camera, center);
|
||||
_updateBox(&projected, &xmin, &xmax, &ymin, &ymax, &zmax);
|
||||
|
||||
center.x += xsize;
|
||||
projected = cameraProject(camera, NULL, center);
|
||||
projected = cameraProject(camera, center);
|
||||
_updateBox(&projected, &xmin, &xmax, &ymin, &ymax, &zmax);
|
||||
|
||||
center.z -= zsize;
|
||||
projected = cameraProject(camera, NULL, center);
|
||||
projected = cameraProject(camera, center);
|
||||
_updateBox(&projected, &xmin, &xmax, &ymin, &ymax, &zmax);
|
||||
|
||||
center.x -= xsize;
|
||||
projected = cameraProject(camera, NULL, center);
|
||||
projected = cameraProject(camera, center);
|
||||
_updateBox(&projected, &xmin, &xmax, &ymin, &ymax, &zmax);
|
||||
|
||||
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/euclid.h"
|
||||
#include "renderer.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
typedef struct CameraDefinition CameraDefinition;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
double yfov;
|
||||
double xratio;
|
||||
double znear;
|
||||
double zfar;
|
||||
} CameraPerspective;
|
||||
|
||||
void cameraSave(PackStream* stream, CameraDefinition* camera);
|
||||
void cameraLoad(PackStream* stream, CameraDefinition* camera);
|
||||
|
||||
CameraDefinition cameraCreateDefinition();
|
||||
CameraDefinition* cameraCreateDefinition();
|
||||
void cameraDeleteDefinition(CameraDefinition* definition);
|
||||
void cameraCopyDefinition(CameraDefinition* source, CameraDefinition* destination);
|
||||
void cameraValidateDefinition(CameraDefinition* definition, int check_above);
|
||||
|
||||
void cameraSetLocation(CameraDefinition* camera, double x, double y, double z);
|
||||
void cameraSetTarget(CameraDefinition* camera, double x, double y, double z);
|
||||
Vector3 cameraGetLocation(CameraDefinition* camera);
|
||||
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 cameraStrafeForward(CameraDefinition* camera, double value);
|
||||
|
@ -30,11 +51,13 @@ void cameraRotateRoll(CameraDefinition* camera, double value);
|
|||
|
||||
void cameraSetRenderSize(CameraDefinition* camera, int width, int height);
|
||||
|
||||
Vector3 cameraProject(CameraDefinition* camera, Renderer* renderer, Vector3 point);
|
||||
Vector3 cameraUnproject(CameraDefinition* camera, Renderer* renderer, Vector3 point);
|
||||
Vector3 cameraProject(CameraDefinition* camera, Vector3 point);
|
||||
Vector3 cameraUnproject(CameraDefinition* camera, Vector3 point);
|
||||
/*void cameraPushOverlay(CameraDefinition* camera, Color col, f_RenderFragmentCallback callback);*/
|
||||
int cameraIsBoxInView(CameraDefinition* camera, Vector3 center, double xsize, double ysize, double zsize);
|
||||
|
||||
int cameraTransitionToAnother(CameraDefinition* current, CameraDefinition* wanted, double factor);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
#include "auto.h"
|
||||
#include "system.h"
|
||||
#include "camera.h"
|
||||
#include "scenery.h"
|
||||
#include "render.h"
|
||||
#include "main.h"
|
||||
|
@ -13,35 +12,13 @@
|
|||
|
||||
void paysagesInit()
|
||||
{
|
||||
CameraDefinition camera;
|
||||
|
||||
systemInit();
|
||||
openclInit();
|
||||
|
||||
sceneryInit();
|
||||
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);
|
||||
|
||||
// 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()
|
||||
|
|
|
@ -27,18 +27,20 @@ static Vector3 _getCameraLocation(Renderer* renderer, Vector3 target)
|
|||
{
|
||||
UNUSED(renderer);
|
||||
UNUSED(target);
|
||||
return renderer->render_camera.location;
|
||||
return cameraGetLocation(renderer->render_camera);
|
||||
}
|
||||
|
||||
static Vector3 _getCameraDirection(Renderer* renderer, Vector3 target)
|
||||
{
|
||||
UNUSED(renderer);
|
||||
UNUSED(target);
|
||||
return renderer->render_camera.forward;
|
||||
|
||||
return cameraGetDirectionNormalized(renderer->render_camera);
|
||||
}
|
||||
|
||||
static double _getPrecision(Renderer* renderer, Vector3 location)
|
||||
{
|
||||
|
||||
UNUSED(renderer);
|
||||
UNUSED(location);
|
||||
return 0.0;
|
||||
|
@ -46,18 +48,21 @@ static double _getPrecision(Renderer* renderer, Vector3 location)
|
|||
|
||||
static Vector3 _projectPoint(Renderer* renderer, Vector3 point)
|
||||
{
|
||||
|
||||
UNUSED(renderer);
|
||||
return point;
|
||||
}
|
||||
|
||||
static Vector3 _unprojectPoint(Renderer* renderer, Vector3 point)
|
||||
{
|
||||
|
||||
UNUSED(renderer);
|
||||
return point;
|
||||
}
|
||||
|
||||
static void _pushTriangle(Renderer* renderer, Vector3 v1, Vector3 v2, Vector3 v3, f_RenderFragmentCallback callback, void* callback_data)
|
||||
{
|
||||
|
||||
Vector3 p1, p2, p3;
|
||||
|
||||
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)
|
||||
{
|
||||
|
||||
renderer->pushTriangle(renderer, v2, v3, v1, 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)
|
||||
{
|
||||
|
||||
Vector3 p1, p2, p3;
|
||||
|
||||
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)
|
||||
{
|
||||
|
||||
renderer->pushDisplacedTriangle(renderer, v2, v3, v1, ov2, ov3, ov1, 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)
|
||||
{
|
||||
|
||||
return _RAYCASTING_NULL;
|
||||
}
|
||||
|
||||
static Color _applyLightingToSurface(Renderer* renderer, Vector3 location, Vector3 normal, SurfaceMaterial* material)
|
||||
{
|
||||
|
||||
LightStatus* light = lightingCreateStatus(renderer->lighting, location, renderer->getCameraLocation(renderer, location));
|
||||
renderer->atmosphere->getLightingStatus(renderer, light, normal, 0);
|
||||
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)
|
||||
{
|
||||
|
||||
color = renderer->atmosphere->applyAerialPerspective(renderer, location, color).final;
|
||||
color = renderer->clouds->getColor(renderer, color, renderer->getCameraLocation(renderer, location), location);
|
||||
return color;
|
||||
|
@ -113,7 +124,8 @@ static Color _applyMediumTraversal(Renderer* renderer, Vector3 location, Color c
|
|||
|
||||
Renderer* rendererCreate()
|
||||
{
|
||||
Renderer* result = malloc(sizeof(Renderer));
|
||||
|
||||
Renderer* result = malloc(sizeof (Renderer));
|
||||
RenderParams params = {1, 1, 1, 5};
|
||||
|
||||
result->render_quality = 5;
|
||||
|
@ -156,6 +168,8 @@ Renderer* rendererCreate()
|
|||
|
||||
void rendererDelete(Renderer* renderer)
|
||||
{
|
||||
|
||||
cameraDeleteDefinition(renderer->render_camera);
|
||||
lightingManagerDelete(renderer->lighting);
|
||||
|
||||
AtmosphereRendererClass.destroy(renderer->atmosphere);
|
||||
|
@ -171,6 +185,7 @@ void rendererDelete(Renderer* renderer)
|
|||
|
||||
void rendererSetPreviewCallbacks(Renderer* renderer, RenderCallbackStart start, RenderCallbackDraw draw, RenderCallbackUpdate update)
|
||||
{
|
||||
|
||||
renderSetPreviewCallbacks(renderer->render_area, start, draw, update);
|
||||
}
|
||||
|
||||
|
@ -189,7 +204,7 @@ void rendererStart(Renderer* renderer, RenderParams params)
|
|||
renderer->render_interrupt = 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);
|
||||
renderSetParams(renderer->render_area, params);
|
||||
|
@ -205,6 +220,7 @@ void rendererStart(Renderer* renderer, RenderParams params)
|
|||
|
||||
if (++loops >= 10)
|
||||
{
|
||||
|
||||
renderUpdate(renderer->render_area);
|
||||
loops = 0;
|
||||
}
|
||||
|
|
|
@ -7,10 +7,12 @@
|
|||
#include "terrain/public.h"
|
||||
#include "textures/public.h"
|
||||
#include "water/public.h"
|
||||
#include "camera.h"
|
||||
#include "render.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct Renderer
|
||||
|
@ -19,18 +21,18 @@ struct Renderer
|
|||
int render_quality;
|
||||
int render_width;
|
||||
int render_height;
|
||||
CameraDefinition render_camera;
|
||||
CameraDefinition* render_camera;
|
||||
|
||||
/* 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);
|
||||
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);
|
||||
Vector3(*projectPoint)(Renderer* renderer, Vector3 point);
|
||||
Vector3(*unprojectPoint)(Renderer* renderer, Vector3 point);
|
||||
int (*addRenderProgress)(Renderer* renderer, double progress);
|
||||
void (*pushTriangle)(Renderer* renderer, Vector3 v1, Vector3 v2, Vector3 v3, f_RenderFragmentCallback callback, void* callback_data);
|
||||
void (*pushQuad)(Renderer* renderer, Vector3 v1, Vector3 v2, Vector3 v3, Vector3 v4, f_RenderFragmentCallback callback, void* callback_data);
|
||||
|
@ -38,11 +40,11 @@ struct Renderer
|
|||
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);
|
||||
|
||||
/* Shortcuts */
|
||||
Color (*applyLightingToSurface)(Renderer* renderer, Vector3 location, Vector3 normal, SurfaceMaterial* material);
|
||||
Color (*applyMediumTraversal)(Renderer* renderer, Vector3 location, Color color);
|
||||
Color(*applyLightingToSurface)(Renderer* renderer, Vector3 location, Vector3 normal, SurfaceMaterial* material);
|
||||
Color(*applyMediumTraversal)(Renderer* renderer, Vector3 location, Color color);
|
||||
|
||||
/* Scenery related */
|
||||
RayCastingResult (*rayWalking)(Renderer* renderer, Vector3 location, Vector3 direction, int terrain, int water, int sky, int clouds);
|
||||
RayCastingResult(*rayWalking)(Renderer* renderer, Vector3 location, Vector3 direction, int terrain, int water, int sky, int clouds);
|
||||
|
||||
/* Autonomous tools */
|
||||
LightingManager* lighting;
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
#include "system.h"
|
||||
|
||||
static AtmosphereDefinition* _atmosphere;
|
||||
static CameraDefinition _camera;
|
||||
static CameraDefinition* _camera;
|
||||
static CloudsDefinition* _clouds;
|
||||
static TerrainDefinition* _terrain;
|
||||
static TexturesDefinition* _textures;
|
||||
|
@ -34,7 +34,7 @@ void sceneryInit()
|
|||
void sceneryQuit()
|
||||
{
|
||||
AtmosphereDefinitionClass.destroy(_atmosphere);
|
||||
cameraDeleteDefinition(&_camera);
|
||||
cameraDeleteDefinition(_camera);
|
||||
CloudsDefinitionClass.destroy(_clouds);
|
||||
TerrainDefinitionClass.destroy(_terrain);
|
||||
TexturesDefinitionClass.destroy(_textures);
|
||||
|
@ -63,7 +63,7 @@ void scenerySave(PackStream* stream)
|
|||
{
|
||||
noiseSave(stream);
|
||||
AtmosphereDefinitionClass.save(stream, _atmosphere);
|
||||
cameraSave(stream, &_camera);
|
||||
cameraSave(stream, _camera);
|
||||
CloudsDefinitionClass.save(stream, _clouds);
|
||||
TerrainDefinitionClass.save(stream, _terrain);
|
||||
TexturesDefinitionClass.save(stream, _textures);
|
||||
|
@ -81,7 +81,7 @@ void sceneryLoad(PackStream* stream)
|
|||
|
||||
noiseLoad(stream);
|
||||
AtmosphereDefinitionClass.load(stream, _atmosphere);
|
||||
cameraLoad(stream, &_camera);
|
||||
cameraLoad(stream, _camera);
|
||||
CloudsDefinitionClass.load(stream, _clouds);
|
||||
TerrainDefinitionClass.load(stream, _terrain);
|
||||
TexturesDefinitionClass.load(stream, _textures);
|
||||
|
@ -105,13 +105,13 @@ void sceneryGetAtmosphere(AtmosphereDefinition* atmosphere)
|
|||
|
||||
void scenerySetCamera(CameraDefinition* camera)
|
||||
{
|
||||
cameraCopyDefinition(camera, &_camera);
|
||||
cameraValidateDefinition(&_camera, 1);
|
||||
cameraCopyDefinition(camera, _camera);
|
||||
cameraValidateDefinition(_camera, 1);
|
||||
}
|
||||
|
||||
void sceneryGetCamera(CameraDefinition* camera)
|
||||
{
|
||||
cameraCopyDefinition(&_camera, camera);
|
||||
cameraCopyDefinition(_camera, camera);
|
||||
}
|
||||
|
||||
void scenerySetClouds(CloudsDefinition* clouds)
|
||||
|
@ -128,7 +128,7 @@ void scenerySetTerrain(TerrainDefinition* terrain)
|
|||
{
|
||||
TerrainDefinitionClass.copy(terrain, _terrain);
|
||||
|
||||
cameraValidateDefinition(&_camera, 1);
|
||||
cameraValidateDefinition(_camera, 1);
|
||||
}
|
||||
|
||||
void sceneryGetTerrain(TerrainDefinition* terrain)
|
||||
|
@ -140,7 +140,7 @@ void scenerySetTextures(TexturesDefinition* textures)
|
|||
{
|
||||
TexturesDefinitionClass.copy(textures, _textures);
|
||||
|
||||
cameraValidateDefinition(&_camera, 1);
|
||||
cameraValidateDefinition(_camera, 1);
|
||||
}
|
||||
|
||||
void sceneryGetTextures(TexturesDefinition* textures)
|
||||
|
@ -152,7 +152,7 @@ void scenerySetWater(WaterDefinition* water)
|
|||
{
|
||||
WaterDefinitionClass.copy(water, _water);
|
||||
|
||||
cameraValidateDefinition(&_camera, 1);
|
||||
cameraValidateDefinition(_camera, 1);
|
||||
}
|
||||
|
||||
void sceneryGetWater(WaterDefinition* water)
|
||||
|
@ -167,11 +167,6 @@ void sceneryRenderFirstPass(Renderer* renderer)
|
|||
atmosphereRenderSkydome(renderer);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/******* Standard renderer *********/
|
||||
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)
|
||||
{
|
||||
return cameraProject(&renderer->render_camera, renderer, point);
|
||||
return cameraProject(renderer->render_camera, 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)
|
||||
{
|
||||
Vector3 projected;
|
||||
|
||||
projected = cameraProject(&renderer->render_camera, renderer, location);
|
||||
projected = cameraProject(renderer->render_camera, location);
|
||||
projected.x += 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()
|
||||
|
@ -218,7 +213,7 @@ Renderer* sceneryCreateStandardRenderer()
|
|||
|
||||
result = rendererCreate();
|
||||
|
||||
cameraCopyDefinition(&_camera, &result->render_camera);
|
||||
cameraCopyDefinition(_camera, result->render_camera);
|
||||
|
||||
result->rayWalking = _rayWalking;
|
||||
result->projectPoint = _projectPoint;
|
||||
|
|
|
@ -13,7 +13,7 @@ static PreviewRenderer* _createRenderer()
|
|||
{
|
||||
PreviewRenderer* renderer;
|
||||
|
||||
renderer = (PreviewRenderer*)malloc(sizeof(PreviewRenderer));
|
||||
renderer = (PreviewRenderer*)malloc(sizeof (PreviewRenderer));
|
||||
renderer->renderer = rendererCreate();
|
||||
|
||||
return renderer;
|
||||
|
@ -27,8 +27,8 @@ static void _deleteRenderer(PreviewRenderer* renderer)
|
|||
|
||||
static void _setCamera(PreviewRenderer* renderer, Vector3 location, Vector3 target)
|
||||
{
|
||||
cameraSetLocation(&renderer->renderer->render_camera, location.x, location.y, location.z);
|
||||
cameraSetTarget(&renderer->renderer->render_camera, target.x, target.y, target.z);
|
||||
cameraSetLocation(renderer->renderer->render_camera, location);
|
||||
cameraSetTarget(renderer->renderer->render_camera, target);
|
||||
}
|
||||
|
||||
PreviewClass previewCreateClass(FuncPreviewCustomizeRenderer customizeRenderer, FuncPreviewBindDefinition bindDefinition, FuncPreviewGetPixelColor getPixelColor)
|
||||
|
|
|
@ -25,29 +25,6 @@ typedef struct
|
|||
double base_height;
|
||||
} 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 (*FuncObjectDelete)(void* object);
|
||||
typedef void (*FuncObjectCopy)(void* source, void* destination);
|
||||
|
|
|
@ -102,10 +102,13 @@ Vector3 v3Cross(Vector3 v1, Vector3 v2)
|
|||
return result;
|
||||
}
|
||||
|
||||
void v3ToEuler(Vector3 v, double* heading, double* attitude)
|
||||
VectorSpherical v3ToSpherical(Vector3 v)
|
||||
{
|
||||
*heading = euclidGet2DAngle(v.x, v.z);
|
||||
*attitude = euclidGet2DAngle(sqrt(v.x * v.x + v.z * v.z), v.y);
|
||||
VectorSpherical result;
|
||||
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)
|
||||
|
@ -361,17 +364,17 @@ Matrix4 m4NewPerspective(double fov_y, double aspect, double near, double far)
|
|||
double m4Determinant(Matrix4 m)
|
||||
{
|
||||
return ((m.a * m.f - m.e * m.b)
|
||||
* (m.k * m.p - m.o * m.l)
|
||||
- (m.a * m.j - m.i * m.b)
|
||||
* (m.g * m.p - m.o * m.h)
|
||||
+ (m.a * m.n - m.m * m.b)
|
||||
* (m.g * m.l - m.k * m.h)
|
||||
+ (m.e * m.j - m.i * m.f)
|
||||
* (m.c * m.p - m.o * m.d)
|
||||
- (m.e * m.n - m.m * m.f)
|
||||
* (m.c * m.l - m.k * m.d)
|
||||
+ (m.i * m.n - m.m * m.j)
|
||||
* (m.c * m.h - m.g * m.d));
|
||||
* (m.k * m.p - m.o * m.l)
|
||||
- (m.a * m.j - m.i * m.b)
|
||||
* (m.g * m.p - m.o * m.h)
|
||||
+ (m.a * m.n - m.m * m.b)
|
||||
* (m.g * m.l - m.k * m.h)
|
||||
+ (m.e * m.j - m.i * m.f)
|
||||
* (m.c * m.p - m.o * m.d)
|
||||
- (m.e * m.n - m.m * m.f)
|
||||
* (m.c * m.l - m.k * m.d)
|
||||
+ (m.i * m.n - m.m * m.j)
|
||||
* (m.c * m.h - m.g * m.d));
|
||||
}
|
||||
|
||||
Matrix4 m4Inverse(Matrix4 m)
|
||||
|
|
|
@ -3,8 +3,36 @@
|
|||
|
||||
#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
|
||||
extern "C" {
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
typedef struct
|
||||
|
@ -14,6 +42,13 @@ typedef struct
|
|||
double z;
|
||||
} Vector3;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
double r;
|
||||
double theta;
|
||||
double phi;
|
||||
} VectorSpherical;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
double a;
|
||||
|
@ -53,7 +88,7 @@ double v3Norm(Vector3 v);
|
|||
Vector3 v3Normalize(Vector3 v);
|
||||
double v3Dot(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 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;
|
||||
}
|
||||
|
||||
static inline void _Vector3_str(Vector3 v, char* buffer, int length)
|
||||
{
|
||||
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), 5.0 * M_PI_4);
|
||||
}
|
||||
|
||||
END_TEST
|
||||
|
||||
START_TEST(test_vectors)
|
||||
{
|
||||
Vector3 v1, v2, v3;
|
||||
double d1, d2;
|
||||
|
||||
/* Test scaling */
|
||||
v1.x = 0.0; v1.y = -4.3; 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;
|
||||
v1.x = 0.0;
|
||||
v1.y = -4.3;
|
||||
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, -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;
|
||||
v3ToEuler(v1, &d1, &d2);
|
||||
ck_assert_double_eq(d1, M_PI_4);
|
||||
ck_assert_double_eq(d2, M_PI_2 - 0.955316618125);
|
||||
v2 = v3ToSpherical(v1);
|
||||
ck_assert_double_eq(v2.r, sqrt(0.5 * 0.5 + 0.5 * 0.5 + 0.5 * 0.5));
|
||||
ck_assert_double_eq(v2.phi, M_PI_4);
|
||||
ck_assert_double_eq(v2.theta, M_PI_2 - 0.955316618125);
|
||||
}
|
||||
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>
|
||||
|
||||
extern void test_euclid_case(Suite* s);
|
||||
extern void test_camera_case(Suite* s);
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
|
@ -10,6 +11,7 @@ int main(int argc, char** argv)
|
|||
|
||||
/* TODO Find a way to automate this */
|
||||
test_euclid_case(s);
|
||||
test_camera_case(s);
|
||||
|
||||
SRunner *sr = srunner_create(s);
|
||||
srunner_run_all(sr, CK_NORMAL);
|
||||
|
|
Loading…
Reference in a new issue