Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Z64Utils/Common/ArrayUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ namespace Common
{
class ArrayUtil
{
public static int ReadInt32BE(byte[] data, int offset = 0)
{
byte[] buff = new byte[sizeof(int)];
Buffer.BlockCopy(data, offset, buff, 0, sizeof(int));
return BitConverter.ToInt32(buff.Reverse().ToArray(), 0);
}
public static uint ReadUint32BE(byte[] data, int offset = 0)
{
byte[] buff = new byte[sizeof(uint)];
Expand Down
26 changes: 22 additions & 4 deletions Z64Utils/Forms/ObjectAnalyzerForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,19 +244,37 @@ private void listView_map_SelectedIndexChanged(object sender, EventArgs e)
StringWriter sw = new StringWriter();
for (int n = 0; n < matrices.Matrices.Count; n++)
{
sw.WriteLine($" ┌ ┐ ");
var mtx = new Mtx(matrices.Matrices[n].GetBuffer()).ToMatrix4();
string[,] mtxStr = new string[4, 4];
int[] columnsWidth = { 0, 0, 0, 0 };
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{
float val = mtx[j, i]; // Matrix4 uses column-major order
string valStr = $"{val}";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Printing the floats only up to the precision necessary for the fixed point range should make things nicer, i.e. Matrix_CheckFloats elects to print the floats as 12.6f in printf notation, although I think it should really be 13.6 as 12.6 fails to account for negative floats with 5-digit integer part (such large numbers likely will never come up in practice however). I'm not sure what the equivalent is in C# interpolated strings.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In decimal,
the smallest positive s16.16 number is 1/0x10000 = 0.0000152587890625
the smallest s16.16 number is 0x80000000/0x10000 = -32768
and the largest is 0x7FFFFFFF/0x10000 = 32767.9999847412109375

so that's 5.16f maybe? and I don't know how it works in C# either. Microsoft probably thought it was funny to make up their own format strings

Copy link
Contributor Author

@Dragorn421 Dragorn421 Sep 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rereading this,

the smallest positive s16.16 number is 1/0x10000 = 0.0000152587890625

absolutely doesn't mean we need 16 digits, but only 5 (for the decimal part)

idk still about this, it's not like there isn't enough space in Z64Utils to show whatever useless digits

mtxStr[i,j] = valStr;
columnsWidth[j] = Math.Max(valStr.Length, columnsWidth[j]);
}
}

string columnSeparator = " ";
int w = 3 * columnSeparator.Length;
for (int j = 0; j < 4; j++)
w += columnsWidth[j];
sw.WriteLine(" ┌ " + new string(' ', w) + " ┐ ");
for (int i = 0; i < 4; i++)
{
var values = "";
for (int j = 0; j < 4; j++)
{
values += $"0x{ArrayUtil.ReadUint32BE(matrices.Matrices[n].GetBuffer(), 4*(4 * i + j)):X08}";
values += mtxStr[i, j].PadLeft(columnsWidth[j]);
if (j != 3)
values += $" ";
values += columnSeparator;
}
sw.WriteLine($" │ {values} │ ");
}
sw.WriteLine($" └ ┘ ");
sw.WriteLine(" └ " + new string(' ', w) + " ┘ ");
}
textBox_holderInfo.Text = sw.ToString();
break;
Expand Down