This repository was archived by the owner on Feb 25, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathMatrix4x4Node.cs
More file actions
488 lines (445 loc) · 19.3 KB
/
Matrix4x4Node.cs
File metadata and controls
488 lines (445 loc) · 19.3 KB
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Numerics;
using Windows.UI.Composition;
namespace Microsoft.Toolkit.Uwp.UI.Animations.Expressions
{
// Ignore warning: 'Matrix4x4Node' defines operator == or operator != but does not override Object.Equals(object o) && Object.GetHashCode()
#pragma warning disable CS0660, CS0661
/// <summary>
/// Class Matrix4x4Node. This class cannot be inherited.
/// </summary>
/// <seealso cref="Microsoft.Toolkit.Uwp.UI.Animations.Expressions.ExpressionNode" />
public sealed partial class Matrix4x4Node : ExpressionNode
{
/// <summary>
/// Initializes a new instance of the <see cref="Matrix4x4Node"/> class.
/// </summary>
internal Matrix4x4Node()
{
}
/// <summary>
/// Initializes a new instance of the <see cref="Matrix4x4Node"/> class.
/// </summary>
/// <param name="value">The value.</param>
internal Matrix4x4Node(Matrix4x4 value)
{
_value = value;
NodeType = ExpressionNodeType.ConstantValue;
}
/// <summary>
/// Initializes a new instance of the <see cref="Matrix4x4Node"/> class.
/// </summary>
/// <param name="paramName">Name of the parameter.</param>
internal Matrix4x4Node(string paramName)
{
ParamName = paramName;
NodeType = ExpressionNodeType.ConstantParameter;
}
/// <summary>
/// Initializes a new instance of the <see cref="Matrix4x4Node"/> class.
/// </summary>
/// <param name="paramName">Name of the parameter.</param>
/// <param name="value">The value.</param>
internal Matrix4x4Node(string paramName, Matrix4x4 value)
{
ParamName = paramName;
_value = value;
NodeType = ExpressionNodeType.ConstantParameter;
SetMatrix4x4Parameter(paramName, value);
}
/// <summary>
/// Performs an implicit conversion from <see cref="Matrix4x4"/> to <see cref="Matrix4x4Node"/>.
/// </summary>
/// <param name="value">The value.</param>
/// <returns>The result of the conversion.</returns>
public static implicit operator Matrix4x4Node(Matrix4x4 value)
{
return new Matrix4x4Node(value);
}
/// <summary>
/// Implements the + operator.
/// </summary>
/// <param name="left">The left.</param>
/// <param name="right">The right.</param>
/// <returns>The result of the operator.</returns>
public static Matrix4x4Node operator +(Matrix4x4Node left, Matrix4x4Node right)
{
return ExpressionFunctions.Function<Matrix4x4Node>(ExpressionNodeType.Add, left, right);
}
/// <summary>
/// Implements the - operator.
/// </summary>
/// <param name="left">The left.</param>
/// <param name="right">The right.</param>
/// <returns>The result of the operator.</returns>
public static Matrix4x4Node operator -(Matrix4x4Node left, Matrix4x4Node right)
{
return ExpressionFunctions.Function<Matrix4x4Node>(ExpressionNodeType.Subtract, left, right);
}
/// <summary>
/// Implements the - operator.
/// </summary>
/// <param name="value">The value.</param>
/// <returns>The result of the operator.</returns>
public static Matrix4x4Node operator -(Matrix4x4Node value)
{
return ExpressionFunctions.Function<Matrix4x4Node>(ExpressionNodeType.Negate, value);
}
/// <summary>
/// Implements the * operator.
/// </summary>
/// <param name="left">The left.</param>
/// <param name="right">The right.</param>
/// <returns>The result of the operator.</returns>
public static Matrix4x4Node operator *(Matrix4x4Node left, ScalarNode right)
{
return ExpressionFunctions.Function<Matrix4x4Node>(ExpressionNodeType.Multiply, left, right);
}
/// <summary>
/// Implements the * operator.
/// </summary>
/// <param name="left">The left.</param>
/// <param name="right">The right.</param>
/// <returns>The result of the operator.</returns>
public static Matrix4x4Node operator *(Matrix4x4Node left, Matrix4x4Node right)
{
return ExpressionFunctions.Function<Matrix4x4Node>(ExpressionNodeType.Multiply, left, right);
}
/// <summary>
/// Implements the == operator.
/// </summary>
/// <param name="left">The left.</param>
/// <param name="right">The right.</param>
/// <returns>The result of the operator.</returns>
public static BooleanNode operator ==(Matrix4x4Node left, Matrix4x4Node right)
{
return ExpressionFunctions.Function<BooleanNode>(ExpressionNodeType.Equals, left, right);
}
/// <summary>
/// Implements the != operator.
/// </summary>
/// <param name="left">The left.</param>
/// <param name="right">The right.</param>
/// <returns>The result of the operator.</returns>
public static BooleanNode operator !=(Matrix4x4Node left, Matrix4x4Node right)
{
return ExpressionFunctions.Function<BooleanNode>(ExpressionNodeType.NotEquals, left, right);
}
/// <summary>
/// Gets the channel11.
/// </summary>
/// <value>The channel11.</value>
public ScalarNode Channel11
{
get { return GetSubchannels(Subchannel.Channel11); }
}
/// <summary>
/// Gets the channel12.
/// </summary>
/// <value>The channel12.</value>
public ScalarNode Channel12
{
get { return GetSubchannels(Subchannel.Channel12); }
}
/// <summary>
/// Gets the channel13.
/// </summary>
/// <value>The channel13.</value>
public ScalarNode Channel13
{
get { return GetSubchannels(Subchannel.Channel13); }
}
/// <summary>
/// Gets the channel14.
/// </summary>
/// <value>The channel14.</value>
public ScalarNode Channel14
{
get { return GetSubchannels(Subchannel.Channel14); }
}
/// <summary>
/// Gets the channel21.
/// </summary>
/// <value>The channel21.</value>
public ScalarNode Channel21
{
get { return GetSubchannels(Subchannel.Channel21); }
}
/// <summary>
/// Gets the channel22.
/// </summary>
/// <value>The channel22.</value>
public ScalarNode Channel22
{
get { return GetSubchannels(Subchannel.Channel22); }
}
/// <summary>
/// Gets the channel23.
/// </summary>
/// <value>The channel23.</value>
public ScalarNode Channel23
{
get { return GetSubchannels(Subchannel.Channel23); }
}
/// <summary>
/// Gets the channel24.
/// </summary>
/// <value>The channel24.</value>
public ScalarNode Channel24
{
get { return GetSubchannels(Subchannel.Channel24); }
}
/// <summary>
/// Gets the channel31.
/// </summary>
/// <value>The channel31.</value>
public ScalarNode Channel31
{
get { return GetSubchannels(Subchannel.Channel31); }
}
/// <summary>
/// Gets the channel32.
/// </summary>
/// <value>The channel32.</value>
public ScalarNode Channel32
{
get { return GetSubchannels(Subchannel.Channel32); }
}
/// <summary>
/// Gets the channel33.
/// </summary>
/// <value>The channel33.</value>
public ScalarNode Channel33
{
get { return GetSubchannels(Subchannel.Channel33); }
}
/// <summary>
/// Gets the channel34.
/// </summary>
/// <value>The channel34.</value>
public ScalarNode Channel34
{
get { return GetSubchannels(Subchannel.Channel34); }
}
/// <summary>
/// Gets the channel41.
/// </summary>
/// <value>The channel41.</value>
public ScalarNode Channel41
{
get { return GetSubchannels(Subchannel.Channel41); }
}
/// <summary>
/// Gets the channel42.
/// </summary>
/// <value>The channel42.</value>
public ScalarNode Channel42
{
get { return GetSubchannels(Subchannel.Channel42); }
}
/// <summary>
/// Gets the channel43.
/// </summary>
/// <value>The channel43.</value>
public ScalarNode Channel43
{
get { return GetSubchannels(Subchannel.Channel43); }
}
/// <summary>
/// Gets the channel44.
/// </summary>
/// <value>The channel44.</value>
public ScalarNode Channel44
{
get { return GetSubchannels(Subchannel.Channel44); }
}
/// <summary>
/// Gets the channel11 channel22 channel33.
/// </summary>
/// <value>The channel11 channel22 channel33.</value>
public Vector3Node Channel11Channel22Channel33
{
get { return GetSubchannels(Subchannel.Channel11, Subchannel.Channel22, Subchannel.Channel33); }
}
/// <summary>
/// Gets the channel41 channel42 channel43.
/// </summary>
/// <value>The channel41 channel42 channel43.</value>
public Vector3Node Channel41Channel42Channel43
{
get { return GetSubchannels(Subchannel.Channel41, Subchannel.Channel42, Subchannel.Channel43); }
}
/// <summary>
/// Create a new type by re-arranging the Matrix subchannels.
/// </summary>
/// <param name="s">The s.</param>
/// <returns>ScalarNode.</returns>
public ScalarNode GetSubchannels(Subchannel s)
{
return SubchannelsInternal<ScalarNode>(s.ToString());
}
/// <summary>
/// Create a new type by re-arranging the Matrix subchannels.
/// </summary>
/// <param name="s1">The first subchannel.</param>
/// <param name="s2">The second subchannel.</param>
/// <returns>Vector2Node</returns>
public Vector2Node GetSubchannels(Subchannel s1, Subchannel s2)
{
return SubchannelsInternal<Vector2Node>(s1.ToString(), s2.ToString());
}
/// <summary>
/// Create a new type by re-arranging the Matrix subchannels.
/// </summary>
/// <param name="s1">The first subchannel.</param>
/// <param name="s2">The second subchannel.</param>
/// <param name="s3">The third subchannel.</param>
/// <returns>Vector3Node</returns>
public Vector3Node GetSubchannels(Subchannel s1, Subchannel s2, Subchannel s3)
{
return SubchannelsInternal<Vector3Node>(s1.ToString(), s2.ToString(), s3.ToString());
}
/// <summary>
/// Create a new type by re-arranging the Matrix subchannels.
/// </summary>
/// <param name="s1">The first subchannel.</param>
/// <param name="s2">The second subchannel.</param>
/// <param name="s3">The third subchannel.</param>
/// <param name="s4">The fourth subchannel.</param>
/// <returns>Vector4Node</returns>
public Vector4Node GetSubchannels(Subchannel s1, Subchannel s2, Subchannel s3, Subchannel s4)
{
return SubchannelsInternal<Vector4Node>(s1.ToString(), s2.ToString(), s3.ToString(), s4.ToString());
}
/// <summary>
/// Create a new type by re-arranging the Matrix subchannels.
/// </summary>
/// <param name="s1">The first subchannel.</param>
/// <param name="s2">The second subchannel.</param>
/// <param name="s3">The third subchannel.</param>
/// <param name="s4">The fourth subchannel.</param>
/// <param name="s5">The fifth subchannel.</param>
/// <param name="s6">The sixth subchannel.</param>
/// <returns>Matrix3x2Node</returns>
public Matrix3x2Node GetSubchannels(Subchannel s1, Subchannel s2, Subchannel s3, Subchannel s4, Subchannel s5, Subchannel s6)
{
return SubchannelsInternal<Matrix3x2Node>(s1.ToString(), s2.ToString(), s3.ToString(), s4.ToString(), s5.ToString(), s6.ToString());
}
/// <summary>
/// Create a new type by re-arranging the Matrix subchannels.
/// </summary>
/// <param name="s1">The first subchannel.</param>
/// <param name="s2">The second subchannel.</param>
/// <param name="s3">The third subchannel.</param>
/// <param name="s4">The fourth subchannel.</param>
/// <param name="s5">The fifth subchannel.</param>
/// <param name="s6">The sixth subchannel.</param>
/// <param name="s7">The seventh subchannel.</param>
/// <param name="s8">The eighth subchannel.</param>
/// <param name="s9">The ninth subchannel.</param>
/// <param name="s10">The tenth subchannel.</param>
/// <param name="s11">The eleventh subchannel.</param>
/// <param name="s12">The twelfth subchannel.</param>
/// <param name="s13">The thirteenth subchannel.</param>
/// <param name="s14">The fourteenth subchannel.</param>
/// <param name="s15">The fifteenth subchannel.</param>
/// <param name="s16">The sixteenth subchannel.</param>
/// <returns>Matrix4x4Node</returns>
#pragma warning disable SA1117 // Parameters must be on same line or separate lines
public Matrix4x4Node GetSubchannels(Subchannel s1, Subchannel s2, Subchannel s3, Subchannel s4,
Subchannel s5, Subchannel s6, Subchannel s7, Subchannel s8,
Subchannel s9, Subchannel s10, Subchannel s11, Subchannel s12,
Subchannel s13, Subchannel s14, Subchannel s15, Subchannel s16)
{
return SubchannelsInternal<Matrix4x4Node>(s1.ToString(), s2.ToString(), s3.ToString(), s4.ToString(),
s5.ToString(), s6.ToString(), s7.ToString(), s8.ToString(),
s9.ToString(), s10.ToString(), s11.ToString(), s12.ToString(),
s13.ToString(), s14.ToString(), s15.ToString(), s16.ToString());
}
#pragma warning restore SA1117 // Parameters must be on same line or separate lines
/// <summary>
/// Gets the value.
/// </summary>
/// <returns>System.String.</returns>
protected internal override string GetValue()
{
return $"Matrix4x4({_value.M11.ToCompositionString()},{_value.M12.ToCompositionString()},{_value.M13.ToCompositionString()},{_value.M14.ToCompositionString()}," +
$"{_value.M21.ToCompositionString()},{_value.M22.ToCompositionString()},{_value.M23.ToCompositionString()},{_value.M24.ToCompositionString()}," +
$"{_value.M31.ToCompositionString()},{_value.M32.ToCompositionString()},{_value.M33.ToCompositionString()},{_value.M34.ToCompositionString()}," +
$"{_value.M41.ToCompositionString()},{_value.M42.ToCompositionString()},{_value.M43.ToCompositionString()},{_value.M44.ToCompositionString()})";
}
private Matrix4x4 _value;
/// <summary>
/// Evaluates the current value of the expression
/// </summary>
/// <returns>The current value of the expression</returns>
public Matrix4x4 Evaluate()
{
switch (NodeType)
{
case ExpressionNodeType.ConstantValue:
return _value;
case ExpressionNodeType.ReferenceProperty:
var reference = (Children[0] as ReferenceNode).Reference;
return PropertyName switch
{
nameof(Visual.TransformMatrix) => (reference as Visual).TransformMatrix,
_ => GetProperty()
};
Matrix4x4 GetProperty()
{
reference.Properties.TryGetMatrix4x4(PropertyName, out var value);
return value;
}
case ExpressionNodeType.Add:
return
(Children[0] as Matrix4x4Node).Evaluate() +
(Children[1] as Matrix4x4Node).Evaluate();
case ExpressionNodeType.Subtract:
return
(Children[0] as Matrix4x4Node).Evaluate() -
(Children[1] as Matrix4x4Node).Evaluate();
case ExpressionNodeType.Negate:
return
-(Children[0] as Matrix4x4Node).Evaluate();
case ExpressionNodeType.Multiply:
return (Children[0], Children[1]) switch
{
(Matrix4x4Node v1, Matrix4x4Node v2) => v1.Evaluate() * v2.Evaluate(),
(Matrix4x4Node v1, ScalarNode s2) => v1.Evaluate() * s2.Evaluate(),
(ScalarNode s1, Matrix4x4Node v2) => v2.Evaluate() * s1.Evaluate(),
_ => throw new NotImplementedException()
};
case ExpressionNodeType.Conditional:
return
(Children[0] as BooleanNode).Evaluate() ?
(Children[1] as Matrix4x4Node).Evaluate() :
(Children[2] as Matrix4x4Node).Evaluate();
case ExpressionNodeType.Swizzle:
return new Matrix4x4(
Children[0].EvaluateSubchannel(Subchannels[0]),
Children[0].EvaluateSubchannel(Subchannels[1]),
Children[0].EvaluateSubchannel(Subchannels[2]),
Children[0].EvaluateSubchannel(Subchannels[3]),
Children[0].EvaluateSubchannel(Subchannels[4]),
Children[0].EvaluateSubchannel(Subchannels[5]),
Children[0].EvaluateSubchannel(Subchannels[6]),
Children[0].EvaluateSubchannel(Subchannels[7]),
Children[0].EvaluateSubchannel(Subchannels[8]),
Children[0].EvaluateSubchannel(Subchannels[9]),
Children[0].EvaluateSubchannel(Subchannels[10]),
Children[0].EvaluateSubchannel(Subchannels[11]),
Children[0].EvaluateSubchannel(Subchannels[12]),
Children[0].EvaluateSubchannel(Subchannels[13]),
Children[0].EvaluateSubchannel(Subchannels[14]),
Children[0].EvaluateSubchannel(Subchannels[15]));
default:
throw new NotImplementedException();
}
}
}
#pragma warning restore CS0660, CS0661
}