2 Physics Effects Copyright(C) 2010 Sony Computer Entertainment Inc.
\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
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
13 A copy of the BSD License is distributed with
\r
14 Physics Effects under the filename: physics_effects_license.txt
\r
17 #include "../../../include/physics_effects/base_level/base/pfx_vec_utils.h"
\r
18 #include "pfx_contact_tri_mesh_sphere.h"
\r
19 #include "pfx_contact_tri_mesh_box.h"
\r
20 #include "pfx_contact_tri_mesh_capsule.h"
\r
21 #include "pfx_contact_tri_mesh_cylinder.h"
\r
22 #include "pfx_contact_tri_mesh_convex.h"
\r
23 #include "pfx_contact_large_tri_mesh.h"
\r
24 #include "pfx_intersect_common.h"
\r
25 #include "pfx_mesh_common.h"
\r
29 namespace PhysicsEffects {
\r
32 PfxInt32 pfxContactLargeTriMesh(
\r
33 PfxContactCache &contacts,
\r
34 const PfxLargeTriMesh *lmeshA,
\r
35 const PfxTransform3 &transformA,
\r
36 const PfxShape &shapeB,
\r
37 const PfxTransform3 &transformB,
\r
38 PfxFloat distanceThreshold)
\r
40 PfxTransform3 transformAB;
\r
41 PfxMatrix3 matrixAB;
\r
42 PfxVector3 offsetAB;
\r
45 transformAB = orthoInverse(transformA) * transformB;
\r
46 matrixAB = transformAB.getUpper3x3();
\r
47 offsetAB = transformAB.getTranslation();
\r
49 // -----------------------------------------------------
\r
50 // LargeTriMeshに含まれるTriMeshのAABBと凸体のAABBを判定し、
\r
51 // 交差するものを個別に衝突判定する。※LargeMesh座標系
\r
53 PfxVector3 shapeHalf(0.0f);
\r
54 PfxVector3 shapeCenter = offsetAB;
\r
57 switch(shapeB.getType()) {
\r
58 case kPfxShapeSphere:
\r
59 shapeHalf = PfxVector3(shapeB.getSphere().m_radius);
\r
62 case kPfxShapeCapsule:
\r
64 PfxCapsule capsule = shapeB.getCapsule();
\r
65 shapeHalf = absPerElem(matrixAB) * PfxVector3(capsule.m_halfLen+capsule.m_radius,capsule.m_radius,capsule.m_radius);
\r
69 case kPfxShapeCylinder:
\r
71 PfxCylinder cylinder = shapeB.getCylinder();
\r
72 shapeHalf = absPerElem(matrixAB) * PfxVector3(cylinder.m_halfLen,cylinder.m_radius,cylinder.m_radius);
\r
77 shapeHalf = absPerElem(matrixAB) * shapeB.getBox().m_half;
\r
80 case kPfxShapeConvexMesh:
\r
81 shapeHalf = absPerElem(matrixAB) * shapeB.getConvexMesh()->m_half;
\r
88 // -----------------------------------------------------
\r
91 PfxVecInt3 aabbMinL,aabbMaxL;
\r
92 lmeshA->getLocalPosition((shapeCenter-shapeHalf),(shapeCenter+shapeHalf),aabbMinL,aabbMaxL);
\r
94 PfxUInt32 numIslands = lmeshA->m_numIslands;
\r
97 for(PfxUInt32 i=0;i<numIslands;i++) {
\r
99 PfxAabb16 aabbB = lmeshA->m_aabbList[i];
\r
100 if(aabbMaxL.getX() < pfxGetXMin(aabbB) || aabbMinL.getX() > pfxGetXMax(aabbB)) continue;
\r
101 if(aabbMaxL.getY() < pfxGetYMin(aabbB) || aabbMinL.getY() > pfxGetYMax(aabbB)) continue;
\r
102 if(aabbMaxL.getZ() < pfxGetZMin(aabbB) || aabbMinL.getZ() > pfxGetZMax(aabbB)) continue;
\r
104 PfxTriMesh *island = &lmeshA->m_islands[i];
\r
107 PfxContactCache localContacts;
\r
108 switch(shapeB.getType()) {
\r
109 case kPfxShapeSphere:
\r
110 pfxContactTriMeshSphere(localContacts,island,transformA,shapeB.getSphere(),transformB,distanceThreshold);
\r
113 case kPfxShapeCapsule:
\r
114 pfxContactTriMeshCapsule(localContacts,island,transformA,shapeB.getCapsule(),transformB,distanceThreshold);
\r
118 pfxContactTriMeshBox(localContacts,island,transformA,shapeB.getBox(),transformB,distanceThreshold);
\r
121 case kPfxShapeCylinder:
\r
122 pfxContactTriMeshCylinder(localContacts,island,transformA,shapeB.getCylinder(),transformB,distanceThreshold);
\r
125 case kPfxShapeConvexMesh:
\r
126 pfxContactTriMeshConvex(localContacts,island,transformA,*shapeB.getConvexMesh(),transformB,distanceThreshold);
\r
135 for(int j=0;j<localContacts.getNumContacts();j++) {
\r
136 PfxSubData subData = localContacts.getSubData(j);
\r
137 subData.setIslandId(i);
\r
138 contacts.addContactPoint(
\r
139 localContacts.getDistance(j),
\r
140 localContacts.getNormal(j),
\r
141 localContacts.getLocalPointA(j),
\r
142 localContacts.getLocalPointB(j),
\r
149 return contacts.getNumContacts();
\r
151 } //namespace PhysicsEffects
\r