mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-14 08:04:40 +00:00
round utility functions
add mRoundF to return nearest floating value to stepsize
This commit is contained in:
parent
f0e7a27c16
commit
f7ed077d82
4 changed files with 27 additions and 24 deletions
|
|
@ -1896,17 +1896,7 @@ Point3F Gizmo::_snapPoint( const Point3F &pnt ) const
|
||||||
|
|
||||||
F32 Gizmo::_snapFloat( const F32 &val, const F32 &snap ) const
|
F32 Gizmo::_snapFloat( const F32 &val, const F32 &snap ) const
|
||||||
{
|
{
|
||||||
if ( snap == 0.0f )
|
return mRoundF(val, snap);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GizmoAlignment Gizmo::_filteredAlignment()
|
GizmoAlignment Gizmo::_filteredAlignment()
|
||||||
|
|
|
||||||
|
|
@ -320,17 +320,7 @@ void WorldEditorSelection::offset( const Point3F& offset, F32 gridSnap )
|
||||||
|
|
||||||
F32 WorldEditorSelection::_snapFloat(const F32 &val, const F32 &snap) const
|
F32 WorldEditorSelection::_snapFloat(const F32 &val, const F32 &snap) const
|
||||||
{
|
{
|
||||||
if (snap == 0.0f)
|
return mRoundF(val, snap);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -103,6 +103,14 @@ DefineEngineFunction( mRound, S32, ( F32 v ),,
|
||||||
"@ingroup Math" )
|
"@ingroup Math" )
|
||||||
{
|
{
|
||||||
return mRound(v);
|
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),
|
DefineEngineFunction(mRoundDelta, S32, (F32 v, S32 d), (0.0, 1),
|
||||||
|
|
|
||||||
|
|
@ -219,6 +219,21 @@ inline F32 mRound(const F32 val, const S32 n)
|
||||||
return mFloor((val*place)+0.5)/place;
|
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)
|
inline S32 mAbs(const S32 val)
|
||||||
{
|
{
|
||||||
return abs(val);
|
return abs(val);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue