Zappy GUI
C++ graphic client: renderer, camera, network
Loading...
Searching...
No Matches
TurnBehavior.cpp
Go to the documentation of this file.
1#include "TurnBehavior.hpp"
2
3#include <cmath>
4
5TurnBehavior::TurnBehavior(VisualState& visual, float fromAngle, float toAngle, float duration)
6 : _visual(visual), _fromAngle(fromAngle), _duration(duration)
7{
8 // Normalize fromAngle to [0, 360) before computing shortest arc
9 float normalizedFrom = fmod(fromAngle, 360.0f);
10 if (normalizedFrom < 0.0f) normalizedFrom += 360.0f;
11 _fromAngle = normalizedFrom;
12 _delta = fmod(toAngle - normalizedFrom + 540.0f, 360.0f) - 180.0f;
13}
14
16{
17 _elapsed += dt;
18 float t = _elapsed / _duration;
19 if (t > 1.0f) t = 1.0f;
21}
22
23bool TurnBehavior::isDone() const { return _elapsed >= _duration; }
24
26float TurnBehavior::_smoothstep(float t) { return t * t * (3.0f - 2.0f * t); }
float toAngle(Orientation orientation)
Returns the Y rotation angle (degrees) for a given orientation.
void update(float dt) override
TurnBehavior(VisualState &visual, float fromAngle, float toAngle, float duration)
bool isDone() const override
Returns true when the behavior has completed and can be removed.
static float _smoothstep(float t)
VisualState & _visual
Visual-only state for an entity, driven by behaviors each frame. Logical state (x,...