Initialize libbullet git in 2.0_beta.
[platform/upstream/libbullet.git] / Extras / PhysicsEffects / src / base_level / collision / pfx_collidable.cpp
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 #include "../../../include/physics_effects/base_level/collision/pfx_collidable.h"\r
18 \r
19 namespace sce {\r
20 namespace PhysicsEffects {\r
21 \r
22 void PfxCollidable::addShape(const PfxShape &shape)\r
23 {\r
24         if(m_numShapes<m_maxShapes) {\r
25                 PfxShape &newShape = getNewShape();\r
26                 newShape = shape;\r
27         }\r
28 }\r
29 \r
30 void PfxCollidable::finish()\r
31 {\r
32         if(m_numShapes == 0) return;\r
33 \r
34         // compute AABB\r
35         PfxVector3 halfMax(-SCE_PFX_FLT_MAX),halfMin(SCE_PFX_FLT_MAX);\r
36 \r
37         for(PfxUInt32 i=0;i<getNumShapes();i++) {\r
38                 const PfxShape &shape = getShape(i);\r
39                 PfxVector3 aabbMin,aabbMax;\r
40                 shape.getAabb(aabbMin,aabbMax);\r
41                 halfMax = maxPerElem(halfMax,aabbMax);\r
42                 halfMin = minPerElem(halfMin,aabbMin);\r
43         }\r
44         \r
45         PfxVector3 allCenter = ( halfMin + halfMax ) * 0.5f;\r
46         PfxVector3 allHalf = ( halfMax - halfMin ) * 0.5f;\r
47         m_center[0] = allCenter[0];\r
48         m_center[1] = allCenter[1];\r
49         m_center[2] = allCenter[2];\r
50         m_half[0] = allHalf[0];\r
51         m_half[1] = allHalf[1];\r
52         m_half[2] = allHalf[2];\r
53 }\r
54 \r
55 } //namespace PhysicsEffects\r
56 } //namespace sce\r