Initialize libbullet git in 2.0_beta.
[platform/upstream/libbullet.git] / Extras / PhysicsEffects / src / base_level / collision / pfx_shape.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_shape.h"\r
18 \r
19 namespace sce {\r
20 namespace PhysicsEffects {\r
21 void pfxGetShapeAabbDummy(const PfxShape &shape,PfxVector3 &aabbMin,PfxVector3 &aabbMax)\r
22 {\r
23         (void)shape,(void)aabbMin,(void)aabbMax;\r
24 }\r
25 \r
26 void pfxGetShapeAabbSphere(const PfxShape &shape,PfxVector3 &aabbMin,PfxVector3 &aabbMax)\r
27 {\r
28         aabbMin = shape.getOffsetPosition() - PfxVector3(shape.getSphere().m_radius);\r
29         aabbMax = shape.getOffsetPosition() + PfxVector3(shape.getSphere().m_radius);\r
30 }\r
31 \r
32 void pfxGetShapeAabbBox(const PfxShape &shape,PfxVector3 &aabbMin,PfxVector3 &aabbMax)\r
33 {\r
34         PfxVector3 boxSize = absPerElem(PfxMatrix3(shape.getOffsetOrientation())) * shape.getBox().m_half;\r
35         aabbMin = shape.getOffsetPosition() - boxSize;\r
36         aabbMax = shape.getOffsetPosition() + boxSize;\r
37 }\r
38 \r
39 void pfxGetShapeAabbCapsule(const PfxShape &shape,PfxVector3 &aabbMin,PfxVector3 &aabbMax)\r
40 {\r
41         PfxVector3 dir = rotate(shape.getOffsetOrientation(),PfxVector3(1.0f,0.0f,0.0f));\r
42         PfxVector3 capSize = absPerElem(dir) * shape.getCapsule().m_halfLen + \r
43                 PfxVector3(shape.getCapsule().m_radius);\r
44         aabbMin = shape.getOffsetPosition() - capSize;\r
45         aabbMax = shape.getOffsetPosition() + capSize;\r
46 }\r
47 \r
48 void pfxGetShapeAabbCylinder(const PfxShape &shape,PfxVector3 &aabbMin,PfxVector3 &aabbMax)\r
49 {\r
50         PfxVector3 capSize = absPerElem(PfxMatrix3(shape.getOffsetOrientation())) * \r
51                 PfxVector3(shape.getCylinder().m_halfLen,shape.getCylinder().m_radius,shape.getCylinder().m_radius);\r
52         aabbMin = shape.getOffsetPosition() - capSize;\r
53         aabbMax = shape.getOffsetPosition() + capSize;\r
54 }\r
55 \r
56 void pfxGetShapeAabbConvexMesh(const PfxShape &shape,PfxVector3 &aabbMin,PfxVector3 &aabbMax)\r
57 {\r
58         const PfxConvexMesh *convex = shape.getConvexMesh();\r
59         PfxVector3 half = absPerElem(PfxMatrix3(shape.getOffsetOrientation())) * convex->m_half;\r
60         aabbMin = shape.getOffsetPosition() - half;\r
61         aabbMax = shape.getOffsetPosition() + half;\r
62 }\r
63 \r
64 void pfxGetShapeAabbLargeTriMesh(const PfxShape &shape,PfxVector3 &aabbMin,PfxVector3 &aabbMax)\r
65 {\r
66         const PfxLargeTriMesh *largemesh = shape.getLargeTriMesh();\r
67         PfxVector3 half = absPerElem(PfxMatrix3(shape.getOffsetOrientation())) *  largemesh->m_half;\r
68         aabbMin = shape.getOffsetPosition() - half;\r
69         aabbMax = shape.getOffsetPosition() + half;\r
70 }\r
71 \r
72 typedef void (*PfxFuncGetShapeAabb)(const PfxShape &shape,PfxVector3 &aabbMin,PfxVector3 &aabbMax);\r
73 \r
74 PfxFuncGetShapeAabb pfxFuncGetShapeAabb[kPfxShapeCount] = {\r
75         pfxGetShapeAabbSphere,\r
76         pfxGetShapeAabbBox,\r
77         pfxGetShapeAabbCapsule,\r
78         pfxGetShapeAabbCylinder,\r
79         pfxGetShapeAabbConvexMesh,\r
80         pfxGetShapeAabbLargeTriMesh,\r
81         pfxGetShapeAabbDummy,\r
82         pfxGetShapeAabbDummy,\r
83         pfxGetShapeAabbDummy,\r
84         pfxGetShapeAabbDummy,\r
85         pfxGetShapeAabbDummy,\r
86         pfxGetShapeAabbDummy,\r
87 };\r
88 \r
89 void PfxShape::getAabb(PfxVector3 &aabbMin,PfxVector3 &aabbMax) const\r
90 {\r
91         return pfxFuncGetShapeAabb[m_type](*this,aabbMin,aabbMax);\r
92 }\r
93 \r
94 } //namespace PhysicsEffects\r
95 } //namespace sce\r