Initialize libbullet git in 2.0_beta.
[platform/upstream/libbullet.git] / Extras / PhysicsEffects / src / base_level / collision / pfx_contact_cache.h
1 /*\r
2 Physics Effects Copyright(C) 2010 Sony Computer Entertainment Inc.\r
3 All rights reserved.\r
4 \r
5 Physics Effects is open software; you can redistribute it and/or\r
6 modify it under the terms of the BSD License.\r
7 \r
8 Physics Effects is distributed in the hope that it will be useful,\r
9 but WITHOUT ANY WARRANTY; without even the implied warranty of\r
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\r
11 See the BSD License for more details.\r
12 \r
13 A copy of the BSD License is distributed with\r
14 Physics Effects under the filename: physics_effects_license.txt\r
15 */\r
16 \r
17 #ifndef _SCE_PFX_CONTACT_CACHE_H\r
18 #define _SCE_PFX_CONTACT_CACHE_H\r
19 \r
20 #include "../../../include/physics_effects/base_level/base/pfx_common.h"\r
21 #include "../../../include/physics_effects/base_level/base/pfx_vec_utils.h"\r
22 #include "../../../include/physics_effects/base_level/collision/pfx_sub_data.h"\r
23 \r
24 namespace sce {\r
25 namespace PhysicsEffects {\r
26 \r
27 #define SCE_PFX_MAX_CACHED_CONTACT_POINTS 4\r
28 \r
29 /*\r
30         内部の衝突判定に使う軽量なコンタクトキャッシュ\r
31 */\r
32 \r
33 ///////////////////////////////////////////////////////////////////////////////\r
34 // Contact Point\r
35 \r
36 struct PfxCachedContactPoint\r
37 {\r
38         PfxSubData m_subData;\r
39         PfxUInt8 m_shapeIdA;\r
40         PfxUInt8 m_shapeIdB;\r
41         SCE_PFX_PADDING(1,2)\r
42         PfxFloat m_distance;\r
43         PfxVector3 m_normal;\r
44         PfxPoint3 m_localPointA;\r
45         PfxPoint3 m_localPointB;\r
46 \r
47         void reset()\r
48         {\r
49                 m_shapeIdA = m_shapeIdB = 0;\r
50                 m_subData = PfxSubData();\r
51                 m_distance = SCE_PFX_FLT_MAX;\r
52         }\r
53 };\r
54 \r
55 ///////////////////////////////////////////////////////////////////////////////\r
56 // Contact Point\r
57 \r
58 class PfxContactCache\r
59 {\r
60 private:\r
61         PfxUInt32 m_numContacts;\r
62         SCE_PFX_PADDING(1,12)\r
63         PfxCachedContactPoint m_cachedContactPoints[SCE_PFX_MAX_CACHED_CONTACT_POINTS];\r
64         \r
65         int findNearestContactPoint(const PfxPoint3 &newPoint,const PfxVector3 &newNormal);\r
66         int sort4ContactPoints(const PfxPoint3 &newPoint,PfxFloat newDistance);\r
67         \r
68 public:\r
69         PfxContactCache() : m_numContacts(0) {}\r
70         \r
71         void addContactPoint(\r
72                 PfxFloat newDistance,\r
73                 const PfxVector3 &newNormal, // world normal vector\r
74                 const PfxPoint3 &newPointA, // local contact point to the objectA\r
75                 const PfxPoint3 &newPointB, // local contact point to the objectB\r
76                 PfxSubData m_subData);\r
77         \r
78         void addContactPoint(const PfxCachedContactPoint &cp);\r
79         \r
80         int getNumContacts() const {return (int)m_numContacts;}\r
81         \r
82         PfxCachedContactPoint &getContactPoint(int i) {return m_cachedContactPoints[i];}\r
83         \r
84         const PfxCachedContactPoint &getContactPoint(int i) const {return m_cachedContactPoints[i];}\r
85 \r
86         PfxFloat getDistance(int i) {return m_cachedContactPoints[i].m_distance;}\r
87         \r
88         const PfxVector3 &getNormal(int i) const {return m_cachedContactPoints[i].m_normal;}\r
89         \r
90         const PfxPoint3 &getLocalPointA(int i) const {return m_cachedContactPoints[i].m_localPointA;}\r
91         \r
92         const PfxPoint3 &getLocalPointB(int i) const {return m_cachedContactPoints[i].m_localPointB;}\r
93         \r
94         const PfxSubData &getSubData(int i) const {return m_cachedContactPoints[i].m_subData;}\r
95 };\r
96 \r
97 } //namespace PhysicsEffects\r
98 } //namespace sce\r
99 \r
100 #endif // _SCE_PFX_CONTACT_CACHE_H\r