From 4df411d95afef5136cf1fa41d2dbfc012c544254 Mon Sep 17 00:00:00 2001 From: vrld Date: Sun, 2 Jan 2011 22:44:19 +0100 Subject: [PATCH] Faster Matrix::setTransformation --- src/common/Matrix.cpp | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/common/Matrix.cpp b/src/common/Matrix.cpp index 45799664f..d9e15294d 100644 --- a/src/common/Matrix.cpp +++ b/src/common/Matrix.cpp @@ -118,12 +118,21 @@ namespace love void Matrix::setTransformation(float x, float y, float angle, float sx, float sy, float ox, float oy) { - // TODO: This works fine, but should consider speeding this up a little. - setIdentity(); - translate(x, y); - rotate(angle); - scale(sx, sy); - translate(-ox, -oy); + memset(e, 0, sizeof(float)*16); // zero out matrix + float c = cos(angle), s = sin(angle); + // matrix multiplication carried out on paper: + // |1 x| |c -s | |sx | |1 -ox| + // | 1 y| |s c | | sy | | 1 -oy| + // | 1 | | 1 | | 1 | | 1 | + // | 1| | 1| | 1| | 1 | + // move rotate scale origin + e[10] = e[15] = 1.0f; + e[0] = sx * c; + e[1] = sx * s; + e[4] = -sy * s; + e[5] = sy * c; + e[12] = -ox * e[0] - oy * e[4] + x; + e[13] = -ox * e[1] - oy * e[5] + y; } void Matrix::translate(float x, float y)