1 /*************************************************************************
2 * *
3 * Tokamak Physics Engine, Copyright (C) 2002-2007 David Lam. *
4 * All rights reserved. Email: david@tokamakphysics.com *
5 * Web: www.tokamakphysics.com *
6 * *
7 * This library is distributed in the hope that it will be useful, *
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files *
10 * LICENSE.TXT for more details. *
11 * *
12 *************************************************************************/
13
14 #include <stdio.h>
15 #include "tokamak.h"
16 #include "containers.h"
17 #include "scenery.h"
18 #include "collision.h"
19 #include "collision2.h"
20 #include "constraint.h"
21 #include "rigidbody.h"
22 #include "scenery.h"
23 #include "stack.h"
24 #include "simulator.h"
25 #include "message.h"
26
27 #ifdef USE_OPCODE
28
29 Opcode::AABBTreeCollider tc;
30
31 Opcode::BVTCache ColCache;
32
33 IceMaths::Matrix4x4 worldA, worldB;
34
GetTriangleOverlap(neCollisionResult & result,s32 i,TConvex & convexA,TConvex & convexB)35 void GetTriangleOverlap(neCollisionResult & result, s32 i, TConvex & convexA, TConvex & convexB)
36 {
37 const Pair * pair = &tc.GetPairs()[i];
38
39 IceMaths::Point * vertsA = convexA.as.opcodeMesh.vertices;
40
41 IndexedTriangle * trisA = convexA.as.opcodeMesh.triIndices;
42
43 IceMaths::Point * vertsB = convexB.as.opcodeMesh.vertices;
44
45 IndexedTriangle * trisB = convexB.as.opcodeMesh.triIndices;
46
47 IceMaths::Point V0 = worldA * vertsA[trisA[pair->id0].mVRef[0]];
48
49 IceMaths::Point V1 = worldA * vertsA[trisA[pair->id0].mVRef[1]];
50
51 IceMaths::Point V2 = worldA * vertsA[trisA[pair->id0].mVRef[2]];
52
53 IceMaths::Point U0 = worldB * vertsB[trisB[pair->id1].mVRef[0]];
54
55 IceMaths::Point U1 = worldB * vertsB[trisB[pair->id1].mVRef[1]];
56
57 IceMaths::Point U2 = worldB * vertsB[trisB[pair->id1].mVRef[2]];
58
59 if (tc.TriTriOverlap(V0, V1, V2, U0, U1, U2))
60 {
61
62 }
63 }
64
Box2OpcodeTest(neCollisionResult & result,TConvex & convexA,neT3 & transA,TConvex & convexB,neT3 & transB)65 void Box2OpcodeTest(neCollisionResult & result, TConvex & convexA, neT3 & transA, TConvex & convexB, neT3 & transB)
66 {
67
68 }
69
Sphere2OpcodeTest(neCollisionResult & result,TConvex & convexA,neT3 & transA,TConvex & convexB,neT3 & transB)70 void Sphere2OpcodeTest(neCollisionResult & result, TConvex & convexA, neT3 & transA, TConvex & convexB, neT3 & transB)
71 {
72 }
73
Cylinder2OpcodeTest(neCollisionResult & result,TConvex & convexA,neT3 & transA,TConvex & convexB,neT3 & transB)74 void Cylinder2OpcodeTest(neCollisionResult & result, TConvex & convexA, neT3 & transA, TConvex & convexB, neT3 & transB)
75 {
76 }
77
Opcode2TerrainTest(neCollisionResult & result,TConvex & convexA,neT3 & transA,TConvex & convexB)78 void Opcode2TerrainTest(neCollisionResult & result, TConvex & convexA, neT3 & transA, TConvex & convexB)
79 {
80 }
81
Opcode2OpcodeTest(neCollisionResult & result,TConvex & convexA,neT3 & transA,TConvex & convexB,neT3 & transB)82 void Opcode2OpcodeTest(neCollisionResult & result, TConvex & convexA, neT3 & transA, TConvex & convexB, neT3 & transB)
83 {
84 tc.SetFirstContact(false);
85 tc.SetFullBoxBoxTest(true);
86 tc.SetFullPrimBoxTest(true);
87 tc.SetTemporalCoherence(false);
88
89 tc.SetPointers0(convexA.as.opcodeMesh.triIndices, convexA.as.opcodeMesh.vertices);
90 tc.SetPointers1(convexB.as.opcodeMesh.triIndices, convexB.as.opcodeMesh.vertices);
91
92 // Setup cache
93
94 ColCache.Model0 = convexA.as.opcodeMesh.opmodel;
95 ColCache.Model1 = convexB.as.opcodeMesh.opmodel;
96
97 transA.AssignIceMatrix(worldA);
98 transB.AssignIceMatrix(worldB);
99 // Collision query
100
101 bool IsOk = tc.Collide(ColCache, &worldA, &worldB);
102
103 if (tc.GetContactStatus() == false)
104 {
105 result.penetrate = false;
106 return;
107 }
108
109 u32 npairs = tc.GetNbPairs();
110
111 result.penetrate = true;
112
113 result.depth = 0.0f;
114
115 for (u32 i = 0; i < npairs; i++)
116 {
117 GetTriangleOverlap(result, i, convexA, convexB);
118 }
119 }
120
121 #endif //USE_OPCODE