Quad117
Quad117

Reputation: 17

Creating rotation matrix

I need to create a rotation function that will be used to rotate items around, it nearly works apart from when trying to do -sin. There doesnt seem to be a function that allows this.

Rotation matrix

Matrix.createRotation = function (rotation) {

    return new Matrix(Math.cos(rotation),  Math.sin(rotation), 0,
        Math.sin(rotation), Math.cos(rotation), 0, 0, 0, 1);
};

Upvotes: 0

Views: 848

Answers (1)

plasmacel
plasmacel

Reputation: 8530

You have to negate the result of Math.sin(rotation) as -Math.sin(rotation):

Matrix.createRotation = function (rotation)
{ 
    return new Matrix(
        Math.cos(rotation), -Math.sin(rotation), 0,
        Math.sin(rotation), Math.cos(rotation), 0,
        0, 0, 1
    );
};

Note that -Math.sin(rotation) is faster than (-1)*Math.sin(rotation).

Upvotes: 1

Related Questions