aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/ModifiedBulletX/ModifiedBulletX/LinearMath/Vector3.cs
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/ModifiedBulletX/ModifiedBulletX/LinearMath/Vector3.cs')
-rw-r--r--libraries/ModifiedBulletX/ModifiedBulletX/LinearMath/Vector3.cs442
1 files changed, 221 insertions, 221 deletions
diff --git a/libraries/ModifiedBulletX/ModifiedBulletX/LinearMath/Vector3.cs b/libraries/ModifiedBulletX/ModifiedBulletX/LinearMath/Vector3.cs
index 79b1262..adeec25 100644
--- a/libraries/ModifiedBulletX/ModifiedBulletX/LinearMath/Vector3.cs
+++ b/libraries/ModifiedBulletX/ModifiedBulletX/LinearMath/Vector3.cs
@@ -1,221 +1,221 @@
1/* 1/*
2 Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru 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 3 Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com
4 4
5 This software is provided 'as-is', without any express or implied 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 6 warranty. In no event will the authors be held liable for any damages
7 arising from the use of this software. 7 arising from the use of this software.
8 8
9 Permission is granted to anyone to use this software for any purpose, 9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it 10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions: 11 freely, subject to the following restrictions:
12 12
13 1. The origin of this software must not be misrepresented; you must not 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 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 15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required. 16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be 17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software. 18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution. 19 3. This notice may not be removed or altered from any source distribution.
20*/ 20*/
21 21
22using System; 22using System;
23using System.Collections.Generic; 23using System.Collections.Generic;
24using System.Text; 24using System.Text;
25 25
26namespace XnaDevRu.BulletX.LinearMath 26namespace XnaDevRu.BulletX.LinearMath
27{ 27{
28 internal class Vector3 : QuadWord 28 internal class Vector3 : QuadWord
29 { 29 {
30 public Vector3() { } 30 public Vector3() { }
31 31
32 public Vector3(float x, float y, float z) 32 public Vector3(float x, float y, float z)
33 : base(x, y, z) { } 33 : base(x, y, z) { }
34 34
35 public void SetInterpolate3(Vector3 a, Vector3 b, float c) 35 public void SetInterpolate3(Vector3 a, Vector3 b, float c)
36 { 36 {
37 float s = 1.0f - c; 37 float s = 1.0f - c;
38 X = s * a.X + c * b.X; 38 X = s * a.X + c * b.X;
39 Y = s * a.Y + c * b.Y; 39 Y = s * a.Y + c * b.Y;
40 Z = s * a.Z + c * b.Z; 40 Z = s * a.Z + c * b.Z;
41 } 41 }
42 42
43 public float LengthSquared() 43 public float LengthSquared()
44 { 44 {
45 return Dot(this, this); 45 return Dot(this, this);
46 } 46 }
47 47
48 public float Length() 48 public float Length()
49 { 49 {
50 return (float)Math.Sqrt(LengthSquared()); 50 return (float)Math.Sqrt(LengthSquared());
51 } 51 }
52 52
53 public int MinAxis() 53 public int MinAxis()
54 { 54 {
55 return X < Y ? (X < Z ? 0 : 2) : (Y < Z ? 1 : 2); 55 return X < Y ? (X < Z ? 0 : 2) : (Y < Z ? 1 : 2);
56 } 56 }
57 57
58 public int MaxAxis() 58 public int MaxAxis()
59 { 59 {
60 return X < Y ? (Y < Z ? 2 : 1) : (X < Z ? 2 : 0); 60 return X < Y ? (Y < Z ? 2 : 1) : (X < Z ? 2 : 0);
61 } 61 }
62 62
63 public int FurthestAxis() 63 public int FurthestAxis()
64 { 64 {
65 return Absolute(this).MinAxis(); 65 return Absolute(this).MinAxis();
66 } 66 }
67 67
68 public int ClosestAxis() 68 public int ClosestAxis()
69 { 69 {
70 return Absolute(this).MaxAxis(); 70 return Absolute(this).MaxAxis();
71 } 71 }
72 72
73 public Vector3 Rotate(Vector3 axis, float angle) 73 public Vector3 Rotate(Vector3 axis, float angle)
74 { 74 {
75 Vector3 o = axis * Dot(axis, this); 75 Vector3 o = axis * Dot(axis, this);
76 Vector3 x = this - o; 76 Vector3 x = this - o;
77 Vector3 y = Cross(axis, this); 77 Vector3 y = Cross(axis, this);
78 78
79 return (o + x * (float)Math.Cos(angle) + y * (float)Math.Sin(angle)); 79 return (o + x * (float)Math.Cos(angle) + y * (float)Math.Sin(angle));
80 } 80 }
81 81
82 public static Vector3 Lerp(Vector3 a, Vector3 b, float c) 82 public static Vector3 Lerp(Vector3 a, Vector3 b, float c)
83 { 83 {
84 return new Vector3( 84 return new Vector3(
85 a.X + (b.X - a.X) * c, 85 a.X + (b.X - a.X) * c,
86 a.Y + (b.Y - a.Y) * c, 86 a.Y + (b.Y - a.Y) * c,
87 a.Z + (b.Z - a.Z) * c); 87 a.Z + (b.Z - a.Z) * c);
88 } 88 }
89 89
90 public static float Angle(Vector3 a, Vector3 b) 90 public static float Angle(Vector3 a, Vector3 b)
91 { 91 {
92 float s = (float)Math.Sqrt(a.LengthSquared() * b.LengthSquared()); 92 float s = (float)Math.Sqrt(a.LengthSquared() * b.LengthSquared());
93 if (s == 0) throw new DivideByZeroException(); 93 if (s == 0) throw new DivideByZeroException();
94 return (float)Math.Acos(Dot(a, b) / s); 94 return (float)Math.Acos(Dot(a, b) / s);
95 } 95 }
96 96
97 public static Vector3 Absolute(Vector3 a) 97 public static Vector3 Absolute(Vector3 a)
98 { 98 {
99 return new Vector3( 99 return new Vector3(
100 Math.Abs(a.X), 100 Math.Abs(a.X),
101 Math.Abs(a.Y), 101 Math.Abs(a.Y),
102 Math.Abs(a.Z)); 102 Math.Abs(a.Z));
103 } 103 }
104 104
105 public static Vector3 Normalize(Vector3 a) 105 public static Vector3 Normalize(Vector3 a)
106 { 106 {
107 return a / a.Length(); 107 return a / a.Length();
108 } 108 }
109 109
110 public static Vector3 Cross(Vector3 a, Vector3 b) 110 public static Vector3 Cross(Vector3 a, Vector3 b)
111 { 111 {
112 return new Vector3( 112 return new Vector3(
113 a.Y * b.Z - a.Z * b.Y, 113 a.Y * b.Z - a.Z * b.Y,
114 a.Z * b.X - a.X * b.Z, 114 a.Z * b.X - a.X * b.Z,
115 a.X * b.Y - a.Y * b.X); 115 a.X * b.Y - a.Y * b.X);
116 } 116 }
117 117
118 public static float Dot(Vector3 a, Vector3 b) 118 public static float Dot(Vector3 a, Vector3 b)
119 { 119 {
120 return a.X * b.X + a.Y * b.Y + a.Z * b.Z; 120 return a.X * b.X + a.Y * b.Y + a.Z * b.Z;
121 } 121 }
122 122
123 public static float Triple(Vector3 a, Vector3 b, Vector3 c) 123 public static float Triple(Vector3 a, Vector3 b, Vector3 c)
124 { 124 {
125 return a.X * (b.Y * c.Z - b.Z * c.Y) + 125 return a.X * (b.Y * c.Z - b.Z * c.Y) +
126 a.Y * (b.Z * c.X - b.X * c.Z) + 126 a.Y * (b.Z * c.X - b.X * c.Z) +
127 a.Z * (b.X * c.Y - b.Y * c.X); 127 a.Z * (b.X * c.Y - b.Y * c.X);
128 } 128 }
129 129
130 public static float Distance(Vector3 a, Vector3 b) 130 public static float Distance(Vector3 a, Vector3 b)
131 { 131 {
132 return (b - a).Length(); 132 return (b - a).Length();
133 } 133 }
134 134
135 public static float DistanceSquared(Vector3 a, Vector3 b) 135 public static float DistanceSquared(Vector3 a, Vector3 b)
136 { 136 {
137 return (b - a).LengthSquared(); 137 return (b - a).LengthSquared();
138 } 138 }
139 139
140 public static Vector3 Rotate(Vector3 a, Vector3 axis, float angle) 140 public static Vector3 Rotate(Vector3 a, Vector3 axis, float angle)
141 { 141 {
142 Vector3 o = axis * Dot(axis, a); 142 Vector3 o = axis * Dot(axis, a);
143 Vector3 x = a - o; 143 Vector3 x = a - o;
144 Vector3 y = Cross(axis, a); 144 Vector3 y = Cross(axis, a);
145 145
146 return (o + x * (float)Math.Cos(angle) + y * (float)Math.Sin(angle)); 146 return (o + x * (float)Math.Cos(angle) + y * (float)Math.Sin(angle));
147 } 147 }
148 148
149 public static Vector3 operator +(Vector3 a, Vector3 b) 149 public static Vector3 operator +(Vector3 a, Vector3 b)
150 { 150 {
151 return new Vector3(a.X + b.X, a.Y + b.Y, a.Z + b.Z); 151 return new Vector3(a.X + b.X, a.Y + b.Y, a.Z + b.Z);
152 } 152 }
153 153
154 public static Vector3 operator -(Vector3 a, Vector3 b) 154 public static Vector3 operator -(Vector3 a, Vector3 b)
155 { 155 {
156 return new Vector3(a.X - b.X, a.Y - b.Y, a.Z - b.Z); 156 return new Vector3(a.X - b.X, a.Y - b.Y, a.Z - b.Z);
157 } 157 }
158 158
159 public static Vector3 operator -(Vector3 a) 159 public static Vector3 operator -(Vector3 a)
160 { 160 {
161 return new Vector3(-a.X, -a.Y, -a.Z); 161 return new Vector3(-a.X, -a.Y, -a.Z);
162 } 162 }
163 163
164 public static Vector3 operator *(float b, Vector3 a) 164 public static Vector3 operator *(float b, Vector3 a)
165 { 165 {
166 return new Vector3(a.X * b, a.Y * b, a.Z * b); 166 return new Vector3(a.X * b, a.Y * b, a.Z * b);
167 } 167 }
168 168
169 public static Vector3 operator *(Vector3 a, float b) 169 public static Vector3 operator *(Vector3 a, float b)
170 { 170 {
171 return new Vector3(a.X * b, a.Y * b, a.Z * b); 171 return new Vector3(a.X * b, a.Y * b, a.Z * b);
172 } 172 }
173 173
174 public static Vector3 operator *(Vector3 a, Vector3 b) 174 public static Vector3 operator *(Vector3 a, Vector3 b)
175 { 175 {
176 return new Vector3(a.X * b.X, a.Y * b.Y, a.Z * b.Z); 176 return new Vector3(a.X * b.X, a.Y * b.Y, a.Z * b.Z);
177 } 177 }
178 178
179 public static Vector3 operator /(Vector3 a, float b) 179 public static Vector3 operator /(Vector3 a, float b)
180 { 180 {
181 if (b == 0) throw new DivideByZeroException(); 181 if (b == 0) throw new DivideByZeroException();
182 return new Vector3(a.X / b, a.Y / b, a.Z / b); 182 return new Vector3(a.X / b, a.Y / b, a.Z / b);
183 } 183 }
184 184
185 public static Vector3 operator /(Vector3 a, Vector3 b) 185 public static Vector3 operator /(Vector3 a, Vector3 b)
186 { 186 {
187 if (b.X == 0 || b.Y == 0 || b.Z == 0) throw new DivideByZeroException(); 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); 188 return new Vector3(a.X / b.X, a.Y / b.Y, a.Z / b.Z);
189 } 189 }
190 190
191 public static bool operator ==(Vector3 a, Vector3 b) 191 public static bool operator ==(Vector3 a, Vector3 b)
192 { 192 {
193 return a.X == b.X && a.Y == b.Y && a.Z == b.Z; 193 return a.X == b.X && a.Y == b.Y && a.Z == b.Z;
194 } 194 }
195 195
196 public static bool operator !=(Vector3 a, Vector3 b) 196 public static bool operator !=(Vector3 a, Vector3 b)
197 { 197 {
198 return a.X != b.X || a.Y != b.Y || a.Z != b.Z; 198 return a.X != b.X || a.Y != b.Y || a.Z != b.Z;
199 } 199 }
200 200
201 public static explicit operator MonoXnaCompactMaths.Vector3(Vector3 a) 201 public static explicit operator MonoXnaCompactMaths.Vector3(Vector3 a)
202 { 202 {
203 return new MonoXnaCompactMaths.Vector3(a.X, a.Y, a.Z); 203 return new MonoXnaCompactMaths.Vector3(a.X, a.Y, a.Z);
204 } 204 }
205 205
206 public override bool Equals(object obj) 206 public override bool Equals(object obj)
207 { 207 {
208 return object.Equals(this, obj); 208 return object.Equals(this, obj);
209 } 209 }
210 210
211 public override int GetHashCode() 211 public override int GetHashCode()
212 { 212 {
213 return X.GetHashCode() & Y.GetHashCode() & Z.GetHashCode(); 213 return X.GetHashCode() & Y.GetHashCode() & Z.GetHashCode();
214 } 214 }
215 215
216 public override string ToString() 216 public override string ToString()
217 { 217 {
218 return string.Format("{0}, {1}, {2}", X, Y, Z); 218 return string.Format("{0}, {1}, {2}", X, Y, Z);
219 } 219 }
220 } 220 }
221} 221}