TrinityCore
MovementDefines.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 "MovementDefines.h"
19#include "ObjectDefines.h"
20#include "Position.h"
21#include <algorithm>
22
23 // ---- ChaseRange ---- //
24
25ChaseRange::ChaseRange(float range) : MinRange(range > CONTACT_DISTANCE ? 0 : range - CONTACT_DISTANCE), MinTolerance(range), MaxRange(range + CONTACT_DISTANCE), MaxTolerance(range) { }
26ChaseRange::ChaseRange(float _minRange, float _maxRange) : MinRange(_minRange), MinTolerance(std::min(_minRange + CONTACT_DISTANCE, (_minRange + _maxRange) / 2)), MaxRange(_maxRange), MaxTolerance(std::max(_maxRange - CONTACT_DISTANCE, MinTolerance)) { }
27ChaseRange::ChaseRange(float _minRange, float _minTolerance, float _maxTolerance, float _maxRange) : MinRange(_minRange), MinTolerance(_minTolerance), MaxRange(_maxRange), MaxTolerance(_maxTolerance) { }
28
29// ---- ChaseAngle ---- //
30
31ChaseAngle::ChaseAngle(float angle, float _tolerance/* = M_PI_4*/) : RelativeAngle(Position::NormalizeOrientation(angle)), Tolerance(_tolerance) { }
32
34{
36}
37
39{
41}
42
43bool ChaseAngle::IsAngleOkay(float relativeAngle) const
44{
45 float const diff = std::abs(relativeAngle - RelativeAngle);
46
47 return (std::min(diff, float(2 * M_PI) - diff) <= Tolerance);
48}
#define M_PI
Definition: Common.h:115
#define CONTACT_DISTANCE
Definition: ObjectDefines.h:23
STL namespace.
ChaseAngle(float angle, float _tolerance=M_PI_4)
float UpperBound() const
float LowerBound() const
float RelativeAngle
bool IsAngleOkay(float relativeAngle) const
ChaseRange(float range)
static float NormalizeOrientation(float o)
Definition: Position.cpp:135