Planeshift
linmove.h
Go to the documentation of this file.
1 /*
2  Crystal Space Entity Layer
3  Copyright (C) 2001 PlaneShift Team (info@planeshift.it,
4  Copyright (C) 2001-2003 by Jorrit Tyberghein
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Library General Public
8  License as published by the Free Software Foundation; either
9  version 2 of the License, or (at your option) any later version.
10 
11  This library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Library General Public License for more details.
15 
16  You should have received a copy of the GNU Library General Public
17  License along with this library; if not, write to the Free
18  Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 */
20 
21 /*
22  * This code is heavily based on pslinmove from the PlaneShift project.
23  * Thanks a lot for making this!
24  */
25 
26 #ifndef __CEL_PF_LINEAR_MOVE_FACT__
27 #define __CEL_PF_LINEAR_MOVE_FACT__
28 
29 //CS Includes
30 #include "cstypes.h"
31 #include "iutil/comp.h"
32 #include "iutil/eventh.h"
33 #include "csutil/scf.h"
34 #include "csutil/stringarray.h"
35 #include "cstool/collider.h"
36 #include "ivaria/collider.h"
37 #include "csutil/sysfunc.h"
38 #include "colldet.h"
39 
40 #define PS_LINMOVE_FOLLOW_ONLY_PORTALS true
41 
42 #define PS_MOVE_FAIL 0
43 #define PS_MOVE_SUCCEED 1
44 #define PS_MOVE_PARTIAL 2
45 #define PS_MOVE_DONTMOVE 3
46 
47 struct iObjectRegistry;
48 struct iVirtualClock;
49 struct iCollider;
50 struct iCollideSystem;
51 struct iSector;
52 class csReversibleTransform;
53 class csObject;
54 class csColliderWrapper;
55 struct iPath;
57 
58 /* Max deviation before we need to send
59  a new DR packet */
60 #define PSLINEARMOVEMENT_DRDELTA 0.2
61 
62 
69 {
70 public:
71  psLinearMovement(iObjectRegistry* object_reg);
72  virtual ~psLinearMovement();
73 
74  virtual void SetAngularVelocity(const csVector3 &angle);
75  virtual void SetAngularVelocity(const csVector3 &angle, const csVector3 &angle_to_reach);
76 
78  virtual void SetVelocity(const csVector3 &vel);
79 
81  virtual void AddVelocity(const csVector3 &vel);
82 
84  virtual void ClearWorldVelocity();
85 
86  virtual void GetVelocity(csVector3 &v) const;
87 
88  virtual const csVector3 GetVelocity() const;
89 
90 
91  virtual bool RotateV(float delta);
92 
96  virtual const csVector3 GetAngularVelocity() const;
97  virtual void GetAngularVelocity(csVector3 &v) const;
98 
99  virtual bool InitCD(const csVector3 &body, const csVector3 &legs, const csVector3 &shift, iMeshWrapper* mesh);
100  virtual void GetCDDimensions(csVector3 &body, csVector3 &legs, csVector3 &shift);
101 
102  virtual float GetYRotation() const;
103  virtual void SetYRotation(float yrot);
104  const csVector3 GetPosition() const;
105  const csVector3 GetFullPosition() const;
106 
107  void SetScale(float set_scale)
108  {
109  scale = set_scale;
110  }
111 
112  virtual void GetLastPosition(csVector3 &pos, float &yrot, iSector* &sector) const;
113  virtual void GetLastFullPosition(csVector3 &pos, float &yrot, iSector* &sector);
114  virtual void SetPosition(const csVector3 &pos, float yrot, const iSector* sector);
115  virtual void SetFullPosition(const csVector3 &pos, float yrot, const iSector* sector);
116  virtual void SetPosition(const char* center_name, float yrot, iSector* sector);
117  virtual void SetFullPosition(const char* center_name, float yrot, iSector* sector);
118  virtual void GetLastClientPosition(csVector3 &pos, float &yrot, iSector* &sector);
119 
120  virtual bool IsOnGround() const;
121 
122  virtual void SetOnGround(bool onground);
123 
124 
126  virtual void SetHugGround(bool hugGround);
127 
128  virtual void SetGravity(float grav);
129 
130  virtual float GetGravity();
131 
132  virtual void ResetGravity();
133 
134  virtual bool IsPath() const;
135 
136 
141  virtual csTicks TimeDiff(void);
142 
143  virtual csTicks ClientTimeDiff()
144  {
145  return csGetTicks() - lastClientDRUpdate;
146  }
147 
149  virtual void GetDRData(bool &on_ground, csVector3 &pos,
150  float &yrot, iSector* &sector, csVector3 &vel, csVector3 &worldVel,
151  float &ang_vel);
152 
154  virtual void SetDRData(bool on_ground, csVector3 &pos,
155  float yrot, iSector* sector, csVector3 &vel, csVector3 &worldVel,
156  float ang_vel);
157 
166  virtual void SetSoftDRData(bool on_ground, csVector3 &pos,
167  float yrot, iSector* sector, csVector3 &vel, csVector3 &worldVel,
168  float ang_vel);
169 
170  virtual void TickEveryFrame();
171 
172  virtual iSector* GetSector() const;
173 
178  virtual int ExtrapolatePosition(float delta);
179 
186  virtual void UpdateDRDelta(csTicks ticksdelta);
194  virtual void UpdateDR(csTicks delta);
195  virtual void UpdateDR();
196 
202  virtual void SetPath(iPath* newpath);
203 
208  virtual void SetPathTime(float timeval);
209 
217  virtual void SetPathSpeed(float speed);
218 
227  virtual void SetPathAction(int which, const char* action);
228 
233  virtual void SetPathSector(const char* sectorname);
234 
235  virtual void SetDeltaLimit(float deltaLimit);
236 
238  virtual csVector3 GetPortalDisplacement();
239 
241  virtual void ClearPortalDisplacement();
242 
243 
244  void UseCD(bool cd);
245 
248  void StackTrace(const char* error);
249 
250 protected:
251 
252  // Move local entity
253  // both MoveV and MoveSprite return CEL_MOVE_* constants defined above
254  int MoveV(float delta);
255  int MoveSprite(float delta);
256  void OffsetSprite(float delta);
257 
262  void HugGround(const csVector3 &pos, iSector* sector);
263 
264 
265  // Returns a list of sectors near a position.
266  int FindSectors(const csVector3 &pos, float size, iSector** sectors);
267 
268 
269  static csCollisionPair our_cd_contact[1000];
270  static int num_our_cd;
271 
272  iObjectRegistry* object_reg;
273 
274  csRef<iMeshWrapper> mesh;
276 
277  csRef<iEngine> engine;
278  csRef<iVirtualClock> vc;
279  csRef<iCollideSystem> cdsys;
280 
281  // Linear vars
282  float angDelta;
286  float gravity;
287 
288  csVector3 angularVelocity;
289  csVector3 angleToReach;
291  csVector3 velBody;
292 
293  csVector3 velWorld;
294 
296  bool hugGround;
297 
298  float xRot;
299  float zRot;
300 
301  float scale;
302 
303  // Path vars
304  csRef<iPath> path;
306  csStringArray path_actions;
307  bool path_sent;
308  csString path_sector;
309 
310  //Collision vars
311  csVector3 shift;
312  csVector3 topSize;
313 
314  csVector3 bottomSize;
315 
316  csBox3 boundingBox;
317 
319  csVector3 portalDisplaced;
320 
322  csVector3 intervalSize;
323 
324  csTicks lastDRUpdate;
329  float deltaLimit;
330 
331  // Variables for 'Soft Update' of position
332  csVector3 offset_err;
333  csVector3 offset_rate;
334 };
335 
336 #endif
virtual void SetPathTime(float timeval)
This function sets the current position on the path for use when time deltas are added later...
csVector3 portalDisplaced
The total change in displacement caused by space warping portals.
Definition: linmove.h:319
virtual void GetLastClientPosition(csVector3 &pos, float &yrot, iSector *&sector)
csVector3 offset_rate
Speed to bring error to ZERO within 1s.
Definition: linmove.h:333
csVector3 angularVelocity
Definition: linmove.h:288
csVector3 offset_err
Error in terms of absolute position.
Definition: linmove.h:332
virtual void GetLastPosition(csVector3 &pos, float &yrot, iSector *&sector) const
virtual void SetAngularVelocity(const csVector3 &angle)
void UseCD(bool cd)
void StackTrace(const char *error)
Procedure used to dump stack in error situations.
bool angleToReachFlag
Definition: linmove.h:290
iSector * lastClientSector
Definition: linmove.h:328
virtual void SetDeltaLimit(float deltaLimit)
csVector3 bottomSize
Definition: linmove.h:314
virtual bool IsOnGround() const
float angDelta
Definition: linmove.h:282
int MoveSprite(float delta)
virtual void SetPosition(const csVector3 &pos, float yrot, const iSector *sector)
csVector3 velWorld
Definition: linmove.h:293
virtual iSector * GetSector() const
virtual void GetDRData(bool &on_ground, csVector3 &pos, float &yrot, iSector *&sector, csVector3 &vel, csVector3 &worldVel, float &ang_vel)
Return all necessary data for Dead Reckoning.
csTicks lastDRUpdate
Definition: linmove.h:324
csVector3 intervalSize
Maximum interval at which to perform CD.
Definition: linmove.h:322
virtual void UpdateDRDelta(csTicks ticksdelta)
This function calls ExtrapolatePosition with a certain time but uses a fixed delta.
bool hugGround
Should the model be tilted so it&#39;s aligned with the ground.
Definition: linmove.h:296
Movement related class.
Definition: linmove.h:68
virtual void SetDRData(bool on_ground, csVector3 &pos, float yrot, iSector *sector, csVector3 &vel, csVector3 &worldVel, float ang_vel)
Sets all relevant dead reckoning data on this entity.
float gravity
Speed affects all aspects of movement, including gravity.
Definition: linmove.h:286
virtual void SetYRotation(float yrot)
virtual void TickEveryFrame()
csRef< iCollideSystem > cdsys
Definition: linmove.h:279
psLinearMovement(iObjectRegistry *object_reg)
csRef< iPath > path
Definition: linmove.h:304
virtual csTicks TimeDiff(void)
Returns the difference in time between now and when the last DR update or extrapolation took place...
csRef< iVirtualClock > vc
Definition: linmove.h:278
virtual void AddVelocity(const csVector3 &vel)
Adds on a velocity to this body in world coordinates.
csVector3 shift
Definition: linmove.h:311
Collision Detection (CD) related class.
Definition: colldet.h:56
float path_time
Definition: linmove.h:305
virtual void SetGravity(float grav)
int MoveV(float delta)
virtual void SetFullPosition(const csVector3 &pos, float yrot, const iSector *sector)
csBox3 boundingBox
Definition: linmove.h:316
csTicks lastClientDRUpdate
Definition: linmove.h:325
psCollisionDetection * colldet
Definition: linmove.h:275
const csVector3 GetPosition() const
virtual csTicks ClientTimeDiff()
Definition: linmove.h:143
const csVector3 GetFullPosition() const
virtual ~psLinearMovement()
virtual void SetOnGround(bool onground)
float path_speed
Definition: linmove.h:305
csRef< iMeshWrapper > mesh
Definition: linmove.h:274
virtual int ExtrapolatePosition(float delta)
This function actually moves and rotates the mesh, relighting if necessary.
csVector3 angleToReach
Definition: linmove.h:289
virtual void SetPathSector(const char *sectorname)
This sets the sector which will be used for the entire path.
virtual void SetPathSpeed(float speed)
This relates the movement of the entity along the path to the time values specified by the path...
virtual float GetYRotation() const
void OffsetSprite(float delta)
csVector3 velBody
Definition: linmove.h:291
float lastClientYrot
Definition: linmove.h:327
static int num_our_cd
Definition: linmove.h:270
virtual void SetVelocity(const csVector3 &vel)
Sets a velocity for this body in body coordinates.
int FindSectors(const csVector3 &pos, float size, iSector **sectors)
void HugGround(const csVector3 &pos, iSector *sector)
Transform pcmesh so that it follows the curvature of the ground at pos (sector)
iObjectRegistry * object_reg
Definition: linmove.h:272
virtual float GetGravity()
virtual void UpdateDR()
csString path_sector
Definition: linmove.h:308
float deltaLimit
Definition: linmove.h:329
virtual csVector3 GetPortalDisplacement()
Get the total displacement caused by space warping portals.
virtual void ResetGravity()
virtual void ClearPortalDisplacement()
Clear the total displacement caused by space warping portals.
csStringArray path_actions
Definition: linmove.h:306
virtual void SetHugGround(bool hugGround)
Set if pcmesh should be transformed to follow the contour of the ground.
virtual void SetPath(iPath *newpath)
This function lets linmove store a ref to the supplied iPath.
csVector3 lastClientPosition
Definition: linmove.h:326
virtual bool InitCD(const csVector3 &body, const csVector3 &legs, const csVector3 &shift, iMeshWrapper *mesh)
virtual const csVector3 GetVelocity() const
virtual bool RotateV(float delta)
csRef< iEngine > engine
Definition: linmove.h:277
virtual void GetCDDimensions(csVector3 &body, csVector3 &legs, csVector3 &shift)
virtual const csVector3 GetAngularVelocity() const
Get the current angular velocity vector.
virtual bool IsPath() const
virtual void ClearWorldVelocity()
Resets the velocity of this body in world coordinates.
virtual void SetSoftDRData(bool on_ground, csVector3 &pos, float yrot, iSector *sector, csVector3 &vel, csVector3 &worldVel, float ang_vel)
Sets dead reckoning data with &#39;soft&#39; position updating.
virtual void GetLastFullPosition(csVector3 &pos, float &yrot, iSector *&sector)
virtual void SetPathAction(int which, const char *action)
This relates a particular action name to be used between two points in the path.
void SetScale(float set_scale)
Definition: linmove.h:107
static csCollisionPair our_cd_contact[1000]
Definition: linmove.h:269
csVector3 topSize
Definition: linmove.h:312