diff options
author | madmaxoft <github@xoft.cz> | 2013-09-07 22:06:30 +0200 |
---|---|---|
committer | madmaxoft <github@xoft.cz> | 2013-09-07 22:06:30 +0200 |
commit | d31142811db9073b7b01b834ca3bf82f6bceb4a9 (patch) | |
tree | 9988b872e675a082253126b9ff292070e913b1cd /source/Entities/Entity.cpp | |
parent | Fixed a missing initialization in cMonster. (diff) | |
parent | Added a (disabled) block logging to projectile path-tracing. (diff) | |
download | cuberite-d31142811db9073b7b01b834ca3bf82f6bceb4a9.tar cuberite-d31142811db9073b7b01b834ca3bf82f6bceb4a9.tar.gz cuberite-d31142811db9073b7b01b834ca3bf82f6bceb4a9.tar.bz2 cuberite-d31142811db9073b7b01b834ca3bf82f6bceb4a9.tar.lz cuberite-d31142811db9073b7b01b834ca3bf82f6bceb4a9.tar.xz cuberite-d31142811db9073b7b01b834ca3bf82f6bceb4a9.tar.zst cuberite-d31142811db9073b7b01b834ca3bf82f6bceb4a9.zip |
Diffstat (limited to 'source/Entities/Entity.cpp')
-rw-r--r-- | source/Entities/Entity.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/source/Entities/Entity.cpp b/source/Entities/Entity.cpp index 4066e81ab..1a593b3d1 100644 --- a/source/Entities/Entity.cpp +++ b/source/Entities/Entity.cpp @@ -253,6 +253,39 @@ void cEntity::TakeDamage(eDamageType a_DamageType, cEntity * a_Attacker, int a_R +void cEntity::SetRotationFromSpeed(void) +{ + const double EPS = 0.0000001; + if ((abs(m_Speed.x) < EPS) && (abs(m_Speed.z) < EPS)) + { + // atan2() may overflow or is undefined, pick any number + SetRotation(0); + return; + } + SetRotation(atan2(m_Speed.x, m_Speed.z) * 180 / PI); +} + + + + + +void cEntity::SetPitchFromSpeed(void) +{ + const double EPS = 0.0000001; + double xz = sqrt(m_Speed.x * m_Speed.x + m_Speed.z * m_Speed.z); // Speed XZ-plane component + if ((abs(xz) < EPS) && (abs(m_Speed.y) < EPS)) + { + // atan2() may overflow or is undefined, pick any number + SetPitch(0); + return; + } + SetPitch(atan2(m_Speed.y, xz) * 180 / PI); +} + + + + + void cEntity::DoTakeDamage(TakeDamageInfo & a_TDI) { if (cRoot::Get()->GetPluginManager()->CallHookTakeDamage(*this, a_TDI)) |