Merge pull request #1250 from Azaezel/alpha41/roundRobin

Alpha41/round robin
This commit is contained in:
Brian Roberts 2024-04-10 16:03:55 -05:00 committed by GitHub
commit 328ff16165
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 39 additions and 54 deletions

View file

@ -958,19 +958,14 @@ void Gizmo::on3DMouseDragged( const Gui3DMouseEvent & event )
mDeltaScale.zero();
Point3F newPosition;
if( mProfile->snapToGrid )
{
Point3F snappedMouseDownProjPnt = _snapPoint( mMouseDownProjPnt );
mDeltaTotalPos = projPnt - snappedMouseDownProjPnt;
newPosition = projPnt;
}
else
{
mDeltaTotalPos = projPnt - mMouseDownProjPnt;
newPosition = mSavedTransform.getPosition() + mDeltaTotalPos;
}
mDeltaTotalPos = projPnt - mMouseDownProjPnt;
newPosition = mSavedTransform.getPosition() + mDeltaTotalPos;
mDeltaPos = newPosition - mTransform.getPosition();
if (mProfile->snapToGrid)
newPosition = _snapPoint(newPosition);
mTransform.setPosition( newPosition );
mCurrentTransform.setPosition( newPosition );
@ -1094,7 +1089,7 @@ void Gizmo::on3DMouseDragged( const Gui3DMouseEvent & event )
//
if((mProfile->forceSnapRotations && event.modifier | SI_SHIFT) || (mProfile->allowSnapRotations && event.modifier & SI_SHIFT ))
angle = mDegToRad( _snapFloat( mRadToDeg( angle ), mProfile->rotationSnap ) );
angle = mDegToRad( mRoundF( mRadToDeg( angle ), mProfile->rotationSnap ) );
mDeltaAngle = angle - mLastAngle;
mLastAngle = angle;
@ -1887,28 +1882,13 @@ Point3F Gizmo::_snapPoint( const Point3F &pnt ) const
return pnt;
Point3F snap;
snap.x = _snapFloat( pnt.x, mProfile->gridSize.x );
snap.y = _snapFloat( pnt.y, mProfile->gridSize.y );
snap.z = _snapFloat( pnt.z, mProfile->gridSize.z );
snap.x = mRoundF( pnt.x, mProfile->gridSize.x );
snap.y = mRoundF( pnt.y, mProfile->gridSize.y );
snap.z = mRoundF( pnt.z, mProfile->gridSize.z );
return snap;
}
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);
}
GizmoAlignment Gizmo::_filteredAlignment()
{
GizmoAlignment align = mProfile->alignment;

View file

@ -313,7 +313,6 @@ protected:
void _renderAxisText();
void _renderPlane();
Point3F _snapPoint( const Point3F &pnt ) const;
F32 _snapFloat( const F32 &val, const F32 &snap ) const;
GizmoAlignment _filteredAlignment();
void _updateState( bool collideGizmo = true );
void _updateEnabledAxices();

View file

@ -306,9 +306,9 @@ void WorldEditorSelection::offset( const Point3F& offset, F32 gridSnap )
if( gridSnap != 0.f )
{
wPos.x = _snapFloat(wPos.x, gridSnap);
wPos.y = _snapFloat(wPos.y, gridSnap);
wPos.z = _snapFloat(wPos.z, gridSnap);
wPos.x = mRoundF(wPos.x, gridSnap);
wPos.y = mRoundF(wPos.y, gridSnap);
wPos.z = mRoundF(wPos.z, gridSnap);
}
mat.setColumn(3, wPos);
@ -318,22 +318,6 @@ void WorldEditorSelection::offset( const Point3F& offset, F32 gridSnap )
mCentroidValid = false;
}
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);
}
//-----------------------------------------------------------------------------
void WorldEditorSelection::setPosition(const Point3F & pos)

View file

@ -108,7 +108,6 @@ class WorldEditorSelection : public SimPersistSet
//
void offset(const Point3F& delta, F32 gridSnap = 0.f );
void setPosition(const Point3F & pos);
F32 _snapFloat(const F32 &val, const F32 &snap) const;
void setCentroidPosition(bool useBoxCenter, const Point3F & pos);
void orient(const MatrixF &, const Point3F &);

View file

@ -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),

View file

@ -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)
{

View file

@ -827,7 +827,7 @@ void mShortestSegmentBetweenLines( const Line &line0, const Line &line1, LineSeg
F32 denom = a*c - b*b;
if ( denom > -0.001f && denom < 0.001f )
if ( denom > -POINT_EPSILON && denom < POINT_EPSILON)
{
outSegment->p0 = line0.origin;
outSegment->p1 = line1.origin + (e/c)*line1.direction;