diff --git a/src/basics/Color.cpp b/src/basics/Color.cpp index 077d6bb..8b16107 100644 --- a/src/basics/Color.cpp +++ b/src/basics/Color.cpp @@ -53,23 +53,23 @@ unsigned int Color::to32BitABGR() const { } Color Color::from32BitRGBA(unsigned int col) { - return Color(((double)(col & 0x000000FF)) / 255.0, ((double)((col & 0x0000FF00) >> 8)) / 255.0, - ((double)((col & 0x00FF0000) >> 16)) / 255.0, ((double)((col & 0xFF000000) >> 24)) / 255.0); + return Color((to_double(col & 0x000000FF)) / 255.0, (to_double((col & 0x0000FF00) >> 8)) / 255.0, + (to_double((col & 0x00FF0000) >> 16)) / 255.0, (to_double((col & 0xFF000000) >> 24)) / 255.0); } Color Color::from32BitBGRA(unsigned int col) { - return Color(((double)(col & 0x000000FF)) / 255.0, ((double)((col & 0x0000FF00) >> 8)) / 255.0, - ((double)((col & 0x00FF0000) >> 16)) / 255.0, ((double)((col & 0xFF000000) >> 24)) / 255.0); + return Color((to_double(col & 0x000000FF)) / 255.0, (to_double((col & 0x0000FF00) >> 8)) / 255.0, + (to_double((col & 0x00FF0000) >> 16)) / 255.0, (to_double((col & 0xFF000000) >> 24)) / 255.0); } Color Color::from32BitARGB(unsigned int col) { - return Color(((double)(col & 0x000000FF)) / 255.0, ((double)((col & 0x0000FF00) >> 8)) / 255.0, - ((double)((col & 0x00FF0000) >> 16)) / 255.0, ((double)((col & 0xFF000000) >> 24)) / 255.0); + return Color((to_double(col & 0x000000FF)) / 255.0, (to_double((col & 0x0000FF00) >> 8)) / 255.0, + (to_double((col & 0x00FF0000) >> 16)) / 255.0, (to_double((col & 0xFF000000) >> 24)) / 255.0); } Color Color::from32BitABGR(unsigned int col) { - return Color(((double)(col & 0x000000FF)) / 255.0, ((double)((col & 0x0000FF00) >> 8)) / 255.0, - ((double)((col & 0x00FF0000) >> 16)) / 255.0, ((double)((col & 0xFF000000) >> 24)) / 255.0); + return Color((to_double(col & 0x000000FF)) / 255.0, (to_double((col & 0x0000FF00) >> 8)) / 255.0, + (to_double((col & 0x00FF0000) >> 16)) / 255.0, (to_double((col & 0xFF000000) >> 24)) / 255.0); } void Color::mask(const Color &mask) { diff --git a/src/basics/ColorProfile.cpp b/src/basics/ColorProfile.cpp index dc3b37a..abd4dbc 100644 --- a/src/basics/ColorProfile.cpp +++ b/src/basics/ColorProfile.cpp @@ -53,13 +53,13 @@ void ColorProfile::setToneMapping(ToneMappingOperator tonemapper, double exposur } void ColorProfile::save(PackStream *stream) const { - int imapper = (int)mapper; + int imapper = trunc_to_int(mapper); stream->write(&imapper); stream->write(&exposure); } void ColorProfile::load(PackStream *stream) { - int imapper = (int)mapper; + int imapper = trunc_to_int(mapper); stream->read(&imapper); stream->read(&exposure); diff --git a/src/basics/NoiseFunctionPerlin.cpp b/src/basics/NoiseFunctionPerlin.cpp index 2b3117d..c3a0fcb 100644 --- a/src/basics/NoiseFunctionPerlin.cpp +++ b/src/basics/NoiseFunctionPerlin.cpp @@ -30,9 +30,9 @@ static double g1[B + B + 2]; #define setup(i, b0, b1, r0, r1) \ t = vec[i] + N; \ - b0 = ((int)t) & BM; \ + b0 = trunc_to_int(t) & BM; \ b1 = (b0 + 1) & BM; \ - r0 = t - (int)t; \ + r0 = t - trunc_to_int(t); \ r1 = r0 - 1.; double noisePerlinGet1DValue(double x) { @@ -165,14 +165,14 @@ static int noisePerlinInit(void) { for (i = 0; i < B; i++) { p[i] = i; - g1[i] = (double)((rand() % (B + B)) - B) / B; + g1[i] = to_double((rand() % (B + B)) - B) / B; for (j = 0; j < 2; j++) - g2[i][j] = (double)((rand() % (B + B)) - B) / B; + g2[i][j] = to_double((rand() % (B + B)) - B) / B; _normalize2(g2[i]); for (j = 0; j < 3; j++) - g3[i][j] = (double)((rand() % (B + B)) - B) / B; + g3[i][j] = to_double((rand() % (B + B)) - B) / B; _normalize3(g3[i]); } diff --git a/src/basics/NoiseFunctionSimplex.cpp b/src/basics/NoiseFunctionSimplex.cpp index 21c8acf..8aa679b 100644 --- a/src/basics/NoiseFunctionSimplex.cpp +++ b/src/basics/NoiseFunctionSimplex.cpp @@ -97,7 +97,7 @@ static double _F4; static double _G4; static inline int _fastfloor(double x) { - int xi = (int)x; + int xi = trunc_to_int(x); return x < xi ? xi - 1 : xi; } @@ -487,7 +487,7 @@ const Texture2D *NoiseFunctionSimplex::getValueTexture() { for (int x = 0; x < width; x++) { for (int z = 0; z < height; z++) { - double val = noiseSimplexGet2DValue((double)x, (double)z); + double val = noiseSimplexGet2DValue(to_double(x), to_double(z)); _valueTexture->setPixel(x, z, Color(val, val, val)); } } @@ -507,9 +507,9 @@ const Texture2D *NoiseFunctionSimplex::getNormalTexture() { for (int x = 0; x < width; x++) { for (int z = 0; z < height; z++) { - double vcenter = noiseSimplexGet2DValue(0.01 * (double)x, 0.01 * (double)z); - double vsouth = noiseSimplexGet2DValue(0.01 * (double)x, 0.01 * (double)z + 0.001); - double veast = noiseSimplexGet2DValue(0.01 * (double)x + 0.001, 0.01 * (double)z); + double vcenter = noiseSimplexGet2DValue(0.01 * to_double(x), 0.01 * to_double(z)); + double vsouth = noiseSimplexGet2DValue(0.01 * to_double(x), 0.01 * to_double(z) + 0.001); + double veast = noiseSimplexGet2DValue(0.01 * to_double(x) + 0.001, 0.01 * to_double(z)); Vector3 normal = Geometry::getNormalFromTriangle(Vector3(0.0, vcenter, 0.0), Vector3(0.0, vsouth, 0.01), Vector3(0.01, veast, 0.0)); diff --git a/src/basics/NoiseGenerator.cpp b/src/basics/NoiseGenerator.cpp index e351c00..a0c330d 100644 --- a/src/basics/NoiseGenerator.cpp +++ b/src/basics/NoiseGenerator.cpp @@ -30,7 +30,7 @@ NoiseGenerator::~NoiseGenerator() { void NoiseGenerator::save(PackStream *stream) const { int x; - x = (int)function.algorithm; + x = static_cast(function.algorithm); stream->write(&x); stream->write(&function.ridge_factor); stream->write(&function.curve_factor); @@ -53,7 +53,7 @@ void NoiseGenerator::load(PackStream *stream) { int x; stream->read(&x); - function.algorithm = (NoiseFunctionAlgorithm)x; + function.algorithm = static_cast(x); stream->read(&function.ridge_factor); stream->read(&function.curve_factor); diff --git a/src/basics/SpaceSegment.cpp b/src/basics/SpaceSegment.cpp index 2c9f7bd..7786e57 100644 --- a/src/basics/SpaceSegment.cpp +++ b/src/basics/SpaceSegment.cpp @@ -99,18 +99,18 @@ bool SpaceSegment::iterateOnGrid(SpaceGridIterator &delegate) { int stepX = diff.x < 0.0 ? -1 : 1; int stepY = diff.y < 0.0 ? -1 : 1; int stepZ = diff.z < 0.0 ? -1 : 1; - int X = (int)floor(start.x); - int Y = (int)floor(start.y); - int Z = (int)floor(start.z); - int limitX = (int)floor(end.x) + stepX; - int limitY = (int)floor(end.y) + stepY; - int limitZ = (int)floor(end.z) + stepZ; + int X = floor_to_int(start.x); + int Y = floor_to_int(start.y); + int Z = floor_to_int(start.z); + int limitX = floor_to_int(end.x) + stepX; + int limitY = floor_to_int(end.y) + stepY; + int limitZ = floor_to_int(end.z) + stepZ; double tDeltaX = diff.x == 0.0 ? 0.0 : 1.0 / fabs(diff.x); double tDeltaY = diff.y == 0.0 ? 0.0 : 1.0 / fabs(diff.y); double tDeltaZ = diff.z == 0.0 ? 0.0 : 1.0 / fabs(diff.z); - double tMaxX = diff.x == 0.0 ? INFINITY : ((double)(X + (stepX > 0 ? 1 : 0)) - start.x) / diff.x; - double tMaxY = diff.y == 0.0 ? INFINITY : ((double)(Y + (stepY > 0 ? 1 : 0)) - start.y) / diff.y; - double tMaxZ = diff.z == 0.0 ? INFINITY : ((double)(Z + (stepZ > 0 ? 1 : 0)) - start.z) / diff.z; + double tMaxX = diff.x == 0.0 ? INFINITY : (to_double(X + (stepX > 0 ? 1 : 0)) - start.x) / diff.x; + double tMaxY = diff.y == 0.0 ? INFINITY : (to_double(Y + (stepY > 0 ? 1 : 0)) - start.y) / diff.y; + double tMaxZ = diff.z == 0.0 ? INFINITY : (to_double(Z + (stepZ > 0 ? 1 : 0)) - start.z) / diff.z; do { if (not delegate.onCell(X, Y, Z)) { diff --git a/src/basics/Texture2D.cpp b/src/basics/Texture2D.cpp index dade33c..b615269 100644 --- a/src/basics/Texture2D.cpp +++ b/src/basics/Texture2D.cpp @@ -47,8 +47,8 @@ Color Texture2D::getNearest(double dx, double dy) const { if (dy > 1.0) dy = 1.0; - int ix = (int)(dx * (double)(this->xsize - 1)); - int iy = (int)(dy * (double)(this->ysize - 1)); + int ix = trunc_to_int(dx * to_double(this->xsize - 1)); + int iy = trunc_to_int(dy * to_double(this->ysize - 1)); assert(ix >= 0 && ix < this->xsize); assert(iy >= 0 && iy < this->ysize); @@ -66,20 +66,20 @@ Color Texture2D::getLinear(double dx, double dy) const { if (dy > 1.0) dy = 1.0; - dx *= (double)(this->xsize - 1); - dy *= (double)(this->ysize - 1); + dx *= to_double(this->xsize - 1); + dy *= to_double(this->ysize - 1); - int ix = (int)floor(dx); + int ix = floor_to_int(dx); if (ix == this->xsize - 1) { ix--; } - int iy = (int)floor(dy); + int iy = floor_to_int(dy); if (iy == this->ysize - 1) { iy--; } - dx -= (double)ix; - dy -= (double)iy; + dx -= to_double(ix); + dy -= to_double(iy); Color *data = this->data + iy * this->xsize + ix; diff --git a/src/basics/Texture3D.cpp b/src/basics/Texture3D.cpp index f598039..f6a0560 100644 --- a/src/basics/Texture3D.cpp +++ b/src/basics/Texture3D.cpp @@ -55,9 +55,9 @@ Color Texture3D::getNearest(double dx, double dy, double dz) const { if (dz > 1.0) dz = 1.0; - int ix = (int)(dx * (double)(this->xsize - 1)); - int iy = (int)(dy * (double)(this->ysize - 1)); - int iz = (int)(dz * (double)(this->zsize - 1)); + int ix = trunc_to_int(dx * to_double(this->xsize - 1)); + int iy = trunc_to_int(dy * to_double(this->ysize - 1)); + int iz = trunc_to_int(dz * to_double(this->zsize - 1)); assert(ix >= 0 && ix < this->xsize); assert(iy >= 0 && iy < this->ysize); @@ -80,26 +80,26 @@ Color Texture3D::getLinear(double dx, double dy, double dz) const { if (dz > 1.0) dz = 1.0; - dx *= (double)(this->xsize - 1); - dy *= (double)(this->ysize - 1); - dz *= (double)(this->zsize - 1); + dx *= to_double(this->xsize - 1); + dy *= to_double(this->ysize - 1); + dz *= to_double(this->zsize - 1); - int ix = (int)floor(dx); + int ix = floor_to_int(dx); if (ix == this->xsize - 1) { ix--; } - int iy = (int)floor(dy); + int iy = floor_to_int(dy); if (iy == this->ysize - 1) { iy--; } - int iz = (int)floor(dz); + int iz = floor_to_int(dz); if (iz == this->zsize - 1) { iz--; } - dx -= (double)ix; - dy -= (double)iy; - dz -= (double)iz; + dx -= to_double(ix); + dy -= to_double(iy); + dz -= to_double(iz); Color *data = this->data + iz * this->xsize * this->ysize + iy * this->xsize + ix; diff --git a/src/basics/Texture4D.cpp b/src/basics/Texture4D.cpp index e16ea0d..2535003 100644 --- a/src/basics/Texture4D.cpp +++ b/src/basics/Texture4D.cpp @@ -64,10 +64,10 @@ Color Texture4D::getNearest(double dx, double dy, double dz, double dw) const { if (dw > 1.0) dw = 1.0; - int ix = (int)(dx * (double)(this->xsize - 1)); - int iy = (int)(dy * (double)(this->ysize - 1)); - int iz = (int)(dz * (double)(this->zsize - 1)); - int iw = (int)(dw * (double)(this->wsize - 1)); + int ix = trunc_to_int(dx * to_double(this->xsize - 1)); + int iy = trunc_to_int(dy * to_double(this->ysize - 1)); + int iz = trunc_to_int(dz * to_double(this->zsize - 1)); + int iw = trunc_to_int(dw * to_double(this->wsize - 1)); assert(ix >= 0 && ix < this->xsize); assert(iy >= 0 && iy < this->ysize); @@ -96,32 +96,32 @@ Color Texture4D::getLinear(double dx, double dy, double dz, double dw) const { if (dw > 1.0) dw = 1.0; - dx *= (double)(this->xsize - 1); - dy *= (double)(this->ysize - 1); - dz *= (double)(this->zsize - 1); - dw *= (double)(this->wsize - 1); + dx *= to_double(this->xsize - 1); + dy *= to_double(this->ysize - 1); + dz *= to_double(this->zsize - 1); + dw *= to_double(this->wsize - 1); - int ix = (int)floor(dx); + int ix = floor_to_int(dx); if (ix == this->xsize - 1) { ix--; } - int iy = (int)floor(dy); + int iy = floor_to_int(dy); if (iy == this->ysize - 1) { iy--; } - int iz = (int)floor(dz); + int iz = floor_to_int(dz); if (iz == this->zsize - 1) { iz--; } - int iw = (int)floor(dw); + int iw = floor_to_int(dw); if (iw == this->wsize - 1) { iw--; } - dx -= (double)ix; - dy -= (double)iy; - dz -= (double)iz; - dw -= (double)iw; + dx -= to_double(ix); + dy -= to_double(iy); + dz -= to_double(iz); + dw -= to_double(iw); Color *data = this->data + iw * this->xsize * this->ysize * this->zsize + iz * this->xsize * this->ysize + iy * this->xsize + ix; diff --git a/src/definition/AtmosphereDefinition.cpp b/src/definition/AtmosphereDefinition.cpp index 830446d..a90ac40 100644 --- a/src/definition/AtmosphereDefinition.cpp +++ b/src/definition/AtmosphereDefinition.cpp @@ -84,7 +84,7 @@ void AtmosphereDefinition::setDayTime(double value) { } void AtmosphereDefinition::setDayTime(int hour, int minute, int second) { - setDayTime((double)hour / 24.0 + (double)minute / 1440.0 + (double)second / 86400.0); + setDayTime(to_double(hour) / 24.0 + to_double(minute) / 1440.0 + to_double(second) / 86400.0); } void AtmosphereDefinition::getHMS(int *hour, int *minute, int *second) const { diff --git a/src/definition/CameraDefinition.cpp b/src/definition/CameraDefinition.cpp index e984f80..33a35c4 100644 --- a/src/definition/CameraDefinition.cpp +++ b/src/definition/CameraDefinition.cpp @@ -179,8 +179,8 @@ void CameraDefinition::rotateRoll(double value) { } void CameraDefinition::setRenderSize(int width, int height) { - this->width = (double)width; - this->height = (double)height; + this->width = to_double(width); + this->height = to_double(height); perspective.xratio = this->width / this->height; validate(); @@ -236,7 +236,7 @@ int CameraDefinition::isProjectedBoxInView(const BoundingBox &box) const { double dx = box.xmax - box.xmin; double dy = box.ymax - box.ymin; - return (int)ceil(dx) * (int)ceil(dy); + return ceil_to_int(dx) * ceil_to_int(dy); } else { return 0; } diff --git a/src/definition/CloudLayerDefinition.cpp b/src/definition/CloudLayerDefinition.cpp index 911d00b..0628919 100644 --- a/src/definition/CloudLayerDefinition.cpp +++ b/src/definition/CloudLayerDefinition.cpp @@ -35,7 +35,7 @@ CloudLayerDefinition *CloudLayerDefinition::newCopy(DefinitionNode *parent) cons void CloudLayerDefinition::save(PackStream *stream) const { DefinitionNode::save(stream); - int clouds_type = (int)type; + int clouds_type = static_cast(type); stream->write(&clouds_type); stream->write(&altitude); @@ -51,7 +51,7 @@ void CloudLayerDefinition::load(PackStream *stream) { int clouds_type; stream->read(&clouds_type); - type = (CloudsType)clouds_type; + type = static_cast(clouds_type); stream->read(&altitude); stream->read(&scaling); stream->read(&coverage); diff --git a/src/definition/DefinitionNode.cpp b/src/definition/DefinitionNode.cpp index bfffed7..9819b08 100644 --- a/src/definition/DefinitionNode.cpp +++ b/src/definition/DefinitionNode.cpp @@ -142,7 +142,7 @@ int DefinitionNode::getWatcherCount() const { } void DefinitionNode::save(PackStream *stream) const { - int children_count = (int)children.size(); + int children_count = static_cast(children.size()); stream->write(&children_count); for (auto child : children) { diff --git a/src/definition/Layers.cpp b/src/definition/Layers.cpp index 3579985..27760be 100644 --- a/src/definition/Layers.cpp +++ b/src/definition/Layers.cpp @@ -15,12 +15,12 @@ Layers::~Layers() { } void Layers::save(PackStream *stream) const { - int layer_count = (int)layers.size(); + int layer_count = static_cast(layers.size()); stream->write(&layer_count); - for (int i = 0; i < layer_count; i++) { - stream->write(layers[i]->getName()); - layers[i]->save(stream); + for (auto &layer: layers) { + stream->write(layer->getName()); + layer->save(stream); } } diff --git a/src/definition/PaintedGrid.cpp b/src/definition/PaintedGrid.cpp index 27a9d0c..49fe9cf 100644 --- a/src/definition/PaintedGrid.cpp +++ b/src/definition/PaintedGrid.cpp @@ -38,8 +38,8 @@ bool PaintedGrid::getInterpolatedValue(double x, double y, double *result) const int xlow; int ylow; - xlow = floor(x); - ylow = floor(y); + xlow = floor_to_int(x); + ylow = floor_to_int(y); int hit = 0; for (ix = xlow - 1; ix <= xlow + 2 && !hit; ix++) { @@ -62,7 +62,7 @@ bool PaintedGrid::getInterpolatedValue(double x, double y, double *result) const } } - *result = Interpolation::bicubic(stencil, x - (double)xlow, y - (double)ylow); + *result = Interpolation::bicubic(stencil, x - to_double(xlow), y - to_double(ylow)); } return hit; @@ -121,9 +121,9 @@ void PaintedGrid::applyBrush(const PaintedGridBrush &brush, double x, double y, double dx, dy, influence; for (ix = xstart; ix <= xend; ix++) { - dx = (double)ix; + dx = to_double(ix); for (iy = ystart; iy <= yend; iy++) { - dy = (double)iy; + dy = to_double(iy); influence = brush.getInfluence(x - dx, y - dy); diff --git a/src/definition/PaintedGridBrush.cpp b/src/definition/PaintedGridBrush.cpp index 97e6cd5..42497b2 100644 --- a/src/definition/PaintedGridBrush.cpp +++ b/src/definition/PaintedGridBrush.cpp @@ -11,10 +11,10 @@ PaintedGridBrush::PaintedGridBrush(double hard_radius, double smoothed_size, dou void PaintedGridBrush::getArea(double x, double y, int *xstart, int *ystart, int *xend, int *yend) const { double s = smoothed_size + hard_radius; - *xstart = (int)floor(x - s); - *xend = (int)ceil(x + s); - *ystart = (int)floor(y - s); - *yend = (int)ceil(y + s); + *xstart = floor_to_int(x - s); + *xend = ceil_to_int(x + s); + *ystart = floor_to_int(y - s); + *yend = ceil_to_int(y + s); } double PaintedGridBrush::getInfluence(double dx, double dy) const { diff --git a/src/definition/Scenery.cpp b/src/definition/Scenery.cpp index c1b7295..f4d10da 100644 --- a/src/definition/Scenery.cpp +++ b/src/definition/Scenery.cpp @@ -37,8 +37,8 @@ void Scenery::validate() { Scenery::FileOperationResult Scenery::saveGlobal(const string &filepath) const { PackStream stream; - double app_header = (double)APP_HEADER; - double version_header = (double)DATA_VERSION; + double app_header = to_double(APP_HEADER); + double version_header = to_double(DATA_VERSION); if (not stream.bindToFile(filepath, true)) { return FILE_OPERATION_IOERROR; diff --git a/src/definition/TerrainDefinition.cpp b/src/definition/TerrainDefinition.cpp index 56c0895..5bf6eba 100644 --- a/src/definition/TerrainDefinition.cpp +++ b/src/definition/TerrainDefinition.cpp @@ -74,7 +74,7 @@ double TerrainDefinition::getGridHeight(int x, int z, bool with_painting) { double h; if (!with_painting || !has_painting || !height_map->getGridValue(x, z, &h)) { - h = _height_noise->get2DTotal((double)x, (double)z); + h = _height_noise->get2DTotal(to_double(x), to_double(z)); } return h; diff --git a/src/definition/VegetationModelDefinition.cpp b/src/definition/VegetationModelDefinition.cpp index 9be4362..fd55ced 100644 --- a/src/definition/VegetationModelDefinition.cpp +++ b/src/definition/VegetationModelDefinition.cpp @@ -115,7 +115,7 @@ static void addBranchRecurse(RandomGenerator &random, vector &br Vector3 new_direction = pivot1.multPoint(direction); for (int i = 0; i < split_count; i++) { Matrix4 pivot2 = - Matrix4::newRotateAxis(randomizeValue(random, M_PI * 2.0 / (double)split_count, 0.9, 1.1), direction); + Matrix4::newRotateAxis(randomizeValue(random, M_PI * 2.0 / to_double(split_count), 0.9, 1.1), direction); new_direction = pivot2.multPoint(new_direction); Vector3 new_base = base.add(direction.scale(randomizeValue(random, length, 0.4, 1.0))); diff --git a/src/interface/commandline/tests.cpp b/src/interface/commandline/tests.cpp index 453a51b..fb9a50e 100644 --- a/src/interface/commandline/tests.cpp +++ b/src/interface/commandline/tests.cpp @@ -84,7 +84,7 @@ static void testGroundShadowQuality() { renderer.setQuality(0.2); for (int i = 0; i < 6; i++) { // TODO keep same rasterization across renders - renderer.getTerrainRenderer()->setQuality((double)i / 5.0); + renderer.getTerrainRenderer()->setQuality(to_double(i) / 5.0); startTestRender(&renderer, "ground_shadow_quality", i); } } @@ -97,7 +97,7 @@ static void testRasterizationQuality() { renderer.setSize(800, 600); renderer.enablePostprocess(false); for (int i = 0; i < 6; i++) { - renderer.setQuality((double)i / 5.0); + renderer.setQuality(to_double(i) / 5.0); startTestRender(&renderer, "rasterization_quality", i); } } @@ -115,7 +115,7 @@ static void testCloudQuality() { SkyRasterizer rasterizer(&renderer, renderer.getProgressHelper(), 0); renderer.setSoloRasterizer(&rasterizer); for (int i = 0; i < 6; i++) { - renderer.setQuality((double)i / 5.0); + renderer.setQuality(to_double(i) / 5.0); rasterizer.setQuality(0.2); startTestRender(&renderer, "cloud_quality", i); } @@ -167,7 +167,7 @@ static void testGodRays() { // quality for (int i = 0; i < 6; i++) { - renderer.setQuality((double)i / 5.0); + renderer.setQuality(to_double(i) / 5.0); rasterizer.setQuality(0.2); startTestRender(&renderer, "god_rays_quality", i); } @@ -175,21 +175,21 @@ static void testGodRays() { // penetration for (int i = 0; i < 3; i++) { - scenery.getAtmosphere()->childGodRays()->propPenetration()->setValue(0.01 + 0.02 * (double)i); + scenery.getAtmosphere()->childGodRays()->propPenetration()->setValue(0.01 + 0.02 * to_double(i)); startTestRender(&renderer, "god_rays_penetration", i); } // resistance scenery.getAtmosphere()->childGodRays()->propPenetration()->setValue(0.01); for (int i = 0; i < 3; i++) { - scenery.getAtmosphere()->childGodRays()->propResistance()->setValue(0.1 + 0.1 * (double)i); + scenery.getAtmosphere()->childGodRays()->propResistance()->setValue(0.1 + 0.1 * to_double(i)); startTestRender(&renderer, "god_rays_resistance", i); } // boost scenery.getAtmosphere()->childGodRays()->propResistance()->setValue(0.3); for (int i = 0; i < 3; i++) { - scenery.getAtmosphere()->childGodRays()->propBoost()->setValue(2.0 + 4.0 * (double)i); + scenery.getAtmosphere()->childGodRays()->propBoost()->setValue(2.0 + 4.0 * to_double(i)); startTestRender(&renderer, "god_rays_boost", i); } } @@ -245,7 +245,7 @@ static void testSunNearHorizon() { renderer.setQuality(0.3); for (int i = 0; i <= 20; i++) { - scenery.getAtmosphere()->propDayTime()->setValue(0.24 + 0.001 * (double)i); + scenery.getAtmosphere()->propDayTime()->setValue(0.24 + 0.001 * to_double(i)); startTestRender(&renderer, "sun_near_horizon", i); } } diff --git a/src/interface/modeler/OpenGLView.cpp b/src/interface/modeler/OpenGLView.cpp index 89d6c3d..c7a6f44 100644 --- a/src/interface/modeler/OpenGLView.cpp +++ b/src/interface/modeler/OpenGLView.cpp @@ -80,7 +80,7 @@ void OpenGLView::wheelEvent(QWheelEvent *event) { } double factor = getSpeedFactor(event); - window->getCamera()->processZoom(0.01 * factor * (double)event->angleDelta().y()); + window->getCamera()->processZoom(0.01 * factor * to_double(event->angleDelta().y())); } void OpenGLView::mousePressEvent(QMouseEvent *event) { diff --git a/src/render/opengl/OpenGLTerrain.cpp b/src/render/opengl/OpenGLTerrain.cpp index da99fca..1b994e0 100644 --- a/src/render/opengl/OpenGLTerrain.cpp +++ b/src/render/opengl/OpenGLTerrain.cpp @@ -77,12 +77,12 @@ void OpenGLTerrain::initialize() { // Add terrain chunks int chunks = 12; double size = 800.0; - double chunksize = size / (double)chunks; + double chunksize = size / to_double(chunks); double start = -size / 2.0; for (int i = 0; i < chunks; i++) { for (int j = 0; j < chunks; j++) { - OpenGLTerrainChunk *chunk = new OpenGLTerrainChunk(renderer, start + chunksize * (double)i, - start + chunksize * (double)j, chunksize, chunks); + OpenGLTerrainChunk *chunk = new OpenGLTerrainChunk(renderer, start + chunksize * to_double(i), + start + chunksize * to_double(j), chunksize, chunks); pv->chunks.push_back(chunk); pv->queue.push_back(chunk); } diff --git a/src/render/opengl/OpenGLTerrainChunk.cpp b/src/render/opengl/OpenGLTerrainChunk.cpp index ee6d4f5..2738adf 100644 --- a/src/render/opengl/OpenGLTerrainChunk.cpp +++ b/src/render/opengl/OpenGLTerrainChunk.cpp @@ -35,7 +35,7 @@ OpenGLTerrainChunk::OpenGLTerrainChunk(OpenGLRenderer *renderer, double x, doubl _startx = x; _startz = z; _size = size; - _overall_step = size * (double)nbchunks; + _overall_step = size * to_double(nbchunks); distance_to_camera = 0.0; @@ -91,12 +91,12 @@ bool OpenGLTerrainChunk::maintain() { int new_texture_size = _texture_current_size ? _texture_current_size * 2 : 1; QImage *new_image = new QImage(_texture->scaled(new_texture_size + 1, new_texture_size + 1, Qt::IgnoreAspectRatio, Qt::FastTransformation)); - double factor = _size / (double)new_texture_size; + double factor = _size / to_double(new_texture_size); for (int j = 0; j <= new_texture_size; j++) { for (int i = 0; i <= new_texture_size; i++) { if (_texture_current_size <= 1 || i % 2 != 0 || j % 2 != 0) { - double x = _startx + factor * (double)i; - double z = _startz + factor * (double)j; + double x = _startx + factor * to_double(i); + double z = _startz + factor * to_double(j); Color color = _renderer->getTexturesRenderer()->applyToTerrain(x, z).final_color; color.normalize(); new_image->setPixel(i, j, color.to32BitRGBA()); @@ -159,7 +159,7 @@ void OpenGLTerrainChunk::updatePriority(CameraDefinition *camera) { // Update priority if (_reset_topology || _reset_texture || (_texture_max_size > 1 && _texture_current_size <= 1) || vertices_level < 8) { - priority = 1000.0 - (double)vertices_level; + priority = 1000.0 - to_double(vertices_level); } else if (_texture_current_size == _texture_wanted_size) { priority = -1000.0; } else { @@ -213,14 +213,14 @@ void OpenGLTerrainChunk::augmentVertices() { int next_vertices_level = vertices_level * 2; // TODO Re-use existing vertices from previous level when possible - double quad_size = _size / (double)next_vertices_level; + double quad_size = _size / to_double(next_vertices_level); for (int iz = 0; iz < next_vertices_level; iz++) { if (interrupt or _reset_topology) { return; } for (int ix = 0; ix < next_vertices_level; ix++) { - fillVerticesFromSquare(&next, (iz * next_vertices_level + ix) * 6, _startx + quad_size * (double)ix, - _startz + quad_size * (double)iz, quad_size); + fillVerticesFromSquare(&next, (iz * next_vertices_level + ix) * 6, _startx + quad_size * to_double(ix), + _startz + quad_size * to_double(iz), quad_size); } } diff --git a/src/render/opengl/OpenGLVegetationImpostor.cpp b/src/render/opengl/OpenGLVegetationImpostor.cpp index fa31f0c..ce5bf80 100644 --- a/src/render/opengl/OpenGLVegetationImpostor.cpp +++ b/src/render/opengl/OpenGLVegetationImpostor.cpp @@ -23,9 +23,9 @@ static inline Matrix4 matrixForIndex(int index) { if (index == 0) { return Matrix4::newRotateZ(M_PI_2); } else if (index < 6) { - return Matrix4::newRotateY(M_2PI * (double)(index - 1) * 0.2).mult(Matrix4::newRotateZ(M_PI_4)); + return Matrix4::newRotateY(M_2PI * to_double(index - 1) * 0.2).mult(Matrix4::newRotateZ(M_PI_4)); } else { - return Matrix4::newRotateY(M_2PI * (double)(index - 6) * 0.1); + return Matrix4::newRotateY(M_2PI * to_double(index - 6) * 0.1); } } @@ -92,9 +92,9 @@ void OpenGLVegetationImpostor::prepareTexture(const VegetationModelDefinition &m int starty = py * partsize; for (int x = 0; x < partsize; x++) { - double dx = (double)x / (double)partsize; + double dx = to_double(x) / to_double(partsize); for (int y = 0; y < partsize; y++) { - double dy = (double)y / (double)partsize; + double dy = to_double(y) / to_double(partsize); Vector3 near(5.0, dy - 0.5, -(dx - 0.5)); Vector3 far(-5.0, dy - 0.5, -(dx - 0.5)); @@ -122,10 +122,10 @@ int OpenGLVegetationImpostor::getIndex(const Vector3 &camera, const Vector3 &ins double angle = diff.phi / M_2PI; if (diff.theta > 0.4) { angle = (angle >= 0.9) ? 0.0 : (angle + 0.1); - return 1 + (int)(5.0 * angle); + return 1 + trunc_to_int(5.0 * angle); } else { angle = (angle >= 0.95) ? 0.0 : (angle + 0.05); - return 6 + (int)(10.0 * angle); + return 6 + trunc_to_int(10.0 * angle); } } @@ -141,7 +141,7 @@ void OpenGLVegetationImpostor::setVertex(int i, float u, float v) { Matrix4 rotation = matrixForIndex(index); Vector3 vertex = rotation.multPoint(Vector3(1.0, u, -(v - 0.5))); - vertices->set(index * 4 + i, vertex, (u + (double)px) / (double)parts, (v + (double)py) / (double)parts); + vertices->set(index * 4 + i, vertex, (u + to_double(px)) / to_double(parts), (v + to_double(py)) / to_double(parts)); } } } diff --git a/src/render/software/AtmosphereModelBruneton.cpp b/src/render/software/AtmosphereModelBruneton.cpp index e29c439..5d65737 100644 --- a/src/render/software/AtmosphereModelBruneton.cpp +++ b/src/render/software/AtmosphereModelBruneton.cpp @@ -179,13 +179,13 @@ static Color _texture4D(Texture4D *tex, double r, double mu, double muS, double double rho = sqrt(r * r - Rg * Rg); double rmu = r * mu; double delta = rmu * rmu - r * r + Rg * Rg; - Color cst = (rmu < 0.0 && delta > 0.0) ? vec4(1.0, 0.0, 0.0, 0.5 - 0.5 / (double)(RES_MU)) - : vec4(-1.0, H * H, H, 0.5 + 0.5 / (double)(RES_MU)); - double uR = 0.5 / (double)(RES_R) + rho / H * (1.0 - 1.0 / (double)(RES_R)); - double uMu = cst.a + (rmu * cst.r + sqrt(delta + cst.g)) / (rho + cst.b) * (0.5 - 1.0 / (double)(RES_MU)); + Color cst = (rmu < 0.0 && delta > 0.0) ? vec4(1.0, 0.0, 0.0, 0.5 - 0.5 / to_double(RES_MU)) + : vec4(-1.0, H * H, H, 0.5 + 0.5 / to_double(RES_MU)); + double uR = 0.5 / to_double(RES_R) + rho / H * (1.0 - 1.0 / to_double(RES_R)); + double uMu = cst.a + (rmu * cst.r + sqrt(delta + cst.g)) / (rho + cst.b) * (0.5 - 1.0 / to_double(RES_MU)); double uMuS = - 0.5 / (double)(RES_MU_S) + - (atan(max(muS, -0.1975) * tan(1.26 * 1.1)) / 1.1 + (1.0 - 0.26)) * 0.5 * (1.0 - 1.0 / (double)(RES_MU_S)); + 0.5 / to_double(RES_MU_S) + + (atan(max(muS, -0.1975) * tan(1.26 * 1.1)) / 1.1 + (1.0 - 0.26)) * 0.5 * (1.0 - 1.0 / to_double(RES_MU_S)); return tex->getLinear(uMu, uMuS, nu, uR); } @@ -311,9 +311,9 @@ static void _texCoordToMuMuSNu(double x, double y, double z, double r, Color dhd double *nu) { double d; - x /= (double)RES_MU; - y /= (double)RES_MU_S; - z /= (double)RES_NU; + x /= to_double(RES_MU); + y /= to_double(RES_MU_S); + z /= to_double(RES_NU); if (x < 0.5) { d = 1.0 - x / 0.5; @@ -349,11 +349,11 @@ static void _getTransmittanceRMu(double x, double y, double *r, double *muS) { static double _opticalDepthTransmittance(double H, double r, double mu) { double result = 0.0; - double dx = _limit(r, mu) / (double)TRANSMITTANCE_INTEGRAL_SAMPLES; + double dx = _limit(r, mu) / to_double(TRANSMITTANCE_INTEGRAL_SAMPLES); double yi = exp(-(r - Rg) / H); int i; for (i = 1; i <= TRANSMITTANCE_INTEGRAL_SAMPLES; ++i) { - double xj = (double)i * dx; + double xj = to_double(i) * dx; double yj = exp(-(sqrt(r * r + xj * xj + 2.0 * xj * r * mu) - Rg) / H); result += (yi + yj) / 2.0 * dx; yi = yj; @@ -367,7 +367,7 @@ static void _precomputeTransmittanceTexture() { for (x = 0; x < TRANSMITTANCE_W; x++) { for (y = 0; y < TRANSMITTANCE_H; y++) { double r, muS; - _getTransmittanceRMu((double)(x + 0.5) / TRANSMITTANCE_W, (double)(y + 0.5) / TRANSMITTANCE_H, &r, &muS); + _getTransmittanceRMu(to_double(x + 0.5) / TRANSMITTANCE_W, to_double(y + 0.5) / TRANSMITTANCE_H, &r, &muS); double depth1 = _opticalDepthTransmittance(HR, r, muS); double depth2 = _opticalDepthTransmittance(HM, r, muS); Color trans; @@ -390,7 +390,7 @@ static void _precomputeIrrDeltaETexture(Texture2D *destination) { for (y = 0; y < SKY_H; y++) { double r, muS; Color trans, irr; - _getIrradianceRMuS((double)x / SKY_W, (double)y / SKY_H, &r, &muS); + _getIrradianceRMuS(to_double(x) / SKY_W, to_double(y) / SKY_H, &r, &muS); trans = _transmittance(r, muS); irr.r = trans.r * max(muS, 0.0); @@ -446,13 +446,13 @@ static void _integrand1(double r, double mu, double muS, double nu, double t, Co static void _inscatter1(double r, double mu, double muS, double nu, Color *ray, Color *mie) { ray->r = ray->g = ray->b = 0.0; mie->r = mie->g = mie->b = 0.0; - double dx = _limit(r, mu) / (double)(INSCATTER_INTEGRAL_SAMPLES); + double dx = _limit(r, mu) / to_double(INSCATTER_INTEGRAL_SAMPLES); Color rayi; Color miei; _integrand1(r, mu, muS, nu, 0.0, &rayi, &miei); int i; for (i = 1; i <= INSCATTER_INTEGRAL_SAMPLES; ++i) { - double xj = (double)(i)*dx; + double xj = to_double(i)*dx; Color rayj; Color miej; _integrand1(r, mu, muS, nu, xj, &rayj, &miej); @@ -492,7 +492,7 @@ static int _inscatter1Worker(ParallelWork *, int layer, void *data) { Color ray = COLOR_BLACK; Color mie = COLOR_BLACK; double mu, muS, nu; - _texCoordToMuMuSNu((double)x, (double)y, (double)z, r, dhdH, &mu, &muS, &nu); + _texCoordToMuMuSNu(to_double(x), to_double(y), to_double(z), r, dhdH, &mu, &muS, &nu); _inscatter1(r, mu, muS, nu, &ray, &mie); /* store separately Rayleigh and Mie contributions, WITHOUT the phase function factor * (cf "Angular precision") */ @@ -510,8 +510,8 @@ static Color _inscatterS(double r, double mu, double muS, double nu, int first, Texture4D *deltaSM) { Color raymie = COLOR_BLACK; - double dphi = M_PI / (double)(INSCATTER_SPHERICAL_INTEGRAL_SAMPLES); - double dtheta = M_PI / (double)(INSCATTER_SPHERICAL_INTEGRAL_SAMPLES); + double dphi = M_PI / to_double(INSCATTER_SPHERICAL_INTEGRAL_SAMPLES); + double dtheta = M_PI / to_double(INSCATTER_SPHERICAL_INTEGRAL_SAMPLES); r = clamp(r, Rg, Rt); mu = clamp(mu, -1.0, 1.0); @@ -528,7 +528,7 @@ static Color _inscatterS(double r, double mu, double muS, double nu, int first, /* integral over 4.PI around x with two nested loops over w directions (theta,phi) -- Eq (7) */ int itheta; for (itheta = 0; itheta < INSCATTER_SPHERICAL_INTEGRAL_SAMPLES; ++itheta) { - double theta = ((double)(itheta) + 0.5) * dtheta; + double theta = (to_double(itheta) + 0.5) * dtheta; double ctheta = cos(theta); double greflectance = 0.0; @@ -544,7 +544,7 @@ static Color _inscatterS(double r, double mu, double muS, double nu, int first, int iphi; for (iphi = 0; iphi < 2 * INSCATTER_SPHERICAL_INTEGRAL_SAMPLES; ++iphi) { - double phi = ((double)(iphi) + 0.5) * dphi; + double phi = (to_double(iphi) + 0.5) * dphi; double dw = dtheta * dphi * sin(theta); Vector3 w = vec3(cos(phi) * sin(theta), sin(phi) * sin(theta), ctheta); @@ -619,7 +619,7 @@ static int _jWorker(ParallelWork *, int layer, void *data) { for (z = 0; z < RES_NU; z++) { Color raymie; double mu, muS, nu; - _texCoordToMuMuSNu((double)x, (double)y, (double)z, r, dhdH, &mu, &muS, &nu); + _texCoordToMuMuSNu(to_double(x), to_double(y), to_double(z), r, dhdH, &mu, &muS, &nu); raymie = _inscatterS(r, mu, muS, nu, params->first, params->deltaE, params->deltaSR, params->deltaSM); params->result->setPixel(x, y, z, layer, raymie); } @@ -632,22 +632,22 @@ static int _jWorker(ParallelWork *, int layer, void *data) { void _irradianceNProg(Texture2D *destination, Texture4D *deltaSR, Texture4D *deltaSM, int first) { int x, y; - double dphi = M_PI / (double)(IRRADIANCE_INTEGRAL_SAMPLES); - double dtheta = M_PI / (double)(IRRADIANCE_INTEGRAL_SAMPLES); + double dphi = M_PI / to_double(IRRADIANCE_INTEGRAL_SAMPLES); + double dtheta = M_PI / to_double(IRRADIANCE_INTEGRAL_SAMPLES); for (x = 0; x < SKY_W; x++) { for (y = 0; y < SKY_H; y++) { double r, muS; int iphi; - _getIrradianceRMuS((double)x / SKY_W, (double)y / SKY_H, &r, &muS); + _getIrradianceRMuS(to_double(x) / SKY_W, to_double(y) / SKY_H, &r, &muS); Vector3 s = vec3(max(sqrt(1.0 - muS * muS), 0.0), 0.0, muS); Color result = COLOR_BLACK; /* integral over 2.PI around x with two nested loops over w directions (theta,phi) -- Eq (15) */ for (iphi = 0; iphi < 2 * IRRADIANCE_INTEGRAL_SAMPLES; ++iphi) { - double phi = ((double)(iphi) + 0.5) * dphi; + double phi = (to_double(iphi) + 0.5) * dphi; int itheta; for (itheta = 0; itheta < IRRADIANCE_INTEGRAL_SAMPLES / 2; ++itheta) { - double theta = ((double)(itheta) + 0.5) * dtheta; + double theta = (to_double(itheta) + 0.5) * dtheta; double dw = dtheta * dphi * sin(theta); Vector3 w = vec3(cos(phi) * sin(theta), sin(phi) * sin(theta), cos(theta)); double nu = s.dotProduct(w); @@ -698,11 +698,11 @@ static Color _integrand2(Texture4D *deltaJ, double r, double mu, double muS, dou static Color _inscatterN(Texture4D *deltaJ, double r, double mu, double muS, double nu) { Color raymie = COLOR_BLACK; - double dx = _limit(r, mu) / (double)(INSCATTER_INTEGRAL_SAMPLES); + double dx = _limit(r, mu) / to_double(INSCATTER_INTEGRAL_SAMPLES); Color raymiei = _integrand2(deltaJ, r, mu, muS, nu, 0.0); int i; for (i = 1; i <= INSCATTER_INTEGRAL_SAMPLES; ++i) { - double xj = (double)(i)*dx; + double xj = to_double(i)*dx; Color raymiej = _integrand2(deltaJ, r, mu, muS, nu, xj); raymie.r += (raymiei.r + raymiej.r) / 2.0 * dx; raymie.g += (raymiei.g + raymiej.g) / 2.0 * dx; @@ -724,7 +724,7 @@ static int _inscatterNWorker(ParallelWork *, int layer, void *data) { for (y = 0; y < RES_MU_S; y++) { for (z = 0; z < RES_NU; z++) { double mu, muS, nu; - _texCoordToMuMuSNu((double)x, (double)y, (double)z, r, dhdH, &mu, &muS, &nu); + _texCoordToMuMuSNu(to_double(x), to_double(y), to_double(z), r, dhdH, &mu, &muS, &nu); params->destination->setPixel(x, y, z, layer, _inscatterN(params->deltaJ, r, mu, muS, nu)); } } @@ -751,7 +751,7 @@ static int _copyInscatterNWorker(ParallelWork *, int layer, void *data) { for (y = 0; y < RES_MU_S; y++) { for (z = 0; z < RES_NU; z++) { double mu, muS, nu; - _texCoordToMuMuSNu((double)x, (double)y, (double)z, r, dhdH, &mu, &muS, &nu); + _texCoordToMuMuSNu(to_double(x), to_double(y), to_double(z), r, dhdH, &mu, &muS, &nu); Color col1 = params->source->getPixel(x, y, z, layer); Color col2 = params->destination->getPixel(x, y, z, layer); col2.r += col1.r / _phaseFunctionR(nu); diff --git a/src/render/software/CanvasPreview.cpp b/src/render/software/CanvasPreview.cpp index 955ef8f..db516c3 100644 --- a/src/render/software/CanvasPreview.cpp +++ b/src/render/software/CanvasPreview.cpp @@ -59,8 +59,8 @@ void CanvasPreview::setSize(int real_width, int real_height, int preview_width, dirty_up = -1; scaled = (real_width != preview_height or real_height != preview_height); - factor_x = (double)preview_width / (double)real_width; - factor_y = (double)preview_height / (double)real_height; + factor_x = to_double(preview_width) / to_double(real_width); + factor_y = to_double(preview_height) / to_double(real_height); factor = factor_x * factor_y; lock->release(); diff --git a/src/render/software/OverlayRasterizer.cpp b/src/render/software/OverlayRasterizer.cpp index b750e10..34f40bc 100644 --- a/src/render/software/OverlayRasterizer.cpp +++ b/src/render/software/OverlayRasterizer.cpp @@ -16,8 +16,8 @@ int OverlayRasterizer::prepareRasterization() { } void OverlayRasterizer::rasterizeToCanvas(CanvasPortion *canvas) { - double width = (double)renderer->render_camera->getWidth(); - double height = (double)renderer->render_camera->getHeight(); + double width = to_double(renderer->render_camera->getWidth()); + double height = to_double(renderer->render_camera->getHeight()); Vector3 topleft = renderer->unprojectPoint(Vector3(height, 0.0, 1.0)); Vector3 bottomleft = renderer->unprojectPoint(Vector3(0.0, 0.0, 1.0)); Vector3 topright = renderer->unprojectPoint(Vector3(height, width, 1.0)); @@ -27,8 +27,8 @@ void OverlayRasterizer::rasterizeToCanvas(CanvasPortion *canvas) { } Color OverlayRasterizer::shadeFragment(const CanvasFragment &fragment, const CanvasFragment *) const { - double width = (double)renderer->render_camera->getWidth() - 1.0; - double height = (double)renderer->render_camera->getHeight() - 1.0; + double width = to_double(renderer->render_camera->getWidth() - 1.0); + double height = to_double(renderer->render_camera->getHeight() - 1.0); double relx; double rely; double x = floor(fragment.getPixel().x); @@ -42,5 +42,5 @@ Color OverlayRasterizer::shadeFragment(const CanvasFragment &fragment, const Can rely = 2.0 * ((y - (height - width) * 0.5) / height - 0.5); } - return processPixel((int)x, (int)y, relx, rely); + return processPixel(trunc_to_int(x), trunc_to_int(y), relx, rely); } diff --git a/src/render/software/Rasterizer.cpp b/src/render/software/Rasterizer.cpp index f47c0a1..63c8bdf 100644 --- a/src/render/software/Rasterizer.cpp +++ b/src/render/software/Rasterizer.cpp @@ -82,8 +82,8 @@ bool Rasterizer::pushProjectedTriangle(CanvasPortion *canvas, const Vector3 &pix const Vector3 &pixel3, const Vector3 &location1, const Vector3 &location2, const Vector3 &location3) { ScanPoint point1, point2, point3; - double limit_width = (double)(canvas->getWidth() - 1); - double limit_height = (double)(canvas->getHeight() - 1); + double limit_width = to_double(canvas->getWidth() - 1); + double limit_height = to_double(canvas->getHeight() - 1); Vector3 canvas_offset(canvas->getXOffset(), canvas->getYOffset(), 0.0); Vector3 dpixel1 = pixel1.sub(canvas_offset); @@ -265,8 +265,8 @@ void Rasterizer::scanInterpolate(CameraDefinition *camera, ScanPoint *v1, ScanPo } void Rasterizer::pushScanPoint(CanvasPortion *canvas, RenderScanlines *scanlines, ScanPoint *point) { - point->x = (int)floor(point->pixel.x); - point->y = (int)floor(point->pixel.y); + point->x = floor_to_int(point->pixel.x); + point->y = floor_to_int(point->pixel.y); if (point->x < 0 || point->x >= canvas->getWidth()) { // Point outside scanline range @@ -332,7 +332,7 @@ void Rasterizer::pushScanLineEdge(CanvasPortion *canvas, RenderScanlines *scanli dx = point2->pixel.x - point1->pixel.x; scanGetDiff(point1, point2, &diff); for (curx = startx; curx <= endx; curx++) { - fx = (double)curx + 0.5; + fx = to_double(curx) + 0.5; if (fx < point1->pixel.x) { fx = point1->pixel.x; } else if (fx > point2->pixel.x) { @@ -341,7 +341,7 @@ void Rasterizer::pushScanLineEdge(CanvasPortion *canvas, RenderScanlines *scanli fx = fx - point1->pixel.x; scanInterpolate(renderer->render_camera, point1, &diff, fx / dx, &point); - /*point.pixel.x = (double)curx;*/ + /*point.pixel.x = to_double(curx);*/ pushScanPoint(canvas, scanlines, &point); } @@ -382,7 +382,7 @@ void Rasterizer::renderScanLines(CanvasPortion *canvas, RenderScanlines *scanlin // Down and up are the same current = down; } else { - fy = (double)cury + 0.5; + fy = to_double(cury) + 0.5; if (fy < down.pixel.y) { fy = down.pixel.y; } else if (fy > up.pixel.y) { diff --git a/src/render/software/RenderProgress.cpp b/src/render/software/RenderProgress.cpp index 5d2c449..de742fb 100644 --- a/src/render/software/RenderProgress.cpp +++ b/src/render/software/RenderProgress.cpp @@ -7,7 +7,7 @@ RenderProgress::RenderProgress(int count) { lock = new Mutex(); global = 0.0; - step = 1.0 / (double)count; + step = 1.0 / to_double(count); start_time = 0; end_time = 0; reset(); @@ -37,7 +37,7 @@ void RenderProgress::reset() { void RenderProgress::add(int value) { lock->acquire(); - global += step * (double)value; + global += step * to_double(value); lock->release(); } @@ -52,7 +52,7 @@ void RenderProgress::enterSub(int count) { lock->acquire(); subs.push(sub); - step /= (double)count; + step /= to_double(count); lock->release(); } @@ -88,7 +88,7 @@ unsigned long RenderProgress::getDuration() const { unsigned long RenderProgress::estimateRemainingTime() { unsigned long spent = getDuration(); - double speed = (global - prev_est_done) / (double)(spent - prev_est_spent); + double speed = (global - prev_est_done) / to_double(spent - prev_est_spent); prev_est_speed = prev_est_speed ? (prev_est_speed * 0.8 + speed * 0.2) : speed; if (spent - prev_est_spent > 5000) { diff --git a/src/render/software/SkyRasterizer.cpp b/src/render/software/SkyRasterizer.cpp index 98854a8..dc39980 100644 --- a/src/render/software/SkyRasterizer.cpp +++ b/src/render/software/SkyRasterizer.cpp @@ -29,8 +29,8 @@ void SkyRasterizer::rasterizeToCanvas(CanvasPortion *canvas) { Vector3 vertex1, vertex2, vertex3, vertex4; Vector3 camera_location, direction; - step_i = M_PI * 2.0 / (double)res_i; - step_j = M_PI / (double)res_j; + step_i = M_PI * 2.0 / to_double(res_i); + step_j = M_PI / to_double(res_j); camera_location = renderer->getCameraLocation(VECTOR_ZERO); @@ -39,10 +39,10 @@ void SkyRasterizer::rasterizeToCanvas(CanvasPortion *canvas) { return; } - current_j = (double)(j - res_j / 2) * step_j; + current_j = to_double(j - res_j / 2) * step_j; for (i = 0; i < res_i; i++) { - current_i = (double)i * step_i; + current_i = to_double(i) * step_i; direction.x = SPHERE_SIZE * cos(current_i) * cos(current_j); direction.y = SPHERE_SIZE * sin(current_j); diff --git a/src/render/software/SoftwareCanvasRenderer.cpp b/src/render/software/SoftwareCanvasRenderer.cpp index 3b73612..c2e448d 100644 --- a/src/render/software/SoftwareCanvasRenderer.cpp +++ b/src/render/software/SoftwareCanvasRenderer.cpp @@ -65,7 +65,7 @@ double SoftwareCanvasRenderer::getProgress() const { void SoftwareCanvasRenderer::setConfig(const RenderConfig &config) { if (not started) { setSize(config.width, config.height, config.antialias); - setQuality((double)(config.quality - 1) / 9.0); + setQuality(to_double(config.quality - 1) / 9.0); } } diff --git a/src/render/software/SoftwareRenderer.cpp b/src/render/software/SoftwareRenderer.cpp index 86b3048..305bab5 100644 --- a/src/render/software/SoftwareRenderer.cpp +++ b/src/render/software/SoftwareRenderer.cpp @@ -102,7 +102,7 @@ void SoftwareRenderer::setQuality(double quality) { godrays->setQuality(quality); // TEMP compat with old code - render_quality = (int)(quality * 9.0) + 1; + render_quality = trunc_to_int(quality * 9.0) + 1; } Color SoftwareRenderer::applyLightingToSurface(const Vector3 &location, const Vector3 &normal, @@ -147,7 +147,7 @@ double SoftwareRenderer::getPrecision(const Vector3 &location) { projected.x += 1.0; // projected.y += 1.0; - return render_camera->unproject(projected).sub(location).getNorm(); // / (double)render_quality; + return render_camera->unproject(projected).sub(location).getNorm(); // / to_double(render_quality); } Vector3 SoftwareRenderer::projectPoint(const Vector3 &point) { diff --git a/src/render/software/TerrainRasterizer.cpp b/src/render/software/TerrainRasterizer.cpp index 7257ce1..ed8beb4 100644 --- a/src/render/software/TerrainRasterizer.cpp +++ b/src/render/software/TerrainRasterizer.cpp @@ -37,12 +37,12 @@ void TerrainRasterizer::tessellateChunk(CanvasPortion *canvas, TerrainChunkInfo double startx = chunk->point_nw.x; double startz = chunk->point_nw.z; - double size = (chunk->point_ne.x - chunk->point_nw.x) / (double)detail; + double size = (chunk->point_ne.x - chunk->point_nw.x) / to_double(detail); int i, j; for (i = 0; i < detail; i++) { for (j = 0; j < detail; j++) { - renderQuad(canvas, startx + (double)i * size, startz + (double)j * size, size, water_height); + renderQuad(canvas, startx + to_double(i) * size, startz + to_double(j) * size, size, water_height); } progress->add(detail); } @@ -127,7 +127,7 @@ void TerrainRasterizer::getChunk(SoftwareRenderer *renderer, TerrainRasterizer:: int coverage = renderer->render_camera->isUnprojectedBoxInView(box); if (coverage > 0) { - chunk->detail_hint = (int)ceil(sqrt((double)coverage) * detail_factor); + chunk->detail_hint = ceil_to_int(sqrt(to_double(coverage)) * detail_factor); if (chunk->detail_hint > max_chunk_detail) { chunk->detail_hint = max_chunk_detail; } @@ -201,7 +201,7 @@ int TerrainRasterizer::performTessellation(CanvasPortion *canvas, bool displaced } } - if (radius_int > 20.0 && chunk_count % 64 == 0 && (double)chunk_factor < radius_int / 20.0) { + if (radius_int > 20.0 && chunk_count % 64 == 0 && to_double(chunk_factor) < radius_int / 20.0) { chunk_count /= 2; chunk_factor *= 2; } diff --git a/src/render/software/VegetationRenderer.cpp b/src/render/software/VegetationRenderer.cpp index 9f52a39..3f696f7 100644 --- a/src/render/software/VegetationRenderer.cpp +++ b/src/render/software/VegetationRenderer.cpp @@ -29,7 +29,7 @@ class VegetationGridIterator : public SpaceGridIterator { } virtual bool onCell(int x, int, int z) override { - result = renderer->getBoundResult(segment, (double)x, (double)z, only_hit); + result = renderer->getBoundResult(segment, to_double(x), to_double(z), only_hit); return not result.hit; } diff --git a/src/render/software/WaterRasterizer.cpp b/src/render/software/WaterRasterizer.cpp index 00b55f3..2869d2f 100644 --- a/src/render/software/WaterRasterizer.cpp +++ b/src/render/software/WaterRasterizer.cpp @@ -84,7 +84,7 @@ int WaterRasterizer::performTessellation(CanvasPortion *canvas) { progress->add(chunk_count - 1); } - if (radius_int > 20.0 && chunk_count % 64 == 0 && (double)chunk_factor < radius_int / 20.0) { + if (radius_int > 20.0 && chunk_count % 64 == 0 && to_double(chunk_factor) < radius_int / 20.0) { chunk_count /= 2; chunk_factor *= 2; } diff --git a/src/system/system_global.h b/src/system/system_global.h index 4b03fb6..1b8bcbc 100644 --- a/src/system/system_global.h +++ b/src/system/system_global.h @@ -40,6 +40,7 @@ using namespace std; // Some useful casts #define to_double(_x_) (static_cast(_x_)) +#define trunc_to_int(_x_) (static_cast(_x_)) #define round_to_int(_x_) (static_cast(round(_x_))) #define floor_to_int(_x_) (static_cast(floor(_x_))) #define ceil_to_int(_x_) (static_cast(ceil(_x_))) diff --git a/src/tests/CanvasPixel_Test.cpp b/src/tests/CanvasPixel_Test.cpp index 733b785..15dc871 100644 --- a/src/tests/CanvasPixel_Test.cpp +++ b/src/tests/CanvasPixel_Test.cpp @@ -10,13 +10,13 @@ TEST(CanvasPixel, MaxFragments) { // Overflow max fragment count with transparent fragments for (int i = 0; i < MAX_FRAGMENTS_PER_PIXEL * 2; i++) { - pixel.pushFragment(CanvasFragment(true, Vector3(0.0, 0.0, (double)i), Vector3(), 0, false)); + pixel.pushFragment(CanvasFragment(true, Vector3(0.0, 0.0, to_double(i)), Vector3(), 0, false)); } ASSERT_EQ(MAX_FRAGMENTS_PER_PIXEL, pixel.getFragmentCount()); EXPECT_DOUBLE_EQ(pixel.getFragment(0).getZ(), 0.0); EXPECT_EQ(pixel.getFragment(0).getOpaque(), true); - EXPECT_DOUBLE_EQ(pixel.getFragment(MAX_FRAGMENTS_PER_PIXEL - 1).getZ(), (double)(MAX_FRAGMENTS_PER_PIXEL * 2 - 1)); + EXPECT_DOUBLE_EQ(pixel.getFragment(MAX_FRAGMENTS_PER_PIXEL - 1).getZ(), to_double(MAX_FRAGMENTS_PER_PIXEL * 2 - 1)); EXPECT_EQ(pixel.getFragment(MAX_FRAGMENTS_PER_PIXEL - 1).getOpaque(), false); } diff --git a/src/tests/PackStream_Test.cpp b/src/tests/PackStream_Test.cpp index 29261cb..d3e3fa6 100644 --- a/src/tests/PackStream_Test.cpp +++ b/src/tests/PackStream_Test.cpp @@ -17,7 +17,7 @@ TEST(PackStream, All) { data_i = i; stream->write(&data_i); - data_d = (double)i; + data_d = to_double(i); stream->write(&data_d); data_s = "Testing string 0123 (accentué) !"; @@ -35,7 +35,7 @@ TEST(PackStream, All) { ASSERT_EQ(i, data_i); stream->read(&data_d); - ASSERT_DOUBLE_EQ((double)i, data_d); + ASSERT_DOUBLE_EQ(to_double(i), data_d); stream->read(buffer, 100); ASSERT_STREQ("Testing string 0123 (accentué) !", buffer);