-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathCCollidableOBBTree.cpp
More file actions
55 lines (43 loc) · 2 KB
/
Copy pathCCollidableOBBTree.cpp
File metadata and controls
55 lines (43 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include "WorldFormat/CCollidableOBBTree.hpp"
#include "WorldFormat/COBBTree.hpp"
uint CCollidableOBBTree::sTableIndex = -1;
CCollidableOBBTree::CCollidableOBBTree(COBBTree* tree, const CMaterialList& material)
: CCollisionPrimitive(material), x10_tree(tree), x14_tries(0), x18_misses(0), x1c_hits(0) {}
CAABox CCollidableOBBTree::CalculateAABox(const CTransform4f& xf) const {
const COBBox obbox = COBBox::FromAABox(x10_tree->CalculateLocalAABox(), xf);
return obbox.CalculateAABox(CTransform4f::Identity());
}
CAABox CCollidableOBBTree::CalculateLocalAABox() const { return x10_tree->CalculateLocalAABox(); }
FourCC CCollidableOBBTree::GetPrimType() const { return 'OBBT'; }
bool CCollidableOBBTree::AABoxCollision(const COBBTree::CNode& node, const CTransform4f& xf,
const CAABox& abb, const COBBox& obb,
const CMaterialList& matList,
const CMaterialFilter& matFilter, const CPlane planes[6],
CCollisionInfoList& outList) const {
bool ret = false;
x14_tries++;
if (obb.OBBIntersectsBox(node.GetOBB())) {
node.SetHit(true);
if (node.IsLeaf()) {
if (AABoxCollideWithLeaf(*node.GetLeafData(), xf, abb, matList, matFilter, planes, outList)) {
ret = true;
}
} else {
if (AABoxCollision(*node.GetLeftNode(), xf, abb, obb, matList, matFilter, planes, outList)) {
ret = true;
}
if (AABoxCollision(*node.GetRightNode(), xf, abb, obb, matList, matFilter, planes, outList)) {
ret = true;
}
}
} else {
x18_misses++;
}
return ret;
}
CPlane TransformPlane(const CPlane& plane, const CTransform4f& xf) {
const CVector3f dVec = xf * (plane.GetNormal() * plane.GetConstant());
const CVector3f normal = xf.Rotate(plane.GetNormal());
return CPlane(dVec, CUnitVector3f(normal.GetX(), normal.GetY(), normal.GetZ()));
}
uint CCollidableOBBTree::GetTableIndex() const { return sTableIndex; }