From 56d899a5652d1e322b760a11b924e2fbe12b11bf Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 6 Jun 2009 21:37:44 +0100 Subject: [PATCH] Fix some Visual C++ warnings --- include/IGraphics.hpp | 14 +++++++------- include/IModel.hpp | 2 +- include/Maths.hpp | 6 +++--- include/TrackCommon.hpp | 2 +- src/Editor.cpp | 8 ++++---- src/Engine.cpp | 4 ++-- src/Game.cpp | 6 +++--- src/Map.cpp | 14 ++++++++------ src/Model.cpp | 2 +- src/SDLWindow.cpp | 32 ++++++++++++++++---------------- src/SmokeTrail.cpp | 12 +++++++----- src/TrackCommon.cpp | 14 +++++++------- src/Waggon.cpp | 4 ++-- src/gui/FuelMeter.cpp | 2 +- 14 files changed, 63 insertions(+), 59 deletions(-) diff --git a/include/IGraphics.hpp b/include/IGraphics.hpp index 2af95ca..701d405 100644 --- a/include/IGraphics.hpp +++ b/include/IGraphics.hpp @@ -26,13 +26,13 @@ struct IGraphics { virtual ~IGraphics() {} // Camera - virtual bool cuboidInViewFrustum(double x, double y, double z, - double sizeX, double sizeY, double sizeZ) = 0; - virtual bool cubeInViewFrustum(double x, double y, double z, - double size) = 0; - virtual bool pointInViewFrustum(double x, double y, double z) = 0; - virtual void setCamera(const Vector& aPos, - const Vector& aRotation) = 0; + virtual bool cuboidInViewFrustum(float x, float y, float z, + float sizeX, float sizeY, float sizeZ) = 0; + virtual bool cubeInViewFrustum(float x, float y, float z, + float size) = 0; + virtual bool pointInViewFrustum(float x, float y, float z) = 0; + virtual void setCamera(const Vector& aPos, + const Vector& aRotation) = 0; virtual void lookAt(const Vector anEyePoint, const Vector aTargetPoint) = 0; }; diff --git a/include/IModel.hpp b/include/IModel.hpp index 5d16705..2a29215 100644 --- a/include/IModel.hpp +++ b/include/IModel.hpp @@ -33,6 +33,6 @@ struct IModel { typedef std::tr1::shared_ptr IModelPtr; // Load a model from a WaveFront .obj file -IModelPtr loadModel(const std::string& fileName, double aScale = 1.0); +IModelPtr loadModel(const std::string& fileName, float aScale = 1.0); #endif diff --git a/include/Maths.hpp b/include/Maths.hpp index 2d3a3b0..5cc297c 100644 --- a/include/Maths.hpp +++ b/include/Maths.hpp @@ -188,13 +188,13 @@ Frustum getViewFrustum(); // Useful functions for converting to/from radians template -inline double degToRad(T t) +inline float degToRad(T t) { - return static_cast(t) * M_PI / 180.0; + return static_cast(t) * M_PI / 180.0; } template -inline T radToDeg(double r) +inline T radToDeg(float r) { return static_cast(r * 180.0 / M_PI); } diff --git a/include/TrackCommon.hpp b/include/TrackCommon.hpp index 951f324..a1b2ec1 100644 --- a/include/TrackCommon.hpp +++ b/include/TrackCommon.hpp @@ -29,7 +29,7 @@ void transformToOrigin(int baseRadius, track::Angle startAngle); // Track constants namespace track { - const float RAIL_HEIGHT = 0.1; + const float RAIL_HEIGHT = 0.1f; } #endif diff --git a/src/Editor.cpp b/src/Editor.cpp index c2b0460..0dfb5f8 100644 --- a/src/Editor.cpp +++ b/src/Editor.cpp @@ -69,7 +69,7 @@ private: IMapPtr myMap; ILightPtr mySun; - Vector myPosition; + Vector myPosition; string myFileName; bool amScrolling; @@ -147,7 +147,7 @@ void Editor::dragBoxBounds(int& xMin, int& xMax, int &yMin, int& yMax) const // Render the next frame void Editor::display(IGraphicsPtr aContext) const { - aContext->setCamera(myPosition, makeVector(45.0, 45.0, 0.0)); + aContext->setCamera(myPosition, makeVector(45.0f, 45.0f, 0.0f)); mySun->apply(); @@ -347,7 +347,7 @@ void Editor::drawDraggedTrack() } } - float startAngle, endAngle; + track::Angle startAngle, endAngle; Point where; if (startDir == axis::X && endDir == axis::Y) { @@ -423,7 +423,7 @@ void Editor::onMouseMove(IPickBufferPtr aPickBuffer, int x, int y, myDragEnd = myMap->pickPosition(id); } else if (amScrolling) { - const double speed = 0.05; + const float speed = 0.05f; myPosition.x -= xrel * speed; myPosition.z -= xrel * speed; diff --git a/src/Engine.cpp b/src/Engine.cpp index 0e450ec..037fbca 100644 --- a/src/Engine.cpp +++ b/src/Engine.cpp @@ -90,13 +90,13 @@ private: // Boiler pressure lags behind temperature MovingAverage myBoilerDelay; - static const double MODEL_SCALE; + static const float MODEL_SCALE; static const double TRACTIVE_EFFORT_KNEE; static const double INIT_PRESSURE, INIT_TEMP; }; -const double Engine::MODEL_SCALE(0.4); +const float Engine::MODEL_SCALE(0.4f); const double Engine::TRACTIVE_EFFORT_KNEE(10.0); const double Engine::INIT_PRESSURE(0.2); const double Engine::INIT_TEMP(50.0); diff --git a/src/Game.cpp b/src/Game.cpp index 1a8e837..dfd543a 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -116,7 +116,7 @@ void Game::display(IGraphicsPtr aContext) const // Two angles give unique position on surface of a sphere // Look up ``spherical coordinates'' - const double yCentre = 0.9f; + const float yCentre = 0.9f; Vector position = trainPos; position.x += myViewRadius * cosf(myHorizAngle) * sinf(myVertAngle); position.z += myViewRadius * sinf(myHorizAngle) * sinf(myVertAngle); @@ -211,12 +211,12 @@ void Game::onMouseMove(IPickBufferPtr aPickBuffer, int x, int y, myVertAngle += yrel / 150.0f; // Don't allow the camera to go under the ground - const double ground = (M_PI / 2.0f) - 0.01f; + const float ground = (M_PI / 2.0f) - 0.01f; if (myVertAngle > ground) myVertAngle = ground; // Don't let the camera flip over the top - const double top = 0.01f; + const float top = 0.01f; if (myVertAngle < top) myVertAngle = top; } diff --git a/src/Map.cpp b/src/Map.cpp index 438be77..f684218 100644 --- a/src/Map.cpp +++ b/src/Map.cpp @@ -193,9 +193,9 @@ Map::Map() myStartDirection(axis::X), shouldDrawGridLines(false), inPickMode(false) { - myFog = makeFog(0.6, 0.7, 0.8, // Colour - 0.25, // Density - 60.0, 70.0); // Start and end distance + myFog = makeFog(0.6f, 0.7f, 0.8f, // Colour + 0.25f, // Density + 60.0f, 70.0f); // Start and end distance } Map::~Map() @@ -361,7 +361,7 @@ void Map::render(IGraphicsPtr aContext) const { resetMarks(); - glClearColor(0.6, 0.7, 0.8, 1.0); + glClearColor(0.6f, 0.7f, 0.8f, 1.0f); myFog->apply(); @@ -404,7 +404,7 @@ void Map::highlightTile(IGraphicsPtr aContext, const Point& aPoint) const for (int i = 0; i < 4; i++) { Vertex& v = myHeightMap[indexes[i]]; glNormal3f(v.normal.x, v.normal.y, v.normal.z); - glVertex3f(v.pos.x, v.pos.y + 0.1, v.pos.z); + glVertex3f(v.pos.x, v.pos.y + 0.1f, v.pos.z); } glEnd(); @@ -430,7 +430,9 @@ void Map::drawStartLocation() const avgHeight += myHeightMap[indexes[i]].pos.y; avgHeight /= 4.0f; - glTranslatef(myStartLocation.x, avgHeight + 0.1f, myStartLocation.y); + glTranslatef(static_cast(myStartLocation.x), + avgHeight + 0.1f, + static_cast(myStartLocation.y)); if (myStartDirection == axis::X) glRotatef(90.0f, 0.0f, 1.0f, 0.0f); diff --git a/src/Model.cpp b/src/Model.cpp index c88b0eb..5e471f4 100644 --- a/src/Model.cpp +++ b/src/Model.cpp @@ -148,7 +148,7 @@ void Model::render() const // Load a WaveFront .obj model from disk or the cache // Each vertex is scaled by `aScale' -IModelPtr loadModel(const string& fileName, double aScale) +IModelPtr loadModel(const string& fileName, float aScale) { ModelCache::iterator it = theCache.find(fileName); if (it != theCache.end()) diff --git a/src/SDLWindow.cpp b/src/SDLWindow.cpp index 4129a15..bfb82cf 100644 --- a/src/SDLWindow.cpp +++ b/src/SDLWindow.cpp @@ -49,12 +49,12 @@ public: void takeScreenShot(); // IGraphics interface - bool cuboidInViewFrustum(double x, double y, double z, - double sizeX, double sizeY, double sizeZ); - bool cubeInViewFrustum(double x, double y, double z, double size); - bool pointInViewFrustum(double x, double y, double z); - void setCamera(const Vector& aPos, - const Vector& aRotation); + bool cuboidInViewFrustum(float x, float y, float z, + float sizeX, float sizeY, float sizeZ); + bool cubeInViewFrustum(float x, float y, float z, float size); + bool pointInViewFrustum(float x, float y, float z); + void setCamera(const Vector& aPos, + const Vector& aRotation); void lookAt(const Vector anEyePoint, const Vector aTargetPoint); IGraphicsPtr beginPick(int x, int y); @@ -253,13 +253,13 @@ void SDLWindow::quit() } // Called to set the camera position -void SDLWindow::setCamera(const Vector& aPos, - const Vector& aRotation) +void SDLWindow::setCamera(const Vector& aPos, + const Vector& aRotation) { - glRotated(aRotation.x, 1.0, 0.0, 0.0); - glRotated(aRotation.y, 0.0, 1.0, 0.0); - glRotated(aRotation.z, 0.0, 0.0, 1.0); - glTranslated(aPos.x, aPos.y, aPos.z); + glRotatef(aRotation.x, 1.0f, 0.0f, 0.0f); + glRotatef(aRotation.y, 0.0f, 1.0f, 0.0f); + glRotatef(aRotation.z, 0.0f, 0.0f, 1.0f); + glTranslatef(aPos.x, aPos.y, aPos.z); myViewFrustum = getViewFrustum(); } @@ -422,20 +422,20 @@ void SDLWindow::resizeGLScene() } // Intersect a cuboid with the current view frustum -bool SDLWindow::cuboidInViewFrustum(double x, double y, double z, - double sizeX, double sizeY, double sizeZ) +bool SDLWindow::cuboidInViewFrustum(float x, float y, float z, + float sizeX, float sizeY, float sizeZ) { return myViewFrustum.cuboidInFrustum(x, y, z, sizeX, sizeY, sizeZ); } // Intersect a cube with the current view frustum -bool SDLWindow::cubeInViewFrustum(double x, double y, double z, double size) +bool SDLWindow::cubeInViewFrustum(float x, float y, float z, float size) { return myViewFrustum.cubeInFrustum(x, y, z, size); } // True if the point is contained within the view frustum -bool SDLWindow::pointInViewFrustum(double x, double y, double z) +bool SDLWindow::pointInViewFrustum(float x, float y, float z) { return myViewFrustum.pointInFrustum(x, y, z); } diff --git a/src/SmokeTrail.cpp b/src/SmokeTrail.cpp index 21664ff..8214a59 100644 --- a/src/SmokeTrail.cpp +++ b/src/SmokeTrail.cpp @@ -134,16 +134,18 @@ void SmokeTrail::newParticle() // Random number generator for colour variance static variate_generator > - colourRand(mt19937(time(NULL)), normal_distribution<>(0.0f, 0.06f)); + colourRand(mt19937(static_cast(time(NULL))), + normal_distribution<>(0.0f, 0.06f)); // Random number generator for position variance static variate_generator > - posRand(mt19937(time(NULL)), normal_distribution<>(0.0f, 0.07f)); + posRand(mt19937(static_cast(time(NULL))), + normal_distribution<>(0.0f, 0.07f)); - const float col = 0.7f + colourRand(); + const float col = 0.7f + static_cast(colourRand()); - const float dx = posRand(); - const float dz = posRand(); + const float dx = static_cast(posRand()); + const float dz = static_cast(posRand()); Particle p = { myX + dx, myY, myZ + dz, // Position diff --git a/src/TrackCommon.cpp b/src/TrackCommon.cpp index b6c76c2..3d1b47d 100644 --- a/src/TrackCommon.cpp +++ b/src/TrackCommon.cpp @@ -34,7 +34,7 @@ namespace { const int SLEEPERS_PER_UNIT = 4; - const float SLEEPER_LENGTH = 0.8; + const float SLEEPER_LENGTH = 0.8f; IMeshPtr theSleeperMesh, theRailMesh; @@ -49,9 +49,9 @@ namespace { const float sleeperWidth = 0.1f; const float sleeperDepth = 0.05f; - const float sleeperOff = sleeperWidth / 2.0; + const float sleeperOff = sleeperWidth / 2.0f; - const float r = SLEEPER_LENGTH / 2.0; + const float r = SLEEPER_LENGTH / 2.0f; // Top buf->addQuad(makeVector(-sleeperOff, sleeperDepth, -r), @@ -127,7 +127,7 @@ namespace { IMeshPtr generateCurvedRailMesh(IMeshBufferPtr buf, int baseRadius, RailType type) { - const float edgeWidth = (1 - GAUGE - RAIL_WIDTH)/2.0; + const float edgeWidth = (1 - GAUGE - RAIL_WIDTH)/2.0f; const float R = static_cast(baseRadius) - edgeWidth - (type == OUTER_RAIL ? 0 : GAUGE); const float r = R - RAIL_WIDTH; @@ -274,15 +274,15 @@ void renderCurvedTrack(int baseRadius, track::Angle startAngle, glPopMatrix(); - const float length = degToRad(endAngle - startAngle) * baseRadius; - const int numSleepers = length * SLEEPERS_PER_UNIT; + const float length = degToRad(static_cast(endAngle - startAngle)) * baseRadius; + const int numSleepers = static_cast(length * SLEEPERS_PER_UNIT); const float sleeperAngle = static_cast(endAngle - startAngle) / numSleepers; for (int i = 0; i < numSleepers; i++) { glPushMatrix(); - glRotatef(static_cast(startAngle) + (i + 0.5)*sleeperAngle, + glRotatef(static_cast(startAngle) + (i + 0.5f)*sleeperAngle, 0.0f, 1.0f, 0.0f); glTranslatef(0.0f, 0.0f, static_cast(baseRadius) - 0.5f); diff --git a/src/Waggon.cpp b/src/Waggon.cpp index 761fb94..7f6af58 100644 --- a/src/Waggon.cpp +++ b/src/Waggon.cpp @@ -36,10 +36,10 @@ public: private: IModelPtr myModel; - static const double MODEL_SCALE; + static const float MODEL_SCALE; }; -const double Waggon::MODEL_SCALE(0.4); +const float Waggon::MODEL_SCALE(0.4f); Waggon::Waggon() { diff --git a/src/gui/FuelMeter.cpp b/src/gui/FuelMeter.cpp index f857568..a789a5d 100644 --- a/src/gui/FuelMeter.cpp +++ b/src/gui/FuelMeter.cpp @@ -111,7 +111,7 @@ void FuelMeter::render(int x, int y) const glBegin(GL_QUADS); glVertex2i(0, 0); glVertex2i(0, METER_HEIGHT); - glVertex2f(unit * myValue, METER_HEIGHT); + glVertex2f(unit * myValue, static_cast(METER_HEIGHT)); glVertex2f(unit * myValue, 0); glEnd(); -- 2.39.2