TrinityCore
Loading...
Searching...
No Matches
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 "MovementInfo.h"
20#include "MovementTypedefs.h"
21#include "SmartEnum.h"
22#include <cmath>
23
24namespace Movement
25{
27
29 float constexpr terminalVelocity = 60.148003f;
30 float constexpr terminalSafefallVelocity = 7.0f;
31
32 float constexpr terminal_length = float(terminalVelocity * terminalVelocity) / (2.0f * gravity);
34 float constexpr terminal_fallTime = float(terminalVelocity / gravity); // the time that needed to reach terminalVelocity
35 float constexpr terminal_safeFall_fallTime = float(terminalSafefallVelocity / gravity); // the time that needed to reach terminalVelocity with safefall
36
37 float computeFallTime(float path_length, bool isSafeFall)
38 {
39 if (path_length < 0.0f)
40 return 0.0f;
41
42 float time;
43 if (isSafeFall)
44 {
45 if (path_length >= terminal_safeFall_length)
47 else
48 time = std::sqrt(2.0f * path_length / gravity);
49 }
50 else
51 {
52 if (path_length >= terminal_length)
53 time = (path_length - terminal_length) / terminalVelocity + terminal_fallTime;
54 else
55 time = std::sqrt(2.0f * path_length / gravity);
56 }
57
58 return time;
59 }
60
61 float computeFallElevation(float t_passed, bool isSafeFall, float start_velocity /*= 0.0f*/)
62 {
63 float termVel;
64 float result;
65
66 if (isSafeFall)
68 else
69 termVel = terminalVelocity;
70
71 if (start_velocity > termVel)
72 start_velocity = termVel;
73
74 float terminal_time = (isSafeFall ? terminal_safeFall_fallTime : terminal_fallTime) - start_velocity / gravity; // the time that needed to reach terminalVelocity
75
76 if (t_passed > terminal_time)
77 {
78 result = termVel * (t_passed - terminal_time) +
79 start_velocity * terminal_time +
80 gravity * terminal_time * terminal_time * 0.5f;
81 }
82 else
83 result = t_passed * (start_velocity + t_passed * gravity * 0.5f);
84
85 return result;
86 }
87
88 template<class Flags>
89 void PrintFlags(Flags t, std::string& str)
90 {
91 for (Flags flag : EnumUtils::Iterate<Flags>())
92 if ((t & flag) != Flags(0))
93 str.append(" ").append(EnumUtils::ToConstant(flag));
94 }
95
96 std::string MoveSplineFlag::ToString() const
97 {
98 std::string str;
99 PrintFlags<MoveSplineFlagEnum>(Raw, str);
100 return str;
101 }
102
104 {
105 std::string str;
106 PrintFlags(flags, str);
107 return str;
108 }
109}
uint16 flags
MovementFlags
static char const * ToConstant(Enum value)
Definition SmartEnum.h:121
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