-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMatrix.cs
105 lines (95 loc) · 2.82 KB
/
Matrix.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// Decompiled with JetBrains decompiler
// Type: DK64Viewer.Matrix
// Assembly: DK64Viewer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: 34C2999C-2061-412A-B2F3-E6D2C8F1D38B
// Assembly location: F:\DKViewer_0.04a\DK64Viewer.exe
using System;
namespace DK64Viewer
{
public class Matrix
{
public float[,] matrix;
public int rows;
public int cols;
public Matrix(int rows, int cols)
{
this.matrix = new float[rows, cols];
this.rows = rows;
this.cols = cols;
}
public Matrix(float[,] matrix)
{
this.matrix = matrix;
this.rows = matrix.GetLength(0);
this.cols = matrix.GetLength(1);
}
public float[] ToGLMatrix()
{
float[] glMatrix = new float[16];
int index1 = 0;
for (int index2 = 0; index2 < this.cols; ++index2)
{
for (int index3 = 0; index3 < this.rows; ++index3)
{
glMatrix[index1] = this.matrix[index3, index2];
++index1;
}
}
return glMatrix;
}
protected static float[,] Multiply(Matrix matrix, float scalar)
{
int rows = matrix.rows;
int cols = matrix.cols;
float[,] matrix1 = matrix.matrix;
float[,] numArray = new float[rows, cols];
for (int index1 = 0; index1 < rows; ++index1)
{
for (int index2 = 0; index2 < cols; ++index2)
numArray[index1, index2] = matrix1[index1, index2] * scalar;
}
return numArray;
}
protected static float[,] Multiply(Matrix matrix1, Matrix matrix2)
{
int rows1 = matrix1.rows;
int cols1 = matrix1.cols;
int rows2 = matrix2.rows;
int cols2 = matrix2.cols;
if (cols1 != rows2)
throw new ArgumentException();
float[,] matrix3 = matrix1.matrix;
float[,] matrix4 = matrix2.matrix;
float[,] numArray = new float[rows1, cols2];
for (int index1 = 0; index1 < rows1; ++index1)
{
for (int index2 = 0; index2 < cols2; ++index2)
{
float num = 0.0f;
for (int index3 = 0; index3 < cols1; ++index3)
num += matrix3[index1, index3] * matrix4[index3, index2];
numArray[index1, index2] = num;
}
}
return numArray;
}
public static Matrix operator *(Matrix m, float scalar) => new Matrix(Matrix.Multiply(m, scalar));
public static Matrix operator *(Matrix m1, Matrix m2) => new Matrix(Matrix.Multiply(m1, m2));
public override string ToString()
{
string str = "";
for (int index1 = 0; index1 < this.rows; ++index1)
{
if (index1 > 0)
str += "|";
for (int index2 = 0; index2 < this.cols; ++index2)
{
if (index2 > 0)
str += ",";
str += (string) (object) this.matrix[index1, index2];
}
}
return "(" + str + ")";
}
}
}