Tactics: Western Philosophers Vs. Musicians  0.12
A turn-based tactical game combining rules and gameplay elements inspired by Final Fantasy Tactics and the Mayfair Exponential Game System. Unlike most games of this type, motion is in full, grid-less 3D.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
IMotionUpdater.h
Go to the documentation of this file.
1 // Copyright (C) 2004-2013 Dylan Blair
3 //
4 // email: dblair@alumni.cs.utexas.edu
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 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 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 
21 #ifndef IMOTION_UPDATER_H
22 #define IMOTION_UPDATER_H
23 
24 #include "CUpdater.h"
25 #include "CPhysicalObject.h"
26 
27 #include <set>
28 
29 namespace OpenSkyNet {
30  namespace Core {
33  class CORE_DLL MotionUpdater : public Updater {
34  public:
35  inline static void setForward(Math::Matrix3x3& rot_, Math::Point<>& forward_) {
36  assert(forward_.getLenSqrd() > Math::CLOSE_TO_ZERO);
37  forward_.normalize();
38  Math::Point<> cross(rot_.col(1).getCross3(forward_));
39  //right = up cross forward iff up and forward are not
40  //parallel or antiparallel.
41  if (cross.getLenSqrd() > Math::CLOSE_TO_ZERO)
42  rot_.col(0) = cross;
43  //up = forward cross right.
44  rot_.col(1) = forward_.getCross3(rot_.col(0));
45  rot_.col(2) = forward_;
46  }
47 
48  enum ATTACH_POINT {
51  NUM_ATTACH_POINTS
52  };
53 
54  struct Anchor {
56 
57  bool _updatePos, _updateRot;
60 
63 
64  Anchor() : _obj(0), _updatePos(true), _updateRot(true), _useAttachPoint(false), _attachPoint(BASE) {}
65 
66  Anchor(Object* obj_, bool updatePos_=true, bool updateRot_=true,
67  ATTACH_POINT attachPoint_=BASE, const Math::Matrix3x3& localRot_=Math::g_identityMatrix3x3) : _obj(obj_),
68  _updatePos(updatePos_), _updateRot(updateRot_), _localRot(localRot_), _useAttachPoint(true), _attachPoint(attachPoint_) {}
69 
70  Anchor(Object* obj_, bool updatePos_, bool updateRot_, const Math::Point<>& localPos_, const Math::Matrix3x3& localRot_) : _obj(obj_),
71  _updatePos(updatePos_), _updateRot(updateRot_), _localPos(localPos_), _localRot(localRot_), _useAttachPoint(false), _attachPoint(BASE) {}
72 
73  bool operator==(const Anchor& rhs_) const { return (_obj == rhs_._obj); }
74  bool operator<(const Anchor& rhs_) const { return (_obj < rhs_._obj); }
75  };
76 
78  struct MotionInfo : public Updater::UpdateInfo {
79  Math::Point<> _attachPoints[NUM_ATTACH_POINTS];
80  std::set<Anchor> _anchors;
81 
82  MotionInfo(Updater::OBJECT_PRIORITY prio_=Updater::OBJ_DISABLED, bool isOneShot_=false) : Updater::UpdateInfo(prio_,isOneShot_) {}
83  };
84 
85  protected:
86  std::map<Object*, MotionInfo*> _nonCollidingInfoMap;
87 
88  virtual bool addObject(Object* obj_, Updater::OBJECT_PRIORITY prio_, bool isOneShot_) = 0;
89  virtual bool removeObject(Object* obj_);
90  virtual void removeAllObjects();
91 
92  virtual void updateAnchors(Object* obj_);
93  public:
94  MotionUpdater(Updater::UPDATER_TYPE type_, const char* typeName_, Updater::UPDATER_PRIORITY prio_, float interval_) : Updater(type_, typeName_, prio_, interval_) {}
95 
100  virtual void addAnchor(Object* base_, Object* anchor_, bool updatePos_, bool updateRot_, const Math::Point<>& localPos_, const Math::Matrix3x3& localRot_);
101  virtual void addAnchor(Object* base_, Object* anchor_, bool updatePos_, bool updateRot_);
102 
103  virtual void removeAnchor(Object* base_, Object* anchor_);
104  virtual void removeAllAnchors(Object* base_);
105  };
106  }
107 }
108 
109 #endif //IMOTION_UPDATER_H
bool _useAttachPoint
Definition: IMotionUpdater.h:61
Anchor(Object *obj_, bool updatePos_=true, bool updateRot_=true, ATTACH_POINT attachPoint_=BASE, const Math::Matrix3x3 &localRot_=Math::g_identityMatrix3x3)
Definition: IMotionUpdater.h:66
Math::Matrix3x3 _localRot
Definition: IMotionUpdater.h:59
Definition: IMotionUpdater.h:50
Definition: IMotionUpdater.h:54
MotionInfo(Updater::OBJECT_PRIORITY prio_=Updater::OBJ_DISABLED, bool isOneShot_=false)
Definition: IMotionUpdater.h:82
void normalize()
Definition: MPoint.h:139
MotionUpdater(Updater::UPDATER_TYPE type_, const char *typeName_, Updater::UPDATER_PRIORITY prio_, float interval_)
Definition: IMotionUpdater.h:94
Anchor(Object *obj_, bool updatePos_, bool updateRot_, const Math::Point<> &localPos_, const Math::Matrix3x3 &localRot_)
Definition: IMotionUpdater.h:70
Definition: IMotionUpdater.h:78
UPDATER_PRIORITY
Definition: CUpdater.h:46
bool operator<(const Anchor &rhs_) const
Definition: IMotionUpdater.h:74
T getLenSqrd() const
Definition: MPoint.h:128
const Matrix3x3 g_identityMatrix3x3
Definition: MMatrix3x3.cpp:5
bool _updateRot
Definition: IMotionUpdater.h:57
std::map< Object *, MotionInfo * > _nonCollidingInfoMap
Definition: IMotionUpdater.h:86
UPDATER_TYPE
Definition: CUpdater.h:43
Definition: CUpdater.h:40
static void setForward(Math::Matrix3x3 &rot_, Math::Point<> &forward_)
Definition: IMotionUpdater.h:35
Definition: IMotionUpdater.h:49
ATTACH_POINT _attachPoint
Definition: IMotionUpdater.h:62
OBJECT_PRIORITY
Definition: CUpdater.h:49
#define CORE_DLL
Definition: CCoreDLL.h:57
Definition: MPoint.h:33
Definition: IObject.h:36
Definition: IMotionUpdater.h:33
ATTACH_POINT
Definition: IMotionUpdater.h:48
Definition: MMatrix3x3.h:32
Point< T > getCross3(const Point< T > &rhs_) const
Definition: MPoint.h:197
Object * _obj
Definition: IMotionUpdater.h:55
const float CLOSE_TO_ZERO(0.00001f)
float float rot_[3]
Definition: ViewerApp.h:31
Math::Point _localPos
Definition: IMotionUpdater.h:58
Math::Point & col(int i_)
Definition: MMatrix3x3.h:49
Anchor()
Definition: IMotionUpdater.h:64
std::set< Anchor > _anchors
Definition: IMotionUpdater.h:80
bool operator==(const Anchor &rhs_) const
Definition: IMotionUpdater.h:73
Definition: CUpdater.h:54