Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
cMapMover.h
Go to the documentation of this file.
1 //
5 
6 #ifndef _INC_CMapMover_H
7 #define _INC_CMapMover_H
8 #ifndef NO_PRAGMA_ONCE
9 #pragma once
10 #endif
11 
12 #include "GrayMapData.h"
15 
16 namespace GrayMapData
17 {
18  class cMapBase;
19 
20 #define MAP_DIST_MIN 0.0001f // smallest delta distance it is important to track. smaller would have lots of rounding error.
21 #define MAP_GRAVITY_ACCEL 9.81f // acceleration of gravity (Earth=9.8m/sec) (m/sec)
22 #define MAP_GRAVITY_TERMINAL 300.0f // terminal velocity. TV of humans is about 55 instead of 40?
23 
25  {
28 
31 
35 #define CMapMoverMode(a,b,c) MAPMOVER_##a,
36 #include "CMapMoverModes.tbl"
37 #undef CMapMoverMode
38 
40  };
41 
43  {
46 
47  public:
48  // m_bFlagCollide = do i collide with others. NOT exactly same as ! m_bFlagInsubstantial. similar but reverse perspective.
49  // WHY is an object in motion blocking different from object at rest ? m_bFlagCollide
50 
51  bool m_bFlagCollide; // Test do i collide with world objects if i move. Not the same as !m_bFlagInsubstantial
52 
53  cVector3f m_vEllipsoidRadius; // x,y,z radius of the ellipsoid used for collision. may change as i move.
54 
55  bool m_bFlagTraction; // Am i connected to the ground? (or my parent, other multi object, ship, building, etc) more than 'air' traction.
56  float m_fTractionRatio; // how efficiently you can apply your force to your current parent/surface to move. 1=perfect, 0=none.
57 
58  float m_fGravity; // how strong will gravity act on this? MAP_GRAVITY_ACCEL
59 
60  public:
62  : m_bFlagCollide(false)
63  , m_vEllipsoidRadius(1.0f, 1.0f, 1.0f)
64  , m_bFlagTraction(false)
65  , m_fTractionRatio(1.0f) // 1 = non movable. 0 = non friction move. NOTE: 'in air' has some traction but very little.
66  , m_fGravity(MAP_GRAVITY_ACCEL)
67  {
68  // NOTE: slow drop = add some m_fTractionRatio2
69  }
70 
71  bool get_CanCollide() const
72  {
73  // When i am in motion do i collide with others ?
74  return m_bFlagCollide; // Can this collide into other things? when i move.
75  }
76  void put_CanCollide(bool bCanCollide)
77  {
78  m_bFlagCollide = bCanCollide;
79  }
80  };
81 
82  class CMapMover : public cRefBase
83  {
88  //
89  friend class cMapEntity;
90  public:
92  private:
93  cVector3f m_vVelocity;
94  public:
95  // Collision system data
97 
98  // a force is acting on this entity. what type ?
100  static const char* k_szModeNames[MAPMOVER_QTY + 1]; // name the mover modes for debug use.
101 
102  // MAPMOVER_TYPE mode specific params:
103  // We MUST use continuous position calculated from hard time! NOT differential changes!
104  float m_fMoveAngleOffset; // offset moving by percentage of the loop cycle
105  float m_fMoveSpeed; // (Meters/sec)
106  cVector3f m_vMoveTarget; // if MAPMOVER_Target or MAPMOVER_Circle center
107  cVector3f m_vMoveTargetStart; // Beginning point of a loop, filled in only if we have an end
108  cVector3f m_vMoveTargetEnd; // in the case of MAPMOVER_Circle, ending point of the center if you want it to move
109  float m_fMoveTargetOffset;// offset the starting progress point of the radius (0.0 to 0.99)
110  cVector3f m_vMoveOrientation; // vector rate of spin ? (radians/sec) i.e. the earth spins on its axis. (particle systems)
111  float m_fMoveLoopTimeCur; // amount of time i have been moving. (sec)
112  float m_fMoveLoopTimeSpan; // length of the stride. (seconds) (depends on current anim, Scale and move speed?)
113 
114  //Note: these are public to allow access through scp files, but should use set functions to maintain correct values
115  float m_fMoveRadius; // try to maintain this distance.
116  float m_fMoveRadiusEnd; // if entered, change to this distance and back over the defined loop time
117  float m_fMoveRadiusOffset; // starting progress offset for progression between radii (0.0 to 0.99)
118  float m_fMoveCircumference; // distance around the current loop
119 
120  public:
121  CMapMover();
122  ~CMapMover();
123 
124  void Mover_PushForce(const cVector3f& vForce);
125  void Mover_TargetArbitrary(const cVector3f& vTarget, float fSpeed);
126  void Mover_CircleArbitrary(const cVector3f& vCenter, float fSpeed, float fRadius);
127 
128  virtual bool FrameMoveMover(bool bRelative, float fElapsedTime); // call before physics
129  virtual bool FrameMovePhysics(bool bRelative, float fTimeDelta); // act on physics.
130 
132 
133  void put_MoverRadius(float fRadius)
134  {
135  m_fMoveRadius = fRadius;
137  }
138  void put_MoverCircumference(float fCirc)
139  {
140  m_fMoveCircumference = fCirc;
142  }
144  {
146  }
147  float get_MoverRadius() const
148  {
149  return m_fMoveRadius;
150  }
152  {
153  return m_fMoveCircumference;
154  }
155 
156  const cVector3f& get_Velocity() const
157  {
158  return m_vVelocity;
159  }
160  float get_VelX() const
161  {
162  return m_vVelocity.get_X();
163  }
164  float get_VelY() const
165  {
166  return m_vVelocity.get_Y();
167  }
168  float get_VelZ() const
169  {
170  return m_vVelocity.get_Z();
171  }
172 
173  void put_Velocity(const cVector3f& vVelocity)
174  {
175 #ifdef _DEBUG
176  if (m_vVelocity == vVelocity)
177  return;
178 #endif
179  m_vVelocity = vVelocity;
180  }
181  void put_VelY(const float fVelY)
182  {
183 #ifdef _DEBUG
184  if (m_vVelocity.y == fVelY)
185  return;
186 #endif
187  m_vVelocity.y = fVelY;
188  }
190  {
191 #ifdef _DEBUG
192  if (m_vVelocity.x == 0 && m_vVelocity.y == 0 && m_vVelocity.z == 0)
193  return;
194 #endif
195  m_vVelocity.SetZero();
196  }
197 
198  };
199 
200  typedef cRefPtr<CMapMover> CMapMoverPtr;
201 };
202 
203 #endif // _INC_CMapMover_H
#define GRAYMAPDATA_LINK
Definition: GrayMapData.h:13
#define MAP_GRAVITY_ACCEL
Definition: cMapMover.h:21
TYPE get_Z() const noexcept
Definition: cVecT.h:577
TYPE y
Definition: cVecT.h:545
TYPE z
Definition: cVecT.h:545
TYPE get_X() const noexcept
Definition: cVecT.h:569
TYPE x
Definition: cVecT.h:545
TYPE get_Y() const noexcept
Definition: cVecT.h:573
void SetZero() noexcept
Definition: cVecT.h:327
Definition: cVector.h:94
Definition: cMapMover.h:43
bool m_bFlagCollide
Definition: cMapMover.h:51
bool m_bFlagTraction
Definition: cMapMover.h:55
bool get_CanCollide() const
Definition: cMapMover.h:71
void put_CanCollide(bool bCanCollide)
Definition: cMapMover.h:76
CMapMovable()
Definition: cMapMover.h:61
cVector3f m_vEllipsoidRadius
Definition: cMapMover.h:53
float m_fGravity
Definition: cMapMover.h:58
float m_fTractionRatio
Definition: cMapMover.h:56
Definition: cMapMover.h:83
float get_MoverCircumference() const
Definition: cMapMover.h:151
float m_fMoveRadiusEnd
Definition: cMapMover.h:116
float m_fMoveAngleOffset
Definition: cMapMover.h:104
void UpdateMoverParams(cMapEntity *pEntity)
void Velocity_Clear()
Definition: cMapMover.h:189
void Mover_CircleArbitrary(const cVector3f &vCenter, float fSpeed, float fRadius)
cVector3f m_vMoveTargetEnd
Definition: cMapMover.h:108
void put_MoverCircumference(float fCirc)
Definition: cMapMover.h:138
float get_MoverRadius() const
Definition: cMapMover.h:147
float m_fMoveLoopTimeCur
Definition: cMapMover.h:111
const cVector3f & get_Velocity() const
Definition: cMapMover.h:156
~CMapMover()
Definition: CMapMover.cpp:44
float m_fMoveTargetOffset
Definition: cMapMover.h:109
TIMESYS_t m_tGravitySkip
skip gravity/traction recalc until this time. (mSec) i.e. i can fly for a bit.
Definition: cMapMover.h:96
float m_fMoveRadiusOffset
Definition: cMapMover.h:117
float get_VelZ() const
Definition: cMapMover.h:168
void Mover_TargetArbitrary(const cVector3f &vTarget, float fSpeed)
cVector3f m_vMoveOrientation
Definition: cMapMover.h:110
void put_Velocity(const cVector3f &vVelocity)
Definition: cMapMover.h:173
float get_VelX() const
Definition: cMapMover.h:160
void put_MoverRadius(float fRadius)
Definition: cMapMover.h:133
cVector3f m_vMoveTargetStart
Definition: cMapMover.h:107
virtual bool FrameMoveMover(bool bRelative, float fElapsedTime)
void Mover_PushForce(const cVector3f &vForce)
cVector3f m_vMoveTarget
Definition: cMapMover.h:106
float m_fMoveCircumference
Definition: cMapMover.h:118
CMapMover()
Definition: CMapMover.cpp:22
float m_fMoveSpeed
Definition: cMapMover.h:105
void check_Circumference()
Definition: cMapMover.h:143
static const char * k_szModeNames[MAPMOVER_QTY+1]
Definition: cMapMover.h:100
float get_VelY() const
Definition: cMapMover.h:164
float m_fMoveRadius
Definition: cMapMover.h:115
virtual bool FrameMovePhysics(bool bRelative, float fTimeDelta)
cVector3f m_vPositionPrev
world coords (or relative coords) of position in last frame.
Definition: cMapMover.h:91
void put_VelY(const float fVelY)
Definition: cMapMover.h:181
float m_fMoveLoopTimeSpan
Definition: cMapMover.h:112
MAPMOVER_TYPE m_eMoveMode
Definition: cMapMover.h:99
Definition: cMapEntity.h:76
Definition: cRefPtr.h:22
Definition: GrayMapData.cpp:12
MAPMOVER_TYPE
Definition: cMapMover.h:25
@ MAPMOVER_PlayerTurn
player controlled turn.
Definition: cMapMover.h:30
@ MAPMOVER_QTY
Definition: cMapMover.h:39
@ MAPMOVER_PlayerMove
player controlled move
Definition: cMapMover.h:29
cRefPtr< CMapMover > CMapMoverPtr
Definition: cMapEntity.h:30
UINT32 TIMESYS_t
TIMESYS_t = The normal system tick timer. milli-seconds since start of system/app ?
Definition: cTimeSys.h:27
Definition: Calc.h:37