-
Notifications
You must be signed in to change notification settings - Fork 47
/
AngleKey.cpp
35 lines (25 loc) · 873 Bytes
/
AngleKey.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include "AngleKey.h"
#include "ientity.h"
#include "string/convert.h"
#include "math/Matrix4.h"
namespace entity
{
const float AngleKey::IDENTITY = 0;
void AngleKey::angleChanged(const std::string& value)
{
_value = getNormalisedAngle(string::convert<float>(value, 0));
_angleChanged();
}
void AngleKey::writeToEntity(double angle, Entity* entity)
{
// To resolve #3150, let's keep existing "angle" keys even if their value is "0"
bool hadAngleValue = !entity->getKeyValue("angle").empty();
entity->setKeyValue("angle", (angle == 0 && !hadAngleValue) ? "" : string::to_string(angle));
}
float AngleKey::getRotatedValue(float angle, const Quaternion& rotation)
{
return static_cast<float>(Matrix4::getRotationAboutZDegrees(angle).getMultipliedBy(
Matrix4::getRotationQuantised(rotation)
).getEulerAnglesXYZDegrees().z());
}
} // namespace