opensim – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | eva | 1 | /* |
2 | * Copyright (c) Contributors, http://opensimulator.org/ |
||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. |
||
4 | * |
||
5 | * Redistribution and use in source and binary forms, with or without |
||
6 | * modification, are permitted provided that the following conditions are met: |
||
7 | * * Redistributions of source code must retain the above copyright |
||
8 | * notice, this list of conditions and the following disclaimer. |
||
9 | * * Redistributions in binary form must reproduce the above copyright |
||
10 | * notice, this list of conditions and the following disclaimer in the |
||
11 | * documentation and/or other materials provided with the distribution. |
||
12 | * * Neither the name of the OpenSimulator Project nor the |
||
13 | * names of its contributors may be used to endorse or promote products |
||
14 | * derived from this software without specific prior written permission. |
||
15 | * |
||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY |
||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY |
||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||
26 | */ |
||
27 | |||
28 | using System; |
||
29 | |||
30 | namespace OpenSim.Region.Physics.Manager |
||
31 | { |
||
32 | /*public class PhysicsVector |
||
33 | { |
||
34 | public float X; |
||
35 | public float Y; |
||
36 | public float Z; |
||
37 | |||
38 | public Vector3() |
||
39 | { |
||
40 | } |
||
41 | |||
42 | public Vector3(float x, float y, float z) |
||
43 | { |
||
44 | X = x; |
||
45 | Y = y; |
||
46 | Z = z; |
||
47 | } |
||
48 | |||
49 | public Vector3(Vector3 pv) : this(pv.X, pv.Y, pv.Z) |
||
50 | { |
||
51 | } |
||
52 | |||
53 | public void setValues(float x, float y, float z) |
||
54 | { |
||
55 | X = x; |
||
56 | Y = y; |
||
57 | Z = z; |
||
58 | } |
||
59 | |||
60 | public static readonly PhysicsVector Zero = new PhysicsVector(0f, 0f, 0f); |
||
61 | |||
62 | public override string ToString() |
||
63 | { |
||
64 | return "<" + X + "," + Y + "," + Z + ">"; |
||
65 | } |
||
66 | |||
67 | /// <summary> |
||
68 | /// These routines are the easiest way to store XYZ values in an Vector3 without requiring 3 calls. |
||
69 | /// </summary> |
||
70 | /// <returns></returns> |
||
71 | public byte[] GetBytes() |
||
72 | { |
||
73 | byte[] byteArray = new byte[12]; |
||
74 | |||
75 | Buffer.BlockCopy(BitConverter.GetBytes(X), 0, byteArray, 0, 4); |
||
76 | Buffer.BlockCopy(BitConverter.GetBytes(Y), 0, byteArray, 4, 4); |
||
77 | Buffer.BlockCopy(BitConverter.GetBytes(Z), 0, byteArray, 8, 4); |
||
78 | |||
79 | if (!BitConverter.IsLittleEndian) |
||
80 | { |
||
81 | Array.Reverse(byteArray, 0, 4); |
||
82 | Array.Reverse(byteArray, 4, 4); |
||
83 | Array.Reverse(byteArray, 8, 4); |
||
84 | } |
||
85 | |||
86 | return byteArray; |
||
87 | } |
||
88 | |||
89 | public void FromBytes(byte[] byteArray, int pos) |
||
90 | { |
||
91 | byte[] conversionBuffer = null; |
||
92 | if (!BitConverter.IsLittleEndian) |
||
93 | { |
||
94 | // Big endian architecture |
||
95 | if (conversionBuffer == null) |
||
96 | conversionBuffer = new byte[12]; |
||
97 | |||
98 | Buffer.BlockCopy(byteArray, pos, conversionBuffer, 0, 12); |
||
99 | |||
100 | Array.Reverse(conversionBuffer, 0, 4); |
||
101 | Array.Reverse(conversionBuffer, 4, 4); |
||
102 | Array.Reverse(conversionBuffer, 8, 4); |
||
103 | |||
104 | X = BitConverter.ToSingle(conversionBuffer, 0); |
||
105 | Y = BitConverter.ToSingle(conversionBuffer, 4); |
||
106 | Z = BitConverter.ToSingle(conversionBuffer, 8); |
||
107 | } |
||
108 | else |
||
109 | { |
||
110 | // Little endian architecture |
||
111 | X = BitConverter.ToSingle(byteArray, pos); |
||
112 | Y = BitConverter.ToSingle(byteArray, pos + 4); |
||
113 | Z = BitConverter.ToSingle(byteArray, pos + 8); |
||
114 | } |
||
115 | } |
||
116 | |||
117 | // Operations |
||
118 | public static PhysicsVector operator +(Vector3 a, Vector3 b) |
||
119 | { |
||
120 | return new PhysicsVector(a.X + b.X, a.Y + b.Y, a.Z + b.Z); |
||
121 | } |
||
122 | |||
123 | public static PhysicsVector operator -(Vector3 a, Vector3 b) |
||
124 | { |
||
125 | return new PhysicsVector(a.X - b.X, a.Y - b.Y, a.Z - b.Z); |
||
126 | } |
||
127 | |||
128 | public static PhysicsVector cross(Vector3 a, Vector3 b) |
||
129 | { |
||
130 | 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); |
||
131 | } |
||
132 | |||
133 | public float length() |
||
134 | { |
||
135 | return (float) Math.Sqrt(X*X + Y*Y + Z*Z); |
||
136 | } |
||
137 | |||
138 | public static float GetDistanceTo(Vector3 a, Vector3 b) |
||
139 | { |
||
140 | float dx = a.X - b.X; |
||
141 | float dy = a.Y - b.Y; |
||
142 | float dz = a.Z - b.Z; |
||
143 | return (float) Math.Sqrt(dx * dx + dy * dy + dz * dz); |
||
144 | } |
||
145 | |||
146 | public static PhysicsVector operator /(Vector3 v, float f) |
||
147 | { |
||
148 | return new PhysicsVector(v.X/f, v.Y/f, v.Z/f); |
||
149 | } |
||
150 | |||
151 | public static PhysicsVector operator *(Vector3 v, float f) |
||
152 | { |
||
153 | return new PhysicsVector(v.X*f, v.Y*f, v.Z*f); |
||
154 | } |
||
155 | |||
156 | public static PhysicsVector operator *(float f, Vector3 v) |
||
157 | { |
||
158 | return v*f; |
||
159 | } |
||
160 | |||
161 | public static bool isFinite(Vector3 v) |
||
162 | { |
||
163 | if (v == null) |
||
164 | return false; |
||
165 | if (Single.IsInfinity(v.X) || Single.IsNaN(v.X)) |
||
166 | return false; |
||
167 | if (Single.IsInfinity(v.Y) || Single.IsNaN(v.Y)) |
||
168 | return false; |
||
169 | if (Single.IsInfinity(v.Z) || Single.IsNaN(v.Z)) |
||
170 | return false; |
||
171 | |||
172 | return true; |
||
173 | } |
||
174 | |||
175 | public virtual bool IsIdentical(Vector3 v, float tolerance) |
||
176 | { |
||
177 | PhysicsVector diff = this - v; |
||
178 | float d = diff.length(); |
||
179 | if (d <= tolerance) |
||
180 | return true; |
||
181 | |||
182 | return false; |
||
183 | } |
||
184 | |||
185 | }*/ |
||
186 | } |