diff options
Diffstat (limited to 'libraries/ModifiedBulletX/ModifiedBulletX/LinearMath/Vector4.cs')
-rw-r--r-- | libraries/ModifiedBulletX/ModifiedBulletX/LinearMath/Vector4.cs | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/libraries/ModifiedBulletX/ModifiedBulletX/LinearMath/Vector4.cs b/libraries/ModifiedBulletX/ModifiedBulletX/LinearMath/Vector4.cs new file mode 100644 index 0000000..a64ce97 --- /dev/null +++ b/libraries/ModifiedBulletX/ModifiedBulletX/LinearMath/Vector4.cs | |||
@@ -0,0 +1,110 @@ | |||
1 | /* | ||
2 | Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru | ||
3 | Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com | ||
4 | |||
5 | This software is provided 'as-is', without any express or implied | ||
6 | warranty. In no event will the authors be held liable for any damages | ||
7 | arising from the use of this software. | ||
8 | |||
9 | Permission is granted to anyone to use this software for any purpose, | ||
10 | including commercial applications, and to alter it and redistribute it | ||
11 | freely, subject to the following restrictions: | ||
12 | |||
13 | 1. The origin of this software must not be misrepresented; you must not | ||
14 | claim that you wrote the original software. If you use this software | ||
15 | in a product, an acknowledgment in the product documentation would be | ||
16 | appreciated but is not required. | ||
17 | 2. Altered source versions must be plainly marked as such, and must not be | ||
18 | misrepresented as being the original software. | ||
19 | 3. This notice may not be removed or altered from any source distribution. | ||
20 | */ | ||
21 | |||
22 | using System; | ||
23 | using System.Collections.Generic; | ||
24 | using System.Text; | ||
25 | |||
26 | namespace XnaDevRu.BulletX.LinearMath | ||
27 | { | ||
28 | internal class Vector4 : Vector3 | ||
29 | { | ||
30 | public Vector4() { } | ||
31 | |||
32 | public Vector4(float x, float y, float z, float w) | ||
33 | : base(x, y, z) { W = w; } | ||
34 | |||
35 | public static Vector4 Absolute4(Vector4 a) | ||
36 | { | ||
37 | return new Vector4( | ||
38 | Math.Abs(a.X), | ||
39 | Math.Abs(a.Y), | ||
40 | Math.Abs(a.Z), | ||
41 | Math.Abs(a.W)); | ||
42 | } | ||
43 | |||
44 | public int MaxAxis4() | ||
45 | { | ||
46 | int maxIndex = -1; | ||
47 | float maxVal = -1e30f; | ||
48 | if (X > maxVal) | ||
49 | { | ||
50 | maxIndex = 0; | ||
51 | maxVal = X; | ||
52 | } | ||
53 | if (Y > maxVal) | ||
54 | { | ||
55 | maxIndex = 1; | ||
56 | maxVal = Y; | ||
57 | } | ||
58 | if (Z > maxVal) | ||
59 | { | ||
60 | maxIndex = 2; | ||
61 | maxVal = Z; | ||
62 | } | ||
63 | if (W > maxVal) | ||
64 | { | ||
65 | maxIndex = 3; | ||
66 | maxVal = W; | ||
67 | } | ||
68 | |||
69 | return maxIndex; | ||
70 | } | ||
71 | |||
72 | public int MinAxis4() | ||
73 | { | ||
74 | int minIndex = -1; | ||
75 | float minVal = 1e30f; | ||
76 | if (X < minVal) | ||
77 | { | ||
78 | minIndex = 0; | ||
79 | minVal = X; | ||
80 | } | ||
81 | if (Y < minVal) | ||
82 | { | ||
83 | minIndex = 1; | ||
84 | minVal = Y; | ||
85 | } | ||
86 | if (Z < minVal) | ||
87 | { | ||
88 | minIndex = 2; | ||
89 | minVal = Z; | ||
90 | } | ||
91 | if (W < minVal) | ||
92 | { | ||
93 | minIndex = 3; | ||
94 | minVal = W; | ||
95 | } | ||
96 | |||
97 | return minIndex; | ||
98 | } | ||
99 | |||
100 | public int ClosestAxis4() | ||
101 | { | ||
102 | return Absolute4(this).MaxAxis4(); | ||
103 | } | ||
104 | |||
105 | public static explicit operator MonoXnaCompactMaths.Vector4(Vector4 a) | ||
106 | { | ||
107 | return new MonoXnaCompactMaths.Vector4(a.X, a.Y, a.Z, a.W); | ||
108 | } | ||
109 | } | ||
110 | } | ||