On 05.05.2013 23:01, Nozomi Kodama wrote:
+ FLOAT xw, xx, xy, xz, yw, yy, yz, zw, zz;
I'm not very happy with the additional amount of variables...
Please have a look at the attached patches. I think something like the
first one (d3dx9: Apply rotationcenter only when a rotation is done.)
should be done but has no influence on your patch (it is only attached,
because the second patch influences the same part).
1. The amount of variables needed could be reduced to 3 by reordering
the calculations (see patch 2, lines 36 - 58). This could also be done
in your patch. Though I'm not sure that's a good idea ... comments and
other opinions are welcome.
Below this the points are not directly related to your patch:
2. In the next step we could also avoid a couple of multiplications by
multiplying the scaling and adjusting the constants (see patch 2, lines
70 - 79).
3. We could also avoid the temps by reordering the calculation (Doing
rotationcenter before the scaling). This way the tempxx could be avoided
by using the out matrix directly.
Cheers
Rico
commit 46c6ed6d9a6950d733652072774e7b01c0277584
Author: Rico Schüller <kgbric...@web.de>
Date: Mon May 6 10:47:44 2013 +0200
d3dx9: Apply rotationcenter only when a rotation is done.
diff --git a/dlls/d3dx9_36/math.c b/dlls/d3dx9_36/math.c
index 43911e9..abecf40 100644
--- a/dlls/d3dx9_36/math.c
+++ b/dlls/d3dx9_36/math.c
@@ -102,13 +102,6 @@ D3DXMATRIX * WINAPI D3DXMatrixAffineTransformation(D3DXMATRIX *out, FLOAT scalin
D3DXMatrixIdentity(out);
- if (rotationcenter)
- {
- out->u.m[3][0] = -rotationcenter->x;
- out->u.m[3][1] = -rotationcenter->y;
- out->u.m[3][2] = -rotationcenter->z;
- }
-
if (rotation)
{
FLOAT temp00, temp01, temp02, temp10, temp11, temp12, temp20, temp21, temp22;
@@ -135,15 +128,9 @@ D3DXMATRIX * WINAPI D3DXMatrixAffineTransformation(D3DXMATRIX *out, FLOAT scalin
if (rotationcenter)
{
- FLOAT x, y, z;
-
- x = out->u.m[3][0];
- y = out->u.m[3][1];
- z = out->u.m[3][2];
-
- out->u.m[3][0] = x * temp00 + y * temp10 + z * temp20;
- out->u.m[3][1] = x * temp01 + y * temp11 + z * temp21;
- out->u.m[3][2] = x * temp02 + y * temp12 + z * temp22;
+ out->u.m[3][0] = rotationcenter->x * (1 - temp00) - rotationcenter->y * temp10 - rotationcenter->z * temp20;
+ out->u.m[3][1] = rotationcenter->y * (1 - temp11) - rotationcenter->x * temp01 - rotationcenter->z * temp21;
+ out->u.m[3][2] = rotationcenter->z * (1 - temp22) - rotationcenter->x * temp02 - rotationcenter->y * temp12;
}
}
else
@@ -153,13 +140,6 @@ D3DXMATRIX * WINAPI D3DXMatrixAffineTransformation(D3DXMATRIX *out, FLOAT scalin
out->u.m[2][2] = scaling;
}
- if (rotationcenter)
- {
- out->u.m[3][0] += rotationcenter->x;
- out->u.m[3][1] += rotationcenter->y;
- out->u.m[3][2] += rotationcenter->z;
- }
-
if (translation)
{
out->u.m[3][0] += translation->x;
commit 78dfc1e21da759860038d1b965d644fffe845cdb
Author: Rico Schüller <kgbric...@web.de>
Date: Mon May 6 12:10:29 2013 +0200
d3dx9: Avoid useless computations in D3DXMatrixAffineTransformation().
diff --git a/dlls/d3dx9_36/math.c b/dlls/d3dx9_36/math.c
index abecf40..abd5dac 100644
--- a/dlls/d3dx9_36/math.c
+++ b/dlls/d3dx9_36/math.c
@@ -104,34 +104,47 @@ D3DXMATRIX * WINAPI D3DXMatrixAffineTransformation(D3DXMATRIX *out, FLOAT scalin
if (rotation)
{
- FLOAT temp00, temp01, temp02, temp10, temp11, temp12, temp20, temp21, temp22;
-
- temp00 = 1.0f - 2.0f * (rotation->y * rotation->y + rotation->z * rotation->z);
- temp01 = 2.0f * (rotation->x * rotation->y + rotation->z * rotation->w);
- temp02 = 2.0f * (rotation->x * rotation->z - rotation->y * rotation->w);
- temp10 = 2.0f * (rotation->x * rotation->y - rotation->z * rotation->w);
- temp11 = 1.0f - 2.0f * (rotation->x * rotation->x + rotation->z * rotation->z);
- temp12 = 2.0f * (rotation->y * rotation->z + rotation->x * rotation->w);
- temp20 = 2.0f * (rotation->x * rotation->z + rotation->y * rotation->w);
- temp21 = 2.0f * (rotation->y * rotation->z - rotation->x * rotation->w);
- temp22 = 1.0f - 2.0f * (rotation->x * rotation->x + rotation->y * rotation->y);
-
- out->u.m[0][0] = scaling * temp00;
- out->u.m[0][1] = scaling * temp01;
- out->u.m[0][2] = scaling * temp02;
- out->u.m[1][0] = scaling * temp10;
- out->u.m[1][1] = scaling * temp11;
- out->u.m[1][2] = scaling * temp12;
- out->u.m[2][0] = scaling * temp20;
- out->u.m[2][1] = scaling * temp21;
- out->u.m[2][2] = scaling * temp22;
+ FLOAT t1, t2, t3;
+
+ t1 = rotation->x * rotation->x;
+ t2 = rotation->y * rotation->y;
+ t3 = rotation->z * rotation->z;
+ out->u.m[0][0] = t2 + t3;
+ out->u.m[2][2] = t1 + t2;
+ out->u.m[1][1] = t1 + t3;
+
+ t1 = rotation->x * rotation->y;
+ t2 = rotation->z * rotation->w;
+ out->u.m[0][1] = t1 + t2;
+ out->u.m[1][0] = t1 - t2;
+
+ t1 = rotation->x * rotation->z;
+ t2 = rotation->y * rotation->w;
+ out->u.m[2][0] = t1 + t2;
+ out->u.m[0][2] = t1 - t2;
+
+ t1 = rotation->y * rotation->z;
+ t2 = rotation->x * rotation->w;
+ out->u.m[1][2] = t1 + t2;
+ out->u.m[2][1] = t1 - t2;
if (rotationcenter)
{
- out->u.m[3][0] = rotationcenter->x * (1 - temp00) - rotationcenter->y * temp10 - rotationcenter->z * temp20;
- out->u.m[3][1] = rotationcenter->y * (1 - temp11) - rotationcenter->x * temp01 - rotationcenter->z * temp21;
- out->u.m[3][2] = rotationcenter->z * (1 - temp22) - rotationcenter->x * temp02 - rotationcenter->y * temp12;
+ out->u.m[3][0] = 2.0f * (rotationcenter->x * out->u.m[0][0] - rotationcenter->y * out->u.m[1][0] - rotationcenter->z * out->u.m[2][0]);
+ out->u.m[3][1] = 2.0f * (rotationcenter->y * out->u.m[1][1] - rotationcenter->x * out->u.m[0][1] - rotationcenter->z * out->u.m[2][1]);
+ out->u.m[3][2] = 2.0f * (rotationcenter->z * out->u.m[2][2] - rotationcenter->x * out->u.m[0][2] - rotationcenter->y * out->u.m[1][2]);
}
+
+ scaling = scaling * 2.0f;
+ out->u.m[0][0] = scaling * (0.5f - out->u.m[0][0]);
+ out->u.m[0][1] *= scaling;
+ out->u.m[0][2] *= scaling;
+ out->u.m[1][0] *= scaling;
+ out->u.m[1][1] = scaling * (0.5f - out->u.m[1][1]);
+ out->u.m[1][2] *= scaling;
+ out->u.m[2][0] *= scaling;
+ out->u.m[2][1] *= scaling;
+ out->u.m[2][2] = scaling * (0.5f - out->u.m[2][2]);
}
else
{