diff options
Diffstat (limited to '')
-rw-r--r-- | libraries/ModifiedBulletX/ModifiedBulletX/LinearMath/Vector3.cs | 221 |
1 files changed, 0 insertions, 221 deletions
diff --git a/libraries/ModifiedBulletX/ModifiedBulletX/LinearMath/Vector3.cs b/libraries/ModifiedBulletX/ModifiedBulletX/LinearMath/Vector3.cs deleted file mode 100644 index adeec25..0000000 --- a/libraries/ModifiedBulletX/ModifiedBulletX/LinearMath/Vector3.cs +++ /dev/null | |||
@@ -1,221 +0,0 @@ | |||
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 Vector3 : QuadWord | ||
29 | { | ||
30 | public Vector3() { } | ||
31 | |||
32 | public Vector3(float x, float y, float z) | ||
33 | : base(x, y, z) { } | ||
34 | |||
35 | public void SetInterpolate3(Vector3 a, Vector3 b, float c) | ||
36 | { | ||
37 | float s = 1.0f - c; | ||
38 | X = s * a.X + c * b.X; | ||
39 | Y = s * a.Y + c * b.Y; | ||
40 | Z = s * a.Z + c * b.Z; | ||
41 | } | ||
42 | |||
43 | public float LengthSquared() | ||
44 | { | ||
45 | return Dot(this, this); | ||
46 | } | ||
47 | |||
48 | public float Length() | ||
49 | { | ||
50 | return (float)Math.Sqrt(LengthSquared()); | ||
51 | } | ||
52 | |||
53 | public int MinAxis() | ||
54 | { | ||
55 | return X < Y ? (X < Z ? 0 : 2) : (Y < Z ? 1 : 2); | ||
56 | } | ||
57 | |||
58 | public int MaxAxis() | ||
59 | { | ||
60 | return X < Y ? (Y < Z ? 2 : 1) : (X < Z ? 2 : 0); | ||
61 | } | ||
62 | |||
63 | public int FurthestAxis() | ||
64 | { | ||
65 | return Absolute(this).MinAxis(); | ||
66 | } | ||
67 | |||
68 | public int ClosestAxis() | ||
69 | { | ||
70 | return Absolute(this).MaxAxis(); | ||
71 | } | ||
72 | |||
73 | public Vector3 Rotate(Vector3 axis, float angle) | ||
74 | { | ||
75 | Vector3 o = axis * Dot(axis, this); | ||
76 | Vector3 x = this - o; | ||
77 | Vector3 y = Cross(axis, this); | ||
78 | |||
79 | return (o + x * (float)Math.Cos(angle) + y * (float)Math.Sin(angle)); | ||
80 | } | ||
81 | |||
82 | public static Vector3 Lerp(Vector3 a, Vector3 b, float c) | ||
83 | { | ||
84 | return new Vector3( | ||
85 | a.X + (b.X - a.X) * c, | ||
86 | a.Y + (b.Y - a.Y) * c, | ||
87 | a.Z + (b.Z - a.Z) * c); | ||
88 | } | ||
89 | |||
90 | public static float Angle(Vector3 a, Vector3 b) | ||
91 | { | ||
92 | float s = (float)Math.Sqrt(a.LengthSquared() * b.LengthSquared()); | ||
93 | if (s == 0) throw new DivideByZeroException(); | ||
94 | return (float)Math.Acos(Dot(a, b) / s); | ||
95 | } | ||
96 | |||
97 | public static Vector3 Absolute(Vector3 a) | ||
98 | { | ||
99 | return new Vector3( | ||
100 | Math.Abs(a.X), | ||
101 | Math.Abs(a.Y), | ||
102 | Math.Abs(a.Z)); | ||
103 | } | ||
104 | |||
105 | public static Vector3 Normalize(Vector3 a) | ||
106 | { | ||
107 | return a / a.Length(); | ||
108 | } | ||
109 | |||
110 | public static Vector3 Cross(Vector3 a, Vector3 b) | ||
111 | { | ||
112 | return new Vector3( | ||
113 | a.Y * b.Z - a.Z * b.Y, | ||
114 | a.Z * b.X - a.X * b.Z, | ||
115 | a.X * b.Y - a.Y * b.X); | ||
116 | } | ||
117 | |||
118 | public static float Dot(Vector3 a, Vector3 b) | ||
119 | { | ||
120 | return a.X * b.X + a.Y * b.Y + a.Z * b.Z; | ||
121 | } | ||
122 | |||
123 | public static float Triple(Vector3 a, Vector3 b, Vector3 c) | ||
124 | { | ||
125 | return a.X * (b.Y * c.Z - b.Z * c.Y) + | ||
126 | a.Y * (b.Z * c.X - b.X * c.Z) + | ||
127 | a.Z * (b.X * c.Y - b.Y * c.X); | ||
128 | } | ||
129 | |||
130 | public static float Distance(Vector3 a, Vector3 b) | ||
131 | { | ||
132 | return (b - a).Length(); | ||
133 | } | ||
134 | |||
135 | public static float DistanceSquared(Vector3 a, Vector3 b) | ||
136 | { | ||
137 | return (b - a).LengthSquared(); | ||
138 | } | ||
139 | |||
140 | public static Vector3 Rotate(Vector3 a, Vector3 axis, float angle) | ||
141 | { | ||
142 | Vector3 o = axis * Dot(axis, a); | ||
143 | Vector3 x = a - o; | ||
144 | Vector3 y = Cross(axis, a); | ||
145 | |||
146 | return (o + x * (float)Math.Cos(angle) + y * (float)Math.Sin(angle)); | ||
147 | } | ||
148 | |||
149 | public static Vector3 operator +(Vector3 a, Vector3 b) | ||
150 | { | ||
151 | return new Vector3(a.X + b.X, a.Y + b.Y, a.Z + b.Z); | ||
152 | } | ||
153 | |||
154 | public static Vector3 operator -(Vector3 a, Vector3 b) | ||
155 | { | ||
156 | return new Vector3(a.X - b.X, a.Y - b.Y, a.Z - b.Z); | ||
157 | } | ||
158 | |||
159 | public static Vector3 operator -(Vector3 a) | ||
160 | { | ||
161 | return new Vector3(-a.X, -a.Y, -a.Z); | ||
162 | } | ||
163 | |||
164 | public static Vector3 operator *(float b, Vector3 a) | ||
165 | { | ||
166 | return new Vector3(a.X * b, a.Y * b, a.Z * b); | ||
167 | } | ||
168 | |||
169 | public static Vector3 operator *(Vector3 a, float b) | ||
170 | { | ||
171 | return new Vector3(a.X * b, a.Y * b, a.Z * b); | ||
172 | } | ||
173 | |||
174 | public static Vector3 operator *(Vector3 a, Vector3 b) | ||
175 | { | ||
176 | return new Vector3(a.X * b.X, a.Y * b.Y, a.Z * b.Z); | ||
177 | } | ||
178 | |||
179 | public static Vector3 operator /(Vector3 a, float b) | ||
180 | { | ||
181 | if (b == 0) throw new DivideByZeroException(); | ||
182 | return new Vector3(a.X / b, a.Y / b, a.Z / b); | ||
183 | } | ||
184 | |||
185 | public static Vector3 operator /(Vector3 a, Vector3 b) | ||
186 | { | ||
187 | if (b.X == 0 || b.Y == 0 || b.Z == 0) throw new DivideByZeroException(); | ||
188 | return new Vector3(a.X / b.X, a.Y / b.Y, a.Z / b.Z); | ||
189 | } | ||
190 | |||
191 | public static bool operator ==(Vector3 a, Vector3 b) | ||
192 | { | ||
193 | return a.X == b.X && a.Y == b.Y && a.Z == b.Z; | ||
194 | } | ||
195 | |||
196 | public static bool operator !=(Vector3 a, Vector3 b) | ||
197 | { | ||
198 | return a.X != b.X || a.Y != b.Y || a.Z != b.Z; | ||
199 | } | ||
200 | |||
201 | public static explicit operator MonoXnaCompactMaths.Vector3(Vector3 a) | ||
202 | { | ||
203 | return new MonoXnaCompactMaths.Vector3(a.X, a.Y, a.Z); | ||
204 | } | ||
205 | |||
206 | public override bool Equals(object obj) | ||
207 | { | ||
208 | return object.Equals(this, obj); | ||
209 | } | ||
210 | |||
211 | public override int GetHashCode() | ||
212 | { | ||
213 | return X.GetHashCode() & Y.GetHashCode() & Z.GetHashCode(); | ||
214 | } | ||
215 | |||
216 | public override string ToString() | ||
217 | { | ||
218 | return string.Format("{0}, {1}, {2}", X, Y, Z); | ||
219 | } | ||
220 | } | ||
221 | } | ||