aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/OdePlugin
diff options
context:
space:
mode:
authorlbsa712007-10-30 09:05:31 +0000
committerlbsa712007-10-30 09:05:31 +0000
commit67e12b95ea7b68f4904a7484d77ecfd787d16d0c (patch)
tree20b00d24c8a7617017960432ec044852e3ad5fa9 /OpenSim/Region/Physics/OdePlugin
parent* Deleted .user file (diff)
downloadopensim-SC_OLD-67e12b95ea7b68f4904a7484d77ecfd787d16d0c.zip
opensim-SC_OLD-67e12b95ea7b68f4904a7484d77ecfd787d16d0c.tar.gz
opensim-SC_OLD-67e12b95ea7b68f4904a7484d77ecfd787d16d0c.tar.bz2
opensim-SC_OLD-67e12b95ea7b68f4904a7484d77ecfd787d16d0c.tar.xz
* Optimized usings
* Shortened type references * Removed redundant 'this' qualifier
Diffstat (limited to 'OpenSim/Region/Physics/OdePlugin')
-rw-r--r--OpenSim/Region/Physics/OdePlugin/AssemblyInfo.cs22
-rw-r--r--OpenSim/Region/Physics/OdePlugin/Meshing/HelperTypes.cs72
-rw-r--r--OpenSim/Region/Physics/OdePlugin/Meshing/Meshmerizer.cs256
-rw-r--r--OpenSim/Region/Physics/OdePlugin/OdePlugin.cs274
4 files changed, 267 insertions, 357 deletions
diff --git a/OpenSim/Region/Physics/OdePlugin/AssemblyInfo.cs b/OpenSim/Region/Physics/OdePlugin/AssemblyInfo.cs
index 3f840cc..d110a17 100644
--- a/OpenSim/Region/Physics/OdePlugin/AssemblyInfo.cs
+++ b/OpenSim/Region/Physics/OdePlugin/AssemblyInfo.cs
@@ -27,24 +27,26 @@
27*/ 27*/
28using System.Reflection; 28using System.Reflection;
29using System.Runtime.InteropServices; 29using System.Runtime.InteropServices;
30
30// Information about this assembly is defined by the following 31// Information about this assembly is defined by the following
31// attributes. 32// attributes.
32// 33//
33// change them to the information which is associated with the assembly 34// change them to the information which is associated with the assembly
34// you compile. 35// you compile.
35 36
36[assembly: AssemblyTitle("RealPhysXplugin")] 37[assembly : AssemblyTitle("RealPhysXplugin")]
37[assembly: AssemblyDescription("")] 38[assembly : AssemblyDescription("")]
38[assembly: AssemblyConfiguration("")] 39[assembly : AssemblyConfiguration("")]
39[assembly: AssemblyCompany("")] 40[assembly : AssemblyCompany("")]
40[assembly: AssemblyProduct("RealPhysXplugin")] 41[assembly : AssemblyProduct("RealPhysXplugin")]
41[assembly: AssemblyCopyright("")] 42[assembly : AssemblyCopyright("")]
42[assembly: AssemblyTrademark("")] 43[assembly : AssemblyTrademark("")]
43[assembly: AssemblyCulture("")] 44[assembly : AssemblyCulture("")]
44 45
45// This sets the default COM visibility of types in the assembly to invisible. 46// This sets the default COM visibility of types in the assembly to invisible.
46// If you need to expose a type to COM, use [ComVisible(true)] on that type. 47// If you need to expose a type to COM, use [ComVisible(true)] on that type.
47[assembly: ComVisible(false)] 48
49[assembly : ComVisible(false)]
48 50
49// The assembly version has following format : 51// The assembly version has following format :
50// 52//
@@ -53,4 +55,4 @@ using System.Runtime.InteropServices;
53// You can specify all values by your own or you can build default build and revision 55// You can specify all values by your own or you can build default build and revision
54// numbers with the '*' character (the default): 56// numbers with the '*' character (the default):
55 57
56[assembly: AssemblyVersion("1.0.*")] 58[assembly : AssemblyVersion("1.0.*")] \ No newline at end of file
diff --git a/OpenSim/Region/Physics/OdePlugin/Meshing/HelperTypes.cs b/OpenSim/Region/Physics/OdePlugin/Meshing/HelperTypes.cs
index 2ace097..13184e2 100644
--- a/OpenSim/Region/Physics/OdePlugin/Meshing/HelperTypes.cs
+++ b/OpenSim/Region/Physics/OdePlugin/Meshing/HelperTypes.cs
@@ -27,10 +27,9 @@
27*/ 27*/
28 28
29using System; 29using System;
30using System.Globalization;
31using System.Diagnostics;
32using System.Collections.Generic; 30using System.Collections.Generic;
33 31using System.Diagnostics;
32using System.Globalization;
34using OpenSim.Region.Physics.Manager; 33using OpenSim.Region.Physics.Manager;
35 34
36public class Vertex : IComparable<Vertex> 35public class Vertex : IComparable<Vertex>
@@ -76,8 +75,6 @@ public class Vertex : IComparable<Vertex>
76 { 75 {
77 return me.CompareTo(other) < 0; 76 return me.CompareTo(other) < 0;
78 } 77 }
79
80
81} 78}
82 79
83public class Simplex : IComparable<Simplex> 80public class Simplex : IComparable<Simplex>
@@ -122,8 +119,7 @@ public class Simplex : IComparable<Simplex>
122 119
123 return 0; 120 return 0;
124 } 121 }
125 122} ;
126};
127 123
128public class Triangle 124public class Triangle
129{ 125{
@@ -131,9 +127,9 @@ public class Triangle
131 public Vertex v2; 127 public Vertex v2;
132 public Vertex v3; 128 public Vertex v3;
133 129
134 float radius_square; 130 private float radius_square;
135 float cx; 131 private float cx;
136 float cy; 132 private float cy;
137 133
138 public Triangle(Vertex _v1, Vertex _v2, Vertex _v3) 134 public Triangle(Vertex _v1, Vertex _v2, Vertex _v3)
139 { 135 {
@@ -149,18 +145,18 @@ public class Triangle
149 float dx, dy; 145 float dx, dy;
150 float dd; 146 float dd;
151 147
152 dx = x - this.cx; 148 dx = x - cx;
153 dy = y - this.cy; 149 dy = y - cy;
154 150
155 dd = dx * dx + dy * dy; 151 dd = dx*dx + dy*dy;
156 if (dd < this.radius_square) 152 if (dd < radius_square)
157 return true; 153 return true;
158 else 154 else
159 return false; 155 return false;
160 } 156 }
161 157
162 158
163 void CalcCircle() 159 private void CalcCircle()
164 { 160 {
165 // Calculate the center and the radius of a circle given by three points p1, p2, p3 161 // Calculate the center and the radius of a circle given by three points p1, p2, p3
166 // It is assumed, that the triangles vertices are already set correctly 162 // It is assumed, that the triangles vertices are already set correctly
@@ -198,8 +194,8 @@ public class Triangle
198 p3y = v3.point.Y; 194 p3y = v3.point.Y;
199 195
200 /* calc helping values first */ 196 /* calc helping values first */
201 c1 = (p1x * p1x + p1y * p1y - p2x * p2x - p2y * p2y) / 2; 197 c1 = (p1x*p1x + p1y*p1y - p2x*p2x - p2y*p2y)/2;
202 c2 = (p1x * p1x + p1y * p1y - p3x * p3x - p3y * p3y) / 2; 198 c2 = (p1x*p1x + p1y*p1y - p3x*p3x - p3y*p3y)/2;
203 199
204 v1x = p1x - p2x; 200 v1x = p1x - p2x;
205 v1y = p1y - p2y; 201 v1y = p1y - p2y;
@@ -207,35 +203,34 @@ public class Triangle
207 v2x = p1x - p3x; 203 v2x = p1x - p3x;
208 v2y = p1y - p3y; 204 v2y = p1y - p3y;
209 205
210 z = (c1 * v2x - c2 * v1x); 206 z = (c1*v2x - c2*v1x);
211 n = (v1y * v2x - v2y * v1x); 207 n = (v1y*v2x - v2y*v1x);
212 208
213 if (n == 0.0) // This is no triangle, i.e there are (at least) two points at the same location 209 if (n == 0.0) // This is no triangle, i.e there are (at least) two points at the same location
214 { 210 {
215 radius_square = 0.0f; 211 radius_square = 0.0f;
216 return; 212 return;
217 } 213 }
218 214
219 this.cy = (float)(z / n); 215 cy = (float) (z/n);
220 216
221 if (v2x != 0.0) 217 if (v2x != 0.0)
222 { 218 {
223 this.cx = (float)((c2 - v2y * this.cy) / v2x); 219 cx = (float) ((c2 - v2y*cy)/v2x);
224 } 220 }
225 else if (v1x != 0.0) 221 else if (v1x != 0.0)
226 { 222 {
227 this.cx = (float)((c1 - v1y * this.cy) / v1x); 223 cx = (float) ((c1 - v1y*cy)/v1x);
228 } 224 }
229 else 225 else
230 { 226 {
231 Debug.Assert(false, "Malformed triangle"); /* Both terms zero means nothing good */ 227 Debug.Assert(false, "Malformed triangle"); /* Both terms zero means nothing good */
232 } 228 }
233 229
234 rx = (p1x - this.cx); 230 rx = (p1x - cx);
235 ry = (p1y - this.cy); 231 ry = (p1y - cy);
236
237 this.radius_square = (float)(rx * rx + ry * ry);
238 232
233 radius_square = (float) (rx*rx + ry*ry);
239 } 234 }
240 235
241 public List<Simplex> GetSimplices() 236 public List<Simplex> GetSimplices()
@@ -254,17 +249,18 @@ public class Triangle
254 249
255 public override String ToString() 250 public override String ToString()
256 { 251 {
257
258 NumberFormatInfo nfi = new NumberFormatInfo(); 252 NumberFormatInfo nfi = new NumberFormatInfo();
259 nfi.CurrencyDecimalDigits = 2; 253 nfi.CurrencyDecimalDigits = 2;
260 nfi.CurrencyDecimalSeparator = "."; 254 nfi.CurrencyDecimalSeparator = ".";
261 255
262 String s1 = "<" + v1.point.X.ToString(nfi) + "," + v1.point.Y.ToString(nfi) + "," + v1.point.Z.ToString(nfi) + ">"; 256 String s1 = "<" + v1.point.X.ToString(nfi) + "," + v1.point.Y.ToString(nfi) + "," + v1.point.Z.ToString(nfi) +
263 String s2 = "<" + v2.point.X.ToString(nfi) + "," + v2.point.Y.ToString(nfi) + "," + v2.point.Z.ToString(nfi) + ">"; 257 ">";
264 String s3 = "<" + v3.point.X.ToString(nfi) + "," + v3.point.Y.ToString(nfi) + "," + v3.point.Z.ToString(nfi) + ">"; 258 String s2 = "<" + v2.point.X.ToString(nfi) + "," + v2.point.Y.ToString(nfi) + "," + v2.point.Z.ToString(nfi) +
259 ">";
260 String s3 = "<" + v3.point.X.ToString(nfi) + "," + v3.point.Y.ToString(nfi) + "," + v3.point.Z.ToString(nfi) +
261 ">";
265 262
266 return s1 + ";" + s2 + ";" + s3; 263 return s1 + ";" + s2 + ";" + s3;
267
268 } 264 }
269 265
270 public PhysicsVector getNormal() 266 public PhysicsVector getNormal()
@@ -281,12 +277,12 @@ public class Triangle
281 // Cross product for normal 277 // Cross product for normal
282 PhysicsVector n = new PhysicsVector(); 278 PhysicsVector n = new PhysicsVector();
283 float nx, ny, nz; 279 float nx, ny, nz;
284 n.X = e1.Y * e2.Z - e1.Z * e2.Y; 280 n.X = e1.Y*e2.Z - e1.Z*e2.Y;
285 n.Y = e1.Z * e2.X - e1.X * e2.Z; 281 n.Y = e1.Z*e2.X - e1.X*e2.Z;
286 n.Z = e1.X * e2.Y - e1.Y * e2.X; 282 n.Z = e1.X*e2.Y - e1.Y*e2.X;
287 283
288 // Length 284 // Length
289 float l = (float)Math.Sqrt(n.X * n.X + n.Y * n.Y + n.Z * n.Z); 285 float l = (float) Math.Sqrt(n.X*n.X + n.Y*n.Y + n.Z*n.Z);
290 286
291 // Normalized "normal" 287 // Normalized "normal"
292 n.X /= l; 288 n.X /= l;
@@ -303,6 +299,4 @@ public class Triangle
303 v1 = v2; 299 v1 = v2;
304 v2 = vt; 300 v2 = vt;
305 } 301 }
306} 302} \ No newline at end of file
307
308
diff --git a/OpenSim/Region/Physics/OdePlugin/Meshing/Meshmerizer.cs b/OpenSim/Region/Physics/OdePlugin/Meshing/Meshmerizer.cs
index dd18e24..46de15e 100644
--- a/OpenSim/Region/Physics/OdePlugin/Meshing/Meshmerizer.cs
+++ b/OpenSim/Region/Physics/OdePlugin/Meshing/Meshmerizer.cs
@@ -27,12 +27,8 @@
27*/ 27*/
28 28
29using System; 29using System;
30using System.Globalization;
31using System.Diagnostics;
32using System.Collections.Generic; 30using System.Collections.Generic;
33using System.Text;
34using System.Runtime.InteropServices; 31using System.Runtime.InteropServices;
35
36using OpenSim.Framework; 32using OpenSim.Framework;
37using OpenSim.Region.Physics.Manager; 33using OpenSim.Region.Physics.Manager;
38 34
@@ -75,14 +71,14 @@ namespace OpenSim.Region.Physics.OdePlugin
75 71
76 public float[] getVertexListAsFloat() 72 public float[] getVertexListAsFloat()
77 { 73 {
78 float[] result = new float[vertices.Count * 3]; 74 float[] result = new float[vertices.Count*3];
79 for (int i = 0; i < vertices.Count; i++) 75 for (int i = 0; i < vertices.Count; i++)
80 { 76 {
81 Vertex v = vertices[i]; 77 Vertex v = vertices[i];
82 PhysicsVector point = v.point; 78 PhysicsVector point = v.point;
83 result[3 * i + 0] = point.X; 79 result[3*i + 0] = point.X;
84 result[3 * i + 1] = point.Y; 80 result[3*i + 1] = point.Y;
85 result[3 * i + 2] = point.Z; 81 result[3*i + 2] = point.Z;
86 } 82 }
87 GCHandle.Alloc(result, GCHandleType.Pinned); 83 GCHandle.Alloc(result, GCHandleType.Pinned);
88 return result; 84 return result;
@@ -90,13 +86,13 @@ namespace OpenSim.Region.Physics.OdePlugin
90 86
91 public int[] getIndexListAsInt() 87 public int[] getIndexListAsInt()
92 { 88 {
93 int[] result = new int[triangles.Count * 3]; 89 int[] result = new int[triangles.Count*3];
94 for (int i = 0; i < triangles.Count; i++) 90 for (int i = 0; i < triangles.Count; i++)
95 { 91 {
96 Triangle t = triangles[i]; 92 Triangle t = triangles[i];
97 result[3 * i + 0] = vertices.IndexOf(t.v1); 93 result[3*i + 0] = vertices.IndexOf(t.v1);
98 result[3 * i + 1] = vertices.IndexOf(t.v2); 94 result[3*i + 1] = vertices.IndexOf(t.v2);
99 result[3 * i + 2] = vertices.IndexOf(t.v3); 95 result[3*i + 2] = vertices.IndexOf(t.v3);
100 } 96 }
101 GCHandle.Alloc(result, GCHandleType.Pinned); 97 GCHandle.Alloc(result, GCHandleType.Pinned);
102 return result; 98 return result;
@@ -110,16 +106,13 @@ namespace OpenSim.Region.Physics.OdePlugin
110 106
111 foreach (Triangle t in newMesh.triangles) 107 foreach (Triangle t in newMesh.triangles)
112 Add(t); 108 Add(t);
113
114 } 109 }
115 } 110 }
116 111
117 112
118
119 public class Meshmerizer 113 public class Meshmerizer
120 { 114 {
121 115 private static List<Triangle> FindInfluencedTriangles(List<Triangle> triangles, Vertex v)
122 static List<Triangle> FindInfluencedTriangles(List<Triangle> triangles, Vertex v)
123 { 116 {
124 List<Triangle> influenced = new List<Triangle>(); 117 List<Triangle> influenced = new List<Triangle>();
125 foreach (Triangle t in triangles) 118 foreach (Triangle t in triangles)
@@ -133,9 +126,10 @@ namespace OpenSim.Region.Physics.OdePlugin
133 } 126 }
134 return influenced; 127 return influenced;
135 } 128 }
136 129
137 130
138 static void InsertVertices(List<Vertex> vertices, int usedForSeed, List<Triangle> triangles, List<int> innerBorders) 131 private static void InsertVertices(List<Vertex> vertices, int usedForSeed, List<Triangle> triangles,
132 List<int> innerBorders)
139 { 133 {
140 // This is a variant of the delaunay algorithm 134 // This is a variant of the delaunay algorithm
141 // each time a new vertex is inserted, all triangles that are influenced by it are deleted 135 // each time a new vertex is inserted, all triangles that are influenced by it are deleted
@@ -143,7 +137,7 @@ namespace OpenSim.Region.Physics.OdePlugin
143 // It is not very time efficient but easy to implement. 137 // It is not very time efficient but easy to implement.
144 138
145 int iCurrentVertex; 139 int iCurrentVertex;
146 int iMaxVertex=vertices.Count; 140 int iMaxVertex = vertices.Count;
147 for (iCurrentVertex = usedForSeed; iCurrentVertex < iMaxVertex; iCurrentVertex++) 141 for (iCurrentVertex = usedForSeed; iCurrentVertex < iMaxVertex; iCurrentVertex++)
148 { 142 {
149 // Background: A triangle mesh fulfills the delaunay condition if (iff!) 143 // Background: A triangle mesh fulfills the delaunay condition if (iff!)
@@ -154,8 +148,8 @@ namespace OpenSim.Region.Physics.OdePlugin
154 // do not fulfill this condition with respect to the new triangle 148 // do not fulfill this condition with respect to the new triangle
155 149
156 // Find the triangles that are influenced by the new vertex 150 // Find the triangles that are influenced by the new vertex
157 Vertex v=vertices[iCurrentVertex]; 151 Vertex v = vertices[iCurrentVertex];
158 List<Triangle> influencedTriangles=FindInfluencedTriangles(triangles, v); 152 List<Triangle> influencedTriangles = FindInfluencedTriangles(triangles, v);
159 153
160 List<Simplex> simplices = new List<Simplex>(); 154 List<Simplex> simplices = new List<Simplex>();
161 155
@@ -175,10 +169,10 @@ namespace OpenSim.Region.Physics.OdePlugin
175 // Look for duplicate simplices here. 169 // Look for duplicate simplices here.
176 // Remember, they are directly side by side in the list right now 170 // Remember, they are directly side by side in the list right now
177 int iSimplex; 171 int iSimplex;
178 List<Simplex> innerSimplices=new List<Simplex>(); 172 List<Simplex> innerSimplices = new List<Simplex>();
179 for (iSimplex = 1; iSimplex < simplices.Count; iSimplex++) // Startindex=1, so we can refer backwards 173 for (iSimplex = 1; iSimplex < simplices.Count; iSimplex++) // Startindex=1, so we can refer backwards
180 { 174 {
181 if (simplices[iSimplex - 1].CompareTo(simplices[iSimplex])==0) 175 if (simplices[iSimplex - 1].CompareTo(simplices[iSimplex]) == 0)
182 { 176 {
183 innerSimplices.Add(simplices[iSimplex - 1]); 177 innerSimplices.Add(simplices[iSimplex - 1]);
184 innerSimplices.Add(simplices[iSimplex]); 178 innerSimplices.Add(simplices[iSimplex]);
@@ -187,7 +181,7 @@ namespace OpenSim.Region.Physics.OdePlugin
187 181
188 foreach (Simplex s in innerSimplices) 182 foreach (Simplex s in innerSimplices)
189 { 183 {
190 simplices.Remove(s); 184 simplices.Remove(s);
191 } 185 }
192 186
193 // each simplex still in the list belongs to the hull of the region in question 187 // each simplex still in the list belongs to the hull of the region in question
@@ -210,7 +204,7 @@ namespace OpenSim.Region.Physics.OdePlugin
210 foreach (Triangle t in triangles) 204 foreach (Triangle t in triangles)
211 { 205 {
212 if ( 206 if (
213 innerBorders.Contains(vertices.IndexOf(t.v1)) 207 innerBorders.Contains(vertices.IndexOf(t.v1))
214 && innerBorders.Contains(vertices.IndexOf(t.v2)) 208 && innerBorders.Contains(vertices.IndexOf(t.v2))
215 && innerBorders.Contains(vertices.IndexOf(t.v3)) 209 && innerBorders.Contains(vertices.IndexOf(t.v3))
216 ) 210 )
@@ -223,18 +217,18 @@ namespace OpenSim.Region.Physics.OdePlugin
223 } 217 }
224 218
225 219
226 static Mesh CreateBoxMeshX(PrimitiveBaseShape primShape, PhysicsVector size) 220 private static Mesh CreateBoxMeshX(PrimitiveBaseShape primShape, PhysicsVector size)
227 // Builds the x (+ and -) surfaces of a box shaped prim 221 // Builds the x (+ and -) surfaces of a box shaped prim
228 { 222 {
229 UInt16 hollowFactor = primShape.ProfileHollow; 223 UInt16 hollowFactor = primShape.ProfileHollow;
230 Mesh meshMX = new Mesh(); 224 Mesh meshMX = new Mesh();
231 225
232 226
233 // Surface 0, -X 227 // Surface 0, -X
234 meshMX.Add(new Vertex("-X-Y-Z", -size.X / 2.0f, -size.Y / 2.0f, -size.Z / 2.0f)); 228 meshMX.Add(new Vertex("-X-Y-Z", -size.X/2.0f, -size.Y/2.0f, -size.Z/2.0f));
235 meshMX.Add(new Vertex("-X+Y-Z", -size.X / 2.0f, +size.Y / 2.0f, -size.Z / 2.0f)); 229 meshMX.Add(new Vertex("-X+Y-Z", -size.X/2.0f, +size.Y/2.0f, -size.Z/2.0f));
236 meshMX.Add(new Vertex("-X-Y+Z", -size.X / 2.0f, -size.Y / 2.0f, +size.Z / 2.0f)); 230 meshMX.Add(new Vertex("-X-Y+Z", -size.X/2.0f, -size.Y/2.0f, +size.Z/2.0f));
237 meshMX.Add(new Vertex("-X+Y+Z", -size.X / 2.0f, +size.Y / 2.0f, +size.Z / 2.0f)); 231 meshMX.Add(new Vertex("-X+Y+Z", -size.X/2.0f, +size.Y/2.0f, +size.Z/2.0f));
238 232
239 meshMX.Add(new Triangle(meshMX.vertices[0], meshMX.vertices[2], meshMX.vertices[1])); 233 meshMX.Add(new Triangle(meshMX.vertices[0], meshMX.vertices[2], meshMX.vertices[1]));
240 meshMX.Add(new Triangle(meshMX.vertices[1], meshMX.vertices[2], meshMX.vertices[3])); 234 meshMX.Add(new Triangle(meshMX.vertices[1], meshMX.vertices[2], meshMX.vertices[3]));
@@ -242,10 +236,10 @@ namespace OpenSim.Region.Physics.OdePlugin
242 236
243 Mesh meshPX = new Mesh(); 237 Mesh meshPX = new Mesh();
244 // Surface 1, +X 238 // Surface 1, +X
245 meshPX.Add(new Vertex("+X-Y-Z", +size.X / 2.0f, -size.Y / 2.0f, -size.Z / 2.0f)); 239 meshPX.Add(new Vertex("+X-Y-Z", +size.X/2.0f, -size.Y/2.0f, -size.Z/2.0f));
246 meshPX.Add(new Vertex("+X+Y-Z", +size.X / 2.0f, +size.Y / 2.0f, -size.Z / 2.0f)); 240 meshPX.Add(new Vertex("+X+Y-Z", +size.X/2.0f, +size.Y/2.0f, -size.Z/2.0f));
247 meshPX.Add(new Vertex("+X-Y+Z", +size.X / 2.0f, -size.Y / 2.0f, +size.Z / 2.0f)); 241 meshPX.Add(new Vertex("+X-Y+Z", +size.X/2.0f, -size.Y/2.0f, +size.Z/2.0f));
248 meshPX.Add(new Vertex("+X+Y+Z", +size.X / 2.0f, +size.Y / 2.0f, +size.Z / 2.0f)); 242 meshPX.Add(new Vertex("+X+Y+Z", +size.X/2.0f, +size.Y/2.0f, +size.Z/2.0f));
249 243
250 244
251 meshPX.Add(new Triangle(meshPX.vertices[0], meshPX.vertices[1], meshPX.vertices[2])); 245 meshPX.Add(new Triangle(meshPX.vertices[0], meshPX.vertices[1], meshPX.vertices[2]));
@@ -254,17 +248,17 @@ namespace OpenSim.Region.Physics.OdePlugin
254 248
255 if (hollowFactor > 0) 249 if (hollowFactor > 0)
256 { 250 {
257 float hollowFactorF = (float)hollowFactor / (float)50000; 251 float hollowFactorF = (float) hollowFactor/(float) 50000;
258 252
259 Vertex IPP; 253 Vertex IPP;
260 Vertex IPM; 254 Vertex IPM;
261 Vertex IMP; 255 Vertex IMP;
262 Vertex IMM; 256 Vertex IMM;
263 257
264 IPP = new Vertex("Inner-X+Y+Z", -size.X * hollowFactorF / 2.0f, +size.Y * hollowFactorF / 2.0f, +size.Z / 2.0f); 258 IPP = new Vertex("Inner-X+Y+Z", -size.X*hollowFactorF/2.0f, +size.Y*hollowFactorF/2.0f, +size.Z/2.0f);
265 IPM = new Vertex("Inner-X+Y-Z", -size.X * hollowFactorF / 2.0f, +size.Y * hollowFactorF / 2.0f, -size.Z / 2.0f); 259 IPM = new Vertex("Inner-X+Y-Z", -size.X*hollowFactorF/2.0f, +size.Y*hollowFactorF/2.0f, -size.Z/2.0f);
266 IMP = new Vertex("Inner-X-Y+Z", -size.X * hollowFactorF / 2.0f, -size.Y * hollowFactorF / 2.0f, +size.Z / 2.0f); 260 IMP = new Vertex("Inner-X-Y+Z", -size.X*hollowFactorF/2.0f, -size.Y*hollowFactorF/2.0f, +size.Z/2.0f);
267 IMM = new Vertex("Inner-X-Y-Z", -size.X * hollowFactorF / 2.0f, -size.Y * hollowFactorF / 2.0f, -size.Z / 2.0f); 261 IMM = new Vertex("Inner-X-Y-Z", -size.X*hollowFactorF/2.0f, -size.Y*hollowFactorF/2.0f, -size.Z/2.0f);
268 262
269 meshMX.Add(IPP); 263 meshMX.Add(IPP);
270 meshMX.Add(IPM); 264 meshMX.Add(IPM);
@@ -280,11 +274,10 @@ namespace OpenSim.Region.Physics.OdePlugin
280 } 274 }
281 275
282 276
283 277 IPP = new Vertex("Inner+X+Y+Z", +size.X*hollowFactorF/2.0f, +size.Y*hollowFactorF/2.0f, +size.Z/2.0f);
284 IPP = new Vertex("Inner+X+Y+Z", +size.X * hollowFactorF / 2.0f, +size.Y * hollowFactorF / 2.0f, +size.Z / 2.0f); 278 IPM = new Vertex("Inner+X+Y-Z", +size.X*hollowFactorF/2.0f, +size.Y*hollowFactorF/2.0f, -size.Z/2.0f);
285 IPM = new Vertex("Inner+X+Y-Z", +size.X * hollowFactorF / 2.0f, +size.Y * hollowFactorF / 2.0f, -size.Z / 2.0f); 279 IMP = new Vertex("Inner+X-Y+Z", +size.X*hollowFactorF/2.0f, -size.Y*hollowFactorF/2.0f, +size.Z/2.0f);
286 IMP = new Vertex("Inner+X-Y+Z", +size.X * hollowFactorF / 2.0f, -size.Y * hollowFactorF / 2.0f, +size.Z / 2.0f); 280 IMM = new Vertex("Inner+X-Y-Z", +size.X*hollowFactorF/2.0f, -size.Y*hollowFactorF/2.0f, -size.Z/2.0f);
287 IMM = new Vertex("Inner+X-Y-Z", +size.X * hollowFactorF / 2.0f, -size.Y * hollowFactorF / 2.0f, -size.Z / 2.0f);
288 281
289 meshPX.Add(IPP); 282 meshPX.Add(IPP);
290 meshPX.Add(IPM); 283 meshPX.Add(IPM);
@@ -308,18 +301,17 @@ namespace OpenSim.Region.Physics.OdePlugin
308 } 301 }
309 302
310 303
311 304 private static Mesh CreateBoxMeshY(PrimitiveBaseShape primShape, PhysicsVector size)
312 static Mesh CreateBoxMeshY(PrimitiveBaseShape primShape, PhysicsVector size) 305 // Builds the y (+ and -) surfaces of a box shaped prim
313 // Builds the y (+ and -) surfaces of a box shaped prim
314 { 306 {
315 UInt16 hollowFactor = primShape.ProfileHollow; 307 UInt16 hollowFactor = primShape.ProfileHollow;
316 308
317 // (M)inus Y 309 // (M)inus Y
318 Mesh MeshMY = new Mesh(); 310 Mesh MeshMY = new Mesh();
319 MeshMY.Add(new Vertex("-X-Y-Z", -size.X / 2.0f, -size.Y / 2.0f, -size.Z / 2.0f)); 311 MeshMY.Add(new Vertex("-X-Y-Z", -size.X/2.0f, -size.Y/2.0f, -size.Z/2.0f));
320 MeshMY.Add(new Vertex("+X-Y-Z", +size.X / 2.0f, -size.Y / 2.0f, -size.Z / 2.0f)); 312 MeshMY.Add(new Vertex("+X-Y-Z", +size.X/2.0f, -size.Y/2.0f, -size.Z/2.0f));
321 MeshMY.Add(new Vertex("-X-Y+Z", -size.X / 2.0f, -size.Y / 2.0f, +size.Z / 2.0f)); 313 MeshMY.Add(new Vertex("-X-Y+Z", -size.X/2.0f, -size.Y/2.0f, +size.Z/2.0f));
322 MeshMY.Add(new Vertex("+X-Y+Z", +size.X / 2.0f, -size.Y / 2.0f, +size.Z / 2.0f)); 314 MeshMY.Add(new Vertex("+X-Y+Z", +size.X/2.0f, -size.Y/2.0f, +size.Z/2.0f));
323 315
324 MeshMY.Add(new Triangle(MeshMY.vertices[0], MeshMY.vertices[1], MeshMY.vertices[2])); 316 MeshMY.Add(new Triangle(MeshMY.vertices[0], MeshMY.vertices[1], MeshMY.vertices[2]));
325 MeshMY.Add(new Triangle(MeshMY.vertices[2], MeshMY.vertices[1], MeshMY.vertices[3])); 317 MeshMY.Add(new Triangle(MeshMY.vertices[2], MeshMY.vertices[1], MeshMY.vertices[3]));
@@ -327,27 +319,27 @@ namespace OpenSim.Region.Physics.OdePlugin
327 // (P)lus Y 319 // (P)lus Y
328 Mesh MeshPY = new Mesh(); 320 Mesh MeshPY = new Mesh();
329 321
330 MeshPY.Add(new Vertex("-X+Y-Z", -size.X / 2.0f, +size.Y / 2.0f, -size.Z / 2.0f)); 322 MeshPY.Add(new Vertex("-X+Y-Z", -size.X/2.0f, +size.Y/2.0f, -size.Z/2.0f));
331 MeshPY.Add(new Vertex("+X+Y-Z", +size.X / 2.0f, +size.Y / 2.0f, -size.Z / 2.0f)); 323 MeshPY.Add(new Vertex("+X+Y-Z", +size.X/2.0f, +size.Y/2.0f, -size.Z/2.0f));
332 MeshPY.Add(new Vertex("-X+Y+Z", -size.X / 2.0f, +size.Y / 2.0f, +size.Z / 2.0f)); 324 MeshPY.Add(new Vertex("-X+Y+Z", -size.X/2.0f, +size.Y/2.0f, +size.Z/2.0f));
333 MeshPY.Add(new Vertex("+X+Y+Z", +size.X / 2.0f, +size.Y / 2.0f, +size.Z / 2.0f)); 325 MeshPY.Add(new Vertex("+X+Y+Z", +size.X/2.0f, +size.Y/2.0f, +size.Z/2.0f));
334 326
335 MeshPY.Add(new Triangle(MeshPY.vertices[1], MeshPY.vertices[0], MeshPY.vertices[2])); 327 MeshPY.Add(new Triangle(MeshPY.vertices[1], MeshPY.vertices[0], MeshPY.vertices[2]));
336 MeshPY.Add(new Triangle(MeshPY.vertices[1], MeshPY.vertices[2], MeshPY.vertices[3])); 328 MeshPY.Add(new Triangle(MeshPY.vertices[1], MeshPY.vertices[2], MeshPY.vertices[3]));
337 329
338 if (hollowFactor > 0) 330 if (hollowFactor > 0)
339 { 331 {
340 float hollowFactorF = (float)hollowFactor / (float)50000; 332 float hollowFactorF = (float) hollowFactor/(float) 50000;
341 333
342 Vertex IPP; 334 Vertex IPP;
343 Vertex IPM; 335 Vertex IPM;
344 Vertex IMP; 336 Vertex IMP;
345 Vertex IMM; 337 Vertex IMM;
346 338
347 IPP = new Vertex("Inner+X-Y+Z", +size.X * hollowFactorF / 2.0f, -size.Y * hollowFactorF / 2.0f, +size.Z / 2.0f); 339 IPP = new Vertex("Inner+X-Y+Z", +size.X*hollowFactorF/2.0f, -size.Y*hollowFactorF/2.0f, +size.Z/2.0f);
348 IPM = new Vertex("Inner+X-Y-Z", +size.X * hollowFactorF / 2.0f, -size.Y * hollowFactorF / 2.0f, -size.Z / 2.0f); 340 IPM = new Vertex("Inner+X-Y-Z", +size.X*hollowFactorF/2.0f, -size.Y*hollowFactorF/2.0f, -size.Z/2.0f);
349 IMP = new Vertex("Inner-X-Y+Z", -size.X * hollowFactorF / 2.0f, -size.Y * hollowFactorF / 2.0f, +size.Z / 2.0f); 341 IMP = new Vertex("Inner-X-Y+Z", -size.X*hollowFactorF/2.0f, -size.Y*hollowFactorF/2.0f, +size.Z/2.0f);
350 IMM = new Vertex("Inner-X-Y-Z", -size.X * hollowFactorF / 2.0f, -size.Y * hollowFactorF / 2.0f, -size.Z / 2.0f); 342 IMM = new Vertex("Inner-X-Y-Z", -size.X*hollowFactorF/2.0f, -size.Y*hollowFactorF/2.0f, -size.Z/2.0f);
351 343
352 MeshMY.Add(IPP); 344 MeshMY.Add(IPP);
353 MeshMY.Add(IPM); 345 MeshMY.Add(IPM);
@@ -363,11 +355,10 @@ namespace OpenSim.Region.Physics.OdePlugin
363 } 355 }
364 356
365 357
366 358 IPP = new Vertex("Inner+X+Y+Z", +size.X*hollowFactorF/2.0f, +size.Y*hollowFactorF/2.0f, +size.Z/2.0f);
367 IPP = new Vertex("Inner+X+Y+Z", +size.X * hollowFactorF / 2.0f, +size.Y * hollowFactorF / 2.0f, +size.Z / 2.0f); 359 IPM = new Vertex("Inner+X+Y-Z", +size.X*hollowFactorF/2.0f, +size.Y*hollowFactorF/2.0f, -size.Z/2.0f);
368 IPM=new Vertex("Inner+X+Y-Z", +size.X * hollowFactorF / 2.0f, +size.Y * hollowFactorF / 2.0f, -size.Z / 2.0f); 360 IMP = new Vertex("Inner-X+Y+Z", -size.X*hollowFactorF/2.0f, +size.Y*hollowFactorF/2.0f, +size.Z/2.0f);
369 IMP=new Vertex("Inner-X+Y+Z", -size.X * hollowFactorF / 2.0f, +size.Y * hollowFactorF / 2.0f, +size.Z / 2.0f); 361 IMM = new Vertex("Inner-X+Y-Z", -size.X*hollowFactorF/2.0f, +size.Y*hollowFactorF/2.0f, -size.Z/2.0f);
370 IMM=new Vertex("Inner-X+Y-Z", -size.X * hollowFactorF / 2.0f, +size.Y * hollowFactorF / 2.0f, -size.Z / 2.0f);
371 362
372 MeshPY.Add(IPP); 363 MeshPY.Add(IPP);
373 MeshPY.Add(IPM); 364 MeshPY.Add(IPM);
@@ -381,9 +372,6 @@ namespace OpenSim.Region.Physics.OdePlugin
381 { 372 {
382 PhysicsVector n = t.getNormal(); 373 PhysicsVector n = t.getNormal();
383 } 374 }
384
385
386
387 } 375 }
388 376
389 377
@@ -393,9 +381,9 @@ namespace OpenSim.Region.Physics.OdePlugin
393 381
394 return result; 382 return result;
395 } 383 }
396 384
397 static Mesh CreateBoxMeshZ(PrimitiveBaseShape primShape, PhysicsVector size) 385 private static Mesh CreateBoxMeshZ(PrimitiveBaseShape primShape, PhysicsVector size)
398 // Builds the z (+ and -) surfaces of a box shaped prim 386 // Builds the z (+ and -) surfaces of a box shaped prim
399 { 387 {
400 UInt16 hollowFactor = primShape.ProfileHollow; 388 UInt16 hollowFactor = primShape.ProfileHollow;
401 389
@@ -403,10 +391,10 @@ namespace OpenSim.Region.Physics.OdePlugin
403 // (M)inus Z 391 // (M)inus Z
404 Mesh MZ = new Mesh(); 392 Mesh MZ = new Mesh();
405 393
406 MZ.Add(new Vertex("-X-Y-Z", -size.X / 2.0f, -size.Y / 2.0f, -size.Z / 2.0f)); 394 MZ.Add(new Vertex("-X-Y-Z", -size.X/2.0f, -size.Y/2.0f, -size.Z/2.0f));
407 MZ.Add(new Vertex("+X-Y-Z", +size.X / 2.0f, -size.Y / 2.0f, -size.Z / 2.0f)); 395 MZ.Add(new Vertex("+X-Y-Z", +size.X/2.0f, -size.Y/2.0f, -size.Z/2.0f));
408 MZ.Add(new Vertex("-X+Y-Z", -size.X / 2.0f, +size.Y / 2.0f, -size.Z / 2.0f)); 396 MZ.Add(new Vertex("-X+Y-Z", -size.X/2.0f, +size.Y/2.0f, -size.Z/2.0f));
409 MZ.Add(new Vertex("+X+Y-Z", +size.X / 2.0f, +size.Y / 2.0f, -size.Z / 2.0f)); 397 MZ.Add(new Vertex("+X+Y-Z", +size.X/2.0f, +size.Y/2.0f, -size.Z/2.0f));
410 398
411 399
412 MZ.Add(new Triangle(MZ.vertices[1], MZ.vertices[0], MZ.vertices[2])); 400 MZ.Add(new Triangle(MZ.vertices[1], MZ.vertices[0], MZ.vertices[2]));
@@ -415,10 +403,10 @@ namespace OpenSim.Region.Physics.OdePlugin
415 // (P)lus Z 403 // (P)lus Z
416 Mesh PZ = new Mesh(); 404 Mesh PZ = new Mesh();
417 405
418 PZ.Add(new Vertex("-X-Y+Z", -size.X / 2.0f, -size.Y / 2.0f, 0.0f)); 406 PZ.Add(new Vertex("-X-Y+Z", -size.X/2.0f, -size.Y/2.0f, 0.0f));
419 PZ.Add(new Vertex("+X-Y+Z", +size.X / 2.0f, -size.Y / 2.0f, 0.0f)); 407 PZ.Add(new Vertex("+X-Y+Z", +size.X/2.0f, -size.Y/2.0f, 0.0f));
420 PZ.Add(new Vertex("-X+Y+Z", -size.X / 2.0f, +size.Y / 2.0f, 0.0f)); 408 PZ.Add(new Vertex("-X+Y+Z", -size.X/2.0f, +size.Y/2.0f, 0.0f));
421 PZ.Add(new Vertex("+X+Y+Z", +size.X / 2.0f, +size.Y / 2.0f, 0.0f)); 409 PZ.Add(new Vertex("+X+Y+Z", +size.X/2.0f, +size.Y/2.0f, 0.0f));
422 410
423 // Surface 5, +Z 411 // Surface 5, +Z
424 PZ.Add(new Triangle(PZ.vertices[0], PZ.vertices[1], PZ.vertices[2])); 412 PZ.Add(new Triangle(PZ.vertices[0], PZ.vertices[1], PZ.vertices[2]));
@@ -426,12 +414,12 @@ namespace OpenSim.Region.Physics.OdePlugin
426 414
427 if (hollowFactor > 0) 415 if (hollowFactor > 0)
428 { 416 {
429 float hollowFactorF = (float)hollowFactor / (float)50000; 417 float hollowFactorF = (float) hollowFactor/(float) 50000;
430 418
431 MZ.Add(new Vertex("-X-Y-Z", -size.X * hollowFactorF / 2.0f, -size.Y * hollowFactorF / 2.0f, 0.0f)); 419 MZ.Add(new Vertex("-X-Y-Z", -size.X*hollowFactorF/2.0f, -size.Y*hollowFactorF/2.0f, 0.0f));
432 MZ.Add(new Vertex("-X+Y-Z", +size.X * hollowFactorF / 2.0f, -size.Y * hollowFactorF / 2.0f, 0.0f)); 420 MZ.Add(new Vertex("-X+Y-Z", +size.X*hollowFactorF/2.0f, -size.Y*hollowFactorF/2.0f, 0.0f));
433 MZ.Add(new Vertex("-X-Y+Z", -size.X * hollowFactorF / 2.0f, +size.Y * hollowFactorF / 2.0f, 0.0f)); 421 MZ.Add(new Vertex("-X-Y+Z", -size.X*hollowFactorF/2.0f, +size.Y*hollowFactorF/2.0f, 0.0f));
434 MZ.Add(new Vertex("-X+Y+Z", +size.X * hollowFactorF / 2.0f, +size.Y * hollowFactorF / 2.0f, 0.0f)); 422 MZ.Add(new Vertex("-X+Y+Z", +size.X*hollowFactorF/2.0f, +size.Y*hollowFactorF/2.0f, 0.0f));
435 423
436 List<int> innerBorders = new List<int>(); 424 List<int> innerBorders = new List<int>();
437 innerBorders.Add(4); 425 innerBorders.Add(4);
@@ -441,10 +429,10 @@ namespace OpenSim.Region.Physics.OdePlugin
441 429
442 InsertVertices(MZ.vertices, 4, MZ.triangles, innerBorders); 430 InsertVertices(MZ.vertices, 4, MZ.triangles, innerBorders);
443 431
444 PZ.Add(new Vertex("-X-Y-Z", -size.X * hollowFactorF / 2.0f, -size.Y * hollowFactorF / 2.0f, 0.0f)); 432 PZ.Add(new Vertex("-X-Y-Z", -size.X*hollowFactorF/2.0f, -size.Y*hollowFactorF/2.0f, 0.0f));
445 PZ.Add(new Vertex("-X+Y-Z", +size.X * hollowFactorF / 2.0f, -size.Y * hollowFactorF / 2.0f, 0.0f)); 433 PZ.Add(new Vertex("-X+Y-Z", +size.X*hollowFactorF/2.0f, -size.Y*hollowFactorF/2.0f, 0.0f));
446 PZ.Add(new Vertex("-X-Y+Z", -size.X * hollowFactorF / 2.0f, +size.Y * hollowFactorF / 2.0f, 0.0f)); 434 PZ.Add(new Vertex("-X-Y+Z", -size.X*hollowFactorF/2.0f, +size.Y*hollowFactorF/2.0f, 0.0f));
447 PZ.Add(new Vertex("-X+Y+Z", +size.X * hollowFactorF / 2.0f, +size.Y * hollowFactorF / 2.0f, 0.0f)); 435 PZ.Add(new Vertex("-X+Y+Z", +size.X*hollowFactorF/2.0f, +size.Y*hollowFactorF/2.0f, 0.0f));
448 436
449 innerBorders = new List<int>(); 437 innerBorders = new List<int>();
450 innerBorders.Add(4); 438 innerBorders.Add(4);
@@ -453,16 +441,15 @@ namespace OpenSim.Region.Physics.OdePlugin
453 innerBorders.Add(7); 441 innerBorders.Add(7);
454 442
455 InsertVertices(PZ.vertices, 4, PZ.triangles, innerBorders); 443 InsertVertices(PZ.vertices, 4, PZ.triangles, innerBorders);
456
457 } 444 }
458 445
459 foreach (Vertex v in PZ.vertices) 446 foreach (Vertex v in PZ.vertices)
460 { 447 {
461 v.point.Z = size.Z / 2.0f; 448 v.point.Z = size.Z/2.0f;
462 } 449 }
463 foreach (Vertex v in MZ.vertices) 450 foreach (Vertex v in MZ.vertices)
464 { 451 {
465 v.point.Z = -size.Z / 2.0f; 452 v.point.Z = -size.Z/2.0f;
466 } 453 }
467 454
468 foreach (Triangle t in MZ.triangles) 455 foreach (Triangle t in MZ.triangles)
@@ -486,15 +473,14 @@ namespace OpenSim.Region.Physics.OdePlugin
486 return result; 473 return result;
487 } 474 }
488 475
489 static Mesh CreateBoxMesh(PrimitiveBaseShape primShape, PhysicsVector size) 476 private static Mesh CreateBoxMesh(PrimitiveBaseShape primShape, PhysicsVector size)
490 { 477 {
491 Mesh result = new Mesh(); 478 Mesh result = new Mesh();
492 479
493 480
494 481 Mesh MeshX = CreateBoxMeshX(primShape, size);
495 Mesh MeshX = Meshmerizer.CreateBoxMeshX(primShape, size); 482 Mesh MeshY = CreateBoxMeshY(primShape, size);
496 Mesh MeshY = Meshmerizer.CreateBoxMeshY(primShape, size); 483 Mesh MeshZ = CreateBoxMeshZ(primShape, size);
497 Mesh MeshZ = Meshmerizer.CreateBoxMeshZ(primShape, size);
498 484
499 result.Append(MeshX); 485 result.Append(MeshX);
500 result.Append(MeshY); 486 result.Append(MeshY);
@@ -504,64 +490,63 @@ namespace OpenSim.Region.Physics.OdePlugin
504 } 490 }
505 491
506 492
507 public static void CalcNormals(Mesh mesh) 493 public static void CalcNormals(Mesh mesh)
508 { 494 {
509 int iTriangles = mesh.triangles.Count; 495 int iTriangles = mesh.triangles.Count;
510 496
511 mesh.normals = new float[iTriangles*3]; 497 mesh.normals = new float[iTriangles*3];
512 498
513 int i=0; 499 int i = 0;
514 foreach (Triangle t in mesh.triangles) 500 foreach (Triangle t in mesh.triangles)
515 { 501 {
516
517 float ux, uy, uz; 502 float ux, uy, uz;
518 float vx, vy, vz; 503 float vx, vy, vz;
519 float wx, wy, wz; 504 float wx, wy, wz;
520 505
521 ux = t.v1.point.X; 506 ux = t.v1.point.X;
522 uy = t.v1.point.Y; 507 uy = t.v1.point.Y;
523 uz = t.v1.point.Z; 508 uz = t.v1.point.Z;
524 509
525 vx = t.v2.point.X; 510 vx = t.v2.point.X;
526 vy = t.v2.point.Y; 511 vy = t.v2.point.Y;
527 vz = t.v2.point.Z; 512 vz = t.v2.point.Z;
528 513
529 wx = t.v3.point.X; 514 wx = t.v3.point.X;
530 wy = t.v3.point.Y; 515 wy = t.v3.point.Y;
531 wz = t.v3.point.Z; 516 wz = t.v3.point.Z;
532 517
533 // Vectors for edges 518 // Vectors for edges
534 float e1x, e1y, e1z; 519 float e1x, e1y, e1z;
535 float e2x, e2y, e2z; 520 float e2x, e2y, e2z;
536 521
537 e1x = ux - vx; 522 e1x = ux - vx;
538 e1y = uy - vy; 523 e1y = uy - vy;
539 e1z = uz - vz; 524 e1z = uz - vz;
540 525
541 e2x = ux - wx; 526 e2x = ux - wx;
542 e2y = uy - wy; 527 e2y = uy - wy;
543 e2z = uz - wz; 528 e2z = uz - wz;
544 529
545 530
546 // Cross product for normal 531 // Cross product for normal
547 float nx, ny, nz; 532 float nx, ny, nz;
548 nx = e1y * e2z - e1z * e2y; 533 nx = e1y*e2z - e1z*e2y;
549 ny = e1z * e2x - e1x * e2z; 534 ny = e1z*e2x - e1x*e2z;
550 nz = e1x * e2y - e1y * e2x; 535 nz = e1x*e2y - e1y*e2x;
551 536
552 // Length 537 // Length
553 float l = (float)Math.Sqrt(nx * nx + ny * ny + nz * nz); 538 float l = (float) Math.Sqrt(nx*nx + ny*ny + nz*nz);
554 539
555 // Normalized "normal" 540 // Normalized "normal"
556 nx /= l; 541 nx /= l;
557 ny /= l; 542 ny /= l;
558 nz /= l; 543 nz /= l;
559 544
560 mesh.normals[i] = nx; 545 mesh.normals[i] = nx;
561 mesh.normals[i + 1] = ny; 546 mesh.normals[i + 1] = ny;
562 mesh.normals[i + 2] = nz; 547 mesh.normals[i + 2] = nz;
563 548
564 i+=3; 549 i += 3;
565 } 550 }
566 } 551 }
567 552
@@ -572,18 +557,15 @@ namespace OpenSim.Region.Physics.OdePlugin
572 switch (primShape.ProfileShape) 557 switch (primShape.ProfileShape)
573 { 558 {
574 case ProfileShape.Square: 559 case ProfileShape.Square:
575 mesh=CreateBoxMesh(primShape, size); 560 mesh = CreateBoxMesh(primShape, size);
576 CalcNormals(mesh); 561 CalcNormals(mesh);
577 break; 562 break;
578 default: 563 default:
579 mesh=null; 564 mesh = null;
580 break; 565 break;
581 } 566 }
582 567
583 return mesh; 568 return mesh;
584
585 } 569 }
586 } 570 }
587} 571} \ No newline at end of file
588
589
diff --git a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
index a20452f..c9af6dd 100644
--- a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
+++ b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
@@ -25,19 +25,14 @@
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
28using System; 29using System;
29using System.Threading;
30using System.Collections.Generic; 30using System.Collections.Generic;
31
32using libsecondlife;
33
34using Axiom.Math; 31using Axiom.Math;
35using Ode.NET; 32using Ode.NET;
36using OpenSim.Framework; 33using OpenSim.Framework;
37using OpenSim.Framework.Console;
38using OpenSim.Region.Physics.Manager; 34using OpenSim.Region.Physics.Manager;
39 35
40
41namespace OpenSim.Region.Physics.OdePlugin 36namespace OpenSim.Region.Physics.OdePlugin
42{ 37{
43 /// <summary> 38 /// <summary>
@@ -49,7 +44,6 @@ namespace OpenSim.Region.Physics.OdePlugin
49 44
50 public OdePlugin() 45 public OdePlugin()
51 { 46 {
52
53 } 47 }
54 48
55 public bool Init() 49 public bool Init()
@@ -73,7 +67,6 @@ namespace OpenSim.Region.Physics.OdePlugin
73 67
74 public void Dispose() 68 public void Dispose()
75 { 69 {
76
77 } 70 }
78 } 71 }
79 72
@@ -82,17 +75,17 @@ namespace OpenSim.Region.Physics.OdePlugin
82 private static float ODE_STEPSIZE = 0.004f; 75 private static float ODE_STEPSIZE = 0.004f;
83 private static bool RENDER_FLAG = false; 76 private static bool RENDER_FLAG = false;
84 private IntPtr contactgroup; 77 private IntPtr contactgroup;
85 private IntPtr LandGeom=(IntPtr)0; 78 private IntPtr LandGeom = (IntPtr) 0;
86 private double[] _heightmap; 79 private double[] _heightmap;
87 private d.NearCallback nearCallback; 80 private d.NearCallback nearCallback;
88 public d.TriCallback triCallback; 81 public d.TriCallback triCallback;
89 public d.TriArrayCallback triArrayCallback; 82 public d.TriArrayCallback triArrayCallback;
90 private List<OdeCharacter> _characters = new List<OdeCharacter>(); 83 private List<OdeCharacter> _characters = new List<OdeCharacter>();
91 private List<OdePrim> _prims = new List<OdePrim>(); 84 private List<OdePrim> _prims = new List<OdePrim>();
92 public Dictionary<IntPtr, String> geom_name_map=new Dictionary<IntPtr, String>(); 85 public Dictionary<IntPtr, String> geom_name_map = new Dictionary<IntPtr, String>();
93 private d.ContactGeom[] contacts = new d.ContactGeom[30]; 86 private d.ContactGeom[] contacts = new d.ContactGeom[30];
94 private d.Contact contact; 87 private d.Contact contact;
95 private float step_time=0.0f; 88 private float step_time = 0.0f;
96 public IntPtr world; 89 public IntPtr world;
97 public IntPtr space; 90 public IntPtr space;
98 public static Object OdeLock = new Object(); 91 public static Object OdeLock = new Object();
@@ -140,7 +133,7 @@ namespace OpenSim.Region.Physics.OdePlugin
140 return; 133 return;
141 134
142 d.GeomClassID id = d.GeomGetClass(g1); 135 d.GeomClassID id = d.GeomGetClass(g1);
143 if (id==d.GeomClassID.TriMeshClass) 136 if (id == d.GeomClassID.TriMeshClass)
144 { 137 {
145 String name1 = null; 138 String name1 = null;
146 String name2 = null; 139 String name2 = null;
@@ -163,7 +156,6 @@ namespace OpenSim.Region.Physics.OdePlugin
163 IntPtr joint = d.JointCreateContact(world, contactgroup, ref contact); 156 IntPtr joint = d.JointCreateContact(world, contactgroup, ref contact);
164 d.JointAttach(joint, b1, b2); 157 d.JointAttach(joint, b1, b2);
165 } 158 }
166
167 } 159 }
168 160
169 private void collision_optimized() 161 private void collision_optimized()
@@ -171,7 +163,8 @@ namespace OpenSim.Region.Physics.OdePlugin
171 foreach (OdeCharacter chr in _characters) 163 foreach (OdeCharacter chr in _characters)
172 { 164 {
173 d.SpaceCollide2(space, chr.Shell, IntPtr.Zero, nearCallback); 165 d.SpaceCollide2(space, chr.Shell, IntPtr.Zero, nearCallback);
174 foreach (OdeCharacter ch2 in _characters) /// should be a separate space -- lots of avatars will be N**2 slow 166 foreach (OdeCharacter ch2 in _characters)
167 /// should be a separate space -- lots of avatars will be N**2 slow
175 { 168 {
176 d.SpaceCollide2(chr.Shell, ch2.Shell, IntPtr.Zero, nearCallback); 169 d.SpaceCollide2(chr.Shell, ch2.Shell, IntPtr.Zero, nearCallback);
177 } 170 }
@@ -193,8 +186,8 @@ namespace OpenSim.Region.Physics.OdePlugin
193 { 186 {
194 lock (OdeLock) 187 lock (OdeLock)
195 { 188 {
196 ((OdeCharacter)actor).Destroy(); 189 ((OdeCharacter) actor).Destroy();
197 _characters.Remove((OdeCharacter)actor); 190 _characters.Remove((OdeCharacter) actor);
198 } 191 }
199 } 192 }
200 193
@@ -204,13 +197,14 @@ namespace OpenSim.Region.Physics.OdePlugin
204 { 197 {
205 lock (OdeLock) 198 lock (OdeLock)
206 { 199 {
207 d.GeomDestroy(((OdePrim)prim).prim_geom); 200 d.GeomDestroy(((OdePrim) prim).prim_geom);
208 _prims.Remove((OdePrim)prim); 201 _prims.Remove((OdePrim) prim);
209 } 202 }
210 } 203 }
211 } 204 }
212 205
213 PhysicsActor AddPrim(String name, PhysicsVector position, PhysicsVector size, Quaternion rotation, Mesh mesh, PrimitiveBaseShape pbs) 206 private PhysicsActor AddPrim(String name, PhysicsVector position, PhysicsVector size, Quaternion rotation,
207 Mesh mesh, PrimitiveBaseShape pbs)
214 { 208 {
215 PhysicsVector pos = new PhysicsVector(); 209 PhysicsVector pos = new PhysicsVector();
216 pos.X = position.X; 210 pos.X = position.X;
@@ -235,7 +229,7 @@ namespace OpenSim.Region.Physics.OdePlugin
235 } 229 }
236 230
237 231
238 public int TriArrayCallback(System.IntPtr trimesh, System.IntPtr refObject, int[] triangleIndex, int triCount) 232 public int TriArrayCallback(IntPtr trimesh, IntPtr refObject, int[] triangleIndex, int triCount)
239 { 233 {
240/* String name1 = null; 234/* String name1 = null;
241 String name2 = null; 235 String name2 = null;
@@ -254,15 +248,14 @@ namespace OpenSim.Region.Physics.OdePlugin
254 return 1; 248 return 1;
255 } 249 }
256 250
257 public int TriCallback(System.IntPtr trimesh, System.IntPtr refObject, int triangleIndex) 251 public int TriCallback(IntPtr trimesh, IntPtr refObject, int triangleIndex)
258 { 252 {
259
260 String name1 = null; 253 String name1 = null;
261 String name2 = null; 254 String name2 = null;
262 255
263 if (!geom_name_map.TryGetValue(trimesh, out name1)) 256 if (!geom_name_map.TryGetValue(trimesh, out name1))
264 { 257 {
265 name1 = "null"; 258 name1 = "null";
266 } 259 }
267 if (!geom_name_map.TryGetValue(refObject, out name2)) 260 if (!geom_name_map.TryGetValue(refObject, out name2))
268 { 261 {
@@ -282,11 +275,12 @@ namespace OpenSim.Region.Physics.OdePlugin
282 } 275 }
283 276
284 277
285 public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, PhysicsVector position, PhysicsVector size, Quaternion rotation) 278 public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, PhysicsVector position,
279 PhysicsVector size, Quaternion rotation)
286 { 280 {
287 PhysicsActor result; 281 PhysicsActor result;
288 282
289 switch(pbs.ProfileShape) 283 switch (pbs.ProfileShape)
290 { 284 {
291 case ProfileShape.Square: 285 case ProfileShape.Square:
292 /// support simple box & hollow box now; later, more shapes 286 /// support simple box & hollow box now; later, more shapes
@@ -310,7 +304,6 @@ namespace OpenSim.Region.Physics.OdePlugin
310 } 304 }
311 305
312 306
313
314 public override void Simulate(float timeStep) 307 public override void Simulate(float timeStep)
315 { 308 {
316 step_time += timeStep; 309 step_time += timeStep;
@@ -327,11 +320,12 @@ namespace OpenSim.Region.Physics.OdePlugin
327 Vector3 rx, ry, rz; 320 Vector3 rx, ry, rz;
328 p.Orientation.ToAxes(out rx, out ry, out rz); 321 p.Orientation.ToAxes(out rx, out ry, out rz);
329 Console.WriteLine("RENDER: block; " + p.Size.X + ", " + p.Size.Y + ", " + p.Size.Z + "; " + 322 Console.WriteLine("RENDER: block; " + p.Size.X + ", " + p.Size.Y + ", " + p.Size.Z + "; " +
330 " 0, 0, 1; " + //shape, size, color 323 " 0, 0, 1; " + //shape, size, color
331 (p.Position.X - 128.0f) + ", " + (p.Position.Y - 128.0f) + ", " + (p.Position.Z - 33.0f) + "; " + // position 324 (p.Position.X - 128.0f) + ", " + (p.Position.Y - 128.0f) + ", " +
332 rx.x + "," + ry.x + "," + rz.x + ", " + // rotation 325 (p.Position.Z - 33.0f) + "; " + // position
333 rx.y + "," + ry.y + "," + rz.y + ", " + 326 rx.x + "," + ry.x + "," + rz.x + ", " + // rotation
334 rx.z + "," + ry.z + "," + rz.z); 327 rx.y + "," + ry.y + "," + rz.y + ", " +
328 rx.z + "," + ry.z + "," + rz.z);
335 } 329 }
336 } 330 }
337 int i = 0; 331 int i = 0;
@@ -357,22 +351,27 @@ namespace OpenSim.Region.Physics.OdePlugin
357 float Zoff = -33.0f; 351 float Zoff = -33.0f;
358 d.Matrix3 temp = d.BodyGetRotation(actor.Body); 352 d.Matrix3 temp = d.BodyGetRotation(actor.Body);
359 Console.WriteLine("RENDER: cylinder; " + // shape 353 Console.WriteLine("RENDER: cylinder; " + // shape
360 OdeCharacter.CAPSULE_RADIUS + ", " + OdeCharacter.CAPSULE_LENGTH + //size 354 OdeCharacter.CAPSULE_RADIUS + ", " + OdeCharacter.CAPSULE_LENGTH + //size
361 "; 0, 1, 0; " + // color 355 "; 0, 1, 0; " + // color
362 (actor.Position.X - 128.0f) + ", " + (actor.Position.Y - 128.0f) + ", " + (actor.Position.Z + Zoff) + "; " + // position 356 (actor.Position.X - 128.0f) + ", " + (actor.Position.Y - 128.0f) + ", " +
363 temp.M00 + "," + temp.M10 + "," + temp.M20 + ", " + // rotation 357 (actor.Position.Z + Zoff) + "; " + // position
364 temp.M01 + "," + temp.M11 + "," + temp.M21 + ", " + 358 temp.M00 + "," + temp.M10 + "," + temp.M20 + ", " + // rotation
365 temp.M02 + "," + temp.M12 + "," + temp.M22); 359 temp.M01 + "," + temp.M11 + "," + temp.M21 + ", " +
366 d.Vector3 caphead; d.BodyGetRelPointPos(actor.Body, 0, 0, OdeCharacter.CAPSULE_LENGTH * .5f, out caphead); 360 temp.M02 + "," + temp.M12 + "," + temp.M22);
367 d.Vector3 capfoot; d.BodyGetRelPointPos(actor.Body, 0, 0, -OdeCharacter.CAPSULE_LENGTH * .5f, out capfoot); 361 d.Vector3 caphead;
362 d.BodyGetRelPointPos(actor.Body, 0, 0, OdeCharacter.CAPSULE_LENGTH*.5f, out caphead);
363 d.Vector3 capfoot;
364 d.BodyGetRelPointPos(actor.Body, 0, 0, -OdeCharacter.CAPSULE_LENGTH*.5f, out capfoot);
368 Console.WriteLine("RENDER: sphere; " + OdeCharacter.CAPSULE_RADIUS + // shape, size 365 Console.WriteLine("RENDER: sphere; " + OdeCharacter.CAPSULE_RADIUS + // shape, size
369 "; 1, 0, 1; " + //color 366 "; 1, 0, 1; " + //color
370 (caphead.X - 128.0f) + ", " + (caphead.Y - 128.0f) + ", " + (caphead.Z + Zoff) + "; " + // position 367 (caphead.X - 128.0f) + ", " + (caphead.Y - 128.0f) + ", " + (caphead.Z + Zoff) +
371 "1,0,0, 0,1,0, 0,0,1"); // rotation 368 "; " + // position
369 "1,0,0, 0,1,0, 0,0,1"); // rotation
372 Console.WriteLine("RENDER: sphere; " + OdeCharacter.CAPSULE_RADIUS + // shape, size 370 Console.WriteLine("RENDER: sphere; " + OdeCharacter.CAPSULE_RADIUS + // shape, size
373 "; 1, 0, 0; " + //color 371 "; 1, 0, 0; " + //color
374 (capfoot.X - 128.0f) + ", " + (capfoot.Y - 128.0f) + ", " + (capfoot.Z + Zoff) + "; " + // position 372 (capfoot.X - 128.0f) + ", " + (capfoot.Y - 128.0f) + ", " + (capfoot.Z + Zoff) +
375 "1,0,0, 0,1,0, 0,0,1"); // rotation 373 "; " + // position
374 "1,0,0, 0,1,0, 0,0,1"); // rotation
376 } 375 }
377 } 376 }
378 } 377 }
@@ -380,14 +379,11 @@ namespace OpenSim.Region.Physics.OdePlugin
380 379
381 public override void GetResults() 380 public override void GetResults()
382 { 381 {
383
384 } 382 }
385 383
386 public override bool IsThreaded 384 public override bool IsThreaded
387 { 385 {
388 get 386 get { return (false); // for now we won't be multithreaded
389 {
390 return (false); // for now we won't be multithreaded
391 } 387 }
392 } 388 }
393 389
@@ -400,21 +396,21 @@ namespace OpenSim.Region.Physics.OdePlugin
400 { 396 {
401 for (int y = 0; y < 258; y++) 397 for (int y = 0; y < 258; y++)
402 { 398 {
403 int xx = x-1; 399 int xx = x - 1;
404 if (xx < 0) xx = 0; 400 if (xx < 0) xx = 0;
405 if (xx > 255) xx = 255; 401 if (xx > 255) xx = 255;
406 int yy = y-1; 402 int yy = y - 1;
407 if (yy < 0) yy = 0; 403 if (yy < 0) yy = 0;
408 if (yy > 255) yy = 255; 404 if (yy > 255) yy = 255;
409 405
410 double val = (double)heightMap[yy * 256 + xx]; 406 double val = (double) heightMap[yy*256 + xx];
411 _heightmap[x * 258 + y] = val; 407 _heightmap[x*258 + y] = val;
412 } 408 }
413 } 409 }
414 410
415 lock (OdeLock) 411 lock (OdeLock)
416 { 412 {
417 if (!(LandGeom == (IntPtr)0)) 413 if (!(LandGeom == (IntPtr) 0))
418 { 414 {
419 d.SpaceRemove(space, LandGeom); 415 d.SpaceRemove(space, LandGeom);
420 } 416 }
@@ -422,7 +418,7 @@ namespace OpenSim.Region.Physics.OdePlugin
422 d.GeomHeightfieldDataBuildDouble(HeightmapData, _heightmap, 0, 258, 258, 258, 258, 1.0f, 0.0f, 2.0f, 0); 418 d.GeomHeightfieldDataBuildDouble(HeightmapData, _heightmap, 0, 258, 258, 258, 258, 1.0f, 0.0f, 2.0f, 0);
423 d.GeomHeightfieldDataSetBounds(HeightmapData, 256, 256); 419 d.GeomHeightfieldDataSetBounds(HeightmapData, 256, 256);
424 LandGeom = d.CreateHeightfield(space, HeightmapData, 1); 420 LandGeom = d.CreateHeightfield(space, HeightmapData, 1);
425 this.geom_name_map[LandGeom]="Terrain"; 421 geom_name_map[LandGeom] = "Terrain";
426 422
427 d.Matrix3 R = new d.Matrix3(); 423 d.Matrix3 R = new d.Matrix3();
428 424
@@ -430,7 +426,7 @@ namespace OpenSim.Region.Physics.OdePlugin
430 Quaternion q2 = Quaternion.FromAngleAxis(1.5707f, new Vector3(0, 1, 0)); 426 Quaternion q2 = Quaternion.FromAngleAxis(1.5707f, new Vector3(0, 1, 0));
431 //Axiom.Math.Quaternion q3 = Axiom.Math.Quaternion.FromAngleAxis(3.14f, new Axiom.Math.Vector3(0, 0, 1)); 427 //Axiom.Math.Quaternion q3 = Axiom.Math.Quaternion.FromAngleAxis(3.14f, new Axiom.Math.Vector3(0, 0, 1));
432 428
433 q1 = q1 * q2; 429 q1 = q1*q2;
434 //q1 = q1 * q3; 430 //q1 = q1 * q3;
435 Vector3 v3 = new Vector3(); 431 Vector3 v3 = new Vector3();
436 float angle = 0; 432 float angle = 0;
@@ -444,7 +440,6 @@ namespace OpenSim.Region.Physics.OdePlugin
444 440
445 public override void DeleteTerrain() 441 public override void DeleteTerrain()
446 { 442 {
447
448 } 443 }
449 } 444 }
450 445
@@ -452,12 +447,12 @@ namespace OpenSim.Region.Physics.OdePlugin
452 { 447 {
453 private PhysicsVector _position; 448 private PhysicsVector _position;
454 private d.Vector3 _zeroPosition; 449 private d.Vector3 _zeroPosition;
455 private bool _zeroFlag=false; 450 private bool _zeroFlag = false;
456 private PhysicsVector _velocity; 451 private PhysicsVector _velocity;
457 private PhysicsVector _target_velocity; 452 private PhysicsVector _target_velocity;
458 private PhysicsVector _acceleration; 453 private PhysicsVector _acceleration;
459 private static float PID_D=4000.0f; 454 private static float PID_D = 4000.0f;
460 private static float PID_P=7000.0f; 455 private static float PID_P = 7000.0f;
461 private static float POSTURE_SERVO = 10000.0f; 456 private static float POSTURE_SERVO = 10000.0f;
462 public static float CAPSULE_RADIUS = 0.5f; 457 public static float CAPSULE_RADIUS = 0.5f;
463 public static float CAPSULE_LENGTH = 0.9f; 458 public static float CAPSULE_LENGTH = 0.9f;
@@ -484,28 +479,18 @@ namespace OpenSim.Region.Physics.OdePlugin
484 d.BodySetPosition(Body, pos.X, pos.Y, pos.Z); 479 d.BodySetPosition(Body, pos.X, pos.Y, pos.Z);
485 d.GeomSetBody(Shell, Body); 480 d.GeomSetBody(Shell, Body);
486 } 481 }
487 parent_scene.geom_name_map[Shell]=avName; 482 parent_scene.geom_name_map[Shell] = avName;
488
489 } 483 }
490 484
491 public override bool Flying 485 public override bool Flying
492 { 486 {
493 get 487 get { return flying; }
494 { 488 set { flying = value; }
495 return flying;
496 }
497 set
498 {
499 flying = value;
500 }
501 } 489 }
502 490
503 public override PhysicsVector Position 491 public override PhysicsVector Position
504 { 492 {
505 get 493 get { return _position; }
506 {
507 return _position;
508 }
509 set 494 set
510 { 495 {
511 lock (OdeScene.OdeLock) 496 lock (OdeScene.OdeLock)
@@ -518,60 +503,34 @@ namespace OpenSim.Region.Physics.OdePlugin
518 503
519 public override PhysicsVector Size 504 public override PhysicsVector Size
520 { 505 {
521 get 506 get { return new PhysicsVector(0, 0, 0); }
522 { 507 set { }
523 return new PhysicsVector(0,0,0);
524 }
525 set
526 {
527 }
528 } 508 }
529 509
530 510
531 public override PhysicsVector Velocity 511 public override PhysicsVector Velocity
532 { 512 {
533 get 513 get { return _velocity; }
534 { 514 set { _target_velocity = value; }
535 return _velocity;
536 }
537 set
538 {
539 _target_velocity = value;
540 }
541 } 515 }
542 516
543 public override bool Kinematic 517 public override bool Kinematic
544 { 518 {
545 get 519 get { return false; }
546 { 520 set { }
547 return false;
548 }
549 set
550 {
551
552 }
553 } 521 }
554 522
555 public override Quaternion Orientation 523 public override Quaternion Orientation
556 { 524 {
557 get 525 get { return Quaternion.Identity; }
558 { 526 set { }
559 return Quaternion.Identity;
560 }
561 set
562 {
563
564 }
565 } 527 }
566 528
567 public override PhysicsVector Acceleration 529 public override PhysicsVector Acceleration
568 { 530 {
569 get 531 get { return _acceleration; }
570 {
571 return _acceleration;
572 }
573
574 } 532 }
533
575 public void SetAcceleration(PhysicsVector accel) 534 public void SetAcceleration(PhysicsVector accel)
576 { 535 {
577 _acceleration = accel; 536 _acceleration = accel;
@@ -579,12 +538,10 @@ namespace OpenSim.Region.Physics.OdePlugin
579 538
580 public override void AddForce(PhysicsVector force) 539 public override void AddForce(PhysicsVector force)
581 { 540 {
582
583 } 541 }
584 542
585 public override void SetMomentum(PhysicsVector momentum) 543 public override void SetMomentum(PhysicsVector momentum)
586 { 544 {
587
588 } 545 }
589 546
590 public void Move(float timeStep) 547 public void Move(float timeStep)
@@ -603,28 +560,28 @@ namespace OpenSim.Region.Physics.OdePlugin
603 _zeroPosition = d.BodyGetPosition(Body); 560 _zeroPosition = d.BodyGetPosition(Body);
604 } 561 }
605 d.Vector3 pos = d.BodyGetPosition(Body); 562 d.Vector3 pos = d.BodyGetPosition(Body);
606 vec.X = (_target_velocity.X - vel.X) * PID_D + (_zeroPosition.X - pos.X) * PID_P; 563 vec.X = (_target_velocity.X - vel.X)*PID_D + (_zeroPosition.X - pos.X)*PID_P;
607 vec.Y = (_target_velocity.Y - vel.Y) * PID_D + (_zeroPosition.Y - pos.Y) * PID_P; 564 vec.Y = (_target_velocity.Y - vel.Y)*PID_D + (_zeroPosition.Y - pos.Y)*PID_P;
608 if (flying) 565 if (flying)
609 { 566 {
610 vec.Z = (_target_velocity.Z - vel.Z) * PID_D + (_zeroPosition.Z - pos.Z) * PID_P; 567 vec.Z = (_target_velocity.Z - vel.Z)*PID_D + (_zeroPosition.Z - pos.Z)*PID_P;
611 } 568 }
612 } 569 }
613 else 570 else
614 { 571 {
615 _zeroFlag = false; 572 _zeroFlag = false;
616 vec.X = (_target_velocity.X - vel.X) * PID_D; 573 vec.X = (_target_velocity.X - vel.X)*PID_D;
617 vec.Y = (_target_velocity.Y - vel.Y) * PID_D; 574 vec.Y = (_target_velocity.Y - vel.Y)*PID_D;
618 if (flying) 575 if (flying)
619 { 576 {
620 vec.Z = (_target_velocity.Z - vel.Z) * PID_D; 577 vec.Z = (_target_velocity.Z - vel.Z)*PID_D;
621 } 578 }
622 } 579 }
623 if (flying) 580 if (flying)
624 { 581 {
625 vec.Z += 10.0f; 582 vec.Z += 10.0f;
626 } 583 }
627 d.BodyAddForce(this.Body, vec.X, vec.Y, vec.Z); 584 d.BodyAddForce(Body, vec.X, vec.Y, vec.Z);
628 585
629 // ok -- let's stand up straight! 586 // ok -- let's stand up straight!
630 d.Vector3 feet; 587 d.Vector3 feet;
@@ -634,7 +591,7 @@ namespace OpenSim.Region.Physics.OdePlugin
634 float posture = head.Z - feet.Z; 591 float posture = head.Z - feet.Z;
635 592
636 // restoring force proportional to lack of posture: 593 // restoring force proportional to lack of posture:
637 float servo = (2.5f-posture) * POSTURE_SERVO; 594 float servo = (2.5f - posture)*POSTURE_SERVO;
638 d.BodyAddForceAtRelPos(Body, 0.0f, 0.0f, servo, 0.0f, 0.0f, 1.0f); 595 d.BodyAddForceAtRelPos(Body, 0.0f, 0.0f, servo, 0.0f, 0.0f, 1.0f);
639 d.BodyAddForceAtRelPos(Body, 0.0f, 0.0f, -servo, 0.0f, 0.0f, -1.0f); 596 d.BodyAddForceAtRelPos(Body, 0.0f, 0.0f, -servo, 0.0f, 0.0f, -1.0f);
640 } 597 }
@@ -650,9 +607,9 @@ namespace OpenSim.Region.Physics.OdePlugin
650 if (vec.X > 255.95f) vec.X = 255.95f; 607 if (vec.X > 255.95f) vec.X = 255.95f;
651 if (vec.Y > 255.95f) vec.Y = 255.95f; 608 if (vec.Y > 255.95f) vec.Y = 255.95f;
652 609
653 this._position.X = vec.X; 610 _position.X = vec.X;
654 this._position.Y = vec.Y; 611 _position.Y = vec.Y;
655 this._position.Z = vec.Z; 612 _position.Z = vec.Z;
656 613
657 if (_zeroFlag) 614 if (_zeroFlag)
658 { 615 {
@@ -673,9 +630,9 @@ namespace OpenSim.Region.Physics.OdePlugin
673 { 630 {
674 lock (OdeScene.OdeLock) 631 lock (OdeScene.OdeLock)
675 { 632 {
676 d.GeomDestroy(this.Shell); 633 d.GeomDestroy(Shell);
677 this._parent_scene.geom_name_map.Remove(this.Shell); 634 _parent_scene.geom_name_map.Remove(Shell);
678 d.BodyDestroy(this.Body); 635 d.BodyDestroy(Body);
679 } 636 }
680 } 637 }
681 } 638 }
@@ -693,7 +650,7 @@ namespace OpenSim.Region.Physics.OdePlugin
693 public IntPtr prim_geom; 650 public IntPtr prim_geom;
694 public IntPtr _triMeshData; 651 public IntPtr _triMeshData;
695 652
696 public OdePrim(String primName, OdeScene parent_scene, PhysicsVector pos, PhysicsVector size, 653 public OdePrim(String primName, OdeScene parent_scene, PhysicsVector pos, PhysicsVector size,
697 Quaternion rotation, Mesh mesh, PrimitiveBaseShape pbs) 654 Quaternion rotation, Mesh mesh, PrimitiveBaseShape pbs)
698 { 655 {
699 _velocity = new PhysicsVector(); 656 _velocity = new PhysicsVector();
@@ -707,7 +664,7 @@ namespace OpenSim.Region.Physics.OdePlugin
707 664
708 lock (OdeScene.OdeLock) 665 lock (OdeScene.OdeLock)
709 { 666 {
710 if (mesh!=null) 667 if (mesh != null)
711 { 668 {
712 setMesh(parent_scene, mesh); 669 setMesh(parent_scene, mesh);
713 } 670 }
@@ -723,20 +680,22 @@ namespace OpenSim.Region.Physics.OdePlugin
723 myrot.Y = rotation.y; 680 myrot.Y = rotation.y;
724 myrot.Z = rotation.z; 681 myrot.Z = rotation.z;
725 d.GeomSetQuaternion(prim_geom, ref myrot); 682 d.GeomSetQuaternion(prim_geom, ref myrot);
726 parent_scene.geom_name_map[prim_geom] = primName; // don't do .add() here; old geoms get recycled with the same hash 683 parent_scene.geom_name_map[prim_geom] = primName;
684 // don't do .add() here; old geoms get recycled with the same hash
727 } 685 }
728 } 686 }
729 687
730 public void setMesh(OdeScene parent_scene, Mesh mesh) 688 public void setMesh(OdeScene parent_scene, Mesh mesh)
731 { 689 {
732 float[] vertexList = mesh.getVertexListAsFloat(); // Note, that vertextList is pinned in memory 690 float[] vertexList = mesh.getVertexListAsFloat(); // Note, that vertextList is pinned in memory
733 int[] indexList = mesh.getIndexListAsInt(); // Also pinned, needs release after usage 691 int[] indexList = mesh.getIndexListAsInt(); // Also pinned, needs release after usage
734 int VertexCount = vertexList.GetLength(0) / 3; 692 int VertexCount = vertexList.GetLength(0)/3;
735 int IndexCount = indexList.GetLength(0); 693 int IndexCount = indexList.GetLength(0);
736 694
737 _triMeshData = d.GeomTriMeshDataCreate(); 695 _triMeshData = d.GeomTriMeshDataCreate();
738 696
739 d.GeomTriMeshDataBuildSimple(_triMeshData, vertexList, 3 * sizeof(float), VertexCount, indexList, IndexCount, 3 * sizeof(int)); 697 d.GeomTriMeshDataBuildSimple(_triMeshData, vertexList, 3*sizeof (float), VertexCount, indexList, IndexCount,
698 3*sizeof (int));
740 d.GeomTriMeshDataPreprocess(_triMeshData); 699 d.GeomTriMeshDataPreprocess(_triMeshData);
741 700
742 prim_geom = d.CreateTriMesh(parent_scene.space, _triMeshData, parent_scene.triCallback, null, null); 701 prim_geom = d.CreateTriMesh(parent_scene.space, _triMeshData, parent_scene.triCallback, null, null);
@@ -744,21 +703,14 @@ namespace OpenSim.Region.Physics.OdePlugin
744 703
745 public override bool Flying 704 public override bool Flying
746 { 705 {
747 get 706 get { return false; //no flying prims for you
748 {
749 return false; //no flying prims for you
750 }
751 set
752 {
753 } 707 }
708 set { }
754 } 709 }
755 710
756 public override PhysicsVector Position 711 public override PhysicsVector Position
757 { 712 {
758 get 713 get { return _position; }
759 {
760 return _position;
761 }
762 set 714 set
763 { 715 {
764 _position = value; 716 _position = value;
@@ -771,10 +723,7 @@ namespace OpenSim.Region.Physics.OdePlugin
771 723
772 public override PhysicsVector Size 724 public override PhysicsVector Size
773 { 725 {
774 get 726 get { return _size; }
775 {
776 return _size;
777 }
778 set 727 set
779 { 728 {
780 _size = value; 729 _size = value;
@@ -798,33 +747,19 @@ namespace OpenSim.Region.Physics.OdePlugin
798 747
799 public override PhysicsVector Velocity 748 public override PhysicsVector Velocity
800 { 749 {
801 get 750 get { return _velocity; }
802 { 751 set { _velocity = value; }
803 return _velocity;
804 }
805 set
806 {
807 _velocity = value;
808 }
809 } 752 }
810 753
811 public override bool Kinematic 754 public override bool Kinematic
812 { 755 {
813 get 756 get { return false; }
814 { 757 set { }
815 return false;
816 }
817 set
818 {
819 }
820 } 758 }
821 759
822 public override Quaternion Orientation 760 public override Quaternion Orientation
823 { 761 {
824 get 762 get { return _orientation; }
825 {
826 return _orientation;
827 }
828 set 763 set
829 { 764 {
830 _orientation = value; 765 _orientation = value;
@@ -842,15 +777,12 @@ namespace OpenSim.Region.Physics.OdePlugin
842 777
843 public override PhysicsVector Acceleration 778 public override PhysicsVector Acceleration
844 { 779 {
845 get 780 get { return _acceleration; }
846 {
847 return _acceleration;
848 }
849 } 781 }
850 782
851 public void SetAcceleration(PhysicsVector accel) 783 public void SetAcceleration(PhysicsVector accel)
852 { 784 {
853 this._acceleration = accel; 785 _acceleration = accel;
854 } 786 }
855 787
856 public override void AddForce(PhysicsVector force) 788 public override void AddForce(PhysicsVector force)
@@ -861,4 +793,4 @@ namespace OpenSim.Region.Physics.OdePlugin
861 { 793 {
862 } 794 }
863 } 795 }
864} 796} \ No newline at end of file