Planeshift
pseffectanchor.h
Go to the documentation of this file.
1 /*
2  * Author: Andrew Robberts
3  *
4  * Copyright (C) 2003 Atomic Blue (info@planeshift.it, http://www.atomicblue.org)
5  *
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation (version 2 of the License)
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
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 
20 #ifndef PS_EFFECT_ANCHOR_HEADER
21 #define PS_EFFECT_ANCHOR_HEADER
22 
23 #include <csutil/csstring.h>
24 #include <csutil/array.h>
25 #include <csutil/bitarray.h>
26 #include <csutil/leakguard.h>
27 #include <csutil/parray.h>
28 #include <csutil/refcount.h>
29 #include <iutil/virtclk.h>
30 #include <imesh/object.h>
31 
32 struct iDocumentNode;
33 struct iEngine;
34 struct iView;
35 struct iMeshFactoryWrapper;
36 struct iSector;
37 struct iSectorList;
38 
47 {
48 public:
50  psEffectAnchorKeyFrame(iDocumentNode* node, const psEffectAnchorKeyFrame* prevKeyFrame);
52 
56  void SetDefaults();
57 
61  void SetupFirstFrame();
62 
64  float time;
65 
67  {
68  IT_NONE = 0,
72 
74  };
75 
77  {
80 
82  };
83  float actions[KA_COUNT];
84 
85  inline const char* GetActionName(size_t idx)
86  {
87  switch(idx)
88  {
89  case KA_POS_X:
90  return "Position X";
91  case KA_POS_Y:
92  return "Position Y";
93  case KA_POS_Z:
94  return "Position Z";
95  case KA_TOTARGET_X:
96  return "To Target X";
97  case KA_TOTARGET_Y:
98  return "To Target Y";
99  case KA_TOTARGET_Z:
100  return "To Target Z";
101  }
102  return "";
103  }
104 
105  inline bool IsActionSet(size_t idx)
106  {
107  return specAction.IsBitSet(idx);
108  }
109 
111  csBitArray specAction;
112 };
113 
114 
119 {
120 private:
121  csPDelArray<psEffectAnchorKeyFrame> keyFrames;
122 
123 public:
126 
132  size_t GetSize() const
133  {
134  return keyFrames.GetSize();
135  }
136 
143  psEffectAnchorKeyFrame* Get(size_t idx) const
144  {
145  return keyFrames[idx];
146  }
147 
154  psEffectAnchorKeyFrame* operator [](size_t idx) const
155  {
156  return keyFrames[idx];
157  }
158 
164  void Push(psEffectAnchorKeyFrame* keyFrame)
165  {
166  keyFrames.Push(keyFrame);
167  }
168 
174  void DeleteIndex(size_t idx)
175  {
176  keyFrames.DeleteIndex(idx);
177  }
178 
182  void DeleteAll()
183  {
184  keyFrames.DeleteAll();
185  }
186 };
187 
192 {
193 public:
194  psEffectAnchor();
195  virtual ~psEffectAnchor();
196 
203  virtual bool Load(iDocumentNode* node);
204 
213  virtual bool Create(const csVector3 &offset, iMeshWrapper* posAttach, bool rotateWithMesh = false);
214 
221  virtual bool Update(csTicks elapsed);
222 
228  void CloneBase(psEffectAnchor* newAnchor) const;
229 
233  virtual psEffectAnchor* Clone() const;
234 
242  virtual void SetPosition(const csVector3 &basePos, iSector* sector, const csMatrix3 &transf);
243 
251  virtual void SetPosition(const csVector3 &basePos, iSectorList* sectors, const csMatrix3 &transf);
252 
259  void SetTarget(const csVector3 &newTarget, const csMatrix3 &transf)
260  {
261  target = newTarget;
262  targetTransf = transf;
263  }
264 
270  const csString &GetName() const
271  {
272  return name;
273  }
274 
280  void SetName(const csString &newName)
281  {
282  name = newName;
283  }
284 
290  iMeshWrapper* GetMesh() const
291  {
292  return mesh;
293  }
294 
300  virtual void SetRotBase(const csMatrix3 &newRotBase)
301  {
302  matBase = newRotBase;
303  }
304 
310  void TransformOffset(csVector3 &offset);
311 
317  size_t GetKeyFrameCount() const
318  {
319  return keyFrames->GetSize();
320  }
321 
329  {
330  return keyFrames->Get(idx);
331  }
332 
338  const char* GetDirectionType() const;
339 
345  void SetDirectionType(const char* newDir);
346 
352  void SetAnimLength(float newAnimLength)
353  {
354  animLength = newAnimLength;
355  }
356 
363  {
364  return animLength;
365  }
366 
373  size_t AddKeyFrame(float time);
374 
380  bool IsReady() const
381  {
382  return isReady;
383  }
384 
385  enum DIR_TYPE
386  {
387  DT_NONE = 0,
390 
391  DT_COUNT
392  };
393 
397  void FillInLerps();
398 
399 protected:
400 
407  size_t FindKeyFrameByTime(float time) const;
408 
417  bool FindNextKeyFrameWithAction(size_t startFrame, size_t action, size_t &index) const;
418 
419  csString name;
420 
421  float life;
422  float animLength;
423 
424  csMatrix3 matBase;
425 
431  csVector3 objEffectPos;
432 
434  csVector3 objBasePos;
435 
437  csVector3 objTargetOffset;
438 
440  csVector3 objOffset;
441  csMatrix3 posTransf;
442 
444  csVector3 target;
445  csMatrix3 targetTransf;
446 
448  csRef<iMeshWrapper> mesh;
449 
451  int dir;
452 
455 
456  size_t currKeyFrame;
457  size_t nextKeyFrame;
458 
460  csRef<psEffectAnchorKeyFrameGroup> keyFrames;
461 
463  csRef<iEngine> engine;
464 
465  bool isReady;
466 
468  inline float lerp(float f1, float f2, float t1, float t2, float t)
469  {
470  if(t2 == t1)
471  return f1;
472 
473  return f1 + (f2-f1)*(t-t1)/(t2-t1);
474  }
475 
477  inline csVector3 lerpVec(const csVector3 &v1, const csVector3 &v2, float t1, float t2, float t)
478  {
479  if(t2 == t1)
480  return v1;
481 
482  return v1 + (v2-v1)*(t-t1)/(t2-t1);
483  }
484 };
485 
488 #endif
float actions[KA_COUNT]
Stores data for a specific effect anchor keyframe.
bool IsActionSet(size_t idx)
csRef< iMeshWrapper > mesh
The mesh that makes up this anchor.
bool rotateWithMesh
Whether the anchor should rotate with the mesh. This is so effects can stay aligned, e.g. flame sword.
csRef< iEngine > engine
Reference to CS&#39;s iEngine.
csVector3 target
Stores the target of the effect.
void SetTarget(const csVector3 &newTarget, const csMatrix3 &transf)
Sets the target of the effect anchor.
Effect anchor KeyFrame group.
void SetName(const csString &newName)
Sets the name of this effect anchor.
csBitArray specAction
keep track of which actions were specified for which
csRef< psEffectAnchorKeyFrameGroup > keyFrames
The next keyframe the anchor will be on.
float GetAnimGetSize()
Gets the animation length of the effect anchor.
size_t GetSize() const
Returns the number of keyframes in the group.
void Push(psEffectAnchorKeyFrame *keyFrame)
Pushes a keyframe onto the group.
float animLength
The amount of time this anchor has been alive (gets reset on loop).
bool IsReady() const
Check to see if this anchor is ready.
csMatrix3 posTransf
csVector3 objTargetOffset
Stores the delta to the effect target.
csMatrix3 targetTransf
void SetupFirstFrame()
Sets up this keyframe for the special case of being the first key frame in the group.
void SetDefaults()
Applies default values to this anchor keyframe.
iMeshWrapper * GetMesh() const
Returns the mesh that&#39;s associated with this effect anchor (almost always a nullmesh).
float life
A unique name identifying this anchor.
csVector3 objOffset
The complete offset, this gets modified by the position action, generally.
int dir
What type of direction does this movable have.
psEffectAnchorKeyFrame * Get(size_t idx) const
Returns the keyframe at the given index.
const csString & GetName() const
Returns the name of this effect anchor.
psEffectAnchorKeyFrame * GetKeyFrame(size_t idx) const
Returns the keyframe at the given index.
csVector3 objBasePos
Base pos for the effect anchor, this is used for things like the variable offset from the anchoring m...
const char * GetActionName(size_t idx)
size_t GetKeyFrameCount() const
Returns the number of keyframes in this anchor.
float lerp(float f1, float f2, float t1, float t2, float t)
Linear interpolation function for a floating point.
void SetAnimLength(float newAnimLength)
Sets the animation length of the effect anchor.
csMatrix3 matBase
The length of each loop of this anchor.
void DeleteAll()
Deletes all of the keyframes in this group.
void DeleteIndex(size_t idx)
Deletes the keyframe at the given index.
float time
this is the time of the keyframe animation (in seconds)
csVector3 objEffectPos
The base transform matrix of this anchor.
virtual void SetRotBase(const csMatrix3 &newRotBase)
Sets the base rotation matrix of the effect anchor.
csVector3 lerpVec(const csVector3 &v1, const csVector3 &v2, float t1, float t2, float t)
Linear interpolation function for a 3D vector.
size_t nextKeyFrame
The current keyframe the anchor is on.
Effect anchors provide a base location / anchor point for all effect objs.