diff --git a/Engine/source/gui/worldEditor/gizmo.cpp b/Engine/source/gui/worldEditor/gizmo.cpp index 200b036cb..ac3d12807 100644 --- a/Engine/source/gui/worldEditor/gizmo.cpp +++ b/Engine/source/gui/worldEditor/gizmo.cpp @@ -1895,18 +1895,8 @@ Point3F Gizmo::_snapPoint( const Point3F &pnt ) const } F32 Gizmo::_snapFloat( const F32 &val, const F32 &snap ) const -{ - if ( snap == 0.0f ) - return val; - - F32 a = mFmod( val, snap ); - - F32 temp = val; - - if ( mFabs(a) > (snap / 2) ) - val < 0.0f ? temp -= snap : temp += snap; - - return(temp - a); +{ + return mRoundF(val, snap); } GizmoAlignment Gizmo::_filteredAlignment() diff --git a/Engine/source/gui/worldEditor/worldEditorSelection.cpp b/Engine/source/gui/worldEditor/worldEditorSelection.cpp index 3d83ccb36..bcf292efa 100644 --- a/Engine/source/gui/worldEditor/worldEditorSelection.cpp +++ b/Engine/source/gui/worldEditor/worldEditorSelection.cpp @@ -320,17 +320,7 @@ void WorldEditorSelection::offset( const Point3F& offset, F32 gridSnap ) F32 WorldEditorSelection::_snapFloat(const F32 &val, const F32 &snap) const { - if (snap == 0.0f) - return val; - - F32 a = mFmod(val, snap); - - F32 temp = val; - - if (mFabs(a) > (snap / 2)) - val < 0.0f ? temp -= snap : temp += snap; - - return(temp - a); + return mRoundF(val, snap); } diff --git a/Engine/source/math/mConsoleFunctions.cpp b/Engine/source/math/mConsoleFunctions.cpp index ef0e14445..ddb90ca93 100644 --- a/Engine/source/math/mConsoleFunctions.cpp +++ b/Engine/source/math/mConsoleFunctions.cpp @@ -103,6 +103,14 @@ DefineEngineFunction( mRound, S32, ( F32 v ),, "@ingroup Math" ) { return mRound(v); + +DefineEngineFunction(mRoundF, F32, (F32 v, F32 step), , + "Round v to the nth decimal place or the nearest whole number by default." + "@param v Value to roundn" + "@return The rounded value as a F32." + "@ingroup Math") +{ + return mRoundF(v, step); } DefineEngineFunction(mRoundDelta, S32, (F32 v, S32 d), (0.0, 1), diff --git a/Engine/source/math/mMathFn.h b/Engine/source/math/mMathFn.h index 6dffd5d3d..1c65604a1 100644 --- a/Engine/source/math/mMathFn.h +++ b/Engine/source/math/mMathFn.h @@ -217,7 +217,22 @@ inline F32 mRound(const F32 val, const S32 n) S32 place = (S32) pow(10.0f, n); return mFloor((val*place)+0.5)/place; -} +} + +inline F32 mRoundF(const F32 val, const F32 step) +{ + if (step == 0.0f) + return val; + + F32 a = mFmod(val, step); + + F32 temp = val; + + if (mFabs(a) > (step / 2)) + val < 0.0f ? temp -= step : temp += step; + + return(temp - a); +} inline S32 mAbs(const S32 val) {