Skip to content

Commit 6aae306

Browse files
committed
Added Mat4.makeRotationAxis.
1 parent c48501b commit 6aae306

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

v3/src/math/Matrix4.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,30 @@ var Matrix4 = new Class({
400400
return this;
401401
},
402402

403+
// Axis = vec3, angle = radians
404+
makeRotationAxis: function (axis, angle)
405+
{
406+
// Based on http://www.gamedev.net/reference/articles/article1199.asp
407+
408+
var c = Math.cos(angle);
409+
var s = Math.sin(angle);
410+
var t = 1 - c;
411+
var x = axis.x;
412+
var y = axis.y;
413+
var z = axis.z;
414+
var tx = t * x;
415+
var ty = t * y;
416+
417+
this.set(
418+
tx * x + c, tx * y - s * z, tx * z + s * y, 0,
419+
tx * y + s * z, ty * y + c, ty * z - s * x, 0,
420+
tx * z - s * y, ty * z + s * x, t * z * z + c, 0,
421+
0, 0, 0, 1
422+
);
423+
424+
return this;
425+
},
426+
403427
rotate: function (rad, axis)
404428
{
405429
var a = this.val;

0 commit comments

Comments
 (0)