-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug.js
More file actions
41 lines (34 loc) · 1.6 KB
/
debug.js
File metadata and controls
41 lines (34 loc) · 1.6 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
var sprintf = require('sprintf');
var THREE = require('./libs/threejs/three.js');
module.exports = {
showMatrix: function(name, m) {
console.log(name + ' =');
this.logMatrix(m);
},
logMatrix: function(m) {
console.log(sprintf("[ %10.4f %10.4f %10.4f %10.4f\n" +
" %10.4f %10.4f %10.4f %10.4f\n" +
" %10.4f %10.4f %10.4f %10.4f\n" +
" %10.4f %10.4f %10.4f %10.4f ]\n",
m.elements[0],m.elements[4],m.elements[ 8],m.elements[12],
m.elements[1],m.elements[5],m.elements[ 9],m.elements[13],
m.elements[2],m.elements[6],m.elements[10],m.elements[14],
m.elements[3],m.elements[7],m.elements[11],m.elements[15]));
},
showVector3: function(name, v) {
console.log(sprintf("%s = [ %10.4f, %10.4f, %10.4f ]",
name, v.x, v.y, v.z));
},
showVector4: function(name, v) {
console.log(sprintf("%s = [ %10.4f, %10.4f, %10.4f, %10.4f ]",
name, v.x, v.y, v.z, v.w));
},
showScreenCoords: function(msg, x,y,z) {
var S = (world.matrixWorld.clone()
.multiply((new THREE.Matrix4()).getInverse(camera.matrixWorld))
.multiply(camera.projectionMatrix));
var v = (new THREE.Vector3(x,y,z)).applyMatrix4(S);
console.log(sprintf("%s [%10.4f, %10.4f, %10.4f] => [%10.4f, %10.4f, %10.4f]",
msg, x, y, z, v.x, v.y, v.z));
}
};