Skip to content

Commit 4bef33e

Browse files
committed
Matrix naming fix
1 parent dfd1e80 commit 4bef33e

File tree

6 files changed

+707
-506
lines changed

6 files changed

+707
-506
lines changed

CSMath/Matrix3.cs

Lines changed: 111 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -27,76 +27,153 @@ public partial struct Matrix3
2727
/// <summary>
2828
/// Value at column 0, row 0 of the matrix.
2929
/// </summary>
30-
public double m00;
30+
public double M00;
3131
/// <summary>
3232
/// Value at column 0, row 1 of the matrix.
3333
/// </summary>
34-
public double m01;
34+
public double M01;
3535
/// <summary>
3636
/// Value at column 0, row 2 of the matrix.
3737
/// </summary>
38-
public double m02;
38+
public double M02;
3939

4040
/// <summary>
4141
/// Value at column 1, row 0 of the matrix.
4242
/// </summary>
43-
public double m10;
43+
public double M10;
4444
/// <summary>
4545
/// Value at column 1, row 1 of the matrix.
4646
/// </summary>
47-
public double m11;
47+
public double M11;
4848
/// <summary>
4949
/// Value at column 1, row 2 of the matrix.
5050
/// </summary>
51-
public double m12;
51+
public double M12;
5252

5353
/// <summary>
5454
/// Value at column 2, row 0 of the matrix.
5555
/// </summary>
56-
public double m20;
56+
public double M20;
5757
/// <summary>
5858
/// Value at column 2, row 1 of the matrix.
5959
/// </summary>
60-
public double m21;
60+
public double M21;
6161
/// <summary>
6262
/// Value at column 2, row 2 of the matrix.
6363
/// </summary>
64-
public double m22;
64+
public double M22;
6565

6666
#endregion Public Fields
6767

68+
public double this[int index]
69+
{
70+
get
71+
{
72+
switch (index)
73+
{
74+
case 0:
75+
return this.M00;
76+
case 1:
77+
return this.M01;
78+
case 2:
79+
return this.M02;
80+
case 3:
81+
return this.M10;
82+
case 4:
83+
return this.M11;
84+
case 5:
85+
return this.M12;
86+
case 6:
87+
return this.M20;
88+
case 7:
89+
return this.M21;
90+
case 8:
91+
return this.M22;
92+
default:
93+
throw new IndexOutOfRangeException();
94+
}
95+
}
96+
set
97+
{
98+
switch (index)
99+
{
100+
case 0:
101+
this.M00 = value;
102+
break;
103+
case 1:
104+
this.M01 = value;
105+
break;
106+
case 2:
107+
this.M02 = value;
108+
break;
109+
case 3:
110+
this.M10 = value;
111+
break;
112+
case 4:
113+
this.M11 = value;
114+
break;
115+
case 5:
116+
this.M12 = value;
117+
break;
118+
case 6:
119+
this.M20 = value;
120+
break;
121+
case 7:
122+
this.M21 = value;
123+
break;
124+
case 8:
125+
this.M22 = value;
126+
break;
127+
default:
128+
throw new IndexOutOfRangeException();
129+
}
130+
}
131+
}
132+
133+
public double this[int column, int row]
134+
{
135+
get
136+
{
137+
return this[(column * 3) + row];
138+
}
139+
set
140+
{
141+
this[(column * 3) + row] = value;
142+
}
143+
}
144+
68145
public Matrix3(
69146
double m00, double m10, double m20,
70147
double m01, double m11, double m21,
71148
double m02, double m12, double m22)
72149
{
73150
//Col 0
74-
this.m00 = m00;
75-
this.m01 = m01;
76-
this.m02 = m02;
151+
this.M00 = m00;
152+
this.M01 = m01;
153+
this.M02 = m02;
77154

78155
//Col 1
79-
this.m10 = m10;
80-
this.m11 = m11;
81-
this.m12 = m12;
156+
this.M10 = m10;
157+
this.M11 = m11;
158+
this.M12 = m12;
82159

83160
//Col 2
84-
this.m20 = m20;
85-
this.m21 = m21;
86-
this.m22 = m22;
161+
this.M20 = m20;
162+
this.M21 = m21;
163+
this.M22 = m22;
87164
}
88165

89166
public Matrix3(Matrix4 matrix)
90167
{
91-
this.m00 = matrix.m00;
92-
this.m01 = matrix.m01;
93-
this.m02 = matrix.m02;
94-
this.m10 = matrix.m10;
95-
this.m11 = matrix.m11;
96-
this.m12 = matrix.m12;
97-
this.m20 = matrix.m20;
98-
this.m21 = matrix.m21;
99-
this.m22 = matrix.m22;
168+
this.M00 = matrix.M00;
169+
this.M01 = matrix.M01;
170+
this.M02 = matrix.M02;
171+
this.M10 = matrix.M10;
172+
this.M11 = matrix.M11;
173+
this.M12 = matrix.M12;
174+
this.M20 = matrix.M20;
175+
this.M21 = matrix.M21;
176+
this.M22 = matrix.M22;
100177
}
101178

102179
/// <summary>
@@ -105,9 +182,9 @@ public Matrix3(Matrix4 matrix)
105182
/// <returns>Transpose matrix.</returns>
106183
public Matrix3 Transpose()
107184
{
108-
return new Matrix3(this.m00, this.m10, this.m20,
109-
this.m01, this.m11, this.m21,
110-
this.m02, this.m12, this.m22);
185+
return new Matrix3(this.M00, this.M10, this.M20,
186+
this.M01, this.M11, this.M21,
187+
this.M02, this.M12, this.M22);
111188
}
112189

113190
/// <summary>
@@ -165,10 +242,10 @@ public override string ToString()
165242
{
166243
string separator = Thread.CurrentThread.CurrentCulture.TextInfo.ListSeparator;
167244
StringBuilder s = new StringBuilder();
168-
s.Append(string.Format("|{0}{2} {0}{2} {1}|" + Environment.NewLine, this.m00, this.m01, this.m02, separator));
169-
s.Append(string.Format("|{0}{2} {0}{2} {1}|" + Environment.NewLine, this.m10, this.m11, this.m12, separator));
170-
s.Append(string.Format("|{0}{2} {0}{2} {1}|", this.m20, this.m21, this.m22, separator));
245+
s.Append(string.Format("|{0}{2} {0}{2} {1}|" + Environment.NewLine, this.M00, this.M01, this.M02, separator));
246+
s.Append(string.Format("|{0}{2} {0}{2} {1}|" + Environment.NewLine, this.M10, this.M11, this.M12, separator));
247+
s.Append(string.Format("|{0}{2} {0}{2} {1}|", this.M20, this.M21, this.M22, separator));
171248
return s.ToString();
172249
}
173250
}
174-
}
251+
}

CSMath/Matrix3.operators.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ public partial struct Matrix3
44
{
55
public static XYZ operator *(Matrix3 matrix, XYZ value)
66
{
7-
return new XYZ(matrix.m00 * value.X + matrix.m01 * value.Y + matrix.m02 * value.Z,
8-
matrix.m10 * value.X + matrix.m11 * value.Y + matrix.m12 * value.Z,
9-
matrix.m20 * value.X + matrix.m21 * value.Y + matrix.m22 * value.Z);
7+
return new XYZ(matrix.M00 * value.X + matrix.M01 * value.Y + matrix.M02 * value.Z,
8+
matrix.M10 * value.X + matrix.M11 * value.Y + matrix.M12 * value.Z,
9+
matrix.M20 * value.X + matrix.M21 * value.Y + matrix.M22 * value.Z);
1010
}
1111

1212
public static Matrix3 operator *(Matrix3 a, Matrix3 b)
1313
{
14-
return new Matrix3(a.m00 * b.m00 + a.m01 * b.m10 + a.m02 * b.m20, a.m00 * b.m01 + a.m01 * b.m11 + a.m02 * b.m21, a.m00 * b.m02 + a.m01 * b.m12 + a.m02 * b.m22,
15-
a.m10 * b.m00 + a.m11 * b.m10 + a.m12 * b.m20, a.m10 * b.m01 + a.m11 * b.m11 + a.m12 * b.m21, a.m10 * b.m02 + a.m11 * b.m12 + a.m12 * b.m22,
16-
a.m20 * b.m00 + a.m21 * b.m10 + a.m22 * b.m20, a.m20 * b.m01 + a.m21 * b.m11 + a.m22 * b.m21, a.m20 * b.m02 + a.m21 * b.m12 + a.m22 * b.m22);
14+
return new Matrix3(a.M00 * b.M00 + a.M01 * b.M10 + a.M02 * b.M20, a.M00 * b.M01 + a.M01 * b.M11 + a.M02 * b.M21, a.M00 * b.M02 + a.M01 * b.M12 + a.M02 * b.M22,
15+
a.M10 * b.M00 + a.M11 * b.M10 + a.M12 * b.M20, a.M10 * b.M01 + a.M11 * b.M11 + a.M12 * b.M21, a.M10 * b.M02 + a.M11 * b.M12 + a.M12 * b.M22,
16+
a.M20 * b.M00 + a.M21 * b.M10 + a.M22 * b.M20, a.M20 * b.M01 + a.M21 * b.M11 + a.M22 * b.M21, a.M20 * b.M02 + a.M21 * b.M12 + a.M22 * b.M22);
1717
}
1818
}
1919
}

CSMath/Matrix4.Operators.cs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,22 @@ public static Matrix4 Multiply(Matrix4 a, Matrix4 b)
1616
var rows = a.GetRows();
1717
var cols = b.GetCols();
1818

19-
result.m00 = rows[0].Dot(cols[0]);
20-
result.m10 = rows[0].Dot(cols[1]);
21-
result.m20 = rows[0].Dot(cols[2]);
22-
result.m30 = rows[0].Dot(cols[3]);
23-
result.m01 = rows[1].Dot(cols[0]);
24-
result.m11 = rows[1].Dot(cols[1]);
25-
result.m21 = rows[1].Dot(cols[2]);
26-
result.m31 = rows[1].Dot(cols[3]);
27-
result.m02 = rows[2].Dot(cols[0]);
28-
result.m12 = rows[2].Dot(cols[1]);
29-
result.m22 = rows[2].Dot(cols[2]);
30-
result.m32 = rows[2].Dot(cols[3]);
31-
result.m03 = rows[3].Dot(cols[0]);
32-
result.m13 = rows[3].Dot(cols[1]);
33-
result.m23 = rows[3].Dot(cols[2]);
34-
result.m33 = rows[3].Dot(cols[3]);
19+
result.M00 = rows[0].Dot(cols[0]);
20+
result.M10 = rows[0].Dot(cols[1]);
21+
result.M20 = rows[0].Dot(cols[2]);
22+
result.M30 = rows[0].Dot(cols[3]);
23+
result.M01 = rows[1].Dot(cols[0]);
24+
result.M11 = rows[1].Dot(cols[1]);
25+
result.M21 = rows[1].Dot(cols[2]);
26+
result.M31 = rows[1].Dot(cols[3]);
27+
result.M02 = rows[2].Dot(cols[0]);
28+
result.M12 = rows[2].Dot(cols[1]);
29+
result.M22 = rows[2].Dot(cols[2]);
30+
result.M32 = rows[2].Dot(cols[3]);
31+
result.M03 = rows[3].Dot(cols[0]);
32+
result.M13 = rows[3].Dot(cols[1]);
33+
result.M23 = rows[3].Dot(cols[2]);
34+
result.M33 = rows[3].Dot(cols[3]);
3535

3636
return result;
3737
}
@@ -71,10 +71,10 @@ public static Matrix4 Multiply(Matrix4 a, Matrix4 b)
7171
public static XYZM operator *(Matrix4 matrix, XYZM v)
7272
{
7373
return new XYZM(
74-
matrix.m00 * v.X + matrix.m10 * v.Y + matrix.m20 * v.Z + matrix.m30 * v.M,
75-
matrix.m01 * v.X + matrix.m11 * v.Y + matrix.m21 * v.Z + matrix.m31 * v.M,
76-
matrix.m02 * v.X + matrix.m12 * v.Y + matrix.m22 * v.Z + matrix.m32 * v.M,
77-
matrix.m03 * v.X + matrix.m13 * v.Y + matrix.m23 * v.Z + matrix.m33 * v.M);
74+
matrix.M00 * v.X + matrix.M10 * v.Y + matrix.M20 * v.Z + matrix.M30 * v.M,
75+
matrix.M01 * v.X + matrix.M11 * v.Y + matrix.M21 * v.Z + matrix.M31 * v.M,
76+
matrix.M02 * v.X + matrix.M12 * v.Y + matrix.M22 * v.Z + matrix.M32 * v.M,
77+
matrix.M03 * v.X + matrix.M13 * v.Y + matrix.M23 * v.Z + matrix.M33 * v.M);
7878
}
7979
}
8080
}

0 commit comments

Comments
 (0)