Added Mat4.makeRotationAxis.

This commit is contained in:
Richard Davey 2017-09-20 16:51:06 +01:00
parent c48501b4ec
commit 6aae306aa0

View file

@ -400,6 +400,30 @@ var Matrix4 = new Class({
return this;
},
// Axis = vec3, angle = radians
makeRotationAxis: function (axis, angle)
{
// Based on http://www.gamedev.net/reference/articles/article1199.asp
var c = Math.cos(angle);
var s = Math.sin(angle);
var t = 1 - c;
var x = axis.x;
var y = axis.y;
var z = axis.z;
var tx = t * x;
var ty = t * y;
this.set(
tx * x + c, tx * y - s * z, tx * z + s * y, 0,
tx * y + s * z, ty * y + c, ty * z - s * x, 0,
tx * z - s * y, ty * z + s * x, t * z * z + c, 0,
0, 0, 0, 1
);
return this;
},
rotate: function (rad, axis)
{
var a = this.val;