ScummVM API documentation
dgCollisionScene.h
1 /* Copyright (c) <2003-2011> <Julio Jerez, Newton Game Dynamics>
2  *
3  * This software is provided 'as-is', without any express or implied
4  * warranty. In no event will the authors be held liable for any damages
5  * arising from the use of this software.
6  *
7  * Permission is granted to anyone to use this software for any purpose,
8  * including commercial applications, and to alter it and redistribute it
9  * freely, subject to the following restrictions:
10  *
11  * 1. The origin of this software must not be misrepresented; you must not
12  * claim that you wrote the original software. If you use this software
13  * in a product, an acknowledgment in the product documentation would be
14  * appreciated but is not required.
15  *
16  * 2. Altered source versions must be plainly marked as such, and must not be
17  * misrepresented as being the original software.
18  *
19  * 3. This notice may not be removed or altered from any source distribution.
20  */
21 
22 #if !defined(AFX_DGCOLLISIONSCENE_H_INCLUDED_)
23 #define AFX_DGCOLLISIONSCENE_H_INCLUDED_
24 
25 #include "dgCollision.h"
26 #include "dgCollisionMesh.h"
27 #include "dgContact.h"
28 
29 class dgCollisionScene : public dgCollision {
30 public:
31  class dgNode {
32  public:
33  DG_CLASS_ALLOCATOR(allocator)
34  dgNode();
35  dgNode(dgNode *const sibling, dgNode *const myNode);
36  ~dgNode();
37 
38  dgVector m_minBox;
39  dgVector m_maxBox;
40  dgFloat32 m_surfaceArea;
41  dgNode *m_parent;
42  dgNode *m_left;
43  dgNode *m_right;
44  dgList<dgNode *>::dgListNode *m_fitnessNode;
45  } DG_GCC_VECTOR_ALIGMENT;
46 
47  class dgProxy : public dgNode {
48  public:
49  DG_CLASS_ALLOCATOR(allocator)
50 
51  dgProxy(dgCollision *shape, const dgMatrix &matrix, dgCollisionScene *const owner);
52  ~dgProxy();
53 
54  dgMatrix m_matrix;
55  void *m_userData;
56  dgCollision *m_shape;
57  dgCollisionScene *m_owner;
59  };
60 
61  dgCollisionScene(dgWorld *const world);
62  dgCollisionScene(dgWorld *const world, dgDeserialize deserialization, void *const userData);
63  virtual ~dgCollisionScene();
64 
65  void *GetFirstProxy() const;
66  void *GetNextProxy(void *const proxy) const;
67  void *AddProxy(dgCollision *const shape, const dgMatrix &matrix);
68  void SetProxyUserData(void *const proxy, void *const userData);
69  void *GetProxyUserData(void *const proxy) const;
70  void RemoveProxy(void *const proxy);
71  void ImproveTotalFitness();
72 
73  dgMatrix GetProxyMatrix(void *const proxy);
74  void SetProxyMatrix(void *const proxy, const dgMatrix &matrix);
75 
76  void CollidePair(dgCollidingPairCollector::dgPair *const pair, dgCollisionParamProxy &proxy) const;
77  void CollidePairSimd(dgCollidingPairCollector::dgPair *const pair, dgCollisionParamProxy &proxy) const;
78 
79  void SetCollisionCallback(dgCollisionMeshCollisionCallback debugCallback);
80 
81 private:
82  virtual dgVector SupportVertex(const dgVector &dir) const;
83  virtual void CalcAABB(const dgMatrix &matrix, dgVector &p0, dgVector &p1) const;
84  virtual void CalcAABBSimd(const dgMatrix &matrix, dgVector &p0, dgVector &p1) const;
85  virtual bool OOBBTest(const dgMatrix &matrix, const dgCollisionConvex *const shape, void *const cacheOrder) const;
86 
87  virtual void DebugCollision(const dgMatrix &matrix, OnDebugCollisionMeshCallback callback, void *const userData) const;
88  virtual dgFloat32 RayCast(const dgVector &localP0, const dgVector &localP1, dgContactPoint &contactOut, OnRayPrecastAction preFilter, const dgBody *const body, void *const userData) const;
89  virtual dgFloat32 RayCastSimd(const dgVector &localP0, const dgVector &localP1, dgContactPoint &contactOut, OnRayPrecastAction preFilter, const dgBody *const body, void *const userData) const;
90  virtual dgFloat32 GetVolume() const;
91 
92  virtual dgInt32 CalculateSignature() const;
93  virtual dgFloat32 GetBoxMinRadius() const;
94  virtual dgFloat32 GetBoxMaxRadius() const;
95  virtual void SetCollisionBBox(const dgVector &p0, const dgVector &p1);
96  virtual void CalculateInertia(dgVector &inertia, dgVector &origin) const;
97  virtual dgVector CalculateVolumeIntegral(const dgMatrix &globalMatrix, GetBuoyancyPlane bouyancyPlane, void *const context) const;
98 
99  virtual void GetCollisionInfo(dgCollisionInfo *info) const;
100  virtual void Serialize(dgSerialize callback, void *const userData) const;
101 
102  void ImproveNodeFitness(dgNode *const node);
103  dgFloat32 CalculateSurfaceArea(const dgNode *const node0, const dgNode *const node1, dgVector &minBox, dgVector &maxBox) const;
104 
105  dgVector m_boxSize;
106  dgVector m_boxOrigin;
107 
108  dgInt32 m_lock;
109  dgWorld *m_world;
110  dgNode *m_rootNode;
111  dgList<dgProxy *> m_list;
112  dgList<dgNode *> m_fitnessList;
113 };
114 
115 #endif
Definition: dgCollision.h:73
Definition: dgBody.h:85
Definition: dgList.h:35
Definition: dgVector.h:86
Definition: dgList.h:33
Definition: dgContact.h:88
Definition: dgCollisionScene.h:29
Definition: dgCollisionConvex.h:39
Definition: dgCollisionScene.h:47
Definition: dgCollision.h:178
Definition: dgMatrix.h:41
Definition: dgWorld.h:118
Definition: dgCollisionScene.h:31
Definition: dgContact.h:53
Definition: dgContact.h:102