diff options
Diffstat (limited to 'OpenSim/Region/Physics/Manager/PhysicsVector.cs')
-rw-r--r-- | OpenSim/Region/Physics/Manager/PhysicsVector.cs | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/OpenSim/Region/Physics/Manager/PhysicsVector.cs b/OpenSim/Region/Physics/Manager/PhysicsVector.cs index 7de37e4..ada2297 100644 --- a/OpenSim/Region/Physics/Manager/PhysicsVector.cs +++ b/OpenSim/Region/Physics/Manager/PhysicsVector.cs | |||
@@ -25,6 +25,10 @@ | |||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | * | 26 | * |
27 | */ | 27 | */ |
28 | |||
29 | using System; | ||
30 | |||
31 | |||
28 | namespace OpenSim.Region.Physics.Manager | 32 | namespace OpenSim.Region.Physics.Manager |
29 | { | 33 | { |
30 | public class PhysicsVector | 34 | public class PhysicsVector |
@@ -50,5 +54,51 @@ namespace OpenSim.Region.Physics.Manager | |||
50 | { | 54 | { |
51 | return "<" + X + "," + Y + "," + Z + ">"; | 55 | return "<" + X + "," + Y + "," + Z + ">"; |
52 | } | 56 | } |
57 | |||
58 | // Operations | ||
59 | public static PhysicsVector operator +(PhysicsVector a, PhysicsVector b) | ||
60 | { | ||
61 | return new PhysicsVector(a.X + b.X, a.Y + b.Y, a.Z + b.Z); | ||
62 | } | ||
63 | |||
64 | public static PhysicsVector operator -(PhysicsVector a, PhysicsVector b) | ||
65 | { | ||
66 | return new PhysicsVector(a.X - b.X, a.Y - b.Y, a.Z - b.Z); | ||
67 | } | ||
68 | |||
69 | public static PhysicsVector cross(PhysicsVector a, PhysicsVector b) | ||
70 | { | ||
71 | return new PhysicsVector(a.Y * b.Z - a.Z * b.Y, a.Z * b.X - a.X * b.Z, a.X * b.Y - a.Y * b.X); | ||
72 | } | ||
73 | |||
74 | public float length() | ||
75 | { | ||
76 | return (float)Math.Sqrt(X*X + Y*Y + Z*Z); | ||
77 | } | ||
78 | |||
79 | public static PhysicsVector operator / (PhysicsVector v, float f) | ||
80 | { | ||
81 | return new PhysicsVector(v.X / f, v.Y / f, v.Z / f); | ||
82 | } | ||
83 | |||
84 | public static PhysicsVector operator *(PhysicsVector v, float f) | ||
85 | { | ||
86 | return new PhysicsVector(v.X * f, v.Y * f, v.Z * f); | ||
87 | } | ||
88 | |||
89 | public static PhysicsVector operator *(float f, PhysicsVector v) | ||
90 | { | ||
91 | return v * f; | ||
92 | } | ||
93 | |||
94 | public virtual bool IsIdentical(PhysicsVector v, float tolerance) | ||
95 | { | ||
96 | PhysicsVector diff = this - v; | ||
97 | float d = diff.length(); | ||
98 | if (d < tolerance) | ||
99 | return true; | ||
100 | |||
101 | return false; | ||
102 | } | ||
53 | } | 103 | } |
54 | } \ No newline at end of file | 104 | } \ No newline at end of file |