Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
Matrix.cs
浏览该文件的文档.
1namespace Engine {
2 public struct Matrix(float m11,
3 float m12,
4 float m13,
5 float m14,
6 float m21,
7 float m22,
8 float m23,
9 float m24,
10 float m31,
11 float m32,
12 float m33,
13 float m34,
14 float m41,
15 float m42,
16 float m43,
17 float m44) : IEquatable<Matrix> {
18 public float M11 = m11;
19 public float M21 = m21;
20 public float M31 = m31;
21 public float M41 = m41;
22 public float M12 = m12;
23 public float M22 = m22;
24 public float M32 = m32;
25 public float M42 = m42;
26 public float M13 = m13;
27 public float M23 = m23;
28 public float M33 = m33;
29 public float M43 = m43;
30 public float M14 = m14;
31 public float M24 = m24;
32 public float M34 = m34;
33 public float M44 = m44;
34
35 public static readonly Matrix Zero = default;
36
37 public static readonly Matrix Identity = new(
38 1f,
39 0f,
40 0f,
41 0f,
42 0f,
43 1f,
44 0f,
45 0f,
46 0f,
47 0f,
48 1f,
49 0f,
50 0f,
51 0f,
52 0f,
53 1f
54 );
55
56 public Vector3 Right {
57 get => new(M11, M12, M13);
58 set {
59 M11 = value.X;
60 M12 = value.Y;
61 M13 = value.Z;
62 }
63 }
64
65 public Vector3 Up {
66 get => new(M21, M22, M23);
67 set {
68 M21 = value.X;
69 M22 = value.Y;
70 M23 = value.Z;
71 }
72 }
73
75 get => new(0f - M31, 0f - M32, 0f - M33);
76 set {
77 M31 = 0f - value.X;
78 M32 = 0f - value.Y;
79 M33 = 0f - value.Z;
80 }
81 }
82
84 get => new(M41, M42, M43);
85 set {
86 M41 = value.X;
87 M42 = value.Y;
88 M43 = value.Z;
89 }
90 }
91
93 get => new(
94 1f,
95 0f,
96 0f,
97 0f,
98 0f,
99 1f,
100 0f,
101 0f,
102 0f,
103 0f,
104 1f,
105 0f,
106 M41,
107 M42,
108 M43,
109 1f
110 );
111 set {
112 M41 = value.M41;
113 M42 = value.M42;
114 M43 = value.M43;
115 }
116 }
117
119 get => new(
120 M11,
121 M12,
122 M13,
123 0f,
124 M21,
125 M22,
126 M23,
127 0f,
128 M31,
129 M32,
130 M33,
131 0f,
132 0f,
133 0f,
134 0f,
135 1f
136 );
137 set {
138 M11 = value.M11;
139 M12 = value.M12;
140 M13 = value.M13;
141 M21 = value.M21;
142 M22 = value.M22;
143 M23 = value.M23;
144 M31 = value.M31;
145 M32 = value.M32;
146 M33 = value.M33;
147 }
148 }
149
150 public override bool Equals(object obj) => obj is Matrix && Equals((Matrix)obj);
151
152 public override int GetHashCode() => M11.GetHashCode()
153 + M12.GetHashCode()
154 + M13.GetHashCode()
155 + M14.GetHashCode()
156 + M21.GetHashCode()
157 + M22.GetHashCode()
158 + M23.GetHashCode()
159 + M24.GetHashCode()
160 + M31.GetHashCode()
161 + M32.GetHashCode()
162 + M33.GetHashCode()
163 + M34.GetHashCode()
164 + M41.GetHashCode()
165 + M42.GetHashCode()
166 + M43.GetHashCode()
167 + M44.GetHashCode();
168
169 public override string ToString() => $"{M11},{M12},{M13},{M14}, {M21},{M22},{M23},{M24}, {M31},{M32},{M33},{M34}, {M41},{M42},{M43},{M44}";
170
171 public bool Equals(Matrix other) => M11 == other.M11
172 && M22 == other.M22
173 && M33 == other.M33
174 && M44 == other.M44
175 && M12 == other.M12
176 && M13 == other.M13
177 && M14 == other.M14
178 && M21 == other.M21
179 && M23 == other.M23
180 && M24 == other.M24
181 && M31 == other.M31
182 && M32 == other.M32
183 && M34 == other.M34
184 && M41 == other.M41
185 && M42 == other.M42
186 && M43 == other.M43;
187
188 public float Determinant() {
189 float num = M33 * M44 - M34 * M43;
190 float num2 = M32 * M44 - M34 * M42;
191 float num3 = M32 * M43 - M33 * M42;
192 float num4 = M31 * M44 - M34 * M41;
193 float num5 = M31 * M43 - M33 * M41;
194 float num6 = M31 * M42 - M32 * M41;
195 return M11 * (M22 * num - M23 * num2 + M24 * num3)
196 - M12 * (M21 * num - M23 * num4 + M24 * num5)
197 + M13 * (M21 * num2 - M22 * num4 + M24 * num6)
198 - M14 * (M21 * num3 - M22 * num5 + M23 * num6);
199 }
200
202 Decompose(out Vector3 _, out Quaternion rotation, out Vector3 _);
203 return rotation.ToYawPitchRoll();
204 }
205
206 public bool Decompose(out Vector3 scale, out Quaternion rotation, out Vector3 translation) {
207 translation.X = M41;
208 translation.Y = M42;
209 translation.Z = M43;
210 float num = !(M11 * M12 * M13 * M14 < 0f) ? 1 : -1;
211 float num2 = !(M21 * M22 * M23 * M24 < 0f) ? 1 : -1;
212 float num3 = !(M31 * M32 * M33 * M34 < 0f) ? 1 : -1;
213 scale.X = num * MathF.Sqrt(M11 * M11 + M12 * M12 + M13 * M13);
214 scale.Y = num2 * MathF.Sqrt(M21 * M21 + M22 * M22 + M23 * M23);
215 scale.Z = num3 * MathF.Sqrt(M31 * M31 + M32 * M32 + M33 * M33);
216 if (scale.X == 0f
217 || scale.Y == 0f
218 || scale.Z == 0f) {
219 rotation = Quaternion.Identity;
220 return false;
221 }
223 new Matrix(
224 M11 / scale.X,
225 M12 / scale.X,
226 M13 / scale.X,
227 0f,
228 M21 / scale.Y,
229 M22 / scale.Y,
230 M23 / scale.Y,
231 0f,
232 M31 / scale.Z,
233 M32 / scale.Z,
234 M33 / scale.Z,
235 0f,
236 0f,
237 0f,
238 0f,
239 1f
240 )
241 );
242 return true;
243 }
244
245 public static Matrix CreateFromAxisAngle(Vector3 axis, float angle) {
246 float x = axis.X;
247 float y = axis.Y;
248 float z = axis.Z;
249 float num = MathF.Sin(angle);
250 float num2 = MathF.Cos(angle);
251 float num3 = x * x;
252 float num4 = y * y;
253 float num5 = z * z;
254 float num6 = x * y;
255 float num7 = x * z;
256 float num8 = y * z;
257 Matrix result = default;
258 result.M11 = num3 + num2 * (1f - num3);
259 result.M12 = num6 - num2 * num6 + num * z;
260 result.M13 = num7 - num2 * num7 - num * y;
261 result.M14 = 0f;
262 result.M21 = num6 - num2 * num6 - num * z;
263 result.M22 = num4 + num2 * (1f - num4);
264 result.M23 = num8 - num2 * num8 + num * x;
265 result.M24 = 0f;
266 result.M31 = num7 - num2 * num7 + num * y;
267 result.M32 = num8 - num2 * num8 - num * x;
268 result.M33 = num5 + num2 * (1f - num5);
269 result.M34 = 0f;
270 result.M41 = 0f;
271 result.M42 = 0f;
272 result.M43 = 0f;
273 result.M44 = 1f;
274 return result;
275 }
276
277 public static Matrix CreateFromQuaternion(Quaternion quaternion) => quaternion.ToMatrix();
278
279 public static Matrix CreateFromYawPitchRoll(float yaw, float pitch, float roll) =>
280 Quaternion.CreateFromYawPitchRoll(yaw, pitch, roll).ToMatrix();
281
282 public static Matrix CreateLookAt(Vector3 position, Vector3 target, Vector3 up) {
283 Vector3 vector = Vector3.Normalize(position - target);
284 Vector3 vector2 = Vector3.Normalize(Vector3.Cross(up, vector));
285 up = Vector3.Normalize(Vector3.Cross(vector, vector2));
286 Matrix result = default;
287 result.M11 = vector2.X;
288 result.M12 = up.X;
289 result.M13 = vector.X;
290 result.M14 = 0f;
291 result.M21 = vector2.Y;
292 result.M22 = up.Y;
293 result.M23 = vector.Y;
294 result.M24 = 0f;
295 result.M31 = vector2.Z;
296 result.M32 = up.Z;
297 result.M33 = vector.Z;
298 result.M34 = 0f;
299 result.M41 = 0f - Vector3.Dot(vector2, position);
300 result.M42 = 0f - Vector3.Dot(up, position);
301 result.M43 = 0f - Vector3.Dot(vector, position);
302 result.M44 = 1f;
303 return result;
304 }
305
306 public static Matrix CreateOrthographic(float width, float height, float nearPlane, float farPlane) {
307 Matrix result = default;
308 result.M11 = 2f / width;
309 result.M12 = result.M13 = result.M14 = 0f;
310 result.M22 = 2f / height;
311 result.M21 = result.M23 = result.M24 = 0f;
312 result.M33 = 1f / (nearPlane - farPlane);
313 result.M31 = result.M32 = result.M34 = 0f;
314 result.M41 = result.M42 = 0f;
315 result.M43 = nearPlane / (nearPlane - farPlane);
316 result.M44 = 1f;
317 return result;
318 }
319
320 public static Matrix CreateOrthographicOffCenter(float left, float right, float bottom, float top, float nearPlane, float farPlane) {
321 Matrix result = default;
322 result.M11 = 2f / (right - left);
323 result.M12 = 0f;
324 result.M13 = 0f;
325 result.M14 = 0f;
326 result.M21 = 0f;
327 result.M22 = 2f / (top - bottom);
328 result.M23 = 0f;
329 result.M24 = 0f;
330 result.M31 = 0f;
331 result.M32 = 0f;
332 result.M33 = 1f / (nearPlane - farPlane);
333 result.M34 = 0f;
334 result.M41 = (left + right) / (left - right);
335 result.M42 = (top + bottom) / (bottom - top);
336 result.M43 = nearPlane / (nearPlane - farPlane);
337 result.M44 = 1f;
338 return result;
339 }
340
341 public static Matrix CreatePerspective(float width, float height, float nearPlane, float farPlane) {
342 Matrix result = default;
343 result.M11 = 2f * nearPlane / width;
344 result.M12 = result.M13 = result.M14 = 0f;
345 result.M22 = 2f * nearPlane / height;
346 result.M21 = result.M23 = result.M24 = 0f;
347 result.M33 = farPlane / (nearPlane - farPlane);
348 result.M31 = result.M32 = 0f;
349 result.M34 = -1f;
350 result.M41 = result.M42 = result.M44 = 0f;
351 result.M43 = nearPlane * farPlane / (nearPlane - farPlane);
352 return result;
353 }
354
355 public static Matrix CreatePerspectiveFieldOfView(float fieldOfViewY, float aspectRatio, float nearPlane, float farPlane) {
356 float num = 1f / MathF.Tan(fieldOfViewY * 0.5f);
357 Matrix result = default;
358 result.M11 = num / aspectRatio;
359 result.M12 = result.M13 = result.M14 = 0f;
360 result.M22 = num;
361 result.M21 = result.M23 = result.M24 = 0f;
362 result.M31 = result.M32 = 0f;
363 result.M33 = farPlane / (nearPlane - farPlane);
364 result.M34 = -1f;
365 result.M41 = result.M42 = result.M44 = 0f;
366 result.M43 = nearPlane * farPlane / (nearPlane - farPlane);
367 return result;
368 }
369
370 public static Matrix CreatePerspectiveOffCenter(float left, float right, float bottom, float top, float nearPlane, float farPlane) {
371 Matrix result = default;
372 result.M11 = 2f * nearPlane / (right - left);
373 result.M12 = result.M13 = result.M14 = 0f;
374 result.M22 = 2f * nearPlane / (top - bottom);
375 result.M21 = result.M23 = result.M24 = 0f;
376 result.M31 = (left + right) / (right - left);
377 result.M32 = (top + bottom) / (top - bottom);
378 result.M33 = farPlane / (nearPlane - farPlane);
379 result.M34 = -1f;
380 result.M43 = nearPlane * farPlane / (nearPlane - farPlane);
381 result.M41 = result.M42 = result.M44 = 0f;
382 return result;
383 }
384
385 public static Matrix CreateRotationX(float radians) {
386 float num = MathF.Cos(radians);
387 float num2 = MathF.Sin(radians);
388 return new Matrix(
389 1f,
390 0f,
391 0f,
392 0f,
393 0f,
394 num,
395 num2,
396 0f,
397 0f,
398 0f - num2,
399 num,
400 0f,
401 0f,
402 0f,
403 0f,
404 1f
405 );
406 }
407
408 public static Matrix CreateRotationX(float radians, Vector3 center) {
409 float num = MathF.Cos(radians);
410 float num2 = MathF.Sin(radians);
411 return new Matrix(
412 1f,
413 0f,
414 0f,
415 0f,
416 0f,
417 num,
418 num2,
419 0f,
420 0f,
421 0f - num2,
422 num,
423 0f,
424 0f,
425 num2 * center.Z - num * center.Y + center.Y,
426 (0f - num) * center.Z - num2 * center.Y + center.Z,
427 1f
428 );
429 }
430
431 public static Matrix CreateRotationY(float radians) {
432 float num = MathF.Cos(radians);
433 float num2 = MathF.Sin(radians);
434 return new Matrix(
435 num,
436 0f,
437 0f - num2,
438 0f,
439 0f,
440 1f,
441 0f,
442 0f,
443 num2,
444 0f,
445 num,
446 0f,
447 0f,
448 0f,
449 0f,
450 1f
451 );
452 }
453
454 public static Matrix CreateRotationY(float radians, Vector3 center) {
455 float num = MathF.Cos(radians);
456 float num2 = MathF.Sin(radians);
457 return new Matrix(
458 num,
459 0f,
460 0f - num2,
461 0f,
462 0f,
463 1f,
464 0f,
465 0f,
466 num2,
467 0f,
468 num,
469 0f,
470 (0f - num2) * center.Z - num * center.X + center.X,
471 0f,
472 (0f - num) * center.Z + num2 * center.X + center.Z,
473 1f
474 );
475 }
476
477 public static Matrix CreateRotationZ(float radians) {
478 float num = MathF.Cos(radians);
479 float num2 = MathF.Sin(radians);
480 return new Matrix(
481 num,
482 num2,
483 0f,
484 0f,
485 0f - num2,
486 num,
487 0f,
488 0f,
489 0f,
490 0f,
491 1f,
492 0f,
493 0f,
494 0f,
495 0f,
496 1f
497 );
498 }
499
500 public static Matrix CreateRotationZ(float radians, Vector3 center) {
501 float num = MathF.Cos(radians);
502 float num2 = MathF.Sin(radians);
503 return new Matrix(
504 num,
505 num2,
506 0f,
507 0f,
508 0f - num2,
509 num,
510 0f,
511 0f,
512 0f,
513 0f,
514 1f,
515 0f,
516 num2 * center.Y - num * center.X + center.X,
517 (0f - num) * center.Y - num2 * center.X + center.Y,
518 0f,
519 1f
520 );
521 }
522
523 public static Matrix CreateScale(float scale) => new(
524 scale,
525 0f,
526 0f,
527 0f,
528 0f,
529 scale,
530 0f,
531 0f,
532 0f,
533 0f,
534 scale,
535 0f,
536 0f,
537 0f,
538 0f,
539 1f
540 );
541
542 public static Matrix CreateScale(float x, float y, float z) => new(
543 x,
544 0f,
545 0f,
546 0f,
547 0f,
548 y,
549 0f,
550 0f,
551 0f,
552 0f,
553 z,
554 0f,
555 0f,
556 0f,
557 0f,
558 1f
559 );
560
561 public static Matrix CreateScale(Vector3 scale) => new(
562 scale.X,
563 0f,
564 0f,
565 0f,
566 0f,
567 scale.Y,
568 0f,
569 0f,
570 0f,
571 0f,
572 scale.Z,
573 0f,
574 0f,
575 0f,
576 0f,
577 1f
578 );
579
580 public static Matrix CreateTranslation(float x, float y, float z) => new(
581 1f,
582 0f,
583 0f,
584 0f,
585 0f,
586 1f,
587 0f,
588 0f,
589 0f,
590 0f,
591 1f,
592 0f,
593 x,
594 y,
595 z,
596 1f
597 );
598
599 public static Matrix CreateTranslation(Vector3 position) => new(
600 1f,
601 0f,
602 0f,
603 0f,
604 0f,
605 1f,
606 0f,
607 0f,
608 0f,
609 0f,
610 1f,
611 0f,
612 position.X,
613 position.Y,
614 position.Z,
615 1f
616 );
617
618 public static Matrix CreateWorld(Vector3 position, Vector3 forward, Vector3 up) {
619 forward = Vector3.Normalize(forward);
620 Vector3 vector = Vector3.Normalize(Vector3.Cross(forward, Vector3.Normalize(up)));
621 up = Vector3.Normalize(Vector3.Cross(vector, forward));
622 Matrix result = default;
623 result.Right = vector;
624 result.Up = up;
625 result.Forward = forward;
626 result.Translation = position;
627 result.M44 = 1f;
628 return result;
629 }
630
631 public static Matrix CreateShadow(Vector4 lightDirection, Plane plane) {
632 float num = plane.Normal.X * lightDirection.X + plane.Normal.Y * lightDirection.Y + plane.Normal.Z * lightDirection.Z;
633 float num2 = 0f - plane.Normal.X;
634 float num3 = 0f - plane.Normal.Y;
635 float num4 = 0f - plane.Normal.Z;
636 float num5 = 0f - plane.D;
637 Matrix result = default;
638 result.M11 = num2 * lightDirection.X + num;
639 result.M21 = num3 * lightDirection.X;
640 result.M31 = num4 * lightDirection.X;
641 result.M41 = num5 * lightDirection.X;
642 result.M12 = num2 * lightDirection.Y;
643 result.M22 = num3 * lightDirection.Y + num;
644 result.M32 = num4 * lightDirection.Y;
645 result.M42 = num5 * lightDirection.Y;
646 result.M13 = num2 * lightDirection.Z;
647 result.M23 = num3 * lightDirection.Z;
648 result.M33 = num4 * lightDirection.Z + num;
649 result.M43 = num5 * lightDirection.Z;
650 result.M14 = num2 * lightDirection.W;
651 result.M24 = num3 * lightDirection.W;
652 result.M34 = num4 * lightDirection.W;
653 result.M44 = num5 * lightDirection.W + num;
654 return result;
655 }
656
657 public static Matrix Transpose(Matrix m) => new(
658 m.M11,
659 m.M21,
660 m.M31,
661 m.M41,
662 m.M12,
663 m.M22,
664 m.M32,
665 m.M42,
666 m.M13,
667 m.M23,
668 m.M33,
669 m.M43,
670 m.M14,
671 m.M24,
672 m.M34,
673 m.M44
674 );
675
676 public static Matrix Invert(Matrix m) {
677 float m2 = m.M11;
678 float m3 = m.M12;
679 float m4 = m.M13;
680 float m5 = m.M14;
681 float m6 = m.M21;
682 float m7 = m.M22;
683 float m8 = m.M23;
684 float m9 = m.M24;
685 float m10 = m.M31;
686 float m11 = m.M32;
687 float m12 = m.M33;
688 float m13 = m.M34;
689 float m14 = m.M41;
690 float m15 = m.M42;
691 float m16 = m.M43;
692 float m17 = m.M44;
693 float num = m12 * m17 - m13 * m16;
694 float num2 = m11 * m17 - m13 * m15;
695 float num3 = m11 * m16 - m12 * m15;
696 float num4 = m10 * m17 - m13 * m14;
697 float num5 = m10 * m16 - m12 * m14;
698 float num6 = m10 * m15 - m11 * m14;
699 float num7 = m7 * num - m8 * num2 + m9 * num3;
700 float num8 = 0f - (m6 * num - m8 * num4 + m9 * num5);
701 float num9 = m6 * num2 - m7 * num4 + m9 * num6;
702 float num10 = 0f - (m6 * num3 - m7 * num5 + m8 * num6);
703 float num11 = 1f / (m2 * num7 + m3 * num8 + m4 * num9 + m5 * num10);
704 Matrix result = default;
705 result.M11 = num7 * num11;
706 result.M21 = num8 * num11;
707 result.M31 = num9 * num11;
708 result.M41 = num10 * num11;
709 result.M12 = (0f - (m3 * num - m4 * num2 + m5 * num3)) * num11;
710 result.M22 = (m2 * num - m4 * num4 + m5 * num5) * num11;
711 result.M32 = (0f - (m2 * num2 - m3 * num4 + m5 * num6)) * num11;
712 result.M42 = (m2 * num3 - m3 * num5 + m4 * num6) * num11;
713 float num12 = m8 * m17 - m9 * m16;
714 float num13 = m7 * m17 - m9 * m15;
715 float num14 = m7 * m16 - m8 * m15;
716 float num15 = m6 * m17 - m9 * m14;
717 float num16 = m6 * m16 - m8 * m14;
718 float num17 = m6 * m15 - m7 * m14;
719 result.M13 = (m3 * num12 - m4 * num13 + m5 * num14) * num11;
720 result.M23 = (0f - (m2 * num12 - m4 * num15 + m5 * num16)) * num11;
721 result.M33 = (m2 * num13 - m3 * num15 + m5 * num17) * num11;
722 result.M43 = (0f - (m2 * num14 - m3 * num16 + m4 * num17)) * num11;
723 float num18 = m8 * m13 - m9 * m12;
724 float num19 = m7 * m13 - m9 * m11;
725 float num20 = m7 * m12 - m8 * m11;
726 float num21 = m6 * m13 - m9 * m10;
727 float num22 = m6 * m12 - m8 * m10;
728 float num23 = m6 * m11 - m7 * m10;
729 result.M14 = (0f - (m3 * num18 - m4 * num19 + m5 * num20)) * num11;
730 result.M24 = (m2 * num18 - m4 * num21 + m5 * num22) * num11;
731 result.M34 = (0f - (m2 * num19 - m3 * num21 + m5 * num23)) * num11;
732 result.M44 = (m2 * num20 - m3 * num22 + m4 * num23) * num11;
733 return result;
734 }
735
736 public static Matrix Lerp(Matrix m1, Matrix m2, float f) {
737 m1.M11 += (m2.M11 - m1.M11) * f;
738 m1.M12 += (m2.M12 - m1.M12) * f;
739 m1.M13 += (m2.M13 - m1.M13) * f;
740 m1.M14 += (m2.M14 - m1.M14) * f;
741 m1.M21 += (m2.M21 - m1.M21) * f;
742 m1.M22 += (m2.M22 - m1.M22) * f;
743 m1.M23 += (m2.M23 - m1.M23) * f;
744 m1.M24 += (m2.M24 - m1.M24) * f;
745 m1.M31 += (m2.M31 - m1.M31) * f;
746 m1.M32 += (m2.M32 - m1.M32) * f;
747 m1.M33 += (m2.M33 - m1.M33) * f;
748 m1.M34 += (m2.M34 - m1.M34) * f;
749 m1.M41 += (m2.M41 - m1.M41) * f;
750 m1.M42 += (m2.M42 - m1.M42) * f;
751 m1.M43 += (m2.M43 - m1.M43) * f;
752 m1.M44 += (m2.M44 - m1.M44) * f;
753 return m1;
754 }
755
756 public static void MultiplyRestricted(ref Matrix m1, ref Matrix m2, out Matrix result) {
757 result.M11 = m1.M11 * m2.M11 + m1.M12 * m2.M21 + m1.M13 * m2.M31 + m1.M14 * m2.M41;
758 result.M12 = m1.M11 * m2.M12 + m1.M12 * m2.M22 + m1.M13 * m2.M32 + m1.M14 * m2.M42;
759 result.M13 = m1.M11 * m2.M13 + m1.M12 * m2.M23 + m1.M13 * m2.M33 + m1.M14 * m2.M43;
760 result.M14 = m1.M11 * m2.M14 + m1.M12 * m2.M24 + m1.M13 * m2.M34 + m1.M14 * m2.M44;
761 result.M21 = m1.M21 * m2.M11 + m1.M22 * m2.M21 + m1.M23 * m2.M31 + m1.M24 * m2.M41;
762 result.M22 = m1.M21 * m2.M12 + m1.M22 * m2.M22 + m1.M23 * m2.M32 + m1.M24 * m2.M42;
763 result.M23 = m1.M21 * m2.M13 + m1.M22 * m2.M23 + m1.M23 * m2.M33 + m1.M24 * m2.M43;
764 result.M24 = m1.M21 * m2.M14 + m1.M22 * m2.M24 + m1.M23 * m2.M34 + m1.M24 * m2.M44;
765 result.M31 = m1.M31 * m2.M11 + m1.M32 * m2.M21 + m1.M33 * m2.M31 + m1.M34 * m2.M41;
766 result.M32 = m1.M31 * m2.M12 + m1.M32 * m2.M22 + m1.M33 * m2.M32 + m1.M34 * m2.M42;
767 result.M33 = m1.M31 * m2.M13 + m1.M32 * m2.M23 + m1.M33 * m2.M33 + m1.M34 * m2.M43;
768 result.M34 = m1.M31 * m2.M14 + m1.M32 * m2.M24 + m1.M33 * m2.M34 + m1.M34 * m2.M44;
769 result.M41 = m1.M41 * m2.M11 + m1.M42 * m2.M21 + m1.M43 * m2.M31 + m1.M44 * m2.M41;
770 result.M42 = m1.M41 * m2.M12 + m1.M42 * m2.M22 + m1.M43 * m2.M32 + m1.M44 * m2.M42;
771 result.M43 = m1.M41 * m2.M13 + m1.M42 * m2.M23 + m1.M43 * m2.M33 + m1.M44 * m2.M43;
772 result.M44 = m1.M41 * m2.M14 + m1.M42 * m2.M24 + m1.M43 * m2.M34 + m1.M44 * m2.M44;
773 }
774
775 public static bool operator ==(Matrix m1, Matrix m2) => m1.Equals(m2);
776
777 public static bool operator !=(Matrix m1, Matrix m2) => !m1.Equals(m2);
778
779 public static Matrix operator +(Matrix m) => m;
780
781 public static Matrix operator -(Matrix m) => new(
782 0f - m.M11,
783 0f - m.M12,
784 0f - m.M13,
785 0f - m.M14,
786 0f - m.M21,
787 0f - m.M22,
788 0f - m.M23,
789 0f - m.M24,
790 0f - m.M31,
791 0f - m.M32,
792 0f - m.M33,
793 0f - m.M34,
794 0f - m.M41,
795 0f - m.M42,
796 0f - m.M43,
797 0f - m.M44
798 );
799
800 public static Matrix operator +(Matrix m1, Matrix m2) => new(
801 m1.M11 + m2.M11,
802 m1.M12 + m2.M12,
803 m1.M13 + m2.M13,
804 m1.M14 + m2.M14,
805 m1.M21 + m2.M21,
806 m1.M22 + m2.M22,
807 m1.M23 + m2.M23,
808 m1.M24 + m2.M24,
809 m1.M31 + m2.M31,
810 m1.M32 + m2.M32,
811 m1.M33 + m2.M33,
812 m1.M34 + m2.M34,
813 m1.M41 + m2.M41,
814 m1.M42 + m2.M42,
815 m1.M43 + m2.M43,
816 m1.M44 + m2.M44
817 );
818
819 public static Matrix operator -(Matrix m1, Matrix m2) => new(
820 m1.M11 - m2.M11,
821 m1.M12 - m2.M12,
822 m1.M13 - m2.M13,
823 m1.M14 - m2.M14,
824 m1.M21 - m2.M21,
825 m1.M22 - m2.M22,
826 m1.M23 - m2.M23,
827 m1.M24 - m2.M24,
828 m1.M31 - m2.M31,
829 m1.M32 - m2.M32,
830 m1.M33 - m2.M33,
831 m1.M34 - m2.M34,
832 m1.M41 - m2.M41,
833 m1.M42 - m2.M42,
834 m1.M43 - m2.M43,
835 m1.M44 - m2.M44
836 );
837
838 public static Matrix operator *(Matrix m1, Matrix m2) {
839 MultiplyRestricted(ref m1, ref m2, out Matrix result);
840 return result;
841 }
842
843 public static Matrix operator *(Matrix m, float s) => new(
844 m.M11 * s,
845 m.M12 * s,
846 m.M13 * s,
847 m.M14 * s,
848 m.M21 * s,
849 m.M22 * s,
850 m.M23 * s,
851 m.M24 * s,
852 m.M31 * s,
853 m.M32 * s,
854 m.M33 * s,
855 m.M34 * s,
856 m.M41 * s,
857 m.M42 * s,
858 m.M43 * s,
859 m.M44 * s
860 );
861
862 public static Matrix operator *(float s, Matrix m) => new(
863 m.M11 * s,
864 m.M12 * s,
865 m.M13 * s,
866 m.M14 * s,
867 m.M21 * s,
868 m.M22 * s,
869 m.M23 * s,
870 m.M24 * s,
871 m.M31 * s,
872 m.M32 * s,
873 m.M33 * s,
874 m.M34 * s,
875 m.M41 * s,
876 m.M42 * s,
877 m.M43 * s,
878 m.M44 * s
879 );
880
881 public static Matrix operator /(Matrix m1, Matrix m2) => new(
882 m1.M11 / m2.M11,
883 m1.M12 / m2.M12,
884 m1.M13 / m2.M13,
885 m1.M14 / m2.M14,
886 m1.M21 / m2.M21,
887 m1.M22 / m2.M22,
888 m1.M23 / m2.M23,
889 m1.M24 / m2.M24,
890 m1.M31 / m2.M31,
891 m1.M32 / m2.M32,
892 m1.M33 / m2.M33,
893 m1.M34 / m2.M34,
894 m1.M41 / m2.M41,
895 m1.M42 / m2.M42,
896 m1.M43 / m2.M43,
897 m1.M44 / m2.M44
898 );
899
900 public static Matrix operator /(Matrix m, float d) {
901 float num = 1f / d;
902 return new Matrix(
903 m.M11 * num,
904 m.M12 * num,
905 m.M13 * num,
906 m.M14 * num,
907 m.M21 * num,
908 m.M22 * num,
909 m.M23 * num,
910 m.M24 * num,
911 m.M31 * num,
912 m.M32 * num,
913 m.M33 * num,
914 m.M34 * num,
915 m.M41 * num,
916 m.M42 * num,
917 m.M43 * num,
918 m.M44 * num
919 );
920 }
921 }
922}
static Matrix CreateRotationY(float radians, Vector3 center)
bool Decompose(out Vector3 scale, out Quaternion rotation, out Vector3 translation)
static Matrix Invert(Matrix m)
static bool operator==(Matrix m1, Matrix m2)
static Matrix CreatePerspective(float width, float height, float nearPlane, float farPlane)
static Matrix CreateShadow(Vector4 lightDirection, Plane plane)
static Matrix CreateRotationX(float radians)
static Matrix CreateScale(Vector3 scale)
static Matrix operator-(Matrix m)
static Matrix CreateFromQuaternion(Quaternion quaternion)
static Matrix CreateTranslation(float x, float y, float z)
static readonly Matrix Zero
static Matrix CreateScale(float x, float y, float z)
Vector3 ToYawPitchRoll()
static Matrix CreateRotationZ(float radians)
static Matrix CreatePerspectiveOffCenter(float left, float right, float bottom, float top, float nearPlane, float farPlane)
override int GetHashCode()
static Matrix CreatePerspectiveFieldOfView(float fieldOfViewY, float aspectRatio, float nearPlane, float farPlane)
static void MultiplyRestricted(ref Matrix m1, ref Matrix m2, out Matrix result)
static readonly Matrix Identity
static Matrix Transpose(Matrix m)
override bool Equals(object obj)
static Matrix CreateLookAt(Vector3 position, Vector3 target, Vector3 up)
float Determinant()
static Matrix CreateFromYawPitchRoll(float yaw, float pitch, float roll)
static Matrix CreateFromAxisAngle(Vector3 axis, float angle)
static Matrix CreateWorld(Vector3 position, Vector3 forward, Vector3 up)
Matrix TranslationMatrix
static Matrix CreateRotationY(float radians)
static Matrix Lerp(Matrix m1, Matrix m2, float f)
static Matrix CreateTranslation(Vector3 position)
Vector3 Translation
bool Equals(Matrix other)
static Matrix CreateRotationX(float radians, Vector3 center)
Vector3 Forward
static Matrix operator+(Matrix m)
static Matrix operator*(Matrix m1, Matrix m2)
static Matrix operator/(Matrix m1, Matrix m2)
static Matrix CreateScale(float scale)
static Matrix CreateOrthographicOffCenter(float left, float right, float bottom, float top, float nearPlane, float farPlane)
static Matrix CreateRotationZ(float radians, Vector3 center)
override string ToString()
Matrix OrientationMatrix
static bool operator!=(Matrix m1, Matrix m2)
static Matrix CreateOrthographic(float width, float height, float nearPlane, float farPlane)
Vector3 Normal
定义 Plane.cs:3
static Quaternion CreateFromYawPitchRoll(float yaw, float pitch, float roll)
static readonly Quaternion Identity
static Quaternion CreateFromRotationMatrix(Matrix m)
static Vector3 Cross(Vector3 v1, Vector3 v2)
static Vector3 Normalize(Vector3 v)
static float Dot(Vector3 v1, Vector3 v2)