forked from kripken/ammo.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuserData.js
47 lines (36 loc) · 1.28 KB
/
userData.js
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
Ammo().then(function(Ammo) {
var transform = new Ammo.btTransform();
transform.setIdentity();
var vec = new Ammo.btVector3();
var quat = new Ammo.btQuaternion();
quat.setValue(0, 0, 0 , 1);
// Create box shape
vec.setValue(0.5, 0.5, 0.5);
var boxShape = new Ammo.btBoxShape(vec);
// Create rigid body
vec.setValue(0, 0, 0);
transform.setOrigin(vec);
transform.setRotation(quat);
var motionState = new Ammo.btDefaultMotionState(transform);
var mass = 10;
boxShape.calculateLocalInertia(mass, vec);
var rbInfo = new Ammo.btRigidBodyConstructionInfo(mass, motionState, boxShape, vec);
var rigidBody = new Ammo.btRigidBody(rbInfo);
// Note that in bullet, the user pointer and index are in an union.
var theValue = 1234;
rigidBody.setUserPointer(theValue);
var userPointer1 = rigidBody.getUserPointer();
assert(userPointer1.ptr == theValue, "User pointer is not the same" );
theValue = 4567;
rigidBody.setUserIndex(theValue);
var userIndex1 = rigidBody.getUserIndex();
assert(userIndex1 == theValue, "User index is not the same" );
Ammo.destroy(rigidBody.getCollisionShape());
Ammo.destroy(motionState);
Ammo.destroy(rigidBody);
Ammo.destroy(rbInfo);
Ammo.destroy(vec);
Ammo.destroy(quat);
Ammo.destroy(transform);
print('ok.');
});