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
CDVolume.h
Go to the documentation of this file.
1 // Copyright (C) 2004-2012 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 CDVOLUME_H
22 #define CDVOLUME_H
23 
24 #include "../Math_LIB/MMatrix3x3.h"
25 
26 namespace OpenSkyNet {
29  namespace CD {
31  enum SHAPE_TYPE { SPHERE, BOX, PLANE };
32 
33  class Volume;
34 
36  struct HitInfo {
39 
40  float _hitSecs;
41 
43 
47 
48  HitInfo(Volume* collider_=0) : _collider(collider_), _hitSecs(Math::PSEUDO_INFINITY) {}
49  };
50 
54  struct Shape {
56 
57  Shape(const float& boundingRadius_=0.0f) : _boundingRadius(boundingRadius_) {}
58 
59  virtual ~Shape() {}
60 
61  virtual SHAPE_TYPE getType() const = 0;
62 
63  virtual float getDist(const Math::Point<>& thisCenter_, const Math::Matrix3x3& thisRot_, const Shape* otherShape_,
64  const Math::Point<>& otherCenter_, const Math::Matrix3x3& otherRot_) const;
65 
66  virtual bool getFirstIntersection(const Math::Point<>& thisCenter_, const Math::Matrix3x3& thisRot_, const Math::Point<>& thisVel_, const Shape* otherShape_,
67  const Math::Point<>& otherCenter_, const Math::Matrix3x3& otherRot_, const Math::Point<>& otherVel_, HitInfo& hitInfo_) const;
68 
73  virtual bool getClosestRayIntersection(const Math::Point<>& thisCenter_, const Math::Matrix3x3& thisRot_,
74  const Math::Point<>& rayOrigin_, const Math::Point<>& rayDir_,
75  Math::Point<>& hitPos_, float& t_, Math::Point<>& hitNormal_) const;
76 
77  virtual void scale(const Math::Point<>& factor_) { UNUSED(factor_); }
78  };
79 
80  struct Sphere : public Shape {
81  Sphere(const float& boundingRadius_) : Shape(boundingRadius_) {}
82 
83  virtual SHAPE_TYPE getType() const { return SPHERE; }
84  };
85 
86  struct Box : public Shape {
88 
89  Box(const float& boundingRadius_, const float& width_, const float& height_, const float& depth_) : Shape(boundingRadius_),
90  _widthDiv2(width_), _heightDiv2(height_), _depthDiv2(depth_) { _widthDiv2 /= 2; _heightDiv2 /= 2; _depthDiv2 /= 2; }
91 
92  virtual SHAPE_TYPE getType() const { return BOX; }
93 
95 
97  virtual float getDist(const Math::Point<>& thisCenter_, const Math::Matrix3x3& thisRot_, const Shape* otherShape_,
98  const Math::Point<>& otherCenter_, const Math::Matrix3x3& otherRot_) const;
99 
100  virtual bool getFirstIntersection(const Math::Point<>& thisCenter_, const Math::Matrix3x3& thisRot_, const Math::Point<>& thisVel_, const Shape* otherShape_,
101  const Math::Point<>& otherCenter_, const Math::Matrix3x3& otherRot_, const Math::Point<>& otherVel_, HitInfo& hitInfo_) const;
102 
103  virtual void scale(const Math::Point<>& factor_);
104  };
105 
106  struct Plane : public Shape {
108 
110 
111  Plane(const Math::Point<>& n_) : _n(n_) {}
112 
113  virtual SHAPE_TYPE getType() const { return PLANE; }
114 
118  virtual float getDist(const Math::Point<>& thisCenter_, const Math::Matrix3x3& thisRot_, const Shape* otherShape_,
119  const Math::Point<>& otherCenter_, const Math::Matrix3x3& otherRot_) const;
120 
121  inline float getDist(const Math::Point<>& thisP_, const Math::Point<>& otherP_) const {
122  Math::Point<> v(otherP_ - thisP_);
123  return _n.getDot3(v);
124  }
125 
133  return NONE;
134  }
135  };
136 
138  #define COL_GROUP_HIT_ALL_HIT_BY_ALL 0xFFFFFFFF
139  #define COL_GROUP_HIT_ALL_HIT_BY_NONE 0xFFFF0000
140  #define COL_GROUP_HIT_NONE_HIT_BY_ALL 0x0000FFFF
141  #define COL_GROUP_HIT_NONE_HIT_BY_NONE 0x00000000
142  #define COL_GROUP_HIT_NONE_HIT_BY_1 0x00000001
143  #define COL_GROUP_HIT_ALL_BUT_1_HIT_BY_NONE 0xFFFE0000
144  #define COL_GROUP_HITTABLE_MASK 0x0000FFFF
145 
146  class Collidable {
147  Math::Point<> _center, _nonCollidingCenter;
148  Math::Matrix3x3 _rot, _nonCollidingRot;
149  void* _userPointer;
150  Utils::uint _colGroup;
151  public:
153  void* userPointer_=0, Utils::uint colGroup_=COL_GROUP_HIT_ALL_HIT_BY_ALL) : _center(center_),
154  _nonCollidingCenter(center_), _rot(rot_), _userPointer(userPointer_), _colGroup(colGroup_) {}
155 
156  virtual ~Collidable() {}
157 
158  inline void translate(const Math::Point<>& delta_) { _center += delta_; }
159 
160  inline void setCenter(const Math::Point<>& center_) { _center = center_; }
161 
162  inline Math::Point<> getCenter() const { return _center; }
163 
169  inline void setNonColTransform(const Math::Point<>& center_, const Math::Matrix3x3& rot_) {
170  _nonCollidingCenter = center_;
171  _nonCollidingRot = rot_;
172  }
173 
175  inline const Math::Point<>& getNonColCenter() const { return _nonCollidingCenter; }
176  inline const Math::Matrix3x3& getNonColRot() const { return _nonCollidingRot; }
177 
178  inline void setRot(const Math::Matrix3x3& rot_) { _rot = rot_; }
179 
180  inline Math::Matrix3x3 getRot() const { return _rot; }
181 
183  inline void setUserPointer(void* userPointer_) { _userPointer = userPointer_; }
184 
186  inline void* getUserPointer() const { return _userPointer; }
187 
195  inline Utils::uint canGroupHitMe(Utils::uint colGroup_) const { return (colGroup_ & ((_colGroup & COL_GROUP_HITTABLE_MASK) << 16)); }
196 
198  inline Utils::uint getColGroup() const { return _colGroup; }
199 
200  inline void setColGroup(Utils::uint colGroup_) { _colGroup = colGroup_; }
201 
202  virtual Shape* getShape() = 0;
203 
204  virtual const Shape* getShape() const = 0;
205 
206  virtual SHAPE_TYPE getType() const { return getShape()->getType(); }
207 
208  virtual float getDist(const Collidable* aCollidable_) const {
209  return getShape()->getDist(_center, _rot, aCollidable_->getShape(), aCollidable_->getCenter(), aCollidable_->getRot());
210  }
211 
212  virtual bool getFirstIntersection(const Math::Point<>& thisVel_, const Collidable* otherCollidable_,
213  const Math::Point<>& otherVel_, HitInfo& hitInfo_) const {
214  return getShape()->getFirstIntersection(_center, _rot, thisVel_, otherCollidable_->getShape(),
215  otherCollidable_->getCenter(), otherCollidable_->getRot(), otherVel_, hitInfo_);
216  }
217 
219  virtual bool getClosestRayIntersection(const Math::Point<>& rayOrigin_, const Math::Point<>& rayDir_,
220  Math::Point<>& hitPos_, float& t_, Math::Point<>& hitNormal_) const {
221  return getShape()->getClosestRayIntersection(_center, _rot, rayOrigin_, rayDir_, hitPos_, t_, hitNormal_);
222  }
223  };
224 
225  class Volume : public Collidable {
226  Shape* _shape;
227  public:
229  void* userPointer_=0, Utils::uint colGroup_=COL_GROUP_HIT_ALL_HIT_BY_ALL) : Collidable(center_,rot_,userPointer_,colGroup_),
230  _shape(shape_) {}
231 
232  inline void setBoundingRadius(const float& boundingRadius_) { _shape->_boundingRadius = boundingRadius_; }
233 
234  inline float getBoundingRadius() const { return _shape->_boundingRadius; }
235 
236  virtual Shape* getShape() { return _shape; }
237 
238  virtual const Shape* getShape() const { return _shape; }
239  };
240  }
241 }
242 
243 #endif //CDVOLUME_H
Sphere(const float &boundingRadius_)
Definition: CDVolume.h:81
#define COL_GROUP_HIT_ALL_HIT_BY_ALL
Definition: CDVolume.h:138
virtual ~Shape()
Definition: CDVolume.h:59
Definition: CDVolume.h:36
Definition: CDVolume.h:106
virtual SHAPE_TYPE getType() const
Definition: CDVolume.h:92
#define UNUSED(var)
Definition: UTypes.h:35
Definition: CDVolume.h:54
Math::Point _colliderStartCenter
Definition: CDVolume.h:46
Definition: CDVolume.h:31
void setColGroup(Utils::uint colGroup_)
Definition: CDVolume.h:200
virtual SHAPE_TYPE getType() const
Definition: CDVolume.h:206
Math::Point getCenter() const
Definition: CDVolume.h:162
virtual float getDist(const Collidable *aCollidable_) const
Definition: CDVolume.h:208
void setCenter(const Math::Point<> &center_)
Definition: CDVolume.h:160
virtual ~Collidable()
Definition: CDVolume.h:156
Volume(Shape *shape_, const Math::Point<> &center_=Math::g_origin, const Math::Matrix3x3 &rot_=Math::g_identityMatrix3x3, void *userPointer_=0, Utils::uint colGroup_=COL_GROUP_HIT_ALL_HIT_BY_ALL)
Definition: CDVolume.h:228
Math::Point _collideeVel
Definition: CDVolume.h:45
void setRot(const Math::Matrix3x3 &rot_)
Definition: CDVolume.h:178
Math::Point _collideeStartCenter
Definition: CDVolume.h:45
Volume * _collider
Definition: CDVolume.h:38
virtual bool getFirstIntersection(const Math::Point<> &thisCenter_, const Math::Matrix3x3 &thisRot_, const Math::Point<> &thisVel_, const Shape *otherShape_, const Math::Point<> &otherCenter_, const Math::Matrix3x3 &otherRot_, const Math::Point<> &otherVel_, HitInfo &hitInfo_) const
Definition: CDVolume.cpp:14
Definition: CDVolume.h:107
const Matrix3x3 g_identityMatrix3x3
Definition: MMatrix3x3.cpp:5
Plane(const Math::Point<> &n_)
Definition: CDVolume.h:111
AXIS_ALIGNMENT
Definition: CDVolume.h:107
const Point g_yAxis(0.0f, 1.0f, 0.0f)
Definition: MPoint.h:216
HitInfo(Volume *collider_=0)
Definition: CDVolume.h:48
virtual bool getFirstIntersection(const Math::Point<> &thisCenter_, const Math::Matrix3x3 &thisRot_, const Math::Point<> &thisVel_, const Shape *otherShape_, const Math::Point<> &otherCenter_, const Math::Matrix3x3 &otherRot_, const Math::Point<> &otherVel_, HitInfo &hitInfo_) const
Definition: CDVolume.cpp:165
Definition: CDVolume.h:225
Definition: CDVolume.h:107
Collidable(const Math::Point<> &center_=Math::g_origin, const Math::Matrix3x3 &rot_=Math::g_identityMatrix3x3, void *userPointer_=0, Utils::uint colGroup_=COL_GROUP_HIT_ALL_HIT_BY_ALL)
Definition: CDVolume.h:152
void setNonColTransform(const Math::Point<> &center_, const Math::Matrix3x3 &rot_)
Definition: CDVolume.h:169
void translate(const Math::Point<> &delta_)
Definition: CDVolume.h:158
#define COL_GROUP_HITTABLE_MASK
Definition: CDVolume.h:144
float _depthDiv2
Definition: CDVolume.h:87
virtual float getDist(const Math::Point<> &thisCenter_, const Math::Matrix3x3 &thisRot_, const Shape *otherShape_, const Math::Point<> &otherCenter_, const Math::Matrix3x3 &otherRot_) const
Definition: CDVolume.cpp:101
Definition: CDVolume.h:107
const Point g_origin
Definition: MPoint.cpp:5
bool equals(const Point< T > &rhs_, T radiusSqrd_) const
Definition: MPoint.h:152
virtual void scale(const Math::Point<> &factor_)
Definition: CDVolume.cpp:360
virtual float getDist(const Math::Point<> &thisCenter_, const Math::Matrix3x3 &thisRot_, const Shape *otherShape_, const Math::Point<> &otherCenter_, const Math::Matrix3x3 &otherRot_) const
Definition: CDVolume.cpp:7
Definition: CDVolume.h:31
Shape(const float &boundingRadius_=0.0f)
Definition: CDVolume.h:57
virtual float getDist(const Math::Point<> &thisCenter_, const Math::Matrix3x3 &thisRot_, const Shape *otherShape_, const Math::Point<> &otherCenter_, const Math::Matrix3x3 &otherRot_) const
Definition: CDVolume.h:80
float _heightDiv2
Definition: CDVolume.h:87
float getBoundingRadius() const
Definition: CDVolume.h:234
Math::Point _hitNormal
Definition: CDVolume.h:42
void setBoundingRadius(const float &boundingRadius_)
Definition: CDVolume.h:232
Utils::uint canGroupHitMe(Utils::uint colGroup_) const
Definition: CDVolume.h:195
const float PSEUDO_INFINITY(1000000.0f)
virtual void scale(const Math::Point<> &factor_)
Definition: CDVolume.h:77
Box(const float &boundingRadius_, const float &width_, const float &height_, const float &depth_)
Definition: CDVolume.h:89
unsigned int uint
Definition: UTypes.h:39
Math::Point _hitPos
Definition: CDVolume.h:42
virtual Shape * getShape()
Definition: CDVolume.h:236
Definition: CDVolume.h:107
virtual SHAPE_TYPE getType() const =0
virtual SHAPE_TYPE getType() const
Definition: CDVolume.h:113
virtual SHAPE_TYPE getType() const
Definition: CDVolume.h:83
virtual bool getClosestRayIntersection(const Math::Point<> &rayOrigin_, const Math::Point<> &rayDir_, Math::Point<> &hitPos_, float &t_, Math::Point<> &hitNormal_) const
Definition: CDVolume.h:219
Definition: MPoint.h:33
Definition: CDVolume.h:107
Definition: CDVolume.h:31
Math::Point _colliderVel
Definition: CDVolume.h:46
const Point g_xAxis(1.0f, 0.0f, 0.0f)
Definition: MPoint.h:215
float _hitSecs
Definition: CDVolume.h:40
Math::Point _n
Definition: CDVolume.h:109
Utils::uint getColGroup() const
Definition: CDVolume.h:198
virtual bool getClosestRayIntersection(const Math::Point<> &thisCenter_, const Math::Matrix3x3 &thisRot_, const Math::Point<> &rayOrigin_, const Math::Point<> &rayDir_, Math::Point<> &hitPos_, float &t_, Math::Point<> &hitNormal_) const
Definition: CDVolume.cpp:62
float _boundingRadius
Definition: CDVolume.h:55
AXIS_ALIGNMENT getAxisAlignment() const
Definition: CDVolume.h:126
SHAPE_TYPE
Definition: CDVolume.h:31
void * getUserPointer() const
Definition: CDVolume.h:186
virtual Shape * getShape()=0
const Math::Point & getNonColCenter() const
Definition: CDVolume.h:175
Definition: MMatrix3x3.h:32
const Point g_zAxis(0.0f, 0.0f, 1.0f)
Definition: MPoint.h:217
T getDot3(const Point< T > &rhs_) const
Definition: MPoint.h:202
Math::Point getDimensions() const
Definition: CDVolume.h:94
Definition: CDVolume.h:146
const Math::Matrix3x3 & getNonColRot() const
Definition: CDVolume.h:176
void setUserPointer(void *userPointer_)
Definition: CDVolume.h:183
virtual bool getFirstIntersection(const Math::Point<> &thisVel_, const Collidable *otherCollidable_, const Math::Point<> &otherVel_, HitInfo &hitInfo_) const
Definition: CDVolume.h:212
const float CLOSE_TO_ZERO(0.00001f)
float float rot_[3]
Definition: ViewerApp.h:31
Math::Matrix3x3 getRot() const
Definition: CDVolume.h:180
float getDist(const Math::Point<> &thisP_, const Math::Point<> &otherP_) const
Definition: CDVolume.h:121
float _widthDiv2
Definition: CDVolume.h:87
Definition: CDVolume.h:86
Definition: CDVolume.h:107
virtual const Shape * getShape() const
Definition: CDVolume.h:238
Definition: CDVolume.h:107