forked from schteppe/cannon.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNarrowphase.js
More file actions
83 lines (70 loc) · 2.18 KB
/
Copy pathNarrowphase.js
File metadata and controls
83 lines (70 loc) · 2.18 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
var Vec3 = require("../src/math/Vec3");
var Quaternion = require("../src/math/Quaternion");
var Box = require('../src/shapes/Box');
var Heightfield = require('../src/shapes/heightfield');
var Narrowphase = require('../src/world/Narrowphase');
var Sphere = require('../src/shapes/Sphere');
var Body = require('../src/objects/Body');
var ContactMaterial = require('../src/material/ContactMaterial');
var World = require('../src/world/World');
module.exports = {
sphereSphere : function(test){
var world = new World();
var cg = new Narrowphase(world);
var result = [];
var sphereShape = new Sphere(1);
var bodyA = new Body({ mass: 1 });
bodyA.addShape(sphereShape);
var bodyB = new Body({ mass: 1 });
bodyB.addShape(sphereShape);
cg.currentContactMaterial = new ContactMaterial();
cg.result = result;
cg.sphereSphere(
sphereShape,
sphereShape,
new Vec3(0.5, 0, 0),
new Vec3(-0.5, 0, 0),
new Quaternion(),
new Quaternion(),
bodyA,
bodyB
);
test.equal(result.length, 1);
test.done();
},
sphereHeightfield : function(test){
var world = new World();
var cg = new Narrowphase(world);
var result = [];
var hfShape = createHeightfield();
var sphereShape = new Sphere(0.1);
cg.currentContactMaterial = new ContactMaterial();
cg.result = result;
cg.sphereHeightfield(
sphereShape,
hfShape,
new Vec3(0.25, 0.25, 0.05), // hit the first triangle in the field
new Vec3(0, 0, 0),
new Quaternion(),
new Quaternion(),
new Body(1, sphereShape),
new Body(1, hfShape)
);
test.equal(result.length, 1);
test.done();
},
};
function createHeightfield(){
var matrix = [];
var size = 20;
for (var i = 0; i < size; i++) {
matrix.push([]);
for (var j = 0; j < size; j++) {
matrix[i].push(0);
}
}
var hfShape = new Heightfield(matrix, {
elementSize: 1,
});
return hfShape;
}