paysages : Revert to doubles instead of floats + Fixed maximum memory size for render area.

git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@350 b1fd45b6-86a6-48da-8261-f70d1f35bdcc
This commit is contained in:
Michaël Lemaire 2012-06-17 09:40:40 +00:00 committed by ThunderK
parent 5deb2fdced
commit 203dd0ab12
78 changed files with 1073 additions and 1091 deletions

5
TODO
View file

@ -1,4 +1,9 @@
Technology Preview 2 :
- InputInt doesn't honor small_step.
- Improve shadow smoothness
=> Configurable smoothness factor
=> Smoothness depends on distance to hit
=> Smoothness stays the same when quality changes, but has better resolution
- Fix the fog impression when cloud layer overlaps with ground range.
- Remove color gradations (replace with automatic boolean and simple colors).
- Replace zone ranges with curves (with curve input and curve dialog).

View file

@ -27,11 +27,11 @@ void displayHelp()
printf(" -rh x Render height (int)\n");
printf(" -rq x Render quality (int, 1 to 10)\n");
printf(" -ra x Render anti-aliasing (int, 1 to 4)\n");
printf(" -di x Day start time (float, 0.0 to 1.0)\n");
printf(" -ds x Day step time (float)\n");
printf(" -di x Day start time (double, 0.0 to 1.0)\n");
printf(" -ds x Day step time (double)\n");
}
void _previewUpdate(float progress)
void _previewUpdate(double progress)
{
printf("\rProgress : %0.1f%% ", progress * 100.0);
fflush(stdout);
@ -43,8 +43,8 @@ int main(int argc, char** argv)
char* conf_file_path = NULL;
RenderParams conf_render_params = {800, 600, 1, 5};
int conf_nb_pictures = 1;
float conf_daytime_start = 0.4;
float conf_daytime_step = 0.0;
double conf_daytime_start = 0.4;
double conf_daytime_step = 0.0;
int outputcount;
char outputpath[500];

View file

@ -47,7 +47,8 @@ bool BaseExplorerChunk::maintain()
{
if (_texture_current_size <= 1 || i % 2 != 0 || j % 2 != 0)
{
Color color = getTextureColor((float)i / (float)new_texture_size, 1.0 - (float)j / (float)new_texture_size);
Color color = getTextureColor((double)i / (double)new_texture_size, 1.0 - (double)j / (double)new_texture_size);
colorNormalize(&color);
new_image->setPixel(i, j, colorTo32BitBGRA(&color));
}
}
@ -139,12 +140,12 @@ void BaseExplorerChunk::onRenderEvent(QGLWidget* widget)
{
}
float BaseExplorerChunk::getDisplayedSizeHint(CameraDefinition* camera)
double BaseExplorerChunk::getDisplayedSizeHint(CameraDefinition* camera)
{
return 0.0;
}
Color BaseExplorerChunk::getTextureColor(float x, float y)
Color BaseExplorerChunk::getTextureColor(double x, double y)
{
return COLOR_TRANSPARENT;
}

View file

@ -15,7 +15,7 @@ public:
void updatePriority(CameraDefinition* camera);
void render(QGLWidget* widget);
float priority;
double priority;
protected:
BaseExplorerChunk(Renderer* renderer);
@ -28,8 +28,8 @@ protected:
virtual void onResetEvent();
virtual bool onMaintainEvent();
virtual void onRenderEvent(QGLWidget* widget);
virtual float getDisplayedSizeHint(CameraDefinition* camera);
virtual Color getTextureColor(float x, float y);
virtual double getDisplayedSizeHint(CameraDefinition* camera);
virtual Color getTextureColor(double x, double y);
QMutex _lock_data;

View file

@ -229,7 +229,7 @@ void BaseForm::addInputInt(QString label, int* value, int min, int max, int smal
addInput(new InputInt(form, label, value, min, max, small_step, large_step));
}
void BaseForm::addInputDouble(QString label, float* value, float min, float max, float small_step, float large_step)
void BaseForm::addInputDouble(QString label, double* value, double min, double max, double small_step, double large_step)
{
addInput(new InputDouble(form, label, value, min, max, small_step, large_step));
}
@ -254,7 +254,7 @@ void BaseForm::addInputNoise(QString label, NoiseGenerator* value)
addInput(new InputNoise(form, label, value));
}
void BaseForm::addInputCurve(QString label, Curve* value, float xmin, float xmax, float ymin, float ymax)
void BaseForm::addInputCurve(QString label, Curve* value, double xmin, double xmax, double ymin, double ymax)
{
addInput(new InputCurve(form, label, value, xmin, xmax, ymin, ymax));
}

View file

@ -39,12 +39,12 @@ protected:
QPushButton* addButton(QString label);
void addInput(BaseInput* input);
void addInputInt(QString label, int* value, int min, int max, int small_step, int large_step);
void addInputDouble(QString label, float* value, float min, float max, float small_step, float large_step);
void addInputDouble(QString label, double* value, double min, double max, double small_step, double large_step);
void addInputBoolean(QString label, int* value);
void addInputColor(QString label, Color* value);
void addInputColorGradation(QString label, ColorGradation* value);
void addInputNoise(QString label, NoiseGenerator* value);
void addInputCurve(QString label, Curve* value, float xmin, float xmax, float ymin, float ymax);
void addInputCurve(QString label, Curve* value, double xmin, double xmax, double ymin, double ymax);
void addInputMaterial(QString label, SurfaceMaterial* material);
int currentLayer();

View file

@ -318,14 +318,14 @@ void BasePreview::updateData()
{
}
QColor BasePreview::getColor(float x, float y)
QColor BasePreview::getColor(double x, double y)
{
return QColor(0, 0, 0);
}
void BasePreview::configScaling(float min, float max, float step, float init, bool logarithmic)
void BasePreview::configScaling(double min, double max, double step, double init, bool logarithmic)
{
float size = (float) width();
double size = (double) width();
if (size >= 1.0)
{
@ -345,7 +345,7 @@ void BasePreview::configScaling(float min, float max, float step, float init, bo
}
}
void BasePreview::configScrolling(float xmin, float xmax, float xinit, float ymin, float ymax, float yinit)
void BasePreview::configScrolling(double xmin, double xmax, double xinit, double ymin, double ymax, double yinit)
{
conf_scroll_xmin = xmin;
conf_scroll_xmax = xmax;
@ -388,7 +388,7 @@ void BasePreview::commitChunkTransaction(QImage* chunk, int x, int y, int w, int
QColor BasePreview::getPixelColor(int x, int y)
{
return getColor((float) (x - _width / 2) * scaling + xoffset, (float) (y - _height / 2) * scaling + yoffset);
return getColor((double) (x - _width / 2) * scaling + xoffset, (double) (y - _height / 2) * scaling + yoffset);
}
void BasePreview::handleRedraw()
@ -523,8 +523,8 @@ void BasePreview::mouseMoveEvent(QMouseEvent* event)
if (ndx <= -width || ndx >= width || ndy <= -height || ndy >= height)
{
xoffset -= (float) ndx * scaling;
yoffset -= (float) ndy * scaling;
xoffset -= (double) ndx * scaling;
yoffset -= (double) ndy * scaling;
lock_drawing->lock();
pixbuf->fill(0x00000000);
@ -537,8 +537,8 @@ void BasePreview::mouseMoveEvent(QMouseEvent* event)
lock_drawing->lock();
xoffset -= (float) ndx * scaling;
yoffset -= (float) ndy * scaling;
xoffset -= (double) ndx * scaling;
yoffset -= (double) ndy * scaling;
if (ndx < 0)
{
@ -580,8 +580,8 @@ void BasePreview::mouseMoveEvent(QMouseEvent* event)
void BasePreview::wheelEvent(QWheelEvent* event)
{
float factor;
float old_scaling;
double factor;
double old_scaling;
int width, height;
int new_width, new_height;
@ -637,8 +637,8 @@ void BasePreview::wheelEvent(QWheelEvent* event)
if (scaling < old_scaling)
{
lock_drawing->lock();
new_width = (int) floor(((float) width) * scaling / old_scaling);
new_height = (int) floor(((float) height) * scaling / old_scaling);
new_width = (int) floor(((double) width) * scaling / old_scaling);
new_height = (int) floor(((double) height) * scaling / old_scaling);
QImage part = pixbuf->copy((width - new_width) / 2, (height - new_height) / 2, new_width, new_height).scaled(width, height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
pixbuf->fill(0x00000000);
QPainter painter(pixbuf);
@ -651,7 +651,7 @@ void BasePreview::wheelEvent(QWheelEvent* event)
else if (scaling > old_scaling)
{
lock_drawing->lock();
QImage part = pixbuf->scaled((int) floor(((float) width) * old_scaling / scaling), (int) floor(((float) height) * old_scaling / scaling), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
QImage part = pixbuf->scaled((int) floor(((double) width) * old_scaling / scaling), (int) floor(((double) height) * old_scaling / scaling), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
pixbuf->fill(0x00000000);
QPainter painter(pixbuf);
painter.drawImage((width - part.width()) / 2, (height - part.height()) / 2, part);

View file

@ -28,14 +28,14 @@ public:
protected:
virtual void updateData();
virtual QColor getColor(float x, float y);
virtual QColor getColor(double x, double y);
void configScaling(float min, float max, float step, float init, bool logarithmic = true);
void configScrolling(float xmin, float xmax, float xinit, float ymin, float ymax, float yinit);
void configScaling(double min, double max, double step, double init, bool logarithmic = true);
void configScrolling(double xmin, double xmax, double xinit, double ymin, double ymax, double yinit);
float xoffset;
float yoffset;
float scaling;
double xoffset;
double yoffset;
double scaling;
private:
void updateScaling();
@ -61,21 +61,21 @@ private:
int mousex;
int mousey;
float scalingbase;
double scalingbase;
bool alive;
float conf_scroll_xmin;
float conf_scroll_xmax;
float conf_scroll_xinit;
float conf_scroll_ymin;
float conf_scroll_ymax;
float conf_scroll_yinit;
double conf_scroll_xmin;
double conf_scroll_xmax;
double conf_scroll_xinit;
double conf_scroll_ymin;
double conf_scroll_ymax;
double conf_scroll_yinit;
float conf_scale_min;
float conf_scale_max;
float conf_scale_init;
float conf_scale_step;
double conf_scale_min;
double conf_scale_max;
double conf_scale_init;
double conf_scale_step;
bool conf_scroll_logarithmic;
signals:

View file

@ -15,7 +15,7 @@
#include "widgetcurveeditor.h"
/**************** Dialog ****************/
DialogCurve::DialogCurve(QWidget *parent, Curve* curve, float xmin, float xmax, float ymin, float ymax) : QDialog(parent)
DialogCurve::DialogCurve(QWidget *parent, Curve* curve, double xmin, double xmax, double ymin, double ymax) : QDialog(parent)
{
QWidget* buttons;
QWidget* form;
@ -70,7 +70,7 @@ DialogCurve::~DialogCurve()
curveDelete(_current);
}
bool DialogCurve::getCurve(QWidget* parent, Curve* curve, float xmin, float xmax, float ymin, float ymax)
bool DialogCurve::getCurve(QWidget* parent, Curve* curve, double xmin, double xmax, double ymin, double ymax)
{
int result;

View file

@ -11,10 +11,10 @@ class DialogCurve : public QDialog
{
Q_OBJECT
public:
explicit DialogCurve(QWidget* parent, Curve* curve, float xmin, float xmax, float ymin, float ymax);
explicit DialogCurve(QWidget* parent, Curve* curve, double xmin, double xmax, double ymin, double ymax);
~DialogCurve();
static bool getCurve(QWidget* parent, Curve* curve, float xmin, float xmax, float ymin, float ymax);
static bool getCurve(QWidget* parent, Curve* curve, double xmin, double xmax, double ymin, double ymax);
public slots:
virtual void accept();

View file

@ -32,7 +32,7 @@ protected:
{
noiseCopy(_noise_original, _noise_preview);
}
QColor getColor(float x, float y)
QColor getColor(double x, double y)
{
if ((_level >= 0) && (y > noiseGet1DLevel(_noise_preview, _level, x)))
{
@ -64,7 +64,7 @@ protected:
{
noiseCopy(_noise_original, _noise_preview);
}
QColor getColor(float x, float y)
QColor getColor(double x, double y)
{
if (y > noiseGet1DTotal(_noise_preview, x))
{
@ -295,7 +295,7 @@ void DialogNoise::levelChanged(int row)
void DialogNoise::heightChanged(int value)
{
_current_level_params.height = ((float)value) / 1000.0;
_current_level_params.height = ((double)value) / 1000.0;
noiseSetLevel(_current, _current_level, _current_level_params);
previewLevel->redraw();
previewTotal->redraw();
@ -303,7 +303,7 @@ void DialogNoise::heightChanged(int value)
void DialogNoise::scalingChanged(int value)
{
_current_level_params.scaling = ((float)value) / 1000.0;
_current_level_params.scaling = ((double)value) / 1000.0;
noiseSetLevel(_current, _current_level, _current_level_params);
previewLevel->redraw();
previewTotal->redraw();

View file

@ -26,7 +26,7 @@ static void _renderDraw(int x, int y, Color col)
_current_dialog->pixbuf->setPixel(x, _current_dialog->pixbuf->height() - 1 - y, colorToQColor(col).rgb());
}
static void _renderUpdate(float progress)
static void _renderUpdate(double progress)
{
_current_dialog->area->update();
_current_dialog->tellProgressChange(progress);
@ -98,7 +98,7 @@ DialogRender::DialogRender(QWidget *parent, Renderer* renderer):
_info->layout()->addWidget(_progress);
connect(this, SIGNAL(renderSizeChanged(int, int)), this, SLOT(applyRenderSize(int, int)));
connect(this, SIGNAL(progressChanged(float)), this, SLOT(applyProgress(float)));
connect(this, SIGNAL(progressChanged(double)), this, SLOT(applyProgress(double)));
}
DialogRender::~DialogRender()
@ -118,7 +118,7 @@ void DialogRender::tellRenderSize(int width, int height)
emit renderSizeChanged(width, height);
}
void DialogRender::tellProgressChange(float value)
void DialogRender::tellProgressChange(double value)
{
emit progressChanged(value);
}
@ -153,7 +153,7 @@ void DialogRender::applyRenderSize(int width, int height)
_scroll->setMinimumSize(width > 800 ? 820 : width + 20, height > 600 ? 620 : height + 20);
}
void DialogRender::applyProgress(float value)
void DialogRender::applyProgress(double value)
{
double diff = difftime(time(NULL), _started);
int hours = (int)floor(diff / 3600.0);

View file

@ -17,7 +17,7 @@ public:
~DialogRender();
void tellRenderSize(int width, int height);
void tellProgressChange(float value);
void tellProgressChange(double value);
void startRender(RenderParams params);
void loadLastRender();
@ -26,11 +26,11 @@ public:
private slots:
void applyRenderSize(int width, int height);
void applyProgress(float value);
void applyProgress(double value);
signals:
void renderSizeChanged(int width, int height);
void progressChanged(float value);
void progressChanged(double value);
private:
QScrollArea* _scroll;

View file

@ -4,7 +4,7 @@
#include "baseexplorerchunk.h"
#include "../lib_paysages/camera.h"
ExplorerChunkSky::ExplorerChunkSky(Renderer* renderer, SkyDefinition* sky, float size, SkyboxOrientation orientation) : BaseExplorerChunk(renderer)
ExplorerChunkSky::ExplorerChunkSky(Renderer* renderer, SkyDefinition* sky, double size, SkyboxOrientation orientation) : BaseExplorerChunk(renderer)
{
_sky = sky;
_box_size = size;
@ -16,7 +16,7 @@ ExplorerChunkSky::ExplorerChunkSky(Renderer* renderer, SkyDefinition* sky, float
void ExplorerChunkSky::onRenderEvent(QGLWidget* widget)
{
float size = _box_size;
double size = _box_size;
Vector3 camera = renderer()->camera_location;
glBegin(GL_QUADS);
@ -86,12 +86,12 @@ void ExplorerChunkSky::onRenderEvent(QGLWidget* widget)
glEnd();
}
float ExplorerChunkSky::getDisplayedSizeHint(CameraDefinition* camera)
double ExplorerChunkSky::getDisplayedSizeHint(CameraDefinition* camera)
{
return 1000.0;
}
Color ExplorerChunkSky::getTextureColor(float x, float y)
Color ExplorerChunkSky::getTextureColor(double x, double y)
{
Vector3 location;

View file

@ -19,16 +19,16 @@ enum SkyboxOrientation
class ExplorerChunkSky:public BaseExplorerChunk
{
public:
ExplorerChunkSky(Renderer* renderer, SkyDefinition* sky, float size, SkyboxOrientation orientation);
ExplorerChunkSky(Renderer* renderer, SkyDefinition* sky, double size, SkyboxOrientation orientation);
void onRenderEvent(QGLWidget* widget);
float getDisplayedSizeHint(CameraDefinition* camera);
Color getTextureColor(float x, float y);
double getDisplayedSizeHint(CameraDefinition* camera);
Color getTextureColor(double x, double y);
private:
SkyDefinition* _sky;
SkyboxOrientation _orientation;
float _box_size;
double _box_size;
};

View file

@ -4,17 +4,17 @@
#include "baseexplorerchunk.h"
#include "../lib_paysages/camera.h"
ExplorerChunkTerrain::ExplorerChunkTerrain(Renderer* renderer, float x, float z, float size, int nbchunks) : BaseExplorerChunk(renderer)
ExplorerChunkTerrain::ExplorerChunkTerrain(Renderer* renderer, double x, double z, double size, int nbchunks) : BaseExplorerChunk(renderer)
{
_startx = x;
_startz = z;
_size = size;
_overall_step = size * (float)nbchunks;
_overall_step = size * (double)nbchunks;
_tessellation_max_size = 32;
_tessellation = new float[(_tessellation_max_size + 1) * (_tessellation_max_size + 1)];
_tessellation = new double[(_tessellation_max_size + 1) * (_tessellation_max_size + 1)];
_tessellation_current_size = 0;
_tessellation_step = _size / (float)_tessellation_max_size;
_tessellation_step = _size / (double)_tessellation_max_size;
setMaxTextureSize(128);
@ -49,7 +49,7 @@ bool ExplorerChunkTerrain::onMaintainEvent()
{
if (_tessellation_current_size == 0 || i % old_tessellation_inc != 0 || j % old_tessellation_inc != 0)
{
float height = renderer->getTerrainHeight(renderer, _startx + _tessellation_step * (float)i, _startz + _tessellation_step * (float)j);
double height = renderer->getTerrainHeight(renderer, _startx + _tessellation_step * (double)i, _startz + _tessellation_step * (double)j);
_tessellation[j * (_tessellation_max_size + 1) + i] = height;
}
}
@ -98,7 +98,7 @@ void ExplorerChunkTerrain::onRenderEvent(QGLWidget* widget)
{
_lock_data.lock();
int tessellation_size = _tessellation_current_size;
float tsize = 1.0 / (float)_tessellation_max_size;
double tsize = 1.0 / (double)_tessellation_max_size;
_lock_data.unlock();
if (tessellation_size <= 1)
@ -106,24 +106,24 @@ void ExplorerChunkTerrain::onRenderEvent(QGLWidget* widget)
return;
}
int tessellation_inc = _tessellation_max_size / (float)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 * (float)i, tsize * (float)j);
glVertex3d(_startx + _tessellation_step * (float)i, _tessellation[j * (_tessellation_max_size + 1) + i], _startz + _tessellation_step * (float)j);
glTexCoord2d(tsize * (float)i, tsize * (float)(j + tessellation_inc));
glVertex3d(_startx + _tessellation_step * (float)i, _tessellation[(j + tessellation_inc) * (_tessellation_max_size + 1) + i], _startz + _tessellation_step * (float)(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();
}
}
float ExplorerChunkTerrain::getDisplayedSizeHint(CameraDefinition* camera)
double ExplorerChunkTerrain::getDisplayedSizeHint(CameraDefinition* camera)
{
float distance;
double distance;
Vector3 center;
center = getCenter();
@ -140,7 +140,7 @@ float ExplorerChunkTerrain::getDisplayedSizeHint(CameraDefinition* camera)
}
}
Color ExplorerChunkTerrain::getTextureColor(float x, float y)
Color ExplorerChunkTerrain::getTextureColor(double x, double y)
{
Vector3 location = {_startx + x * _size, 0.0, _startz + y * _size};
return renderer()->applyTextures(renderer(), location, 0.01);

View file

@ -8,28 +8,28 @@
class ExplorerChunkTerrain:public BaseExplorerChunk
{
public:
ExplorerChunkTerrain(Renderer* renderer, float x, float z, float size, int nbchunks);
ExplorerChunkTerrain(Renderer* renderer, double x, double z, double size, int nbchunks);
~ExplorerChunkTerrain();
void onCameraEvent(CameraDefinition* camera);
void onResetEvent();
bool onMaintainEvent();
void onRenderEvent(QGLWidget* widget);
float getDisplayedSizeHint(CameraDefinition* camera);
Color getTextureColor(float x, float y);
double getDisplayedSizeHint(CameraDefinition* camera);
Color getTextureColor(double x, double y);
private:
Vector3 getCenter();
float _startx;
float _startz;
float _size;
float _overall_step;
double _startx;
double _startz;
double _size;
double _overall_step;
float* _tessellation;
double* _tessellation;
int _tessellation_max_size;
int _tessellation_current_size;
float _tessellation_step;
double _tessellation_step;
};

View file

@ -21,7 +21,7 @@ public:
configScaling(100.0, 1000.0, 20.0, 200.0);
}
protected:
QColor getColor(float x, float y)
QColor getColor(double x, double y)
{
Vector3 eye, look, location;

View file

@ -25,7 +25,7 @@ public:
configScaling(100.0, 1000.0, 20.0, 200.0);
}
protected:
QColor getColor(float x, float y)
QColor getColor(double x, double y)
{
Vector3 eye, look;
Color color_layer, result;
@ -89,7 +89,7 @@ public:
configScaling(1.0, 4.0, 0.2, 2.0);
}
protected:
QColor getColor(float x, float y)
QColor getColor(double x, double y)
{
Vector3 start, end;
Color color_layer, result;
@ -120,9 +120,9 @@ private:
CloudsLayerDefinition _preview_layer;
LightingDefinition _lighting;
static float _coverageFunc(CloudsLayerDefinition* layer, Vector3 position)
static double _coverageFunc(CloudsLayerDefinition* layer, Vector3 position)
{
float dist = v3Norm(position);
double dist = v3Norm(position);
if (dist >= layer->ymax)
{

View file

@ -37,11 +37,11 @@ public:
configScrolling(-1000.0, 1000.0, 0.0, -1000.0, 1000.0, 0.0);
}
protected:
QColor getColor(float x, float y)
QColor getColor(double x, double y)
{
Vector3 down = {0.0, -1.0, 0.0};
Vector3 location;
float height = terrainGetHeight(&_terrain, x, y);
double height = terrainGetHeight(&_terrain, x, y);
if (height < _water.height)
{
@ -69,12 +69,12 @@ private:
TexturesDefinition _textures;
LightingDefinition _lighting;
static float _getTerrainHeight(Renderer* renderer, float x, float z)
static double _getTerrainHeight(Renderer* renderer, double x, double z)
{
return terrainGetHeight((TerrainDefinition*)(renderer->customData[0]), x, z);
}
static Color _applyTextures(Renderer* renderer, Vector3 location, float precision)
static Color _applyTextures(Renderer* renderer, Vector3 location, double precision)
{
return texturesGetColor((TexturesDefinition*)(renderer->customData[1]), renderer, location.x, location.z, precision);
}

View file

@ -25,7 +25,7 @@ public:
configScaling(0.5, 5.0, 0.5, 2.5);
}
protected:
QColor getColor(float x, float y)
QColor getColor(double x, double y)
{
y -= 100.0 * scaling;
if (y > 0.0)
@ -65,7 +65,7 @@ public:
configScaling(0.5, 5.0, 0.5, 2.5);
}
protected:
QColor getColor(float x, float y)
QColor getColor(double x, double y)
{
y -= 100.0 * scaling;
if (y > 0.0)

View file

@ -23,9 +23,9 @@ public:
configScrolling(-1000.0, 1000.0, 0.0, -1000.0, 1000.0, 0.0);
}
protected:
QColor getColor(float x, float y)
QColor getColor(double x, double y)
{
float height;
double height;
height = terrainGetHeightNormalized(&_preview_definition, x, y);
return QColor((int)(255.0 * height), (int)(255.0 * height), (int)(255.0 * height));
@ -100,7 +100,7 @@ public:
configScrolling(-1000.0, 1000.0, 0.0, -1000.0, 1000.0, 0.0);
}
protected:
QColor getColor(float x, float y)
QColor getColor(double x, double y)
{
return colorToQColor(terrainGetColor(&_terrain, &_renderer, x, y, scaling));
}
@ -115,12 +115,12 @@ private:
TexturesDefinition _textures;
LightingDefinition _lighting;
static float _getTerrainHeight(Renderer* renderer, float x, float z)
static double _getTerrainHeight(Renderer* renderer, double x, double z)
{
return terrainGetHeight((TerrainDefinition*)(renderer->customData[0]), x, z);
}
static Color _applyTextures(Renderer* renderer, Vector3 location, float precision)
static Color _applyTextures(Renderer* renderer, Vector3 location, double precision)
{
return texturesGetColor((TexturesDefinition*)(renderer->customData[1]), renderer, location.x, location.z, precision);
}

View file

@ -9,14 +9,14 @@ static TextureLayerDefinition _layer;
typedef struct
{
float height_soft_min;
float height_hard_min;
float height_hard_max;
float height_soft_max;
float slope_soft_min;
float slope_hard_min;
float slope_hard_max;
float slope_soft_max;
double height_soft_min;
double height_hard_min;
double height_hard_max;
double height_soft_max;
double slope_soft_min;
double slope_hard_min;
double slope_hard_max;
double slope_soft_max;
} TextureSupp;
static TextureSupp _supp;
@ -39,10 +39,10 @@ public:
configScrolling(-1000.0, 1000.0, 0.0, -1000.0, 1000.0, 0.0);
}
protected:
QColor getColor(float x, float y)
QColor getColor(double x, double y)
{
Vector3 location;
float coverage;
double coverage;
location.x = x;
location.y = terrainGetHeight(&_terrain, x, y);
location.z = y;
@ -56,7 +56,7 @@ protected:
}
private:
static float _getTerrainHeight(Renderer* renderer, float x, float z)
static double _getTerrainHeight(Renderer* renderer, double x, double z)
{
return terrainGetHeight((TerrainDefinition*)(renderer->customData[0]), x, z);
}
@ -101,7 +101,7 @@ public:
configScrolling(-1000.0, 1000.0, 0.0, -1000.0, 1000.0, 0.0);
}
protected:
QColor getColor(float x, float y)
QColor getColor(double x, double y)
{
Vector3 location;
location.x = x;

View file

@ -28,9 +28,9 @@ public:
configScrolling(-1000.0, 1000.0, 0.0, -1000.0, 1000.0, 0.0);
}
protected:
QColor getColor(float x, float y)
QColor getColor(double x, double y)
{
float height;
double height;
height = terrainGetHeight(&_terrain, x, y);
if (height > _definition.height)
@ -84,7 +84,7 @@ public:
//configScrolling(-30.0, 30.0, 0.0, -20.0, 20.0, 0.0);
}
protected:
QColor getColor(float x, float y)
QColor getColor(double x, double y)
{
Vector3 eye, look, location;
@ -126,7 +126,7 @@ private:
static RayCastingResult _rayWalking(Renderer* renderer, Vector3 location, Vector3 direction, int terrain, int water, int sky, int clouds)
{
RayCastingResult result;
float x, y;
double x, y;
result.hit = 1;
if (direction.z < 0.0001)

View file

@ -8,7 +8,7 @@
class CurveSmallPreview:public QWidget
{
public:
CurveSmallPreview(QWidget* parent, Curve* curve, float xmin, float xmax, float ymin, float ymax) : QWidget(parent)
CurveSmallPreview(QWidget* parent, Curve* curve, double xmin, double xmax, double ymin, double ymax) : QWidget(parent)
{
_curve = curve;
_xmin = xmin;
@ -27,29 +27,29 @@ public:
QPainter painter(this);
int width = this->width();
int height = this->height();
float position, value, prev_value, next_value;
double position, value, prev_value, next_value;
painter.fillRect(rect(), QColor(255, 255, 255));
for (int x = 0; x < width; x++)
{
painter.setPen(QColor(0, 0, 0));
position = _xmin + (_xmax - _xmin) * (float)x / (float)(width - 1);
position = _xmin + (_xmax - _xmin) * (double)x / (double)(width - 1);
value = (curveGetValue(_curve, position) - _ymin) * (_ymax - _ymin);
prev_value = curveGetValue(_curve, position - 1.0 / (float)(width - 1));
next_value = curveGetValue(_curve, position + 1.0 / (float)(width - 1));
prev_value = curveGetValue(_curve, position - 1.0 / (double)(width - 1));
next_value = curveGetValue(_curve, position + 1.0 / (double)(width - 1));
painter.drawLine(x, height - 1 - (int)((value + (prev_value - value) / 2.0) * (float)(height - 1)), x, height - 1 - (int)((value + (next_value - value) / 2.0) * (float)(height - 1)));
painter.drawPoint(x, height - 1 - (int)(value * (float)(height - 1)));
painter.drawLine(x, height - 1 - (int)((value + (prev_value - value) / 2.0) * (double)(height - 1)), x, height - 1 - (int)((value + (next_value - value) / 2.0) * (double)(height - 1)));
painter.drawPoint(x, height - 1 - (int)(value * (double)(height - 1)));
}
}
Curve* _curve;
float _xmin;
float _xmax;
float _ymin;
float _ymax;
double _xmin;
double _xmax;
double _ymin;
double _ymax;
};
InputCurve::InputCurve(QWidget* form, QString label, Curve* value, float xmin, float xmax, float ymin, float ymax) : BaseInput(form, label)
InputCurve::InputCurve(QWidget* form, QString label, Curve* value, double xmin, double xmax, double ymin, double ymax) : BaseInput(form, label)
{
_value = value;
_xmin = xmin;

View file

@ -11,7 +11,7 @@ class InputCurve:public BaseInput
Q_OBJECT
public:
InputCurve(QWidget* form, QString label, Curve* value, float xmin, float xmax, float ymin, float ymax);
InputCurve(QWidget* form, QString label, Curve* value, double xmin, double xmax, double ymin, double ymax);
public slots:
virtual void updatePreview();
@ -23,10 +23,10 @@ private slots:
private:
Curve* _value;
float _xmin;
float _xmax;
float _ymin;
float _ymax;
double _xmin;
double _xmax;
double _ymin;
double _ymax;
};
#endif

View file

@ -3,7 +3,7 @@
#include <QLabel>
#include "math.h"
InputDouble::InputDouble(QWidget* form, QString label, float* value, float min, float max, float small_step, float large_step):
InputDouble::InputDouble(QWidget* form, QString label, double* value, double min, double max, double small_step, double large_step):
BaseInput(form, label),
value(value), min(min), max(max), small_step(small_step), large_step(large_step)
{
@ -43,7 +43,7 @@ void InputDouble::applyValue()
}
else
{
*value = min + ((float)ivalue) * small_step;
*value = min + ((double)ivalue) * small_step;
}
if (fabs(*value) < 0.0000001)
{

View file

@ -10,7 +10,7 @@ class InputDouble:public BaseInput
Q_OBJECT
public:
InputDouble(QWidget* form, QString label, float* value, float min, float max, float small_step, float large_step);
InputDouble(QWidget* form, QString label, double* value, double min, double max, double small_step, double large_step);
public slots:
virtual void updatePreview();
@ -19,11 +19,11 @@ public slots:
private:
QSlider* slider;
float* value;
float min;
float max;
float small_step;
float large_step;
double* value;
double min;
double max;
double small_step;
double large_step;
};
#endif // _PAYSAGES_QT_INPUTDOUBLE_H_

View file

@ -26,12 +26,12 @@ public:
QPainter painter(this);
int width = this->width();
int height = this->height();
float value, factor;
double value, factor;
for (int x = 0; x < width; x++)
{
factor = ((float)(height / 2)) / noiseGetMaxValue(noise);
value = noiseGet1DTotal(noise, ((float)x) / factor) * factor;
factor = ((double)(height / 2)) / noiseGetMaxValue(noise);
value = noiseGet1DTotal(noise, ((double)x) / factor) * factor;
painter.setPen(QColor(255, 255, 255));
painter.drawLine(x, 0, x, height / 2 + value);
painter.setPen(QColor(0, 0, 0));

View file

@ -49,16 +49,16 @@ void PreviewColorGradation::paintEvent(QPaintEvent* event)
switch (band)
{
case COLORGRADATIONBAND_RED:
painter.setPen(QColor::fromRgbF(curveGetValue(curve, (float)x / (float)width), 0.0, 0.0));
painter.setPen(QColor::fromRgbF(curveGetValue(curve, (double)x / (double)width), 0.0, 0.0));
break;
case COLORGRADATIONBAND_GREEN:
painter.setPen(QColor::fromRgbF(0.0, curveGetValue(curve, (float)x / (float)width), 0.0));
painter.setPen(QColor::fromRgbF(0.0, curveGetValue(curve, (double)x / (double)width), 0.0));
break;
case COLORGRADATIONBAND_BLUE:
painter.setPen(QColor::fromRgbF(0.0, 0.0, curveGetValue(curve, (float)x / (float)width)));
painter.setPen(QColor::fromRgbF(0.0, 0.0, curveGetValue(curve, (double)x / (double)width)));
break;
case COLORGRADATIONBAND_FINAL:
painter.setPen(colorToQColor(colorGradationGet(gradation, (float)x / (float)width)));
painter.setPen(colorToQColor(colorGradationGet(gradation, (double)x / (double)width)));
break;
}
painter.drawLine(x, 0, x, height - 1);

View file

@ -39,9 +39,9 @@ SmallMaterialPreview::~SmallMaterialPreview()
rendererDelete(&_renderer);
}
QColor SmallMaterialPreview::getColor(float x, float y)
QColor SmallMaterialPreview::getColor(double x, double y)
{
float dist = sqrt(x * x + y * y);
double dist = sqrt(x * x + y * y);
Vector3 point;
Color color;
@ -77,24 +77,24 @@ void SmallMaterialPreview::paintEvent(QPaintEvent* event)
QPainter painter(this);
int width = this->width();
int height = this->height();
float factor, dx, dy;
double factor, dx, dy;
if (width > height)
{
factor = 2.0 / (float)height;
factor = 2.0 / (double)height;
}
else
{
factor = 2.0 / (float)width;
factor = 2.0 / (double)width;
}
dx = factor * (float)width / 2.0;
dy = factor * (float)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(getColor((float)x * factor - dx, (float)y * factor - dy));
painter.setPen(getColor((double)x * factor - dx, (double)y * factor - dy));
painter.drawPoint(x, y);
}
}
@ -115,7 +115,7 @@ PreviewMaterial::~PreviewMaterial()
delete _small;
}
QColor PreviewMaterial::getColor(float x, float y)
QColor PreviewMaterial::getColor(double x, double y)
{
return _small->getColor(x, y);
}

View file

@ -12,7 +12,7 @@ public:
SmallMaterialPreview(QWidget* parent, SurfaceMaterial* material);
~SmallMaterialPreview();
QColor getColor(float x, float y);
QColor getColor(double x, double y);
protected:
virtual void paintEvent(QPaintEvent* event);
@ -32,7 +32,7 @@ public:
~PreviewMaterial();
protected:
virtual QColor getColor(float x, float y);
virtual QColor getColor(double x, double y);
private:
SmallMaterialPreview* _small;

View file

@ -4,7 +4,7 @@
#include <QMouseEvent>
#include "../lib_paysages/tools.h"
WidgetCurveEditor::WidgetCurveEditor(QWidget *parent, float xmin, float xmax, float ymin, float ymax) : QWidget(parent)
WidgetCurveEditor::WidgetCurveEditor(QWidget *parent, double xmin, double xmax, double ymin, double ymax) : QWidget(parent)
{
_curve = curveCreate();
_dragged = -1;
@ -39,14 +39,14 @@ void WidgetCurveEditor::paintEvent(QPaintEvent* event)
{
int i, n;
int width, height;
float dwidth, dheight;
double dwidth, dheight;
CurvePoint point;
float position, value, prev_value, next_value;
double position, value, prev_value, next_value;
width = this->width();
height = this->height();
dheight = (float)(height - 1);
dwidth = (float)(width - 1);
dheight = (double)(height - 1);
dwidth = (double)(width - 1);
QPainter painter(this);
painter.fillRect(0, 0, width, height, QColor(255, 255, 255));
@ -54,7 +54,7 @@ void WidgetCurveEditor::paintEvent(QPaintEvent* event)
for (int x = 0; x < width; x++)
{
position = ((float)x) / dwidth;
position = ((double)x) / dwidth;
value = curveGetValue(_curve, position);
prev_value = curveGetValue(_curve, position - 1.0 / dwidth);
@ -88,8 +88,8 @@ void WidgetCurveEditor::mouseMoveEvent(QMouseEvent* event)
if (_dragged >= 0 && (event->buttons() & Qt::LeftButton))
{
point.position = ((float)event->x()) / (float)(width() - 1);
point.value = 1.0 - ((float)event->y()) / (float)(height() - 1);
point.position = ((double)event->x()) / (double)(width() - 1);
point.value = 1.0 - ((double)event->y()) / (double)(height() - 1);
point.position = (point.position < 0.0) ? 0.0 : point.position;
point.position = (point.position > 1.0) ? 1.0 : point.position;
@ -138,8 +138,8 @@ void WidgetCurveEditor::mouseDoubleClickEvent(QMouseEvent* event)
{
if (getPointAt(event->x(), event->y()) < 0)
{
point.position = ((float)event->x()) / (float)(width() - 1);
point.value = 1.0 - ((float)event->y()) / (float)(height() - 1);
point.position = ((double)event->x()) / (double)(width() - 1);
point.value = 1.0 - ((double)event->y()) / (double)(height() - 1);
curveAddPoint(_curve, &point);
curveValidate(_curve);
@ -153,10 +153,10 @@ int WidgetCurveEditor::getPointAt(int x, int y)
{
int n;
int nearest;
float distance, ndistance;
double distance, ndistance;
CurvePoint point;
float dx = ((float)x) / (float)(width() - 1);
float dy = 1.0 - ((float)y) / (float)(height() - 1);
double dx = ((double)x) / (double)(width() - 1);
double dy = 1.0 - ((double)y) / (double)(height() - 1);
n = curveGetPointCount(_curve);
if (n < 1)

View file

@ -10,7 +10,7 @@ class WidgetCurveEditor : public QWidget
Q_OBJECT
public:
WidgetCurveEditor(QWidget* parent, float xmin, float xmax, float ymin, float ymax);
WidgetCurveEditor(QWidget* parent, double xmin, double xmax, double ymin, double ymax);
~WidgetCurveEditor();
void setCurve(Curve* curve);

View file

@ -48,12 +48,12 @@ private:
static QVector<ChunkMaintenanceThread*> _threads;
static float _getTerrainHeight(Renderer* renderer, float x, float z)
static double _getTerrainHeight(Renderer* renderer, double x, double z)
{
return terrainGetHeight((TerrainDefinition*)(renderer->customData[0]), x, z);
}
static Color _applyTextures(Renderer* renderer, Vector3 location, float precision)
static Color _applyTextures(Renderer* renderer, Vector3 location, double precision)
{
return texturesGetColor((TexturesDefinition*)(renderer->customData[1]), renderer, location.x, location.z, precision);
}
@ -103,14 +103,14 @@ WidgetExplorer::WidgetExplorer(QWidget *parent, CameraDefinition* camera):
// Add terrain
int chunks = 20;
float size = 200.0;
float chunksize = size / (float)chunks;
float start = -size / 2.0;
double size = 200.0;
double chunksize = size / (double)chunks;
double start = -size / 2.0;
for (int i = 0; i < chunks; i++)
{
for (int j = 0; j < chunks; j++)
{
ExplorerChunkTerrain* chunk = new ExplorerChunkTerrain(&_renderer, start + chunksize * (float)i, start + chunksize * (float)j, chunksize, chunks);
ExplorerChunkTerrain* chunk = new ExplorerChunkTerrain(&_renderer, start + chunksize * (double)i, start + chunksize * (double)j, chunksize, chunks);
_chunks.append(chunk);
_updateQueue.append(chunk);
}
@ -228,7 +228,7 @@ void WidgetExplorer::validateCamera()
void WidgetExplorer::keyPressEvent(QKeyEvent* event)
{
float factor;
double factor;
if (event->modifiers() & Qt::ControlModifier)
{
@ -290,7 +290,7 @@ void WidgetExplorer::mousePressEvent(QMouseEvent* event)
void WidgetExplorer::mouseMoveEvent(QMouseEvent* event)
{
float factor;
double factor;
if (event->modifiers() & Qt::ControlModifier)
{
@ -308,15 +308,15 @@ void WidgetExplorer::mouseMoveEvent(QMouseEvent* event)
if (event->buttons() & Qt::LeftButton)
{
cameraRotateYaw(&_current_camera, (float)(event->x() - _last_mouse_x) * factor * 0.1);
cameraRotatePitch(&_current_camera, (float)(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, (float)(_last_mouse_x - event->x()) * factor);
cameraStrafeUp(&_current_camera, (float)(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 +331,7 @@ void WidgetExplorer::mouseMoveEvent(QMouseEvent* event)
void WidgetExplorer::wheelEvent(QWheelEvent* event)
{
float factor;
double factor;
if (event->modifiers() & Qt::ControlModifier)
{
@ -349,7 +349,7 @@ void WidgetExplorer::wheelEvent(QWheelEvent* event)
if (event->orientation() == Qt::Vertical)
{
cameraStrafeForward(&_current_camera, (float)event->delta() * factor);
cameraStrafeForward(&_current_camera, (double)event->delta() * factor);
updateGL();
}
@ -413,7 +413,7 @@ void WidgetExplorer::paintGL()
{
GLenum error_code;
QTime start_time;
float frame_time;
double frame_time;
if (_current_camera.location.y > 30.0)
{
@ -452,7 +452,7 @@ void WidgetExplorer::paintGL()
_chunks[i]->render(this);
}
frame_time = 0.001 * (float)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);

View file

@ -56,7 +56,7 @@ private:
TexturesDefinition _textures;
LightingDefinition _lighting;
float _average_frame_time;
double _average_frame_time;
int _quality;
int _last_mouse_x;

View file

@ -15,18 +15,18 @@ void atmosphereQuit()
void atmosphereSave(PackStream* stream, AtmosphereDefinition* definition)
{
packWriteFloat(stream, &definition->distance_near);
packWriteFloat(stream, &definition->distance_far);
packWriteFloat(stream, &definition->full_mask);
packWriteDouble(stream, &definition->distance_near);
packWriteDouble(stream, &definition->distance_far);
packWriteDouble(stream, &definition->full_mask);
packWriteInt(stream, &definition->auto_lock_on_haze);
colorSave(stream, &definition->color);
}
void atmosphereLoad(PackStream* stream, AtmosphereDefinition* definition)
{
packReadFloat(stream, &definition->distance_near);
packReadFloat(stream, &definition->distance_far);
packReadFloat(stream, &definition->full_mask);
packReadDouble(stream, &definition->distance_near);
packReadDouble(stream, &definition->distance_far);
packReadDouble(stream, &definition->full_mask);
packReadInt(stream, &definition->auto_lock_on_haze);
colorLoad(stream, &definition->color);
@ -85,8 +85,8 @@ void atmosphereValidateDefinition(AtmosphereDefinition* definition)
Color atmosphereApply(AtmosphereDefinition* definition, Renderer* renderer, Vector3 location, Color base)
{
Color mask = definition->color;
float distance = v3Norm(v3Sub(renderer->camera_location, location));
float value;
double distance = v3Norm(v3Sub(renderer->camera_location, location));
double value;
if (distance < definition->distance_near)
{

View file

@ -12,9 +12,9 @@ extern "C" {
typedef struct
{
float distance_near;
float distance_far;
float full_mask;
double distance_near;
double distance_far;
double full_mask;
int auto_lock_on_haze;
Color color;
} AtmosphereDefinition;

View file

@ -20,10 +20,10 @@
void autoSetDaytime(int hour, int minute)
{
autoSetDaytimeFraction((float)hour / 24.0 + (float)minute / 1440.0);
autoSetDaytimeFraction((double)hour / 24.0 + (double)minute / 1440.0);
}
void autoSetDaytimeFraction(float daytime)
void autoSetDaytimeFraction(double daytime)
{
SkyDefinition sky;
/*ColorGradation grad_sun;

View file

@ -8,7 +8,7 @@ extern "C" {
#endif
void autoSetDaytime(int hour, int minute);
void autoSetDaytimeFraction(float daytime);
void autoSetDaytimeFraction(double daytime);
void autoGenRealisticLandscape(int seed);
#ifdef __cplusplus

View file

@ -20,17 +20,17 @@ void cameraQuit()
void cameraSave(PackStream* stream, CameraDefinition* camera)
{
v3Save(stream, &camera->location);
packWriteFloat(stream, &camera->yaw);
packWriteFloat(stream, &camera->pitch);
packWriteFloat(stream, &camera->roll);
packWriteDouble(stream, &camera->yaw);
packWriteDouble(stream, &camera->pitch);
packWriteDouble(stream, &camera->roll);
}
void cameraLoad(PackStream* stream, CameraDefinition* camera)
{
v3Load(stream, &camera->location);
packReadFloat(stream, &camera->yaw);
packReadFloat(stream, &camera->pitch);
packReadFloat(stream, &camera->roll);
packReadDouble(stream, &camera->yaw);
packReadDouble(stream, &camera->pitch);
packReadDouble(stream, &camera->roll);
cameraValidateDefinition(camera, 0);
}
@ -73,7 +73,7 @@ void cameraValidateDefinition(CameraDefinition* definition, int check_above)
{
WaterDefinition water;
TerrainDefinition terrain;
float water_height, terrain_height, diff;
double water_height, terrain_height, diff;
Vector3 move;
Matrix4 rotation;
@ -128,7 +128,7 @@ void cameraValidateDefinition(CameraDefinition* definition, int check_above)
definition->unproject = m4Inverse(definition->project);
}
void cameraSetLocation(CameraDefinition* camera, float x, float y, float z)
void cameraSetLocation(CameraDefinition* camera, double x, double y, double z)
{
camera->location.x = x;
camera->location.y = y;
@ -137,7 +137,7 @@ void cameraSetLocation(CameraDefinition* camera, float x, float y, float z)
cameraValidateDefinition(camera, 0);
}
void cameraSetTarget(CameraDefinition* camera, float x, float y, float z)
void cameraSetTarget(CameraDefinition* camera, double x, double y, double z)
{
Vector3 forward, target;
@ -172,49 +172,49 @@ void cameraSetTarget(CameraDefinition* camera, float x, float y, float z)
cameraValidateDefinition(camera, 0);
}
void cameraSetRoll(CameraDefinition* camera, float angle)
void cameraSetRoll(CameraDefinition* camera, double angle)
{
camera->roll = angle;
cameraValidateDefinition(camera, 0);
}
void cameraStrafeForward(CameraDefinition* camera, float value)
void cameraStrafeForward(CameraDefinition* camera, double value)
{
camera->location = v3Add(camera->location, v3Scale(camera->forward, value));
cameraValidateDefinition(camera, 0);
}
void cameraStrafeRight(CameraDefinition* camera, float value)
void cameraStrafeRight(CameraDefinition* camera, double value)
{
camera->location = v3Add(camera->location, v3Scale(camera->right, value));
cameraValidateDefinition(camera, 0);
}
void cameraStrafeUp(CameraDefinition* camera, float value)
void cameraStrafeUp(CameraDefinition* camera, double value)
{
camera->location = v3Add(camera->location, v3Scale(camera->up, value));
cameraValidateDefinition(camera, 0);
}
void cameraRotateYaw(CameraDefinition* camera, float value)
void cameraRotateYaw(CameraDefinition* camera, double value)
{
camera->yaw += value;
cameraValidateDefinition(camera, 0);
}
void cameraRotatePitch(CameraDefinition* camera, float value)
void cameraRotatePitch(CameraDefinition* camera, double value)
{
camera->pitch += value;
cameraValidateDefinition(camera, 0);
}
void cameraRotateRoll(CameraDefinition* camera, float value)
void cameraRotateRoll(CameraDefinition* camera, double value)
{
camera->roll += value;
@ -223,8 +223,8 @@ void cameraRotateRoll(CameraDefinition* camera, float value)
void cameraSetRenderSize(CameraDefinition* camera, int width, int height)
{
camera->width = (float)width;
camera->height = (float)height;
camera->width = (double)width;
camera->height = (double)height;
camera->xratio = camera->width / camera->height;
cameraValidateDefinition(camera, 0);
@ -250,15 +250,6 @@ Vector3 cameraUnproject(CameraDefinition* camera, Renderer* renderer, Vector3 po
return m4Transform(camera->unproject, point);
}
void cameraProjectToFragment(CameraDefinition* camera, Renderer* renderer, float x, float y, float z, RenderFragment* result)
{
Vector3 point = {x, y, z};
point = cameraProject(camera, renderer, point);
result->x = lround(point.x);
result->y = lround(point.y);
result->z = point.z;
}
/**
* Render a quad that will fill the view in front of the camera.
* This quad can be used for post-processing.
@ -279,20 +270,20 @@ void cameraProjectToFragment(CameraDefinition* camera, Renderer* renderer, float
v1.callback = callback;
v.x = 0.0;
v.y = (float)render_height;
v.y = (double)render_height;
v.z = 10.0;
v2.location = cameraUnproject(camera, v);
v2.color = col;
v2.callback = callback;
v.x = (float)render_width;
v.y = (float)render_height;
v.x = (double)render_width;
v.y = (double)render_height;
v.z = 10.0;
v3.location = cameraUnproject(camera, v);
v3.color = col;
v3.callback = callback;
v.x = (float)render_width;
v.x = (double)render_width;
v.y = 0.0;
v.z = 10.0;
v4.location = cameraUnproject(camera, v);
@ -302,7 +293,7 @@ void cameraProjectToFragment(CameraDefinition* camera, Renderer* renderer, float
renderPushQuad(&v1, &v2, &v3, &v4);
}*/
static inline void _updateBox(Vector3* point, float* xmin, float* xmax, float* ymin, float* ymax, float* zmax)
static inline void _updateBox(Vector3* point, double* xmin, double* xmax, double* ymin, double* ymax, double* zmax)
{
*xmin = MIN(*xmin, point->x);
*xmax = MAX(*xmax, point->x);
@ -311,10 +302,10 @@ static inline void _updateBox(Vector3* point, float* xmin, float* xmax, float* y
*zmax = MAX(*zmax, point->z);
}
int cameraIsBoxInView(CameraDefinition* camera, Vector3 center, float xsize, float ysize, float zsize)
int cameraIsBoxInView(CameraDefinition* camera, Vector3 center, double xsize, double ysize, double zsize)
{
Vector3 projected;
float xmin, xmax, ymin, ymax, zmax;
double xmin, xmax, ymin, ymax, zmax;
center.x -= xsize / 2.0;
center.y -= ysize / 2.0;

View file

@ -19,24 +19,23 @@ void cameraDeleteDefinition(CameraDefinition* definition);
void cameraCopyDefinition(CameraDefinition* source, CameraDefinition* destination);
void cameraValidateDefinition(CameraDefinition* definition, int check_above);
void cameraSetLocation(CameraDefinition* camera, float x, float y, float z);
void cameraSetTarget(CameraDefinition* camera, float x, float y, float z);
void cameraSetRoll(CameraDefinition* camera, float angle);
void cameraSetLocation(CameraDefinition* camera, double x, double y, double z);
void cameraSetTarget(CameraDefinition* camera, double x, double y, double z);
void cameraSetRoll(CameraDefinition* camera, double angle);
void cameraStrafeForward(CameraDefinition* camera, float value);
void cameraStrafeRight(CameraDefinition* camera, float value);
void cameraStrafeUp(CameraDefinition* camera, float value);
void cameraRotateYaw(CameraDefinition* camera, float value);
void cameraRotatePitch(CameraDefinition* camera, float value);
void cameraRotateRoll(CameraDefinition* camera, float value);
void cameraStrafeForward(CameraDefinition* camera, double value);
void cameraStrafeRight(CameraDefinition* camera, double value);
void cameraStrafeUp(CameraDefinition* camera, double value);
void cameraRotateYaw(CameraDefinition* camera, double value);
void cameraRotatePitch(CameraDefinition* camera, double value);
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);
void cameraProjectToFragment(CameraDefinition* camera, Renderer* renderer, float x, float y, float z, RenderFragment* result);
/*void cameraPushOverlay(CameraDefinition* camera, Color col, f_RenderFragmentCallback callback);*/
int cameraIsBoxInView(CameraDefinition* camera, Vector3 center, float xsize, float ysize, float zsize);
int cameraIsBoxInView(CameraDefinition* camera, Vector3 center, double xsize, double ysize, double zsize);
#ifdef __cplusplus
}

View file

@ -13,7 +13,7 @@ typedef struct
{
Vector3 start;
Vector3 end;
float length;
double length;
} CloudSegment;
static CloudsLayerDefinition NULL_LAYER;
@ -39,20 +39,20 @@ void cloudsSave(PackStream* stream, CloudsDefinition* definition)
{
layer = definition->layers + i;
packWriteFloat(stream, &layer->ymin);
packWriteFloat(stream, &layer->ymax);
packWriteDouble(stream, &layer->ymin);
packWriteDouble(stream, &layer->ymax);
curveSave(stream, layer->coverage_by_altitude);
noiseSaveGenerator(stream, layer->shape_noise);
noiseSaveGenerator(stream, layer->edge_noise);
materialSave(stream, &layer->material);
packWriteFloat(stream, &layer->hardness);
packWriteFloat(stream, &layer->transparencydepth);
packWriteFloat(stream, &layer->lighttraversal);
packWriteFloat(stream, &layer->minimumlight);
packWriteFloat(stream, &layer->shape_scaling);
packWriteFloat(stream, &layer->edge_scaling);
packWriteFloat(stream, &layer->edge_length);
packWriteFloat(stream, &layer->base_coverage);
packWriteDouble(stream, &layer->hardness);
packWriteDouble(stream, &layer->transparencydepth);
packWriteDouble(stream, &layer->lighttraversal);
packWriteDouble(stream, &layer->minimumlight);
packWriteDouble(stream, &layer->shape_scaling);
packWriteDouble(stream, &layer->edge_scaling);
packWriteDouble(stream, &layer->edge_length);
packWriteDouble(stream, &layer->base_coverage);
}
}
@ -71,20 +71,20 @@ void cloudsLoad(PackStream* stream, CloudsDefinition* definition)
{
layer = definition->layers + cloudsAddLayer(definition);
packReadFloat(stream, &layer->ymin);
packReadFloat(stream, &layer->ymax);
packReadDouble(stream, &layer->ymin);
packReadDouble(stream, &layer->ymax);
curveLoad(stream, layer->coverage_by_altitude);
noiseLoadGenerator(stream, layer->shape_noise);
noiseLoadGenerator(stream, layer->edge_noise);
materialLoad(stream, &layer->material);
packReadFloat(stream, &layer->hardness);
packReadFloat(stream, &layer->transparencydepth);
packReadFloat(stream, &layer->lighttraversal);
packReadFloat(stream, &layer->minimumlight);
packReadFloat(stream, &layer->shape_scaling);
packReadFloat(stream, &layer->edge_scaling);
packReadFloat(stream, &layer->edge_length);
packReadFloat(stream, &layer->base_coverage);
packReadDouble(stream, &layer->hardness);
packReadDouble(stream, &layer->transparencydepth);
packReadDouble(stream, &layer->lighttraversal);
packReadDouble(stream, &layer->minimumlight);
packReadDouble(stream, &layer->shape_scaling);
packReadDouble(stream, &layer->edge_scaling);
packReadDouble(stream, &layer->edge_length);
packReadDouble(stream, &layer->base_coverage);
}
}
@ -130,7 +130,7 @@ void cloudsValidateDefinition(CloudsDefinition* definition)
}
}
static float _standardCoverageFunc(CloudsLayerDefinition* layer, Vector3 position)
static double _standardCoverageFunc(CloudsLayerDefinition* layer, Vector3 position)
{
if (position.y > layer->ymax || position.y < layer->ymin)
{
@ -269,9 +269,9 @@ void cloudsDeleteLayer(CloudsDefinition* definition, int layer)
}
}
static inline float _getDistanceToBorder(CloudsLayerDefinition* layer, Vector3 position)
static inline double _getDistanceToBorder(CloudsLayerDefinition* layer, Vector3 position)
{
float density, coverage, val;
double density, coverage, val;
val = noiseGet3DTotal(layer->shape_noise, position.x / layer->shape_scaling, position.y / layer->shape_scaling, position.z / layer->shape_scaling) / noiseGetMaxValue(layer->shape_noise);
coverage = layer->_custom_coverage(layer, position);
@ -302,11 +302,11 @@ static inline float _getDistanceToBorder(CloudsLayerDefinition* layer, Vector3 p
}
}
static inline Vector3 _getNormal(CloudsLayerDefinition* layer, Vector3 position, float detail)
static inline Vector3 _getNormal(CloudsLayerDefinition* layer, Vector3 position, double detail)
{
Vector3 result = {0.0, 0.0, 0.0};
Vector3 dposition;
float val, dval;
double val, dval;
val = _getDistanceToBorder(layer, position);
@ -418,21 +418,21 @@ static int _optimizeSearchLimits(CloudsLayerDefinition* layer, Vector3* start, V
* @param out_segments Allocated space to fill found segments
* @return Number of segments found
*/
static int _findSegments(CloudsLayerDefinition* definition, Renderer* renderer, Vector3 start, Vector3 direction, float detail, int max_segments, float max_inside_length, float max_total_length, float* inside_length, float* total_length, CloudSegment* out_segments)
static int _findSegments(CloudsLayerDefinition* definition, Renderer* renderer, Vector3 start, Vector3 direction, double detail, int max_segments, double max_inside_length, double max_total_length, double* inside_length, double* total_length, CloudSegment* out_segments)
{
int inside, segment_count;
float current_total_length, current_inside_length;
float step_length, segment_length, remaining_length;
float noise_distance, last_noise_distance;
double current_total_length, current_inside_length;
double step_length, segment_length, remaining_length;
double noise_distance, last_noise_distance;
Vector3 walker, step, segment_start;
float render_precision;
double render_precision;
if (max_segments <= 0)
{
return 0;
}
render_precision = 15.2 - 1.5 * (float)renderer->render_quality;
render_precision = 15.2 - 1.5 * (double)renderer->render_quality;
render_precision = render_precision * definition->shape_scaling / 50.0;
if (render_precision > max_total_length / 10.0)
{
@ -513,7 +513,7 @@ static int _findSegments(CloudsLayerDefinition* definition, Renderer* renderer,
return segment_count;
}
static Color _applyLayerLighting(CloudsLayerDefinition* definition, Renderer* renderer, Vector3 position, float detail)
static Color _applyLayerLighting(CloudsLayerDefinition* definition, Renderer* renderer, Vector3 position, double detail)
{
Vector3 normal;
Color col1, col2;
@ -546,7 +546,7 @@ static Color _applyLayerLighting(CloudsLayerDefinition* definition, Renderer* re
Color cloudsGetLayerColor(CloudsLayerDefinition* definition, Renderer* renderer, Vector3 start, Vector3 end)
{
int i, segment_count;
float max_length, detail, total_length, inside_length;
double max_length, detail, total_length, inside_length;
Vector3 direction;
Color result, col;
CloudSegment segments[20];
@ -613,7 +613,7 @@ Color cloudsGetColor(CloudsDefinition* definition, Renderer* renderer, Vector3 s
Color cloudsLayerFilterLight(CloudsLayerDefinition* definition, Renderer* renderer, Color light, Vector3 location, Vector3 light_location, Vector3 direction_to_light)
{
float inside_depth, total_depth, factor;
double inside_depth, total_depth, factor;
CloudSegment segments[20];
_optimizeSearchLimits(definition, &location, &light_location);

View file

@ -14,24 +14,24 @@ extern "C" {
typedef struct CloudsLayerDefinition CloudsLayerDefinition;
typedef float (*CloudCoverageFunc)(CloudsLayerDefinition* definition, Vector3 position);
typedef double (*CloudCoverageFunc)(CloudsLayerDefinition* definition, Vector3 position);
struct CloudsLayerDefinition
{
float ymin;
float ymax;
float base_coverage;
double ymin;
double ymax;
double base_coverage;
Curve* coverage_by_altitude;
NoiseGenerator* shape_noise;
float shape_scaling;
double shape_scaling;
NoiseGenerator* edge_noise;
float edge_scaling;
float edge_length;
double edge_scaling;
double edge_length;
SurfaceMaterial material;
float hardness;
float transparencydepth;
float lighttraversal;
float minimumlight;
double hardness;
double transparencydepth;
double lighttraversal;
double minimumlight;
CloudCoverageFunc _custom_coverage;
};

View file

@ -23,18 +23,18 @@ struct ColorGradation
void colorSave(PackStream* stream, Color* col)
{
packWriteFloat(stream, &col->r);
packWriteFloat(stream, &col->g);
packWriteFloat(stream, &col->b);
packWriteFloat(stream, &col->a);
packWriteDouble(stream, &col->r);
packWriteDouble(stream, &col->g);
packWriteDouble(stream, &col->b);
packWriteDouble(stream, &col->a);
}
void colorLoad(PackStream* stream, Color* col)
{
packReadFloat(stream, &col->r);
packReadFloat(stream, &col->g);
packReadFloat(stream, &col->b);
packReadFloat(stream, &col->a);
packReadDouble(stream, &col->r);
packReadDouble(stream, &col->g);
packReadDouble(stream, &col->b);
packReadDouble(stream, &col->a);
}
unsigned int colorTo32BitRGBA(Color* col)
@ -59,15 +59,15 @@ unsigned int colorTo32BitABGR(Color* col)
void colorMask(Color* base, Color* mask)
{
float new_a;
double new_a;
new_a = base->a + mask->a - (base->a * mask->a);
base->r = (mask->r * mask->a + base->r * base->a - base->r * base->a * mask->a) / new_a;
base->g = (mask->g * mask->a + base->g * base->a - base->g * base->a * mask->a) / new_a;
base->b = (mask->b * mask->a + base->b * base->a - base->b * base->a * mask->a) / new_a;
base->a = new_a;
/*float mask_weight = mask->a;
float base_weight = 1.0 - mask_weight;
/*double mask_weight = mask->a;
double base_weight = 1.0 - mask_weight;
base->r = mask->r * mask_weight + base->r * base_weight;
base->g = mask->g * mask_weight + base->g * base_weight;
@ -75,9 +75,9 @@ void colorMask(Color* base, Color* mask)
base->a = base->a + mask_weight * (1.0 - base->a);*/
}
float colorNormalize(Color* col)
double colorNormalize(Color* col)
{
float max = colorGetValue(col);
double max = colorGetValue(col);
assert(col->r >= 0.0);
assert(col->g >= 0.0);
@ -93,9 +93,9 @@ float colorNormalize(Color* col)
return max;
}
float colorGetValue(Color* col)
double colorGetValue(Color* col)
{
float max;
double max;
max = col->r;
if (col->g > max)
@ -183,12 +183,12 @@ void colorGradationSetBlueCurve(ColorGradation* gradation, Curve* curve)
curveValidate(gradation->blue);
}
void colorGradationQuickAdd(ColorGradation* gradation, float value, Color* col)
void colorGradationQuickAdd(ColorGradation* gradation, double value, Color* col)
{
colorGradationQuickAddRgb(gradation, value, col->r, col->g, col->b);
}
void colorGradationQuickAddRgb(ColorGradation* gradation, float value, float r, float g, float b)
void colorGradationQuickAddRgb(ColorGradation* gradation, double value, double r, double g, double b)
{
curveQuickAddPoint(gradation->red, value, r);
curveValidate(gradation->red);
@ -200,7 +200,7 @@ void colorGradationQuickAddRgb(ColorGradation* gradation, float value, float r,
curveValidate(gradation->blue);
}
Color colorGradationGet(ColorGradation* gradation, float value)
Color colorGradationGet(ColorGradation* gradation, double value)
{
Color result;

View file

@ -9,10 +9,10 @@ extern "C" {
typedef struct
{
float r;
float g;
float b;
float a;
double r;
double g;
double b;
double a;
} Color;
extern Color COLOR_TRANSPARENT;
@ -33,8 +33,8 @@ unsigned int colorTo32BitARGB(Color* col);
unsigned int colorTo32BitABGR(Color* col);
void colorMask(Color* base, Color* mask);
float colorNormalize(Color* col);
float colorGetValue(Color* col);
double colorNormalize(Color* col);
double colorGetValue(Color* col);
/* ColorGradation */
typedef struct ColorGradation ColorGradation;
@ -54,10 +54,10 @@ void colorGradationSetRedCurve(ColorGradation* gradation, Curve* curve);
void colorGradationSetGreenCurve(ColorGradation* gradation, Curve* curve);
void colorGradationSetBlueCurve(ColorGradation* gradation, Curve* curve);
void colorGradationQuickAdd(ColorGradation* gradation, float value, Color* col);
void colorGradationQuickAddRgb(ColorGradation* gradation, float value, float r, float g, float b);
void colorGradationQuickAdd(ColorGradation* gradation, double value, Color* col);
void colorGradationQuickAddRgb(ColorGradation* gradation, double value, double r, double g, double b);
Color colorGradationGet(ColorGradation* gradation, float value);
Color colorGradationGet(ColorGradation* gradation, double value);
#ifdef __cplusplus
}

View file

@ -39,8 +39,8 @@ void curveSave(PackStream* stream, Curve* curve)
packWriteInt(stream, &curve->nbpoints);
for (i = 0; i < curve->nbpoints; i++)
{
packWriteFloat(stream, &curve->points[i].position);
packWriteFloat(stream, &curve->points[i].value);
packWriteDouble(stream, &curve->points[i].position);
packWriteDouble(stream, &curve->points[i].value);
}
}
@ -51,8 +51,8 @@ void curveLoad(PackStream* stream, Curve* curve)
packReadInt(stream, &curve->nbpoints);
for (i = 0; i < curve->nbpoints; i++)
{
packReadFloat(stream, &curve->points[i].position);
packReadFloat(stream, &curve->points[i].value);
packReadDouble(stream, &curve->points[i].position);
packReadDouble(stream, &curve->points[i].value);
}
}
@ -74,7 +74,7 @@ int curveAddPoint(Curve* curve, CurvePoint* point)
}
}
int curveQuickAddPoint(Curve* curve, float position, float value)
int curveQuickAddPoint(Curve* curve, double position, double value)
{
CurvePoint point;
@ -137,10 +137,10 @@ void curveValidate(Curve* curve)
}
}
float curveGetValue(Curve* curve, float position)
double curveGetValue(Curve* curve, double position)
{
int i;
float fact;
double fact;
if (curve->nbpoints == 0)
{

View file

@ -8,8 +8,8 @@ extern "C" {
#endif
typedef struct {
float position;
float value;
double position;
double value;
} CurvePoint;
typedef struct Curve Curve;
@ -22,14 +22,14 @@ void curveLoad(PackStream* stream, Curve* curve);
void curveClear(Curve* curve);
int curveAddPoint(Curve* curve, CurvePoint* point);
int curveQuickAddPoint(Curve* curve, float position, float value);
int curveQuickAddPoint(Curve* curve, double position, double value);
int curveGetPointCount(Curve* curve);
void curveGetPoint(Curve* curve, int number, CurvePoint* point);
void curveSetPoint(Curve* curve, int number, CurvePoint* point);
void curveRemovePoint(Curve* curve, int number);
void curveValidate(Curve* curve);
float curveGetValue(Curve* curve, float position);
double curveGetValue(Curve* curve, double position);
#ifdef __cplusplus
}

View file

@ -8,19 +8,19 @@ Vector3 VECTOR_ZERO = {0.0, 0.0, 0.0};
void v3Save(PackStream* stream, Vector3* v)
{
packWriteFloat(stream, &v->x);
packWriteFloat(stream, &v->y);
packWriteFloat(stream, &v->z);
packWriteDouble(stream, &v->x);
packWriteDouble(stream, &v->y);
packWriteDouble(stream, &v->z);
}
void v3Load(PackStream* stream, Vector3* v)
{
packReadFloat(stream, &v->x);
packReadFloat(stream, &v->y);
packReadFloat(stream, &v->z);
packReadDouble(stream, &v->x);
packReadDouble(stream, &v->y);
packReadDouble(stream, &v->z);
}
Vector3 v3Translate(Vector3 v1, float x, float y, float z)
Vector3 v3Translate(Vector3 v1, double x, double y, double z)
{
Vector3 result;
result.x = v1.x + x;
@ -56,7 +56,7 @@ Vector3 v3Neg(Vector3 v)
return result;
}
Vector3 v3Scale(Vector3 v, float scale)
Vector3 v3Scale(Vector3 v, double scale)
{
Vector3 result;
result.x = v.x * scale;
@ -65,14 +65,14 @@ Vector3 v3Scale(Vector3 v, float scale)
return result;
}
float v3Norm(Vector3 v)
double v3Norm(Vector3 v)
{
return sqrt(v.x * v.x + v.y * v.y + v.z * v.z);
}
Vector3 v3Normalize(Vector3 v)
{
float norm = v3Norm(v);
double norm = v3Norm(v);
if (norm == 0.0)
{
return VECTOR_ZERO;
@ -83,7 +83,7 @@ Vector3 v3Normalize(Vector3 v)
}
}
float v3Dot(Vector3 v1, Vector3 v2)
double v3Dot(Vector3 v1, Vector3 v2)
{
return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z;
}
@ -99,42 +99,42 @@ Vector3 v3Cross(Vector3 v1, Vector3 v2)
void m4Save(PackStream* stream, Matrix4* m)
{
packWriteFloat(stream, &m->a);
packWriteFloat(stream, &m->b);
packWriteFloat(stream, &m->c);
packWriteFloat(stream, &m->d);
packWriteFloat(stream, &m->e);
packWriteFloat(stream, &m->f);
packWriteFloat(stream, &m->g);
packWriteFloat(stream, &m->h);
packWriteFloat(stream, &m->i);
packWriteFloat(stream, &m->j);
packWriteFloat(stream, &m->k);
packWriteFloat(stream, &m->l);
packWriteFloat(stream, &m->m);
packWriteFloat(stream, &m->n);
packWriteFloat(stream, &m->o);
packWriteFloat(stream, &m->p);
packWriteDouble(stream, &m->a);
packWriteDouble(stream, &m->b);
packWriteDouble(stream, &m->c);
packWriteDouble(stream, &m->d);
packWriteDouble(stream, &m->e);
packWriteDouble(stream, &m->f);
packWriteDouble(stream, &m->g);
packWriteDouble(stream, &m->h);
packWriteDouble(stream, &m->i);
packWriteDouble(stream, &m->j);
packWriteDouble(stream, &m->k);
packWriteDouble(stream, &m->l);
packWriteDouble(stream, &m->m);
packWriteDouble(stream, &m->n);
packWriteDouble(stream, &m->o);
packWriteDouble(stream, &m->p);
}
void m4Load(PackStream* stream, Matrix4* m)
{
packReadFloat(stream, &m->a);
packReadFloat(stream, &m->b);
packReadFloat(stream, &m->c);
packReadFloat(stream, &m->d);
packReadFloat(stream, &m->e);
packReadFloat(stream, &m->f);
packReadFloat(stream, &m->g);
packReadFloat(stream, &m->h);
packReadFloat(stream, &m->i);
packReadFloat(stream, &m->j);
packReadFloat(stream, &m->k);
packReadFloat(stream, &m->l);
packReadFloat(stream, &m->m);
packReadFloat(stream, &m->n);
packReadFloat(stream, &m->o);
packReadFloat(stream, &m->p);
packReadDouble(stream, &m->a);
packReadDouble(stream, &m->b);
packReadDouble(stream, &m->c);
packReadDouble(stream, &m->d);
packReadDouble(stream, &m->e);
packReadDouble(stream, &m->f);
packReadDouble(stream, &m->g);
packReadDouble(stream, &m->h);
packReadDouble(stream, &m->i);
packReadDouble(stream, &m->j);
packReadDouble(stream, &m->k);
packReadDouble(stream, &m->l);
packReadDouble(stream, &m->m);
packReadDouble(stream, &m->n);
packReadDouble(stream, &m->o);
packReadDouble(stream, &m->p);
}
Matrix4 m4NewIdentity()
@ -180,7 +180,7 @@ Vector3 m4MultPoint(Matrix4 m, Vector3 v)
Vector3 m4Transform(Matrix4 m, Vector3 v)
{
Vector3 result;
float w;
double w;
result.x = m.a * v.x + m.b * v.y + m.c * v.z + m.d;
result.y = m.e * v.x + m.f * v.y + m.g * v.z + m.h;
result.z = m.i * v.x + m.j * v.y + m.k * v.z + m.l;
@ -216,7 +216,7 @@ Matrix4 m4Transpose(Matrix4 m)
return result;
}
Matrix4 m4NewScale(float x, float y, float z)
Matrix4 m4NewScale(double x, double y, double z)
{
Matrix4 result = m4NewIdentity();
result.a = x;
@ -225,7 +225,7 @@ Matrix4 m4NewScale(float x, float y, float z)
return result;
}
Matrix4 m4NewTranslate(float x, float y, float z)
Matrix4 m4NewTranslate(double x, double y, double z)
{
Matrix4 result = m4NewIdentity();
result.d = x;
@ -234,45 +234,45 @@ Matrix4 m4NewTranslate(float x, float y, float z)
return result;
}
Matrix4 m4NewRotateX(float angle)
Matrix4 m4NewRotateX(double angle)
{
Matrix4 result = m4NewIdentity();
float s = sin(angle);
float c = cos(angle);
double s = sin(angle);
double c = cos(angle);
result.f = result.k = c;
result.g = -s;
result.j = s;
return result;
}
Matrix4 m4NewRotateY(float angle)
Matrix4 m4NewRotateY(double angle)
{
Matrix4 result = m4NewIdentity();
float s = sin(angle);
float c = cos(angle);
double s = sin(angle);
double c = cos(angle);
result.a = result.k = c;
result.c = s;
result.i = -s;
return result;
}
Matrix4 m4NewRotateZ(float angle)
Matrix4 m4NewRotateZ(double angle)
{
Matrix4 result = m4NewIdentity();
float s = sin(angle);
float c = cos(angle);
double s = sin(angle);
double c = cos(angle);
result.a = result.f = c;
result.b = -s;
result.e = s;
return result;
}
Matrix4 m4NewRotateAxis(float angle, Vector3 axis)
Matrix4 m4NewRotateAxis(double angle, Vector3 axis)
{
Matrix4 result = m4NewIdentity();
float s = sin(angle);
float c = cos(angle);
float c1 = 1.0 - c;
double s = sin(angle);
double c = cos(angle);
double c1 = 1.0 - c;
axis = v3Normalize(axis);
result.a = axis.x * axis.x * c1 + c;
result.b = axis.x * axis.y * c1 - axis.z * s;
@ -286,15 +286,15 @@ Matrix4 m4NewRotateAxis(float angle, Vector3 axis)
return result;
}
Matrix4 m4NewRotateEuler(float heading, float attitude, float bank)
Matrix4 m4NewRotateEuler(double heading, double attitude, double bank)
{
Matrix4 result = m4NewIdentity();
float ch = cos(heading);
float sh = sin(heading);
float ca = cos(attitude);
float sa = sin(attitude);
float cb = cos(bank);
float sb = sin(bank);
double ch = cos(heading);
double sh = sin(heading);
double ca = cos(attitude);
double sa = sin(attitude);
double cb = cos(bank);
double sb = sin(bank);
result.a = ch * ca;
result.b = sh * sb - ch * sa * cb;
result.c = ch * sa * sb + sh * cb;
@ -334,10 +334,10 @@ Matrix4 m4NewLookAt(Vector3 eye, Vector3 at, Vector3 up)
return m4Inverse(result);
}
Matrix4 m4NewPerspective(float fov_y, float aspect, float near, float far)
Matrix4 m4NewPerspective(double fov_y, double aspect, double near, double far)
{
Matrix4 result = m4NewIdentity();
float f = 1 / tan(fov_y / 2.0);
double f = 1 / tan(fov_y / 2.0);
result.a = f / aspect;
result.f = f;
result.k = (far + near) / (near - far);
@ -347,7 +347,7 @@ Matrix4 m4NewPerspective(float fov_y, float aspect, float near, float far)
return result;
}
float m4Determinant(Matrix4 m)
double m4Determinant(Matrix4 m)
{
return ((m.a * m.f - m.e * m.b)
* (m.k * m.p - m.o * m.l)
@ -366,7 +366,7 @@ float m4Determinant(Matrix4 m)
Matrix4 m4Inverse(Matrix4 m)
{
Matrix4 result;
float d = m4Determinant(m);
double d = m4Determinant(m);
if (fabs(d) < 0.00001)
{

View file

@ -9,43 +9,43 @@ extern "C" {
typedef struct
{
float x;
float y;
float z;
double x;
double y;
double z;
} Vector3;
typedef struct
{
float a;
float b;
float c;
float d;
float e;
float f;
float g;
float h;
float i;
float j;
float k;
float l;
float m;
float n;
float o;
float p;
double a;
double b;
double c;
double d;
double e;
double f;
double g;
double h;
double i;
double j;
double k;
double l;
double m;
double n;
double o;
double p;
} Matrix4;
extern Vector3 VECTOR_ZERO;
void v3Save(PackStream* stream, Vector3* v);
void v3Load(PackStream* stream, Vector3* v);
Vector3 v3Translate(Vector3 v1, float x, float y, float z);
Vector3 v3Translate(Vector3 v1, double x, double y, double z);
Vector3 v3Add(Vector3 v1, Vector3 v2);
Vector3 v3Sub(Vector3 v1, Vector3 v2);
Vector3 v3Neg(Vector3 v);
Vector3 v3Scale(Vector3 v, float scale);
float v3Norm(Vector3 v);
Vector3 v3Scale(Vector3 v, double scale);
double v3Norm(Vector3 v);
Vector3 v3Normalize(Vector3 v);
float v3Dot(Vector3 v1, Vector3 v2);
double v3Dot(Vector3 v1, Vector3 v2);
Vector3 v3Cross(Vector3 v1, Vector3 v2);
void m4Save(PackStream* stream, Matrix4* m);
@ -55,17 +55,17 @@ Matrix4 m4Mult(Matrix4 m1, Matrix4 m2);
Vector3 m4MultPoint(Matrix4 m, Vector3 v);
Vector3 m4Transform(Matrix4 m, Vector3 v);
Matrix4 m4Transpose(Matrix4 m);
Matrix4 m4NewScale(float x, float y, float z);
Matrix4 m4NewTranslate(float x, float y, float z);
Matrix4 m4NewRotateX(float angle);
Matrix4 m4NewRotateY(float angle);
Matrix4 m4NewRotateZ(float angle);
Matrix4 m4NewRotateAxis(float angle, Vector3 axis);
Matrix4 m4NewRotateEuler(float heading, float attitude, float bank);
Matrix4 m4NewScale(double x, double y, double z);
Matrix4 m4NewTranslate(double x, double y, double z);
Matrix4 m4NewRotateX(double angle);
Matrix4 m4NewRotateY(double angle);
Matrix4 m4NewRotateZ(double angle);
Matrix4 m4NewRotateAxis(double angle, Vector3 axis);
Matrix4 m4NewRotateEuler(double heading, double attitude, double bank);
Matrix4 m4NewRotateTripleAxis(Vector3 x, Vector3 y, Vector3 z);
Matrix4 m4NewLookAt(Vector3 eye, Vector3 at, Vector3 up);
Matrix4 m4NewPerspective(float fov_y, float aspect, float near, float far);
float m4Determinant(Matrix4 m);
Matrix4 m4NewPerspective(double fov_y, double aspect, double near, double far);
double m4Determinant(Matrix4 m);
Matrix4 m4Inverse(Matrix4 m);
#ifdef __cplusplus

View file

@ -43,10 +43,10 @@ void lightingSave(PackStream* stream, LightingDefinition* definition)
{
v3Save(stream, &definition->lights[i].direction);
colorSave(stream, &definition->lights[i].color);
packWriteFloat(stream, &definition->lights[i].reflection);
packWriteDouble(stream, &definition->lights[i].reflection);
packWriteInt(stream, &definition->lights[i].filtered);
packWriteInt(stream, &definition->lights[i].masked);
packWriteFloat(stream, &definition->lights[i].amplitude);
packWriteDouble(stream, &definition->lights[i].amplitude);
}
}
@ -60,10 +60,10 @@ void lightingLoad(PackStream* stream, LightingDefinition* definition)
{
v3Load(stream, &definition->lights[i].direction);
colorLoad(stream, &definition->lights[i].color);
packReadFloat(stream, &definition->lights[i].reflection);
packReadDouble(stream, &definition->lights[i].reflection);
packReadInt(stream, &definition->lights[i].filtered);
packReadInt(stream, &definition->lights[i].masked);
packReadFloat(stream, &definition->lights[i].amplitude);
packReadDouble(stream, &definition->lights[i].amplitude);
}
lightingValidateDefinition(definition);
@ -170,7 +170,7 @@ static int _getLightStatus(LightDefinition* definition, Renderer* renderer, Vect
static Color _applyDirectLight(LightDefinition* definition, Renderer* renderer, Vector3 location, Vector3 normal, SurfaceMaterial material)
{
Color result, light;
float diffuse, specular, normal_norm;
double diffuse, specular, normal_norm;
Vector3 view, reflect, direction_inv;
light = definition->color;
@ -180,16 +180,16 @@ static Color _applyDirectLight(LightDefinition* definition, Renderer* renderer,
{
/* TODO Sampling around light direction */
int xsamples, ysamples, samples, x, y;
float xstep, ystep, factor;
double xstep, ystep, factor;
LightDefinition sublight;
ysamples = renderer->render_quality / 4 + 1;
xsamples = renderer->render_quality / 2 + 1;
samples = xsamples * ysamples + 1;
factor = 1.0 / (float)samples;
factor = 1.0 / (double)samples;
xstep = M_PI * 2.0 / (float)xsamples;
ystep = M_PI * 0.5 / (float)(ysamples - 1);
xstep = M_PI * 2.0 / (double)xsamples;
ystep = M_PI * 0.5 / (double)(ysamples - 1);
sublight = *definition;
sublight.amplitude = 0.0;

View file

@ -15,10 +15,10 @@ struct LightDefinition
{
Vector3 direction; /* Global direction of the light */
Color color; /* Main color of the light */
float reflection; /* Reflected factor of the light (for specular lighting) */
double reflection; /* Reflected factor of the light (for specular lighting) */
int filtered; /* Should the light be filtered (by atmosphere, water...) */
int masked; /* Should the light be masked (cast shadows..) */
float amplitude; /* Angle amplitude of the light source (for multi-sampling, pi / 2.0 for skydome) */
double amplitude; /* Angle amplitude of the light source (for multi-sampling, pi / 2.0 for skydome) */
};
typedef struct

View file

@ -38,7 +38,7 @@ void paysagesInit()
autoSetDaytime(8, 30);
// DEBUG
/*float last_height, height, x;
/*double last_height, height, x;
last_height = height = 0.0;
x = 0.0;
while (height <= 1.0 || height >= last_height || last_height < 0.1)
@ -60,17 +60,17 @@ void paysagesQuit()
FileOperationResult paysagesSave(char* filepath)
{
PackStream* stream = packWriteFile(filepath);
float app_header, version_header;
double app_header, version_header;
if (!stream)
{
return FILE_OPERATION_IOERROR;
}
app_header = (float)APP_HEADER;
packWriteFloat(stream, &app_header);
version_header = (float)PAYSAGES_CURRENT_DATA_VERSION;
packWriteFloat(stream, &version_header);
app_header = (double)APP_HEADER;
packWriteDouble(stream, &app_header);
version_header = (double)PAYSAGES_CURRENT_DATA_VERSION;
packWriteDouble(stream, &version_header);
scenerySave(stream);
@ -82,21 +82,21 @@ FileOperationResult paysagesSave(char* filepath)
FileOperationResult paysagesLoad(char* filepath)
{
PackStream* stream = packReadFile(filepath);
float app_header, version_header;
double app_header, version_header;
if (!stream)
{
return FILE_OPERATION_IOERROR;
}
packReadFloat(stream, &app_header);
packReadDouble(stream, &app_header);
if (app_header != APP_HEADER)
{
packCloseStream(stream);
return FILE_OPERATION_APP_MISMATCH;
}
packReadFloat(stream, &version_header);
packReadDouble(stream, &version_header);
if ((int)version_header != PAYSAGES_CURRENT_DATA_VERSION)
{
packCloseStream(stream);

View file

@ -13,7 +13,7 @@ struct HeightModifier
{
Zone* zone;
int mode;
float value;
double value;
};
HeightModifier* modifierCreate()
@ -49,14 +49,14 @@ void modifierDelete(HeightModifier* modifier)
void modifierSave(PackStream* stream, HeightModifier* modifier)
{
packWriteInt(stream, &modifier->mode);
packWriteFloat(stream, &modifier->value);
packWriteDouble(stream, &modifier->value);
zoneSave(stream, modifier->zone);
}
void modifierLoad(PackStream* stream, HeightModifier* modifier)
{
packReadInt(stream, &modifier->mode);
packReadFloat(stream, &modifier->value);
packReadDouble(stream, &modifier->value);
zoneLoad(stream, modifier->zone);
}
@ -65,13 +65,13 @@ Zone* modifierGetZone(HeightModifier* modifier)
return modifier->zone;
}
void modifierActionAddValue(HeightModifier* modifier, float value)
void modifierActionAddValue(HeightModifier* modifier, double value)
{
modifier->mode = MODE_ADD_VALUE;
modifier->value = value;
}
void modifierActionFixValue(HeightModifier* modifier, float value)
void modifierActionFixValue(HeightModifier* modifier, double value)
{
modifier->mode = MODE_FIX_VALUE;
modifier->value = value;
@ -79,7 +79,7 @@ void modifierActionFixValue(HeightModifier* modifier, float value)
Vector3 modifierApply(HeightModifier* modifier, Vector3 location)
{
float influence, diff;
double influence, diff;
Vector3 normal;
switch (modifier->mode)

View file

@ -16,8 +16,8 @@ void modifierDelete(HeightModifier* modifier);
void modifierSave(PackStream* stream, HeightModifier* modifier);
void modifierLoad(PackStream* stream, HeightModifier* modifier);
Zone* modifierGetZone(HeightModifier* modifier);
void modifierActionAddValue(HeightModifier* modifier, float value);
void modifierActionFixValue(HeightModifier* modifier, float value);
void modifierActionAddValue(HeightModifier* modifier, double value);
void modifierActionFixValue(HeightModifier* modifier, double value);
Vector3 modifierApply(HeightModifier* modifier, Vector3 location);
#ifdef __cplusplus

View file

@ -15,15 +15,15 @@ struct NoiseGenerator
int size1;
int size2;
int size3;
float height_offset;
double height_offset;
int level_count;
struct NoiseLevel levels[MAX_LEVEL_COUNT];
};
static int _noise_pool_size;
static float* _noise_pool;
static double* _noise_pool;
static inline float _cubicInterpolate(float* p, float x)
static inline double _cubicInterpolate(double* p, double x)
{
return p[1] + 0.5 * x * (p[2] - p[0] + x * (2.0 * p[0] - 5.0 * p[1] + 4.0 * p[2] - p[3] + x * (3.0 * (p[1] - p[2]) + p[3] - p[0])));
}
@ -33,7 +33,7 @@ void noiseInit()
int i;
_noise_pool_size = 1048576;
_noise_pool = malloc(sizeof(float) * _noise_pool_size);
_noise_pool = malloc(sizeof(double) * _noise_pool_size);
for (i = 0; i < _noise_pool_size; i++)
{
@ -53,7 +53,7 @@ void noiseSave(PackStream* stream)
packWriteInt(stream, &_noise_pool_size);
for (i = 0; i < _noise_pool_size; i++)
{
packWriteFloat(stream, _noise_pool + i);
packWriteDouble(stream, _noise_pool + i);
}
}
@ -62,10 +62,10 @@ void noiseLoad(PackStream* stream)
int i;
packReadInt(stream, &_noise_pool_size);
_noise_pool = realloc(_noise_pool, sizeof(float) * _noise_pool_size);
_noise_pool = realloc(_noise_pool, sizeof(double) * _noise_pool_size);
for (i = 0; i < _noise_pool_size; i++)
{
packReadFloat(stream, _noise_pool + i);
packReadDouble(stream, _noise_pool + i);
}
}
@ -96,18 +96,18 @@ void noiseSaveGenerator(PackStream* stream, NoiseGenerator* perlin)
packWriteInt(stream, &perlin->size1);
packWriteInt(stream, &perlin->size2);
packWriteInt(stream, &perlin->size3);
packWriteFloat(stream, &perlin->height_offset);
packWriteDouble(stream, &perlin->height_offset);
packWriteInt(stream, &perlin->level_count);
for (x = 0; x < perlin->level_count; x++)
{
NoiseLevel* level = perlin->levels + x;
packWriteFloat(stream, &level->scaling);
packWriteFloat(stream, &level->height);
packWriteFloat(stream, &level->xoffset);
packWriteFloat(stream, &level->yoffset);
packWriteFloat(stream, &level->zoffset);
packWriteDouble(stream, &level->scaling);
packWriteDouble(stream, &level->height);
packWriteDouble(stream, &level->xoffset);
packWriteDouble(stream, &level->yoffset);
packWriteDouble(stream, &level->zoffset);
}
}
@ -118,18 +118,18 @@ void noiseLoadGenerator(PackStream* stream, NoiseGenerator* perlin)
packReadInt(stream, &perlin->size1);
packReadInt(stream, &perlin->size2);
packReadInt(stream, &perlin->size3);
packReadFloat(stream, &perlin->height_offset);
packReadDouble(stream, &perlin->height_offset);
packReadInt(stream, &perlin->level_count);
for (x = 0; x < perlin->level_count; x++)
{
NoiseLevel* level = perlin->levels + x;
packReadFloat(stream, &level->scaling);
packReadFloat(stream, &level->height);
packReadFloat(stream, &level->xoffset);
packReadFloat(stream, &level->yoffset);
packReadFloat(stream, &level->zoffset);
packReadDouble(stream, &level->scaling);
packReadDouble(stream, &level->height);
packReadDouble(stream, &level->xoffset);
packReadDouble(stream, &level->yoffset);
packReadDouble(stream, &level->zoffset);
}
}
@ -150,8 +150,8 @@ void noiseGenerateBaseNoise(NoiseGenerator* generator, int size)
size = (size > _noise_pool_size) ? _noise_pool_size : size;
generator->size1 = size;
generator->size2 = (int)floor(sqrt((float)size));
generator->size3 = (int)floor(cbrt((float)size));
generator->size2 = (int)floor(sqrt((double)size));
generator->size3 = (int)floor(cbrt((double)size));
}
int noiseGetBaseSize(NoiseGenerator* generator)
@ -159,10 +159,10 @@ int noiseGetBaseSize(NoiseGenerator* generator)
return generator->size1;
}
float noiseGetMaxValue(NoiseGenerator* generator)
double noiseGetMaxValue(NoiseGenerator* generator)
{
int x;
float result = generator->height_offset;
double result = generator->height_offset;
for (x = 0; x < generator->level_count; x++)
{
@ -191,7 +191,7 @@ void noiseAddLevel(NoiseGenerator* generator, NoiseLevel level)
}
}
void noiseAddLevelSimple(NoiseGenerator* generator, float scaling, float height)
void noiseAddLevelSimple(NoiseGenerator* generator, double scaling, double height)
{
NoiseLevel level;
@ -204,7 +204,7 @@ void noiseAddLevelSimple(NoiseGenerator* generator, float scaling, float height)
noiseAddLevel(generator, level);
}
void noiseAddLevels(NoiseGenerator* generator, int level_count, NoiseLevel start_level, float scaling_factor, float height_factor, int randomize_offset)
void noiseAddLevels(NoiseGenerator* generator, int level_count, NoiseLevel start_level, double scaling_factor, double height_factor, int randomize_offset)
{
int i;
@ -222,7 +222,7 @@ void noiseAddLevels(NoiseGenerator* generator, int level_count, NoiseLevel start
}
}
void noiseAddLevelsSimple(NoiseGenerator* generator, int level_count, float scaling, float height)
void noiseAddLevelsSimple(NoiseGenerator* generator, int level_count, double scaling, double height)
{
NoiseLevel level;
@ -264,7 +264,7 @@ void noiseSetLevel(NoiseGenerator* generator, int level, NoiseLevel params)
}
}
void noiseSetLevelSimple(NoiseGenerator* generator, int level, float scaling, float height)
void noiseSetLevelSimple(NoiseGenerator* generator, int level, double scaling, double height)
{
NoiseLevel params;
@ -277,11 +277,11 @@ void noiseSetLevelSimple(NoiseGenerator* generator, int level, float scaling, fl
noiseSetLevel(generator, level, params);
}
void noiseNormalizeHeight(NoiseGenerator* generator, float min_height, float max_height, int adjust_scaling)
void noiseNormalizeHeight(NoiseGenerator* generator, double min_height, double max_height, int adjust_scaling)
{
int level;
float height = 0.0;
float target_height = max_height - min_height;
double height = 0.0;
double target_height = max_height - min_height;
if (generator->level_count == 0)
{
@ -306,13 +306,13 @@ void noiseNormalizeHeight(NoiseGenerator* generator, float min_height, float max
static inline float _get1DRawNoiseValue(NoiseGenerator* generator, float x)
static inline double _get1DRawNoiseValue(NoiseGenerator* generator, double x)
{
int size = generator->size1;
int xbase = (int)floor(x);
float xinternal = x - (float)xbase;
double xinternal = x - (double)xbase;
int x0 = (xbase - 1) % size;
if (x0 < 0)
@ -335,7 +335,7 @@ static inline float _get1DRawNoiseValue(NoiseGenerator* generator, float x)
x3 += size;
}
float buf_cubic_x[4];
double buf_cubic_x[4];
buf_cubic_x[0] = _noise_pool[x0 % _noise_pool_size];
buf_cubic_x[1] = _noise_pool[x1 % _noise_pool_size];
@ -345,12 +345,12 @@ static inline float _get1DRawNoiseValue(NoiseGenerator* generator, float x)
return _cubicInterpolate(buf_cubic_x, xinternal);
}
static inline float _get1DLevelValue(NoiseGenerator* generator, NoiseLevel* level, float x)
static inline double _get1DLevelValue(NoiseGenerator* generator, NoiseLevel* level, double x)
{
return _get1DRawNoiseValue(generator, x / level->scaling + level->xoffset * generator->size1) * level->height;
}
float noiseGet1DLevel(NoiseGenerator* generator, int level, float x)
double noiseGet1DLevel(NoiseGenerator* generator, int level, double x)
{
if (level >= 0 && level < generator->level_count)
{
@ -362,10 +362,10 @@ float noiseGet1DLevel(NoiseGenerator* generator, int level, float x)
}
}
float noiseGet1DTotal(NoiseGenerator* generator, float x)
double noiseGet1DTotal(NoiseGenerator* generator, double x)
{
int level;
float result;
double result;
result = 0.0;
for (level = 0; level < generator->level_count; level++)
@ -375,10 +375,10 @@ float noiseGet1DTotal(NoiseGenerator* generator, float x)
return result + generator->height_offset;
}
float noiseGet1DDetail(NoiseGenerator* generator, float x, float detail)
double noiseGet1DDetail(NoiseGenerator* generator, double x, double detail)
{
int level;
float result, height, factor;
double result, height, factor;
result = 0.0;
for (level = 0; level < generator->level_count; level++)
@ -402,15 +402,15 @@ float noiseGet1DDetail(NoiseGenerator* generator, float x, float detail)
static inline float _get2DRawNoiseValue(NoiseGenerator* generator, float x, float y)
static inline double _get2DRawNoiseValue(NoiseGenerator* generator, double x, double y)
{
int size = generator->size2;
int xbase = (int)floor(x);
int ybase = (int)floor(y);
float xinternal = x - (float)xbase;
float yinternal = y - (float)ybase;
double xinternal = x - (double)xbase;
double yinternal = y - (double)ybase;
int x0 = (xbase - 1) % size;
if (x0 < 0)
@ -454,8 +454,8 @@ static inline float _get2DRawNoiseValue(NoiseGenerator* generator, float x, floa
y3 += size;
}
float buf_cubic_x[4];
float buf_cubic_y[4];
double buf_cubic_x[4];
double buf_cubic_y[4];
buf_cubic_x[0] = _noise_pool[(y0 * size + x0) % _noise_pool_size];
buf_cubic_x[1] = _noise_pool[(y0 * size + x1) % _noise_pool_size];
@ -484,12 +484,12 @@ static inline float _get2DRawNoiseValue(NoiseGenerator* generator, float x, floa
return _cubicInterpolate(buf_cubic_y, yinternal);
}
static inline float _get2DLevelValue(NoiseGenerator* generator, NoiseLevel* level, float x, float y)
static inline double _get2DLevelValue(NoiseGenerator* generator, NoiseLevel* level, double x, double y)
{
return _get2DRawNoiseValue(generator, x / level->scaling + level->xoffset * generator->size2, y / level->scaling + level->yoffset * generator->size2) * level->height;
}
float noiseGet2DLevel(NoiseGenerator* generator, int level, float x, float y)
double noiseGet2DLevel(NoiseGenerator* generator, int level, double x, double y)
{
if (level >= 0 && level < generator->level_count)
{
@ -501,10 +501,10 @@ float noiseGet2DLevel(NoiseGenerator* generator, int level, float x, float y)
}
}
float noiseGet2DTotal(NoiseGenerator* generator, float x, float y)
double noiseGet2DTotal(NoiseGenerator* generator, double x, double y)
{
int level;
float result;
double result;
result = 0.0;
for (level = 0; level < generator->level_count; level++)
@ -514,10 +514,10 @@ float noiseGet2DTotal(NoiseGenerator* generator, float x, float y)
return result + generator->height_offset;
}
float noiseGet2DDetail(NoiseGenerator* generator, float x, float y, float detail)
double noiseGet2DDetail(NoiseGenerator* generator, double x, double y, double detail)
{
int level;
float result, height, factor;
double result, height, factor;
result = 0.0;
for (level = 0; level < generator->level_count; level++)
@ -541,7 +541,7 @@ float noiseGet2DDetail(NoiseGenerator* generator, float x, float y, float detail
static inline float _get3DRawNoiseValue(NoiseGenerator* generator, float x, float y, float z)
static inline double _get3DRawNoiseValue(NoiseGenerator* generator, double x, double y, double z)
{
int size = generator->size3;
@ -549,9 +549,9 @@ static inline float _get3DRawNoiseValue(NoiseGenerator* generator, float x, floa
int ybase = (int)floor(y);
int zbase = (int)floor(z);
float xinternal = x - (float)xbase;
float yinternal = y - (float)ybase;
float zinternal = z - (float)zbase;
double xinternal = x - (double)xbase;
double yinternal = y - (double)ybase;
double zinternal = z - (double)zbase;
int x0 = (xbase - 1) % size;
if (x0 < 0)
@ -616,9 +616,9 @@ static inline float _get3DRawNoiseValue(NoiseGenerator* generator, float x, floa
z3 += size;
}
float buf_cubic_x[4];
float buf_cubic_y[4];
float buf_cubic_z[4];
double buf_cubic_x[4];
double buf_cubic_y[4];
double buf_cubic_z[4];
buf_cubic_x[0] = _noise_pool[(y0 * size * size + x0 * size + z0) % _noise_pool_size];
buf_cubic_x[1] = _noise_pool[(y0 * size * size + x1 * size + z0) % _noise_pool_size];
@ -727,12 +727,12 @@ static inline float _get3DRawNoiseValue(NoiseGenerator* generator, float x, floa
return _cubicInterpolate(buf_cubic_z, zinternal);
}
static inline float _get3DLevelValue(NoiseGenerator* generator, NoiseLevel* level, float x, float y, float z)
static inline double _get3DLevelValue(NoiseGenerator* generator, NoiseLevel* level, double x, double y, double z)
{
return _get3DRawNoiseValue(generator, x / level->scaling + level->xoffset * generator->size3, y / level->scaling + level->yoffset * generator->size3, z / level->scaling + level->zoffset * generator->size3) * level->height;
}
float noiseGet3DLevel(NoiseGenerator* generator, int level, float x, float y, float z)
double noiseGet3DLevel(NoiseGenerator* generator, int level, double x, double y, double z)
{
if (level >= 0 && level < generator->level_count)
{
@ -744,10 +744,10 @@ float noiseGet3DLevel(NoiseGenerator* generator, int level, float x, float y, fl
}
}
float noiseGet3DTotal(NoiseGenerator* generator, float x, float y, float z)
double noiseGet3DTotal(NoiseGenerator* generator, double x, double y, double z)
{
int level;
float result;
double result;
result = 0.0;
for (level = 0; level < generator->level_count; level++)
@ -757,10 +757,10 @@ float noiseGet3DTotal(NoiseGenerator* generator, float x, float y, float z)
return result + generator->height_offset;
}
float noiseGet3DDetail(NoiseGenerator* generator, float x, float y, float z, float detail)
double noiseGet3DDetail(NoiseGenerator* generator, double x, double y, double z, double detail)
{
int level;
float result, height, factor;
double result, height, factor;
result = 0.0;
for (level = 0; level < generator->level_count; level++)

View file

@ -9,11 +9,11 @@ extern "C" {
struct NoiseLevel
{
float scaling;
float height;
float xoffset;
float yoffset;
float zoffset;
double scaling;
double height;
double xoffset;
double yoffset;
double zoffset;
};
typedef struct NoiseLevel NoiseLevel;
typedef struct NoiseGenerator NoiseGenerator;
@ -30,27 +30,27 @@ void noiseLoadGenerator(PackStream* stream, NoiseGenerator* perlin);
void noiseCopy(NoiseGenerator* source, NoiseGenerator* destination);
void noiseGenerateBaseNoise(NoiseGenerator* generator, int size);
int noiseGetBaseSize(NoiseGenerator* generator);
float noiseGetMaxValue(NoiseGenerator* generator);
double noiseGetMaxValue(NoiseGenerator* generator);
int noiseGetLevelCount(NoiseGenerator* generator);
void noiseClearLevels(NoiseGenerator* generator);
void noiseAddLevel(NoiseGenerator* generator, NoiseLevel level);
void noiseAddLevelSimple(NoiseGenerator* generator, float scaling, float height);
void noiseAddLevels(NoiseGenerator* generator, int level_count, NoiseLevel start_level, float scaling_factor, float height_factor, int randomize_offset);
void noiseAddLevelsSimple(NoiseGenerator* generator, int level_count, float scaling, float height);
void noiseAddLevelSimple(NoiseGenerator* generator, double scaling, double height);
void noiseAddLevels(NoiseGenerator* generator, int level_count, NoiseLevel start_level, double scaling_factor, double height_factor, int randomize_offset);
void noiseAddLevelsSimple(NoiseGenerator* generator, int level_count, double scaling, double height);
void noiseRemoveLevel(NoiseGenerator* generator, int level);
int noiseGetLevel(NoiseGenerator* generator, int level, NoiseLevel* params);
void noiseSetLevel(NoiseGenerator* generator, int level, NoiseLevel params);
void noiseSetLevelSimple(NoiseGenerator* generator, int level, float scaling, float height);
void noiseNormalizeHeight(NoiseGenerator* generator, float min_height, float max_height, int adjust_scaling);
float noiseGet1DLevel(NoiseGenerator* generator, int level, float x);
float noiseGet1DTotal(NoiseGenerator* generator, float x);
float noiseGet1DDetail(NoiseGenerator* generator, float x, float detail);
float noiseGet2DLevel(NoiseGenerator* generator, int level, float x, float y);
float noiseGet2DTotal(NoiseGenerator* generator, float x, float y);
float noiseGet2DDetail(NoiseGenerator* generator, float x, float y, float detail);
float noiseGet3DLevel(NoiseGenerator* generator, int level, float x, float y, float z);
float noiseGet3DTotal(NoiseGenerator* generator, float x, float y, float z);
float noiseGet3DDetail(NoiseGenerator* generator, float x, float y, float z, float detail);
void noiseSetLevelSimple(NoiseGenerator* generator, int level, double scaling, double height);
void noiseNormalizeHeight(NoiseGenerator* generator, double min_height, double max_height, int adjust_scaling);
double noiseGet1DLevel(NoiseGenerator* generator, int level, double x);
double noiseGet1DTotal(NoiseGenerator* generator, double x);
double noiseGet1DDetail(NoiseGenerator* generator, double x, double detail);
double noiseGet2DLevel(NoiseGenerator* generator, int level, double x, double y);
double noiseGet2DTotal(NoiseGenerator* generator, double x, double y);
double noiseGet2DDetail(NoiseGenerator* generator, double x, double y, double detail);
double noiseGet3DLevel(NoiseGenerator* generator, int level, double x, double y, double z);
double noiseGet3DTotal(NoiseGenerator* generator, double x, double y, double z);
double noiseGet3DDetail(NoiseGenerator* generator, double x, double y, double z, double detail);
#ifdef __cplusplus
}

View file

@ -20,9 +20,9 @@ struct PackStream
#define unpack754_32(i) (unpack754((i), 32, 8))
#define unpack754_64(i) (unpack754((i), 64, 11))
static uint64_t pack754(float f, unsigned bits, unsigned expbits)
static uint64_t pack754(double f, unsigned bits, unsigned expbits)
{
float fnorm;
double fnorm;
int shift;
long long sign, exp, significand;
unsigned significandbits = bits - expbits - 1; // -1 for sign bit
@ -39,7 +39,7 @@ static uint64_t pack754(float f, unsigned bits, unsigned expbits)
while(fnorm < 1.0) { fnorm *= 2.0; shift--; }
fnorm = fnorm - 1.0;
// calculate the binary form (non-float) of the significand data
// calculate the binary form (non-double) of the significand data
significand = fnorm * ((1LL<<significandbits) + 0.5f);
// get the biased exponent
@ -49,9 +49,9 @@ static uint64_t pack754(float f, unsigned bits, unsigned expbits)
return (sign<<(bits-1)) | (exp<<(bits-expbits-1)) | significand;
}
static float unpack754(uint64_t i, unsigned bits, unsigned expbits)
static double unpack754(uint64_t i, unsigned bits, unsigned expbits)
{
float result;
double result;
long long shift;
unsigned bias;
unsigned significandbits = bits - expbits - 1; // -1 for sign bit
@ -60,7 +60,7 @@ static float unpack754(uint64_t i, unsigned bits, unsigned expbits)
// pull the significand
result = (i&((1LL<<significandbits)-1)); // mask
result /= (1LL<<significandbits); // convert back to float
result /= (1LL<<significandbits); // convert back to double
result += 1.0f; // add the one back on
// deal with the exponent
@ -107,15 +107,15 @@ void packCloseStream(PackStream* stream)
free(stream);
}
void packWriteFloat(PackStream* stream, float* value)
void packWriteDouble(PackStream* stream, double* value)
{
uint64_t servalue;
servalue = pack754_32(*value);
servalue = pack754_64(*value);
fwrite(&servalue, sizeof(uint64_t), 1, stream->fd);
}
void packReadFloat(PackStream* stream, float* value)
void packReadDouble(PackStream* stream, double* value)
{
int read;
uint64_t servalue;
@ -123,7 +123,7 @@ void packReadFloat(PackStream* stream, float* value)
read = fread(&servalue, sizeof(uint64_t), 1, stream->fd);
assert(read == 1);
*value = unpack754_32(servalue);
*value = unpack754_64(servalue);
}
void packWriteInt(PackStream* stream, int* value)

View file

@ -11,8 +11,8 @@ PackStream* packReadFile(char* filepath);
PackStream* packWriteFile(char* filepath);
void packCloseStream(PackStream* stream);
void packWriteFloat(PackStream* stream, float* value);
void packReadFloat(PackStream* stream, float* value);
void packWriteDouble(PackStream* stream, double* value);
void packReadDouble(PackStream* stream, double* value);
void packWriteInt(PackStream* stream, int* value);
void packReadInt(PackStream* stream, int* value);

View file

@ -10,13 +10,50 @@
#include "color.h"
#include "system.h"
typedef struct
{
struct
{
unsigned char dirty : 1;
unsigned char edge : 1;
unsigned char callback : 6;
} flags;
union
{
Vector3 location;
struct {
double r;
double g;
double b;
} color;
} data;
double z;
} RenderFragment;
typedef struct
{
int x;
int y;
Vector3 pixel;
Vector3 location;
int callback;
} ScanPoint;
typedef struct
{
f_RenderFragmentCallback function;
void* data;
} FragmentCallback;
struct RenderArea
{
RenderParams params;
int pixel_count;
RenderFragment* pixels;
RenderFragment* scanline_up;
RenderFragment* scanline_down;
ScanPoint* scanline_up;
ScanPoint* scanline_down;
int fragment_callbacks_count;
FragmentCallback fragment_callbacks[64];
int scanline_left;
int scanline_right;
Color background_color;
@ -31,12 +68,23 @@ struct RenderArea
RenderCallbackUpdate callback_update;
};
typedef struct {
int startx;
int endx;
int starty;
int endy;
int finished;
int interrupt;
Thread* thread;
RenderArea* area;
Renderer* renderer;
} RenderChunk;
#define RENDER_INVERSE 1
#define RENDER_WIREFRAME 1
static void _callbackStart(int width, int height, Color background) {}
static void _callbackDraw(int x, int y, Color col) {}
static void _callbackUpdate(float progress) {}
static void _callbackUpdate(double progress) {}
void renderInit()
{
@ -57,8 +105,9 @@ RenderArea* renderCreateArea()
result->params.quality = 5;
result->pixel_count = 1;
result->pixels = malloc(sizeof(RenderFragment));
result->scanline_up = malloc(sizeof(RenderFragment));
result->scanline_down = malloc(sizeof(RenderFragment));
result->fragment_callbacks_count = 0;
result->scanline_up = malloc(sizeof(ScanPoint));
result->scanline_down = malloc(sizeof(ScanPoint));
result->scanline_left = 0;
result->scanline_right = 0;
result->background_color = COLOR_TRANSPARENT;
@ -97,8 +146,8 @@ void renderSetParams(RenderArea* area, RenderParams params)
area->scanline_left = 0;
area->scanline_right = width - 1;
area->scanline_up = realloc(area->scanline_up, sizeof(RenderFragment) * width);
area->scanline_down = realloc(area->scanline_down, sizeof(RenderFragment) * width);
area->scanline_up = realloc(area->scanline_up, sizeof(ScanPoint) * width);
area->scanline_down = realloc(area->scanline_down, sizeof(ScanPoint) * width);
area->dirty_left = width;
area->dirty_right = -1;
@ -114,24 +163,45 @@ void renderSetBackgroundColor(RenderArea* area, Color* col)
area->background_color = *col;
}
static void _clearScanLines(RenderArea* area)
{
int x;
for (x = area->scanline_left; x <= area->scanline_right; x++)
{
area->scanline_up[x].y = -1;
area->scanline_down[x].y = area->params.height * area->params.antialias;
}
area->scanline_left = area->params.width * area->params.antialias;
area->scanline_right = -1;
}
void renderClear(RenderArea* area)
{
RenderFragment* pixel;
int x;
int y;
area->fragment_callbacks_count = 1;
area->fragment_callbacks[0].function = NULL;
area->fragment_callbacks[0].data = NULL;
for (x = 0; x < area->params.width * area->params.antialias; x++)
{
for (y = 0; y < area->params.height * area->params.antialias; y++)
{
pixel = area->pixels + (y * area->params.width * area->params.antialias + x);
pixel->z = -100000000.0;
pixel->vertex.color = area->background_color;
pixel->flags.dirty = 0;
pixel->flags.callback = 0;
pixel->data.color.r = area->background_color.r;
pixel->data.color.g = area->background_color.g;
pixel->data.color.b = area->background_color.b;
}
}
area->scanline_left = 0;
area->scanline_right = area->params.width * area->params.antialias - 1;
_clearScanLines(area);
area->callback_start(area->params.width, area->params.height, area->background_color);
@ -142,26 +212,7 @@ void renderClear(RenderArea* area)
area->dirty_count = 0;
}
/*static int _sortRenderFragment(void const* a, void const* b)
{
float za, zb;
za = ((RenderFragment*)a)->z;
zb = ((RenderFragment*)b)->z;
if (za > zb)
{
return 1;
}
else if (za < zb)
{
return -1;
}
else
{
return 0;
}
}*/
static inline void _setDirtyPixel(RenderArea* area, RenderFragment* fragment, int x, int y)
static inline void _setDirtyPixel(RenderArea* area, int x, int y)
{
if (x < area->dirty_left)
{
@ -196,10 +247,26 @@ static inline Color _getFinalPixel(RenderArea* area, int x, int y)
for (sy = 0; sy < area->params.antialias; sy++)
{
pixel_data = area->pixels + (y * area->params.antialias + sy) * area->params.width * area->params.antialias + (x * area->params.antialias + sx);
col = pixel_data->vertex.color;
result.r += col.r / (float)(area->params.antialias * area->params.antialias);
result.g += col.g / (float)(area->params.antialias * area->params.antialias);
result.b += col.b / (float)(area->params.antialias * area->params.antialias);
if (pixel_data->flags.dirty)
{
if (pixel_data->flags.edge)
{
col = COLOR_RED;
}
else
{
col = COLOR_GREY;
}
}
else
{
col.r = pixel_data->data.color.r;
col.g = pixel_data->data.color.g;
col.b = pixel_data->data.color.b;
}
result.r += col.r / (double)(area->params.antialias * area->params.antialias);
result.g += col.g / (double)(area->params.antialias * area->params.antialias);
result.b += col.b / (double)(area->params.antialias * area->params.antialias);
}
}
@ -248,12 +315,32 @@ static void _setAllDirty(RenderArea* area)
area->dirty_up = area->params.height * area->params.antialias - 1;
}
void renderAddFragment(RenderArea* area, RenderFragment* fragment)
static inline unsigned int _pushCallback(RenderArea* area, FragmentCallback callback)
{
int i;
for (i = 0; i < area->fragment_callbacks_count; i++)
{
if (area->fragment_callbacks[i].function == callback.function && area->fragment_callbacks[i].data == callback.data)
{
return i;
}
}
if (area->fragment_callbacks_count >= 64)
{
return 0;
}
else
{
area->fragment_callbacks[area->fragment_callbacks_count].function = callback.function;
area->fragment_callbacks[area->fragment_callbacks_count].data = callback.data;
return area->fragment_callbacks_count++;
}
}
static void _pushFragment(RenderArea* area, int x, int y, double z, int edge, Vector3 location, int callback)
{
RenderFragment* pixel_data;
int x = fragment->x;
int y = fragment->y;
float z = fragment->z;
if (x >= 0 && x < area->params.width * area->params.antialias && y >= 0 && y < area->params.height * area->params.antialias && z > 1.0)
{
@ -261,98 +348,88 @@ void renderAddFragment(RenderArea* area, RenderFragment* fragment)
if (z > pixel_data->z)
{
*pixel_data = *fragment;
_setDirtyPixel(area, pixel_data, x, y);
pixel_data->flags.dirty = (unsigned char)1;
pixel_data->flags.edge = (unsigned char)edge;
pixel_data->flags.callback = (unsigned char)callback;
pixel_data->data.location = location;
pixel_data->z = z;
_setDirtyPixel(area, x, y);
}
}
}
void renderPushFragment(RenderArea* area, int x, int y, float z, Vertex* vertex)
{
RenderFragment fragment;
fragment.x = x;
fragment.y = y;
fragment.z = z;
fragment.vertex = *vertex;
renderAddFragment(area, &fragment);
}
static void __vertexGetDiff(Vertex* v1, Vertex* v2, Vertex* result)
static void _scanGetDiff(ScanPoint* v1, ScanPoint* v2, ScanPoint* result)
{
result->pixel.x = v2->pixel.x - v1->pixel.x;
result->pixel.y = v2->pixel.y - v1->pixel.y;
result->pixel.z = v2->pixel.z - v1->pixel.z;
result->location.x = v2->location.x - v1->location.x;
result->location.y = v2->location.y - v1->location.y;
result->location.z = v2->location.z - v1->location.z;
result->color.r = v2->color.r - v1->color.r;
result->color.g = v2->color.g - v1->color.g;
result->color.b = v2->color.b - v1->color.b;
result->color.a = v2->color.a - v1->color.a;
result->callback = v1->callback;
result->callback_data = v1->callback_data;
}
static void __vertexInterpolate(Vertex* v1, Vertex* diff, float value, Vertex* result)
static void _scanInterpolate(ScanPoint* v1, ScanPoint* diff, double value, ScanPoint* result)
{
result->pixel.x = v1->pixel.x + diff->pixel.x * value;
result->pixel.y = v1->pixel.y + diff->pixel.y * value;
result->pixel.z = v1->pixel.z + diff->pixel.z * value;
result->location.x = v1->location.x + diff->location.x * value;
result->location.y = v1->location.y + diff->location.y * value;
result->location.z = v1->location.z + diff->location.z * value;
result->color.r = v1->color.r + diff->color.r * value;
result->color.g = v1->color.g + diff->color.g * value;
result->color.b = v1->color.b + diff->color.b * value;
result->color.a = v1->color.a + diff->color.a * value;
result->callback = v1->callback;
result->callback_data = v1->callback_data;
}
static void __pushScanLinePoint(RenderArea* area, RenderFragment point)
static void _pushScanPoint(RenderArea* area, ScanPoint* point)
{
if (point.x < 0 || point.x >= area->params.width * area->params.antialias)
point->x = (int)floor(point->pixel.x);
point->y = (int)floor(point->pixel.y);
if (point->x < 0 || point->x >= area->params.width * area->params.antialias)
{
return;
}
if (point.x > area->scanline_right)
if (point->x > area->scanline_right)
{
area->scanline_right = point.x;
area->scanline_up[area->scanline_right] = point;
area->scanline_down[area->scanline_right] = point;
if (point.x < area->scanline_left)
area->scanline_right = point->x;
area->scanline_up[area->scanline_right] = *point;
area->scanline_down[area->scanline_right] = *point;
if (point->x < area->scanline_left)
{
area->scanline_left = point.x;
area->scanline_left = point->x;
}
}
else if (point.x < area->scanline_left)
else if (point->x < area->scanline_left)
{
area->scanline_left = point.x;
area->scanline_up[area->scanline_left] = point;
area->scanline_down[area->scanline_left] = point;
area->scanline_left = point->x;
area->scanline_up[area->scanline_left] = *point;
area->scanline_down[area->scanline_left] = *point;
}
else
{
if (point.y > area->scanline_up[point.x].y)
if (point->y > area->scanline_up[point->x].y)
{
area->scanline_up[point.x] = point;
area->scanline_up[point->x] = *point;
}
if (point.y < area->scanline_down[point.x].y)
if (point->y < area->scanline_down[point->x].y)
{
area->scanline_down[point.x] = point;
area->scanline_down[point->x] = *point;
}
}
}
static void __pushScanLineEdge(RenderArea* area, Vector3 v1, Vector3 v2, Vertex* vertex1, Vertex* vertex2)
static void _pushScanLineEdge(RenderArea* area, ScanPoint* point1, ScanPoint* point2)
{
float dx, dy, dz, fx;
Vertex diff;
int startx = lround(v1.x);
int endx = lround(v2.x);
double dx, fx;
ScanPoint diff, point;
int startx = lround(point1->pixel.x);
int endx = lround(point2->pixel.x);
int curx;
RenderFragment fragment;
if (endx < startx)
{
__pushScanLineEdge(area, v2, v1, vertex2, vertex1);
_pushScanLineEdge(area, point2, point1);
}
else if (endx < 0 || startx >= area->params.width * area->params.antialias)
{
@ -360,19 +437,8 @@ static void __pushScanLineEdge(RenderArea* area, Vector3 v1, Vector3 v2, Vertex*
}
else if (startx == endx)
{
fragment.x = startx;
fragment.y = lround(v1.y);
fragment.z = v1.z;
fragment.vertex = *vertex1;
__pushScanLinePoint(area, fragment);
fragment.x = endx;
fragment.y = lround(v2.y);
fragment.z = v2.z;
fragment.vertex = *vertex2;
__pushScanLinePoint(area, fragment);
_pushScanPoint(area, point1);
_pushScanPoint(area, point2);
}
else
{
@ -385,50 +451,35 @@ static void __pushScanLineEdge(RenderArea* area, Vector3 v1, Vector3 v2, Vertex*
endx = area->params.width * area->params.antialias - 1;
}
dx = v2.x - v1.x;
dy = v2.y - v1.y;
dz = v2.z - v1.z;
__vertexGetDiff(vertex1, vertex2, &diff);
dx = point2->pixel.x - point1->pixel.x;
_scanGetDiff(point1, point2, &diff);
for (curx = startx; curx <= endx; curx++)
{
fx = (float)curx + 0.5;
if (fx < v1.x)
fx = (double)curx + 0.5;
if (fx < point1->pixel.x)
{
fx = v1.x;
fx = point1->pixel.x;
}
else if (fx > v2.x)
else if (fx > point2->pixel.x)
{
fx = v2.x;
fx = point2->pixel.x;
}
fx = fx - v1.x;
fragment.x = curx;
fragment.y = lround(v1.y + dy * fx / dx);
fragment.z = v1.z + dz * fx / dx;
__vertexInterpolate(vertex1, &diff, fx / dx, &(fragment.vertex));
fx = fx - point1->pixel.x;
_scanInterpolate(point1, &diff, fx / dx, &point);
__pushScanLinePoint(area, fragment);
/*point.pixel.x = (double)curx;*/
_pushScanPoint(area, &point);
}
}
}
static void __clearScanLines(RenderArea* area)
{
int x;
for (x = area->scanline_left; x <= area->scanline_right; x++)
{
area->scanline_up[x].y = -1;
area->scanline_down[x].y = area->params.height * area->params.antialias;
}
area->scanline_left = area->params.width * area->params.antialias;
area->scanline_right = -1;
}
static void __renderScanLines(RenderArea* area)
static void _renderScanLines(RenderArea* area)
{
int x, starty, endy, cury;
Vertex diff;
float dy, dz, fy;
RenderFragment up, down, current;
ScanPoint diff;
double dy, fy;
ScanPoint up, down, current;
if (area->scanline_right > 0)
{
@ -454,64 +505,68 @@ static void __renderScanLines(RenderArea* area)
endy = area->params.height * area->params.antialias - 1;
}
dy = (float)(up.y - down.y);
dz = up.z - down.z;
__vertexGetDiff(&down.vertex, &up.vertex, &diff);
dy = up.pixel.y - down.pixel.y;
_scanGetDiff(&down, &up, &diff);
current.x = x;
for (cury = starty; cury <= endy; cury++)
{
fy = (float)cury - down.y;
fy = (double)cury + 0.5;
if (fy < down.pixel.y)
{
fy = down.pixel.y;
}
else if (fy > up.pixel.y)
{
fy = up.pixel.y;
}
fy = fy - down.pixel.y;
current.y = cury;
current.z = down.z + dz * fy / dy;
__vertexInterpolate(&down.vertex, &diff, fy / dy, &current.vertex);
_scanInterpolate(&down, &diff, fy / dy, &current);
#ifdef RENDER_WIREFRAME
if (cury == starty || cury == endy)
_pushFragment(area, current.x, current.y, current.pixel.z, (cury == starty || cury == endy), current.location, current.callback);
}
}
}
}
void renderPushTriangle(RenderArea* area, Vector3 pixel1, Vector3 pixel2, Vector3 pixel3, Vector3 location1, Vector3 location2, Vector3 location3, f_RenderFragmentCallback callback, void* callback_data)
{
current.vertex.color = COLOR_RED;
}
#endif
renderAddFragment(area, &current);
}
}
}
}
void renderPushTriangle(RenderArea* area, Vertex* v1, Vertex* v2, Vertex* v3, Vector3 p1, Vector3 p2, Vector3 p3)
{
float limit_width = (float)(area->params.width * area->params.antialias - 1);
float limit_height = (float)(area->params.height * area->params.antialias - 1);
FragmentCallback fragment_callback = {callback, callback_data};
ScanPoint point1, point2, point3;
double limit_width = (double)(area->params.width * area->params.antialias - 1);
double limit_height = (double)(area->params.height * area->params.antialias - 1);
/* Filter if outside screen */
if (p1.z < 1.0 || p2.z < 1.0 || p3.z < 1.0 || (p1.x < 0.0 && p2.x < 0.0 && p3.x < 0.0) || (p1.y < 0.0 && p2.y < 0.0 && p3.y < 0.0) || (p1.x > limit_width && p2.x > limit_width && p3.x > limit_width) || (p1.y > limit_height && p2.y > limit_height && p3.y > limit_height))
if (pixel1.z < 1.0 || pixel2.z < 1.0 || pixel3.z < 1.0 || (pixel1.x < 0.0 && pixel2.x < 0.0 && pixel3.x < 0.0) || (pixel1.y < 0.0 && pixel2.y < 0.0 && pixel3.y < 0.0) || (pixel1.x > limit_width && pixel2.x > limit_width && pixel3.x > limit_width) || (pixel1.y > limit_height && pixel2.y > limit_height && pixel3.y > limit_height))
{
return;
}
__clearScanLines(area);
__pushScanLineEdge(area, p1, p2, v1, v2);
__pushScanLineEdge(area, p2, p3, v2, v3);
__pushScanLineEdge(area, p3, p1, v3, v1);
point1.pixel = pixel1;
point1.location = location1;
point1.callback = _pushCallback(area, fragment_callback);
point2.pixel = pixel2;
point2.location = location2;
point2.callback = _pushCallback(area, fragment_callback);
point3.pixel = pixel3;
point3.location = location3;
point3.callback = _pushCallback(area, fragment_callback);
_clearScanLines(area);
_pushScanLineEdge(area, &point1, &point2);
_pushScanLineEdge(area, &point2, &point3);
_pushScanLineEdge(area, &point3, &point1);
mutexAcquire(area->lock);
__renderScanLines(area);
_renderScanLines(area);
mutexRelease(area->lock);
}
typedef struct {
int startx;
int endx;
int starty;
int endy;
int finished;
int interrupt;
Thread* thread;
RenderArea* area;
Renderer* renderer;
} RenderChunk;
void* _renderPostProcessChunk(void* data)
{
int x, y;
@ -527,13 +582,28 @@ void* _renderPostProcessChunk(void* data)
for (x = chunk->startx; x <= chunk->endx; x++)
{
fragment = chunk->area->pixels + (y * chunk->area->params.width * chunk->area->params.antialias + x);
if (fragment->vertex.callback)
if (fragment->flags.dirty)
{
if (fragment->vertex.callback(fragment, chunk->renderer, fragment->vertex.callback_data))
FragmentCallback callback;
Color col;
callback = chunk->area->fragment_callbacks[fragment->flags.callback];
if (callback.function)
{
colorNormalize(&fragment->vertex.color);
_setDirtyPixel(chunk->area, fragment, x, y);
col = callback.function(chunk->renderer, fragment->data.location, callback.data);
colorNormalize(&col);
}
else
{
col = COLOR_BLACK;
}
fragment->data.color.r = col.r;
fragment->data.color.g = col.g;
fragment->data.color.b = col.b;
fragment->flags.dirty = 0;
_setDirtyPixel(chunk->area, x, y);
}
/* chunk->area->progress_pixels++; */
}
@ -638,7 +708,7 @@ void renderPostProcess(RenderArea* area, Renderer* renderer, int nbchunks)
if (++loops >= 10)
{
mutexAcquire(area->lock);
/*_progress = (float)_progress_pixels / (float)_pixel_count;*/
/*_progress = (double)_progress_pixels / (double)_pixel_count;*/
_processDirtyPixels(area);
mutexRelease(area->lock);

View file

@ -20,9 +20,7 @@ void renderSetBackgroundColor(RenderArea* area, Color* col);
void renderClear(RenderArea* area);
void renderUpdate(RenderArea* area);
void renderAddFragment(RenderArea* area, RenderFragment* fragment);
void renderPushFragment(RenderArea* area, int x, int y, float z, Vertex* vertex);
void renderPushTriangle(RenderArea* area, Vertex* v1, Vertex* v2, Vertex* v3, Vector3 p1, Vector3 p2, Vector3 p3);
void renderPushTriangle(RenderArea* area, Vector3 pixel1, Vector3 pixel2, Vector3 pixel3, Vector3 location1, Vector3 location2, Vector3 location3, f_RenderFragmentCallback callback, void* callback_data);
void renderPostProcess(RenderArea* area, Renderer* renderer, int nbchunks);
int renderSaveToFile(RenderArea* area, const char* path);

View file

@ -17,12 +17,12 @@ static void* _renderFirstPass(void* data)
return NULL;
}
static int _addRenderProgress(Renderer* renderer, float progress)
static int _addRenderProgress(Renderer* renderer, double progress)
{
return !renderer->render_interrupt;
}
static float _getPrecision(Renderer* renderer, Vector3 location)
static double _getPrecision(Renderer* renderer, Vector3 location)
{
return 0.001;
}
@ -37,21 +37,21 @@ static Vector3 _unprojectPoint(Renderer* renderer, Vector3 point)
return point;
}
static void _pushTriangle(Renderer* renderer, Vertex* v1, Vertex* v2, Vertex* v3)
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->location);
p2 = renderer->projectPoint(renderer, v2->location);
p3 = renderer->projectPoint(renderer, v3->location);
p1 = renderer->projectPoint(renderer, v1);
p2 = renderer->projectPoint(renderer, v2);
p3 = renderer->projectPoint(renderer, v3);
renderPushTriangle(renderer->render_area, v1, v2, v3, p1, p2, p3);
renderPushTriangle(renderer->render_area, p1, p2, p3, v1, v2, v3, callback, callback_data);
}
static void _pushQuad(Renderer* renderer, Vertex* v1, Vertex* v2, Vertex* v3, Vertex* v4)
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);
renderer->pushTriangle(renderer, v4, v1, v3);
renderer->pushTriangle(renderer, v2, v3, v1, callback, callback_data);
renderer->pushTriangle(renderer, v4, v1, v3, callback, callback_data);
}
static void _alterLight(Renderer* renderer, LightDefinition* light, Vector3 location)
@ -73,7 +73,7 @@ static RayCastingResult _rayWalking(Renderer* renderer, Vector3 location, Vector
return _RAYCASTING_NULL;
}
static float _getTerrainHeight(Renderer* renderer, float x, float z)
static double _getTerrainHeight(Renderer* renderer, double x, double z)
{
return 0.0;
}
@ -83,7 +83,7 @@ static HeightInfo _getWaterHeightInfo(Renderer* renderer)
return _WATER_HEIGHT_INFO;
}
static Color _applyTextures(Renderer* renderer, Vector3 location, float precision)
static Color _applyTextures(Renderer* renderer, Vector3 location, double precision)
{
return COLOR_TRANSPARENT;
}

View file

@ -20,21 +20,21 @@ struct Renderer
/* Render related */
RenderArea* render_area;
float render_progress;
double render_progress;
int render_interrupt;
int is_rendering;
float (*getPrecision)(Renderer* renderer, Vector3 location);
double (*getPrecision)(Renderer* renderer, Vector3 location);
Vector3 (*projectPoint)(Renderer* renderer, Vector3 point);
Vector3 (*unprojectPoint)(Renderer* renderer, Vector3 point);
int (*addRenderProgress)(Renderer* renderer, float progress);
void (*pushTriangle)(Renderer* renderer, Vertex* v1, Vertex* v2, Vertex* v3);
void (*pushQuad)(Renderer* renderer, Vertex* v1, Vertex* v2, Vertex* v3, Vertex* v4);
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);
/* Scenery related */
RayCastingResult (*rayWalking)(Renderer* renderer, Vector3 location, Vector3 direction, int terrain, int water, int sky, int clouds);
float (*getTerrainHeight)(Renderer* renderer, float x, float z);
double (*getTerrainHeight)(Renderer* renderer, double x, double z);
HeightInfo (*getWaterHeightInfo)(Renderer* renderer);
Color (*applyTextures)(Renderer* renderer, Vector3 location, float precision);
Color (*applyTextures)(Renderer* renderer, Vector3 location, double precision);
Color (*applyAtmosphere)(Renderer* renderer, Vector3 location, Color base);
Color (*applyClouds)(Renderer* renderer, Color base, Vector3 start, Vector3 end);

View file

@ -213,21 +213,9 @@ void sceneryGetWater(WaterDefinition* water)
void sceneryRenderFirstPass(Renderer* renderer)
{
/*if (!renderSetNextProgressStep(0.0, 0.01))
{
return;
}*/
skyRender(&_sky, renderer);
/*if (!renderSetNextProgressStep(0.01, 0.085))
{
return;
}*/
terrainRender(&_terrain, renderer);
/*if (!renderSetNextProgressStep(0.085, 0.1))
{
return;
}*/
waterRender(&_water, renderer);
skyRender(&_sky, renderer);
}
@ -282,7 +270,7 @@ static RayCastingResult _rayWalking(Renderer* renderer, Vector3 location, Vector
return result;
}
static float _getTerrainHeight(Renderer* renderer, float x, float z)
static double _getTerrainHeight(Renderer* renderer, double x, double z)
{
return terrainGetHeight(&_terrain, x, z);
}
@ -292,7 +280,7 @@ static HeightInfo _getWaterHeightInfo(Renderer* renderer)
return waterGetHeightInfo(&_water);
}
static Color _applyTextures(Renderer* renderer, Vector3 location, float precision)
static Color _applyTextures(Renderer* renderer, Vector3 location, double precision)
{
return texturesGetColor(&_textures, renderer, location.x, location.z, precision);
}
@ -322,7 +310,7 @@ static Vector3 _unprojectPoint(Renderer* renderer, Vector3 point)
return cameraUnproject(&renderer->render_camera, renderer, point);
}
static float _getPrecision(Renderer* renderer, Vector3 location)
static double _getPrecision(Renderer* renderer, Vector3 location)
{
Vector3 projected;
@ -330,7 +318,7 @@ static float _getPrecision(Renderer* renderer, Vector3 location)
projected.x += 1.0;
//projected.y += 1.0;
return v3Norm(v3Sub(cameraUnproject(&renderer->render_camera, renderer, projected), location)); // / (float)render_quality;
return v3Norm(v3Sub(cameraUnproject(&renderer->render_camera, renderer, projected), location)); // / (double)render_quality;
}
Renderer sceneryCreateStandardRenderer()

View file

@ -8,29 +8,12 @@
extern "C" {
#endif
struct RenderFragment;
struct Renderer;
typedef struct LightDefinition LightDefinition;
typedef struct LightStatus LightStatus;
typedef int(*f_RenderFragmentCallback)(struct RenderFragment*, struct Renderer* renderer, void* data);
typedef struct
{
Vector3 location;
Color color;
f_RenderFragmentCallback callback;
void* callback_data;
} Vertex;
typedef struct RenderFragment
{
short int x;
short int y;
float z;
Vertex vertex;
} RenderFragment;
typedef Color (*f_RenderFragmentCallback)(struct Renderer* renderer, Vector3 location, void* data);
typedef struct
{
@ -52,13 +35,13 @@ typedef struct
typedef struct
{
Color base;
float reflection;
float shininess;
double reflection;
double shininess;
} SurfaceMaterial;
typedef void (*RenderCallbackStart)(int width, int height, Color background);
typedef void (*RenderCallbackDraw)(int x, int y, Color col);
typedef void (*RenderCallbackUpdate)(float progress);
typedef void (*RenderCallbackUpdate)(double progress);
typedef struct RenderArea RenderArea;
@ -72,29 +55,29 @@ typedef RayCastingResult (*RayCastingFunction)(Vector3 start, Vector3 direction)
typedef struct
{
float min_height;
float max_height;
float base_height;
double min_height;
double max_height;
double base_height;
} HeightInfo;
typedef struct
{
Vector3 location;
float yaw;
float pitch;
float roll;
double yaw;
double pitch;
double roll;
Vector3 target;
Vector3 forward;
Vector3 right;
Vector3 up;
float width;
float height;
float yfov;
float xratio;
float znear;
float zfar;
double width;
double height;
double yfov;
double xratio;
double znear;
double zfar;
Matrix4 project;
Matrix4 unproject;

View file

@ -23,28 +23,28 @@ void skyQuit()
void skySave(PackStream* stream, SkyDefinition* definition)
{
packWriteFloat(stream, &definition->daytime);
packWriteDouble(stream, &definition->daytime);
colorGradationSave(stream, definition->sun_color);
packWriteFloat(stream, &definition->sun_radius);
packWriteFloat(stream, &definition->sun_halo_size);
packWriteDouble(stream, &definition->sun_radius);
packWriteDouble(stream, &definition->sun_halo_size);
curveSave(stream, definition->sun_halo_profile);
colorGradationSave(stream, definition->zenith_color);
colorGradationSave(stream, definition->haze_color);
packWriteFloat(stream, &definition->haze_height);
packWriteFloat(stream, &definition->haze_smoothing);
packWriteDouble(stream, &definition->haze_height);
packWriteDouble(stream, &definition->haze_smoothing);
}
void skyLoad(PackStream* stream, SkyDefinition* definition)
{
packReadFloat(stream, &definition->daytime);
packReadDouble(stream, &definition->daytime);
colorGradationLoad(stream, definition->sun_color);
packReadFloat(stream, &definition->sun_radius);
packReadFloat(stream, &definition->sun_halo_size);
packReadDouble(stream, &definition->sun_radius);
packReadDouble(stream, &definition->sun_halo_size);
curveLoad(stream, definition->sun_halo_profile);
colorGradationLoad(stream, definition->zenith_color);
colorGradationLoad(stream, definition->haze_color);
packReadFloat(stream, &definition->haze_height);
packReadFloat(stream, &definition->haze_smoothing);
packReadDouble(stream, &definition->haze_height);
packReadDouble(stream, &definition->haze_smoothing);
skyValidateDefinition(definition);
}
@ -108,7 +108,7 @@ void skyValidateDefinition(SkyDefinition* definition)
int skyGetLights(SkyDefinition* sky, LightDefinition* lights, int max_lights)
{
float sun_angle;
double sun_angle;
Vector3 sun_direction;
int nblights = 0;
@ -152,7 +152,7 @@ int skyGetLights(SkyDefinition* sky, LightDefinition* lights, int max_lights)
Color skyGetColor(SkyDefinition* definition, Renderer* renderer, Vector3 eye, Vector3 look)
{
float dist;
double dist;
Vector3 sun_position;
Color sun_color, sky_color;
@ -183,43 +183,35 @@ Color skyGetColor(SkyDefinition* definition, Renderer* renderer, Vector3 eye, Ve
}
}
static int _postProcessFragment(RenderFragment* fragment, Renderer* renderer, void* data)
static Color _postProcessFragment(Renderer* renderer, Vector3 location, void* data)
{
Vector3 location, direction;
Vector3 direction;
Color result;
SkyDefinition* definition;
definition = (SkyDefinition*)data;
location = fragment->vertex.location;
direction = v3Sub(location, renderer->camera_location);
result = skyGetColor(definition, renderer, renderer->camera_location, v3Normalize(direction));
result = renderer->applyClouds(renderer, result, renderer->camera_location, v3Add(renderer->camera_location, v3Scale(direction, 10.0)));
fragment->vertex.color = result;
return 1;
return result;
}
void skyRender(SkyDefinition* definition, Renderer* renderer)
{
int res_i, res_j;
int i, j;
float step_i, step_j;
float current_i, current_j;
Vertex vertex1, vertex2, vertex3, vertex4;
Color col;
double step_i, step_j;
double current_i, current_j;
Vector3 vertex1, vertex2, vertex3, vertex4;
Vector3 direction;
res_i = renderer->render_quality * 40;
res_j = renderer->render_quality * 20;
step_i = M_PI * 2.0 / (float)res_i;
step_j = M_PI / (float)res_j;
col.r = 0.0;
col.g = 0.0;
col.a = 1.0;
step_i = M_PI * 2.0 / (double)res_i;
step_j = M_PI / (double)res_j;
for (j = 0; j < res_j; j++)
{
@ -228,50 +220,34 @@ void skyRender(SkyDefinition* definition, Renderer* renderer)
return;
}
current_j = (float)(j - res_j / 2) * step_j;
current_j = (double)(j - res_j / 2) * step_j;
for (i = 0; i < res_i; i++)
{
current_i = (float)i * step_i;
current_i = (double)i * step_i;
direction.x = SPHERE_SIZE * cos(current_i) * cos(current_j);
direction.y = SPHERE_SIZE * sin(current_j);
direction.z = SPHERE_SIZE * sin(current_i) * cos(current_j);
vertex1.location = v3Add(renderer->camera_location, direction);
col.b = sin(direction.x) * sin(direction.x) * cos(direction.z) * cos(direction.z);
vertex1.color = col;
vertex1.callback = _postProcessFragment;
vertex1.callback_data = definition;
vertex1 = v3Add(renderer->camera_location, direction);
direction.x = SPHERE_SIZE * cos(current_i + step_i) * cos(current_j);
direction.y = SPHERE_SIZE * sin(current_j);
direction.z = SPHERE_SIZE * sin(current_i + step_i) * cos(current_j);
vertex2.location = v3Add(renderer->camera_location, direction);
col.b = sin(direction.x) * sin(direction.x) * cos(direction.z) * cos(direction.z);
vertex2.color = col;
vertex2.callback = _postProcessFragment;
vertex2.callback_data = definition;
vertex2 = v3Add(renderer->camera_location, direction);
direction.x = SPHERE_SIZE * cos(current_i + step_i) * cos(current_j + step_j);
direction.y = SPHERE_SIZE * sin(current_j + step_j);
direction.z = SPHERE_SIZE * sin(current_i + step_i) * cos(current_j + step_j);
vertex3.location = v3Add(renderer->camera_location, direction);
col.b = sin(direction.x) * sin(direction.x) * cos(direction.z) * cos(direction.z);
vertex3.color = col;
vertex3.callback = _postProcessFragment;
vertex3.callback_data = definition;
vertex3 = v3Add(renderer->camera_location, direction);
direction.x = SPHERE_SIZE * cos(current_i) * cos(current_j + step_j);
direction.y = SPHERE_SIZE * sin(current_j + step_j);
direction.z = SPHERE_SIZE * sin(current_i) * cos(current_j + step_j);
vertex4.location = v3Add(renderer->camera_location, direction);
col.b = sin(direction.x) * sin(direction.x) * cos(direction.z) * cos(direction.z);
vertex4.color = col;
vertex4.callback = _postProcessFragment;
vertex4.callback_data = definition;
vertex4 = v3Add(renderer->camera_location, direction);
/* TODO Triangles at poles */
renderer->pushQuad(renderer, &vertex1, &vertex4, &vertex3, &vertex2);
renderer->pushQuad(renderer, vertex1, vertex4, vertex3, vertex2, _postProcessFragment, definition);
}
}
}
@ -279,7 +255,7 @@ void skyRender(SkyDefinition* definition, Renderer* renderer)
Vector3 skyGetSunDirection(SkyDefinition* definition)
{
Vector3 result;
float sun_angle = (definition->daytime + 0.75) * M_PI * 2.0;
double sun_angle = (definition->daytime + 0.75) * M_PI * 2.0;
result.x = cos(sun_angle);
result.y = sin(sun_angle);
result.z = 0.0;

View file

@ -12,15 +12,15 @@ extern "C" {
typedef struct
{
float daytime;
double daytime;
ColorGradation* sun_color;
float sun_radius;
float sun_halo_size;
double sun_radius;
double sun_halo_size;
Curve* sun_halo_profile;
ColorGradation* zenith_color;
ColorGradation* haze_color;
float haze_height;
float haze_smoothing;
double haze_height;
double haze_smoothing;
ColorGradation* _sky_gradation;
} SkyDefinition;

View file

@ -25,8 +25,8 @@ void terrainSave(PackStream* stream, TerrainDefinition* definition)
int i;
noiseSaveGenerator(stream, definition->height_noise);
packWriteFloat(stream, &definition->height_factor);
packWriteFloat(stream, &definition->scaling);
packWriteDouble(stream, &definition->height_factor);
packWriteDouble(stream, &definition->scaling);
packWriteInt(stream, &definition->height_modifiers_count);
for (i = 0; i < definition->height_modifiers_count; i++)
@ -41,8 +41,8 @@ void terrainLoad(PackStream* stream, TerrainDefinition* definition)
HeightModifier* modifier;
noiseLoadGenerator(stream, definition->height_noise);
packReadFloat(stream, &definition->height_factor);
packReadFloat(stream, &definition->scaling);
packReadDouble(stream, &definition->height_factor);
packReadDouble(stream, &definition->scaling);
while (definition->height_modifiers_count > 0)
{
@ -139,7 +139,7 @@ void terrainDelModifier(TerrainDefinition* definition, int modifier_position)
}
}
static inline float _getHeight(TerrainDefinition* definition, float x, float z)
static inline double _getHeight(TerrainDefinition* definition, double x, double z)
{
Vector3 location;
int i;
@ -156,7 +156,7 @@ static inline float _getHeight(TerrainDefinition* definition, float x, float z)
return location.y;
}
static inline float _getHeightDetail(TerrainDefinition* definition, float x, float z, float detail)
static inline double _getHeightDetail(TerrainDefinition* definition, double x, double z, double detail)
{
Vector3 location;
int i;
@ -173,7 +173,7 @@ static inline float _getHeightDetail(TerrainDefinition* definition, float x, flo
return location.y;
}
static inline Vector3 _getPoint(TerrainDefinition* definition, float x, float z)
static inline Vector3 _getPoint(TerrainDefinition* definition, double x, double z)
{
Vector3 result;
@ -187,7 +187,7 @@ static inline Vector3 _getPoint(TerrainDefinition* definition, float x, float z)
Color terrainLightFilter(TerrainDefinition* definition, Renderer* renderer, Color light, Vector3 location, Vector3 light_location, Vector3 direction_to_light)
{
Vector3 inc_vector;
float inc_value, inc_base, inc_factor, height, diff, light_factor, smoothing, length;
double inc_value, inc_base, inc_factor, height, diff, light_factor, smoothing, length;
direction_to_light = v3Normalize(direction_to_light);
if (fabs(direction_to_light.x) < 0.0001 && fabs(direction_to_light.z) < 0.0001)
@ -205,7 +205,7 @@ Color terrainLightFilter(TerrainDefinition* definition, Renderer* renderer, Colo
light.b *= (0.05 + direction_to_light.y) / 0.05;
}
inc_factor = (float)renderer->render_quality;
inc_factor = (double)renderer->render_quality;
inc_base = 1.0;
inc_value = inc_base / inc_factor;
smoothing = 0.03 * inc_factor;
@ -253,7 +253,7 @@ Color terrainLightFilter(TerrainDefinition* definition, Renderer* renderer, Colo
}
}
static Color _getColor(TerrainDefinition* definition, Renderer* renderer, Vector3 point, float precision)
static Color _getColor(TerrainDefinition* definition, Renderer* renderer, Vector3 point, double precision)
{
Color color;
@ -267,10 +267,10 @@ static Color _getColor(TerrainDefinition* definition, Renderer* renderer, Vector
int terrainProjectRay(TerrainDefinition* definition, Renderer* renderer, Vector3 start, Vector3 direction, Vector3* hit_point, Color* hit_color)
{
Vector3 inc_vector;
float inc_value, inc_base, inc_factor, height, diff, lastdiff, length;
double inc_value, inc_base, inc_factor, height, diff, lastdiff, length;
direction = v3Normalize(direction);
inc_factor = (float)renderer->render_quality;
inc_factor = (double)renderer->render_quality;
inc_base = 1.0;
inc_value = inc_base / inc_factor;
lastdiff = start.y - _getHeight(definition, start.x, start.z);
@ -317,61 +317,40 @@ int terrainProjectRay(TerrainDefinition* definition, Renderer* renderer, Vector3
return 0;
}
static int _postProcessFragment(RenderFragment* fragment, Renderer* renderer, void* data)
static Color _postProcessFragment(Renderer* renderer, Vector3 point, void* data)
{
Vector3 point;
float precision;
double precision;
TerrainDefinition* definition;
definition = (TerrainDefinition*)data;
point = fragment->vertex.location;
point = _getPoint(definition, point.x, point.z);
precision = renderer->getPrecision(renderer, point);
fragment->vertex.color = _getColor(definition, renderer, point, precision);
return 1;
return _getColor(definition, renderer, point, precision);
}
static Vertex _getFirstPassVertex(TerrainDefinition* definition, float x, float z, float detail)
static void _renderQuad(TerrainDefinition* definition, Renderer* renderer, double x, double z, double size, double water_height)
{
Vertex result;
float value;
Vector3 v1, v2, v3, v4;
result.location = _getPoint(definition, x, z);
value = sin(x) * sin(x) * cos(z) * cos(z);
result.color.r = value;
result.color.g = value;
result.color.b = value;
result.color.a = 1.0;
result.callback = _postProcessFragment;
result.callback_data = definition;
v1 = _getPoint(definition, x, z);
v2 = _getPoint(definition, x, z + size);
v3 = _getPoint(definition, x + size, z + size);
v4 = _getPoint(definition, x + size, z);
return result;
}
static void _renderQuad(TerrainDefinition* definition, Renderer* renderer, float x, float z, float size, float water_height)
if (v1.y > water_height || v2.y > water_height || v3.y > water_height || v4.y > water_height)
{
Vertex v1, v2, v3, v4;
v1 = _getFirstPassVertex(definition, x, z, size);
v2 = _getFirstPassVertex(definition, x, z + size, size);
v3 = _getFirstPassVertex(definition, x + size, z + size, size);
v4 = _getFirstPassVertex(definition, x + size, z, size);
if (v1.location.y > water_height || v2.location.y > water_height || v3.location.y > water_height || v4.location.y > water_height)
{
renderer->pushQuad(renderer, &v1, &v2, &v3, &v4);
renderer->pushQuad(renderer, v1, v2, v3, v4, _postProcessFragment, definition);
}
}
float terrainGetHeight(TerrainDefinition* definition, float x, float z)
double terrainGetHeight(TerrainDefinition* definition, double x, double z)
{
return _getHeight(definition, x, z);
}
float terrainGetHeightNormalized(TerrainDefinition* definition, float x, float z)
double terrainGetHeightNormalized(TerrainDefinition* definition, double x, double z)
{
if (definition->_max_height == 0.0)
{
@ -383,7 +362,7 @@ float terrainGetHeightNormalized(TerrainDefinition* definition, float x, float z
}
}
Color terrainGetColor(TerrainDefinition* definition, Renderer* renderer, float x, float z, float detail)
Color terrainGetColor(TerrainDefinition* definition, Renderer* renderer, double x, double z, double detail)
{
Vector3 point = _getPoint(definition, x, z);
return _getColor(definition, renderer, point, detail);
@ -392,14 +371,14 @@ Color terrainGetColor(TerrainDefinition* definition, Renderer* renderer, float x
void terrainRender(TerrainDefinition* definition, Renderer* renderer)
{
int chunk_factor, chunk_count, i;
float cx = renderer->camera_location.x;
float cz = renderer->camera_location.z;
float min_chunk_size, visible_chunk_size;
float radius_int, radius_ext, chunk_size;
float water_height;
double cx = renderer->camera_location.x;
double cz = renderer->camera_location.z;
double min_chunk_size, visible_chunk_size;
double radius_int, radius_ext, chunk_size;
double water_height;
min_chunk_size = 0.1 / (float)renderer->render_quality;
visible_chunk_size = 0.05 / (float)renderer->render_quality;
min_chunk_size = 0.1 / (double)renderer->render_quality;
visible_chunk_size = 0.05 / (double)renderer->render_quality;
chunk_factor = 1;
chunk_count = 2;

View file

@ -16,12 +16,12 @@ extern "C" {
typedef struct
{
NoiseGenerator* height_noise;
float height_factor;
float scaling;
double height_factor;
double scaling;
int height_modifiers_count;
HeightModifier* height_modifiers[TERRAIN_MAX_MODIFIERS];
float _max_height;
double _max_height;
} TerrainDefinition;
void terrainInit();
@ -39,9 +39,9 @@ void terrainDelModifier(TerrainDefinition* definition, int modifier_position);
Color terrainLightFilter(TerrainDefinition* definition, Renderer* renderer, Color light, Vector3 location, Vector3 light_location, Vector3 direction_to_light);
int terrainProjectRay(TerrainDefinition* definition, Renderer* renderer, Vector3 start, Vector3 direction, Vector3* hit_point, Color* hit_color);
float terrainGetHeight(TerrainDefinition* definition, float x, float z);
float terrainGetHeightNormalized(TerrainDefinition* definition, float x, float z);
Color terrainGetColor(TerrainDefinition* definition, Renderer* renderer, float x, float z, float detail);
double terrainGetHeight(TerrainDefinition* definition, double x, double z);
double terrainGetHeightNormalized(TerrainDefinition* definition, double x, double z);
Color terrainGetColor(TerrainDefinition* definition, Renderer* renderer, double x, double z, double detail);
void terrainRender(TerrainDefinition* definition, Renderer* renderer);
#ifdef __cplusplus

View file

@ -16,7 +16,7 @@ static TextureLayerDefinition _NULL_LAYER;
typedef struct
{
float thickness;
double thickness;
Vector3 location;
Vector3 normal;
TextureLayerDefinition* definition;
@ -41,12 +41,12 @@ void texturesSave(PackStream* stream, TexturesDefinition* definition)
{
zoneSave(stream, definition->textures[i].zone);
noiseSaveGenerator(stream, definition->textures[i].bump_noise);
packWriteFloat(stream, &definition->textures[i].bump_height);
packWriteFloat(stream, &definition->textures[i].bump_scaling);
packWriteDouble(stream, &definition->textures[i].bump_height);
packWriteDouble(stream, &definition->textures[i].bump_scaling);
materialSave(stream, &definition->textures[i].material);
packWriteFloat(stream, &definition->textures[i].thickness);
packWriteFloat(stream, &definition->textures[i].slope_range);
packWriteFloat(stream, &definition->textures[i].thickness_transparency);
packWriteDouble(stream, &definition->textures[i].thickness);
packWriteDouble(stream, &definition->textures[i].slope_range);
packWriteDouble(stream, &definition->textures[i].thickness_transparency);
}
}
@ -67,12 +67,12 @@ void texturesLoad(PackStream* stream, TexturesDefinition* definition)
zoneLoad(stream, layer->zone);
noiseLoadGenerator(stream, layer->bump_noise);
packReadFloat(stream, &layer->bump_height);
packReadFloat(stream, &layer->bump_scaling);
packReadDouble(stream, &layer->bump_height);
packReadDouble(stream, &layer->bump_scaling);
materialLoad(stream, &layer->material);
packReadFloat(stream, &definition->textures[i].thickness);
packReadFloat(stream, &definition->textures[i].slope_range);
packReadFloat(stream, &definition->textures[i].thickness_transparency);
packReadDouble(stream, &definition->textures[i].thickness);
packReadDouble(stream, &definition->textures[i].slope_range);
packReadDouble(stream, &definition->textures[i].thickness_transparency);
}
texturesValidateDefinition(definition);
@ -236,7 +236,7 @@ static inline Vector3 _getNormal2(Vector3 center, Vector3 east, Vector3 south)
return v3Normalize(v3Cross(v3Sub(south, center), v3Sub(east, center)));
}
static inline TextureResult _getTerrainResult(Renderer* renderer, float x, float z, float detail)
static inline TextureResult _getTerrainResult(Renderer* renderer, double x, double z, double detail)
{
TextureResult result;
Vector3 center, north, east, south, west;
@ -279,10 +279,10 @@ static inline TextureResult _getTerrainResult(Renderer* renderer, float x, float
return result;
}
static inline void _getLayerThickness(TextureLayerDefinition* definition, Renderer* renderer, float x, float z, TextureResult* result)
static inline void _getLayerThickness(TextureLayerDefinition* definition, Renderer* renderer, double x, double z, TextureResult* result)
{
TextureResult base;
float coverage;
double coverage;
base = _getTerrainResult(renderer, x, z, definition->slope_range);
coverage = zoneGetValue(definition->zone, base.location, base.normal);
@ -300,7 +300,7 @@ static inline void _getLayerThickness(TextureLayerDefinition* definition, Render
}
}
static inline TextureResult _getLayerResult(TextureLayerDefinition* definition, Renderer* renderer, float x, float z, float detail)
static inline TextureResult _getLayerResult(TextureLayerDefinition* definition, Renderer* renderer, double x, double z, double detail)
{
TextureResult result_center, result_north, result_east, result_south, result_west;
@ -330,7 +330,7 @@ static int _cmpResults(const void* result1, const void* result2)
return ((TextureResult*)result1)->thickness > ((TextureResult*)result2)->thickness;
}
float texturesGetLayerCoverage(TextureLayerDefinition* definition, Renderer* renderer, Vector3 location, float detail)
double texturesGetLayerCoverage(TextureLayerDefinition* definition, Renderer* renderer, Vector3 location, double detail)
{
TextureResult base = _getTerrainResult(renderer, location.x, location.z, definition->slope_range);
return zoneGetValue(definition->zone, base.location, base.normal);
@ -341,7 +341,7 @@ static inline Color _getLayerColor(Renderer* renderer, TextureResult result, Lig
return renderer->applyLightStatus(renderer, light, result.location, result.normal, result.definition->material);
}
Color texturesGetLayerColor(TextureLayerDefinition* definition, Renderer* renderer, Vector3 location, float detail)
Color texturesGetLayerColor(TextureLayerDefinition* definition, Renderer* renderer, Vector3 location, double detail)
{
LightStatus light;
TextureResult result = _getLayerResult(definition, renderer, location.x, location.z, detail);
@ -349,11 +349,11 @@ Color texturesGetLayerColor(TextureLayerDefinition* definition, Renderer* render
return _getLayerColor(renderer, result, &light);
}
Color texturesGetColor(TexturesDefinition* definition, Renderer* renderer, float x, float z, float detail)
Color texturesGetColor(TexturesDefinition* definition, Renderer* renderer, double x, double z, double detail)
{
TextureResult results[TEXTURES_MAX_LAYERS + 1];
Color result, color;
float thickness, last_height;
double thickness, last_height;
int i, start;
detail *= 0.1;

View file

@ -17,12 +17,12 @@ typedef struct
{
Zone* zone;
NoiseGenerator* bump_noise;
float bump_scaling;
float bump_height;
double bump_scaling;
double bump_height;
SurfaceMaterial material;
float thickness;
float slope_range;
float thickness_transparency;
double thickness;
double slope_range;
double thickness_transparency;
} TextureLayerDefinition;
typedef struct
@ -51,9 +51,9 @@ TextureLayerDefinition* texturesGetLayer(TexturesDefinition* definition, int lay
int texturesAddLayer(TexturesDefinition* definition);
void texturesDeleteLayer(TexturesDefinition* definition, int layer);
float texturesGetLayerCoverage(TextureLayerDefinition* definition, Renderer* renderer, Vector3 location, float detail);
Color texturesGetLayerColor(TextureLayerDefinition* definition, Renderer* renderer, Vector3 location, float detail);
Color texturesGetColor(TexturesDefinition* definition, Renderer* renderer, float x, float z, float detail);
double texturesGetLayerCoverage(TextureLayerDefinition* definition, Renderer* renderer, Vector3 location, double detail);
Color texturesGetLayerColor(TextureLayerDefinition* definition, Renderer* renderer, Vector3 location, double detail);
Color texturesGetColor(TexturesDefinition* definition, Renderer* renderer, double x, double z, double detail);
#ifdef __cplusplus
}

View file

@ -8,19 +8,19 @@
#include "color.h"
#include "euclid.h"
float toolsRandom()
double toolsRandom()
{
return (float)rand() / (float)RAND_MAX;
return ((double)rand()) / (double)RAND_MAX;
}
static inline float __cubicInterpolate(float p[4], float x)
static inline double __cubicInterpolate(double p[4], double x)
{
return p[1] + 0.5 * x * (p[2] - p[0] + x * (2.0 * p[0] - 5.0 * p[1] + 4.0 * p[2] - p[3] + x * (3.0 * (p[1] - p[2]) + p[3] - p[0])));
}
float toolsBicubicInterpolate(float stencil[16], float x, float y)
double toolsBicubicInterpolate(double stencil[16], double x, double y)
{
float buf_cubic_y[4];
double buf_cubic_y[4];
buf_cubic_y[0] = __cubicInterpolate(stencil, x);
buf_cubic_y[1] = __cubicInterpolate(stencil + 4, x);
@ -30,12 +30,12 @@ float toolsBicubicInterpolate(float stencil[16], float x, float y)
return __cubicInterpolate(buf_cubic_y, y);
}
void toolsFloat2DMapCopy(float* src, float* dest, int src_xstart, int src_ystart, int dest_xstart, int dest_ystart, int xsize, int ysize, int src_xstep, int src_ystep, int dest_xstep, int dest_ystep)
void toolsFloat2DMapCopy(double* src, double* dest, int src_xstart, int src_ystart, int dest_xstart, int dest_ystart, int xsize, int ysize, int src_xstep, int src_ystep, int dest_xstep, int dest_ystep)
{
/* TODO Optimize with memcpy if src_xstep == dest_xstep == 1 */
int x, y;
float* src_row;
float* dest_row;
double* src_row;
double* dest_row;
src += src_ystart * src_ystep + src_xstart * src_xstep;
dest += dest_ystart * dest_ystep + dest_xstart * dest_xstep;
for (y = 0; y < ysize; y++)
@ -60,23 +60,23 @@ Vector3 toolsGetNormalFromTriangle(Vector3 center, Vector3 bottom, Vector3 right
return v3Normalize(v3Cross(dz, dx));
}
float toolsGetDistance2D(float x1, float y1, float x2, float y2)
double toolsGetDistance2D(double x1, double y1, double x2, double y2)
{
float dx = x2 - x1;
float dy = y2 - y1;
double dx = x2 - x1;
double dy = y2 - y1;
return sqrt(dx * dx + dy * dy);
}
void materialSave(PackStream* stream, SurfaceMaterial* material)
{
colorSave(stream, &material->base);
packWriteFloat(stream, &material->reflection);
packWriteFloat(stream, &material->shininess);
packWriteDouble(stream, &material->reflection);
packWriteDouble(stream, &material->shininess);
}
void materialLoad(PackStream* stream, SurfaceMaterial* material)
{
colorLoad(stream, &material->base);
packReadFloat(stream, &material->reflection);
packReadFloat(stream, &material->shininess);
packReadDouble(stream, &material->reflection);
packReadDouble(stream, &material->shininess);
}

View file

@ -8,11 +8,11 @@
extern "C" {
#endif
float toolsRandom();
float toolsBicubicInterpolate(float stencil[16], float x, float y);
void toolsFloat2DMapCopy(float* src, float* dest, int src_xstart, int src_ystart, int dest_xstart, int dest_ystart, int xsize, int ysize, int src_xstep, int src_ystep, int dest_xstep, int dest_ystep);
double toolsRandom();
double toolsBicubicInterpolate(double stencil[16], double x, double y);
void toolsFloat2DMapCopy(double* src, double* dest, int src_xstart, int src_ystart, int dest_xstart, int dest_ystart, int xsize, int ysize, int src_xstep, int src_ystep, int dest_xstep, int dest_ystep);
Vector3 toolsGetNormalFromTriangle(Vector3 center, Vector3 bottom, Vector3 right);
float toolsGetDistance2D(float x1, float y1, float x2, float y2);
double toolsGetDistance2D(double x1, double y1, double x2, double y2);
void materialSave(PackStream* stream, SurfaceMaterial* material);
void materialLoad(PackStream* stream, SurfaceMaterial* material);

View file

@ -13,7 +13,7 @@ extern "C" {
typedef struct
{
Zone* zone;
float max_height;
double max_height;
} VegetationLayerDefinition;
typedef struct VegetationDefinition VegetationDefinition;
@ -39,7 +39,7 @@ int vegetationSetLayer(VegetationDefinition* definition, int position, Vegetatio
int vegetationAddLayer(VegetationDefinition* definition);
void vegetationDeleteLayer(VegetationDefinition* definition, int layer);
/*float vegetationGetLayerCoverage(TextureLayerDefinition* definition, Renderer* renderer, Vector3 location, float detail);*/
/*double vegetationGetLayerCoverage(TextureLayerDefinition* definition, Renderer* renderer, Vector3 location, double detail);*/
#ifdef __cplusplus
}

View file

@ -20,30 +20,30 @@ void waterQuit()
void waterSave(PackStream* stream, WaterDefinition* definition)
{
packWriteFloat(stream, &definition->height);
packWriteDouble(stream, &definition->height);
materialSave(stream, &definition->material);
colorSave(stream, &definition->depth_color);
packWriteFloat(stream, &definition->transparency_depth);
packWriteFloat(stream, &definition->transparency);
packWriteFloat(stream, &definition->reflection);
packWriteFloat(stream, &definition->lighting_depth);
packWriteDouble(stream, &definition->transparency_depth);
packWriteDouble(stream, &definition->transparency);
packWriteDouble(stream, &definition->reflection);
packWriteDouble(stream, &definition->lighting_depth);
noiseSaveGenerator(stream, definition->waves_noise);
packWriteFloat(stream, &definition->waves_noise_height);
packWriteFloat(stream, &definition->waves_noise_scale);
packWriteDouble(stream, &definition->waves_noise_height);
packWriteDouble(stream, &definition->waves_noise_scale);
}
void waterLoad(PackStream* stream, WaterDefinition* definition)
{
packReadFloat(stream, &definition->height);
packReadDouble(stream, &definition->height);
materialLoad(stream, &definition->material);
colorLoad(stream, &definition->depth_color);
packReadFloat(stream, &definition->transparency_depth);
packReadFloat(stream, &definition->transparency);
packReadFloat(stream, &definition->reflection);
packReadFloat(stream, &definition->lighting_depth);
packReadDouble(stream, &definition->transparency_depth);
packReadDouble(stream, &definition->transparency);
packReadDouble(stream, &definition->reflection);
packReadDouble(stream, &definition->lighting_depth);
noiseLoadGenerator(stream, definition->waves_noise);
packReadFloat(stream, &definition->waves_noise_height);
packReadFloat(stream, &definition->waves_noise_scale);
packReadDouble(stream, &definition->waves_noise_height);
packReadDouble(stream, &definition->waves_noise_scale);
waterValidateDefinition(definition);
}
@ -87,15 +87,15 @@ void waterValidateDefinition(WaterDefinition* definition)
{
}
static inline float _getHeight(WaterDefinition* definition, float x, float z, float detail)
static inline double _getHeight(WaterDefinition* definition, double x, double z, double detail)
{
return definition->height + noiseGet2DDetail(definition->waves_noise, x / definition->waves_noise_scale, z / definition->waves_noise_scale, detail) * definition->waves_noise_height;
}
static inline Vector3 _getNormal(WaterDefinition* definition, Vector3 base, float detail)
static inline Vector3 _getNormal(WaterDefinition* definition, Vector3 base, double detail)
{
Vector3 back, right;
float x, z;
double x, z;
x = base.x;
z = base.z;
@ -115,7 +115,7 @@ static inline Vector3 _getNormal(WaterDefinition* definition, Vector3 base, floa
static inline Vector3 _reflectRay(Vector3 incoming, Vector3 normal)
{
float c;
double c;
c = v3Dot(normal, v3Scale(incoming, -1.0));
return v3Add(incoming, v3Scale(normal, 2.0 * c));
@ -123,7 +123,7 @@ static inline Vector3 _reflectRay(Vector3 incoming, Vector3 normal)
static inline Vector3 _refractRay(Vector3 incoming, Vector3 normal)
{
float c1, c2, f;
double c1, c2, f;
f = 1.0 / 1.33;
c1 = v3Dot(normal, v3Scale(incoming, -1.0));
@ -151,7 +151,7 @@ HeightInfo waterGetHeightInfo(WaterDefinition* definition)
Color waterLightFilter(WaterDefinition* definition, Renderer* renderer, Color light, Vector3 location, Vector3 light_location, Vector3 direction_to_light)
{
float factor;
double factor;
if (location.y < definition->height)
{
@ -189,7 +189,7 @@ WaterResult waterGetColorDetail(WaterDefinition* definition, Renderer* renderer,
Color color;
LightStatus light;
SurfaceMaterial material;
float detail, depth;
double detail, depth;
detail = renderer->getPrecision(renderer, location);
@ -237,50 +237,42 @@ Color waterGetColor(WaterDefinition* definition, Renderer* renderer, Vector3 loc
return waterGetColorDetail(definition, renderer, location, look).final;
}
static int _postProcessFragment(RenderFragment* fragment, Renderer* renderer, void* data)
static Color _postProcessFragment(Renderer* renderer, Vector3 location, void* data)
{
fragment->vertex.color = waterGetColor((WaterDefinition*)data, renderer, fragment->vertex.location, v3Sub(fragment->vertex.location, renderer->camera_location));
return 1;
return waterGetColor((WaterDefinition*)data, renderer, location, v3Sub(location, renderer->camera_location));
}
static Vertex _getFirstPassVertex(WaterDefinition* definition, float x, float z, float precision)
static Vector3 _getFirstPassVertex(WaterDefinition* definition, double x, double z, double precision)
{
Vertex result;
float value;
Vector3 result;
result.location.x = x;
result.location.y = _getHeight(definition, x, z, 0.0);
result.location.z = z;
value = sin(x) * sin(x) * cos(z) * cos(z);
result.color.r = 0.0;
result.color.g = value;
result.color.b = value;
result.color.a = 1.0;
result.callback = _postProcessFragment;
result.callback_data = definition;
result.x = x;
result.y = _getHeight(definition, x, z, 0.0);
result.z = z;
return result;
}
static void _renderQuad(WaterDefinition* definition, Renderer* renderer, float x, float z, float size)
static void _renderQuad(WaterDefinition* definition, Renderer* renderer, double x, double z, double size)
{
Vertex v1, v2, v3, v4;
Vector3 v1, v2, v3, v4;
v1 = _getFirstPassVertex(definition, x, z, size);
v2 = _getFirstPassVertex(definition, x, z + size, size);
v3 = _getFirstPassVertex(definition, x + size, z + size, size);
v4 = _getFirstPassVertex(definition, x + size, z, size);
renderer->pushQuad(renderer, &v1, &v2, &v3, &v4);
renderer->pushQuad(renderer, v1, v2, v3, v4, _postProcessFragment, definition);
}
void waterRender(WaterDefinition* definition, Renderer* renderer)
{
int chunk_factor, chunk_count, i;
float cx = renderer->camera_location.x;
float cz = renderer->camera_location.z;
float radius_int, radius_ext, base_chunk_size, chunk_size;
double cx = renderer->camera_location.x;
double cz = renderer->camera_location.z;
double radius_int, radius_ext, base_chunk_size, chunk_size;
base_chunk_size = 2.0 / (float)renderer->render_quality;
base_chunk_size = 2.0 / (double)renderer->render_quality;
chunk_factor = 1;
chunk_count = 2;
@ -303,7 +295,7 @@ void waterRender(WaterDefinition* definition, Renderer* renderer)
_renderQuad(definition, renderer, cx - radius_ext, cz + radius_int - chunk_size * i, chunk_size);
}
if (radius_int > 20.0 && chunk_count % 64 == 0 && (float)chunk_factor < radius_int / 20.0)
if (radius_int > 20.0 && chunk_count % 64 == 0 && (double)chunk_factor < radius_int / 20.0)
{
chunk_count /= 2;
chunk_factor *= 2;

View file

@ -13,16 +13,16 @@ extern "C" {
typedef struct
{
float height;
float transparency;
float reflection;
double height;
double transparency;
double reflection;
SurfaceMaterial material;
Color depth_color;
float transparency_depth;
float lighting_depth;
double transparency_depth;
double lighting_depth;
NoiseGenerator* waves_noise;
float waves_noise_height;
float waves_noise_scale;
double waves_noise_height;
double waves_noise_scale;
} WaterDefinition;
typedef struct

View file

@ -9,11 +9,11 @@
typedef struct
{
float value;
float centerx;
float centerz;
float softradius;
float hardradius;
double value;
double centerx;
double centerz;
double softradius;
double hardradius;
} Circle;
struct Zone {
@ -55,41 +55,41 @@ void zoneSave(PackStream* stream, Zone* zone)
packWriteInt(stream, &zone->height_ranges_count);
for (i = 0; i < zone->height_ranges_count; i++)
{
packWriteFloat(stream, &zone->height_ranges[i].value);
packWriteFloat(stream, &zone->height_ranges[i].hardmin);
packWriteFloat(stream, &zone->height_ranges[i].softmin);
packWriteFloat(stream, &zone->height_ranges[i].softmax);
packWriteFloat(stream, &zone->height_ranges[i].hardmax);
packWriteDouble(stream, &zone->height_ranges[i].value);
packWriteDouble(stream, &zone->height_ranges[i].hardmin);
packWriteDouble(stream, &zone->height_ranges[i].softmin);
packWriteDouble(stream, &zone->height_ranges[i].softmax);
packWriteDouble(stream, &zone->height_ranges[i].hardmax);
}
packWriteInt(stream, &zone->slope_ranges_count);
for (i = 0; i < zone->slope_ranges_count; i++)
{
packWriteFloat(stream, &zone->slope_ranges[i].value);
packWriteFloat(stream, &zone->slope_ranges[i].hardmin);
packWriteFloat(stream, &zone->slope_ranges[i].softmin);
packWriteFloat(stream, &zone->slope_ranges[i].softmax);
packWriteFloat(stream, &zone->slope_ranges[i].hardmax);
packWriteDouble(stream, &zone->slope_ranges[i].value);
packWriteDouble(stream, &zone->slope_ranges[i].hardmin);
packWriteDouble(stream, &zone->slope_ranges[i].softmin);
packWriteDouble(stream, &zone->slope_ranges[i].softmax);
packWriteDouble(stream, &zone->slope_ranges[i].hardmax);
}
packWriteInt(stream, &zone->circles_included_count);
for (i = 0; i < zone->circles_included_count; i++)
{
packWriteFloat(stream, &zone->circles_included[i].value);
packWriteFloat(stream, &zone->circles_included[i].centerx);
packWriteFloat(stream, &zone->circles_included[i].centerz);
packWriteFloat(stream, &zone->circles_included[i].softradius);
packWriteFloat(stream, &zone->circles_included[i].hardradius);
packWriteDouble(stream, &zone->circles_included[i].value);
packWriteDouble(stream, &zone->circles_included[i].centerx);
packWriteDouble(stream, &zone->circles_included[i].centerz);
packWriteDouble(stream, &zone->circles_included[i].softradius);
packWriteDouble(stream, &zone->circles_included[i].hardradius);
}
packWriteInt(stream, &zone->circles_excluded_count);
for (i = 0; i < zone->circles_excluded_count; i++)
{
packWriteFloat(stream, &zone->circles_excluded[i].value);
packWriteFloat(stream, &zone->circles_excluded[i].centerx);
packWriteFloat(stream, &zone->circles_excluded[i].centerz);
packWriteFloat(stream, &zone->circles_excluded[i].softradius);
packWriteFloat(stream, &zone->circles_excluded[i].hardradius);
packWriteDouble(stream, &zone->circles_excluded[i].value);
packWriteDouble(stream, &zone->circles_excluded[i].centerx);
packWriteDouble(stream, &zone->circles_excluded[i].centerz);
packWriteDouble(stream, &zone->circles_excluded[i].softradius);
packWriteDouble(stream, &zone->circles_excluded[i].hardradius);
}
}
@ -100,41 +100,41 @@ void zoneLoad(PackStream* stream, Zone* zone)
packReadInt(stream, &zone->height_ranges_count);
for (i = 0; i < zone->height_ranges_count; i++)
{
packReadFloat(stream, &zone->height_ranges[i].value);
packReadFloat(stream, &zone->height_ranges[i].hardmin);
packReadFloat(stream, &zone->height_ranges[i].softmin);
packReadFloat(stream, &zone->height_ranges[i].softmax);
packReadFloat(stream, &zone->height_ranges[i].hardmax);
packReadDouble(stream, &zone->height_ranges[i].value);
packReadDouble(stream, &zone->height_ranges[i].hardmin);
packReadDouble(stream, &zone->height_ranges[i].softmin);
packReadDouble(stream, &zone->height_ranges[i].softmax);
packReadDouble(stream, &zone->height_ranges[i].hardmax);
}
packReadInt(stream, &zone->slope_ranges_count);
for (i = 0; i < zone->slope_ranges_count; i++)
{
packReadFloat(stream, &zone->slope_ranges[i].value);
packReadFloat(stream, &zone->slope_ranges[i].hardmin);
packReadFloat(stream, &zone->slope_ranges[i].softmin);
packReadFloat(stream, &zone->slope_ranges[i].softmax);
packReadFloat(stream, &zone->slope_ranges[i].hardmax);
packReadDouble(stream, &zone->slope_ranges[i].value);
packReadDouble(stream, &zone->slope_ranges[i].hardmin);
packReadDouble(stream, &zone->slope_ranges[i].softmin);
packReadDouble(stream, &zone->slope_ranges[i].softmax);
packReadDouble(stream, &zone->slope_ranges[i].hardmax);
}
packReadInt(stream, &zone->circles_included_count);
for (i = 0; i < zone->circles_included_count; i++)
{
packReadFloat(stream, &zone->circles_included[i].value);
packReadFloat(stream, &zone->circles_included[i].centerx);
packReadFloat(stream, &zone->circles_included[i].centerz);
packReadFloat(stream, &zone->circles_included[i].softradius);
packReadFloat(stream, &zone->circles_included[i].hardradius);
packReadDouble(stream, &zone->circles_included[i].value);
packReadDouble(stream, &zone->circles_included[i].centerx);
packReadDouble(stream, &zone->circles_included[i].centerz);
packReadDouble(stream, &zone->circles_included[i].softradius);
packReadDouble(stream, &zone->circles_included[i].hardradius);
}
packReadInt(stream, &zone->circles_excluded_count);
for (i = 0; i < zone->circles_excluded_count; i++)
{
packReadFloat(stream, &zone->circles_excluded[i].value);
packReadFloat(stream, &zone->circles_excluded[i].centerx);
packReadFloat(stream, &zone->circles_excluded[i].centerz);
packReadFloat(stream, &zone->circles_excluded[i].softradius);
packReadFloat(stream, &zone->circles_excluded[i].hardradius);
packReadDouble(stream, &zone->circles_excluded[i].value);
packReadDouble(stream, &zone->circles_excluded[i].centerx);
packReadDouble(stream, &zone->circles_excluded[i].centerz);
packReadDouble(stream, &zone->circles_excluded[i].softradius);
packReadDouble(stream, &zone->circles_excluded[i].hardradius);
}
}
@ -143,7 +143,7 @@ void zoneCopy(Zone* source, Zone* destination)
*destination = *source;
}
void zoneIncludeCircleArea(Zone* zone, float value, float centerx, float centerz, float softradius, float hardradius)
void zoneIncludeCircleArea(Zone* zone, double value, double centerx, double centerz, double softradius, double hardradius)
{
Circle circle = {value, centerx, centerz, softradius, hardradius};
@ -153,7 +153,7 @@ void zoneIncludeCircleArea(Zone* zone, float value, float centerx, float centerz
}
}
void zoneExcludeCircleArea(Zone* zone, float centerx, float centerz, float softradius, float hardradius)
void zoneExcludeCircleArea(Zone* zone, double centerx, double centerz, double softradius, double hardradius)
{
/* TODO */
}
@ -206,7 +206,7 @@ int zoneSetHeightRange(Zone* zone, int position, ZoneRangeCondition* range)
}
}
int zoneAddHeightRangeQuick(Zone* zone, float value, float hardmin, float softmin, float softmax, float hardmax)
int zoneAddHeightRangeQuick(Zone* zone, double value, double hardmin, double softmin, double softmax, double hardmax)
{
ZoneRangeCondition range = {value, hardmin, softmin, softmax, hardmax};
int position;
@ -267,7 +267,7 @@ int zoneSetSlopeRange(Zone* zone, int position, ZoneRangeCondition* range)
}
}
int zoneAddSlopeRangeQuick(Zone* zone, float value, float hardmin, float softmin, float softmax, float hardmax)
int zoneAddSlopeRangeQuick(Zone* zone, double value, double hardmin, double softmin, double softmax, double hardmax)
{
ZoneRangeCondition range = {value, hardmin, softmin, softmax, hardmax};
int position;
@ -280,7 +280,7 @@ int zoneAddSlopeRangeQuick(Zone* zone, float value, float hardmin, float softmin
return position;
}
static inline float _getRangeInfluence(ZoneRangeCondition range, float position)
static inline double _getRangeInfluence(ZoneRangeCondition range, double position)
{
if (position >= range.hardmin && position <= range.hardmax)
{
@ -303,9 +303,9 @@ static inline float _getRangeInfluence(ZoneRangeCondition range, float position)
}
}
static inline float _getCircleInfluence(Circle circle, Vector3 position)
static inline double _getCircleInfluence(Circle circle, Vector3 position)
{
float radius, dx, dz;
double radius, dx, dz;
dx = position.x - circle.centerx;
dz = position.z - circle.centerz;
@ -325,10 +325,10 @@ static inline float _getCircleInfluence(Circle circle, Vector3 position)
}
}
float zoneGetValue(Zone* zone, Vector3 location, Vector3 normal)
double zoneGetValue(Zone* zone, Vector3 location, Vector3 normal)
{
int i;
float value, value_height, value_steepness, value_circle;
double value, value_height, value_steepness, value_circle;
if (zone->circles_included_count > 0)
{

View file

@ -12,11 +12,11 @@ typedef struct Zone Zone;
typedef struct
{
float value;
float hardmin;
float softmin;
float softmax;
float hardmax;
double value;
double hardmin;
double softmin;
double softmax;
double hardmax;
} ZoneRangeCondition;
Zone* zoneCreate();
@ -24,22 +24,22 @@ void zoneDelete(Zone* zone);
void zoneSave(PackStream* stream, Zone* zone);
void zoneLoad(PackStream* stream, Zone* zone);
void zoneCopy(Zone* source, Zone* destination);
void zoneIncludeCircleArea(Zone* zone, float value, float centerx, float centerz, float softradius, float hardradius);
void zoneExcludeCircleArea(Zone* zone, float centerx, float centerz, float softradius, float hardradius);
void zoneIncludeCircleArea(Zone* zone, double value, double centerx, double centerz, double softradius, double hardradius);
void zoneExcludeCircleArea(Zone* zone, double centerx, double centerz, double softradius, double hardradius);
int zoneAddHeightRange(Zone* zone);
int zoneGetHeightRangeCount(Zone* zone);
int zoneGetHeightRange(Zone* zone, int position, ZoneRangeCondition* range);
int zoneSetHeightRange(Zone* zone, int position, ZoneRangeCondition* range);
int zoneAddHeightRangeQuick(Zone* zone, float value, float hardmin, float softmin, float softmax, float hardmax);
int zoneAddHeightRangeQuick(Zone* zone, double value, double hardmin, double softmin, double softmax, double hardmax);
int zoneAddSlopeRange(Zone* zone);
int zoneGetSlopeRangeCount(Zone* zone);
int zoneGetSlopeRange(Zone* zone, int position, ZoneRangeCondition* range);
int zoneSetSlopeRange(Zone* zone, int position, ZoneRangeCondition* range);
int zoneAddSlopeRangeQuick(Zone* zone, float value, float hardmin, float softmin, float softmax, float hardmax);
int zoneAddSlopeRangeQuick(Zone* zone, double value, double hardmin, double softmin, double softmax, double hardmax);
float zoneGetValue(Zone* zone, Vector3 location, Vector3 normal);
double zoneGetValue(Zone* zone, Vector3 location, Vector3 normal);
#ifdef __cplusplus
}