TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
MoveSpline.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2011 MaNGOS <http://getmangos.com/>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */
18 
19 #ifndef TRINITYSERVER_MOVEPLINE_H
20 #define TRINITYSERVER_MOVEPLINE_H
21 
22 #include "Spline.h"
23 #include "MoveSplineInitArgs.h"
24 
25 namespace WorldPackets
26 {
27  namespace Movement
28  {
29  class CommonMovement;
30  class MonsterMove;
31  }
32 }
33 
34 namespace Movement
35 {
36  struct Location : public Vector3
37  {
38  Location() : orientation(0) { }
39  Location(float x, float y, float z, float o) : Vector3(x, y, z), orientation(o) { }
40  Location(const Vector3& v) : Vector3(v), orientation(0) { }
41  Location(const Vector3& v, float o) : Vector3(v), orientation(o) { }
42 
43  float orientation;
44  };
45 
46  // MoveSpline represents smooth catmullrom or linear curve and point that moves belong it
47  // curve can be cyclic - in this case movement will be cyclic
48  // point can have vertical acceleration motion component (used in fall, parabolic movement)
50  {
53 
54  public:
56 
58  {
59  Result_None = 0x01,
60  Result_Arrived = 0x02,
61  Result_NextCycle = 0x04,
62  Result_NextSegment = 0x08
63  };
64 
65  protected:
66  MySpline spline;
67 
69 
71 
73 
75  // currently duration mods are unused, but its _currently_
76  //float duration_mod;
77  //float duration_mod_next;
83 
84  void init_spline(const MoveSplineInitArgs& args);
85 
86  protected:
87  MySpline::ControlArray const& getPath() const { return spline.getPoints(); }
88  void computeParabolicElevation(float& el) const;
89  void computeFallElevation(float& el) const;
90 
91  UpdateResult _updateState(int32& ms_time_diff);
92  int32 next_timestamp() const { return spline.length(point_Idx + 1); }
93  int32 segment_time_elapsed() const { return next_timestamp() - time_passed; }
94  int32 timeElapsed() const { return Duration() - time_passed; }
95  int32 timePassed() const { return time_passed; }
96 
97  public:
98  int32 Duration() const { return spline.length(); }
99  MySpline const& _Spline() const { return spline; }
100  int32 _currentSplineIdx() const { return point_Idx; }
101  void _Finalize();
102  void _Interrupt() { splineflags.done = true; }
103 
104  public:
105  void Initialize(const MoveSplineInitArgs&);
106  bool Initialized() const { return !spline.empty(); }
107 
108  MoveSpline();
109 
110  template<class UpdateHandler>
111  void updateState(int32 difftime, UpdateHandler& handler)
112  {
113  ASSERT(Initialized());
114  do
115  handler(_updateState(difftime));
116  while (difftime > 0);
117  }
118 
119  void updateState(int32 difftime)
120  {
121  ASSERT(Initialized());
122  do _updateState(difftime);
123  while (difftime > 0);
124  }
125 
126  Location ComputePosition() const;
127 
128  uint32 GetId() const { return m_Id; }
129  bool Finalized() const { return splineflags.done; }
130  bool isCyclic() const { return splineflags.cyclic; }
131  bool isFalling() const { return splineflags.falling; }
132  Vector3 const& FinalDestination() const { return Initialized() ? spline.getPoint(spline.last()) : Vector3::zero(); }
133  Vector3 const& CurrentDestination() const { return Initialized() ? spline.getPoint(point_Idx + 1) : Vector3::zero(); }
134  int32 currentPathIdx() const;
135 
137  std::string ToString() const;
138  };
139 }
140 #endif // TRINITYSERVER_MOVEPLINE_H
Definition: MoveSpline.h:49
Location(const Vector3 &v)
Definition: MoveSpline.h:40
Location()
Definition: MoveSpline.h:38
Vector3 const & CurrentDestination() const
Definition: MoveSpline.h:133
bool isFalling() const
Definition: MoveSpline.h:131
float x
Definition: Vector3.h:62
Location(const Vector3 &v, float o)
Definition: MoveSpline.h:41
bool cyclic
Definition: MoveSplineFlag.h:121
Definition: MovementPackets.h:101
int32 time_passed
Definition: MoveSpline.h:74
int32 segment_time_elapsed() const
Definition: MoveSpline.h:93
bool done
Definition: MoveSplineFlag.h:114
Definition: MoveSpline.h:36
uint32 m_Id
Definition: MoveSpline.h:70
bool falling
Definition: MoveSplineFlag.h:115
MoveSplineFlag splineflags
Definition: MoveSpline.h:72
int32 point_Idx
Definition: MoveSpline.h:81
bool Initialized() const
Definition: MoveSpline.h:106
float y
Definition: Vector3.h:62
Spline< int32 > MySpline
Definition: MoveSpline.h:55
std::vector< Vector3 > ControlArray
Definition: Spline.h:32
Definition: Vector3.h:58
Definition: MoveSplineInitArgs.h:32
bool onTransport
Definition: MoveSpline.h:136
void _Interrupt()
Definition: MoveSpline.h:102
static const Vector3 & zero()
Definition: Vector3.cpp:119
string ToString(int i)
Definition: strutil.h:491
Definition: DBUpdater.h:44
Definition: Unit.h:409
length_type length() const
Definition: Spline.h:199
int32 timeElapsed() const
Definition: MoveSpline.h:94
float initialOrientation
Definition: MoveSpline.h:79
float orientation
Definition: MoveSpline.h:43
int32_t int32
Definition: Define.h:146
bool Finalized() const
Definition: MoveSpline.h:129
uint32_t uint32
Definition: Define.h:150
static void Initialize(PCASC_SALSA20 pState, LPBYTE pbKey, DWORD cbKeyLength, LPBYTE pbVector)
Definition: CascDecrypt.cpp:81
float vertical_acceleration
Definition: MoveSpline.h:78
void updateState(int32 difftime, UpdateHandler &handler)
Definition: MoveSpline.h:111
Definition: MoveSplineFlag.h:28
Definition: BattlegroundMgr.h:57
int32 Duration() const
Definition: MoveSpline.h:98
Vector3 const & FinalDestination() const
Definition: MoveSpline.h:132
MySpline const & _Spline() const
Definition: MoveSpline.h:99
float z
Definition: Vector3.h:62
int32 _currentSplineIdx() const
Definition: MoveSpline.h:100
void updateState(int32 difftime)
Definition: MoveSpline.h:119
int32 effect_start_time
Definition: MoveSpline.h:80
uint32 GetId() const
Definition: MoveSpline.h:128
#define TC_GAME_API
Definition: Define.h:134
#define ASSERT
Definition: Errors.h:55
MySpline::ControlArray const & getPath() const
Definition: MoveSpline.h:87
FacingInfo facing
Definition: MoveSpline.h:68
int32 next_timestamp() const
Definition: MoveSpline.h:92
int32 timePassed() const
Definition: MoveSpline.h:95
int32 point_Idx_offset
Definition: MoveSpline.h:82
float computeFallElevation(float t_passed, bool isSafeFall, float start_velocity=0.0f)
Definition: MovementUtil.cpp:59
MySpline spline
Definition: MoveSpline.h:66
bool isCyclic() const
Definition: MoveSpline.h:130
Location(float x, float y, float z, float o)
Definition: MoveSpline.h:39
Definition: MovementPackets.h:107
Definition: MoveSplineInitArgs.h:41