From 1cb0cd80441c26d1305974bbed589648e06a7464 Mon Sep 17 00:00:00 2001 From: Jan Bender Date: Thu, 16 Apr 2020 09:25:51 +0200 Subject: [PATCH] - fixed several compiler warnings --- CMake/Common.cmake | 11 ++++--- Changelog.txt | 1 + Demos/Visualization/MiniGL.cpp | 10 +++--- .../PositionBasedRigidBodyDynamics.cpp | 32 +++++++++---------- Simulation/BoundingSphere.h | 18 +++++------ Utils/Logger.h | 2 +- 6 files changed, 38 insertions(+), 36 deletions(-) diff --git a/CMake/Common.cmake b/CMake/Common.cmake index ac795954..4a4a0025 100644 --- a/CMake/Common.cmake +++ b/CMake/Common.cmake @@ -33,11 +33,10 @@ if (MSVC) set(CMAKE_USE_RELATIVE_PATHS "1") # Set compiler flags set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MP /bigobj") - set(CMAKE_CXX_FLAGS_RELEASE "/MD /MP /Ox /Ob2 /Oi /Ot /D NDEBUG") - set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "/MD /Zi /MP /Ox /Ob2 /Oi /Ot /D NDEBUG /bigobj") - set(CMAKE_EXE_LINKER_FLAGS_RELEASE "/INCREMENTAL:NO") - set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "/INCREMENTAL:NO") - set(CMAKE_STATIC_LINKER_FLAGS_RELEASE "/INCREMENTAL:NO") + set(CMAKE_CXX_FLAGS_RELEASE "/MD /MP /Ox /Ob2 /Oi /Ot /fp:fast /D NDEBUG") + set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "/MD /Zi /MP /Ox /Ob2 /Oi /Ot /fp:fast /D NDEBUG /bigobj") + set(CMAKE_EXE_LINKER_FLAGS_RELEASE "/INCREMENTAL") + set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "/INCREMENTAL") endif (MSVC) if (UNIX OR MINGW) @@ -57,7 +56,9 @@ endif() set (CMAKE_CXX_STANDARD 11) +if (MSVC) add_definitions(-D_CRT_SECURE_NO_DEPRECATE) +endif(MSVC) OPTION(USE_DOUBLE_PRECISION "Use double precision" ON) if (USE_DOUBLE_PRECISION) diff --git a/Changelog.txt b/Changelog.txt index 8bc0f1ac..387ecd00 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -1,3 +1,4 @@ + - fixed several compiler warnings - removed MiniBall dependency - update to Eigen 3.3.7 diff --git a/Demos/Visualization/MiniGL.cpp b/Demos/Visualization/MiniGL.cpp index d1cd1981..4704fd28 100644 --- a/Demos/Visualization/MiniGL.cpp +++ b/Demos/Visualization/MiniGL.cpp @@ -189,7 +189,7 @@ void MiniGL::drawCylinder(const Vector3r &a, const Vector3r &b, const float *col if (vz == 0) vz = .00000001; Real v = sqrt(vx*vx + vy*vy + vz*vz); - Real ax = 57.2957795*acos(vz / v); + Real ax = static_cast(57.2957795)*acos(vz / v); if (vz < 0.0) ax = -ax; Real rx = -vy*vz; @@ -924,18 +924,18 @@ void MiniGL::mouseMove (int x, int y) // translate scene in z direction if (modifier_key == GLUT_ACTIVE_CTRL) { - move (0, 0, -(d_x + d_y) / 10.0); + move (0, 0, -(d_x + d_y) / static_cast(10.0)); } // translate scene in x/y direction else if (modifier_key == GLUT_ACTIVE_SHIFT) { - move (-d_x / 20.0f, -d_y / 20.0, 0); + move (-d_x / static_cast(20.0), -d_y / static_cast(20.0), 0); } // rotate scene around x, y axis else if (modifier_key == GLUT_ACTIVE_ALT) { - rotateX(d_y/ 100.0); - rotateY(-d_x/ 100.0); + rotateX(d_y/ static_cast(100.0)); + rotateY(-d_x/ static_cast(100.0)); } } diff --git a/PositionBasedDynamics/PositionBasedRigidBodyDynamics.cpp b/PositionBasedDynamics/PositionBasedRigidBodyDynamics.cpp index bfcd38d3..6bdc46d6 100644 --- a/PositionBasedDynamics/PositionBasedRigidBodyDynamics.cpp +++ b/PositionBasedDynamics/PositionBasedRigidBodyDynamics.cpp @@ -90,21 +90,21 @@ void PositionBasedRigidBodyDynamics::computeMatrixK( // ---------------------------------------------------------------------------------------------- void PositionBasedRigidBodyDynamics::computeMatrixG(const Quaternionr &q, Eigen::Matrix &G) { - G(0, 0) = -0.5*q.x(); - G(0, 1) = -0.5*q.y(); - G(0, 2) = -0.5*q.z(); + G(0, 0) = -static_cast(0.5)*q.x(); + G(0, 1) = -static_cast(0.5)*q.y(); + G(0, 2) = -static_cast(0.5)*q.z(); - G(1, 0) = 0.5*q.w(); - G(1, 1) = 0.5*q.z(); - G(1, 2) = -0.5*q.y(); + G(1, 0) = static_cast(0.5)*q.w(); + G(1, 1) = static_cast(0.5)*q.z(); + G(1, 2) = static_cast(-0.5)*q.y(); - G(2, 0) = -0.5*q.z(); - G(2, 1) = 0.5*q.w(); - G(2, 2) = 0.5*q.x(); + G(2, 0) = static_cast(-0.5)*q.z(); + G(2, 1) = static_cast(0.5)*q.w(); + G(2, 2) = static_cast(0.5)*q.x(); - G(3, 0) = 0.5*q.y(); - G(3, 1) = -0.5*q.x(); - G(3, 2) = 0.5*q.w(); + G(3, 0) = static_cast(0.5)*q.y(); + G(3, 1) = static_cast(-0.5)*q.x(); + G(3, 2) = static_cast(0.5)*q.w(); } // ---------------------------------------------------------------------------------------------- @@ -371,13 +371,13 @@ bool PositionBasedRigidBodyDynamics::solve_DistanceJoint( Real alpha = 0.0; if (stiffness != 0.0) { - alpha = 1.0 / (stiffness * dt * dt); + alpha = static_cast(1.0) / (stiffness * dt * dt); K += alpha; } Real Kinv = 0.0; if (fabs(K) > static_cast(1e-6)) - Kinv = 1.0 / K; + Kinv = static_cast(1.0) / K; else { corr_x0.setZero(); @@ -1609,7 +1609,7 @@ bool PositionBasedRigidBodyDynamics::solve_TargetAngleMotorHingeJoint( const Quaternionr tmp = (q0.conjugate() * q1); const Vector4r qVec(tmp.w(), tmp.x(), tmp.y(), tmp.z()); C.block<3, 1>(3, 0) = Pr * qVec; - C(3, 0) -= sin(0.5*targetAngle); + C(3, 0) -= sin(static_cast(0.5)*targetAngle); const Vector3r r0 = c0 - x0; @@ -2085,7 +2085,7 @@ bool PositionBasedRigidBodyDynamics::velocitySolve_TargetVelocityMotorHingeJoint Real alpha = 0.0; if (stiffness != 0.0) { - alpha = 1.0 / (stiffness * dt * dt); + alpha = static_cast(1.0) / (stiffness * dt * dt); K(0,0) += alpha; } diff --git a/Simulation/BoundingSphere.h b/Simulation/BoundingSphere.h index 9a8608bc..58915954 100644 --- a/Simulation/BoundingSphere.h +++ b/Simulation/BoundingSphere.h @@ -47,8 +47,8 @@ namespace PBD { const Vector3r ba = b - a; - m_x = (a + b) * 0.5; - m_r = 0.5 * ba.norm(); + m_x = (a + b) * static_cast(0.5); + m_r = static_cast(0.5) * ba.norm(); } /** @@ -69,9 +69,9 @@ namespace PBD ca[0], ca[1], ca[2], baxca[0], baxca[1], baxca[2]; - r[0] = 0.5 * ba.squaredNorm(); - r[1] = 0.5 * ca.squaredNorm(); - r[2] = 0.0; + r[0] = static_cast(0.5) * ba.squaredNorm(); + r[1] = static_cast(0.5) * ca.squaredNorm(); + r[2] = static_cast(0.0); m_x = T.inverse() * r; m_r = m_x.norm(); @@ -97,9 +97,9 @@ namespace PBD ca[0], ca[1], ca[2], da[0], da[1], da[2]; - r[0] = 0.5 * ba.squaredNorm(); - r[1] = 0.5 * ca.squaredNorm(); - r[2] = 0.5 * da.squaredNorm(); + r[0] = static_cast(0.5) * ba.squaredNorm(); + r[1] = static_cast(0.5) * ca.squaredNorm(); + r[2] = static_cast(0.5) * da.squaredNorm(); m_x = T.inverse() * r; m_r = m_x.norm(); m_x += a; @@ -189,7 +189,7 @@ namespace PBD } m_x = S.m_x; - m_r = S.m_r + epsilon; //add epsilon to make sure that all non-pertubated points are inside the sphere + m_r = S.m_r + static_cast(epsilon); //add epsilon to make sure that all non-pertubated points are inside the sphere } /** diff --git a/Utils/Logger.h b/Utils/Logger.h index 25747631..298daee1 100644 --- a/Utils/Logger.h +++ b/Utils/Logger.h @@ -12,7 +12,7 @@ namespace Utilities { - enum LogLevel { DEBUG=0, INFO, WARN, ERR }; + enum class LogLevel { DEBUG=0, INFO, WARN, ERR }; class LogSink {