TrinityCore
MovementUtil.cpp
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include "MoveSplineFlag.h"
19#include "MovementTypedefs.h"
20#include "SmartEnum.h"
21#include <cmath>
22
23namespace Movement
24{
26
28 float constexpr terminalVelocity = 60.148003f;
29 float constexpr terminalSafefallVelocity = 7.0f;
30
31 float constexpr terminal_length = float(terminalVelocity * terminalVelocity) / (2.0f * gravity);
33 float constexpr terminal_fallTime = float(terminalVelocity / gravity); // the time that needed to reach terminalVelocity
34 float constexpr terminal_safeFall_fallTime = float(terminalSafefallVelocity / gravity); // the time that needed to reach terminalVelocity with safefall
35
36 float computeFallTime(float path_length, bool isSafeFall)
37 {
38 if (path_length < 0.0f)
39 return 0.0f;
40
41 float time;
42 if (isSafeFall)
43 {
44 if (path_length >= terminal_safeFall_length)
46 else
47 time = std::sqrt(2.0f * path_length / gravity);
48 }
49 else
50 {
51 if (path_length >= terminal_length)
52 time = (path_length - terminal_length) / terminalVelocity + terminal_fallTime;
53 else
54 time = std::sqrt(2.0f * path_length / gravity);
55 }
56
57 return time;
58 }
59
60 float computeFallElevation(float t_passed, bool isSafeFall, float start_velocity /*= 0.0f*/)
61 {
62 float termVel;
63 float result;
64
65 if (isSafeFall)
67 else
68 termVel = terminalVelocity;
69
70 if (start_velocity > termVel)
71 start_velocity = termVel;
72
73 float terminal_time = (isSafeFall ? terminal_safeFall_fallTime : terminal_fallTime) - start_velocity / gravity; // the time that needed to reach terminalVelocity
74
75 if (t_passed > terminal_time)
76 {
77 result = termVel * (t_passed - terminal_time) +
78 start_velocity * terminal_time +
79 gravity * terminal_time * terminal_time * 0.5f;
80 }
81 else
82 result = t_passed * (start_velocity + t_passed * gravity * 0.5f);
83
84 return result;
85 }
86
87 template<class Flags>
88 void PrintFlags(Flags t, std::string& str)
89 {
90 for (Flags flag : EnumUtils::Iterate<Flags>())
91 if ((t & flag) != Flags(0))
92 str.append(" ").append(EnumUtils::ToConstant(flag));
93 }
94
95 std::string MoveSplineFlag::ToString() const
96 {
97 std::string str;
98 PrintFlags<MoveSplineFlagEnum>(Raw, str);
99 return str;
100 }
101
103 {
104 std::string str;
105 PrintFlags(flags, str);
106 return str;
107 }
108
110 {
111 std::string str;
112 PrintFlags(flags, str);
113 return str;
114 }
115
117 {
118 std::string str;
119 PrintFlags(flags, str);
120 return str;
121 }
122}
uint16 flags
Definition: DisableMgr.cpp:49
MovementFlags
Definition: UnitDefines.h:384
MovementFlags2
Definition: UnitDefines.h:444
MovementFlags3
Definition: UnitDefines.h:469
static char const * ToConstant(Enum value)
Definition: SmartEnum.h:120
float constexpr terminalVelocity
Velocity bounds that makes fall speed limited.
float constexpr gravity
float computeFallTime(float path_length, bool isSafeFall)
void PrintFlags(Flags t, std::string &str)
TC_GAME_API UInt32Counter splineIdGen
float constexpr terminalSafefallVelocity
float constexpr terminal_safeFall_length
float constexpr terminal_fallTime
float constexpr terminal_safeFall_fallTime
float computeFallElevation(float t_passed, bool isSafeFall, float start_velocity=0.0f)
TC_GAME_API std::string MovementFlags_ToString(MovementFlags flags)
float constexpr terminal_length
std::string ToString() const
EnumFlag< MoveSplineFlagEnum > Raw