Move MakeFloatMatrix to Graphics.Util.

This commit is contained in:
Paul Chote
2013-06-08 18:19:23 +12:00
parent 5f0ab1f62d
commit 4152f61999
2 changed files with 11 additions and 11 deletions

View File

@@ -231,6 +231,14 @@ namespace OpenRA.Graphics
return mtx; return mtx;
} }
public static float[] MakeFloatMatrix(int[] imtx)
{
var fmtx = new float[16];
for (var i = 0; i < 16; i++)
fmtx[i] = imtx[i]*1f / imtx[15];
return fmtx;
}
public static float[] MatrixAABBMultiply(float[] mtx, float[] bounds) public static float[] MatrixAABBMultiply(float[] mtx, float[] bounds)
{ {
// Corner offsets // Corner offsets

View File

@@ -76,14 +76,6 @@ namespace OpenRA.Graphics
return tVec; return tVec;
} }
static float[] MakeFloatMatrix(int[] imtx)
{
var fmtx = new float[16];
for (var i = 0; i < 16; i++)
fmtx[i] = imtx[i]*1f / imtx[15];
return fmtx;
}
public void Draw(VoxelRenderer r, float[] lightAmbientColor, float[] lightDiffuseColor, public void Draw(VoxelRenderer r, float[] lightAmbientColor, float[] lightDiffuseColor,
int colorPalette, int normalsPalette) int colorPalette, int normalsPalette)
{ {
@@ -125,8 +117,8 @@ namespace OpenRA.Graphics
var pxPos = wr.ScreenPosition(pos); var pxPos = wr.ScreenPosition(pos);
var posMtx = Util.TranslationMatrix(pxPos.X, pxPos.Y, pxPos.Y); var posMtx = Util.TranslationMatrix(pxPos.X, pxPos.Y, pxPos.Y);
var scaleMtx = Util.ScaleMatrix(scale, scale, scale); var scaleMtx = Util.ScaleMatrix(scale, scale, scale);
var rotMtx = rotations.Reverse().Aggregate(MakeFloatMatrix(camera.AsMatrix()), var rotMtx = rotations.Reverse().Aggregate(Util.MakeFloatMatrix(camera.AsMatrix()),
(a,b) => Util.MatrixMultiply(a, MakeFloatMatrix(b.AsMatrix()))); (a,b) => Util.MatrixMultiply(a, Util.MakeFloatMatrix(b.AsMatrix())));
// Each limb has its own transformation matrix // Each limb has its own transformation matrix
for (uint i = 0; i < limbs.Length; i++) for (uint i = 0; i < limbs.Length; i++)
@@ -137,7 +129,7 @@ namespace OpenRA.Graphics
transform[i] = Util.MatrixMultiply(posMtx, transform[i]); transform[i] = Util.MatrixMultiply(posMtx, transform[i]);
// Transform light direction into limb-space // Transform light direction into limb-space
var undoPitch = MakeFloatMatrix(new WRot(camera.Pitch, WAngle.Zero, WAngle.Zero).AsMatrix()); var undoPitch = Util.MakeFloatMatrix(new WRot(camera.Pitch, WAngle.Zero, WAngle.Zero).AsMatrix());
var lightTransform = Util.MatrixMultiply(Util.MatrixInverse(transform[i]), undoPitch); var lightTransform = Util.MatrixMultiply(Util.MatrixInverse(transform[i]), undoPitch);
lightDirection[i] = ExtractRotationVector(lightTransform, forward.Rotate(lightSource)); lightDirection[i] = ExtractRotationVector(lightTransform, forward.Rotate(lightSource));