Bugfix in MoverRelative.
Old code was "undoing" offsets other than their own, so stacking multiple movers was broken.
This commit is contained in:
parent
383ea0c17b
commit
3e8084c385
3 changed files with 23 additions and 4 deletions
|
@ -14,7 +14,7 @@ namespace cloonel {
|
|||
Mover ( void ) = default;
|
||||
virtual ~Mover ( void ) noexcept = default;
|
||||
|
||||
void Update ( float parDelta );
|
||||
virtual void Update ( float parDelta );
|
||||
PlaceableTicketType RegisterPlaceable ( Placeable* parPlaceable ) { return m_placeables.Add(parPlaceable); }
|
||||
void UnregisterPlaceable ( PlaceableTicketType parID ) noexcept { m_placeables.Remove(parID); }
|
||||
|
||||
|
|
|
@ -2,10 +2,24 @@
|
|||
#include "placeable.hpp"
|
||||
|
||||
namespace cloonel {
|
||||
///--------------------------------------------------------------------------
|
||||
///--------------------------------------------------------------------------
|
||||
MoverRelative::MoverRelative() :
|
||||
m_prevOffset(0.0f)
|
||||
{
|
||||
}
|
||||
|
||||
///--------------------------------------------------------------------------
|
||||
///--------------------------------------------------------------------------
|
||||
void MoverRelative::UpdateSingle (Placeable* parPlaceable) {
|
||||
const float2 newPos(GetOffset() - parPlaceable->GetPos());
|
||||
parPlaceable->AddOffset(newPos);
|
||||
const float2 offs(GetOffset() - m_prevOffset);
|
||||
parPlaceable->AddOffset(offs);
|
||||
}
|
||||
|
||||
///--------------------------------------------------------------------------
|
||||
///--------------------------------------------------------------------------
|
||||
void MoverRelative::Update (float parDelta) {
|
||||
m_prevOffset = GetOffset();
|
||||
Mover::Update(parDelta);
|
||||
}
|
||||
} //namespace cloonel
|
||||
|
|
|
@ -6,12 +6,17 @@
|
|||
namespace cloonel {
|
||||
class MoverRelative : public Mover {
|
||||
public:
|
||||
MoverRelative ( void ) = default;
|
||||
MoverRelative ( void );
|
||||
virtual ~MoverRelative ( void ) noexcept = default;
|
||||
|
||||
virtual void Update ( float parDelta );
|
||||
|
||||
protected:
|
||||
virtual void UpdateSingle ( Placeable* parPlaceable );
|
||||
virtual float2 GetOffset ( void ) const = 0;
|
||||
|
||||
private:
|
||||
float2 m_prevOffset;
|
||||
};
|
||||
} //namespace cloonel
|
||||
|
||||
|
|
Loading…
Reference in a new issue