aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/ModifiedBulletX/MonoXnaCompactMaths/Matrix.cs
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/ModifiedBulletX/MonoXnaCompactMaths/Matrix.cs')
-rw-r--r--libraries/ModifiedBulletX/MonoXnaCompactMaths/Matrix.cs683
1 files changed, 683 insertions, 0 deletions
diff --git a/libraries/ModifiedBulletX/MonoXnaCompactMaths/Matrix.cs b/libraries/ModifiedBulletX/MonoXnaCompactMaths/Matrix.cs
new file mode 100644
index 0000000..a104d89
--- /dev/null
+++ b/libraries/ModifiedBulletX/MonoXnaCompactMaths/Matrix.cs
@@ -0,0 +1,683 @@
1#region License
2/*
3MIT License
4Copyright © 2006 The Mono.Xna Team
5
6All rights reserved.
7
8Permission is hereby granted, free of charge, to any person obtaining a copy
9of this software and associated documentation files (the "Software"), to deal
10in the Software without restriction, including without limitation the rights
11to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12copies of the Software, and to permit persons to whom the Software is
13furnished to do so, subject to the following conditions:
14
15The above copyright notice and this permission notice shall be included in all
16copies or substantial portions of the Software.
17
18THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24SOFTWARE.
25*/
26#endregion License
27
28using System;
29using System.ComponentModel;
30using System.Runtime.InteropServices;
31
32namespace MonoXnaCompactMaths
33{
34 [Serializable]
35 [StructLayout(LayoutKind.Sequential)]
36 //[TypeConverter(typeof(MatrixConverter))]
37 public struct Matrix : IEquatable<Matrix>
38 {
39 #region Public Constructors
40
41 public Matrix(float m11, float m12, float m13, float m14, float m21, float m22, float m23, float m24, float m31,
42 float m32, float m33, float m34, float m41, float m42, float m43, float m44)
43 {
44 this.M11 = m11;
45 this.M12 = m12;
46 this.M13 = m13;
47 this.M14 = m14;
48 this.M21 = m21;
49 this.M22 = m22;
50 this.M23 = m23;
51 this.M24 = m24;
52 this.M31 = m31;
53 this.M32 = m32;
54 this.M33 = m33;
55 this.M34 = m34;
56 this.M41 = m41;
57 this.M42 = m42;
58 this.M43 = m43;
59 this.M44 = m44;
60 }
61
62 #endregion Public Constructors
63
64
65 #region Public Fields
66
67 public float M11;
68 public float M12;
69 public float M13;
70 public float M14;
71 public float M21;
72 public float M22;
73 public float M23;
74 public float M24;
75 public float M31;
76 public float M32;
77 public float M33;
78 public float M34;
79 public float M41;
80 public float M42;
81 public float M43;
82 public float M44;
83
84 #endregion Public Fields
85
86
87 #region Private Members
88 private static Matrix identity = new Matrix(1f, 0f, 0f, 0f, 0f, 1f, 0f, 0f, 0f, 0f, 1f, 0f, 0f, 0f, 0f, 1f);
89 #endregion Private Members
90
91
92 #region Public Properties
93
94 public Vector3 Backward
95 {
96 get
97 {
98 return new Vector3(this.M31, this.M32, this.M33);
99 }
100 set
101 {
102 this.M31 = value.X;
103 this.M32 = value.Y;
104 this.M33 = value.Z;
105 }
106 }
107
108
109 public Vector3 Down
110 {
111 get
112 {
113 return new Vector3(-this.M21, -this.M22, -this.M23);
114 }
115 set
116 {
117 this.M21 = -value.X;
118 this.M22 = -value.Y;
119 this.M23 = -value.Z;
120 }
121 }
122
123
124 public Vector3 Forward
125 {
126 get
127 {
128 return new Vector3(-this.M31, -this.M32, -this.M33);
129 }
130 set
131 {
132 this.M31 = -value.X;
133 this.M32 = -value.Y;
134 this.M33 = -value.Z;
135 }
136 }
137
138
139 public static Matrix Identity
140 {
141 get { return identity; }
142 }
143
144
145 public Vector3 Left
146 {
147 get
148 {
149 return new Vector3(-this.M11, -this.M12, -this.M13);
150 }
151 set
152 {
153 this.M11 = -value.X;
154 this.M12 = -value.Y;
155 this.M13 = -value.Z;
156 }
157 }
158
159
160 public Vector3 Right
161 {
162 get
163 {
164 return new Vector3(this.M11, this.M12, this.M13);
165 }
166 set
167 {
168 this.M11 = value.X;
169 this.M12 = value.Y;
170 this.M13 = value.Z;
171 }
172 }
173
174
175 public Vector3 Translation
176 {
177 get
178 {
179 return new Vector3(this.M41, this.M42, this.M43);
180 }
181 set
182 {
183 this.M41 = value.X;
184 this.M42 = value.Y;
185 this.M43 = value.Z;
186 }
187 }
188
189
190 public Vector3 Up
191 {
192 get
193 {
194 return new Vector3(this.M21, this.M22, this.M23);
195 }
196 set
197 {
198 this.M21 = value.X;
199 this.M22 = value.Y;
200 this.M23 = value.Z;
201 }
202 }
203 #endregion Public Properties
204
205
206 #region Public Methods
207
208 public static Matrix Add(Matrix matrix1, Matrix matrix2)
209 {
210 throw new NotImplementedException();
211 }
212
213
214 public static void Add(ref Matrix matrix1, ref Matrix matrix2, out Matrix result)
215 {
216 throw new NotImplementedException();
217 }
218
219
220 public static Matrix CreateBillboard(Vector3 objectPosition, Vector3 cameraPosition,
221 Vector3 cameraUpVector, Nullable<Vector3> cameraForwardVector)
222 {
223 throw new NotImplementedException();
224 }
225
226
227 public static void CreateBillboard(ref Vector3 objectPosition, ref Vector3 cameraPosition,
228 ref Vector3 cameraUpVector, Vector3? cameraForwardVector, out Matrix result)
229 {
230 throw new NotImplementedException();
231 }
232
233
234 public static Matrix CreateConstrainedBillboard(Vector3 objectPosition, Vector3 cameraPosition,
235 Vector3 rotateAxis, Nullable<Vector3> cameraForwardVector, Nullable<Vector3> objectForwardVector)
236 {
237 throw new NotImplementedException();
238 }
239
240
241 public static void CreateConstrainedBillboard(ref Vector3 objectPosition, ref Vector3 cameraPosition,
242 ref Vector3 rotateAxis, Vector3? cameraForwardVector, Vector3? objectForwardVector, out Matrix result)
243 {
244 throw new NotImplementedException();
245 }
246
247
248 public static Matrix CreateFromAxisAngle(Vector3 axis, float angle)
249 {
250 throw new NotImplementedException();
251 }
252
253
254 public static void CreateFromAxisAngle(ref Vector3 axis, float angle, out Matrix result)
255 {
256 throw new NotImplementedException();
257 }
258
259
260 public static Matrix CreateFromQuaternion(Quaternion quaternion)
261 {
262 //---
263 //http://lists.ximian.com/pipermail/mono-patches/2006-December/084667.html
264 float xx = quaternion.X * quaternion.X;
265 float xy = quaternion.X * quaternion.Y;
266 float xw = quaternion.X * quaternion.W;
267 float yy = quaternion.Y * quaternion.Y;
268 float yw = quaternion.Y * quaternion.W;
269 float yz = quaternion.Y * quaternion.Z;
270 float zx = quaternion.Z * quaternion.X;
271 float zw = quaternion.Z * quaternion.W;
272 float zz = quaternion.Z * quaternion.Z;
273 return new Matrix(1f - (2f * (yy + zz)), 2f * (xy + zw), 2f * (zx - yw), 0f, 2f * (xy - zw),
274 1f - (2f * (zz + xx)), 2f * (yz + xw), 0f, 2f * (zx + yw), 2f * (yz - xw),
275 1f - (2f * (yy + xx)), 0f, 0f, 0f, 0f, 1f);
276 //throw new NotImplementedException();
277 }
278
279
280 public static void CreateFromQuaternion(ref Quaternion quaternion, out Matrix result)
281 {
282 throw new NotImplementedException();
283 }
284
285
286 public static Matrix CreateLookAt(Vector3 cameraPosition, Vector3 cameraTarget, Vector3 cameraUpVector)
287 {
288 throw new NotImplementedException();
289 }
290
291
292 public static void CreateLookAt(ref Vector3 cameraPosition, ref Vector3 cameraTarget, ref Vector3 cameraUpVector, out Matrix result)
293 {
294 throw new NotImplementedException();
295 }
296
297
298 public static Matrix CreateOrthographic(float width, float height, float zNearPlane, float zFarPlane)
299 {
300 throw new NotImplementedException();
301 }
302
303
304 public static void CreateOrthographic(float width, float height, float zNearPlane, float zFarPlane, out Matrix result)
305 {
306 throw new NotImplementedException();
307 }
308
309
310 public static Matrix CreateOrthographicOffCenter(float left, float right, float bottom, float top, float zNearPlane, float zFarPlane)
311 {
312 throw new NotImplementedException();
313 }
314
315
316 public static void CreateOrthographicOffCenter(float left, float right, float bottom, float top,
317 float zNearPlane, float zFarPlane, out Matrix result)
318 {
319 throw new NotImplementedException();
320 }
321
322
323 public static Matrix CreatePerspective(float width, float height, float zNearPlane, float zFarPlane)
324 {
325 throw new NotImplementedException();
326 }
327
328
329 public static void CreatePerspective(float width, float height, float zNearPlane, float zFarPlane, out Matrix result)
330 {
331 throw new NotImplementedException();
332 }
333
334
335 public static Matrix CreatePerspectiveFieldOfView(float fieldOfView, float aspectRatio, float zNearPlane, float zFarPlane)
336 {
337 throw new NotImplementedException();
338 }
339
340
341 public static void CreatePerspectiveFieldOfView(float fieldOfView, float aspectRatio, float nearPlaneDistance, float farPlaneDistance, out Matrix result)
342 {
343 throw new NotImplementedException();
344 }
345
346
347 public static Matrix CreatePerspectiveOffCenter(float left, float right, float bottom, float top, float zNearPlane, float zFarPlane)
348 {
349 throw new NotImplementedException();
350 }
351
352
353 public static void CreatePerspectiveOffCenter(float left, float right, float bottom, float top, float nearPlaneDistance, float farPlaneDistance, out Matrix result)
354 {
355 throw new NotImplementedException();
356 }
357
358
359 public static Matrix CreateRotationX(float radians)
360 {
361 throw new NotImplementedException();
362 }
363
364
365 public static void CreateRotationX(float radians, out Matrix result)
366 {
367 throw new NotImplementedException();
368 }
369
370
371 public static Matrix CreateRotationY(float radians)
372 {
373 throw new NotImplementedException();
374 }
375
376
377 public static void CreateRotationY(float radians, out Matrix result)
378 {
379 throw new NotImplementedException();
380 }
381
382
383 public static Matrix CreateRotationZ(float radians)
384 {
385 throw new NotImplementedException();
386 }
387
388
389 public static void CreateRotationZ(float radians, out Matrix result)
390 {
391 throw new NotImplementedException();
392 }
393
394
395 public static Matrix CreateScale(float scale)
396 {
397 throw new NotImplementedException();
398 }
399
400
401 public static void CreateScale(float scale, out Matrix result)
402 {
403 throw new NotImplementedException();
404 }
405
406
407 public static Matrix CreateScale(float xScale, float yScale, float zScale)
408 {
409 throw new NotImplementedException();
410 }
411
412
413 public static void CreateScale(float xScale, float yScale, float zScale, out Matrix result)
414 {
415 throw new NotImplementedException();
416 }
417
418
419 public static Matrix CreateScale(Vector3 scales)
420 {
421 throw new NotImplementedException();
422 }
423
424
425 public static void CreateScale(ref Vector3 scales, out Matrix result)
426 {
427 throw new NotImplementedException();
428 }
429
430
431 public static Matrix CreateTranslation(float xPosition, float yPosition, float zPosition)
432 {
433 throw new NotImplementedException();
434 }
435
436
437 public static void CreateTranslation(ref Vector3 position, out Matrix result)
438 {
439 throw new NotImplementedException();
440 }
441
442
443 public static Matrix CreateTranslation(Vector3 position)
444 {
445 throw new NotImplementedException();
446 }
447
448
449 public static void CreateTranslation(float xPosition, float yPosition, float zPosition, out Matrix result)
450 {
451 throw new NotImplementedException();
452 }
453
454
455 public float Determinant()
456 {
457 throw new NotImplementedException();
458 }
459
460
461 public static Matrix Divide(Matrix matrix1, Matrix matrix2)
462 {
463 throw new NotImplementedException();
464 }
465
466
467 public static void Divide(ref Matrix matrix1, ref Matrix matrix2, out Matrix result)
468 {
469 throw new NotImplementedException();
470 }
471
472
473 public static Matrix Divide(Matrix matrix1, float divider)
474 {
475 throw new NotImplementedException();
476 }
477
478
479 public static void Divide(ref Matrix matrix1, float divider, out Matrix result)
480 {
481 throw new NotImplementedException();
482 }
483
484
485 public bool Equals(Matrix other)
486 {
487 throw new NotImplementedException();
488 }
489
490
491 public override bool Equals(object obj)
492 {
493 throw new NotImplementedException();
494 }
495
496
497 public override int GetHashCode()
498 {
499 throw new NotImplementedException();
500 }
501
502
503 public static Matrix Invert(Matrix matrix)
504 {
505 throw new NotImplementedException();
506 }
507
508
509 public static void Invert(ref Matrix matrix, out Matrix result)
510 {
511 throw new NotImplementedException();
512 }
513
514
515 public static Matrix Lerp(Matrix matrix1, Matrix matrix2, float amount)
516 {
517 throw new NotImplementedException();
518 }
519
520
521 public static void Lerp(ref Matrix matrix1, ref Matrix matrix2, float amount, out Matrix result)
522 {
523 throw new NotImplementedException();
524 }
525
526 public static Matrix Multiply(Matrix matrix1, Matrix matrix2)
527 {
528 throw new NotImplementedException();
529 }
530
531
532 public static void Multiply(ref Matrix matrix1, ref Matrix matrix2, out Matrix result)
533 {
534 throw new NotImplementedException();
535 }
536
537
538 public static Matrix Multiply(Matrix matrix1, float factor)
539 {
540 throw new NotImplementedException();
541 }
542
543
544 public static void Multiply(ref Matrix matrix1, float factor, out Matrix result)
545 {
546 throw new NotImplementedException();
547 }
548
549
550 public static Matrix Negate(Matrix matrix)
551 {
552 throw new NotImplementedException();
553 }
554
555
556 public static void Negate(ref Matrix matrix, out Matrix result)
557 {
558 throw new NotImplementedException();
559 }
560
561
562 public static Matrix operator +(Matrix matrix1, Matrix matrix2)
563 {
564 throw new NotImplementedException();
565 }
566
567
568 public static Matrix operator /(Matrix matrix1, Matrix matrix2)
569 {
570 throw new NotImplementedException();
571 }
572
573
574 public static Matrix operator /(Matrix matrix1, float divider)
575 {
576 throw new NotImplementedException();
577 }
578
579
580 public static bool operator ==(Matrix matrix1, Matrix matrix2)
581 {
582 throw new NotImplementedException();
583 }
584
585
586 public static bool operator !=(Matrix matrix1, Matrix matrix2)
587 {
588 throw new NotImplementedException();
589 }
590
591
592 public static Matrix operator *(Matrix matrix1, Matrix matrix2)
593 {
594 //---
595 float[, ] arrayMatrix1 = new float[4, 4];
596 float[, ] arrayMatrix2 = new float[4, 4];
597 float[, ] arrayMatrixProduct = new float[4, 4];
598 arrayMatrix1[0, 0] = matrix1.M11; arrayMatrix1[0, 1] = matrix1.M12; arrayMatrix1[0, 2] = matrix1.M13; arrayMatrix1[0, 3] = matrix1.M14;
599 arrayMatrix1[1, 0] = matrix1.M21; arrayMatrix1[1, 1] = matrix1.M22; arrayMatrix1[1, 2] = matrix1.M23; arrayMatrix1[1, 3] = matrix1.M24;
600 arrayMatrix1[2, 0] = matrix1.M31; arrayMatrix1[2, 1] = matrix1.M32; arrayMatrix1[2, 2] = matrix1.M33; arrayMatrix1[2, 3] = matrix1.M34;
601 arrayMatrix1[3, 0] = matrix1.M41; arrayMatrix1[3, 1] = matrix1.M42; arrayMatrix1[3, 2] = matrix1.M43; arrayMatrix1[3, 3] = matrix1.M44;
602
603 arrayMatrix2[0, 0] = matrix2.M11; arrayMatrix2[0, 1] = matrix2.M12; arrayMatrix2[0, 2] = matrix2.M13; arrayMatrix2[0, 3] = matrix2.M14;
604 arrayMatrix2[1, 0] = matrix2.M21; arrayMatrix2[1, 1] = matrix2.M22; arrayMatrix2[1, 2] = matrix2.M23; arrayMatrix2[1, 3] = matrix2.M24;
605 arrayMatrix2[2, 0] = matrix2.M31; arrayMatrix2[2, 1] = matrix2.M32; arrayMatrix2[2, 2] = matrix2.M33; arrayMatrix2[2, 3] = matrix2.M34;
606 arrayMatrix2[3, 0] = matrix2.M41; arrayMatrix2[3, 1] = matrix2.M42; arrayMatrix2[3, 2] = matrix2.M43; arrayMatrix2[3, 3] = matrix2.M44;
607
608 int n = 4;
609 for (int i = 0; i < n; i++)
610 {
611 for (int j = 0; j < n; j++)
612 {
613 // (AB)[i,j] = Sum(k=0; k < 4; k++) { A[i,k] * B[k, j] }
614 for (int k = 0; k < n; k++)
615 {
616 arrayMatrixProduct[i, j] += arrayMatrix1[i, k] * arrayMatrix2[k, j];
617 }
618 }
619 }
620 return new Matrix( arrayMatrixProduct[0, 0], arrayMatrixProduct[0, 1], arrayMatrixProduct[0, 2], arrayMatrixProduct[0, 3],
621 arrayMatrixProduct[1, 0], arrayMatrixProduct[1, 1], arrayMatrixProduct[1, 2], arrayMatrixProduct[1, 3],
622 arrayMatrixProduct[2, 0], arrayMatrixProduct[2, 1], arrayMatrixProduct[2, 2], arrayMatrixProduct[2, 3],
623 arrayMatrixProduct[3, 1], arrayMatrixProduct[3, 1], arrayMatrixProduct[3, 2], arrayMatrixProduct[3, 3]);
624 //---
625 //throw new NotImplementedException();
626 }
627
628
629 public static Matrix operator *(Matrix matrix, float scaleFactor)
630 {
631 throw new NotImplementedException();
632 }
633
634
635 public static Matrix operator -(Matrix matrix1, Matrix matrix2)
636 {
637 throw new NotImplementedException();
638 }
639
640
641 public static Matrix operator -(Matrix matrix1)
642 {
643 throw new NotImplementedException();
644 }
645
646
647 public static Matrix Subtract(Matrix matrix1, Matrix matrix2)
648 {
649 throw new NotImplementedException();
650 }
651
652
653 public static void Subtract(ref Matrix matrix1, ref Matrix matrix2, out Matrix result)
654 {
655 throw new NotImplementedException();
656 }
657
658
659 public override string ToString()
660 {
661 throw new NotImplementedException();
662 }
663
664
665 public static Matrix Transpose(Matrix matrix)
666 {
667 //---
668 return new Matrix( matrix.M11, matrix.M21, matrix.M31, matrix.M41,
669 matrix.M12, matrix.M22, matrix.M32, matrix.M42,
670 matrix.M13, matrix.M23, matrix.M33, matrix.M43,
671 matrix.M14, matrix.M24, matrix.M34, matrix.M44);
672 //---
673 //throw new NotImplementedException();
674 }
675
676
677 public static void Transpose(ref Matrix matrix, out Matrix result)
678 {
679 throw new NotImplementedException();
680 }
681 #endregion Public Methods
682 }
683}