From 67e12b95ea7b68f4904a7484d77ecfd787d16d0c Mon Sep 17 00:00:00 2001 From: lbsa71 Date: Tue, 30 Oct 2007 09:05:31 +0000 Subject: * Optimized usings * Shortened type references * Removed redundant 'this' qualifier --- OpenSim/Region/Physics/OdePlugin/AssemblyInfo.cs | 22 +- .../Physics/OdePlugin/Meshing/HelperTypes.cs | 72 +++--- .../Physics/OdePlugin/Meshing/Meshmerizer.cs | 256 +++++++++---------- OpenSim/Region/Physics/OdePlugin/OdePlugin.cs | 274 ++++++++------------- 4 files changed, 267 insertions(+), 357 deletions(-) (limited to 'OpenSim/Region/Physics/OdePlugin') 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 @@ */ using System.Reflection; using System.Runtime.InteropServices; + // Information about this assembly is defined by the following // attributes. // // change them to the information which is associated with the assembly // you compile. -[assembly: AssemblyTitle("RealPhysXplugin")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("RealPhysXplugin")] -[assembly: AssemblyCopyright("")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] +[assembly : AssemblyTitle("RealPhysXplugin")] +[assembly : AssemblyDescription("")] +[assembly : AssemblyConfiguration("")] +[assembly : AssemblyCompany("")] +[assembly : AssemblyProduct("RealPhysXplugin")] +[assembly : AssemblyCopyright("")] +[assembly : AssemblyTrademark("")] +[assembly : AssemblyCulture("")] // This sets the default COM visibility of types in the assembly to invisible. // If you need to expose a type to COM, use [ComVisible(true)] on that type. -[assembly: ComVisible(false)] + +[assembly : ComVisible(false)] // The assembly version has following format : // @@ -53,4 +55,4 @@ using System.Runtime.InteropServices; // You can specify all values by your own or you can build default build and revision // numbers with the '*' character (the default): -[assembly: AssemblyVersion("1.0.*")] +[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 @@ */ using System; -using System.Globalization; -using System.Diagnostics; using System.Collections.Generic; - +using System.Diagnostics; +using System.Globalization; using OpenSim.Region.Physics.Manager; public class Vertex : IComparable @@ -76,8 +75,6 @@ public class Vertex : IComparable { return me.CompareTo(other) < 0; } - - } public class Simplex : IComparable @@ -122,8 +119,7 @@ public class Simplex : IComparable return 0; } - -}; +} ; public class Triangle { @@ -131,9 +127,9 @@ public class Triangle public Vertex v2; public Vertex v3; - float radius_square; - float cx; - float cy; + private float radius_square; + private float cx; + private float cy; public Triangle(Vertex _v1, Vertex _v2, Vertex _v3) { @@ -149,18 +145,18 @@ public class Triangle float dx, dy; float dd; - dx = x - this.cx; - dy = y - this.cy; + dx = x - cx; + dy = y - cy; - dd = dx * dx + dy * dy; - if (dd < this.radius_square) + dd = dx*dx + dy*dy; + if (dd < radius_square) return true; else return false; } - void CalcCircle() + private void CalcCircle() { // Calculate the center and the radius of a circle given by three points p1, p2, p3 // It is assumed, that the triangles vertices are already set correctly @@ -198,8 +194,8 @@ public class Triangle p3y = v3.point.Y; /* calc helping values first */ - c1 = (p1x * p1x + p1y * p1y - p2x * p2x - p2y * p2y) / 2; - c2 = (p1x * p1x + p1y * p1y - p3x * p3x - p3y * p3y) / 2; + c1 = (p1x*p1x + p1y*p1y - p2x*p2x - p2y*p2y)/2; + c2 = (p1x*p1x + p1y*p1y - p3x*p3x - p3y*p3y)/2; v1x = p1x - p2x; v1y = p1y - p2y; @@ -207,35 +203,34 @@ public class Triangle v2x = p1x - p3x; v2y = p1y - p3y; - z = (c1 * v2x - c2 * v1x); - n = (v1y * v2x - v2y * v1x); + z = (c1*v2x - c2*v1x); + n = (v1y*v2x - v2y*v1x); - if (n == 0.0) // This is no triangle, i.e there are (at least) two points at the same location + if (n == 0.0) // This is no triangle, i.e there are (at least) two points at the same location { radius_square = 0.0f; return; } - this.cy = (float)(z / n); + cy = (float) (z/n); if (v2x != 0.0) { - this.cx = (float)((c2 - v2y * this.cy) / v2x); + cx = (float) ((c2 - v2y*cy)/v2x); } else if (v1x != 0.0) { - this.cx = (float)((c1 - v1y * this.cy) / v1x); + cx = (float) ((c1 - v1y*cy)/v1x); } else { Debug.Assert(false, "Malformed triangle"); /* Both terms zero means nothing good */ } - rx = (p1x - this.cx); - ry = (p1y - this.cy); - - this.radius_square = (float)(rx * rx + ry * ry); + rx = (p1x - cx); + ry = (p1y - cy); + radius_square = (float) (rx*rx + ry*ry); } public List GetSimplices() @@ -254,17 +249,18 @@ public class Triangle public override String ToString() { - NumberFormatInfo nfi = new NumberFormatInfo(); nfi.CurrencyDecimalDigits = 2; nfi.CurrencyDecimalSeparator = "."; - String s1 = "<" + v1.point.X.ToString(nfi) + "," + v1.point.Y.ToString(nfi) + "," + v1.point.Z.ToString(nfi) + ">"; - String s2 = "<" + v2.point.X.ToString(nfi) + "," + v2.point.Y.ToString(nfi) + "," + v2.point.Z.ToString(nfi) + ">"; - String s3 = "<" + v3.point.X.ToString(nfi) + "," + v3.point.Y.ToString(nfi) + "," + v3.point.Z.ToString(nfi) + ">"; + String s1 = "<" + v1.point.X.ToString(nfi) + "," + v1.point.Y.ToString(nfi) + "," + v1.point.Z.ToString(nfi) + + ">"; + String s2 = "<" + v2.point.X.ToString(nfi) + "," + v2.point.Y.ToString(nfi) + "," + v2.point.Z.ToString(nfi) + + ">"; + String s3 = "<" + v3.point.X.ToString(nfi) + "," + v3.point.Y.ToString(nfi) + "," + v3.point.Z.ToString(nfi) + + ">"; return s1 + ";" + s2 + ";" + s3; - } public PhysicsVector getNormal() @@ -281,12 +277,12 @@ public class Triangle // Cross product for normal PhysicsVector n = new PhysicsVector(); float nx, ny, nz; - n.X = e1.Y * e2.Z - e1.Z * e2.Y; - n.Y = e1.Z * e2.X - e1.X * e2.Z; - n.Z = e1.X * e2.Y - e1.Y * e2.X; + n.X = e1.Y*e2.Z - e1.Z*e2.Y; + n.Y = e1.Z*e2.X - e1.X*e2.Z; + n.Z = e1.X*e2.Y - e1.Y*e2.X; // Length - float l = (float)Math.Sqrt(n.X * n.X + n.Y * n.Y + n.Z * n.Z); + float l = (float) Math.Sqrt(n.X*n.X + n.Y*n.Y + n.Z*n.Z); // Normalized "normal" n.X /= l; @@ -303,6 +299,4 @@ public class Triangle v1 = v2; v2 = vt; } -} - - +} \ No newline at end of file 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 @@ */ using System; -using System.Globalization; -using System.Diagnostics; using System.Collections.Generic; -using System.Text; using System.Runtime.InteropServices; - using OpenSim.Framework; using OpenSim.Region.Physics.Manager; @@ -75,14 +71,14 @@ namespace OpenSim.Region.Physics.OdePlugin public float[] getVertexListAsFloat() { - float[] result = new float[vertices.Count * 3]; + float[] result = new float[vertices.Count*3]; for (int i = 0; i < vertices.Count; i++) { Vertex v = vertices[i]; PhysicsVector point = v.point; - result[3 * i + 0] = point.X; - result[3 * i + 1] = point.Y; - result[3 * i + 2] = point.Z; + result[3*i + 0] = point.X; + result[3*i + 1] = point.Y; + result[3*i + 2] = point.Z; } GCHandle.Alloc(result, GCHandleType.Pinned); return result; @@ -90,13 +86,13 @@ namespace OpenSim.Region.Physics.OdePlugin public int[] getIndexListAsInt() { - int[] result = new int[triangles.Count * 3]; + int[] result = new int[triangles.Count*3]; for (int i = 0; i < triangles.Count; i++) { Triangle t = triangles[i]; - result[3 * i + 0] = vertices.IndexOf(t.v1); - result[3 * i + 1] = vertices.IndexOf(t.v2); - result[3 * i + 2] = vertices.IndexOf(t.v3); + result[3*i + 0] = vertices.IndexOf(t.v1); + result[3*i + 1] = vertices.IndexOf(t.v2); + result[3*i + 2] = vertices.IndexOf(t.v3); } GCHandle.Alloc(result, GCHandleType.Pinned); return result; @@ -110,16 +106,13 @@ namespace OpenSim.Region.Physics.OdePlugin foreach (Triangle t in newMesh.triangles) Add(t); - } } - public class Meshmerizer { - - static List FindInfluencedTriangles(List triangles, Vertex v) + private static List FindInfluencedTriangles(List triangles, Vertex v) { List influenced = new List(); foreach (Triangle t in triangles) @@ -133,9 +126,10 @@ namespace OpenSim.Region.Physics.OdePlugin } return influenced; } - - - static void InsertVertices(List vertices, int usedForSeed, List triangles, List innerBorders) + + + private static void InsertVertices(List vertices, int usedForSeed, List triangles, + List innerBorders) { // This is a variant of the delaunay algorithm // 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 // It is not very time efficient but easy to implement. int iCurrentVertex; - int iMaxVertex=vertices.Count; + int iMaxVertex = vertices.Count; for (iCurrentVertex = usedForSeed; iCurrentVertex < iMaxVertex; iCurrentVertex++) { // Background: A triangle mesh fulfills the delaunay condition if (iff!) @@ -154,8 +148,8 @@ namespace OpenSim.Region.Physics.OdePlugin // do not fulfill this condition with respect to the new triangle // Find the triangles that are influenced by the new vertex - Vertex v=vertices[iCurrentVertex]; - List influencedTriangles=FindInfluencedTriangles(triangles, v); + Vertex v = vertices[iCurrentVertex]; + List influencedTriangles = FindInfluencedTriangles(triangles, v); List simplices = new List(); @@ -175,10 +169,10 @@ namespace OpenSim.Region.Physics.OdePlugin // Look for duplicate simplices here. // Remember, they are directly side by side in the list right now int iSimplex; - List innerSimplices=new List(); + List innerSimplices = new List(); for (iSimplex = 1; iSimplex < simplices.Count; iSimplex++) // Startindex=1, so we can refer backwards { - if (simplices[iSimplex - 1].CompareTo(simplices[iSimplex])==0) + if (simplices[iSimplex - 1].CompareTo(simplices[iSimplex]) == 0) { innerSimplices.Add(simplices[iSimplex - 1]); innerSimplices.Add(simplices[iSimplex]); @@ -187,7 +181,7 @@ namespace OpenSim.Region.Physics.OdePlugin foreach (Simplex s in innerSimplices) { - simplices.Remove(s); + simplices.Remove(s); } // each simplex still in the list belongs to the hull of the region in question @@ -210,7 +204,7 @@ namespace OpenSim.Region.Physics.OdePlugin foreach (Triangle t in triangles) { if ( - innerBorders.Contains(vertices.IndexOf(t.v1)) + innerBorders.Contains(vertices.IndexOf(t.v1)) && innerBorders.Contains(vertices.IndexOf(t.v2)) && innerBorders.Contains(vertices.IndexOf(t.v3)) ) @@ -223,18 +217,18 @@ namespace OpenSim.Region.Physics.OdePlugin } - static Mesh CreateBoxMeshX(PrimitiveBaseShape primShape, PhysicsVector size) - // Builds the x (+ and -) surfaces of a box shaped prim + private static Mesh CreateBoxMeshX(PrimitiveBaseShape primShape, PhysicsVector size) + // Builds the x (+ and -) surfaces of a box shaped prim { UInt16 hollowFactor = primShape.ProfileHollow; Mesh meshMX = new Mesh(); // Surface 0, -X - meshMX.Add(new Vertex("-X-Y-Z", -size.X / 2.0f, -size.Y / 2.0f, -size.Z / 2.0f)); - meshMX.Add(new Vertex("-X+Y-Z", -size.X / 2.0f, +size.Y / 2.0f, -size.Z / 2.0f)); - meshMX.Add(new Vertex("-X-Y+Z", -size.X / 2.0f, -size.Y / 2.0f, +size.Z / 2.0f)); - meshMX.Add(new Vertex("-X+Y+Z", -size.X / 2.0f, +size.Y / 2.0f, +size.Z / 2.0f)); + meshMX.Add(new Vertex("-X-Y-Z", -size.X/2.0f, -size.Y/2.0f, -size.Z/2.0f)); + meshMX.Add(new Vertex("-X+Y-Z", -size.X/2.0f, +size.Y/2.0f, -size.Z/2.0f)); + meshMX.Add(new Vertex("-X-Y+Z", -size.X/2.0f, -size.Y/2.0f, +size.Z/2.0f)); + meshMX.Add(new Vertex("-X+Y+Z", -size.X/2.0f, +size.Y/2.0f, +size.Z/2.0f)); meshMX.Add(new Triangle(meshMX.vertices[0], meshMX.vertices[2], meshMX.vertices[1])); meshMX.Add(new Triangle(meshMX.vertices[1], meshMX.vertices[2], meshMX.vertices[3])); @@ -242,10 +236,10 @@ namespace OpenSim.Region.Physics.OdePlugin Mesh meshPX = new Mesh(); // Surface 1, +X - meshPX.Add(new Vertex("+X-Y-Z", +size.X / 2.0f, -size.Y / 2.0f, -size.Z / 2.0f)); - meshPX.Add(new Vertex("+X+Y-Z", +size.X / 2.0f, +size.Y / 2.0f, -size.Z / 2.0f)); - meshPX.Add(new Vertex("+X-Y+Z", +size.X / 2.0f, -size.Y / 2.0f, +size.Z / 2.0f)); - meshPX.Add(new Vertex("+X+Y+Z", +size.X / 2.0f, +size.Y / 2.0f, +size.Z / 2.0f)); + meshPX.Add(new Vertex("+X-Y-Z", +size.X/2.0f, -size.Y/2.0f, -size.Z/2.0f)); + meshPX.Add(new Vertex("+X+Y-Z", +size.X/2.0f, +size.Y/2.0f, -size.Z/2.0f)); + meshPX.Add(new Vertex("+X-Y+Z", +size.X/2.0f, -size.Y/2.0f, +size.Z/2.0f)); + meshPX.Add(new Vertex("+X+Y+Z", +size.X/2.0f, +size.Y/2.0f, +size.Z/2.0f)); meshPX.Add(new Triangle(meshPX.vertices[0], meshPX.vertices[1], meshPX.vertices[2])); @@ -254,17 +248,17 @@ namespace OpenSim.Region.Physics.OdePlugin if (hollowFactor > 0) { - float hollowFactorF = (float)hollowFactor / (float)50000; + float hollowFactorF = (float) hollowFactor/(float) 50000; Vertex IPP; Vertex IPM; Vertex IMP; Vertex IMM; - IPP = new Vertex("Inner-X+Y+Z", -size.X * hollowFactorF / 2.0f, +size.Y * hollowFactorF / 2.0f, +size.Z / 2.0f); - IPM = new Vertex("Inner-X+Y-Z", -size.X * hollowFactorF / 2.0f, +size.Y * hollowFactorF / 2.0f, -size.Z / 2.0f); - IMP = new Vertex("Inner-X-Y+Z", -size.X * hollowFactorF / 2.0f, -size.Y * hollowFactorF / 2.0f, +size.Z / 2.0f); - IMM = new Vertex("Inner-X-Y-Z", -size.X * hollowFactorF / 2.0f, -size.Y * hollowFactorF / 2.0f, -size.Z / 2.0f); + IPP = new Vertex("Inner-X+Y+Z", -size.X*hollowFactorF/2.0f, +size.Y*hollowFactorF/2.0f, +size.Z/2.0f); + IPM = new Vertex("Inner-X+Y-Z", -size.X*hollowFactorF/2.0f, +size.Y*hollowFactorF/2.0f, -size.Z/2.0f); + IMP = new Vertex("Inner-X-Y+Z", -size.X*hollowFactorF/2.0f, -size.Y*hollowFactorF/2.0f, +size.Z/2.0f); + IMM = new Vertex("Inner-X-Y-Z", -size.X*hollowFactorF/2.0f, -size.Y*hollowFactorF/2.0f, -size.Z/2.0f); meshMX.Add(IPP); meshMX.Add(IPM); @@ -280,11 +274,10 @@ namespace OpenSim.Region.Physics.OdePlugin } - - IPP = new Vertex("Inner+X+Y+Z", +size.X * hollowFactorF / 2.0f, +size.Y * hollowFactorF / 2.0f, +size.Z / 2.0f); - IPM = new Vertex("Inner+X+Y-Z", +size.X * hollowFactorF / 2.0f, +size.Y * hollowFactorF / 2.0f, -size.Z / 2.0f); - IMP = new Vertex("Inner+X-Y+Z", +size.X * hollowFactorF / 2.0f, -size.Y * hollowFactorF / 2.0f, +size.Z / 2.0f); - IMM = new Vertex("Inner+X-Y-Z", +size.X * hollowFactorF / 2.0f, -size.Y * hollowFactorF / 2.0f, -size.Z / 2.0f); + IPP = new Vertex("Inner+X+Y+Z", +size.X*hollowFactorF/2.0f, +size.Y*hollowFactorF/2.0f, +size.Z/2.0f); + IPM = new Vertex("Inner+X+Y-Z", +size.X*hollowFactorF/2.0f, +size.Y*hollowFactorF/2.0f, -size.Z/2.0f); + IMP = new Vertex("Inner+X-Y+Z", +size.X*hollowFactorF/2.0f, -size.Y*hollowFactorF/2.0f, +size.Z/2.0f); + IMM = new Vertex("Inner+X-Y-Z", +size.X*hollowFactorF/2.0f, -size.Y*hollowFactorF/2.0f, -size.Z/2.0f); meshPX.Add(IPP); meshPX.Add(IPM); @@ -308,18 +301,17 @@ namespace OpenSim.Region.Physics.OdePlugin } - - static Mesh CreateBoxMeshY(PrimitiveBaseShape primShape, PhysicsVector size) - // Builds the y (+ and -) surfaces of a box shaped prim + private static Mesh CreateBoxMeshY(PrimitiveBaseShape primShape, PhysicsVector size) + // Builds the y (+ and -) surfaces of a box shaped prim { UInt16 hollowFactor = primShape.ProfileHollow; // (M)inus Y Mesh MeshMY = new Mesh(); - MeshMY.Add(new Vertex("-X-Y-Z", -size.X / 2.0f, -size.Y / 2.0f, -size.Z / 2.0f)); - MeshMY.Add(new Vertex("+X-Y-Z", +size.X / 2.0f, -size.Y / 2.0f, -size.Z / 2.0f)); - MeshMY.Add(new Vertex("-X-Y+Z", -size.X / 2.0f, -size.Y / 2.0f, +size.Z / 2.0f)); - MeshMY.Add(new Vertex("+X-Y+Z", +size.X / 2.0f, -size.Y / 2.0f, +size.Z / 2.0f)); + MeshMY.Add(new Vertex("-X-Y-Z", -size.X/2.0f, -size.Y/2.0f, -size.Z/2.0f)); + MeshMY.Add(new Vertex("+X-Y-Z", +size.X/2.0f, -size.Y/2.0f, -size.Z/2.0f)); + MeshMY.Add(new Vertex("-X-Y+Z", -size.X/2.0f, -size.Y/2.0f, +size.Z/2.0f)); + MeshMY.Add(new Vertex("+X-Y+Z", +size.X/2.0f, -size.Y/2.0f, +size.Z/2.0f)); MeshMY.Add(new Triangle(MeshMY.vertices[0], MeshMY.vertices[1], MeshMY.vertices[2])); MeshMY.Add(new Triangle(MeshMY.vertices[2], MeshMY.vertices[1], MeshMY.vertices[3])); @@ -327,27 +319,27 @@ namespace OpenSim.Region.Physics.OdePlugin // (P)lus Y Mesh MeshPY = new Mesh(); - MeshPY.Add(new Vertex("-X+Y-Z", -size.X / 2.0f, +size.Y / 2.0f, -size.Z / 2.0f)); - MeshPY.Add(new Vertex("+X+Y-Z", +size.X / 2.0f, +size.Y / 2.0f, -size.Z / 2.0f)); - MeshPY.Add(new Vertex("-X+Y+Z", -size.X / 2.0f, +size.Y / 2.0f, +size.Z / 2.0f)); - MeshPY.Add(new Vertex("+X+Y+Z", +size.X / 2.0f, +size.Y / 2.0f, +size.Z / 2.0f)); + MeshPY.Add(new Vertex("-X+Y-Z", -size.X/2.0f, +size.Y/2.0f, -size.Z/2.0f)); + MeshPY.Add(new Vertex("+X+Y-Z", +size.X/2.0f, +size.Y/2.0f, -size.Z/2.0f)); + MeshPY.Add(new Vertex("-X+Y+Z", -size.X/2.0f, +size.Y/2.0f, +size.Z/2.0f)); + MeshPY.Add(new Vertex("+X+Y+Z", +size.X/2.0f, +size.Y/2.0f, +size.Z/2.0f)); MeshPY.Add(new Triangle(MeshPY.vertices[1], MeshPY.vertices[0], MeshPY.vertices[2])); MeshPY.Add(new Triangle(MeshPY.vertices[1], MeshPY.vertices[2], MeshPY.vertices[3])); if (hollowFactor > 0) { - float hollowFactorF = (float)hollowFactor / (float)50000; + float hollowFactorF = (float) hollowFactor/(float) 50000; Vertex IPP; Vertex IPM; Vertex IMP; Vertex IMM; - IPP = new Vertex("Inner+X-Y+Z", +size.X * hollowFactorF / 2.0f, -size.Y * hollowFactorF / 2.0f, +size.Z / 2.0f); - IPM = new Vertex("Inner+X-Y-Z", +size.X * hollowFactorF / 2.0f, -size.Y * hollowFactorF / 2.0f, -size.Z / 2.0f); - IMP = new Vertex("Inner-X-Y+Z", -size.X * hollowFactorF / 2.0f, -size.Y * hollowFactorF / 2.0f, +size.Z / 2.0f); - IMM = new Vertex("Inner-X-Y-Z", -size.X * hollowFactorF / 2.0f, -size.Y * hollowFactorF / 2.0f, -size.Z / 2.0f); + IPP = new Vertex("Inner+X-Y+Z", +size.X*hollowFactorF/2.0f, -size.Y*hollowFactorF/2.0f, +size.Z/2.0f); + IPM = new Vertex("Inner+X-Y-Z", +size.X*hollowFactorF/2.0f, -size.Y*hollowFactorF/2.0f, -size.Z/2.0f); + IMP = new Vertex("Inner-X-Y+Z", -size.X*hollowFactorF/2.0f, -size.Y*hollowFactorF/2.0f, +size.Z/2.0f); + IMM = new Vertex("Inner-X-Y-Z", -size.X*hollowFactorF/2.0f, -size.Y*hollowFactorF/2.0f, -size.Z/2.0f); MeshMY.Add(IPP); MeshMY.Add(IPM); @@ -363,11 +355,10 @@ namespace OpenSim.Region.Physics.OdePlugin } - - IPP = new Vertex("Inner+X+Y+Z", +size.X * hollowFactorF / 2.0f, +size.Y * hollowFactorF / 2.0f, +size.Z / 2.0f); - IPM=new Vertex("Inner+X+Y-Z", +size.X * hollowFactorF / 2.0f, +size.Y * hollowFactorF / 2.0f, -size.Z / 2.0f); - IMP=new Vertex("Inner-X+Y+Z", -size.X * hollowFactorF / 2.0f, +size.Y * hollowFactorF / 2.0f, +size.Z / 2.0f); - IMM=new Vertex("Inner-X+Y-Z", -size.X * hollowFactorF / 2.0f, +size.Y * hollowFactorF / 2.0f, -size.Z / 2.0f); + IPP = new Vertex("Inner+X+Y+Z", +size.X*hollowFactorF/2.0f, +size.Y*hollowFactorF/2.0f, +size.Z/2.0f); + IPM = new Vertex("Inner+X+Y-Z", +size.X*hollowFactorF/2.0f, +size.Y*hollowFactorF/2.0f, -size.Z/2.0f); + IMP = new Vertex("Inner-X+Y+Z", -size.X*hollowFactorF/2.0f, +size.Y*hollowFactorF/2.0f, +size.Z/2.0f); + IMM = new Vertex("Inner-X+Y-Z", -size.X*hollowFactorF/2.0f, +size.Y*hollowFactorF/2.0f, -size.Z/2.0f); MeshPY.Add(IPP); MeshPY.Add(IPM); @@ -381,9 +372,6 @@ namespace OpenSim.Region.Physics.OdePlugin { PhysicsVector n = t.getNormal(); } - - - } @@ -393,9 +381,9 @@ namespace OpenSim.Region.Physics.OdePlugin return result; } - - static Mesh CreateBoxMeshZ(PrimitiveBaseShape primShape, PhysicsVector size) - // Builds the z (+ and -) surfaces of a box shaped prim + + private static Mesh CreateBoxMeshZ(PrimitiveBaseShape primShape, PhysicsVector size) + // Builds the z (+ and -) surfaces of a box shaped prim { UInt16 hollowFactor = primShape.ProfileHollow; @@ -403,10 +391,10 @@ namespace OpenSim.Region.Physics.OdePlugin // (M)inus Z Mesh MZ = new Mesh(); - MZ.Add(new Vertex("-X-Y-Z", -size.X / 2.0f, -size.Y / 2.0f, -size.Z / 2.0f)); - MZ.Add(new Vertex("+X-Y-Z", +size.X / 2.0f, -size.Y / 2.0f, -size.Z / 2.0f)); - MZ.Add(new Vertex("-X+Y-Z", -size.X / 2.0f, +size.Y / 2.0f, -size.Z / 2.0f)); - MZ.Add(new Vertex("+X+Y-Z", +size.X / 2.0f, +size.Y / 2.0f, -size.Z / 2.0f)); + MZ.Add(new Vertex("-X-Y-Z", -size.X/2.0f, -size.Y/2.0f, -size.Z/2.0f)); + MZ.Add(new Vertex("+X-Y-Z", +size.X/2.0f, -size.Y/2.0f, -size.Z/2.0f)); + MZ.Add(new Vertex("-X+Y-Z", -size.X/2.0f, +size.Y/2.0f, -size.Z/2.0f)); + MZ.Add(new Vertex("+X+Y-Z", +size.X/2.0f, +size.Y/2.0f, -size.Z/2.0f)); MZ.Add(new Triangle(MZ.vertices[1], MZ.vertices[0], MZ.vertices[2])); @@ -415,10 +403,10 @@ namespace OpenSim.Region.Physics.OdePlugin // (P)lus Z Mesh PZ = new Mesh(); - PZ.Add(new Vertex("-X-Y+Z", -size.X / 2.0f, -size.Y / 2.0f, 0.0f)); - PZ.Add(new Vertex("+X-Y+Z", +size.X / 2.0f, -size.Y / 2.0f, 0.0f)); - PZ.Add(new Vertex("-X+Y+Z", -size.X / 2.0f, +size.Y / 2.0f, 0.0f)); - PZ.Add(new Vertex("+X+Y+Z", +size.X / 2.0f, +size.Y / 2.0f, 0.0f)); + PZ.Add(new Vertex("-X-Y+Z", -size.X/2.0f, -size.Y/2.0f, 0.0f)); + PZ.Add(new Vertex("+X-Y+Z", +size.X/2.0f, -size.Y/2.0f, 0.0f)); + PZ.Add(new Vertex("-X+Y+Z", -size.X/2.0f, +size.Y/2.0f, 0.0f)); + PZ.Add(new Vertex("+X+Y+Z", +size.X/2.0f, +size.Y/2.0f, 0.0f)); // Surface 5, +Z PZ.Add(new Triangle(PZ.vertices[0], PZ.vertices[1], PZ.vertices[2])); @@ -426,12 +414,12 @@ namespace OpenSim.Region.Physics.OdePlugin if (hollowFactor > 0) { - float hollowFactorF = (float)hollowFactor / (float)50000; + float hollowFactorF = (float) hollowFactor/(float) 50000; - MZ.Add(new Vertex("-X-Y-Z", -size.X * hollowFactorF / 2.0f, -size.Y * hollowFactorF / 2.0f, 0.0f)); - MZ.Add(new Vertex("-X+Y-Z", +size.X * hollowFactorF / 2.0f, -size.Y * hollowFactorF / 2.0f, 0.0f)); - MZ.Add(new Vertex("-X-Y+Z", -size.X * hollowFactorF / 2.0f, +size.Y * hollowFactorF / 2.0f, 0.0f)); - MZ.Add(new Vertex("-X+Y+Z", +size.X * hollowFactorF / 2.0f, +size.Y * hollowFactorF / 2.0f, 0.0f)); + MZ.Add(new Vertex("-X-Y-Z", -size.X*hollowFactorF/2.0f, -size.Y*hollowFactorF/2.0f, 0.0f)); + MZ.Add(new Vertex("-X+Y-Z", +size.X*hollowFactorF/2.0f, -size.Y*hollowFactorF/2.0f, 0.0f)); + MZ.Add(new Vertex("-X-Y+Z", -size.X*hollowFactorF/2.0f, +size.Y*hollowFactorF/2.0f, 0.0f)); + MZ.Add(new Vertex("-X+Y+Z", +size.X*hollowFactorF/2.0f, +size.Y*hollowFactorF/2.0f, 0.0f)); List innerBorders = new List(); innerBorders.Add(4); @@ -441,10 +429,10 @@ namespace OpenSim.Region.Physics.OdePlugin InsertVertices(MZ.vertices, 4, MZ.triangles, innerBorders); - PZ.Add(new Vertex("-X-Y-Z", -size.X * hollowFactorF / 2.0f, -size.Y * hollowFactorF / 2.0f, 0.0f)); - PZ.Add(new Vertex("-X+Y-Z", +size.X * hollowFactorF / 2.0f, -size.Y * hollowFactorF / 2.0f, 0.0f)); - PZ.Add(new Vertex("-X-Y+Z", -size.X * hollowFactorF / 2.0f, +size.Y * hollowFactorF / 2.0f, 0.0f)); - PZ.Add(new Vertex("-X+Y+Z", +size.X * hollowFactorF / 2.0f, +size.Y * hollowFactorF / 2.0f, 0.0f)); + PZ.Add(new Vertex("-X-Y-Z", -size.X*hollowFactorF/2.0f, -size.Y*hollowFactorF/2.0f, 0.0f)); + PZ.Add(new Vertex("-X+Y-Z", +size.X*hollowFactorF/2.0f, -size.Y*hollowFactorF/2.0f, 0.0f)); + PZ.Add(new Vertex("-X-Y+Z", -size.X*hollowFactorF/2.0f, +size.Y*hollowFactorF/2.0f, 0.0f)); + PZ.Add(new Vertex("-X+Y+Z", +size.X*hollowFactorF/2.0f, +size.Y*hollowFactorF/2.0f, 0.0f)); innerBorders = new List(); innerBorders.Add(4); @@ -453,16 +441,15 @@ namespace OpenSim.Region.Physics.OdePlugin innerBorders.Add(7); InsertVertices(PZ.vertices, 4, PZ.triangles, innerBorders); - } foreach (Vertex v in PZ.vertices) { - v.point.Z = size.Z / 2.0f; + v.point.Z = size.Z/2.0f; } foreach (Vertex v in MZ.vertices) { - v.point.Z = -size.Z / 2.0f; + v.point.Z = -size.Z/2.0f; } foreach (Triangle t in MZ.triangles) @@ -486,15 +473,14 @@ namespace OpenSim.Region.Physics.OdePlugin return result; } - static Mesh CreateBoxMesh(PrimitiveBaseShape primShape, PhysicsVector size) + private static Mesh CreateBoxMesh(PrimitiveBaseShape primShape, PhysicsVector size) { Mesh result = new Mesh(); - - Mesh MeshX = Meshmerizer.CreateBoxMeshX(primShape, size); - Mesh MeshY = Meshmerizer.CreateBoxMeshY(primShape, size); - Mesh MeshZ = Meshmerizer.CreateBoxMeshZ(primShape, size); + Mesh MeshX = CreateBoxMeshX(primShape, size); + Mesh MeshY = CreateBoxMeshY(primShape, size); + Mesh MeshZ = CreateBoxMeshZ(primShape, size); result.Append(MeshX); result.Append(MeshY); @@ -504,64 +490,63 @@ namespace OpenSim.Region.Physics.OdePlugin } - public static void CalcNormals(Mesh mesh) + public static void CalcNormals(Mesh mesh) { int iTriangles = mesh.triangles.Count; mesh.normals = new float[iTriangles*3]; - int i=0; + int i = 0; foreach (Triangle t in mesh.triangles) { - float ux, uy, uz; float vx, vy, vz; float wx, wy, wz; - ux = t.v1.point.X; - uy = t.v1.point.Y; - uz = t.v1.point.Z; + ux = t.v1.point.X; + uy = t.v1.point.Y; + uz = t.v1.point.Z; - vx = t.v2.point.X; - vy = t.v2.point.Y; - vz = t.v2.point.Z; + vx = t.v2.point.X; + vy = t.v2.point.Y; + vz = t.v2.point.Z; - wx = t.v3.point.X; - wy = t.v3.point.Y; - wz = t.v3.point.Z; + wx = t.v3.point.X; + wy = t.v3.point.Y; + wz = t.v3.point.Z; - // Vectors for edges - float e1x, e1y, e1z; - float e2x, e2y, e2z; + // Vectors for edges + float e1x, e1y, e1z; + float e2x, e2y, e2z; - e1x = ux - vx; - e1y = uy - vy; - e1z = uz - vz; + e1x = ux - vx; + e1y = uy - vy; + e1z = uz - vz; - e2x = ux - wx; - e2y = uy - wy; - e2z = uz - wz; + e2x = ux - wx; + e2y = uy - wy; + e2z = uz - wz; - // Cross product for normal - float nx, ny, nz; - nx = e1y * e2z - e1z * e2y; - ny = e1z * e2x - e1x * e2z; - nz = e1x * e2y - e1y * e2x; + // Cross product for normal + float nx, ny, nz; + nx = e1y*e2z - e1z*e2y; + ny = e1z*e2x - e1x*e2z; + nz = e1x*e2y - e1y*e2x; - // Length - float l = (float)Math.Sqrt(nx * nx + ny * ny + nz * nz); + // Length + float l = (float) Math.Sqrt(nx*nx + ny*ny + nz*nz); - // Normalized "normal" - nx /= l; - ny /= l; - nz /= l; + // Normalized "normal" + nx /= l; + ny /= l; + nz /= l; mesh.normals[i] = nx; mesh.normals[i + 1] = ny; mesh.normals[i + 2] = nz; - i+=3; + i += 3; } } @@ -572,18 +557,15 @@ namespace OpenSim.Region.Physics.OdePlugin switch (primShape.ProfileShape) { case ProfileShape.Square: - mesh=CreateBoxMesh(primShape, size); + mesh = CreateBoxMesh(primShape, size); CalcNormals(mesh); break; default: - mesh=null; + mesh = null; break; } return mesh; - } } -} - - +} \ No newline at end of file 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 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ + using System; -using System.Threading; using System.Collections.Generic; - -using libsecondlife; - using Axiom.Math; using Ode.NET; using OpenSim.Framework; -using OpenSim.Framework.Console; using OpenSim.Region.Physics.Manager; - namespace OpenSim.Region.Physics.OdePlugin { /// @@ -49,7 +44,6 @@ namespace OpenSim.Region.Physics.OdePlugin public OdePlugin() { - } public bool Init() @@ -73,7 +67,6 @@ namespace OpenSim.Region.Physics.OdePlugin public void Dispose() { - } } @@ -82,17 +75,17 @@ namespace OpenSim.Region.Physics.OdePlugin private static float ODE_STEPSIZE = 0.004f; private static bool RENDER_FLAG = false; private IntPtr contactgroup; - private IntPtr LandGeom=(IntPtr)0; + private IntPtr LandGeom = (IntPtr) 0; private double[] _heightmap; private d.NearCallback nearCallback; public d.TriCallback triCallback; public d.TriArrayCallback triArrayCallback; private List _characters = new List(); private List _prims = new List(); - public Dictionary geom_name_map=new Dictionary(); + public Dictionary geom_name_map = new Dictionary(); private d.ContactGeom[] contacts = new d.ContactGeom[30]; private d.Contact contact; - private float step_time=0.0f; + private float step_time = 0.0f; public IntPtr world; public IntPtr space; public static Object OdeLock = new Object(); @@ -140,7 +133,7 @@ namespace OpenSim.Region.Physics.OdePlugin return; d.GeomClassID id = d.GeomGetClass(g1); - if (id==d.GeomClassID.TriMeshClass) + if (id == d.GeomClassID.TriMeshClass) { String name1 = null; String name2 = null; @@ -163,7 +156,6 @@ namespace OpenSim.Region.Physics.OdePlugin IntPtr joint = d.JointCreateContact(world, contactgroup, ref contact); d.JointAttach(joint, b1, b2); } - } private void collision_optimized() @@ -171,7 +163,8 @@ namespace OpenSim.Region.Physics.OdePlugin foreach (OdeCharacter chr in _characters) { d.SpaceCollide2(space, chr.Shell, IntPtr.Zero, nearCallback); - foreach (OdeCharacter ch2 in _characters) /// should be a separate space -- lots of avatars will be N**2 slow + foreach (OdeCharacter ch2 in _characters) + /// should be a separate space -- lots of avatars will be N**2 slow { d.SpaceCollide2(chr.Shell, ch2.Shell, IntPtr.Zero, nearCallback); } @@ -193,8 +186,8 @@ namespace OpenSim.Region.Physics.OdePlugin { lock (OdeLock) { - ((OdeCharacter)actor).Destroy(); - _characters.Remove((OdeCharacter)actor); + ((OdeCharacter) actor).Destroy(); + _characters.Remove((OdeCharacter) actor); } } @@ -204,13 +197,14 @@ namespace OpenSim.Region.Physics.OdePlugin { lock (OdeLock) { - d.GeomDestroy(((OdePrim)prim).prim_geom); - _prims.Remove((OdePrim)prim); + d.GeomDestroy(((OdePrim) prim).prim_geom); + _prims.Remove((OdePrim) prim); } } } - PhysicsActor AddPrim(String name, PhysicsVector position, PhysicsVector size, Quaternion rotation, Mesh mesh, PrimitiveBaseShape pbs) + private PhysicsActor AddPrim(String name, PhysicsVector position, PhysicsVector size, Quaternion rotation, + Mesh mesh, PrimitiveBaseShape pbs) { PhysicsVector pos = new PhysicsVector(); pos.X = position.X; @@ -235,7 +229,7 @@ namespace OpenSim.Region.Physics.OdePlugin } - public int TriArrayCallback(System.IntPtr trimesh, System.IntPtr refObject, int[] triangleIndex, int triCount) + public int TriArrayCallback(IntPtr trimesh, IntPtr refObject, int[] triangleIndex, int triCount) { /* String name1 = null; String name2 = null; @@ -254,15 +248,14 @@ namespace OpenSim.Region.Physics.OdePlugin return 1; } - public int TriCallback(System.IntPtr trimesh, System.IntPtr refObject, int triangleIndex) + public int TriCallback(IntPtr trimesh, IntPtr refObject, int triangleIndex) { - String name1 = null; String name2 = null; if (!geom_name_map.TryGetValue(trimesh, out name1)) { - name1 = "null"; + name1 = "null"; } if (!geom_name_map.TryGetValue(refObject, out name2)) { @@ -282,11 +275,12 @@ namespace OpenSim.Region.Physics.OdePlugin } - public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, PhysicsVector position, PhysicsVector size, Quaternion rotation) + public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, PhysicsVector position, + PhysicsVector size, Quaternion rotation) { PhysicsActor result; - switch(pbs.ProfileShape) + switch (pbs.ProfileShape) { case ProfileShape.Square: /// support simple box & hollow box now; later, more shapes @@ -310,7 +304,6 @@ namespace OpenSim.Region.Physics.OdePlugin } - public override void Simulate(float timeStep) { step_time += timeStep; @@ -327,11 +320,12 @@ namespace OpenSim.Region.Physics.OdePlugin Vector3 rx, ry, rz; p.Orientation.ToAxes(out rx, out ry, out rz); Console.WriteLine("RENDER: block; " + p.Size.X + ", " + p.Size.Y + ", " + p.Size.Z + "; " + - " 0, 0, 1; " + //shape, size, color - (p.Position.X - 128.0f) + ", " + (p.Position.Y - 128.0f) + ", " + (p.Position.Z - 33.0f) + "; " + // position - rx.x + "," + ry.x + "," + rz.x + ", " + // rotation - rx.y + "," + ry.y + "," + rz.y + ", " + - rx.z + "," + ry.z + "," + rz.z); + " 0, 0, 1; " + //shape, size, color + (p.Position.X - 128.0f) + ", " + (p.Position.Y - 128.0f) + ", " + + (p.Position.Z - 33.0f) + "; " + // position + rx.x + "," + ry.x + "," + rz.x + ", " + // rotation + rx.y + "," + ry.y + "," + rz.y + ", " + + rx.z + "," + ry.z + "," + rz.z); } } int i = 0; @@ -357,22 +351,27 @@ namespace OpenSim.Region.Physics.OdePlugin float Zoff = -33.0f; d.Matrix3 temp = d.BodyGetRotation(actor.Body); Console.WriteLine("RENDER: cylinder; " + // shape - OdeCharacter.CAPSULE_RADIUS + ", " + OdeCharacter.CAPSULE_LENGTH + //size - "; 0, 1, 0; " + // color - (actor.Position.X - 128.0f) + ", " + (actor.Position.Y - 128.0f) + ", " + (actor.Position.Z + Zoff) + "; " + // position - temp.M00 + "," + temp.M10 + "," + temp.M20 + ", " + // rotation - temp.M01 + "," + temp.M11 + "," + temp.M21 + ", " + - temp.M02 + "," + temp.M12 + "," + temp.M22); - d.Vector3 caphead; d.BodyGetRelPointPos(actor.Body, 0, 0, OdeCharacter.CAPSULE_LENGTH * .5f, out caphead); - d.Vector3 capfoot; d.BodyGetRelPointPos(actor.Body, 0, 0, -OdeCharacter.CAPSULE_LENGTH * .5f, out capfoot); + OdeCharacter.CAPSULE_RADIUS + ", " + OdeCharacter.CAPSULE_LENGTH + //size + "; 0, 1, 0; " + // color + (actor.Position.X - 128.0f) + ", " + (actor.Position.Y - 128.0f) + ", " + + (actor.Position.Z + Zoff) + "; " + // position + temp.M00 + "," + temp.M10 + "," + temp.M20 + ", " + // rotation + temp.M01 + "," + temp.M11 + "," + temp.M21 + ", " + + temp.M02 + "," + temp.M12 + "," + temp.M22); + d.Vector3 caphead; + d.BodyGetRelPointPos(actor.Body, 0, 0, OdeCharacter.CAPSULE_LENGTH*.5f, out caphead); + d.Vector3 capfoot; + d.BodyGetRelPointPos(actor.Body, 0, 0, -OdeCharacter.CAPSULE_LENGTH*.5f, out capfoot); Console.WriteLine("RENDER: sphere; " + OdeCharacter.CAPSULE_RADIUS + // shape, size - "; 1, 0, 1; " + //color - (caphead.X - 128.0f) + ", " + (caphead.Y - 128.0f) + ", " + (caphead.Z + Zoff) + "; " + // position - "1,0,0, 0,1,0, 0,0,1"); // rotation + "; 1, 0, 1; " + //color + (caphead.X - 128.0f) + ", " + (caphead.Y - 128.0f) + ", " + (caphead.Z + Zoff) + + "; " + // position + "1,0,0, 0,1,0, 0,0,1"); // rotation Console.WriteLine("RENDER: sphere; " + OdeCharacter.CAPSULE_RADIUS + // shape, size - "; 1, 0, 0; " + //color - (capfoot.X - 128.0f) + ", " + (capfoot.Y - 128.0f) + ", " + (capfoot.Z + Zoff) + "; " + // position - "1,0,0, 0,1,0, 0,0,1"); // rotation + "; 1, 0, 0; " + //color + (capfoot.X - 128.0f) + ", " + (capfoot.Y - 128.0f) + ", " + (capfoot.Z + Zoff) + + "; " + // position + "1,0,0, 0,1,0, 0,0,1"); // rotation } } } @@ -380,14 +379,11 @@ namespace OpenSim.Region.Physics.OdePlugin public override void GetResults() { - } public override bool IsThreaded { - get - { - return (false); // for now we won't be multithreaded + get { return (false); // for now we won't be multithreaded } } @@ -400,21 +396,21 @@ namespace OpenSim.Region.Physics.OdePlugin { for (int y = 0; y < 258; y++) { - int xx = x-1; + int xx = x - 1; if (xx < 0) xx = 0; if (xx > 255) xx = 255; - int yy = y-1; + int yy = y - 1; if (yy < 0) yy = 0; if (yy > 255) yy = 255; - double val = (double)heightMap[yy * 256 + xx]; - _heightmap[x * 258 + y] = val; + double val = (double) heightMap[yy*256 + xx]; + _heightmap[x*258 + y] = val; } } lock (OdeLock) { - if (!(LandGeom == (IntPtr)0)) + if (!(LandGeom == (IntPtr) 0)) { d.SpaceRemove(space, LandGeom); } @@ -422,7 +418,7 @@ namespace OpenSim.Region.Physics.OdePlugin d.GeomHeightfieldDataBuildDouble(HeightmapData, _heightmap, 0, 258, 258, 258, 258, 1.0f, 0.0f, 2.0f, 0); d.GeomHeightfieldDataSetBounds(HeightmapData, 256, 256); LandGeom = d.CreateHeightfield(space, HeightmapData, 1); - this.geom_name_map[LandGeom]="Terrain"; + geom_name_map[LandGeom] = "Terrain"; d.Matrix3 R = new d.Matrix3(); @@ -430,7 +426,7 @@ namespace OpenSim.Region.Physics.OdePlugin Quaternion q2 = Quaternion.FromAngleAxis(1.5707f, new Vector3(0, 1, 0)); //Axiom.Math.Quaternion q3 = Axiom.Math.Quaternion.FromAngleAxis(3.14f, new Axiom.Math.Vector3(0, 0, 1)); - q1 = q1 * q2; + q1 = q1*q2; //q1 = q1 * q3; Vector3 v3 = new Vector3(); float angle = 0; @@ -444,7 +440,6 @@ namespace OpenSim.Region.Physics.OdePlugin public override void DeleteTerrain() { - } } @@ -452,12 +447,12 @@ namespace OpenSim.Region.Physics.OdePlugin { private PhysicsVector _position; private d.Vector3 _zeroPosition; - private bool _zeroFlag=false; + private bool _zeroFlag = false; private PhysicsVector _velocity; private PhysicsVector _target_velocity; private PhysicsVector _acceleration; - private static float PID_D=4000.0f; - private static float PID_P=7000.0f; + private static float PID_D = 4000.0f; + private static float PID_P = 7000.0f; private static float POSTURE_SERVO = 10000.0f; public static float CAPSULE_RADIUS = 0.5f; public static float CAPSULE_LENGTH = 0.9f; @@ -484,28 +479,18 @@ namespace OpenSim.Region.Physics.OdePlugin d.BodySetPosition(Body, pos.X, pos.Y, pos.Z); d.GeomSetBody(Shell, Body); } - parent_scene.geom_name_map[Shell]=avName; - + parent_scene.geom_name_map[Shell] = avName; } public override bool Flying { - get - { - return flying; - } - set - { - flying = value; - } + get { return flying; } + set { flying = value; } } public override PhysicsVector Position { - get - { - return _position; - } + get { return _position; } set { lock (OdeScene.OdeLock) @@ -518,60 +503,34 @@ namespace OpenSim.Region.Physics.OdePlugin public override PhysicsVector Size { - get - { - return new PhysicsVector(0,0,0); - } - set - { - } + get { return new PhysicsVector(0, 0, 0); } + set { } } public override PhysicsVector Velocity { - get - { - return _velocity; - } - set - { - _target_velocity = value; - } + get { return _velocity; } + set { _target_velocity = value; } } public override bool Kinematic { - get - { - return false; - } - set - { - - } + get { return false; } + set { } } public override Quaternion Orientation { - get - { - return Quaternion.Identity; - } - set - { - - } + get { return Quaternion.Identity; } + set { } } public override PhysicsVector Acceleration { - get - { - return _acceleration; - } - + get { return _acceleration; } } + public void SetAcceleration(PhysicsVector accel) { _acceleration = accel; @@ -579,12 +538,10 @@ namespace OpenSim.Region.Physics.OdePlugin public override void AddForce(PhysicsVector force) { - } public override void SetMomentum(PhysicsVector momentum) { - } public void Move(float timeStep) @@ -603,28 +560,28 @@ namespace OpenSim.Region.Physics.OdePlugin _zeroPosition = d.BodyGetPosition(Body); } d.Vector3 pos = d.BodyGetPosition(Body); - vec.X = (_target_velocity.X - vel.X) * PID_D + (_zeroPosition.X - pos.X) * PID_P; - vec.Y = (_target_velocity.Y - vel.Y) * PID_D + (_zeroPosition.Y - pos.Y) * PID_P; + vec.X = (_target_velocity.X - vel.X)*PID_D + (_zeroPosition.X - pos.X)*PID_P; + vec.Y = (_target_velocity.Y - vel.Y)*PID_D + (_zeroPosition.Y - pos.Y)*PID_P; if (flying) { - vec.Z = (_target_velocity.Z - vel.Z) * PID_D + (_zeroPosition.Z - pos.Z) * PID_P; + vec.Z = (_target_velocity.Z - vel.Z)*PID_D + (_zeroPosition.Z - pos.Z)*PID_P; } } else { _zeroFlag = false; - vec.X = (_target_velocity.X - vel.X) * PID_D; - vec.Y = (_target_velocity.Y - vel.Y) * PID_D; + vec.X = (_target_velocity.X - vel.X)*PID_D; + vec.Y = (_target_velocity.Y - vel.Y)*PID_D; if (flying) { - vec.Z = (_target_velocity.Z - vel.Z) * PID_D; + vec.Z = (_target_velocity.Z - vel.Z)*PID_D; } } if (flying) { vec.Z += 10.0f; } - d.BodyAddForce(this.Body, vec.X, vec.Y, vec.Z); + d.BodyAddForce(Body, vec.X, vec.Y, vec.Z); // ok -- let's stand up straight! d.Vector3 feet; @@ -634,7 +591,7 @@ namespace OpenSim.Region.Physics.OdePlugin float posture = head.Z - feet.Z; // restoring force proportional to lack of posture: - float servo = (2.5f-posture) * POSTURE_SERVO; + float servo = (2.5f - posture)*POSTURE_SERVO; d.BodyAddForceAtRelPos(Body, 0.0f, 0.0f, servo, 0.0f, 0.0f, 1.0f); d.BodyAddForceAtRelPos(Body, 0.0f, 0.0f, -servo, 0.0f, 0.0f, -1.0f); } @@ -650,9 +607,9 @@ namespace OpenSim.Region.Physics.OdePlugin if (vec.X > 255.95f) vec.X = 255.95f; if (vec.Y > 255.95f) vec.Y = 255.95f; - this._position.X = vec.X; - this._position.Y = vec.Y; - this._position.Z = vec.Z; + _position.X = vec.X; + _position.Y = vec.Y; + _position.Z = vec.Z; if (_zeroFlag) { @@ -673,9 +630,9 @@ namespace OpenSim.Region.Physics.OdePlugin { lock (OdeScene.OdeLock) { - d.GeomDestroy(this.Shell); - this._parent_scene.geom_name_map.Remove(this.Shell); - d.BodyDestroy(this.Body); + d.GeomDestroy(Shell); + _parent_scene.geom_name_map.Remove(Shell); + d.BodyDestroy(Body); } } } @@ -693,7 +650,7 @@ namespace OpenSim.Region.Physics.OdePlugin public IntPtr prim_geom; public IntPtr _triMeshData; - public OdePrim(String primName, OdeScene parent_scene, PhysicsVector pos, PhysicsVector size, + public OdePrim(String primName, OdeScene parent_scene, PhysicsVector pos, PhysicsVector size, Quaternion rotation, Mesh mesh, PrimitiveBaseShape pbs) { _velocity = new PhysicsVector(); @@ -707,7 +664,7 @@ namespace OpenSim.Region.Physics.OdePlugin lock (OdeScene.OdeLock) { - if (mesh!=null) + if (mesh != null) { setMesh(parent_scene, mesh); } @@ -723,20 +680,22 @@ namespace OpenSim.Region.Physics.OdePlugin myrot.Y = rotation.y; myrot.Z = rotation.z; d.GeomSetQuaternion(prim_geom, ref myrot); - parent_scene.geom_name_map[prim_geom] = primName; // don't do .add() here; old geoms get recycled with the same hash + parent_scene.geom_name_map[prim_geom] = primName; + // don't do .add() here; old geoms get recycled with the same hash } } - public void setMesh(OdeScene parent_scene, Mesh mesh) + public void setMesh(OdeScene parent_scene, Mesh mesh) { float[] vertexList = mesh.getVertexListAsFloat(); // Note, that vertextList is pinned in memory int[] indexList = mesh.getIndexListAsInt(); // Also pinned, needs release after usage - int VertexCount = vertexList.GetLength(0) / 3; + int VertexCount = vertexList.GetLength(0)/3; int IndexCount = indexList.GetLength(0); _triMeshData = d.GeomTriMeshDataCreate(); - d.GeomTriMeshDataBuildSimple(_triMeshData, vertexList, 3 * sizeof(float), VertexCount, indexList, IndexCount, 3 * sizeof(int)); + d.GeomTriMeshDataBuildSimple(_triMeshData, vertexList, 3*sizeof (float), VertexCount, indexList, IndexCount, + 3*sizeof (int)); d.GeomTriMeshDataPreprocess(_triMeshData); prim_geom = d.CreateTriMesh(parent_scene.space, _triMeshData, parent_scene.triCallback, null, null); @@ -744,21 +703,14 @@ namespace OpenSim.Region.Physics.OdePlugin public override bool Flying { - get - { - return false; //no flying prims for you - } - set - { + get { return false; //no flying prims for you } + set { } } public override PhysicsVector Position { - get - { - return _position; - } + get { return _position; } set { _position = value; @@ -771,10 +723,7 @@ namespace OpenSim.Region.Physics.OdePlugin public override PhysicsVector Size { - get - { - return _size; - } + get { return _size; } set { _size = value; @@ -798,33 +747,19 @@ namespace OpenSim.Region.Physics.OdePlugin public override PhysicsVector Velocity { - get - { - return _velocity; - } - set - { - _velocity = value; - } + get { return _velocity; } + set { _velocity = value; } } public override bool Kinematic { - get - { - return false; - } - set - { - } + get { return false; } + set { } } public override Quaternion Orientation { - get - { - return _orientation; - } + get { return _orientation; } set { _orientation = value; @@ -842,15 +777,12 @@ namespace OpenSim.Region.Physics.OdePlugin public override PhysicsVector Acceleration { - get - { - return _acceleration; - } + get { return _acceleration; } } public void SetAcceleration(PhysicsVector accel) { - this._acceleration = accel; + _acceleration = accel; } public override void AddForce(PhysicsVector force) @@ -861,4 +793,4 @@ namespace OpenSim.Region.Physics.OdePlugin { } } -} +} \ No newline at end of file -- cgit v1.1