From 646bbbc84b8010e0dacbeed5342cdb045f46cc49 Mon Sep 17 00:00:00 2001
From: MW
Date: Wed, 27 Jun 2007 15:28:52 +0000
Subject: Some work on restructuring the namespaces / project names. Note this
doesn't compile yet as not all the code has been changed to use the new
namespaces. Am committing it now for feedback on the namespaces.
---
OpenSim/Region/Physics/OdePlugin/AssemblyInfo.cs | 58 +++
OpenSim/Region/Physics/OdePlugin/OdePlugin.cs | 456 +++++++++++++++++++++
.../OpenSim.Region.Physics.OdePlugin.csproj | 97 +++++
.../OpenSim.Region.Physics.OdePlugin.csproj.user | 12 +
4 files changed, 623 insertions(+)
create mode 100644 OpenSim/Region/Physics/OdePlugin/AssemblyInfo.cs
create mode 100644 OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
create mode 100644 OpenSim/Region/Physics/OdePlugin/OpenSim.Region.Physics.OdePlugin.csproj
create mode 100644 OpenSim/Region/Physics/OdePlugin/OpenSim.Region.Physics.OdePlugin.csproj.user
(limited to 'OpenSim/Region/Physics/OdePlugin')
diff --git a/OpenSim/Region/Physics/OdePlugin/AssemblyInfo.cs b/OpenSim/Region/Physics/OdePlugin/AssemblyInfo.cs
new file mode 100644
index 0000000..b49c8da
--- /dev/null
+++ b/OpenSim/Region/Physics/OdePlugin/AssemblyInfo.cs
@@ -0,0 +1,58 @@
+/*
+* Copyright (c) Contributors, http://www.openmetaverse.org/
+* See CONTRIBUTORS.TXT for a full list of copyright holders.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* * Redistributions in binary form must reproduce the above copyright
+* notice, this list of conditions and the following disclaimer in the
+* documentation and/or other materials provided with the distribution.
+* * Neither the name of the OpenSim Project nor the
+* names of its contributors may be used to endorse or promote products
+* derived from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
+* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+*/
+using System.Reflection;
+using System.Runtime.CompilerServices;
+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("")]
+
+// 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)]
+
+// The assembly version has following format :
+//
+// Major.Minor.Build.Revision
+//
+// 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.*")]
diff --git a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
new file mode 100644
index 0000000..8aca851
--- /dev/null
+++ b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
@@ -0,0 +1,456 @@
+/*
+* Copyright (c) Contributors, http://www.openmetaverse.org/
+* See CONTRIBUTORS.TXT for a full list of copyright holders.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* * Redistributions in binary form must reproduce the above copyright
+* notice, this list of conditions and the following disclaimer in the
+* documentation and/or other materials provided with the distribution.
+* * Neither the name of the OpenSim Project nor the
+* names of its contributors may be used to endorse or promote products
+* derived from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
+* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+*/
+using System;
+using System.Collections.Generic;
+using OpenSim.Physics.Manager;
+using Ode.NET;
+
+namespace OpenSim.Region.Physics.OdePlugin
+{
+ ///
+ /// ODE plugin
+ ///
+ public class OdePlugin : IPhysicsPlugin
+ {
+ private OdeScene _mScene;
+
+ public OdePlugin()
+ {
+
+ }
+
+ public bool Init()
+ {
+ return true;
+ }
+
+ public PhysicsScene GetScene()
+ {
+ if (_mScene == null)
+ {
+ _mScene = new OdeScene();
+ }
+ return (_mScene);
+ }
+
+ public string GetName()
+ {
+ return ("OpenDynamicsEngine");
+ }
+
+ public void Dispose()
+ {
+
+ }
+ }
+
+ public class OdeScene : PhysicsScene
+ {
+ static public IntPtr world;
+ static public IntPtr space;
+ static private IntPtr contactgroup;
+ static private IntPtr LandGeom;
+ //static private IntPtr Land;
+ private double[] _heightmap;
+ static private d.NearCallback nearCallback = near;
+ private List _characters = new List();
+ private static d.ContactGeom[] contacts = new d.ContactGeom[30];
+ private static d.Contact contact;
+
+ public OdeScene()
+ {
+ contact.surface.mode = d.ContactFlags.Bounce | d.ContactFlags.SoftCFM;
+ contact.surface.mu = d.Infinity;
+ contact.surface.mu2 = 0.0f;
+ contact.surface.bounce = 0.1f;
+ contact.surface.bounce_vel = 0.1f;
+ contact.surface.soft_cfm = 0.01f;
+
+ world = d.WorldCreate();
+ space = d.HashSpaceCreate(IntPtr.Zero);
+ contactgroup = d.JointGroupCreate(0);
+ d.WorldSetGravity(world, 0.0f, 0.0f, -0.5f);
+ //d.WorldSetCFM(world, 1e-5f);
+ d.WorldSetAutoDisableFlag(world, false);
+ d.WorldSetContactSurfaceLayer(world, 0.001f);
+ // d.CreatePlane(space, 0, 0, 1, 0);
+ this._heightmap = new double[65536];
+ }
+
+ // This function blatantly ripped off from BoxStack.cs
+ static private void near(IntPtr space, IntPtr g1, IntPtr g2)
+ {
+ IntPtr b1 = d.GeomGetBody(g1);
+ IntPtr b2 = d.GeomGetBody(g2);
+ if (b1 != IntPtr.Zero && b2 != IntPtr.Zero && d.AreConnectedExcluding(b1, b2, d.JointType.Contact))
+ return;
+
+ int count = d.Collide(g1, g2, 500, contacts, d.ContactGeom.SizeOf);
+ for (int i = 0; i < count; ++i)
+ {
+ contact.geom = contacts[i];
+ IntPtr joint = d.JointCreateContact(world, contactgroup, ref contact);
+ d.JointAttach(joint, b1, b2);
+ }
+
+ }
+
+ public override PhysicsActor AddAvatar(PhysicsVector position)
+ {
+ PhysicsVector pos = new PhysicsVector();
+ pos.X = position.X;
+ pos.Y = position.Y;
+ pos.Z = position.Z + 20;
+ OdeCharacter newAv = new OdeCharacter(this, pos);
+ this._characters.Add(newAv);
+ return newAv;
+ }
+
+ public override void RemoveAvatar(PhysicsActor actor)
+ {
+
+ }
+
+ public override PhysicsActor AddPrim(PhysicsVector position, PhysicsVector size)
+ {
+ PhysicsVector pos = new PhysicsVector();
+ pos.X = position.X;
+ pos.Y = position.Y;
+ pos.Z = position.Z;
+ PhysicsVector siz = new PhysicsVector();
+ siz.X = size.X;
+ siz.Y = size.Y;
+ siz.Z = size.Z;
+ return new OdePrim();
+ }
+
+ public override void Simulate(float timeStep)
+ {
+ foreach (OdeCharacter actor in _characters)
+ {
+ actor.Move(timeStep * 5f);
+ }
+ d.SpaceCollide(space, IntPtr.Zero, nearCallback);
+ d.WorldQuickStep(world, timeStep * 5f);
+ d.JointGroupEmpty(contactgroup);
+ foreach (OdeCharacter actor in _characters)
+ {
+ actor.UpdatePosition();
+ }
+
+ }
+
+ public override void GetResults()
+ {
+
+ }
+
+ public override bool IsThreaded
+ {
+ get
+ {
+ return (false); // for now we won't be multithreaded
+ }
+ }
+
+ public override void SetTerrain(float[] heightMap)
+ {
+ for (int i = 0; i < 65536; i++)
+ {
+ // this._heightmap[i] = (double)heightMap[i];
+ // dbm (danx0r) -- heightmap x,y must be swapped for Ode (should fix ODE, but for now...)
+ int x = i & 0xff;
+ int y = i >> 8;
+ this._heightmap[i] = (double)heightMap[x * 256 + y];
+ }
+ IntPtr HeightmapData = d.GeomHeightfieldDataCreate();
+ d.GeomHeightfieldDataBuildDouble(HeightmapData, _heightmap, 0, 256, 256, 256, 256, 1.0f, 0.0f, 2.0f, 0);
+ d.GeomHeightfieldDataSetBounds(HeightmapData, 256, 256);
+ LandGeom = d.CreateHeightfield(space, HeightmapData, 1);
+ d.Matrix3 R = new d.Matrix3();
+
+ Axiom.MathLib.Quaternion q1 =Axiom.MathLib.Quaternion.FromAngleAxis(1.5707f, new Axiom.MathLib.Vector3(1,0,0));
+ Axiom.MathLib.Quaternion q2 =Axiom.MathLib.Quaternion.FromAngleAxis(1.5707f, new Axiom.MathLib.Vector3(0,1,0));
+ //Axiom.MathLib.Quaternion q3 = Axiom.MathLib.Quaternion.FromAngleAxis(3.14f, new Axiom.MathLib.Vector3(0, 0, 1));
+
+ q1 = q1 * q2;
+ //q1 = q1 * q3;
+ Axiom.MathLib.Vector3 v3 = new Axiom.MathLib.Vector3();
+ float angle = 0;
+ q1.ToAngleAxis(ref angle, ref v3);
+
+ d.RFromAxisAndAngle(out R, v3.x, v3.y, v3.z, angle);
+ d.GeomSetRotation(LandGeom, ref R);
+ d.GeomSetPosition(LandGeom, 128, 128, 0);
+ }
+
+ public override void DeleteTerrain()
+ {
+
+ }
+ }
+
+ public class OdeCharacter : PhysicsActor
+ {
+ private PhysicsVector _position;
+ private PhysicsVector _velocity;
+ private PhysicsVector _acceleration;
+ private bool flying;
+ //private float gravityAccel;
+ private IntPtr BoundingCapsule;
+ IntPtr capsule_geom;
+ d.Mass capsule_mass;
+
+ public OdeCharacter(OdeScene parent_scene, PhysicsVector pos)
+ {
+ _velocity = new PhysicsVector();
+ _position = pos;
+ _acceleration = new PhysicsVector();
+ d.MassSetCapsule(out capsule_mass, 5.0f, 3, 0.5f, 2f);
+ capsule_geom = d.CreateCapsule(OdeScene.space, 0.5f, 2f);
+ this.BoundingCapsule = d.BodyCreate(OdeScene.world);
+ d.BodySetMass(BoundingCapsule, ref capsule_mass);
+ d.BodySetPosition(BoundingCapsule, pos.X, pos.Y, pos.Z);
+ d.GeomSetBody(capsule_geom, BoundingCapsule);
+ }
+
+ public override bool Flying
+ {
+ get
+ {
+ return flying;
+ }
+ set
+ {
+ flying = value;
+ }
+ }
+
+ public override PhysicsVector Position
+ {
+ get
+ {
+ return _position;
+ }
+ set
+ {
+ _position = value;
+ }
+ }
+
+ public override PhysicsVector Velocity
+ {
+ get
+ {
+ return _velocity;
+ }
+ set
+ {
+ _velocity = value;
+ }
+ }
+
+ public override bool Kinematic
+ {
+ get
+ {
+ return false;
+ }
+ set
+ {
+
+ }
+ }
+
+ public override Axiom.MathLib.Quaternion Orientation
+ {
+ get
+ {
+ return Axiom.MathLib.Quaternion.Identity;
+ }
+ set
+ {
+
+ }
+ }
+
+ public override PhysicsVector Acceleration
+ {
+ get
+ {
+ return _acceleration;
+ }
+
+ }
+ public void SetAcceleration(PhysicsVector accel)
+ {
+ this._acceleration = accel;
+ }
+
+ public override void AddForce(PhysicsVector force)
+ {
+
+ }
+
+ public override void SetMomentum(PhysicsVector momentum)
+ {
+
+ }
+
+ public void Move(float timeStep)
+ {
+ PhysicsVector vec = new PhysicsVector();
+ vec.X = this._velocity.X * timeStep;
+ vec.Y = this._velocity.Y * timeStep;
+ if (flying)
+ {
+ vec.Z = (this._velocity.Z + 0.5f) * timeStep;
+ }
+ d.BodySetLinearVel(this.BoundingCapsule, vec.X, vec.Y, vec.Z);
+ }
+
+ public void UpdatePosition()
+ {
+ d.Vector3 vec = d.BodyGetPosition(BoundingCapsule);
+ this._position.X = vec.X;
+ this._position.Y = vec.Y;
+ this._position.Z = vec.Z+1.0f;
+ }
+ }
+
+ public class OdePrim : PhysicsActor
+ {
+ private PhysicsVector _position;
+ private PhysicsVector _velocity;
+ private PhysicsVector _acceleration;
+
+ public OdePrim()
+ {
+ _velocity = new PhysicsVector();
+ _position = new PhysicsVector();
+ _acceleration = new PhysicsVector();
+ }
+ public override bool Flying
+ {
+ get
+ {
+ return false; //no flying prims for you
+ }
+ set
+ {
+
+ }
+ }
+ public override PhysicsVector Position
+ {
+ get
+ {
+ PhysicsVector pos = new PhysicsVector();
+ // PhysicsVector vec = this._prim.Position;
+ //pos.X = vec.X;
+ //pos.Y = vec.Y;
+ //pos.Z = vec.Z;
+ return pos;
+
+ }
+ set
+ {
+ /*PhysicsVector vec = value;
+ PhysicsVector pos = new PhysicsVector();
+ pos.X = vec.X;
+ pos.Y = vec.Y;
+ pos.Z = vec.Z;
+ this._prim.Position = pos;*/
+ }
+ }
+
+ public override PhysicsVector Velocity
+ {
+ get
+ {
+ return _velocity;
+ }
+ set
+ {
+ _velocity = value;
+ }
+ }
+
+ public override bool Kinematic
+ {
+ get
+ {
+ return false;
+ //return this._prim.Kinematic;
+ }
+ set
+ {
+ //this._prim.Kinematic = value;
+ }
+ }
+
+ public override Axiom.MathLib.Quaternion Orientation
+ {
+ get
+ {
+ Axiom.MathLib.Quaternion res = new Axiom.MathLib.Quaternion();
+ return res;
+ }
+ set
+ {
+
+ }
+ }
+
+ public override PhysicsVector Acceleration
+ {
+ get
+ {
+ return _acceleration;
+ }
+
+ }
+ public void SetAcceleration(PhysicsVector accel)
+ {
+ this._acceleration = accel;
+ }
+
+ public override void AddForce(PhysicsVector force)
+ {
+
+ }
+
+ public override void SetMomentum(PhysicsVector momentum)
+ {
+
+ }
+
+
+ }
+
+}
diff --git a/OpenSim/Region/Physics/OdePlugin/OpenSim.Region.Physics.OdePlugin.csproj b/OpenSim/Region/Physics/OdePlugin/OpenSim.Region.Physics.OdePlugin.csproj
new file mode 100644
index 0000000..490c681
--- /dev/null
+++ b/OpenSim/Region/Physics/OdePlugin/OpenSim.Region.Physics.OdePlugin.csproj
@@ -0,0 +1,97 @@
+
+
+ Local
+ 8.0.50727
+ 2.0
+ {90620634-0000-0000-0000-000000000000}
+ Debug
+ AnyCPU
+
+
+
+ OpenSim.Region.Physics.OdePlugin
+ JScript
+ Grid
+ IE50
+ false
+ Library
+
+ OpenSim.Region.Physics.OdePlugin
+
+
+
+
+
+ False
+ 285212672
+ False
+
+
+ TRACE;DEBUG
+
+ True
+ 4096
+ False
+ ..\..\..\..\bin\Physics\
+ False
+ False
+ False
+ 4
+
+
+
+ False
+ 285212672
+ False
+
+
+ TRACE
+
+ False
+ 4096
+ True
+ ..\..\..\..\bin\Physics\
+ False
+ False
+ False
+ 4
+
+
+
+
+ ..\..\..\..\bin\Axiom.MathLib.dll
+ False
+
+
+ ..\..\..\..\bin\Ode.NET.dll
+ False
+
+
+ System.dll
+ False
+
+
+
+
+ OpenSim.Region.Physics.Manager
+ {F4FF31EB-0000-0000-0000-000000000000}
+ {FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
+ False
+
+
+
+
+ Code
+
+
+ Code
+
+
+
+
+
+
+
+
+
+
diff --git a/OpenSim/Region/Physics/OdePlugin/OpenSim.Region.Physics.OdePlugin.csproj.user b/OpenSim/Region/Physics/OdePlugin/OpenSim.Region.Physics.OdePlugin.csproj.user
new file mode 100644
index 0000000..6841907
--- /dev/null
+++ b/OpenSim/Region/Physics/OdePlugin/OpenSim.Region.Physics.OdePlugin.csproj.user
@@ -0,0 +1,12 @@
+
+
+ Debug
+ AnyCPU
+ C:\New Folder\second-life-viewer\opensim-dailys2\opensim15-06\NameSpaceChanges\bin\
+ 8.0.50727
+ ProjectFiles
+ 0
+
+
+
+
--
cgit v1.1
From fe120533efd0ec6b2248d96b9a1f8b7637c5dadd Mon Sep 17 00:00:00 2001
From: mingchen
Date: Wed, 27 Jun 2007 17:12:32 +0000
Subject: *Updated prebuild.xml and ran prebuild again *Removed .user, .suo,
and unneccessary files in /bin/Physics/ *OpenSim.sln should compile with nant
and on windows now
---
.../OdePlugin/OpenSim.Region.Physics.OdePlugin.csproj.user | 12 ------------
1 file changed, 12 deletions(-)
delete mode 100644 OpenSim/Region/Physics/OdePlugin/OpenSim.Region.Physics.OdePlugin.csproj.user
(limited to 'OpenSim/Region/Physics/OdePlugin')
diff --git a/OpenSim/Region/Physics/OdePlugin/OpenSim.Region.Physics.OdePlugin.csproj.user b/OpenSim/Region/Physics/OdePlugin/OpenSim.Region.Physics.OdePlugin.csproj.user
deleted file mode 100644
index 6841907..0000000
--- a/OpenSim/Region/Physics/OdePlugin/OpenSim.Region.Physics.OdePlugin.csproj.user
+++ /dev/null
@@ -1,12 +0,0 @@
-
-
- Debug
- AnyCPU
- C:\New Folder\second-life-viewer\opensim-dailys2\opensim15-06\NameSpaceChanges\bin\
- 8.0.50727
- ProjectFiles
- 0
-
-
-
-
--
cgit v1.1
From 3456d951d89fbc83f742d40ca8ca2a1a79d414eb Mon Sep 17 00:00:00 2001
From: MW
Date: Thu, 28 Jun 2007 13:13:17 +0000
Subject: Imported the scripting changes, so now should be up to date with
sugilite.
---
.../OpenSim.Region.Physics.OdePlugin.dll.build | 43 ++++++++++++++++++++++
1 file changed, 43 insertions(+)
create mode 100644 OpenSim/Region/Physics/OdePlugin/OpenSim.Region.Physics.OdePlugin.dll.build
(limited to 'OpenSim/Region/Physics/OdePlugin')
diff --git a/OpenSim/Region/Physics/OdePlugin/OpenSim.Region.Physics.OdePlugin.dll.build b/OpenSim/Region/Physics/OdePlugin/OpenSim.Region.Physics.OdePlugin.dll.build
new file mode 100644
index 0000000..07b9386
--- /dev/null
+++ b/OpenSim/Region/Physics/OdePlugin/OpenSim.Region.Physics.OdePlugin.dll.build
@@ -0,0 +1,43 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
--
cgit v1.1
From 9b6b6d05d45cf0f754a0b26bf6240ef50be66563 Mon Sep 17 00:00:00 2001
From: lbsa71
Date: Tue, 3 Jul 2007 14:37:29 +0000
Subject: * Optimized usings (the 'LL ate my scripts' commit) * added some
licensing info
---
OpenSim/Region/Physics/OdePlugin/AssemblyInfo.cs | 2 --
OpenSim/Region/Physics/OdePlugin/OdePlugin.cs | 17 +++++++++--------
2 files changed, 9 insertions(+), 10 deletions(-)
(limited to 'OpenSim/Region/Physics/OdePlugin')
diff --git a/OpenSim/Region/Physics/OdePlugin/AssemblyInfo.cs b/OpenSim/Region/Physics/OdePlugin/AssemblyInfo.cs
index b49c8da..ee10430 100644
--- a/OpenSim/Region/Physics/OdePlugin/AssemblyInfo.cs
+++ b/OpenSim/Region/Physics/OdePlugin/AssemblyInfo.cs
@@ -26,9 +26,7 @@
*
*/
using System.Reflection;
-using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
-
// Information about this assembly is defined by the following
// attributes.
//
diff --git a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
index 8aca851..b85c052 100644
--- a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
+++ b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
@@ -27,8 +27,9 @@
*/
using System;
using System.Collections.Generic;
-using OpenSim.Physics.Manager;
+using Axiom.MathLib;
using Ode.NET;
+using OpenSim.Physics.Manager;
namespace OpenSim.Region.Physics.OdePlugin
{
@@ -194,13 +195,13 @@ namespace OpenSim.Region.Physics.OdePlugin
LandGeom = d.CreateHeightfield(space, HeightmapData, 1);
d.Matrix3 R = new d.Matrix3();
- Axiom.MathLib.Quaternion q1 =Axiom.MathLib.Quaternion.FromAngleAxis(1.5707f, new Axiom.MathLib.Vector3(1,0,0));
- Axiom.MathLib.Quaternion q2 =Axiom.MathLib.Quaternion.FromAngleAxis(1.5707f, new Axiom.MathLib.Vector3(0,1,0));
+ Quaternion q1 =Quaternion.FromAngleAxis(1.5707f, new Vector3(1,0,0));
+ Quaternion q2 =Quaternion.FromAngleAxis(1.5707f, new Vector3(0,1,0));
//Axiom.MathLib.Quaternion q3 = Axiom.MathLib.Quaternion.FromAngleAxis(3.14f, new Axiom.MathLib.Vector3(0, 0, 1));
q1 = q1 * q2;
//q1 = q1 * q3;
- Axiom.MathLib.Vector3 v3 = new Axiom.MathLib.Vector3();
+ Vector3 v3 = new Vector3();
float angle = 0;
q1.ToAngleAxis(ref angle, ref v3);
@@ -287,11 +288,11 @@ namespace OpenSim.Region.Physics.OdePlugin
}
}
- public override Axiom.MathLib.Quaternion Orientation
+ public override Quaternion Orientation
{
get
{
- return Axiom.MathLib.Quaternion.Identity;
+ return Quaternion.Identity;
}
set
{
@@ -414,11 +415,11 @@ namespace OpenSim.Region.Physics.OdePlugin
}
}
- public override Axiom.MathLib.Quaternion Orientation
+ public override Quaternion Orientation
{
get
{
- Axiom.MathLib.Quaternion res = new Axiom.MathLib.Quaternion();
+ Quaternion res = new Quaternion();
return res;
}
set
--
cgit v1.1
From beb3073bec9438a439e13eaec40a8320a9279adc Mon Sep 17 00:00:00 2001
From: MW
Date: Wed, 4 Jul 2007 19:07:27 +0000
Subject: A bit more work on Building tools/support. updated Axiom.MathLib.dll.
---
OpenSim/Region/Physics/OdePlugin/OdePlugin.cs | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
(limited to 'OpenSim/Region/Physics/OdePlugin')
diff --git a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
index b85c052..2780188 100644
--- a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
+++ b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
@@ -27,7 +27,7 @@
*/
using System;
using System.Collections.Generic;
-using Axiom.MathLib;
+using Axiom.Math;
using Ode.NET;
using OpenSim.Physics.Manager;
@@ -197,7 +197,7 @@ namespace OpenSim.Region.Physics.OdePlugin
Quaternion q1 =Quaternion.FromAngleAxis(1.5707f, new Vector3(1,0,0));
Quaternion q2 =Quaternion.FromAngleAxis(1.5707f, new Vector3(0,1,0));
- //Axiom.MathLib.Quaternion q3 = Axiom.MathLib.Quaternion.FromAngleAxis(3.14f, new Axiom.MathLib.Vector3(0, 0, 1));
+ //Axiom.Math.Quaternion q3 = Axiom.Math.Quaternion.FromAngleAxis(3.14f, new Axiom.Math.Vector3(0, 0, 1));
q1 = q1 * q2;
//q1 = q1 * q3;
--
cgit v1.1
From 5f8de1e7045b9daa2d4f3b21ca826987e32efe6e Mon Sep 17 00:00:00 2001
From: lbsa71
Date: Sun, 8 Jul 2007 19:27:04 +0000
Subject: * By popular demand, all generated build files are now deleted.
Somebody should make sure the wiki is updated.
---
.../OpenSim.Region.Physics.OdePlugin.csproj | 97 ----------------------
.../OpenSim.Region.Physics.OdePlugin.dll.build | 43 ----------
2 files changed, 140 deletions(-)
delete mode 100644 OpenSim/Region/Physics/OdePlugin/OpenSim.Region.Physics.OdePlugin.csproj
delete mode 100644 OpenSim/Region/Physics/OdePlugin/OpenSim.Region.Physics.OdePlugin.dll.build
(limited to 'OpenSim/Region/Physics/OdePlugin')
diff --git a/OpenSim/Region/Physics/OdePlugin/OpenSim.Region.Physics.OdePlugin.csproj b/OpenSim/Region/Physics/OdePlugin/OpenSim.Region.Physics.OdePlugin.csproj
deleted file mode 100644
index 490c681..0000000
--- a/OpenSim/Region/Physics/OdePlugin/OpenSim.Region.Physics.OdePlugin.csproj
+++ /dev/null
@@ -1,97 +0,0 @@
-
-
- Local
- 8.0.50727
- 2.0
- {90620634-0000-0000-0000-000000000000}
- Debug
- AnyCPU
-
-
-
- OpenSim.Region.Physics.OdePlugin
- JScript
- Grid
- IE50
- false
- Library
-
- OpenSim.Region.Physics.OdePlugin
-
-
-
-
-
- False
- 285212672
- False
-
-
- TRACE;DEBUG
-
- True
- 4096
- False
- ..\..\..\..\bin\Physics\
- False
- False
- False
- 4
-
-
-
- False
- 285212672
- False
-
-
- TRACE
-
- False
- 4096
- True
- ..\..\..\..\bin\Physics\
- False
- False
- False
- 4
-
-
-
-
- ..\..\..\..\bin\Axiom.MathLib.dll
- False
-
-
- ..\..\..\..\bin\Ode.NET.dll
- False
-
-
- System.dll
- False
-
-
-
-
- OpenSim.Region.Physics.Manager
- {F4FF31EB-0000-0000-0000-000000000000}
- {FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
- False
-
-
-
-
- Code
-
-
- Code
-
-
-
-
-
-
-
-
-
-
diff --git a/OpenSim/Region/Physics/OdePlugin/OpenSim.Region.Physics.OdePlugin.dll.build b/OpenSim/Region/Physics/OdePlugin/OpenSim.Region.Physics.OdePlugin.dll.build
deleted file mode 100644
index 07b9386..0000000
--- a/OpenSim/Region/Physics/OdePlugin/OpenSim.Region.Physics.OdePlugin.dll.build
+++ /dev/null
@@ -1,43 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
--
cgit v1.1
From 2a3c79df83e800d5dfe75a1a3b140ed81da2b1d6 Mon Sep 17 00:00:00 2001
From: Sean Dague
Date: Mon, 16 Jul 2007 15:40:11 +0000
Subject: changed to native line ending encoding
---
OpenSim/Region/Physics/OdePlugin/AssemblyInfo.cs | 112 +--
OpenSim/Region/Physics/OdePlugin/OdePlugin.cs | 914 +++++++++++------------
2 files changed, 513 insertions(+), 513 deletions(-)
(limited to 'OpenSim/Region/Physics/OdePlugin')
diff --git a/OpenSim/Region/Physics/OdePlugin/AssemblyInfo.cs b/OpenSim/Region/Physics/OdePlugin/AssemblyInfo.cs
index ee10430..662b75a 100644
--- a/OpenSim/Region/Physics/OdePlugin/AssemblyInfo.cs
+++ b/OpenSim/Region/Physics/OdePlugin/AssemblyInfo.cs
@@ -1,56 +1,56 @@
-/*
-* Copyright (c) Contributors, http://www.openmetaverse.org/
-* See CONTRIBUTORS.TXT for a full list of copyright holders.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions are met:
-* * Redistributions of source code must retain the above copyright
-* notice, this list of conditions and the following disclaimer.
-* * Redistributions in binary form must reproduce the above copyright
-* notice, this list of conditions and the following disclaimer in the
-* documentation and/or other materials provided with the distribution.
-* * Neither the name of the OpenSim Project nor the
-* names of its contributors may be used to endorse or promote products
-* derived from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
-* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
-* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*
-*/
-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("")]
-
-// 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)]
-
-// The assembly version has following format :
-//
-// Major.Minor.Build.Revision
-//
-// 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.*")]
+/*
+* Copyright (c) Contributors, http://www.openmetaverse.org/
+* See CONTRIBUTORS.TXT for a full list of copyright holders.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* * Redistributions in binary form must reproduce the above copyright
+* notice, this list of conditions and the following disclaimer in the
+* documentation and/or other materials provided with the distribution.
+* * Neither the name of the OpenSim Project nor the
+* names of its contributors may be used to endorse or promote products
+* derived from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
+* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+*/
+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("")]
+
+// 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)]
+
+// The assembly version has following format :
+//
+// Major.Minor.Build.Revision
+//
+// 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.*")]
diff --git a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
index 2780188..486fa9e 100644
--- a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
+++ b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
@@ -1,457 +1,457 @@
-/*
-* Copyright (c) Contributors, http://www.openmetaverse.org/
-* See CONTRIBUTORS.TXT for a full list of copyright holders.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions are met:
-* * Redistributions of source code must retain the above copyright
-* notice, this list of conditions and the following disclaimer.
-* * Redistributions in binary form must reproduce the above copyright
-* notice, this list of conditions and the following disclaimer in the
-* documentation and/or other materials provided with the distribution.
-* * Neither the name of the OpenSim Project nor the
-* names of its contributors may be used to endorse or promote products
-* derived from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
-* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
-* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*
-*/
-using System;
-using System.Collections.Generic;
-using Axiom.Math;
-using Ode.NET;
-using OpenSim.Physics.Manager;
-
-namespace OpenSim.Region.Physics.OdePlugin
-{
- ///
- /// ODE plugin
- ///
- public class OdePlugin : IPhysicsPlugin
- {
- private OdeScene _mScene;
-
- public OdePlugin()
- {
-
- }
-
- public bool Init()
- {
- return true;
- }
-
- public PhysicsScene GetScene()
- {
- if (_mScene == null)
- {
- _mScene = new OdeScene();
- }
- return (_mScene);
- }
-
- public string GetName()
- {
- return ("OpenDynamicsEngine");
- }
-
- public void Dispose()
- {
-
- }
- }
-
- public class OdeScene : PhysicsScene
- {
- static public IntPtr world;
- static public IntPtr space;
- static private IntPtr contactgroup;
- static private IntPtr LandGeom;
- //static private IntPtr Land;
- private double[] _heightmap;
- static private d.NearCallback nearCallback = near;
- private List _characters = new List();
- private static d.ContactGeom[] contacts = new d.ContactGeom[30];
- private static d.Contact contact;
-
- public OdeScene()
- {
- contact.surface.mode = d.ContactFlags.Bounce | d.ContactFlags.SoftCFM;
- contact.surface.mu = d.Infinity;
- contact.surface.mu2 = 0.0f;
- contact.surface.bounce = 0.1f;
- contact.surface.bounce_vel = 0.1f;
- contact.surface.soft_cfm = 0.01f;
-
- world = d.WorldCreate();
- space = d.HashSpaceCreate(IntPtr.Zero);
- contactgroup = d.JointGroupCreate(0);
- d.WorldSetGravity(world, 0.0f, 0.0f, -0.5f);
- //d.WorldSetCFM(world, 1e-5f);
- d.WorldSetAutoDisableFlag(world, false);
- d.WorldSetContactSurfaceLayer(world, 0.001f);
- // d.CreatePlane(space, 0, 0, 1, 0);
- this._heightmap = new double[65536];
- }
-
- // This function blatantly ripped off from BoxStack.cs
- static private void near(IntPtr space, IntPtr g1, IntPtr g2)
- {
- IntPtr b1 = d.GeomGetBody(g1);
- IntPtr b2 = d.GeomGetBody(g2);
- if (b1 != IntPtr.Zero && b2 != IntPtr.Zero && d.AreConnectedExcluding(b1, b2, d.JointType.Contact))
- return;
-
- int count = d.Collide(g1, g2, 500, contacts, d.ContactGeom.SizeOf);
- for (int i = 0; i < count; ++i)
- {
- contact.geom = contacts[i];
- IntPtr joint = d.JointCreateContact(world, contactgroup, ref contact);
- d.JointAttach(joint, b1, b2);
- }
-
- }
-
- public override PhysicsActor AddAvatar(PhysicsVector position)
- {
- PhysicsVector pos = new PhysicsVector();
- pos.X = position.X;
- pos.Y = position.Y;
- pos.Z = position.Z + 20;
- OdeCharacter newAv = new OdeCharacter(this, pos);
- this._characters.Add(newAv);
- return newAv;
- }
-
- public override void RemoveAvatar(PhysicsActor actor)
- {
-
- }
-
- public override PhysicsActor AddPrim(PhysicsVector position, PhysicsVector size)
- {
- PhysicsVector pos = new PhysicsVector();
- pos.X = position.X;
- pos.Y = position.Y;
- pos.Z = position.Z;
- PhysicsVector siz = new PhysicsVector();
- siz.X = size.X;
- siz.Y = size.Y;
- siz.Z = size.Z;
- return new OdePrim();
- }
-
- public override void Simulate(float timeStep)
- {
- foreach (OdeCharacter actor in _characters)
- {
- actor.Move(timeStep * 5f);
- }
- d.SpaceCollide(space, IntPtr.Zero, nearCallback);
- d.WorldQuickStep(world, timeStep * 5f);
- d.JointGroupEmpty(contactgroup);
- foreach (OdeCharacter actor in _characters)
- {
- actor.UpdatePosition();
- }
-
- }
-
- public override void GetResults()
- {
-
- }
-
- public override bool IsThreaded
- {
- get
- {
- return (false); // for now we won't be multithreaded
- }
- }
-
- public override void SetTerrain(float[] heightMap)
- {
- for (int i = 0; i < 65536; i++)
- {
- // this._heightmap[i] = (double)heightMap[i];
- // dbm (danx0r) -- heightmap x,y must be swapped for Ode (should fix ODE, but for now...)
- int x = i & 0xff;
- int y = i >> 8;
- this._heightmap[i] = (double)heightMap[x * 256 + y];
- }
- IntPtr HeightmapData = d.GeomHeightfieldDataCreate();
- d.GeomHeightfieldDataBuildDouble(HeightmapData, _heightmap, 0, 256, 256, 256, 256, 1.0f, 0.0f, 2.0f, 0);
- d.GeomHeightfieldDataSetBounds(HeightmapData, 256, 256);
- LandGeom = d.CreateHeightfield(space, HeightmapData, 1);
- d.Matrix3 R = new d.Matrix3();
-
- Quaternion q1 =Quaternion.FromAngleAxis(1.5707f, new Vector3(1,0,0));
- 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 * q3;
- Vector3 v3 = new Vector3();
- float angle = 0;
- q1.ToAngleAxis(ref angle, ref v3);
-
- d.RFromAxisAndAngle(out R, v3.x, v3.y, v3.z, angle);
- d.GeomSetRotation(LandGeom, ref R);
- d.GeomSetPosition(LandGeom, 128, 128, 0);
- }
-
- public override void DeleteTerrain()
- {
-
- }
- }
-
- public class OdeCharacter : PhysicsActor
- {
- private PhysicsVector _position;
- private PhysicsVector _velocity;
- private PhysicsVector _acceleration;
- private bool flying;
- //private float gravityAccel;
- private IntPtr BoundingCapsule;
- IntPtr capsule_geom;
- d.Mass capsule_mass;
-
- public OdeCharacter(OdeScene parent_scene, PhysicsVector pos)
- {
- _velocity = new PhysicsVector();
- _position = pos;
- _acceleration = new PhysicsVector();
- d.MassSetCapsule(out capsule_mass, 5.0f, 3, 0.5f, 2f);
- capsule_geom = d.CreateCapsule(OdeScene.space, 0.5f, 2f);
- this.BoundingCapsule = d.BodyCreate(OdeScene.world);
- d.BodySetMass(BoundingCapsule, ref capsule_mass);
- d.BodySetPosition(BoundingCapsule, pos.X, pos.Y, pos.Z);
- d.GeomSetBody(capsule_geom, BoundingCapsule);
- }
-
- public override bool Flying
- {
- get
- {
- return flying;
- }
- set
- {
- flying = value;
- }
- }
-
- public override PhysicsVector Position
- {
- get
- {
- return _position;
- }
- set
- {
- _position = value;
- }
- }
-
- public override PhysicsVector Velocity
- {
- get
- {
- return _velocity;
- }
- set
- {
- _velocity = value;
- }
- }
-
- public override bool Kinematic
- {
- get
- {
- return false;
- }
- set
- {
-
- }
- }
-
- public override Quaternion Orientation
- {
- get
- {
- return Quaternion.Identity;
- }
- set
- {
-
- }
- }
-
- public override PhysicsVector Acceleration
- {
- get
- {
- return _acceleration;
- }
-
- }
- public void SetAcceleration(PhysicsVector accel)
- {
- this._acceleration = accel;
- }
-
- public override void AddForce(PhysicsVector force)
- {
-
- }
-
- public override void SetMomentum(PhysicsVector momentum)
- {
-
- }
-
- public void Move(float timeStep)
- {
- PhysicsVector vec = new PhysicsVector();
- vec.X = this._velocity.X * timeStep;
- vec.Y = this._velocity.Y * timeStep;
- if (flying)
- {
- vec.Z = (this._velocity.Z + 0.5f) * timeStep;
- }
- d.BodySetLinearVel(this.BoundingCapsule, vec.X, vec.Y, vec.Z);
- }
-
- public void UpdatePosition()
- {
- d.Vector3 vec = d.BodyGetPosition(BoundingCapsule);
- this._position.X = vec.X;
- this._position.Y = vec.Y;
- this._position.Z = vec.Z+1.0f;
- }
- }
-
- public class OdePrim : PhysicsActor
- {
- private PhysicsVector _position;
- private PhysicsVector _velocity;
- private PhysicsVector _acceleration;
-
- public OdePrim()
- {
- _velocity = new PhysicsVector();
- _position = new PhysicsVector();
- _acceleration = new PhysicsVector();
- }
- public override bool Flying
- {
- get
- {
- return false; //no flying prims for you
- }
- set
- {
-
- }
- }
- public override PhysicsVector Position
- {
- get
- {
- PhysicsVector pos = new PhysicsVector();
- // PhysicsVector vec = this._prim.Position;
- //pos.X = vec.X;
- //pos.Y = vec.Y;
- //pos.Z = vec.Z;
- return pos;
-
- }
- set
- {
- /*PhysicsVector vec = value;
- PhysicsVector pos = new PhysicsVector();
- pos.X = vec.X;
- pos.Y = vec.Y;
- pos.Z = vec.Z;
- this._prim.Position = pos;*/
- }
- }
-
- public override PhysicsVector Velocity
- {
- get
- {
- return _velocity;
- }
- set
- {
- _velocity = value;
- }
- }
-
- public override bool Kinematic
- {
- get
- {
- return false;
- //return this._prim.Kinematic;
- }
- set
- {
- //this._prim.Kinematic = value;
- }
- }
-
- public override Quaternion Orientation
- {
- get
- {
- Quaternion res = new Quaternion();
- return res;
- }
- set
- {
-
- }
- }
-
- public override PhysicsVector Acceleration
- {
- get
- {
- return _acceleration;
- }
-
- }
- public void SetAcceleration(PhysicsVector accel)
- {
- this._acceleration = accel;
- }
-
- public override void AddForce(PhysicsVector force)
- {
-
- }
-
- public override void SetMomentum(PhysicsVector momentum)
- {
-
- }
-
-
- }
-
-}
+/*
+* Copyright (c) Contributors, http://www.openmetaverse.org/
+* See CONTRIBUTORS.TXT for a full list of copyright holders.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* * Redistributions in binary form must reproduce the above copyright
+* notice, this list of conditions and the following disclaimer in the
+* documentation and/or other materials provided with the distribution.
+* * Neither the name of the OpenSim Project nor the
+* names of its contributors may be used to endorse or promote products
+* derived from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
+* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+*/
+using System;
+using System.Collections.Generic;
+using Axiom.Math;
+using Ode.NET;
+using OpenSim.Physics.Manager;
+
+namespace OpenSim.Region.Physics.OdePlugin
+{
+ ///
+ /// ODE plugin
+ ///
+ public class OdePlugin : IPhysicsPlugin
+ {
+ private OdeScene _mScene;
+
+ public OdePlugin()
+ {
+
+ }
+
+ public bool Init()
+ {
+ return true;
+ }
+
+ public PhysicsScene GetScene()
+ {
+ if (_mScene == null)
+ {
+ _mScene = new OdeScene();
+ }
+ return (_mScene);
+ }
+
+ public string GetName()
+ {
+ return ("OpenDynamicsEngine");
+ }
+
+ public void Dispose()
+ {
+
+ }
+ }
+
+ public class OdeScene : PhysicsScene
+ {
+ static public IntPtr world;
+ static public IntPtr space;
+ static private IntPtr contactgroup;
+ static private IntPtr LandGeom;
+ //static private IntPtr Land;
+ private double[] _heightmap;
+ static private d.NearCallback nearCallback = near;
+ private List _characters = new List();
+ private static d.ContactGeom[] contacts = new d.ContactGeom[30];
+ private static d.Contact contact;
+
+ public OdeScene()
+ {
+ contact.surface.mode = d.ContactFlags.Bounce | d.ContactFlags.SoftCFM;
+ contact.surface.mu = d.Infinity;
+ contact.surface.mu2 = 0.0f;
+ contact.surface.bounce = 0.1f;
+ contact.surface.bounce_vel = 0.1f;
+ contact.surface.soft_cfm = 0.01f;
+
+ world = d.WorldCreate();
+ space = d.HashSpaceCreate(IntPtr.Zero);
+ contactgroup = d.JointGroupCreate(0);
+ d.WorldSetGravity(world, 0.0f, 0.0f, -0.5f);
+ //d.WorldSetCFM(world, 1e-5f);
+ d.WorldSetAutoDisableFlag(world, false);
+ d.WorldSetContactSurfaceLayer(world, 0.001f);
+ // d.CreatePlane(space, 0, 0, 1, 0);
+ this._heightmap = new double[65536];
+ }
+
+ // This function blatantly ripped off from BoxStack.cs
+ static private void near(IntPtr space, IntPtr g1, IntPtr g2)
+ {
+ IntPtr b1 = d.GeomGetBody(g1);
+ IntPtr b2 = d.GeomGetBody(g2);
+ if (b1 != IntPtr.Zero && b2 != IntPtr.Zero && d.AreConnectedExcluding(b1, b2, d.JointType.Contact))
+ return;
+
+ int count = d.Collide(g1, g2, 500, contacts, d.ContactGeom.SizeOf);
+ for (int i = 0; i < count; ++i)
+ {
+ contact.geom = contacts[i];
+ IntPtr joint = d.JointCreateContact(world, contactgroup, ref contact);
+ d.JointAttach(joint, b1, b2);
+ }
+
+ }
+
+ public override PhysicsActor AddAvatar(PhysicsVector position)
+ {
+ PhysicsVector pos = new PhysicsVector();
+ pos.X = position.X;
+ pos.Y = position.Y;
+ pos.Z = position.Z + 20;
+ OdeCharacter newAv = new OdeCharacter(this, pos);
+ this._characters.Add(newAv);
+ return newAv;
+ }
+
+ public override void RemoveAvatar(PhysicsActor actor)
+ {
+
+ }
+
+ public override PhysicsActor AddPrim(PhysicsVector position, PhysicsVector size)
+ {
+ PhysicsVector pos = new PhysicsVector();
+ pos.X = position.X;
+ pos.Y = position.Y;
+ pos.Z = position.Z;
+ PhysicsVector siz = new PhysicsVector();
+ siz.X = size.X;
+ siz.Y = size.Y;
+ siz.Z = size.Z;
+ return new OdePrim();
+ }
+
+ public override void Simulate(float timeStep)
+ {
+ foreach (OdeCharacter actor in _characters)
+ {
+ actor.Move(timeStep * 5f);
+ }
+ d.SpaceCollide(space, IntPtr.Zero, nearCallback);
+ d.WorldQuickStep(world, timeStep * 5f);
+ d.JointGroupEmpty(contactgroup);
+ foreach (OdeCharacter actor in _characters)
+ {
+ actor.UpdatePosition();
+ }
+
+ }
+
+ public override void GetResults()
+ {
+
+ }
+
+ public override bool IsThreaded
+ {
+ get
+ {
+ return (false); // for now we won't be multithreaded
+ }
+ }
+
+ public override void SetTerrain(float[] heightMap)
+ {
+ for (int i = 0; i < 65536; i++)
+ {
+ // this._heightmap[i] = (double)heightMap[i];
+ // dbm (danx0r) -- heightmap x,y must be swapped for Ode (should fix ODE, but for now...)
+ int x = i & 0xff;
+ int y = i >> 8;
+ this._heightmap[i] = (double)heightMap[x * 256 + y];
+ }
+ IntPtr HeightmapData = d.GeomHeightfieldDataCreate();
+ d.GeomHeightfieldDataBuildDouble(HeightmapData, _heightmap, 0, 256, 256, 256, 256, 1.0f, 0.0f, 2.0f, 0);
+ d.GeomHeightfieldDataSetBounds(HeightmapData, 256, 256);
+ LandGeom = d.CreateHeightfield(space, HeightmapData, 1);
+ d.Matrix3 R = new d.Matrix3();
+
+ Quaternion q1 =Quaternion.FromAngleAxis(1.5707f, new Vector3(1,0,0));
+ 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 * q3;
+ Vector3 v3 = new Vector3();
+ float angle = 0;
+ q1.ToAngleAxis(ref angle, ref v3);
+
+ d.RFromAxisAndAngle(out R, v3.x, v3.y, v3.z, angle);
+ d.GeomSetRotation(LandGeom, ref R);
+ d.GeomSetPosition(LandGeom, 128, 128, 0);
+ }
+
+ public override void DeleteTerrain()
+ {
+
+ }
+ }
+
+ public class OdeCharacter : PhysicsActor
+ {
+ private PhysicsVector _position;
+ private PhysicsVector _velocity;
+ private PhysicsVector _acceleration;
+ private bool flying;
+ //private float gravityAccel;
+ private IntPtr BoundingCapsule;
+ IntPtr capsule_geom;
+ d.Mass capsule_mass;
+
+ public OdeCharacter(OdeScene parent_scene, PhysicsVector pos)
+ {
+ _velocity = new PhysicsVector();
+ _position = pos;
+ _acceleration = new PhysicsVector();
+ d.MassSetCapsule(out capsule_mass, 5.0f, 3, 0.5f, 2f);
+ capsule_geom = d.CreateCapsule(OdeScene.space, 0.5f, 2f);
+ this.BoundingCapsule = d.BodyCreate(OdeScene.world);
+ d.BodySetMass(BoundingCapsule, ref capsule_mass);
+ d.BodySetPosition(BoundingCapsule, pos.X, pos.Y, pos.Z);
+ d.GeomSetBody(capsule_geom, BoundingCapsule);
+ }
+
+ public override bool Flying
+ {
+ get
+ {
+ return flying;
+ }
+ set
+ {
+ flying = value;
+ }
+ }
+
+ public override PhysicsVector Position
+ {
+ get
+ {
+ return _position;
+ }
+ set
+ {
+ _position = value;
+ }
+ }
+
+ public override PhysicsVector Velocity
+ {
+ get
+ {
+ return _velocity;
+ }
+ set
+ {
+ _velocity = value;
+ }
+ }
+
+ public override bool Kinematic
+ {
+ get
+ {
+ return false;
+ }
+ set
+ {
+
+ }
+ }
+
+ public override Quaternion Orientation
+ {
+ get
+ {
+ return Quaternion.Identity;
+ }
+ set
+ {
+
+ }
+ }
+
+ public override PhysicsVector Acceleration
+ {
+ get
+ {
+ return _acceleration;
+ }
+
+ }
+ public void SetAcceleration(PhysicsVector accel)
+ {
+ this._acceleration = accel;
+ }
+
+ public override void AddForce(PhysicsVector force)
+ {
+
+ }
+
+ public override void SetMomentum(PhysicsVector momentum)
+ {
+
+ }
+
+ public void Move(float timeStep)
+ {
+ PhysicsVector vec = new PhysicsVector();
+ vec.X = this._velocity.X * timeStep;
+ vec.Y = this._velocity.Y * timeStep;
+ if (flying)
+ {
+ vec.Z = (this._velocity.Z + 0.5f) * timeStep;
+ }
+ d.BodySetLinearVel(this.BoundingCapsule, vec.X, vec.Y, vec.Z);
+ }
+
+ public void UpdatePosition()
+ {
+ d.Vector3 vec = d.BodyGetPosition(BoundingCapsule);
+ this._position.X = vec.X;
+ this._position.Y = vec.Y;
+ this._position.Z = vec.Z+1.0f;
+ }
+ }
+
+ public class OdePrim : PhysicsActor
+ {
+ private PhysicsVector _position;
+ private PhysicsVector _velocity;
+ private PhysicsVector _acceleration;
+
+ public OdePrim()
+ {
+ _velocity = new PhysicsVector();
+ _position = new PhysicsVector();
+ _acceleration = new PhysicsVector();
+ }
+ public override bool Flying
+ {
+ get
+ {
+ return false; //no flying prims for you
+ }
+ set
+ {
+
+ }
+ }
+ public override PhysicsVector Position
+ {
+ get
+ {
+ PhysicsVector pos = new PhysicsVector();
+ // PhysicsVector vec = this._prim.Position;
+ //pos.X = vec.X;
+ //pos.Y = vec.Y;
+ //pos.Z = vec.Z;
+ return pos;
+
+ }
+ set
+ {
+ /*PhysicsVector vec = value;
+ PhysicsVector pos = new PhysicsVector();
+ pos.X = vec.X;
+ pos.Y = vec.Y;
+ pos.Z = vec.Z;
+ this._prim.Position = pos;*/
+ }
+ }
+
+ public override PhysicsVector Velocity
+ {
+ get
+ {
+ return _velocity;
+ }
+ set
+ {
+ _velocity = value;
+ }
+ }
+
+ public override bool Kinematic
+ {
+ get
+ {
+ return false;
+ //return this._prim.Kinematic;
+ }
+ set
+ {
+ //this._prim.Kinematic = value;
+ }
+ }
+
+ public override Quaternion Orientation
+ {
+ get
+ {
+ Quaternion res = new Quaternion();
+ return res;
+ }
+ set
+ {
+
+ }
+ }
+
+ public override PhysicsVector Acceleration
+ {
+ get
+ {
+ return _acceleration;
+ }
+
+ }
+ public void SetAcceleration(PhysicsVector accel)
+ {
+ this._acceleration = accel;
+ }
+
+ public override void AddForce(PhysicsVector force)
+ {
+
+ }
+
+ public override void SetMomentum(PhysicsVector momentum)
+ {
+
+ }
+
+
+ }
+
+}
--
cgit v1.1
From 3520e9e3ee068e393a79a9699069bf20fc5c1a83 Mon Sep 17 00:00:00 2001
From: MW
Date: Sat, 11 Aug 2007 17:54:46 +0000
Subject: Applied danx0r 's ODE patch [mantis issue 263]
---
OpenSim/Region/Physics/OdePlugin/OdePlugin.cs | 41 ++++++++++++++-------------
1 file changed, 21 insertions(+), 20 deletions(-)
(limited to 'OpenSim/Region/Physics/OdePlugin')
diff --git a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
index 486fa9e..4b1d3f0 100644
--- a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
+++ b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
@@ -85,21 +85,18 @@ namespace OpenSim.Region.Physics.OdePlugin
public OdeScene()
{
- contact.surface.mode = d.ContactFlags.Bounce | d.ContactFlags.SoftCFM;
- contact.surface.mu = d.Infinity;
- contact.surface.mu2 = 0.0f;
- contact.surface.bounce = 0.1f;
- contact.surface.bounce_vel = 0.1f;
- contact.surface.soft_cfm = 0.01f;
+ contact.surface.mode |= d.ContactFlags.Approx1 | d.ContactFlags.SoftCFM | d.ContactFlags.SoftERP;
+ contact.surface.mu = 10.0f;
+ contact.surface.bounce = 0.9f;
+ contact.surface.soft_erp = 0.005f;
+ contact.surface.soft_cfm = 0.00003f;
world = d.WorldCreate();
space = d.HashSpaceCreate(IntPtr.Zero);
contactgroup = d.JointGroupCreate(0);
- d.WorldSetGravity(world, 0.0f, 0.0f, -0.5f);
- //d.WorldSetCFM(world, 1e-5f);
+ d.WorldSetGravity(world, 0.0f, 0.0f, -10.0f);
d.WorldSetAutoDisableFlag(world, false);
d.WorldSetContactSurfaceLayer(world, 0.001f);
- // d.CreatePlane(space, 0, 0, 1, 0);
this._heightmap = new double[65536];
}
@@ -154,16 +151,19 @@ namespace OpenSim.Region.Physics.OdePlugin
{
foreach (OdeCharacter actor in _characters)
{
- actor.Move(timeStep * 5f);
+ actor.Move(timeStep);
}
d.SpaceCollide(space, IntPtr.Zero, nearCallback);
- d.WorldQuickStep(world, timeStep * 5f);
+ for (int i = 0; i < 50; i++)
+ {
+ d.WorldQuickStep(world, timeStep * 0.02f);
+ }
+
d.JointGroupEmpty(contactgroup);
foreach (OdeCharacter actor in _characters)
{
actor.UpdatePosition();
}
-
}
public override void GetResults()
@@ -221,7 +221,7 @@ namespace OpenSim.Region.Physics.OdePlugin
private PhysicsVector _position;
private PhysicsVector _velocity;
private PhysicsVector _acceleration;
- private bool flying;
+ private bool flying = false;
//private float gravityAccel;
private IntPtr BoundingCapsule;
IntPtr capsule_geom;
@@ -232,8 +232,8 @@ namespace OpenSim.Region.Physics.OdePlugin
_velocity = new PhysicsVector();
_position = pos;
_acceleration = new PhysicsVector();
- d.MassSetCapsule(out capsule_mass, 5.0f, 3, 0.5f, 2f);
- capsule_geom = d.CreateCapsule(OdeScene.space, 0.5f, 2f);
+ d.MassSetCapsule(out capsule_mass, 50.0f, 3, 0.5f, 2f);
+ capsule_geom = d.CreateSphere(OdeScene.space, 1.0f); /// not a typo! Spheres roll, capsules tumble
this.BoundingCapsule = d.BodyCreate(OdeScene.world);
d.BodySetMass(BoundingCapsule, ref capsule_mass);
d.BodySetPosition(BoundingCapsule, pos.X, pos.Y, pos.Z);
@@ -326,13 +326,14 @@ namespace OpenSim.Region.Physics.OdePlugin
public void Move(float timeStep)
{
PhysicsVector vec = new PhysicsVector();
- vec.X = this._velocity.X * timeStep;
- vec.Y = this._velocity.Y * timeStep;
+ d.Vector3 vel = d.BodyGetLinearVel(BoundingCapsule);
+ vec.X = (vel.X - this._velocity.X) * -75000.0f;
+ vec.Y = (vel.Y - this._velocity.Y) * -75000.0f;
if (flying)
{
- vec.Z = (this._velocity.Z + 0.5f) * timeStep;
+ vec.Z = (vel.Z - this._velocity.Z) * -75000.0f;
}
- d.BodySetLinearVel(this.BoundingCapsule, vec.X, vec.Y, vec.Z);
+ d.BodyAddForce(this.BoundingCapsule, vec.X, vec.Y, vec.Z);
}
public void UpdatePosition()
@@ -340,7 +341,7 @@ namespace OpenSim.Region.Physics.OdePlugin
d.Vector3 vec = d.BodyGetPosition(BoundingCapsule);
this._position.X = vec.X;
this._position.Y = vec.Y;
- this._position.Z = vec.Z+1.0f;
+ this._position.Z = vec.Z;
}
}
--
cgit v1.1
From 318376707de4f5406958239eac069f24ef8ef62a Mon Sep 17 00:00:00 2001
From: Brian McBee
Date: Sat, 18 Aug 2007 23:05:02 +0000
Subject: starting to add bits and pieces to physics prims that we will
eventually need for collisions. not hooked in yet.
---
OpenSim/Region/Physics/OdePlugin/OdePlugin.cs | 35 +++++++++++++++++++++------
1 file changed, 28 insertions(+), 7 deletions(-)
(limited to 'OpenSim/Region/Physics/OdePlugin')
diff --git a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
index 4b1d3f0..af79e63 100644
--- a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
+++ b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
@@ -80,6 +80,7 @@ namespace OpenSim.Region.Physics.OdePlugin
private double[] _heightmap;
static private d.NearCallback nearCallback = near;
private List _characters = new List();
+ private List _prims = new List();
private static d.ContactGeom[] contacts = new d.ContactGeom[30];
private static d.Contact contact;
@@ -134,7 +135,7 @@ namespace OpenSim.Region.Physics.OdePlugin
}
- public override PhysicsActor AddPrim(PhysicsVector position, PhysicsVector size)
+ public override PhysicsActor AddPrim(PhysicsVector position, PhysicsVector size, Quaternion rotation)
{
PhysicsVector pos = new PhysicsVector();
pos.X = position.X;
@@ -144,7 +145,14 @@ namespace OpenSim.Region.Physics.OdePlugin
siz.X = size.X;
siz.Y = size.Y;
siz.Z = size.Z;
- return new OdePrim();
+ Quaternion rot = new Quaternion();
+ rot.w = rotation.w;
+ rot.x = rotation.x;
+ rot.y = rotation.y;
+ rot.z = rotation.z;
+ OdePrim newPrim = new OdePrim(this, pos, siz, rot);
+ this._prims.Add(newPrim);
+ return newPrim;
}
public override void Simulate(float timeStep)
@@ -347,15 +355,29 @@ namespace OpenSim.Region.Physics.OdePlugin
public class OdePrim : PhysicsActor
{
+
private PhysicsVector _position;
private PhysicsVector _velocity;
+ private PhysicsVector _size;
private PhysicsVector _acceleration;
+ private Quaternion _orientation;
+ private IntPtr BoundingCapsule;
+ IntPtr capsule_geom;
+ d.Mass capsule_mass;
- public OdePrim()
+ public OdePrim(OdeScene parent_scene, PhysicsVector pos, PhysicsVector size, Quaternion rotation)
{
_velocity = new PhysicsVector();
- _position = new PhysicsVector();
+ _position = pos;
+ _size = size;
_acceleration = new PhysicsVector();
+ d.MassSetCapsule(out capsule_mass, 50.0f, 3, 0.5f, 2f);
+ capsule_geom = d.CreateBox(OdeScene.space, _size.X, _size.Y, _size.Z);
+ this.BoundingCapsule = d.BodyCreate(OdeScene.world);
+ d.BodySetMass(BoundingCapsule, ref capsule_mass);
+ d.BodySetPosition(BoundingCapsule, pos.X, pos.Y, pos.Z);
+ d.GeomSetBody(capsule_geom, BoundingCapsule);
+ _orientation = rotation;
}
public override bool Flying
{
@@ -420,12 +442,11 @@ namespace OpenSim.Region.Physics.OdePlugin
{
get
{
- Quaternion res = new Quaternion();
- return res;
+ return _orientation;
}
set
{
-
+ _orientation = value;
}
}
--
cgit v1.1
From 75f6c3d36455fa542e67c16a96c1fda61e9956d5 Mon Sep 17 00:00:00 2001
From: Brian McBee
Date: Sun, 19 Aug 2007 06:14:36 +0000
Subject: More prep work for adding prims to ODE physics
---
OpenSim/Region/Physics/OdePlugin/OdePlugin.cs | 75 ++++++++++++++++-----------
1 file changed, 44 insertions(+), 31 deletions(-)
(limited to 'OpenSim/Region/Physics/OdePlugin')
diff --git a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
index af79e63..397ba6d 100644
--- a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
+++ b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
@@ -272,6 +272,18 @@ namespace OpenSim.Region.Physics.OdePlugin
}
}
+ public override PhysicsVector Size
+ {
+ get
+ {
+ return new PhysicsVector(0,0,0);
+ }
+ set
+ {
+ }
+ }
+
+
public override PhysicsVector Velocity
{
get
@@ -355,15 +367,12 @@ namespace OpenSim.Region.Physics.OdePlugin
public class OdePrim : PhysicsActor
{
-
private PhysicsVector _position;
private PhysicsVector _velocity;
private PhysicsVector _size;
private PhysicsVector _acceleration;
private Quaternion _orientation;
- private IntPtr BoundingCapsule;
- IntPtr capsule_geom;
- d.Mass capsule_mass;
+ IntPtr prim_geom;
public OdePrim(OdeScene parent_scene, PhysicsVector pos, PhysicsVector size, Quaternion rotation)
{
@@ -371,14 +380,17 @@ namespace OpenSim.Region.Physics.OdePlugin
_position = pos;
_size = size;
_acceleration = new PhysicsVector();
- d.MassSetCapsule(out capsule_mass, 50.0f, 3, 0.5f, 2f);
- capsule_geom = d.CreateBox(OdeScene.space, _size.X, _size.Y, _size.Z);
- this.BoundingCapsule = d.BodyCreate(OdeScene.world);
- d.BodySetMass(BoundingCapsule, ref capsule_mass);
- d.BodySetPosition(BoundingCapsule, pos.X, pos.Y, pos.Z);
- d.GeomSetBody(capsule_geom, BoundingCapsule);
_orientation = rotation;
+ prim_geom = d.CreateBox(OdeScene.space, _size.X, _size.Y, _size.Z);
+ d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
+ d.Quaternion myrot = new d.Quaternion();
+ myrot.W = rotation.w;
+ myrot.X = rotation.x;
+ myrot.Y = rotation.y;
+ myrot.Z = rotation.z;
+ d.GeomSetQuaternion(prim_geom, ref myrot);
}
+
public override bool Flying
{
get
@@ -387,29 +399,31 @@ namespace OpenSim.Region.Physics.OdePlugin
}
set
{
-
}
}
+
public override PhysicsVector Position
{
get
{
- PhysicsVector pos = new PhysicsVector();
- // PhysicsVector vec = this._prim.Position;
- //pos.X = vec.X;
- //pos.Y = vec.Y;
- //pos.Z = vec.Z;
- return pos;
+ return _position;
+ }
+ set
+ {
+ _position = value;
+ d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
+ }
+ }
+ public override PhysicsVector Size
+ {
+ get
+ {
+ return _size;
}
set
{
- /*PhysicsVector vec = value;
- PhysicsVector pos = new PhysicsVector();
- pos.X = vec.X;
- pos.Y = vec.Y;
- pos.Z = vec.Z;
- this._prim.Position = pos;*/
+ _size = value;
}
}
@@ -430,11 +444,9 @@ namespace OpenSim.Region.Physics.OdePlugin
get
{
return false;
- //return this._prim.Kinematic;
}
set
{
- //this._prim.Kinematic = value;
}
}
@@ -447,6 +459,12 @@ namespace OpenSim.Region.Physics.OdePlugin
set
{
_orientation = value;
+ d.Quaternion myrot = new d.Quaternion();
+ myrot.W = _orientation.w;
+ myrot.X = _orientation.x;
+ myrot.Y = _orientation.y;
+ myrot.Z = _orientation.z;
+ d.GeomSetQuaternion(prim_geom, ref myrot);
}
}
@@ -456,8 +474,8 @@ namespace OpenSim.Region.Physics.OdePlugin
{
return _acceleration;
}
-
}
+
public void SetAcceleration(PhysicsVector accel)
{
this._acceleration = accel;
@@ -465,15 +483,10 @@ namespace OpenSim.Region.Physics.OdePlugin
public override void AddForce(PhysicsVector force)
{
-
}
public override void SetMomentum(PhysicsVector momentum)
{
-
}
-
-
}
-
}
--
cgit v1.1
From 9a8742e838cdefba925292d554a2f8bc9a6b3806 Mon Sep 17 00:00:00 2001
From: MW
Date: Thu, 23 Aug 2007 10:53:42 +0000
Subject: Added danx0r's physics patch, although for now have disabled the
lines in Scene.cs, as any changes to prims (like size or position changes)
are only updated to the physics engine when you restart opensim. Also prims
aren't deleted from the physics engine. These shouldn't be hard to fix.
---
OpenSim/Region/Physics/OdePlugin/OdePlugin.cs | 38 +++++++++++++++++++++++++--
1 file changed, 36 insertions(+), 2 deletions(-)
(limited to 'OpenSim/Region/Physics/OdePlugin')
diff --git a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
index 397ba6d..ae46feb 100644
--- a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
+++ b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
@@ -26,6 +26,7 @@
*
*/
using System;
+using System.Threading;
using System.Collections.Generic;
using Axiom.Math;
using Ode.NET;
@@ -83,7 +84,6 @@ namespace OpenSim.Region.Physics.OdePlugin
private List _prims = new List();
private static d.ContactGeom[] contacts = new d.ContactGeom[30];
private static d.Contact contact;
-
public OdeScene()
{
contact.surface.mode |= d.ContactFlags.Approx1 | d.ContactFlags.SoftCFM | d.ContactFlags.SoftERP;
@@ -92,24 +92,35 @@ namespace OpenSim.Region.Physics.OdePlugin
contact.surface.soft_erp = 0.005f;
contact.surface.soft_cfm = 0.00003f;
+ Monitor.Enter(typeof(OdeScene));
world = d.WorldCreate();
space = d.HashSpaceCreate(IntPtr.Zero);
contactgroup = d.JointGroupCreate(0);
d.WorldSetGravity(world, 0.0f, 0.0f, -10.0f);
d.WorldSetAutoDisableFlag(world, false);
d.WorldSetContactSurfaceLayer(world, 0.001f);
+ Monitor.Exit(typeof(OdeScene));
+
this._heightmap = new double[65536];
}
// This function blatantly ripped off from BoxStack.cs
static private void near(IntPtr space, IntPtr g1, IntPtr g2)
{
+ // no lock here! It's invoked from within Simulate(), which is thread-locked
IntPtr b1 = d.GeomGetBody(g1);
IntPtr b2 = d.GeomGetBody(g2);
if (b1 != IntPtr.Zero && b2 != IntPtr.Zero && d.AreConnectedExcluding(b1, b2, d.JointType.Contact))
return;
int count = d.Collide(g1, g2, 500, contacts, d.ContactGeom.SizeOf);
+ if (count>0)
+ {
+ if (b2 != IntPtr.Zero)
+ {
+ Console.WriteLine("+++++ collision twixt: " + b1 + " & " + b2);
+ }
+ }
for (int i = 0; i < count; ++i)
{
contact.geom = contacts[i];
@@ -137,6 +148,7 @@ namespace OpenSim.Region.Physics.OdePlugin
public override PhysicsActor AddPrim(PhysicsVector position, PhysicsVector size, Quaternion rotation)
{
+ Console.WriteLine("+++++++++++++++++++++++++++++++++AddPrim pos: " + position + " size: " + size + " quat: " + rotation);
PhysicsVector pos = new PhysicsVector();
pos.X = position.X;
pos.Y = position.Y;
@@ -157,6 +169,11 @@ namespace OpenSim.Region.Physics.OdePlugin
public override void Simulate(float timeStep)
{
+ Monitor.Enter(typeof(OdeScene));
+ foreach (OdePrim p in _prims)
+ {
+// Console.WriteLine("+++ prim: " + p.Position);
+ }
foreach (OdeCharacter actor in _characters)
{
actor.Move(timeStep);
@@ -172,6 +189,7 @@ namespace OpenSim.Region.Physics.OdePlugin
{
actor.UpdatePosition();
}
+ Monitor.Exit(typeof(OdeScene));
}
public override void GetResults()
@@ -198,6 +216,8 @@ namespace OpenSim.Region.Physics.OdePlugin
this._heightmap[i] = (double)heightMap[x * 256 + y];
}
IntPtr HeightmapData = d.GeomHeightfieldDataCreate();
+
+ Monitor.Enter(typeof(OdeScene));
d.GeomHeightfieldDataBuildDouble(HeightmapData, _heightmap, 0, 256, 256, 256, 256, 1.0f, 0.0f, 2.0f, 0);
d.GeomHeightfieldDataSetBounds(HeightmapData, 256, 256);
LandGeom = d.CreateHeightfield(space, HeightmapData, 1);
@@ -215,7 +235,8 @@ namespace OpenSim.Region.Physics.OdePlugin
d.RFromAxisAndAngle(out R, v3.x, v3.y, v3.z, angle);
d.GeomSetRotation(LandGeom, ref R);
- d.GeomSetPosition(LandGeom, 128, 128, 0);
+ d.GeomSetPosition(LandGeom, 128, 128, 0);
+ Monitor.Exit(typeof(OdeScene));
}
public override void DeleteTerrain()
@@ -240,12 +261,14 @@ namespace OpenSim.Region.Physics.OdePlugin
_velocity = new PhysicsVector();
_position = pos;
_acceleration = new PhysicsVector();
+ Monitor.Enter(typeof(OdeScene));
d.MassSetCapsule(out capsule_mass, 50.0f, 3, 0.5f, 2f);
capsule_geom = d.CreateSphere(OdeScene.space, 1.0f); /// not a typo! Spheres roll, capsules tumble
this.BoundingCapsule = d.BodyCreate(OdeScene.world);
d.BodySetMass(BoundingCapsule, ref capsule_mass);
d.BodySetPosition(BoundingCapsule, pos.X, pos.Y, pos.Z);
d.GeomSetBody(capsule_geom, BoundingCapsule);
+ Monitor.Exit(typeof(OdeScene));
}
public override bool Flying
@@ -345,6 +368,7 @@ namespace OpenSim.Region.Physics.OdePlugin
public void Move(float timeStep)
{
+ // no lock; for now it's only called from within Simulate()
PhysicsVector vec = new PhysicsVector();
d.Vector3 vel = d.BodyGetLinearVel(BoundingCapsule);
vec.X = (vel.X - this._velocity.X) * -75000.0f;
@@ -358,6 +382,7 @@ namespace OpenSim.Region.Physics.OdePlugin
public void UpdatePosition()
{
+ // no lock; called from Simulate() -- if you call this from elsewhere, gotta lock or do Monitor.Enter/Exit!
d.Vector3 vec = d.BodyGetPosition(BoundingCapsule);
this._position.X = vec.X;
this._position.Y = vec.Y;
@@ -382,6 +407,7 @@ namespace OpenSim.Region.Physics.OdePlugin
_acceleration = new PhysicsVector();
_orientation = rotation;
prim_geom = d.CreateBox(OdeScene.space, _size.X, _size.Y, _size.Z);
+ Monitor.Enter(typeof(OdeScene));
d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
d.Quaternion myrot = new d.Quaternion();
myrot.W = rotation.w;
@@ -389,6 +415,7 @@ namespace OpenSim.Region.Physics.OdePlugin
myrot.Y = rotation.y;
myrot.Z = rotation.z;
d.GeomSetQuaternion(prim_geom, ref myrot);
+ Monitor.Exit(typeof(OdeScene));
}
public override bool Flying
@@ -410,8 +437,12 @@ namespace OpenSim.Region.Physics.OdePlugin
}
set
{
+ Console.WriteLine("+++++++++++++++++++++++++++++++++++++++++++ setting pos: " + value);
_position = value;
+ Monitor.Enter(typeof(OdeScene));
d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
+ Monitor.Exit(typeof(OdeScene));
+
}
}
@@ -423,6 +454,7 @@ namespace OpenSim.Region.Physics.OdePlugin
}
set
{
+ Console.WriteLine("+++++++++++++++++++++++++++++++++++++++++++ setting size: " + value);
_size = value;
}
}
@@ -459,12 +491,14 @@ namespace OpenSim.Region.Physics.OdePlugin
set
{
_orientation = value;
+ Monitor.Enter(typeof(OdeScene));
d.Quaternion myrot = new d.Quaternion();
myrot.W = _orientation.w;
myrot.X = _orientation.x;
myrot.Y = _orientation.y;
myrot.Z = _orientation.z;
d.GeomSetQuaternion(prim_geom, ref myrot);
+ Monitor.Exit(typeof(OdeScene));
}
}
--
cgit v1.1
From edd50f2e8ea384e1fe9f9dc0ed5903477cb383f3 Mon Sep 17 00:00:00 2001
From: MW
Date: Thu, 23 Aug 2007 11:38:50 +0000
Subject: Implemented Resize Method in OdePrim. attached the links to that from
SceneObject, so now resizing works (as much as resizing currently works in
opensim, fixing resizing in general is on my todo list for today). Rotation
of a root prim also now updates the physics engine. So think there really is
only deleteprim left, then it should be usable (Different shapes (other than
boxes that it currently uses) can wait a little bit longer). [of course there
are still the other issues of ODE not really working when there is more than
one region in a instance of opensim].
---
OpenSim/Region/Physics/OdePlugin/OdePlugin.cs | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
(limited to 'OpenSim/Region/Physics/OdePlugin')
diff --git a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
index ae46feb..f168340 100644
--- a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
+++ b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
@@ -148,7 +148,7 @@ namespace OpenSim.Region.Physics.OdePlugin
public override PhysicsActor AddPrim(PhysicsVector position, PhysicsVector size, Quaternion rotation)
{
- Console.WriteLine("+++++++++++++++++++++++++++++++++AddPrim pos: " + position + " size: " + size + " quat: " + rotation);
+ //Console.WriteLine("+++++++++++++++++++++++++++++++++AddPrim pos: " + position + " size: " + size + " quat: " + rotation);
PhysicsVector pos = new PhysicsVector();
pos.X = position.X;
pos.Y = position.Y;
@@ -437,7 +437,7 @@ namespace OpenSim.Region.Physics.OdePlugin
}
set
{
- Console.WriteLine("+++++++++++++++++++++++++++++++++++++++++++ setting pos: " + value);
+ //Console.WriteLine("+++++++++++++++++++++++++++++++++++++++++++ setting pos: " + value);
_position = value;
Monitor.Enter(typeof(OdeScene));
d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
@@ -454,8 +454,11 @@ namespace OpenSim.Region.Physics.OdePlugin
}
set
{
- Console.WriteLine("+++++++++++++++++++++++++++++++++++++++++++ setting size: " + value);
+ //Console.WriteLine("+++++++++++++++++++++++++++++++++++++++++++ setting size: " + value);
_size = value;
+ Monitor.Enter(typeof(OdeScene));
+ d.GeomBoxSetLengths(prim_geom, _size.X, _size.Y, _size.Z);
+ Monitor.Exit(typeof(OdeScene));
}
}
@@ -490,6 +493,7 @@ namespace OpenSim.Region.Physics.OdePlugin
}
set
{
+ //Console.WriteLine("+++++++++++++++++++++++++++++++++++++++++++ setting Orientation");
_orientation = value;
Monitor.Enter(typeof(OdeScene));
d.Quaternion myrot = new d.Quaternion();
--
cgit v1.1
From 0d5311e49bf5700efcf779bfa4bc83a00585c424 Mon Sep 17 00:00:00 2001
From: MW
Date: Thu, 23 Aug 2007 17:21:08 +0000
Subject: Added RemovePrim method to the physics plugins interface. Implemented
that method in ODE plugin. Hooked it up so when deleting/taking prims into
your inventory they will be removed from physics engine. Enabled the other
physics hook ups in Scene.cs (and also added registering prims with physics
plugin when they are rezzed from Inventory.) So now to get the avatar to prim
collision testing working, just change to use the ODE plugin (in the
OpenSim.ini file, physics = OpenDynamicsEngine). Remember though ODE only
really works (without problems) when running with a single region.
---
OpenSim/Region/Physics/OdePlugin/OdePlugin.cs | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
(limited to 'OpenSim/Region/Physics/OdePlugin')
diff --git a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
index f168340..420693b 100644
--- a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
+++ b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
@@ -143,7 +143,16 @@ namespace OpenSim.Region.Physics.OdePlugin
public override void RemoveAvatar(PhysicsActor actor)
{
+
+ }
+ public override void RemovePrim(PhysicsActor prim)
+ {
+ if (prim is OdePrim)
+ {
+ d.GeomDestroy(((OdePrim)prim).prim_geom);
+ this._prims.Remove((OdePrim)prim);
+ }
}
public override PhysicsActor AddPrim(PhysicsVector position, PhysicsVector size, Quaternion rotation)
@@ -397,7 +406,7 @@ namespace OpenSim.Region.Physics.OdePlugin
private PhysicsVector _size;
private PhysicsVector _acceleration;
private Quaternion _orientation;
- IntPtr prim_geom;
+ public IntPtr prim_geom;
public OdePrim(OdeScene parent_scene, PhysicsVector pos, PhysicsVector size, Quaternion rotation)
{
--
cgit v1.1
From 87711c58696a7033a59b9ee61bce217da35c7f63 Mon Sep 17 00:00:00 2001
From: Tedd Hansen
Date: Sun, 26 Aug 2007 15:56:42 +0000
Subject: Danxors patch for >30prims with ODE
---
OpenSim/Region/Physics/OdePlugin/OdePlugin.cs | 12 ++++--------
1 file changed, 4 insertions(+), 8 deletions(-)
(limited to 'OpenSim/Region/Physics/OdePlugin')
diff --git a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
index 420693b..5e8f3c1 100644
--- a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
+++ b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
@@ -114,13 +114,6 @@ namespace OpenSim.Region.Physics.OdePlugin
return;
int count = d.Collide(g1, g2, 500, contacts, d.ContactGeom.SizeOf);
- if (count>0)
- {
- if (b2 != IntPtr.Zero)
- {
- Console.WriteLine("+++++ collision twixt: " + b1 + " & " + b2);
- }
- }
for (int i = 0; i < count; ++i)
{
contact.geom = contacts[i];
@@ -171,7 +164,10 @@ namespace OpenSim.Region.Physics.OdePlugin
rot.x = rotation.x;
rot.y = rotation.y;
rot.z = rotation.z;
- OdePrim newPrim = new OdePrim(this, pos, siz, rot);
+ OdePrim newPrim;
+ lock(typeof(OdeScene)) {
+ newPrim = new OdePrim(this, pos, siz, rot);
+ }
this._prims.Add(newPrim);
return newPrim;
}
--
cgit v1.1
From 7915adc6c569536742acf783bcc2f4aba673950e Mon Sep 17 00:00:00 2001
From: MW
Date: Tue, 28 Aug 2007 18:40:40 +0000
Subject: Corrected the namespace in OpenSim.Region.Physics.Manager, so now
namespace should equal project and directory.
---
OpenSim/Region/Physics/OdePlugin/OdePlugin.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'OpenSim/Region/Physics/OdePlugin')
diff --git a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
index 5e8f3c1..04ef1a3 100644
--- a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
+++ b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
@@ -30,7 +30,7 @@ using System.Threading;
using System.Collections.Generic;
using Axiom.Math;
using Ode.NET;
-using OpenSim.Physics.Manager;
+using OpenSim.Region.Physics.Manager;
namespace OpenSim.Region.Physics.OdePlugin
{
--
cgit v1.1
From 3a97f3f597b0e07320b135b614c056ba28b04d7c Mon Sep 17 00:00:00 2001
From: MW
Date: Tue, 28 Aug 2007 19:55:42 +0000
Subject: Applied danx0r's ODE patch [mantis number 340]. Corrected a few out
dated things in the ExtensionsScriptModule.
---
OpenSim/Region/Physics/OdePlugin/OdePlugin.cs | 188 ++++++++++++++------------
1 file changed, 102 insertions(+), 86 deletions(-)
(limited to 'OpenSim/Region/Physics/OdePlugin')
diff --git a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
index 04ef1a3..3cc690d 100644
--- a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
+++ b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
@@ -84,6 +84,7 @@ namespace OpenSim.Region.Physics.OdePlugin
private List _prims = new List();
private static d.ContactGeom[] contacts = new d.ContactGeom[30];
private static d.Contact contact;
+ public static Object OdeLock = new Object();
public OdeScene()
{
contact.surface.mode |= d.ContactFlags.Approx1 | d.ContactFlags.SoftCFM | d.ContactFlags.SoftERP;
@@ -92,14 +93,15 @@ namespace OpenSim.Region.Physics.OdePlugin
contact.surface.soft_erp = 0.005f;
contact.surface.soft_cfm = 0.00003f;
- Monitor.Enter(typeof(OdeScene));
- world = d.WorldCreate();
- space = d.HashSpaceCreate(IntPtr.Zero);
- contactgroup = d.JointGroupCreate(0);
- d.WorldSetGravity(world, 0.0f, 0.0f, -10.0f);
- d.WorldSetAutoDisableFlag(world, false);
- d.WorldSetContactSurfaceLayer(world, 0.001f);
- Monitor.Exit(typeof(OdeScene));
+ lock (OdeLock)
+ {
+ world = d.WorldCreate();
+ space = d.HashSpaceCreate(IntPtr.Zero);
+ contactgroup = d.JointGroupCreate(0);
+ d.WorldSetGravity(world, 0.0f, 0.0f, -10.0f);
+ d.WorldSetAutoDisableFlag(world, false);
+ d.WorldSetContactSurfaceLayer(world, 0.001f);
+ }
this._heightmap = new double[65536];
}
@@ -128,7 +130,7 @@ namespace OpenSim.Region.Physics.OdePlugin
PhysicsVector pos = new PhysicsVector();
pos.X = position.X;
pos.Y = position.Y;
- pos.Z = position.Z + 20;
+ pos.Z = position.Z;
OdeCharacter newAv = new OdeCharacter(this, pos);
this._characters.Add(newAv);
return newAv;
@@ -136,7 +138,6 @@ namespace OpenSim.Region.Physics.OdePlugin
public override void RemoveAvatar(PhysicsActor actor)
{
-
}
public override void RemovePrim(PhysicsActor prim)
@@ -150,7 +151,6 @@ namespace OpenSim.Region.Physics.OdePlugin
public override PhysicsActor AddPrim(PhysicsVector position, PhysicsVector size, Quaternion rotation)
{
- //Console.WriteLine("+++++++++++++++++++++++++++++++++AddPrim pos: " + position + " size: " + size + " quat: " + rotation);
PhysicsVector pos = new PhysicsVector();
pos.X = position.X;
pos.Y = position.Y;
@@ -165,7 +165,8 @@ namespace OpenSim.Region.Physics.OdePlugin
rot.y = rotation.y;
rot.z = rotation.z;
OdePrim newPrim;
- lock(typeof(OdeScene)) {
+ lock (OdeLock)
+ {
newPrim = new OdePrim(this, pos, siz, rot);
}
this._prims.Add(newPrim);
@@ -174,27 +175,27 @@ namespace OpenSim.Region.Physics.OdePlugin
public override void Simulate(float timeStep)
{
- Monitor.Enter(typeof(OdeScene));
- foreach (OdePrim p in _prims)
- {
-// Console.WriteLine("+++ prim: " + p.Position);
- }
- foreach (OdeCharacter actor in _characters)
- {
- actor.Move(timeStep);
- }
- d.SpaceCollide(space, IntPtr.Zero, nearCallback);
- for (int i = 0; i < 50; i++)
+ lock (OdeLock)
{
- d.WorldQuickStep(world, timeStep * 0.02f);
- }
+ foreach (OdePrim p in _prims)
+ {
+ }
+ foreach (OdeCharacter actor in _characters)
+ {
+ actor.Move(timeStep);
+ }
+ d.SpaceCollide(space, IntPtr.Zero, nearCallback);
+ for (int i = 0; i < 50; i++)
+ {
+ d.WorldQuickStep(world, timeStep * 0.02f);
+ }
- d.JointGroupEmpty(contactgroup);
- foreach (OdeCharacter actor in _characters)
- {
- actor.UpdatePosition();
+ d.JointGroupEmpty(contactgroup);
+ foreach (OdeCharacter actor in _characters)
+ {
+ actor.UpdatePosition();
+ }
}
- Monitor.Exit(typeof(OdeScene));
}
public override void GetResults()
@@ -222,26 +223,27 @@ namespace OpenSim.Region.Physics.OdePlugin
}
IntPtr HeightmapData = d.GeomHeightfieldDataCreate();
- Monitor.Enter(typeof(OdeScene));
- d.GeomHeightfieldDataBuildDouble(HeightmapData, _heightmap, 0, 256, 256, 256, 256, 1.0f, 0.0f, 2.0f, 0);
- d.GeomHeightfieldDataSetBounds(HeightmapData, 256, 256);
- LandGeom = d.CreateHeightfield(space, HeightmapData, 1);
- d.Matrix3 R = new d.Matrix3();
-
- Quaternion q1 =Quaternion.FromAngleAxis(1.5707f, new Vector3(1,0,0));
- 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 * q3;
- Vector3 v3 = new Vector3();
- float angle = 0;
- q1.ToAngleAxis(ref angle, ref v3);
-
- d.RFromAxisAndAngle(out R, v3.x, v3.y, v3.z, angle);
- d.GeomSetRotation(LandGeom, ref R);
- d.GeomSetPosition(LandGeom, 128, 128, 0);
- Monitor.Exit(typeof(OdeScene));
+ lock (OdeLock)
+ {
+ d.GeomHeightfieldDataBuildDouble(HeightmapData, _heightmap, 0, 256, 256, 256, 256, 1.0f, 0.0f, 2.0f, 0);
+ d.GeomHeightfieldDataSetBounds(HeightmapData, 256, 256);
+ LandGeom = d.CreateHeightfield(space, HeightmapData, 1);
+ d.Matrix3 R = new d.Matrix3();
+
+ Quaternion q1 = Quaternion.FromAngleAxis(1.5707f, new Vector3(1, 0, 0));
+ 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 * q3;
+ Vector3 v3 = new Vector3();
+ float angle = 0;
+ q1.ToAngleAxis(ref angle, ref v3);
+
+ d.RFromAxisAndAngle(out R, v3.x, v3.y, v3.z, angle);
+ d.GeomSetRotation(LandGeom, ref R);
+ d.GeomSetPosition(LandGeom, 128, 128, 0);
+ }
}
public override void DeleteTerrain()
@@ -260,20 +262,23 @@ namespace OpenSim.Region.Physics.OdePlugin
private IntPtr BoundingCapsule;
IntPtr capsule_geom;
d.Mass capsule_mass;
+ private OdeScene _parent_scene;
public OdeCharacter(OdeScene parent_scene, PhysicsVector pos)
{
_velocity = new PhysicsVector();
_position = pos;
_acceleration = new PhysicsVector();
- Monitor.Enter(typeof(OdeScene));
- d.MassSetCapsule(out capsule_mass, 50.0f, 3, 0.5f, 2f);
- capsule_geom = d.CreateSphere(OdeScene.space, 1.0f); /// not a typo! Spheres roll, capsules tumble
- this.BoundingCapsule = d.BodyCreate(OdeScene.world);
- d.BodySetMass(BoundingCapsule, ref capsule_mass);
- d.BodySetPosition(BoundingCapsule, pos.X, pos.Y, pos.Z);
- d.GeomSetBody(capsule_geom, BoundingCapsule);
- Monitor.Exit(typeof(OdeScene));
+ _parent_scene = parent_scene;
+ lock (OdeScene.OdeLock)
+ {
+ d.MassSetCapsule(out capsule_mass, 50.0f, 3, 0.5f, 2f);
+ capsule_geom = d.CreateSphere(OdeScene.space, 1.0f); /// not a typo! Spheres roll, capsules tumble
+ this.BoundingCapsule = d.BodyCreate(OdeScene.world);
+ d.BodySetMass(BoundingCapsule, ref capsule_mass);
+ d.BodySetPosition(BoundingCapsule, pos.X, pos.Y, pos.Z);
+ d.GeomSetBody(capsule_geom, BoundingCapsule);
+ }
}
public override bool Flying
@@ -296,7 +301,11 @@ namespace OpenSim.Region.Physics.OdePlugin
}
set
{
- _position = value;
+ lock (OdeScene.OdeLock)
+ {
+ d.BodySetPosition(BoundingCapsule, value.X, value.Y, value.Z);
+ _position = value;
+ }
}
}
@@ -389,6 +398,13 @@ namespace OpenSim.Region.Physics.OdePlugin
{
// no lock; called from Simulate() -- if you call this from elsewhere, gotta lock or do Monitor.Enter/Exit!
d.Vector3 vec = d.BodyGetPosition(BoundingCapsule);
+
+ // kluge to keep things in bounds. ODE lets dead avatars drift away (they should be removed!)
+ if (vec.X < 0.0f) vec.X = 0.0f;
+ if (vec.Y < 0.0f) vec.Y = 0.0f;
+ 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;
@@ -412,15 +428,16 @@ namespace OpenSim.Region.Physics.OdePlugin
_acceleration = new PhysicsVector();
_orientation = rotation;
prim_geom = d.CreateBox(OdeScene.space, _size.X, _size.Y, _size.Z);
- Monitor.Enter(typeof(OdeScene));
- d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
- d.Quaternion myrot = new d.Quaternion();
- myrot.W = rotation.w;
- myrot.X = rotation.x;
- myrot.Y = rotation.y;
- myrot.Z = rotation.z;
- d.GeomSetQuaternion(prim_geom, ref myrot);
- Monitor.Exit(typeof(OdeScene));
+ lock (OdeScene.OdeLock)
+ {
+ d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
+ d.Quaternion myrot = new d.Quaternion();
+ myrot.W = rotation.w;
+ myrot.X = rotation.x;
+ myrot.Y = rotation.y;
+ myrot.Z = rotation.z;
+ d.GeomSetQuaternion(prim_geom, ref myrot);
+ }
}
public override bool Flying
@@ -442,12 +459,11 @@ namespace OpenSim.Region.Physics.OdePlugin
}
set
{
- //Console.WriteLine("+++++++++++++++++++++++++++++++++++++++++++ setting pos: " + value);
_position = value;
- Monitor.Enter(typeof(OdeScene));
- d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
- Monitor.Exit(typeof(OdeScene));
-
+ lock (OdeScene.OdeLock)
+ {
+ d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
+ }
}
}
@@ -459,11 +475,11 @@ namespace OpenSim.Region.Physics.OdePlugin
}
set
{
- //Console.WriteLine("+++++++++++++++++++++++++++++++++++++++++++ setting size: " + value);
_size = value;
- Monitor.Enter(typeof(OdeScene));
- d.GeomBoxSetLengths(prim_geom, _size.X, _size.Y, _size.Z);
- Monitor.Exit(typeof(OdeScene));
+ lock (OdeScene.OdeLock)
+ {
+ d.GeomBoxSetLengths(prim_geom, _size.X, _size.Y, _size.Z);
+ }
}
}
@@ -498,16 +514,16 @@ namespace OpenSim.Region.Physics.OdePlugin
}
set
{
- //Console.WriteLine("+++++++++++++++++++++++++++++++++++++++++++ setting Orientation");
_orientation = value;
- Monitor.Enter(typeof(OdeScene));
- d.Quaternion myrot = new d.Quaternion();
- myrot.W = _orientation.w;
- myrot.X = _orientation.x;
- myrot.Y = _orientation.y;
- myrot.Z = _orientation.z;
- d.GeomSetQuaternion(prim_geom, ref myrot);
- Monitor.Exit(typeof(OdeScene));
+ lock (OdeScene.OdeLock)
+ {
+ d.Quaternion myrot = new d.Quaternion();
+ myrot.W = _orientation.w;
+ myrot.X = _orientation.x;
+ myrot.Y = _orientation.y;
+ myrot.Z = _orientation.z;
+ d.GeomSetQuaternion(prim_geom, ref myrot);
+ }
}
}
--
cgit v1.1
From e158a45b09a2706df4b623bd4d264724dc58e0a5 Mon Sep 17 00:00:00 2001
From: dan miller
Date: Thu, 30 Aug 2007 23:23:44 +0000
Subject: danx0r (first checkin!) fixes OdePlugin.cs RemovePrim() lock bug
---
OpenSim/Region/Physics/OdePlugin/OdePlugin.cs | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
(limited to 'OpenSim/Region/Physics/OdePlugin')
diff --git a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
index 3cc690d..62b6fb7 100644
--- a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
+++ b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
@@ -144,8 +144,11 @@ namespace OpenSim.Region.Physics.OdePlugin
{
if (prim is OdePrim)
{
- d.GeomDestroy(((OdePrim)prim).prim_geom);
- this._prims.Remove((OdePrim)prim);
+ lock (OdeLock)
+ {
+ d.GeomDestroy(((OdePrim)prim).prim_geom);
+ this._prims.Remove((OdePrim)prim);
+ }
}
}
@@ -221,10 +224,10 @@ namespace OpenSim.Region.Physics.OdePlugin
int y = i >> 8;
this._heightmap[i] = (double)heightMap[x * 256 + y];
}
- IntPtr HeightmapData = d.GeomHeightfieldDataCreate();
lock (OdeLock)
{
+ IntPtr HeightmapData = d.GeomHeightfieldDataCreate();
d.GeomHeightfieldDataBuildDouble(HeightmapData, _heightmap, 0, 256, 256, 256, 256, 1.0f, 0.0f, 2.0f, 0);
d.GeomHeightfieldDataSetBounds(HeightmapData, 256, 256);
LandGeom = d.CreateHeightfield(space, HeightmapData, 1);
@@ -427,9 +430,9 @@ namespace OpenSim.Region.Physics.OdePlugin
_size = size;
_acceleration = new PhysicsVector();
_orientation = rotation;
- prim_geom = d.CreateBox(OdeScene.space, _size.X, _size.Y, _size.Z);
lock (OdeScene.OdeLock)
{
+ prim_geom = d.CreateBox(OdeScene.space, _size.X, _size.Y, _size.Z);
d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
d.Quaternion myrot = new d.Quaternion();
myrot.W = rotation.w;
--
cgit v1.1
From 0901dfded17bc22e81301be8f3dd1b30b8da4305 Mon Sep 17 00:00:00 2001
From: dan miller
Date: Sat, 1 Sep 2007 11:01:11 +0000
Subject: umm, nevermind all that -- this is the real ODE region fix. I'll get
subversion someday
---
OpenSim/Region/Physics/OdePlugin/OdePlugin.cs | 55 ++++++++++++++++-----------
1 file changed, 33 insertions(+), 22 deletions(-)
(limited to 'OpenSim/Region/Physics/OdePlugin')
diff --git a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
index 62b6fb7..7141f09 100644
--- a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
+++ b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
@@ -73,20 +73,22 @@ namespace OpenSim.Region.Physics.OdePlugin
public class OdeScene : PhysicsScene
{
- static public IntPtr world;
- static public IntPtr space;
- static private IntPtr contactgroup;
- static private IntPtr LandGeom;
- //static private IntPtr Land;
+ private IntPtr contactgroup;
+ private IntPtr LandGeom;
private double[] _heightmap;
- static private d.NearCallback nearCallback = near;
+ private d.NearCallback nearCallback;
private List _characters = new List();
private List _prims = new List();
- private static d.ContactGeom[] contacts = new d.ContactGeom[30];
- private static d.Contact contact;
+ private d.ContactGeom[] contacts = new d.ContactGeom[30];
+ private d.Contact contact;
+
+ public IntPtr world;
+ public IntPtr space;
public static Object OdeLock = new Object();
+
public OdeScene()
{
+ nearCallback = near;
contact.surface.mode |= d.ContactFlags.Approx1 | d.ContactFlags.SoftCFM | d.ContactFlags.SoftERP;
contact.surface.mu = 10.0f;
contact.surface.bounce = 0.9f;
@@ -103,11 +105,11 @@ namespace OpenSim.Region.Physics.OdePlugin
d.WorldSetContactSurfaceLayer(world, 0.001f);
}
- this._heightmap = new double[65536];
+ _heightmap = new double[65536];
}
// This function blatantly ripped off from BoxStack.cs
- static private void near(IntPtr space, IntPtr g1, IntPtr g2)
+ private void near(IntPtr space, IntPtr g1, IntPtr g2)
{
// no lock here! It's invoked from within Simulate(), which is thread-locked
IntPtr b1 = d.GeomGetBody(g1);
@@ -116,7 +118,7 @@ namespace OpenSim.Region.Physics.OdePlugin
return;
int count = d.Collide(g1, g2, 500, contacts, d.ContactGeom.SizeOf);
- for (int i = 0; i < count; ++i)
+ for (int i = 0; i < count; i++)
{
contact.geom = contacts[i];
IntPtr joint = d.JointCreateContact(world, contactgroup, ref contact);
@@ -125,6 +127,14 @@ namespace OpenSim.Region.Physics.OdePlugin
}
+ private void collision_optimized()
+ {
+ foreach (OdeCharacter chr in _characters)
+ {
+ d.SpaceCollide2(space, _characters[_characters.Count - 1].capsule_geom, IntPtr.Zero, nearCallback);
+ }
+ }
+
public override PhysicsActor AddAvatar(PhysicsVector position)
{
PhysicsVector pos = new PhysicsVector();
@@ -132,7 +142,7 @@ namespace OpenSim.Region.Physics.OdePlugin
pos.Y = position.Y;
pos.Z = position.Z;
OdeCharacter newAv = new OdeCharacter(this, pos);
- this._characters.Add(newAv);
+ _characters.Add(newAv);
return newAv;
}
@@ -147,13 +157,14 @@ namespace OpenSim.Region.Physics.OdePlugin
lock (OdeLock)
{
d.GeomDestroy(((OdePrim)prim).prim_geom);
- this._prims.Remove((OdePrim)prim);
+ _prims.Remove((OdePrim)prim);
}
}
}
public override PhysicsActor AddPrim(PhysicsVector position, PhysicsVector size, Quaternion rotation)
{
+ Console.WriteLine("++++++++++++++++++++++++++++++++++ AddPrim: " + position);
PhysicsVector pos = new PhysicsVector();
pos.X = position.X;
pos.Y = position.Y;
@@ -172,7 +183,7 @@ namespace OpenSim.Region.Physics.OdePlugin
{
newPrim = new OdePrim(this, pos, siz, rot);
}
- this._prims.Add(newPrim);
+ _prims.Add(newPrim);
return newPrim;
}
@@ -187,7 +198,7 @@ namespace OpenSim.Region.Physics.OdePlugin
{
actor.Move(timeStep);
}
- d.SpaceCollide(space, IntPtr.Zero, nearCallback);
+ collision_optimized();
for (int i = 0; i < 50; i++)
{
d.WorldQuickStep(world, timeStep * 0.02f);
@@ -222,7 +233,7 @@ namespace OpenSim.Region.Physics.OdePlugin
// dbm (danx0r) -- heightmap x,y must be swapped for Ode (should fix ODE, but for now...)
int x = i & 0xff;
int y = i >> 8;
- this._heightmap[i] = (double)heightMap[x * 256 + y];
+ _heightmap[i] = (double)heightMap[x * 256 + y];
}
lock (OdeLock)
@@ -263,9 +274,9 @@ namespace OpenSim.Region.Physics.OdePlugin
private bool flying = false;
//private float gravityAccel;
private IntPtr BoundingCapsule;
- IntPtr capsule_geom;
- d.Mass capsule_mass;
private OdeScene _parent_scene;
+ public IntPtr capsule_geom;
+ public d.Mass capsule_mass;
public OdeCharacter(OdeScene parent_scene, PhysicsVector pos)
{
@@ -276,8 +287,8 @@ namespace OpenSim.Region.Physics.OdePlugin
lock (OdeScene.OdeLock)
{
d.MassSetCapsule(out capsule_mass, 50.0f, 3, 0.5f, 2f);
- capsule_geom = d.CreateSphere(OdeScene.space, 1.0f); /// not a typo! Spheres roll, capsules tumble
- this.BoundingCapsule = d.BodyCreate(OdeScene.world);
+ capsule_geom = d.CreateSphere(parent_scene.space, 1.0f); /// not a typo! Spheres roll, capsules tumble
+ BoundingCapsule = d.BodyCreate(parent_scene.world);
d.BodySetMass(BoundingCapsule, ref capsule_mass);
d.BodySetPosition(BoundingCapsule, pos.X, pos.Y, pos.Z);
d.GeomSetBody(capsule_geom, BoundingCapsule);
@@ -370,7 +381,7 @@ namespace OpenSim.Region.Physics.OdePlugin
}
public void SetAcceleration(PhysicsVector accel)
{
- this._acceleration = accel;
+ _acceleration = accel;
}
public override void AddForce(PhysicsVector force)
@@ -432,7 +443,7 @@ namespace OpenSim.Region.Physics.OdePlugin
_orientation = rotation;
lock (OdeScene.OdeLock)
{
- prim_geom = d.CreateBox(OdeScene.space, _size.X, _size.Y, _size.Z);
+ prim_geom = d.CreateBox(parent_scene.space, _size.X, _size.Y, _size.Z);
d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
d.Quaternion myrot = new d.Quaternion();
myrot.W = rotation.w;
--
cgit v1.1
From 00d4d5a21b22adae26ddba7ca89bac1eee0517f1 Mon Sep 17 00:00:00 2001
From: dan miller
Date: Sat, 1 Sep 2007 11:06:48 +0000
Subject: once more, without the debug statements (ODE multi-region fixes,
various debugging)
---
OpenSim/Region/Physics/OdePlugin/OdePlugin.cs | 1 -
1 file changed, 1 deletion(-)
(limited to 'OpenSim/Region/Physics/OdePlugin')
diff --git a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
index 7141f09..18e78d7 100644
--- a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
+++ b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
@@ -164,7 +164,6 @@ namespace OpenSim.Region.Physics.OdePlugin
public override PhysicsActor AddPrim(PhysicsVector position, PhysicsVector size, Quaternion rotation)
{
- Console.WriteLine("++++++++++++++++++++++++++++++++++ AddPrim: " + position);
PhysicsVector pos = new PhysicsVector();
pos.X = position.X;
pos.Y = position.Y;
--
cgit v1.1
From 825a2208c6225651c91d18152ddccf0b2c441f9c Mon Sep 17 00:00:00 2001
From: dan miller
Date: Sat, 1 Sep 2007 21:30:51 +0000
Subject: ODE bugfix: multiple avatars now supported properly
---
OpenSim/Region/Physics/OdePlugin/OdePlugin.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'OpenSim/Region/Physics/OdePlugin')
diff --git a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
index 18e78d7..5900c78 100644
--- a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
+++ b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
@@ -131,7 +131,7 @@ namespace OpenSim.Region.Physics.OdePlugin
{
foreach (OdeCharacter chr in _characters)
{
- d.SpaceCollide2(space, _characters[_characters.Count - 1].capsule_geom, IntPtr.Zero, nearCallback);
+ d.SpaceCollide2(space, chr.capsule_geom, IntPtr.Zero, nearCallback);
}
}
--
cgit v1.1
From 588ab9f09095710a1e7928f940cd381f8c9ef848 Mon Sep 17 00:00:00 2001
From: dan miller
Date: Sun, 9 Sep 2007 13:24:18 +0000
Subject: ODE fix: avatar/avatar collision enabled. Needs client update fix to
be seen correctly. In the right repository this time..
---
OpenSim/Region/Physics/OdePlugin/OdePlugin.cs | 4 ++++
1 file changed, 4 insertions(+)
(limited to 'OpenSim/Region/Physics/OdePlugin')
diff --git a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
index 5900c78..3397384 100644
--- a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
+++ b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
@@ -132,6 +132,10 @@ namespace OpenSim.Region.Physics.OdePlugin
foreach (OdeCharacter chr in _characters)
{
d.SpaceCollide2(space, chr.capsule_geom, IntPtr.Zero, nearCallback);
+ foreach (OdeCharacter ch2 in _characters) /// should be a separate space -- lots of avatars will be N**2 slow
+ {
+ d.SpaceCollide2(chr.capsule_geom, ch2.capsule_geom, IntPtr.Zero, nearCallback);
+ }
}
}
--
cgit v1.1
From ffe9c9374a9b220b2046940a4dec7eb47e5c958b Mon Sep 17 00:00:00 2001
From: Sean Dague
Date: Mon, 10 Sep 2007 08:14:38 +0000
Subject: mass update of urls in source code to new website
---
OpenSim/Region/Physics/OdePlugin/AssemblyInfo.cs | 2 +-
OpenSim/Region/Physics/OdePlugin/OdePlugin.cs | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
(limited to 'OpenSim/Region/Physics/OdePlugin')
diff --git a/OpenSim/Region/Physics/OdePlugin/AssemblyInfo.cs b/OpenSim/Region/Physics/OdePlugin/AssemblyInfo.cs
index 662b75a..3f840cc 100644
--- a/OpenSim/Region/Physics/OdePlugin/AssemblyInfo.cs
+++ b/OpenSim/Region/Physics/OdePlugin/AssemblyInfo.cs
@@ -1,5 +1,5 @@
/*
-* Copyright (c) Contributors, http://www.openmetaverse.org/
+* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
* Redistribution and use in source and binary forms, with or without
diff --git a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
index 3397384..bfbd880 100644
--- a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
+++ b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
@@ -1,5 +1,5 @@
/*
-* Copyright (c) Contributors, http://www.openmetaverse.org/
+* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
* Redistribution and use in source and binary forms, with or without
--
cgit v1.1
From b31fc4980f95710cd93384f434b1a0655c30a2fd Mon Sep 17 00:00:00 2001
From: dan miller
Date: Thu, 13 Sep 2007 21:53:13 +0000
Subject: ODE: no more slippin' & slidin'
---
OpenSim/Region/Physics/OdePlugin/OdePlugin.cs | 28 +++++++++++++++++++++++----
1 file changed, 24 insertions(+), 4 deletions(-)
(limited to 'OpenSim/Region/Physics/OdePlugin')
diff --git a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
index bfbd880..a6834d4 100644
--- a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
+++ b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
@@ -272,6 +272,8 @@ namespace OpenSim.Region.Physics.OdePlugin
public class OdeCharacter : PhysicsActor
{
private PhysicsVector _position;
+ private d.Vector3 _zeroPosition;
+ private bool _zeroFlag=false;
private PhysicsVector _velocity;
private PhysicsVector _acceleration;
private bool flying = false;
@@ -402,11 +404,29 @@ namespace OpenSim.Region.Physics.OdePlugin
// no lock; for now it's only called from within Simulate()
PhysicsVector vec = new PhysicsVector();
d.Vector3 vel = d.BodyGetLinearVel(BoundingCapsule);
- vec.X = (vel.X - this._velocity.X) * -75000.0f;
- vec.Y = (vel.Y - this._velocity.Y) * -75000.0f;
- if (flying)
+
+ // if velocity is zero, use position control; otherwise, velocity control
+ if (_velocity.X == 0.0f & _velocity.Y == 0.0f & _velocity.Z == 0.0f & !flying)
{
- vec.Z = (vel.Z - this._velocity.Z) * -75000.0f;
+ // keep track of where we stopped. No more slippin' & slidin'
+ if (!_zeroFlag)
+ {
+ _zeroFlag = true;
+ _zeroPosition = d.BodyGetPosition(BoundingCapsule);
+ }
+ d.Vector3 pos = d.BodyGetPosition(BoundingCapsule);
+ vec.X = (_velocity.X - vel.X) * 75000.0f + (_zeroPosition.X - pos.X) * 120000.0f;
+ vec.Y = (_velocity.Y - vel.Y) * 75000.0f + (_zeroPosition.Y - pos.Y) * 120000.0f;
+ }
+ else
+ {
+ _zeroFlag = false;
+ vec.X = (_velocity.X - vel.X) * 75000.0f;
+ vec.Y = (_velocity.Y - vel.Y) * 75000.0f;
+ if (flying)
+ {
+ vec.Z = (_velocity.Z - vel.Z) * 75000.0f;
+ }
}
d.BodyAddForce(this.BoundingCapsule, vec.X, vec.Y, vec.Z);
}
--
cgit v1.1
From 04e7fcd0e93300ec25758727ab5cfbb80942e97f Mon Sep 17 00:00:00 2001
From: dan miller
Date: Tue, 18 Sep 2007 02:38:10 +0000
Subject: RemoveAvatar called from scene.cs; implemented in ODE. Still issues
with multi-region; see bug 410
---
OpenSim/Region/Physics/OdePlugin/OdePlugin.cs | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
(limited to 'OpenSim/Region/Physics/OdePlugin')
diff --git a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
index a6834d4..8b49f70 100644
--- a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
+++ b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
@@ -152,6 +152,9 @@ namespace OpenSim.Region.Physics.OdePlugin
public override void RemoveAvatar(PhysicsActor actor)
{
+ OdeCharacter och = (OdeCharacter)actor;
+ d.BodyDestroy(och.BoundingCapsule);
+ _characters.Remove(och);
}
public override void RemovePrim(PhysicsActor prim)
@@ -278,7 +281,7 @@ namespace OpenSim.Region.Physics.OdePlugin
private PhysicsVector _acceleration;
private bool flying = false;
//private float gravityAccel;
- private IntPtr BoundingCapsule;
+ public IntPtr BoundingCapsule;
private OdeScene _parent_scene;
public IntPtr capsule_geom;
public d.Mass capsule_mass;
--
cgit v1.1
From d3050724d8fdb0de5b87285b782de9c4d2f9bac7 Mon Sep 17 00:00:00 2001
From: dan miller
Date: Fri, 21 Sep 2007 02:31:36 +0000
Subject: physics-related fixes; should stabilize border crossings
---
OpenSim/Region/Physics/OdePlugin/OdePlugin.cs | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
(limited to 'OpenSim/Region/Physics/OdePlugin')
diff --git a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
index 8b49f70..8d142ab 100644
--- a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
+++ b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
@@ -152,9 +152,8 @@ namespace OpenSim.Region.Physics.OdePlugin
public override void RemoveAvatar(PhysicsActor actor)
{
- OdeCharacter och = (OdeCharacter)actor;
- d.BodyDestroy(och.BoundingCapsule);
- _characters.Remove(och);
+ ((OdeCharacter)actor).Destroy();
+ _characters.Remove((OdeCharacter)actor);
}
public override void RemovePrim(PhysicsActor prim)
@@ -449,6 +448,15 @@ namespace OpenSim.Region.Physics.OdePlugin
this._position.Y = vec.Y;
this._position.Z = vec.Z;
}
+
+ public void Destroy()
+ {
+ lock (OdeScene.OdeLock)
+ {
+ d.GeomDestroy(this.capsule_geom);
+ d.BodyDestroy(this.BoundingCapsule);
+ }
+ }
}
public class OdePrim : PhysicsActor
--
cgit v1.1
From a0265300aa09be0bdd2d4629d6a22394d5b219be Mon Sep 17 00:00:00 2001
From: dan miller
Date: Sat, 29 Sep 2007 03:56:36 +0000
Subject: Hollow prims (box only), thanks Gerard! Enjoy
---
OpenSim/Region/Physics/OdePlugin/OdePlugin.cs | 187 ++++++++++++++++++++++++--
1 file changed, 176 insertions(+), 11 deletions(-)
(limited to 'OpenSim/Region/Physics/OdePlugin')
diff --git a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
index 8d142ab..e7592fb 100644
--- a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
+++ b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
@@ -28,10 +28,17 @@
using System;
using System.Threading;
using System.Collections.Generic;
+
+using libsecondlife;
+using libsecondlife.Utilities;
+
using Axiom.Math;
using Ode.NET;
+using OpenSim.Framework.Types;
+using OpenSim.Framework.Console;
using OpenSim.Region.Physics.Manager;
+
namespace OpenSim.Region.Physics.OdePlugin
{
///
@@ -77,8 +84,11 @@ namespace OpenSim.Region.Physics.OdePlugin
private IntPtr LandGeom;
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();
private d.ContactGeom[] contacts = new d.ContactGeom[30];
private d.Contact contact;
@@ -89,6 +99,8 @@ namespace OpenSim.Region.Physics.OdePlugin
public OdeScene()
{
nearCallback = near;
+ triCallback = TriCallback;
+ triArrayCallback = TriArrayCallback;
contact.surface.mode |= d.ContactFlags.Approx1 | d.ContactFlags.SoftCFM | d.ContactFlags.SoftERP;
contact.surface.mu = 10.0f;
contact.surface.bounce = 0.9f;
@@ -112,12 +124,33 @@ namespace OpenSim.Region.Physics.OdePlugin
private void near(IntPtr space, IntPtr g1, IntPtr g2)
{
// no lock here! It's invoked from within Simulate(), which is thread-locked
+ if (g1 == g2)
+ return; // Can't collide with yourself
+
IntPtr b1 = d.GeomGetBody(g1);
IntPtr b2 = d.GeomGetBody(g2);
+
if (b1 != IntPtr.Zero && b2 != IntPtr.Zero && d.AreConnectedExcluding(b1, b2, d.JointType.Contact))
return;
- int count = d.Collide(g1, g2, 500, contacts, d.ContactGeom.SizeOf);
+ d.GeomClassID id = d.GeomGetClass(g1);
+ if (id==d.GeomClassID.TriMeshClass)
+ {
+ String name1 = null;
+ String name2 = null;
+ if (!geom_name_map.TryGetValue(g1, out name1))
+ {
+ name1 = "null";
+ }
+ if (!geom_name_map.TryGetValue(g2, out name2))
+ {
+ name2 = "null";
+ }
+
+// MainLog.Instance.Verbose("near: A collision was detected between {1} and {2}", 0, name1, name2);
+ }
+
+ int count = d.Collide(g1, g2, contacts.GetLength(0), contacts, d.ContactGeom.SizeOf);
for (int i = 0; i < count; i++)
{
contact.geom = contacts[i];
@@ -139,21 +172,24 @@ namespace OpenSim.Region.Physics.OdePlugin
}
}
- public override PhysicsActor AddAvatar(PhysicsVector position)
+ public override PhysicsActor AddAvatar(string avName, PhysicsVector position)
{
PhysicsVector pos = new PhysicsVector();
pos.X = position.X;
pos.Y = position.Y;
pos.Z = position.Z;
- OdeCharacter newAv = new OdeCharacter(this, pos);
+ OdeCharacter newAv = new OdeCharacter(avName, this, pos);
_characters.Add(newAv);
return newAv;
}
public override void RemoveAvatar(PhysicsActor actor)
{
- ((OdeCharacter)actor).Destroy();
- _characters.Remove((OdeCharacter)actor);
+ lock (OdeLock)
+ {
+ ((OdeCharacter)actor).Destroy();
+ _characters.Remove((OdeCharacter)actor);
+ }
}
public override void RemovePrim(PhysicsActor prim)
@@ -168,7 +204,7 @@ namespace OpenSim.Region.Physics.OdePlugin
}
}
- public override PhysicsActor AddPrim(PhysicsVector position, PhysicsVector size, Quaternion rotation)
+ PhysicsActor AddPrim(String name, PhysicsVector position, PhysicsVector size, Quaternion rotation, Mesh mesh, PrimitiveBaseShape pbs)
{
PhysicsVector pos = new PhysicsVector();
pos.X = position.X;
@@ -186,12 +222,91 @@ namespace OpenSim.Region.Physics.OdePlugin
OdePrim newPrim;
lock (OdeLock)
{
- newPrim = new OdePrim(this, pos, siz, rot);
+ newPrim = new OdePrim(name, this, pos, siz, rot, mesh, pbs);
}
_prims.Add(newPrim);
return newPrim;
}
+
+ public int TriArrayCallback(System.IntPtr trimesh, System.IntPtr refObject, int[] triangleIndex, int triCount)
+ {
+/* String name1 = null;
+ String name2 = null;
+
+ if (!geom_name_map.TryGetValue(trimesh, out name1))
+ {
+ name1 = "null";
+ }
+ if (!geom_name_map.TryGetValue(refObject, out name2))
+ {
+ name2 = "null";
+ }
+
+ MainLog.Instance.Verbose("TriArrayCallback: A collision was detected between {1} and {2}", 0, name1, name2);
+*/
+ return 1;
+ }
+
+ public int TriCallback(System.IntPtr trimesh, System.IntPtr refObject, int triangleIndex)
+ {
+
+ String name1 = null;
+ String name2 = null;
+
+ if (!geom_name_map.TryGetValue(trimesh, out name1))
+ {
+ Console.WriteLine("+++ nulling " + name1);
+ name1 = "null";
+ }
+ if (!geom_name_map.TryGetValue(refObject, out name2))
+ {
+ Console.WriteLine("+++ nulling " + name2);
+ name2 = "null";
+ }
+
+// MainLog.Instance.Verbose("TriCallback: A collision was detected between {1} and {2}. Index was {3}", 0, name1, name2, triangleIndex);
+
+ d.Vector3 v0 = new d.Vector3();
+ d.Vector3 v1 = new d.Vector3();
+ d.Vector3 v2 = new d.Vector3();
+
+ d.GeomTriMeshGetTriangle(trimesh, 0, ref v0, ref v1, ref v2);
+ MainLog.Instance.Debug("Triangle {0} is <{1},{2},{3}>, <{4},{5},{6}>, <{7},{8},{9}>", triangleIndex, v0.X, v0.Y, v0.Z, v1.X, v1.Y, v1.Z, v2.X, v2.Y, v2.Z);
+
+ return 1;
+ }
+
+
+ public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, PhysicsVector position, PhysicsVector size, Quaternion rotation)
+ {
+ PhysicsActor result;
+
+ switch(pbs.ProfileShape)
+ {
+ case ProfileShape.Square:
+ /// support simple box & hollow box now; later, more shapes
+ if (pbs.ProfileHollow == 0)
+ {
+ result = AddPrim(primName, position, size, rotation, null, null);
+ }
+ else
+ {
+ Mesh mesh = Meshmerizer.CreateMesh(pbs, size);
+ result = AddPrim(primName, position, size, rotation, mesh, pbs);
+ }
+ break;
+
+ default:
+ result = AddPrim(primName, position, size, rotation, null, null);
+ break;
+ }
+
+ return result;
+ }
+
+
+
public override void Simulate(float timeStep)
{
lock (OdeLock)
@@ -247,6 +362,8 @@ namespace OpenSim.Region.Physics.OdePlugin
d.GeomHeightfieldDataBuildDouble(HeightmapData, _heightmap, 0, 256, 256, 256, 256, 1.0f, 0.0f, 2.0f, 0);
d.GeomHeightfieldDataSetBounds(HeightmapData, 256, 256);
LandGeom = d.CreateHeightfield(space, HeightmapData, 1);
+ this.geom_name_map[LandGeom]="Terrain";
+
d.Matrix3 R = new d.Matrix3();
Quaternion q1 = Quaternion.FromAngleAxis(1.5707f, new Vector3(1, 0, 0));
@@ -285,7 +402,7 @@ namespace OpenSim.Region.Physics.OdePlugin
public IntPtr capsule_geom;
public d.Mass capsule_mass;
- public OdeCharacter(OdeScene parent_scene, PhysicsVector pos)
+ public OdeCharacter(String avName, OdeScene parent_scene, PhysicsVector pos)
{
_velocity = new PhysicsVector();
_position = pos;
@@ -300,6 +417,8 @@ namespace OpenSim.Region.Physics.OdePlugin
d.BodySetPosition(BoundingCapsule, pos.X, pos.Y, pos.Z);
d.GeomSetBody(capsule_geom, BoundingCapsule);
}
+ parent_scene.geom_name_map[capsule_geom]=avName;
+
}
public override bool Flying
@@ -454,6 +573,8 @@ namespace OpenSim.Region.Physics.OdePlugin
lock (OdeScene.OdeLock)
{
d.GeomDestroy(this.capsule_geom);
+ Console.WriteLine("+++ removing geom");
+ this._parent_scene.geom_name_map.Remove(this.capsule_geom);
d.BodyDestroy(this.BoundingCapsule);
}
}
@@ -466,18 +587,35 @@ namespace OpenSim.Region.Physics.OdePlugin
private PhysicsVector _size;
private PhysicsVector _acceleration;
private Quaternion _orientation;
+ private Mesh _mesh;
+ private PrimitiveBaseShape _pbs;
+ private OdeScene _parent_scene;
public IntPtr prim_geom;
+ public IntPtr _triMeshData;
- public OdePrim(OdeScene parent_scene, PhysicsVector pos, PhysicsVector size, Quaternion rotation)
+ public OdePrim(String primName, OdeScene parent_scene, PhysicsVector pos, PhysicsVector size,
+ Quaternion rotation, Mesh mesh, PrimitiveBaseShape pbs)
{
_velocity = new PhysicsVector();
_position = pos;
_size = size;
_acceleration = new PhysicsVector();
_orientation = rotation;
+ _mesh = mesh;
+ _pbs = pbs;
+ _parent_scene = parent_scene;
+
lock (OdeScene.OdeLock)
{
- prim_geom = d.CreateBox(parent_scene.space, _size.X, _size.Y, _size.Z);
+ if (mesh!=null)
+ {
+ setMesh(parent_scene, mesh);
+ }
+ else
+ {
+ prim_geom = d.CreateBox(parent_scene.space, _size.X, _size.Y, _size.Z);
+ }
+
d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
d.Quaternion myrot = new d.Quaternion();
myrot.W = rotation.w;
@@ -485,9 +623,25 @@ 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
}
}
+ 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 IndexCount = indexList.GetLength(0);
+
+ _triMeshData = d.GeomTriMeshDataCreate();
+
+ 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, parent_scene.triArrayCallback, null);
+ }
+
public override bool Flying
{
get
@@ -526,7 +680,18 @@ namespace OpenSim.Region.Physics.OdePlugin
_size = value;
lock (OdeScene.OdeLock)
{
- d.GeomBoxSetLengths(prim_geom, _size.X, _size.Y, _size.Z);
+ if (_mesh != null) // We deal with a mesh here
+ {
+ string oldname = _parent_scene.geom_name_map[prim_geom];
+ d.GeomDestroy(prim_geom);
+ Mesh mesh = Meshmerizer.CreateMesh(_pbs, _size);
+ setMesh(_parent_scene, mesh);
+ _parent_scene.geom_name_map[prim_geom] = oldname;
+ }
+ else
+ {
+ d.GeomBoxSetLengths(prim_geom, _size.X, _size.Y, _size.Z);
+ }
}
}
}
--
cgit v1.1
From c1d3e93fbb3284b38b85294d43189001bfce5214 Mon Sep 17 00:00:00 2001
From: dan miller
Date: Sat, 29 Sep 2007 04:08:33 +0000
Subject: Hollow prims (box only), thanks Gerard! Enjoy
---
.../Physics/OdePlugin/Meshing\\/HelperTypes.cs" | 279 ++++++++++
.../Physics/OdePlugin/Meshing\\/Meshmerizer.cs" | 560 +++++++++++++++++++++
2 files changed, 839 insertions(+)
create mode 100644 "OpenSim/Region/Physics/OdePlugin/Meshing\\/HelperTypes.cs"
create mode 100644 "OpenSim/Region/Physics/OdePlugin/Meshing\\/Meshmerizer.cs"
(limited to 'OpenSim/Region/Physics/OdePlugin')
diff --git "a/OpenSim/Region/Physics/OdePlugin/Meshing\\/HelperTypes.cs" "b/OpenSim/Region/Physics/OdePlugin/Meshing\\/HelperTypes.cs"
new file mode 100644
index 0000000..3d40c04
--- /dev/null
+++ "b/OpenSim/Region/Physics/OdePlugin/Meshing\\/HelperTypes.cs"
@@ -0,0 +1,279 @@
+using System;
+using System.Globalization;
+using System.Diagnostics;
+using System.Collections.Generic;
+
+using OpenSim.Region.Physics.Manager;
+
+public class Vertex : IComparable
+{
+ public String name;
+ public PhysicsVector point;
+
+ public Vertex(String name, float x, float y, float z)
+ {
+ this.name = name;
+ point = new PhysicsVector(x, y, z);
+ }
+
+ public int CompareTo(Vertex other)
+ {
+ if (point.X < other.point.X)
+ return -1;
+
+ if (point.X > other.point.X)
+ return 1;
+
+ if (point.Y < other.point.Y)
+ return -1;
+
+ if (point.Y > other.point.Y)
+ return 1;
+
+ if (point.Z < other.point.Z)
+ return -1;
+
+ if (point.Z > other.point.Z)
+ return 1;
+
+ return 0;
+ }
+
+ public static bool operator >(Vertex me, Vertex other)
+ {
+ return me.CompareTo(other) > 0;
+ }
+
+ public static bool operator <(Vertex me, Vertex other)
+ {
+ return me.CompareTo(other) < 0;
+ }
+
+
+}
+
+public class Simplex : IComparable
+{
+ public Vertex v1;
+ public Vertex v2;
+
+ public Simplex(Vertex _v1, Vertex _v2)
+ {
+ // Presort indices to make sorting (comparing) easier
+ if (_v1 > _v2)
+ {
+ v1 = _v1;
+ v2 = _v2;
+ }
+ else
+ {
+ v1 = _v2;
+ v2 = _v1;
+ }
+ }
+
+ public int CompareTo(Simplex other)
+ {
+ if (v1 > other.v1)
+ {
+ return 1;
+ }
+ if (v1 < other.v1)
+ {
+ return -1;
+ }
+
+ if (v2 > other.v2)
+ {
+ return 1;
+ }
+ if (v2 < other.v2)
+ {
+ return -1;
+ }
+
+ return 0;
+ }
+
+};
+
+public class Triangle
+{
+ public Vertex v1;
+ public Vertex v2;
+ public Vertex v3;
+
+ float radius_square;
+ float cx;
+ float cy;
+
+ public Triangle(Vertex _v1, Vertex _v2, Vertex _v3)
+ {
+ v1 = _v1;
+ v2 = _v2;
+ v3 = _v3;
+
+ CalcCircle();
+ }
+
+ public bool isInCircle(float x, float y)
+ {
+ float dx, dy;
+ float dd;
+
+ dx = x - this.cx;
+ dy = y - this.cy;
+
+ dd = dx * dx + dy * dy;
+ if (dd < this.radius_square)
+ return true;
+ else
+ return false;
+ }
+
+
+ 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
+ double p1x, p2x, p1y, p2y, p3x, p3y;
+
+ // Deviation of this routine:
+ // A circle has the general equation (M-p)^2=r^2, where M and p are vectors
+ // this gives us three equations f(p)=r^2, each for one point p1, p2, p3
+ // putting respectively two equations together gives two equations
+ // f(p1)=f(p2) and f(p1)=f(p3)
+ // bringing all constant terms to one side brings them to the form
+ // M*v1=c1 resp.M*v2=c2 where v1=(p1-p2) and v2=(p1-p3) (still vectors)
+ // and c1, c2 are scalars (Naming conventions like the variables below)
+ // Now using the equations that are formed by the components of the vectors
+ // and isolate Mx lets you make one equation that only holds My
+ // The rest is straight forward and eaasy :-)
+ //
+
+ /* helping variables for temporary results */
+ double c1, c2;
+ double v1x, v1y, v2x, v2y;
+
+ double z, n;
+
+ double rx, ry;
+
+ // Readout the three points, the triangle consists of
+ p1x = v1.point.X;
+ p1y = v1.point.Y;
+
+ p2x = v2.point.X;
+ p2y = v2.point.Y;
+
+ p3x = v3.point.X;
+ 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;
+
+ v1x = p1x - p2x;
+ v1y = p1y - p2y;
+
+ v2x = p1x - p3x;
+ v2y = p1y - p3y;
+
+ 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
+ {
+ radius_square = 0.0f;
+ return;
+ }
+
+ this.cy = (float)(z / n);
+
+ if (v2x != 0.0)
+ {
+ this.cx = (float)((c2 - v2y * this.cy) / v2x);
+ }
+ else if (v1x != 0.0)
+ {
+ this.cx = (float)((c1 - v1y * this.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);
+
+ }
+
+ public List GetSimplices()
+ {
+ List result = new List();
+ Simplex s1 = new Simplex(v1, v2);
+ Simplex s2 = new Simplex(v2, v3);
+ Simplex s3 = new Simplex(v3, v1);
+
+ result.Add(s1);
+ result.Add(s2);
+ result.Add(s3);
+
+ return result;
+ }
+
+ 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) + ">";
+
+ return s1 + ";" + s2 + ";" + s3;
+
+ }
+
+ public PhysicsVector getNormal()
+ {
+ // Vertices
+
+ // Vectors for edges
+ PhysicsVector e1;
+ PhysicsVector e2;
+
+ e1 = new PhysicsVector(v1.point.X - v2.point.X, v1.point.Y - v2.point.Y, v1.point.Z - v2.point.Z);
+ e2 = new PhysicsVector(v1.point.X - v3.point.X, v1.point.Y - v3.point.Y, v1.point.Z - v3.point.Z);
+
+ // 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;
+
+ // Length
+ float l = (float)Math.Sqrt(n.X * n.X + n.Y * n.Y + n.Z * n.Z);
+
+ // Normalized "normal"
+ n.X /= l;
+ n.Y /= l;
+ n.Z /= l;
+
+ return n;
+ }
+
+ public void invertNormal()
+ {
+ Vertex vt;
+ vt = v1;
+ v1 = v2;
+ v2 = vt;
+ }
+}
+
diff --git "a/OpenSim/Region/Physics/OdePlugin/Meshing\\/Meshmerizer.cs" "b/OpenSim/Region/Physics/OdePlugin/Meshing\\/Meshmerizer.cs"
new file mode 100644
index 0000000..28dca41
--- /dev/null
+++ "b/OpenSim/Region/Physics/OdePlugin/Meshing\\/Meshmerizer.cs"
@@ -0,0 +1,560 @@
+using System;
+using System.Globalization;
+using System.Diagnostics;
+using System.Collections.Generic;
+using System.Text;
+using System.Runtime.InteropServices;
+
+using OpenSim.Framework.Types;
+using OpenSim.Region.Physics.Manager;
+
+namespace OpenSim.Region.Physics.OdePlugin
+{
+ public class Mesh
+ {
+ public List vertices;
+ public List triangles;
+
+ public float[] normals;
+
+ public Mesh()
+ {
+ vertices = new List();
+ triangles = new List();
+ }
+
+ public void Add(Triangle triangle)
+ {
+ int i;
+ i = vertices.IndexOf(triangle.v1);
+ if (i < 0)
+ throw new ArgumentException("Vertex v1 not known to mesh");
+ i = vertices.IndexOf(triangle.v2);
+ if (i < 0)
+ throw new ArgumentException("Vertex v2 not known to mesh");
+ i = vertices.IndexOf(triangle.v3);
+ if (i < 0)
+ throw new ArgumentException("Vertex v3 not known to mesh");
+
+ triangles.Add(triangle);
+ }
+
+ public void Add(Vertex v)
+ {
+ vertices.Add(v);
+ }
+
+
+ public float[] getVertexListAsFloat()
+ {
+ 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;
+ }
+ GCHandle.Alloc(result, GCHandleType.Pinned);
+ return result;
+ }
+
+ public int[] getIndexListAsInt()
+ {
+ 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);
+ }
+ GCHandle.Alloc(result, GCHandleType.Pinned);
+ return result;
+ }
+
+
+ public void Append(Mesh newMesh)
+ {
+ foreach (Vertex v in newMesh.vertices)
+ vertices.Add(v);
+
+ foreach (Triangle t in newMesh.triangles)
+ Add(t);
+
+ }
+ }
+
+
+
+ public class Meshmerizer
+ {
+
+ static List FindInfluencedTriangles(List triangles, Vertex v)
+ {
+ List influenced = new List();
+ foreach (Triangle t in triangles)
+ {
+ float dx, dy;
+
+ if (t.isInCircle(v.point.X, v.point.Y))
+ {
+ influenced.Add(t);
+ }
+ }
+ return influenced;
+ }
+
+
+ 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
+ // and replaced by new ones including the new vertex
+ // It is not very time efficient but easy to implement.
+
+ int iCurrentVertex;
+ int iMaxVertex=vertices.Count;
+ for (iCurrentVertex = usedForSeed; iCurrentVertex < iMaxVertex; iCurrentVertex++)
+ {
+ // Background: A triangle mesh fulfills the delaunay condition if (iff!)
+ // each circumlocutory circle (i.e. the circle that touches all three corners)
+ // of each triangle is empty of other vertices.
+ // Obviously a single (seeding) triangle fulfills this condition.
+ // If we now add one vertex, we need to reconstruct all triangles, that
+ // 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);
+
+ List simplices = new List();
+
+ // Reconstruction phase. First step, dissolve each triangle into it's simplices,
+ // i.e. it's "border lines"
+ // Goal is to find "inner" borders and delete them, while the hull gets conserved.
+ // Inner borders are special in the way that they always come twice, which is how we detect them
+ foreach (Triangle t in influencedTriangles)
+ {
+ List newSimplices = t.GetSimplices();
+ simplices.AddRange(newSimplices);
+ triangles.Remove(t);
+ }
+ // Now sort the simplices. That will make identical ones side by side in the list
+ simplices.Sort();
+
+ // Look for duplicate simplices here.
+ // Remember, they are directly side by side in the list right now
+ int iSimplex;
+ 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)
+ {
+ innerSimplices.Add(simplices[iSimplex - 1]);
+ innerSimplices.Add(simplices[iSimplex]);
+ }
+ }
+
+ foreach (Simplex s in innerSimplices)
+ {
+ simplices.Remove(s);
+ }
+
+ // each simplex still in the list belongs to the hull of the region in question
+ // The new vertex (yes, we still deal with verices here :-) ) forms a triangle
+ // With each of these simplices. Build the new triangles and add them to the list
+ foreach (Simplex s in simplices)
+ {
+ Triangle t = new Triangle(s.v1, s.v2, vertices[iCurrentVertex]);
+ triangles.Add(t);
+ }
+ }
+
+ // At this point all vertices should be inserted into the mesh
+ // But the areas, that should be kept free still are filled with triangles
+ // We have to remove them. For this we have a list of indices to vertices.
+ // Each triangle that solemnly constists of vertices from the inner border
+ // are deleted
+
+ List innerTriangles = new List();
+ foreach (Triangle t in triangles)
+ {
+ if (
+ innerBorders.Contains(vertices.IndexOf(t.v1))
+ && innerBorders.Contains(vertices.IndexOf(t.v2))
+ && innerBorders.Contains(vertices.IndexOf(t.v3))
+ )
+ innerTriangles.Add(t);
+ }
+ foreach (Triangle t in innerTriangles)
+ {
+ triangles.Remove(t);
+ }
+ }
+
+
+ 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 Triangle(meshMX.vertices[0], meshMX.vertices[2], meshMX.vertices[1]));
+ meshMX.Add(new Triangle(meshMX.vertices[1], meshMX.vertices[2], meshMX.vertices[3]));
+
+
+ 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 Triangle(meshPX.vertices[0], meshPX.vertices[1], meshPX.vertices[2]));
+ meshPX.Add(new Triangle(meshPX.vertices[2], meshPX.vertices[1], meshPX.vertices[3]));
+
+
+ if (hollowFactor > 0)
+ {
+ 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);
+
+ meshMX.Add(IPP);
+ meshMX.Add(IPM);
+ meshMX.Add(IMP);
+ meshMX.Add(IMM);
+
+ meshMX.Add(new Triangle(IPP, IMP, IPM));
+ meshMX.Add(new Triangle(IPM, IMP, IMM));
+
+ foreach (Triangle t in meshMX.triangles)
+ {
+ PhysicsVector n = t.getNormal();
+ }
+
+
+
+ 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);
+ meshPX.Add(IMP);
+ meshPX.Add(IMM);
+
+ meshPX.Add(new Triangle(IPP, IPM, IMP));
+ meshPX.Add(new Triangle(IMP, IPM, IMM));
+
+ foreach (Triangle t in meshPX.triangles)
+ {
+ PhysicsVector n = t.getNormal();
+ }
+ }
+
+ Mesh result = new Mesh();
+ result.Append(meshMX);
+ result.Append(meshPX);
+
+ return result;
+ }
+
+
+
+ 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 Triangle(MeshMY.vertices[0], MeshMY.vertices[1], MeshMY.vertices[2]));
+ MeshMY.Add(new Triangle(MeshMY.vertices[2], MeshMY.vertices[1], MeshMY.vertices[3]));
+
+ // (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 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;
+
+ 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);
+
+ MeshMY.Add(IPP);
+ MeshMY.Add(IPM);
+ MeshMY.Add(IMP);
+ MeshMY.Add(IMM);
+
+ MeshMY.Add(new Triangle(IPP, IPM, IMP));
+ MeshMY.Add(new Triangle(IMP, IPM, IMM));
+
+ foreach (Triangle t in MeshMY.triangles)
+ {
+ PhysicsVector n = t.getNormal();
+ }
+
+
+
+ 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);
+ MeshPY.Add(IMP);
+ MeshPY.Add(IMM);
+
+ MeshPY.Add(new Triangle(IPM, IPP, IMP));
+ MeshPY.Add(new Triangle(IMP, IMM, IPM));
+
+ foreach (Triangle t in MeshPY.triangles)
+ {
+ PhysicsVector n = t.getNormal();
+ }
+
+
+
+ }
+
+
+ Mesh result = new Mesh();
+ result.Append(MeshMY);
+ result.Append(MeshPY);
+
+ return result;
+ }
+
+ static Mesh CreateBoxMeshZ(PrimitiveBaseShape primShape, PhysicsVector size)
+ // Builds the z (+ and -) surfaces of a box shaped prim
+ {
+ UInt16 hollowFactor = primShape.ProfileHollow;
+
+ // Base, i.e. outer shape
+ // (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 Triangle(MZ.vertices[1], MZ.vertices[0], MZ.vertices[2]));
+ MZ.Add(new Triangle(MZ.vertices[1], MZ.vertices[2], MZ.vertices[3]));
+
+ // (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));
+
+ // Surface 5, +Z
+ PZ.Add(new Triangle(PZ.vertices[0], PZ.vertices[1], PZ.vertices[2]));
+ PZ.Add(new Triangle(PZ.vertices[2], PZ.vertices[1], PZ.vertices[3]));
+
+ if (hollowFactor > 0)
+ {
+ 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));
+
+ List innerBorders = new List();
+ innerBorders.Add(4);
+ innerBorders.Add(5);
+ innerBorders.Add(6);
+ innerBorders.Add(7);
+
+ 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));
+
+ innerBorders = new List();
+ innerBorders.Add(4);
+ innerBorders.Add(5);
+ innerBorders.Add(6);
+ innerBorders.Add(7);
+
+ InsertVertices(PZ.vertices, 4, PZ.triangles, innerBorders);
+
+ }
+
+ foreach (Vertex v in PZ.vertices)
+ {
+ v.point.Z = size.Z / 2.0f;
+ }
+ foreach (Vertex v in MZ.vertices)
+ {
+ v.point.Z = -size.Z / 2.0f;
+ }
+
+ foreach (Triangle t in MZ.triangles)
+ {
+ PhysicsVector n = t.getNormal();
+ if (n.Z > 0.0)
+ t.invertNormal();
+ }
+
+ foreach (Triangle t in PZ.triangles)
+ {
+ PhysicsVector n = t.getNormal();
+ if (n.Z < 0.0)
+ t.invertNormal();
+ }
+
+ Mesh result = new Mesh();
+ result.Append(MZ);
+ result.Append(PZ);
+
+ return result;
+ }
+
+ 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);
+
+ result.Append(MeshX);
+ result.Append(MeshY);
+ result.Append(MeshZ);
+
+ return result;
+ }
+
+
+ public static void CalcNormals(Mesh mesh)
+ {
+ int iTriangles = mesh.triangles.Count;
+
+ mesh.normals = new float[iTriangles*3];
+
+ 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;
+
+ 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;
+
+ // Vectors for edges
+ float e1x, e1y, e1z;
+ float e2x, e2y, e2z;
+
+ e1x = ux - vx;
+ e1y = uy - vy;
+ e1z = uz - vz;
+
+ 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;
+
+ // Length
+ float l = (float)Math.Sqrt(nx * nx + ny * ny + nz * nz);
+
+ // Normalized "normal"
+ nx /= l;
+ ny /= l;
+ nz /= l;
+
+ mesh.normals[i] = nx;
+ mesh.normals[i + 1] = ny;
+ mesh.normals[i + 2] = nz;
+
+ i+=3;
+ }
+ }
+
+ public static Mesh CreateMesh(PrimitiveBaseShape primShape, PhysicsVector size)
+ {
+ Mesh mesh = null;
+
+ switch (primShape.ProfileShape)
+ {
+ case ProfileShape.Square:
+ mesh=CreateBoxMesh(primShape, size);
+ CalcNormals(mesh);
+ break;
+ default:
+ mesh=null;
+ break;
+ }
+
+ return mesh;
+
+ }
+ }
+}
+
--
cgit v1.1
From d20d621ab1aaa972e5d3157b30c67251c26d3912 Mon Sep 17 00:00:00 2001
From: Dalien Talbot
Date: Sun, 30 Sep 2007 08:50:49 +0000
Subject: Corrected the typo in the folder name.
---
.../Physics/OdePlugin/Meshing/HelperTypes.cs | 279 ++++++++++
.../Physics/OdePlugin/Meshing/Meshmerizer.cs | 560 +++++++++++++++++++++
.../Physics/OdePlugin/Meshing\\/HelperTypes.cs" | 279 ----------
.../Physics/OdePlugin/Meshing\\/Meshmerizer.cs" | 560 ---------------------
4 files changed, 839 insertions(+), 839 deletions(-)
create mode 100644 OpenSim/Region/Physics/OdePlugin/Meshing/HelperTypes.cs
create mode 100644 OpenSim/Region/Physics/OdePlugin/Meshing/Meshmerizer.cs
delete mode 100644 "OpenSim/Region/Physics/OdePlugin/Meshing\\/HelperTypes.cs"
delete mode 100644 "OpenSim/Region/Physics/OdePlugin/Meshing\\/Meshmerizer.cs"
(limited to 'OpenSim/Region/Physics/OdePlugin')
diff --git a/OpenSim/Region/Physics/OdePlugin/Meshing/HelperTypes.cs b/OpenSim/Region/Physics/OdePlugin/Meshing/HelperTypes.cs
new file mode 100644
index 0000000..3d40c04
--- /dev/null
+++ b/OpenSim/Region/Physics/OdePlugin/Meshing/HelperTypes.cs
@@ -0,0 +1,279 @@
+using System;
+using System.Globalization;
+using System.Diagnostics;
+using System.Collections.Generic;
+
+using OpenSim.Region.Physics.Manager;
+
+public class Vertex : IComparable
+{
+ public String name;
+ public PhysicsVector point;
+
+ public Vertex(String name, float x, float y, float z)
+ {
+ this.name = name;
+ point = new PhysicsVector(x, y, z);
+ }
+
+ public int CompareTo(Vertex other)
+ {
+ if (point.X < other.point.X)
+ return -1;
+
+ if (point.X > other.point.X)
+ return 1;
+
+ if (point.Y < other.point.Y)
+ return -1;
+
+ if (point.Y > other.point.Y)
+ return 1;
+
+ if (point.Z < other.point.Z)
+ return -1;
+
+ if (point.Z > other.point.Z)
+ return 1;
+
+ return 0;
+ }
+
+ public static bool operator >(Vertex me, Vertex other)
+ {
+ return me.CompareTo(other) > 0;
+ }
+
+ public static bool operator <(Vertex me, Vertex other)
+ {
+ return me.CompareTo(other) < 0;
+ }
+
+
+}
+
+public class Simplex : IComparable
+{
+ public Vertex v1;
+ public Vertex v2;
+
+ public Simplex(Vertex _v1, Vertex _v2)
+ {
+ // Presort indices to make sorting (comparing) easier
+ if (_v1 > _v2)
+ {
+ v1 = _v1;
+ v2 = _v2;
+ }
+ else
+ {
+ v1 = _v2;
+ v2 = _v1;
+ }
+ }
+
+ public int CompareTo(Simplex other)
+ {
+ if (v1 > other.v1)
+ {
+ return 1;
+ }
+ if (v1 < other.v1)
+ {
+ return -1;
+ }
+
+ if (v2 > other.v2)
+ {
+ return 1;
+ }
+ if (v2 < other.v2)
+ {
+ return -1;
+ }
+
+ return 0;
+ }
+
+};
+
+public class Triangle
+{
+ public Vertex v1;
+ public Vertex v2;
+ public Vertex v3;
+
+ float radius_square;
+ float cx;
+ float cy;
+
+ public Triangle(Vertex _v1, Vertex _v2, Vertex _v3)
+ {
+ v1 = _v1;
+ v2 = _v2;
+ v3 = _v3;
+
+ CalcCircle();
+ }
+
+ public bool isInCircle(float x, float y)
+ {
+ float dx, dy;
+ float dd;
+
+ dx = x - this.cx;
+ dy = y - this.cy;
+
+ dd = dx * dx + dy * dy;
+ if (dd < this.radius_square)
+ return true;
+ else
+ return false;
+ }
+
+
+ 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
+ double p1x, p2x, p1y, p2y, p3x, p3y;
+
+ // Deviation of this routine:
+ // A circle has the general equation (M-p)^2=r^2, where M and p are vectors
+ // this gives us three equations f(p)=r^2, each for one point p1, p2, p3
+ // putting respectively two equations together gives two equations
+ // f(p1)=f(p2) and f(p1)=f(p3)
+ // bringing all constant terms to one side brings them to the form
+ // M*v1=c1 resp.M*v2=c2 where v1=(p1-p2) and v2=(p1-p3) (still vectors)
+ // and c1, c2 are scalars (Naming conventions like the variables below)
+ // Now using the equations that are formed by the components of the vectors
+ // and isolate Mx lets you make one equation that only holds My
+ // The rest is straight forward and eaasy :-)
+ //
+
+ /* helping variables for temporary results */
+ double c1, c2;
+ double v1x, v1y, v2x, v2y;
+
+ double z, n;
+
+ double rx, ry;
+
+ // Readout the three points, the triangle consists of
+ p1x = v1.point.X;
+ p1y = v1.point.Y;
+
+ p2x = v2.point.X;
+ p2y = v2.point.Y;
+
+ p3x = v3.point.X;
+ 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;
+
+ v1x = p1x - p2x;
+ v1y = p1y - p2y;
+
+ v2x = p1x - p3x;
+ v2y = p1y - p3y;
+
+ 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
+ {
+ radius_square = 0.0f;
+ return;
+ }
+
+ this.cy = (float)(z / n);
+
+ if (v2x != 0.0)
+ {
+ this.cx = (float)((c2 - v2y * this.cy) / v2x);
+ }
+ else if (v1x != 0.0)
+ {
+ this.cx = (float)((c1 - v1y * this.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);
+
+ }
+
+ public List GetSimplices()
+ {
+ List result = new List();
+ Simplex s1 = new Simplex(v1, v2);
+ Simplex s2 = new Simplex(v2, v3);
+ Simplex s3 = new Simplex(v3, v1);
+
+ result.Add(s1);
+ result.Add(s2);
+ result.Add(s3);
+
+ return result;
+ }
+
+ 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) + ">";
+
+ return s1 + ";" + s2 + ";" + s3;
+
+ }
+
+ public PhysicsVector getNormal()
+ {
+ // Vertices
+
+ // Vectors for edges
+ PhysicsVector e1;
+ PhysicsVector e2;
+
+ e1 = new PhysicsVector(v1.point.X - v2.point.X, v1.point.Y - v2.point.Y, v1.point.Z - v2.point.Z);
+ e2 = new PhysicsVector(v1.point.X - v3.point.X, v1.point.Y - v3.point.Y, v1.point.Z - v3.point.Z);
+
+ // 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;
+
+ // Length
+ float l = (float)Math.Sqrt(n.X * n.X + n.Y * n.Y + n.Z * n.Z);
+
+ // Normalized "normal"
+ n.X /= l;
+ n.Y /= l;
+ n.Z /= l;
+
+ return n;
+ }
+
+ public void invertNormal()
+ {
+ Vertex vt;
+ vt = v1;
+ v1 = v2;
+ v2 = vt;
+ }
+}
+
diff --git a/OpenSim/Region/Physics/OdePlugin/Meshing/Meshmerizer.cs b/OpenSim/Region/Physics/OdePlugin/Meshing/Meshmerizer.cs
new file mode 100644
index 0000000..28dca41
--- /dev/null
+++ b/OpenSim/Region/Physics/OdePlugin/Meshing/Meshmerizer.cs
@@ -0,0 +1,560 @@
+using System;
+using System.Globalization;
+using System.Diagnostics;
+using System.Collections.Generic;
+using System.Text;
+using System.Runtime.InteropServices;
+
+using OpenSim.Framework.Types;
+using OpenSim.Region.Physics.Manager;
+
+namespace OpenSim.Region.Physics.OdePlugin
+{
+ public class Mesh
+ {
+ public List vertices;
+ public List triangles;
+
+ public float[] normals;
+
+ public Mesh()
+ {
+ vertices = new List();
+ triangles = new List();
+ }
+
+ public void Add(Triangle triangle)
+ {
+ int i;
+ i = vertices.IndexOf(triangle.v1);
+ if (i < 0)
+ throw new ArgumentException("Vertex v1 not known to mesh");
+ i = vertices.IndexOf(triangle.v2);
+ if (i < 0)
+ throw new ArgumentException("Vertex v2 not known to mesh");
+ i = vertices.IndexOf(triangle.v3);
+ if (i < 0)
+ throw new ArgumentException("Vertex v3 not known to mesh");
+
+ triangles.Add(triangle);
+ }
+
+ public void Add(Vertex v)
+ {
+ vertices.Add(v);
+ }
+
+
+ public float[] getVertexListAsFloat()
+ {
+ 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;
+ }
+ GCHandle.Alloc(result, GCHandleType.Pinned);
+ return result;
+ }
+
+ public int[] getIndexListAsInt()
+ {
+ 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);
+ }
+ GCHandle.Alloc(result, GCHandleType.Pinned);
+ return result;
+ }
+
+
+ public void Append(Mesh newMesh)
+ {
+ foreach (Vertex v in newMesh.vertices)
+ vertices.Add(v);
+
+ foreach (Triangle t in newMesh.triangles)
+ Add(t);
+
+ }
+ }
+
+
+
+ public class Meshmerizer
+ {
+
+ static List FindInfluencedTriangles(List triangles, Vertex v)
+ {
+ List influenced = new List();
+ foreach (Triangle t in triangles)
+ {
+ float dx, dy;
+
+ if (t.isInCircle(v.point.X, v.point.Y))
+ {
+ influenced.Add(t);
+ }
+ }
+ return influenced;
+ }
+
+
+ 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
+ // and replaced by new ones including the new vertex
+ // It is not very time efficient but easy to implement.
+
+ int iCurrentVertex;
+ int iMaxVertex=vertices.Count;
+ for (iCurrentVertex = usedForSeed; iCurrentVertex < iMaxVertex; iCurrentVertex++)
+ {
+ // Background: A triangle mesh fulfills the delaunay condition if (iff!)
+ // each circumlocutory circle (i.e. the circle that touches all three corners)
+ // of each triangle is empty of other vertices.
+ // Obviously a single (seeding) triangle fulfills this condition.
+ // If we now add one vertex, we need to reconstruct all triangles, that
+ // 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);
+
+ List simplices = new List();
+
+ // Reconstruction phase. First step, dissolve each triangle into it's simplices,
+ // i.e. it's "border lines"
+ // Goal is to find "inner" borders and delete them, while the hull gets conserved.
+ // Inner borders are special in the way that they always come twice, which is how we detect them
+ foreach (Triangle t in influencedTriangles)
+ {
+ List newSimplices = t.GetSimplices();
+ simplices.AddRange(newSimplices);
+ triangles.Remove(t);
+ }
+ // Now sort the simplices. That will make identical ones side by side in the list
+ simplices.Sort();
+
+ // Look for duplicate simplices here.
+ // Remember, they are directly side by side in the list right now
+ int iSimplex;
+ 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)
+ {
+ innerSimplices.Add(simplices[iSimplex - 1]);
+ innerSimplices.Add(simplices[iSimplex]);
+ }
+ }
+
+ foreach (Simplex s in innerSimplices)
+ {
+ simplices.Remove(s);
+ }
+
+ // each simplex still in the list belongs to the hull of the region in question
+ // The new vertex (yes, we still deal with verices here :-) ) forms a triangle
+ // With each of these simplices. Build the new triangles and add them to the list
+ foreach (Simplex s in simplices)
+ {
+ Triangle t = new Triangle(s.v1, s.v2, vertices[iCurrentVertex]);
+ triangles.Add(t);
+ }
+ }
+
+ // At this point all vertices should be inserted into the mesh
+ // But the areas, that should be kept free still are filled with triangles
+ // We have to remove them. For this we have a list of indices to vertices.
+ // Each triangle that solemnly constists of vertices from the inner border
+ // are deleted
+
+ List innerTriangles = new List();
+ foreach (Triangle t in triangles)
+ {
+ if (
+ innerBorders.Contains(vertices.IndexOf(t.v1))
+ && innerBorders.Contains(vertices.IndexOf(t.v2))
+ && innerBorders.Contains(vertices.IndexOf(t.v3))
+ )
+ innerTriangles.Add(t);
+ }
+ foreach (Triangle t in innerTriangles)
+ {
+ triangles.Remove(t);
+ }
+ }
+
+
+ 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 Triangle(meshMX.vertices[0], meshMX.vertices[2], meshMX.vertices[1]));
+ meshMX.Add(new Triangle(meshMX.vertices[1], meshMX.vertices[2], meshMX.vertices[3]));
+
+
+ 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 Triangle(meshPX.vertices[0], meshPX.vertices[1], meshPX.vertices[2]));
+ meshPX.Add(new Triangle(meshPX.vertices[2], meshPX.vertices[1], meshPX.vertices[3]));
+
+
+ if (hollowFactor > 0)
+ {
+ 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);
+
+ meshMX.Add(IPP);
+ meshMX.Add(IPM);
+ meshMX.Add(IMP);
+ meshMX.Add(IMM);
+
+ meshMX.Add(new Triangle(IPP, IMP, IPM));
+ meshMX.Add(new Triangle(IPM, IMP, IMM));
+
+ foreach (Triangle t in meshMX.triangles)
+ {
+ PhysicsVector n = t.getNormal();
+ }
+
+
+
+ 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);
+ meshPX.Add(IMP);
+ meshPX.Add(IMM);
+
+ meshPX.Add(new Triangle(IPP, IPM, IMP));
+ meshPX.Add(new Triangle(IMP, IPM, IMM));
+
+ foreach (Triangle t in meshPX.triangles)
+ {
+ PhysicsVector n = t.getNormal();
+ }
+ }
+
+ Mesh result = new Mesh();
+ result.Append(meshMX);
+ result.Append(meshPX);
+
+ return result;
+ }
+
+
+
+ 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 Triangle(MeshMY.vertices[0], MeshMY.vertices[1], MeshMY.vertices[2]));
+ MeshMY.Add(new Triangle(MeshMY.vertices[2], MeshMY.vertices[1], MeshMY.vertices[3]));
+
+ // (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 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;
+
+ 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);
+
+ MeshMY.Add(IPP);
+ MeshMY.Add(IPM);
+ MeshMY.Add(IMP);
+ MeshMY.Add(IMM);
+
+ MeshMY.Add(new Triangle(IPP, IPM, IMP));
+ MeshMY.Add(new Triangle(IMP, IPM, IMM));
+
+ foreach (Triangle t in MeshMY.triangles)
+ {
+ PhysicsVector n = t.getNormal();
+ }
+
+
+
+ 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);
+ MeshPY.Add(IMP);
+ MeshPY.Add(IMM);
+
+ MeshPY.Add(new Triangle(IPM, IPP, IMP));
+ MeshPY.Add(new Triangle(IMP, IMM, IPM));
+
+ foreach (Triangle t in MeshPY.triangles)
+ {
+ PhysicsVector n = t.getNormal();
+ }
+
+
+
+ }
+
+
+ Mesh result = new Mesh();
+ result.Append(MeshMY);
+ result.Append(MeshPY);
+
+ return result;
+ }
+
+ static Mesh CreateBoxMeshZ(PrimitiveBaseShape primShape, PhysicsVector size)
+ // Builds the z (+ and -) surfaces of a box shaped prim
+ {
+ UInt16 hollowFactor = primShape.ProfileHollow;
+
+ // Base, i.e. outer shape
+ // (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 Triangle(MZ.vertices[1], MZ.vertices[0], MZ.vertices[2]));
+ MZ.Add(new Triangle(MZ.vertices[1], MZ.vertices[2], MZ.vertices[3]));
+
+ // (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));
+
+ // Surface 5, +Z
+ PZ.Add(new Triangle(PZ.vertices[0], PZ.vertices[1], PZ.vertices[2]));
+ PZ.Add(new Triangle(PZ.vertices[2], PZ.vertices[1], PZ.vertices[3]));
+
+ if (hollowFactor > 0)
+ {
+ 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));
+
+ List innerBorders = new List();
+ innerBorders.Add(4);
+ innerBorders.Add(5);
+ innerBorders.Add(6);
+ innerBorders.Add(7);
+
+ 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));
+
+ innerBorders = new List();
+ innerBorders.Add(4);
+ innerBorders.Add(5);
+ innerBorders.Add(6);
+ innerBorders.Add(7);
+
+ InsertVertices(PZ.vertices, 4, PZ.triangles, innerBorders);
+
+ }
+
+ foreach (Vertex v in PZ.vertices)
+ {
+ v.point.Z = size.Z / 2.0f;
+ }
+ foreach (Vertex v in MZ.vertices)
+ {
+ v.point.Z = -size.Z / 2.0f;
+ }
+
+ foreach (Triangle t in MZ.triangles)
+ {
+ PhysicsVector n = t.getNormal();
+ if (n.Z > 0.0)
+ t.invertNormal();
+ }
+
+ foreach (Triangle t in PZ.triangles)
+ {
+ PhysicsVector n = t.getNormal();
+ if (n.Z < 0.0)
+ t.invertNormal();
+ }
+
+ Mesh result = new Mesh();
+ result.Append(MZ);
+ result.Append(PZ);
+
+ return result;
+ }
+
+ 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);
+
+ result.Append(MeshX);
+ result.Append(MeshY);
+ result.Append(MeshZ);
+
+ return result;
+ }
+
+
+ public static void CalcNormals(Mesh mesh)
+ {
+ int iTriangles = mesh.triangles.Count;
+
+ mesh.normals = new float[iTriangles*3];
+
+ 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;
+
+ 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;
+
+ // Vectors for edges
+ float e1x, e1y, e1z;
+ float e2x, e2y, e2z;
+
+ e1x = ux - vx;
+ e1y = uy - vy;
+ e1z = uz - vz;
+
+ 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;
+
+ // Length
+ float l = (float)Math.Sqrt(nx * nx + ny * ny + nz * nz);
+
+ // Normalized "normal"
+ nx /= l;
+ ny /= l;
+ nz /= l;
+
+ mesh.normals[i] = nx;
+ mesh.normals[i + 1] = ny;
+ mesh.normals[i + 2] = nz;
+
+ i+=3;
+ }
+ }
+
+ public static Mesh CreateMesh(PrimitiveBaseShape primShape, PhysicsVector size)
+ {
+ Mesh mesh = null;
+
+ switch (primShape.ProfileShape)
+ {
+ case ProfileShape.Square:
+ mesh=CreateBoxMesh(primShape, size);
+ CalcNormals(mesh);
+ break;
+ default:
+ mesh=null;
+ break;
+ }
+
+ return mesh;
+
+ }
+ }
+}
+
diff --git "a/OpenSim/Region/Physics/OdePlugin/Meshing\\/HelperTypes.cs" "b/OpenSim/Region/Physics/OdePlugin/Meshing\\/HelperTypes.cs"
deleted file mode 100644
index 3d40c04..0000000
--- "a/OpenSim/Region/Physics/OdePlugin/Meshing\\/HelperTypes.cs"
+++ /dev/null
@@ -1,279 +0,0 @@
-using System;
-using System.Globalization;
-using System.Diagnostics;
-using System.Collections.Generic;
-
-using OpenSim.Region.Physics.Manager;
-
-public class Vertex : IComparable
-{
- public String name;
- public PhysicsVector point;
-
- public Vertex(String name, float x, float y, float z)
- {
- this.name = name;
- point = new PhysicsVector(x, y, z);
- }
-
- public int CompareTo(Vertex other)
- {
- if (point.X < other.point.X)
- return -1;
-
- if (point.X > other.point.X)
- return 1;
-
- if (point.Y < other.point.Y)
- return -1;
-
- if (point.Y > other.point.Y)
- return 1;
-
- if (point.Z < other.point.Z)
- return -1;
-
- if (point.Z > other.point.Z)
- return 1;
-
- return 0;
- }
-
- public static bool operator >(Vertex me, Vertex other)
- {
- return me.CompareTo(other) > 0;
- }
-
- public static bool operator <(Vertex me, Vertex other)
- {
- return me.CompareTo(other) < 0;
- }
-
-
-}
-
-public class Simplex : IComparable
-{
- public Vertex v1;
- public Vertex v2;
-
- public Simplex(Vertex _v1, Vertex _v2)
- {
- // Presort indices to make sorting (comparing) easier
- if (_v1 > _v2)
- {
- v1 = _v1;
- v2 = _v2;
- }
- else
- {
- v1 = _v2;
- v2 = _v1;
- }
- }
-
- public int CompareTo(Simplex other)
- {
- if (v1 > other.v1)
- {
- return 1;
- }
- if (v1 < other.v1)
- {
- return -1;
- }
-
- if (v2 > other.v2)
- {
- return 1;
- }
- if (v2 < other.v2)
- {
- return -1;
- }
-
- return 0;
- }
-
-};
-
-public class Triangle
-{
- public Vertex v1;
- public Vertex v2;
- public Vertex v3;
-
- float radius_square;
- float cx;
- float cy;
-
- public Triangle(Vertex _v1, Vertex _v2, Vertex _v3)
- {
- v1 = _v1;
- v2 = _v2;
- v3 = _v3;
-
- CalcCircle();
- }
-
- public bool isInCircle(float x, float y)
- {
- float dx, dy;
- float dd;
-
- dx = x - this.cx;
- dy = y - this.cy;
-
- dd = dx * dx + dy * dy;
- if (dd < this.radius_square)
- return true;
- else
- return false;
- }
-
-
- 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
- double p1x, p2x, p1y, p2y, p3x, p3y;
-
- // Deviation of this routine:
- // A circle has the general equation (M-p)^2=r^2, where M and p are vectors
- // this gives us three equations f(p)=r^2, each for one point p1, p2, p3
- // putting respectively two equations together gives two equations
- // f(p1)=f(p2) and f(p1)=f(p3)
- // bringing all constant terms to one side brings them to the form
- // M*v1=c1 resp.M*v2=c2 where v1=(p1-p2) and v2=(p1-p3) (still vectors)
- // and c1, c2 are scalars (Naming conventions like the variables below)
- // Now using the equations that are formed by the components of the vectors
- // and isolate Mx lets you make one equation that only holds My
- // The rest is straight forward and eaasy :-)
- //
-
- /* helping variables for temporary results */
- double c1, c2;
- double v1x, v1y, v2x, v2y;
-
- double z, n;
-
- double rx, ry;
-
- // Readout the three points, the triangle consists of
- p1x = v1.point.X;
- p1y = v1.point.Y;
-
- p2x = v2.point.X;
- p2y = v2.point.Y;
-
- p3x = v3.point.X;
- 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;
-
- v1x = p1x - p2x;
- v1y = p1y - p2y;
-
- v2x = p1x - p3x;
- v2y = p1y - p3y;
-
- 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
- {
- radius_square = 0.0f;
- return;
- }
-
- this.cy = (float)(z / n);
-
- if (v2x != 0.0)
- {
- this.cx = (float)((c2 - v2y * this.cy) / v2x);
- }
- else if (v1x != 0.0)
- {
- this.cx = (float)((c1 - v1y * this.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);
-
- }
-
- public List GetSimplices()
- {
- List result = new List();
- Simplex s1 = new Simplex(v1, v2);
- Simplex s2 = new Simplex(v2, v3);
- Simplex s3 = new Simplex(v3, v1);
-
- result.Add(s1);
- result.Add(s2);
- result.Add(s3);
-
- return result;
- }
-
- 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) + ">";
-
- return s1 + ";" + s2 + ";" + s3;
-
- }
-
- public PhysicsVector getNormal()
- {
- // Vertices
-
- // Vectors for edges
- PhysicsVector e1;
- PhysicsVector e2;
-
- e1 = new PhysicsVector(v1.point.X - v2.point.X, v1.point.Y - v2.point.Y, v1.point.Z - v2.point.Z);
- e2 = new PhysicsVector(v1.point.X - v3.point.X, v1.point.Y - v3.point.Y, v1.point.Z - v3.point.Z);
-
- // 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;
-
- // Length
- float l = (float)Math.Sqrt(n.X * n.X + n.Y * n.Y + n.Z * n.Z);
-
- // Normalized "normal"
- n.X /= l;
- n.Y /= l;
- n.Z /= l;
-
- return n;
- }
-
- public void invertNormal()
- {
- Vertex vt;
- vt = v1;
- v1 = v2;
- v2 = vt;
- }
-}
-
diff --git "a/OpenSim/Region/Physics/OdePlugin/Meshing\\/Meshmerizer.cs" "b/OpenSim/Region/Physics/OdePlugin/Meshing\\/Meshmerizer.cs"
deleted file mode 100644
index 28dca41..0000000
--- "a/OpenSim/Region/Physics/OdePlugin/Meshing\\/Meshmerizer.cs"
+++ /dev/null
@@ -1,560 +0,0 @@
-using System;
-using System.Globalization;
-using System.Diagnostics;
-using System.Collections.Generic;
-using System.Text;
-using System.Runtime.InteropServices;
-
-using OpenSim.Framework.Types;
-using OpenSim.Region.Physics.Manager;
-
-namespace OpenSim.Region.Physics.OdePlugin
-{
- public class Mesh
- {
- public List vertices;
- public List triangles;
-
- public float[] normals;
-
- public Mesh()
- {
- vertices = new List();
- triangles = new List();
- }
-
- public void Add(Triangle triangle)
- {
- int i;
- i = vertices.IndexOf(triangle.v1);
- if (i < 0)
- throw new ArgumentException("Vertex v1 not known to mesh");
- i = vertices.IndexOf(triangle.v2);
- if (i < 0)
- throw new ArgumentException("Vertex v2 not known to mesh");
- i = vertices.IndexOf(triangle.v3);
- if (i < 0)
- throw new ArgumentException("Vertex v3 not known to mesh");
-
- triangles.Add(triangle);
- }
-
- public void Add(Vertex v)
- {
- vertices.Add(v);
- }
-
-
- public float[] getVertexListAsFloat()
- {
- 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;
- }
- GCHandle.Alloc(result, GCHandleType.Pinned);
- return result;
- }
-
- public int[] getIndexListAsInt()
- {
- 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);
- }
- GCHandle.Alloc(result, GCHandleType.Pinned);
- return result;
- }
-
-
- public void Append(Mesh newMesh)
- {
- foreach (Vertex v in newMesh.vertices)
- vertices.Add(v);
-
- foreach (Triangle t in newMesh.triangles)
- Add(t);
-
- }
- }
-
-
-
- public class Meshmerizer
- {
-
- static List FindInfluencedTriangles(List triangles, Vertex v)
- {
- List influenced = new List();
- foreach (Triangle t in triangles)
- {
- float dx, dy;
-
- if (t.isInCircle(v.point.X, v.point.Y))
- {
- influenced.Add(t);
- }
- }
- return influenced;
- }
-
-
- 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
- // and replaced by new ones including the new vertex
- // It is not very time efficient but easy to implement.
-
- int iCurrentVertex;
- int iMaxVertex=vertices.Count;
- for (iCurrentVertex = usedForSeed; iCurrentVertex < iMaxVertex; iCurrentVertex++)
- {
- // Background: A triangle mesh fulfills the delaunay condition if (iff!)
- // each circumlocutory circle (i.e. the circle that touches all three corners)
- // of each triangle is empty of other vertices.
- // Obviously a single (seeding) triangle fulfills this condition.
- // If we now add one vertex, we need to reconstruct all triangles, that
- // 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);
-
- List simplices = new List();
-
- // Reconstruction phase. First step, dissolve each triangle into it's simplices,
- // i.e. it's "border lines"
- // Goal is to find "inner" borders and delete them, while the hull gets conserved.
- // Inner borders are special in the way that they always come twice, which is how we detect them
- foreach (Triangle t in influencedTriangles)
- {
- List newSimplices = t.GetSimplices();
- simplices.AddRange(newSimplices);
- triangles.Remove(t);
- }
- // Now sort the simplices. That will make identical ones side by side in the list
- simplices.Sort();
-
- // Look for duplicate simplices here.
- // Remember, they are directly side by side in the list right now
- int iSimplex;
- 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)
- {
- innerSimplices.Add(simplices[iSimplex - 1]);
- innerSimplices.Add(simplices[iSimplex]);
- }
- }
-
- foreach (Simplex s in innerSimplices)
- {
- simplices.Remove(s);
- }
-
- // each simplex still in the list belongs to the hull of the region in question
- // The new vertex (yes, we still deal with verices here :-) ) forms a triangle
- // With each of these simplices. Build the new triangles and add them to the list
- foreach (Simplex s in simplices)
- {
- Triangle t = new Triangle(s.v1, s.v2, vertices[iCurrentVertex]);
- triangles.Add(t);
- }
- }
-
- // At this point all vertices should be inserted into the mesh
- // But the areas, that should be kept free still are filled with triangles
- // We have to remove them. For this we have a list of indices to vertices.
- // Each triangle that solemnly constists of vertices from the inner border
- // are deleted
-
- List innerTriangles = new List();
- foreach (Triangle t in triangles)
- {
- if (
- innerBorders.Contains(vertices.IndexOf(t.v1))
- && innerBorders.Contains(vertices.IndexOf(t.v2))
- && innerBorders.Contains(vertices.IndexOf(t.v3))
- )
- innerTriangles.Add(t);
- }
- foreach (Triangle t in innerTriangles)
- {
- triangles.Remove(t);
- }
- }
-
-
- 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 Triangle(meshMX.vertices[0], meshMX.vertices[2], meshMX.vertices[1]));
- meshMX.Add(new Triangle(meshMX.vertices[1], meshMX.vertices[2], meshMX.vertices[3]));
-
-
- 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 Triangle(meshPX.vertices[0], meshPX.vertices[1], meshPX.vertices[2]));
- meshPX.Add(new Triangle(meshPX.vertices[2], meshPX.vertices[1], meshPX.vertices[3]));
-
-
- if (hollowFactor > 0)
- {
- 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);
-
- meshMX.Add(IPP);
- meshMX.Add(IPM);
- meshMX.Add(IMP);
- meshMX.Add(IMM);
-
- meshMX.Add(new Triangle(IPP, IMP, IPM));
- meshMX.Add(new Triangle(IPM, IMP, IMM));
-
- foreach (Triangle t in meshMX.triangles)
- {
- PhysicsVector n = t.getNormal();
- }
-
-
-
- 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);
- meshPX.Add(IMP);
- meshPX.Add(IMM);
-
- meshPX.Add(new Triangle(IPP, IPM, IMP));
- meshPX.Add(new Triangle(IMP, IPM, IMM));
-
- foreach (Triangle t in meshPX.triangles)
- {
- PhysicsVector n = t.getNormal();
- }
- }
-
- Mesh result = new Mesh();
- result.Append(meshMX);
- result.Append(meshPX);
-
- return result;
- }
-
-
-
- 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 Triangle(MeshMY.vertices[0], MeshMY.vertices[1], MeshMY.vertices[2]));
- MeshMY.Add(new Triangle(MeshMY.vertices[2], MeshMY.vertices[1], MeshMY.vertices[3]));
-
- // (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 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;
-
- 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);
-
- MeshMY.Add(IPP);
- MeshMY.Add(IPM);
- MeshMY.Add(IMP);
- MeshMY.Add(IMM);
-
- MeshMY.Add(new Triangle(IPP, IPM, IMP));
- MeshMY.Add(new Triangle(IMP, IPM, IMM));
-
- foreach (Triangle t in MeshMY.triangles)
- {
- PhysicsVector n = t.getNormal();
- }
-
-
-
- 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);
- MeshPY.Add(IMP);
- MeshPY.Add(IMM);
-
- MeshPY.Add(new Triangle(IPM, IPP, IMP));
- MeshPY.Add(new Triangle(IMP, IMM, IPM));
-
- foreach (Triangle t in MeshPY.triangles)
- {
- PhysicsVector n = t.getNormal();
- }
-
-
-
- }
-
-
- Mesh result = new Mesh();
- result.Append(MeshMY);
- result.Append(MeshPY);
-
- return result;
- }
-
- static Mesh CreateBoxMeshZ(PrimitiveBaseShape primShape, PhysicsVector size)
- // Builds the z (+ and -) surfaces of a box shaped prim
- {
- UInt16 hollowFactor = primShape.ProfileHollow;
-
- // Base, i.e. outer shape
- // (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 Triangle(MZ.vertices[1], MZ.vertices[0], MZ.vertices[2]));
- MZ.Add(new Triangle(MZ.vertices[1], MZ.vertices[2], MZ.vertices[3]));
-
- // (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));
-
- // Surface 5, +Z
- PZ.Add(new Triangle(PZ.vertices[0], PZ.vertices[1], PZ.vertices[2]));
- PZ.Add(new Triangle(PZ.vertices[2], PZ.vertices[1], PZ.vertices[3]));
-
- if (hollowFactor > 0)
- {
- 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));
-
- List innerBorders = new List();
- innerBorders.Add(4);
- innerBorders.Add(5);
- innerBorders.Add(6);
- innerBorders.Add(7);
-
- 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));
-
- innerBorders = new List();
- innerBorders.Add(4);
- innerBorders.Add(5);
- innerBorders.Add(6);
- innerBorders.Add(7);
-
- InsertVertices(PZ.vertices, 4, PZ.triangles, innerBorders);
-
- }
-
- foreach (Vertex v in PZ.vertices)
- {
- v.point.Z = size.Z / 2.0f;
- }
- foreach (Vertex v in MZ.vertices)
- {
- v.point.Z = -size.Z / 2.0f;
- }
-
- foreach (Triangle t in MZ.triangles)
- {
- PhysicsVector n = t.getNormal();
- if (n.Z > 0.0)
- t.invertNormal();
- }
-
- foreach (Triangle t in PZ.triangles)
- {
- PhysicsVector n = t.getNormal();
- if (n.Z < 0.0)
- t.invertNormal();
- }
-
- Mesh result = new Mesh();
- result.Append(MZ);
- result.Append(PZ);
-
- return result;
- }
-
- 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);
-
- result.Append(MeshX);
- result.Append(MeshY);
- result.Append(MeshZ);
-
- return result;
- }
-
-
- public static void CalcNormals(Mesh mesh)
- {
- int iTriangles = mesh.triangles.Count;
-
- mesh.normals = new float[iTriangles*3];
-
- 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;
-
- 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;
-
- // Vectors for edges
- float e1x, e1y, e1z;
- float e2x, e2y, e2z;
-
- e1x = ux - vx;
- e1y = uy - vy;
- e1z = uz - vz;
-
- 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;
-
- // Length
- float l = (float)Math.Sqrt(nx * nx + ny * ny + nz * nz);
-
- // Normalized "normal"
- nx /= l;
- ny /= l;
- nz /= l;
-
- mesh.normals[i] = nx;
- mesh.normals[i + 1] = ny;
- mesh.normals[i + 2] = nz;
-
- i+=3;
- }
- }
-
- public static Mesh CreateMesh(PrimitiveBaseShape primShape, PhysicsVector size)
- {
- Mesh mesh = null;
-
- switch (primShape.ProfileShape)
- {
- case ProfileShape.Square:
- mesh=CreateBoxMesh(primShape, size);
- CalcNormals(mesh);
- break;
- default:
- mesh=null;
- break;
- }
-
- return mesh;
-
- }
- }
-}
-
--
cgit v1.1
From d644b1f440b36f5b0f492ad085f3fbac0e7920ad Mon Sep 17 00:00:00 2001
From: dan miller
Date: Mon, 1 Oct 2007 16:01:42 +0000
Subject: this should fix mantis 452 and related -- hollow prims work in Linux!
(I hope)
---
OpenSim/Region/Physics/OdePlugin/OdePlugin.cs | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
(limited to 'OpenSim/Region/Physics/OdePlugin')
diff --git a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
index e7592fb..1594490 100644
--- a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
+++ b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
@@ -69,6 +69,7 @@ namespace OpenSim.Region.Physics.OdePlugin
public string GetName()
{
+ d.bug();
return ("OpenDynamicsEngine");
}
@@ -639,7 +640,7 @@ namespace OpenSim.Region.Physics.OdePlugin
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, parent_scene.triArrayCallback, null);
+ prim_geom = d.CreateTriMesh(parent_scene.space, _triMeshData, parent_scene.triCallback, null, null);
}
public override bool Flying
--
cgit v1.1
From 034f0b4bb75c27ef9278ab284cf99c6e1d4d21af Mon Sep 17 00:00:00 2001
From: dan miller
Date: Mon, 1 Oct 2007 16:18:34 +0000
Subject: fixing odeplugin debug bug
---
OpenSim/Region/Physics/OdePlugin/OdePlugin.cs | 1 -
1 file changed, 1 deletion(-)
(limited to 'OpenSim/Region/Physics/OdePlugin')
diff --git a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
index 1594490..3c5bdce 100644
--- a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
+++ b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
@@ -69,7 +69,6 @@ namespace OpenSim.Region.Physics.OdePlugin
public string GetName()
{
- d.bug();
return ("OpenDynamicsEngine");
}
--
cgit v1.1
From 625164d3e2834f4afb5768090fdce6978a1468d3 Mon Sep 17 00:00:00 2001
From: dan miller
Date: Mon, 1 Oct 2007 16:26:15 +0000
Subject: removed debug statements
---
OpenSim/Region/Physics/OdePlugin/OdePlugin.cs | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
(limited to 'OpenSim/Region/Physics/OdePlugin')
diff --git a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
index 3c5bdce..ddc6c4a 100644
--- a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
+++ b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
@@ -256,12 +256,10 @@ namespace OpenSim.Region.Physics.OdePlugin
if (!geom_name_map.TryGetValue(trimesh, out name1))
{
- Console.WriteLine("+++ nulling " + name1);
name1 = "null";
}
if (!geom_name_map.TryGetValue(refObject, out name2))
{
- Console.WriteLine("+++ nulling " + name2);
name2 = "null";
}
@@ -272,7 +270,7 @@ namespace OpenSim.Region.Physics.OdePlugin
d.Vector3 v2 = new d.Vector3();
d.GeomTriMeshGetTriangle(trimesh, 0, ref v0, ref v1, ref v2);
- MainLog.Instance.Debug("Triangle {0} is <{1},{2},{3}>, <{4},{5},{6}>, <{7},{8},{9}>", triangleIndex, v0.X, v0.Y, v0.Z, v1.X, v1.Y, v1.Z, v2.X, v2.Y, v2.Z);
+// MainLog.Instance.Debug("Triangle {0} is <{1},{2},{3}>, <{4},{5},{6}>, <{7},{8},{9}>", triangleIndex, v0.X, v0.Y, v0.Z, v1.X, v1.Y, v1.Z, v2.X, v2.Y, v2.Z);
return 1;
}
--
cgit v1.1
From d36316e1c9aac6427716a99a817546002ba3d9a1 Mon Sep 17 00:00:00 2001
From: dan miller
Date: Wed, 3 Oct 2007 01:59:43 +0000
Subject: Droppin da fyzyx bomb on ya seriously, this is quite the update.
Fixes a number of nagging physics problems, including avatar shell size/shape
The internal logic is quite different, and CPU usage may be affected. Also
some work remains wrt flying. Please test this rev out before you deploy
widely
---
OpenSim/Region/Physics/OdePlugin/OdePlugin.cs | 130 ++++++++++++++++++--------
1 file changed, 89 insertions(+), 41 deletions(-)
(limited to 'OpenSim/Region/Physics/OdePlugin')
diff --git a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
index ddc6c4a..ac784cf 100644
--- a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
+++ b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
@@ -80,6 +80,7 @@ namespace OpenSim.Region.Physics.OdePlugin
public class OdeScene : PhysicsScene
{
+ private static float ODE_STEPSIZE = 0.004f;
private IntPtr contactgroup;
private IntPtr LandGeom;
private double[] _heightmap;
@@ -91,7 +92,7 @@ namespace OpenSim.Region.Physics.OdePlugin
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;
public IntPtr world;
public IntPtr space;
public static Object OdeLock = new Object();
@@ -101,12 +102,15 @@ namespace OpenSim.Region.Physics.OdePlugin
nearCallback = near;
triCallback = TriCallback;
triArrayCallback = TriArrayCallback;
+ /*
contact.surface.mode |= d.ContactFlags.Approx1 | d.ContactFlags.SoftCFM | d.ContactFlags.SoftERP;
contact.surface.mu = 10.0f;
contact.surface.bounce = 0.9f;
contact.surface.soft_erp = 0.005f;
contact.surface.soft_cfm = 0.00003f;
-
+ */
+ contact.surface.mu = 250.0f;
+ contact.surface.bounce = 0.2f;
lock (OdeLock)
{
world = d.WorldCreate();
@@ -115,6 +119,8 @@ namespace OpenSim.Region.Physics.OdePlugin
d.WorldSetGravity(world, 0.0f, 0.0f, -10.0f);
d.WorldSetAutoDisableFlag(world, false);
d.WorldSetContactSurfaceLayer(world, 0.001f);
+ d.WorldSetQuickStepNumIterations(world, 10);
+ d.WorldSetContactMaxCorrectingVel(world, 1000.0f);
}
_heightmap = new double[65536];
@@ -164,10 +170,10 @@ namespace OpenSim.Region.Physics.OdePlugin
{
foreach (OdeCharacter chr in _characters)
{
- d.SpaceCollide2(space, chr.capsule_geom, IntPtr.Zero, nearCallback);
+ 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
{
- d.SpaceCollide2(chr.capsule_geom, ch2.capsule_geom, IntPtr.Zero, nearCallback);
+ d.SpaceCollide2(chr.Shell, ch2.Shell, IntPtr.Zero, nearCallback);
}
}
}
@@ -307,25 +313,29 @@ namespace OpenSim.Region.Physics.OdePlugin
public override void Simulate(float timeStep)
{
+ step_time += timeStep;
lock (OdeLock)
{
foreach (OdePrim p in _prims)
{
}
- foreach (OdeCharacter actor in _characters)
- {
- actor.Move(timeStep);
- }
- collision_optimized();
- for (int i = 0; i < 50; i++)
+ int i = 0;
+ while (step_time > 0.0f)
{
- d.WorldQuickStep(world, timeStep * 0.02f);
+ foreach (OdeCharacter actor in _characters)
+ {
+ actor.Move(timeStep);
+ }
+ collision_optimized();
+ d.WorldQuickStep(world, ODE_STEPSIZE);
+ d.JointGroupEmpty(contactgroup);
+ step_time -= ODE_STEPSIZE;
+ i++;
}
- d.JointGroupEmpty(contactgroup);
foreach (OdeCharacter actor in _characters)
{
- actor.UpdatePosition();
+ actor.UpdatePositionAndVelocity();
}
}
}
@@ -392,30 +402,35 @@ namespace OpenSim.Region.Physics.OdePlugin
private d.Vector3 _zeroPosition;
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 POSTURE_SERVO = 10000.0f;
private bool flying = false;
//private float gravityAccel;
- public IntPtr BoundingCapsule;
+ public IntPtr Body;
private OdeScene _parent_scene;
- public IntPtr capsule_geom;
- public d.Mass capsule_mass;
+ public IntPtr Shell;
+ public d.Mass ShellMass;
public OdeCharacter(String avName, OdeScene parent_scene, PhysicsVector pos)
{
_velocity = new PhysicsVector();
+ _target_velocity = new PhysicsVector();
_position = pos;
_acceleration = new PhysicsVector();
_parent_scene = parent_scene;
lock (OdeScene.OdeLock)
{
- d.MassSetCapsule(out capsule_mass, 50.0f, 3, 0.5f, 2f);
- capsule_geom = d.CreateSphere(parent_scene.space, 1.0f); /// not a typo! Spheres roll, capsules tumble
- BoundingCapsule = d.BodyCreate(parent_scene.world);
- d.BodySetMass(BoundingCapsule, ref capsule_mass);
- d.BodySetPosition(BoundingCapsule, pos.X, pos.Y, pos.Z);
- d.GeomSetBody(capsule_geom, BoundingCapsule);
+ Shell = d.CreateCapsule(parent_scene.space, 0.4f, 1.0f);
+ d.MassSetCapsule(out ShellMass, 50.0f, 3, 0.4f, 1.0f);
+ Body = d.BodyCreate(parent_scene.world);
+ d.BodySetMass(Body, ref ShellMass);
+ d.BodySetPosition(Body, pos.X, pos.Y, pos.Z);
+ d.GeomSetBody(Shell, Body);
}
- parent_scene.geom_name_map[capsule_geom]=avName;
+ parent_scene.geom_name_map[Shell]=avName;
}
@@ -441,7 +456,7 @@ namespace OpenSim.Region.Physics.OdePlugin
{
lock (OdeScene.OdeLock)
{
- d.BodySetPosition(BoundingCapsule, value.X, value.Y, value.Z);
+ d.BodySetPosition(Body, value.X, value.Y, value.Z);
_position = value;
}
}
@@ -467,7 +482,7 @@ namespace OpenSim.Region.Physics.OdePlugin
}
set
{
- _velocity = value;
+ _target_velocity = value;
}
}
@@ -522,38 +537,58 @@ namespace OpenSim.Region.Physics.OdePlugin
{
// no lock; for now it's only called from within Simulate()
PhysicsVector vec = new PhysicsVector();
- d.Vector3 vel = d.BodyGetLinearVel(BoundingCapsule);
+ d.Vector3 vel = d.BodyGetLinearVel(Body);
// if velocity is zero, use position control; otherwise, velocity control
- if (_velocity.X == 0.0f & _velocity.Y == 0.0f & _velocity.Z == 0.0f & !flying)
+ if (_target_velocity.X == 0.0f & _target_velocity.Y == 0.0f & _target_velocity.Z == 0.0f)
{
// keep track of where we stopped. No more slippin' & slidin'
if (!_zeroFlag)
{
_zeroFlag = true;
- _zeroPosition = d.BodyGetPosition(BoundingCapsule);
+ _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;
+ if (flying)
+ {
+ vec.Z = (_target_velocity.Z - vel.Z) * PID_D + (_zeroPosition.Z - pos.Z) * PID_P;
}
- d.Vector3 pos = d.BodyGetPosition(BoundingCapsule);
- vec.X = (_velocity.X - vel.X) * 75000.0f + (_zeroPosition.X - pos.X) * 120000.0f;
- vec.Y = (_velocity.Y - vel.Y) * 75000.0f + (_zeroPosition.Y - pos.Y) * 120000.0f;
}
else
{
_zeroFlag = false;
- vec.X = (_velocity.X - vel.X) * 75000.0f;
- vec.Y = (_velocity.Y - vel.Y) * 75000.0f;
+ vec.X = (_target_velocity.X - vel.X) * PID_D;
+ vec.Y = (_target_velocity.Y - vel.Y) * PID_D;
if (flying)
{
- vec.Z = (_velocity.Z - vel.Z) * 75000.0f;
+ vec.Z = (_target_velocity.Z - vel.Z) * PID_D;
}
}
- d.BodyAddForce(this.BoundingCapsule, vec.X, vec.Y, vec.Z);
+ if (flying)
+ {
+ vec.Z += 10.0f;
+ }
+ d.BodyAddForce(this.Body, vec.X, vec.Y, vec.Z);
+
+ // ok -- let's stand up straight!
+ d.Vector3 feet;
+ d.Vector3 head;
+ d.BodyGetRelPointPos(Body, 0.0f, 0.0f, -1.0f, out feet);
+ d.BodyGetRelPointPos(Body, 0.0f, 0.0f, 1.0f, out head);
+ float posture = head.Z - feet.Z;
+
+ // restoring force proportional to lack of posture:
+ 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);
}
- public void UpdatePosition()
+ public void UpdatePositionAndVelocity()
{
// no lock; called from Simulate() -- if you call this from elsewhere, gotta lock or do Monitor.Enter/Exit!
- d.Vector3 vec = d.BodyGetPosition(BoundingCapsule);
+ d.Vector3 vec = d.BodyGetPosition(Body);
// kluge to keep things in bounds. ODE lets dead avatars drift away (they should be removed!)
if (vec.X < 0.0f) vec.X = 0.0f;
@@ -564,16 +599,29 @@ namespace OpenSim.Region.Physics.OdePlugin
this._position.X = vec.X;
this._position.Y = vec.Y;
this._position.Z = vec.Z;
+
+ if (_zeroFlag)
+ {
+ _velocity.X = 0.0f;
+ _velocity.Y = 0.0f;
+ _velocity.Z = 0.0f;
+ }
+ else
+ {
+ vec = d.BodyGetLinearVel(Body);
+ _velocity.X = vec.X;
+ _velocity.Y = vec.Y;
+ _velocity.Z = vec.Z;
+ }
}
public void Destroy()
{
lock (OdeScene.OdeLock)
{
- d.GeomDestroy(this.capsule_geom);
- Console.WriteLine("+++ removing geom");
- this._parent_scene.geom_name_map.Remove(this.capsule_geom);
- d.BodyDestroy(this.BoundingCapsule);
+ d.GeomDestroy(this.Shell);
+ this._parent_scene.geom_name_map.Remove(this.Shell);
+ d.BodyDestroy(this.Body);
}
}
}
--
cgit v1.1
From c3d8f1f4253f72484100394940e62f2912cbc4ff Mon Sep 17 00:00:00 2001
From: Sean Dague
Date: Fri, 5 Oct 2007 15:45:45 +0000
Subject: getting all our line endings consistant again
---
.../Physics/OdePlugin/Meshing/Meshmerizer.cs | 1120 ++++++++++----------
1 file changed, 560 insertions(+), 560 deletions(-)
(limited to 'OpenSim/Region/Physics/OdePlugin')
diff --git a/OpenSim/Region/Physics/OdePlugin/Meshing/Meshmerizer.cs b/OpenSim/Region/Physics/OdePlugin/Meshing/Meshmerizer.cs
index 28dca41..ce3ba5c 100644
--- a/OpenSim/Region/Physics/OdePlugin/Meshing/Meshmerizer.cs
+++ b/OpenSim/Region/Physics/OdePlugin/Meshing/Meshmerizer.cs
@@ -1,560 +1,560 @@
-using System;
-using System.Globalization;
-using System.Diagnostics;
-using System.Collections.Generic;
-using System.Text;
-using System.Runtime.InteropServices;
-
-using OpenSim.Framework.Types;
-using OpenSim.Region.Physics.Manager;
-
-namespace OpenSim.Region.Physics.OdePlugin
-{
- public class Mesh
- {
- public List vertices;
- public List triangles;
-
- public float[] normals;
-
- public Mesh()
- {
- vertices = new List();
- triangles = new List();
- }
-
- public void Add(Triangle triangle)
- {
- int i;
- i = vertices.IndexOf(triangle.v1);
- if (i < 0)
- throw new ArgumentException("Vertex v1 not known to mesh");
- i = vertices.IndexOf(triangle.v2);
- if (i < 0)
- throw new ArgumentException("Vertex v2 not known to mesh");
- i = vertices.IndexOf(triangle.v3);
- if (i < 0)
- throw new ArgumentException("Vertex v3 not known to mesh");
-
- triangles.Add(triangle);
- }
-
- public void Add(Vertex v)
- {
- vertices.Add(v);
- }
-
-
- public float[] getVertexListAsFloat()
- {
- 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;
- }
- GCHandle.Alloc(result, GCHandleType.Pinned);
- return result;
- }
-
- public int[] getIndexListAsInt()
- {
- 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);
- }
- GCHandle.Alloc(result, GCHandleType.Pinned);
- return result;
- }
-
-
- public void Append(Mesh newMesh)
- {
- foreach (Vertex v in newMesh.vertices)
- vertices.Add(v);
-
- foreach (Triangle t in newMesh.triangles)
- Add(t);
-
- }
- }
-
-
-
- public class Meshmerizer
- {
-
- static List FindInfluencedTriangles(List triangles, Vertex v)
- {
- List influenced = new List();
- foreach (Triangle t in triangles)
- {
- float dx, dy;
-
- if (t.isInCircle(v.point.X, v.point.Y))
- {
- influenced.Add(t);
- }
- }
- return influenced;
- }
-
-
- 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
- // and replaced by new ones including the new vertex
- // It is not very time efficient but easy to implement.
-
- int iCurrentVertex;
- int iMaxVertex=vertices.Count;
- for (iCurrentVertex = usedForSeed; iCurrentVertex < iMaxVertex; iCurrentVertex++)
- {
- // Background: A triangle mesh fulfills the delaunay condition if (iff!)
- // each circumlocutory circle (i.e. the circle that touches all three corners)
- // of each triangle is empty of other vertices.
- // Obviously a single (seeding) triangle fulfills this condition.
- // If we now add one vertex, we need to reconstruct all triangles, that
- // 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);
-
- List simplices = new List();
-
- // Reconstruction phase. First step, dissolve each triangle into it's simplices,
- // i.e. it's "border lines"
- // Goal is to find "inner" borders and delete them, while the hull gets conserved.
- // Inner borders are special in the way that they always come twice, which is how we detect them
- foreach (Triangle t in influencedTriangles)
- {
- List newSimplices = t.GetSimplices();
- simplices.AddRange(newSimplices);
- triangles.Remove(t);
- }
- // Now sort the simplices. That will make identical ones side by side in the list
- simplices.Sort();
-
- // Look for duplicate simplices here.
- // Remember, they are directly side by side in the list right now
- int iSimplex;
- 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)
- {
- innerSimplices.Add(simplices[iSimplex - 1]);
- innerSimplices.Add(simplices[iSimplex]);
- }
- }
-
- foreach (Simplex s in innerSimplices)
- {
- simplices.Remove(s);
- }
-
- // each simplex still in the list belongs to the hull of the region in question
- // The new vertex (yes, we still deal with verices here :-) ) forms a triangle
- // With each of these simplices. Build the new triangles and add them to the list
- foreach (Simplex s in simplices)
- {
- Triangle t = new Triangle(s.v1, s.v2, vertices[iCurrentVertex]);
- triangles.Add(t);
- }
- }
-
- // At this point all vertices should be inserted into the mesh
- // But the areas, that should be kept free still are filled with triangles
- // We have to remove them. For this we have a list of indices to vertices.
- // Each triangle that solemnly constists of vertices from the inner border
- // are deleted
-
- List innerTriangles = new List();
- foreach (Triangle t in triangles)
- {
- if (
- innerBorders.Contains(vertices.IndexOf(t.v1))
- && innerBorders.Contains(vertices.IndexOf(t.v2))
- && innerBorders.Contains(vertices.IndexOf(t.v3))
- )
- innerTriangles.Add(t);
- }
- foreach (Triangle t in innerTriangles)
- {
- triangles.Remove(t);
- }
- }
-
-
- 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 Triangle(meshMX.vertices[0], meshMX.vertices[2], meshMX.vertices[1]));
- meshMX.Add(new Triangle(meshMX.vertices[1], meshMX.vertices[2], meshMX.vertices[3]));
-
-
- 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 Triangle(meshPX.vertices[0], meshPX.vertices[1], meshPX.vertices[2]));
- meshPX.Add(new Triangle(meshPX.vertices[2], meshPX.vertices[1], meshPX.vertices[3]));
-
-
- if (hollowFactor > 0)
- {
- 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);
-
- meshMX.Add(IPP);
- meshMX.Add(IPM);
- meshMX.Add(IMP);
- meshMX.Add(IMM);
-
- meshMX.Add(new Triangle(IPP, IMP, IPM));
- meshMX.Add(new Triangle(IPM, IMP, IMM));
-
- foreach (Triangle t in meshMX.triangles)
- {
- PhysicsVector n = t.getNormal();
- }
-
-
-
- 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);
- meshPX.Add(IMP);
- meshPX.Add(IMM);
-
- meshPX.Add(new Triangle(IPP, IPM, IMP));
- meshPX.Add(new Triangle(IMP, IPM, IMM));
-
- foreach (Triangle t in meshPX.triangles)
- {
- PhysicsVector n = t.getNormal();
- }
- }
-
- Mesh result = new Mesh();
- result.Append(meshMX);
- result.Append(meshPX);
-
- return result;
- }
-
-
-
- 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 Triangle(MeshMY.vertices[0], MeshMY.vertices[1], MeshMY.vertices[2]));
- MeshMY.Add(new Triangle(MeshMY.vertices[2], MeshMY.vertices[1], MeshMY.vertices[3]));
-
- // (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 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;
-
- 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);
-
- MeshMY.Add(IPP);
- MeshMY.Add(IPM);
- MeshMY.Add(IMP);
- MeshMY.Add(IMM);
-
- MeshMY.Add(new Triangle(IPP, IPM, IMP));
- MeshMY.Add(new Triangle(IMP, IPM, IMM));
-
- foreach (Triangle t in MeshMY.triangles)
- {
- PhysicsVector n = t.getNormal();
- }
-
-
-
- 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);
- MeshPY.Add(IMP);
- MeshPY.Add(IMM);
-
- MeshPY.Add(new Triangle(IPM, IPP, IMP));
- MeshPY.Add(new Triangle(IMP, IMM, IPM));
-
- foreach (Triangle t in MeshPY.triangles)
- {
- PhysicsVector n = t.getNormal();
- }
-
-
-
- }
-
-
- Mesh result = new Mesh();
- result.Append(MeshMY);
- result.Append(MeshPY);
-
- return result;
- }
-
- static Mesh CreateBoxMeshZ(PrimitiveBaseShape primShape, PhysicsVector size)
- // Builds the z (+ and -) surfaces of a box shaped prim
- {
- UInt16 hollowFactor = primShape.ProfileHollow;
-
- // Base, i.e. outer shape
- // (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 Triangle(MZ.vertices[1], MZ.vertices[0], MZ.vertices[2]));
- MZ.Add(new Triangle(MZ.vertices[1], MZ.vertices[2], MZ.vertices[3]));
-
- // (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));
-
- // Surface 5, +Z
- PZ.Add(new Triangle(PZ.vertices[0], PZ.vertices[1], PZ.vertices[2]));
- PZ.Add(new Triangle(PZ.vertices[2], PZ.vertices[1], PZ.vertices[3]));
-
- if (hollowFactor > 0)
- {
- 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));
-
- List innerBorders = new List();
- innerBorders.Add(4);
- innerBorders.Add(5);
- innerBorders.Add(6);
- innerBorders.Add(7);
-
- 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));
-
- innerBorders = new List();
- innerBorders.Add(4);
- innerBorders.Add(5);
- innerBorders.Add(6);
- innerBorders.Add(7);
-
- InsertVertices(PZ.vertices, 4, PZ.triangles, innerBorders);
-
- }
-
- foreach (Vertex v in PZ.vertices)
- {
- v.point.Z = size.Z / 2.0f;
- }
- foreach (Vertex v in MZ.vertices)
- {
- v.point.Z = -size.Z / 2.0f;
- }
-
- foreach (Triangle t in MZ.triangles)
- {
- PhysicsVector n = t.getNormal();
- if (n.Z > 0.0)
- t.invertNormal();
- }
-
- foreach (Triangle t in PZ.triangles)
- {
- PhysicsVector n = t.getNormal();
- if (n.Z < 0.0)
- t.invertNormal();
- }
-
- Mesh result = new Mesh();
- result.Append(MZ);
- result.Append(PZ);
-
- return result;
- }
-
- 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);
-
- result.Append(MeshX);
- result.Append(MeshY);
- result.Append(MeshZ);
-
- return result;
- }
-
-
- public static void CalcNormals(Mesh mesh)
- {
- int iTriangles = mesh.triangles.Count;
-
- mesh.normals = new float[iTriangles*3];
-
- 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;
-
- 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;
-
- // Vectors for edges
- float e1x, e1y, e1z;
- float e2x, e2y, e2z;
-
- e1x = ux - vx;
- e1y = uy - vy;
- e1z = uz - vz;
-
- 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;
-
- // Length
- float l = (float)Math.Sqrt(nx * nx + ny * ny + nz * nz);
-
- // Normalized "normal"
- nx /= l;
- ny /= l;
- nz /= l;
-
- mesh.normals[i] = nx;
- mesh.normals[i + 1] = ny;
- mesh.normals[i + 2] = nz;
-
- i+=3;
- }
- }
-
- public static Mesh CreateMesh(PrimitiveBaseShape primShape, PhysicsVector size)
- {
- Mesh mesh = null;
-
- switch (primShape.ProfileShape)
- {
- case ProfileShape.Square:
- mesh=CreateBoxMesh(primShape, size);
- CalcNormals(mesh);
- break;
- default:
- mesh=null;
- break;
- }
-
- return mesh;
-
- }
- }
-}
-
+using System;
+using System.Globalization;
+using System.Diagnostics;
+using System.Collections.Generic;
+using System.Text;
+using System.Runtime.InteropServices;
+
+using OpenSim.Framework.Types;
+using OpenSim.Region.Physics.Manager;
+
+namespace OpenSim.Region.Physics.OdePlugin
+{
+ public class Mesh
+ {
+ public List vertices;
+ public List triangles;
+
+ public float[] normals;
+
+ public Mesh()
+ {
+ vertices = new List();
+ triangles = new List();
+ }
+
+ public void Add(Triangle triangle)
+ {
+ int i;
+ i = vertices.IndexOf(triangle.v1);
+ if (i < 0)
+ throw new ArgumentException("Vertex v1 not known to mesh");
+ i = vertices.IndexOf(triangle.v2);
+ if (i < 0)
+ throw new ArgumentException("Vertex v2 not known to mesh");
+ i = vertices.IndexOf(triangle.v3);
+ if (i < 0)
+ throw new ArgumentException("Vertex v3 not known to mesh");
+
+ triangles.Add(triangle);
+ }
+
+ public void Add(Vertex v)
+ {
+ vertices.Add(v);
+ }
+
+
+ public float[] getVertexListAsFloat()
+ {
+ 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;
+ }
+ GCHandle.Alloc(result, GCHandleType.Pinned);
+ return result;
+ }
+
+ public int[] getIndexListAsInt()
+ {
+ 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);
+ }
+ GCHandle.Alloc(result, GCHandleType.Pinned);
+ return result;
+ }
+
+
+ public void Append(Mesh newMesh)
+ {
+ foreach (Vertex v in newMesh.vertices)
+ vertices.Add(v);
+
+ foreach (Triangle t in newMesh.triangles)
+ Add(t);
+
+ }
+ }
+
+
+
+ public class Meshmerizer
+ {
+
+ static List FindInfluencedTriangles(List triangles, Vertex v)
+ {
+ List influenced = new List();
+ foreach (Triangle t in triangles)
+ {
+ float dx, dy;
+
+ if (t.isInCircle(v.point.X, v.point.Y))
+ {
+ influenced.Add(t);
+ }
+ }
+ return influenced;
+ }
+
+
+ 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
+ // and replaced by new ones including the new vertex
+ // It is not very time efficient but easy to implement.
+
+ int iCurrentVertex;
+ int iMaxVertex=vertices.Count;
+ for (iCurrentVertex = usedForSeed; iCurrentVertex < iMaxVertex; iCurrentVertex++)
+ {
+ // Background: A triangle mesh fulfills the delaunay condition if (iff!)
+ // each circumlocutory circle (i.e. the circle that touches all three corners)
+ // of each triangle is empty of other vertices.
+ // Obviously a single (seeding) triangle fulfills this condition.
+ // If we now add one vertex, we need to reconstruct all triangles, that
+ // 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);
+
+ List simplices = new List();
+
+ // Reconstruction phase. First step, dissolve each triangle into it's simplices,
+ // i.e. it's "border lines"
+ // Goal is to find "inner" borders and delete them, while the hull gets conserved.
+ // Inner borders are special in the way that they always come twice, which is how we detect them
+ foreach (Triangle t in influencedTriangles)
+ {
+ List newSimplices = t.GetSimplices();
+ simplices.AddRange(newSimplices);
+ triangles.Remove(t);
+ }
+ // Now sort the simplices. That will make identical ones side by side in the list
+ simplices.Sort();
+
+ // Look for duplicate simplices here.
+ // Remember, they are directly side by side in the list right now
+ int iSimplex;
+ 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)
+ {
+ innerSimplices.Add(simplices[iSimplex - 1]);
+ innerSimplices.Add(simplices[iSimplex]);
+ }
+ }
+
+ foreach (Simplex s in innerSimplices)
+ {
+ simplices.Remove(s);
+ }
+
+ // each simplex still in the list belongs to the hull of the region in question
+ // The new vertex (yes, we still deal with verices here :-) ) forms a triangle
+ // With each of these simplices. Build the new triangles and add them to the list
+ foreach (Simplex s in simplices)
+ {
+ Triangle t = new Triangle(s.v1, s.v2, vertices[iCurrentVertex]);
+ triangles.Add(t);
+ }
+ }
+
+ // At this point all vertices should be inserted into the mesh
+ // But the areas, that should be kept free still are filled with triangles
+ // We have to remove them. For this we have a list of indices to vertices.
+ // Each triangle that solemnly constists of vertices from the inner border
+ // are deleted
+
+ List innerTriangles = new List();
+ foreach (Triangle t in triangles)
+ {
+ if (
+ innerBorders.Contains(vertices.IndexOf(t.v1))
+ && innerBorders.Contains(vertices.IndexOf(t.v2))
+ && innerBorders.Contains(vertices.IndexOf(t.v3))
+ )
+ innerTriangles.Add(t);
+ }
+ foreach (Triangle t in innerTriangles)
+ {
+ triangles.Remove(t);
+ }
+ }
+
+
+ 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 Triangle(meshMX.vertices[0], meshMX.vertices[2], meshMX.vertices[1]));
+ meshMX.Add(new Triangle(meshMX.vertices[1], meshMX.vertices[2], meshMX.vertices[3]));
+
+
+ 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 Triangle(meshPX.vertices[0], meshPX.vertices[1], meshPX.vertices[2]));
+ meshPX.Add(new Triangle(meshPX.vertices[2], meshPX.vertices[1], meshPX.vertices[3]));
+
+
+ if (hollowFactor > 0)
+ {
+ 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);
+
+ meshMX.Add(IPP);
+ meshMX.Add(IPM);
+ meshMX.Add(IMP);
+ meshMX.Add(IMM);
+
+ meshMX.Add(new Triangle(IPP, IMP, IPM));
+ meshMX.Add(new Triangle(IPM, IMP, IMM));
+
+ foreach (Triangle t in meshMX.triangles)
+ {
+ PhysicsVector n = t.getNormal();
+ }
+
+
+
+ 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);
+ meshPX.Add(IMP);
+ meshPX.Add(IMM);
+
+ meshPX.Add(new Triangle(IPP, IPM, IMP));
+ meshPX.Add(new Triangle(IMP, IPM, IMM));
+
+ foreach (Triangle t in meshPX.triangles)
+ {
+ PhysicsVector n = t.getNormal();
+ }
+ }
+
+ Mesh result = new Mesh();
+ result.Append(meshMX);
+ result.Append(meshPX);
+
+ return result;
+ }
+
+
+
+ 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 Triangle(MeshMY.vertices[0], MeshMY.vertices[1], MeshMY.vertices[2]));
+ MeshMY.Add(new Triangle(MeshMY.vertices[2], MeshMY.vertices[1], MeshMY.vertices[3]));
+
+ // (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 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;
+
+ 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);
+
+ MeshMY.Add(IPP);
+ MeshMY.Add(IPM);
+ MeshMY.Add(IMP);
+ MeshMY.Add(IMM);
+
+ MeshMY.Add(new Triangle(IPP, IPM, IMP));
+ MeshMY.Add(new Triangle(IMP, IPM, IMM));
+
+ foreach (Triangle t in MeshMY.triangles)
+ {
+ PhysicsVector n = t.getNormal();
+ }
+
+
+
+ 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);
+ MeshPY.Add(IMP);
+ MeshPY.Add(IMM);
+
+ MeshPY.Add(new Triangle(IPM, IPP, IMP));
+ MeshPY.Add(new Triangle(IMP, IMM, IPM));
+
+ foreach (Triangle t in MeshPY.triangles)
+ {
+ PhysicsVector n = t.getNormal();
+ }
+
+
+
+ }
+
+
+ Mesh result = new Mesh();
+ result.Append(MeshMY);
+ result.Append(MeshPY);
+
+ return result;
+ }
+
+ static Mesh CreateBoxMeshZ(PrimitiveBaseShape primShape, PhysicsVector size)
+ // Builds the z (+ and -) surfaces of a box shaped prim
+ {
+ UInt16 hollowFactor = primShape.ProfileHollow;
+
+ // Base, i.e. outer shape
+ // (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 Triangle(MZ.vertices[1], MZ.vertices[0], MZ.vertices[2]));
+ MZ.Add(new Triangle(MZ.vertices[1], MZ.vertices[2], MZ.vertices[3]));
+
+ // (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));
+
+ // Surface 5, +Z
+ PZ.Add(new Triangle(PZ.vertices[0], PZ.vertices[1], PZ.vertices[2]));
+ PZ.Add(new Triangle(PZ.vertices[2], PZ.vertices[1], PZ.vertices[3]));
+
+ if (hollowFactor > 0)
+ {
+ 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));
+
+ List innerBorders = new List();
+ innerBorders.Add(4);
+ innerBorders.Add(5);
+ innerBorders.Add(6);
+ innerBorders.Add(7);
+
+ 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));
+
+ innerBorders = new List();
+ innerBorders.Add(4);
+ innerBorders.Add(5);
+ innerBorders.Add(6);
+ innerBorders.Add(7);
+
+ InsertVertices(PZ.vertices, 4, PZ.triangles, innerBorders);
+
+ }
+
+ foreach (Vertex v in PZ.vertices)
+ {
+ v.point.Z = size.Z / 2.0f;
+ }
+ foreach (Vertex v in MZ.vertices)
+ {
+ v.point.Z = -size.Z / 2.0f;
+ }
+
+ foreach (Triangle t in MZ.triangles)
+ {
+ PhysicsVector n = t.getNormal();
+ if (n.Z > 0.0)
+ t.invertNormal();
+ }
+
+ foreach (Triangle t in PZ.triangles)
+ {
+ PhysicsVector n = t.getNormal();
+ if (n.Z < 0.0)
+ t.invertNormal();
+ }
+
+ Mesh result = new Mesh();
+ result.Append(MZ);
+ result.Append(PZ);
+
+ return result;
+ }
+
+ 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);
+
+ result.Append(MeshX);
+ result.Append(MeshY);
+ result.Append(MeshZ);
+
+ return result;
+ }
+
+
+ public static void CalcNormals(Mesh mesh)
+ {
+ int iTriangles = mesh.triangles.Count;
+
+ mesh.normals = new float[iTriangles*3];
+
+ 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;
+
+ 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;
+
+ // Vectors for edges
+ float e1x, e1y, e1z;
+ float e2x, e2y, e2z;
+
+ e1x = ux - vx;
+ e1y = uy - vy;
+ e1z = uz - vz;
+
+ 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;
+
+ // Length
+ float l = (float)Math.Sqrt(nx * nx + ny * ny + nz * nz);
+
+ // Normalized "normal"
+ nx /= l;
+ ny /= l;
+ nz /= l;
+
+ mesh.normals[i] = nx;
+ mesh.normals[i + 1] = ny;
+ mesh.normals[i + 2] = nz;
+
+ i+=3;
+ }
+ }
+
+ public static Mesh CreateMesh(PrimitiveBaseShape primShape, PhysicsVector size)
+ {
+ Mesh mesh = null;
+
+ switch (primShape.ProfileShape)
+ {
+ case ProfileShape.Square:
+ mesh=CreateBoxMesh(primShape, size);
+ CalcNormals(mesh);
+ break;
+ default:
+ mesh=null;
+ break;
+ }
+
+ return mesh;
+
+ }
+ }
+}
+
--
cgit v1.1
From 23eeeaae0396dab2fe76d274414139fa892b6a3d Mon Sep 17 00:00:00 2001
From: dan miller
Date: Thu, 11 Oct 2007 05:54:56 +0000
Subject: fixes for nebadon"s terrain bugs; includes patched 0.9 ode.dll,
libode.so
---
OpenSim/Region/Physics/OdePlugin/OdePlugin.cs | 53 +++++++++++++++++++++++++--
1 file changed, 49 insertions(+), 4 deletions(-)
(limited to 'OpenSim/Region/Physics/OdePlugin')
diff --git a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
index ac784cf..e9ac642 100644
--- a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
+++ b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
@@ -81,8 +81,9 @@ namespace OpenSim.Region.Physics.OdePlugin
public class OdeScene : PhysicsScene
{
private static float ODE_STEPSIZE = 0.004f;
+ private static bool RENDER_FLAG = false;
private IntPtr contactgroup;
- private IntPtr LandGeom;
+ private IntPtr LandGeom=(IntPtr)0;
private double[] _heightmap;
private d.NearCallback nearCallback;
public d.TriCallback triCallback;
@@ -316,8 +317,23 @@ namespace OpenSim.Region.Physics.OdePlugin
step_time += timeStep;
lock (OdeLock)
{
+ if (_characters.Count > 0 & RENDER_FLAG)
+ {
+ Console.WriteLine("RENDER: frame");
+ }
foreach (OdePrim p in _prims)
{
+ if (_characters.Count > 0 & RENDER_FLAG)
+ {
+ 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);
+ }
}
int i = 0;
while (step_time > 0.0f)
@@ -336,6 +352,29 @@ namespace OpenSim.Region.Physics.OdePlugin
foreach (OdeCharacter actor in _characters)
{
actor.UpdatePositionAndVelocity();
+ if (RENDER_FLAG)
+ {
+ /// debugging code
+ 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);
+ 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
+ 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
+ }
}
}
}
@@ -366,6 +405,10 @@ namespace OpenSim.Region.Physics.OdePlugin
lock (OdeLock)
{
+ if (!(LandGeom == (IntPtr)0))
+ {
+ d.SpaceRemove(space, LandGeom);
+ }
IntPtr HeightmapData = d.GeomHeightfieldDataCreate();
d.GeomHeightfieldDataBuildDouble(HeightmapData, _heightmap, 0, 256, 256, 256, 256, 1.0f, 0.0f, 2.0f, 0);
d.GeomHeightfieldDataSetBounds(HeightmapData, 256, 256);
@@ -407,6 +450,8 @@ namespace OpenSim.Region.Physics.OdePlugin
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;
private bool flying = false;
//private float gravityAccel;
public IntPtr Body;
@@ -423,7 +468,7 @@ namespace OpenSim.Region.Physics.OdePlugin
_parent_scene = parent_scene;
lock (OdeScene.OdeLock)
{
- Shell = d.CreateCapsule(parent_scene.space, 0.4f, 1.0f);
+ Shell = d.CreateCapsule(parent_scene.space, CAPSULE_RADIUS, CAPSULE_LENGTH);
d.MassSetCapsule(out ShellMass, 50.0f, 3, 0.4f, 1.0f);
Body = d.BodyCreate(parent_scene.world);
d.BodySetMass(Body, ref ShellMass);
@@ -628,11 +673,11 @@ namespace OpenSim.Region.Physics.OdePlugin
public class OdePrim : PhysicsActor
{
- private PhysicsVector _position;
+ public PhysicsVector _position;
private PhysicsVector _velocity;
private PhysicsVector _size;
private PhysicsVector _acceleration;
- private Quaternion _orientation;
+ public Quaternion _orientation;
private Mesh _mesh;
private PrimitiveBaseShape _pbs;
private OdeScene _parent_scene;
--
cgit v1.1
From 1232eb1c587ffdc06c26a1c5b1b4fa5f22848754 Mon Sep 17 00:00:00 2001
From: Tleiades Hax
Date: Sat, 13 Oct 2007 07:26:21 +0000
Subject: Asset server implementation. Again one of these "plumbing" releases,
where no real functionality has been introduced, but ground work has been
made, enabling the asset server, and preparing the sim server to query the
asset server.
Introduced an "IPlugin" interface, which plugins can inherit from.
---
OpenSim/Region/Physics/OdePlugin/OdePlugin.cs | 1 -
1 file changed, 1 deletion(-)
(limited to 'OpenSim/Region/Physics/OdePlugin')
diff --git a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
index e9ac642..e0661f8 100644
--- a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
+++ b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
@@ -30,7 +30,6 @@ using System.Threading;
using System.Collections.Generic;
using libsecondlife;
-using libsecondlife.Utilities;
using Axiom.Math;
using Ode.NET;
--
cgit v1.1
From b48390213b4b0f03e6de922a83fcdd648f6c830e Mon Sep 17 00:00:00 2001
From: lbsa71
Date: Mon, 15 Oct 2007 07:25:32 +0000
Subject: * Applied Chillken patch #418: copyright-r2094.patch updating
copyright messages. Thanks Chillken!
---
.../Physics/OdePlugin/Meshing/HelperTypes.cs | 29 ++++++++++++++++++++++
.../Physics/OdePlugin/Meshing/Meshmerizer.cs | 29 ++++++++++++++++++++++
2 files changed, 58 insertions(+)
(limited to 'OpenSim/Region/Physics/OdePlugin')
diff --git a/OpenSim/Region/Physics/OdePlugin/Meshing/HelperTypes.cs b/OpenSim/Region/Physics/OdePlugin/Meshing/HelperTypes.cs
index 3d40c04..2ace097 100644
--- a/OpenSim/Region/Physics/OdePlugin/Meshing/HelperTypes.cs
+++ b/OpenSim/Region/Physics/OdePlugin/Meshing/HelperTypes.cs
@@ -1,3 +1,31 @@
+/*
+* Copyright (c) Contributors, http://opensimulator.org/
+* See CONTRIBUTORS.TXT for a full list of copyright holders.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* * Redistributions in binary form must reproduce the above copyright
+* notice, this list of conditions and the following disclaimer in the
+* documentation and/or other materials provided with the distribution.
+* * Neither the name of the OpenSim Project nor the
+* names of its contributors may be used to endorse or promote products
+* derived from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS AS IS AND ANY
+* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+*/
+
using System;
using System.Globalization;
using System.Diagnostics;
@@ -277,3 +305,4 @@ public class Triangle
}
}
+
diff --git a/OpenSim/Region/Physics/OdePlugin/Meshing/Meshmerizer.cs b/OpenSim/Region/Physics/OdePlugin/Meshing/Meshmerizer.cs
index ce3ba5c..17da483 100644
--- a/OpenSim/Region/Physics/OdePlugin/Meshing/Meshmerizer.cs
+++ b/OpenSim/Region/Physics/OdePlugin/Meshing/Meshmerizer.cs
@@ -1,3 +1,31 @@
+/*
+* Copyright (c) Contributors, http://opensimulator.org/
+* See CONTRIBUTORS.TXT for a full list of copyright holders.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* * Redistributions in binary form must reproduce the above copyright
+* notice, this list of conditions and the following disclaimer in the
+* documentation and/or other materials provided with the distribution.
+* * Neither the name of the OpenSim Project nor the
+* names of its contributors may be used to endorse or promote products
+* derived from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS AS IS AND ANY
+* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+*/
+
using System;
using System.Globalization;
using System.Diagnostics;
@@ -558,3 +586,4 @@ namespace OpenSim.Region.Physics.OdePlugin
}
}
+
--
cgit v1.1
From 7415eb73550089c3d5652b90fd0a710021141a5a Mon Sep 17 00:00:00 2001
From: dan miller
Date: Wed, 17 Oct 2007 05:43:35 +0000
Subject: this might help with ODE errors. Or maybe not. YMMV
---
OpenSim/Region/Physics/OdePlugin/OdePlugin.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'OpenSim/Region/Physics/OdePlugin')
diff --git a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
index e0661f8..c707a87 100644
--- a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
+++ b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
@@ -409,7 +409,7 @@ namespace OpenSim.Region.Physics.OdePlugin
d.SpaceRemove(space, LandGeom);
}
IntPtr HeightmapData = d.GeomHeightfieldDataCreate();
- d.GeomHeightfieldDataBuildDouble(HeightmapData, _heightmap, 0, 256, 256, 256, 256, 1.0f, 0.0f, 2.0f, 0);
+ d.GeomHeightfieldDataBuildDouble(HeightmapData, _heightmap, 0, 256, 256, 256, 256, 1.0f, 0.0f, 2.0f, 1);
d.GeomHeightfieldDataSetBounds(HeightmapData, 256, 256);
LandGeom = d.CreateHeightfield(space, HeightmapData, 1);
this.geom_name_map[LandGeom]="Terrain";
--
cgit v1.1
From c29f8b3873888df9505965399fe0639f13fe8db0 Mon Sep 17 00:00:00 2001
From: dan miller
Date: Mon, 29 Oct 2007 06:15:06 +0000
Subject: should help with ODE bounce on region cross
---
OpenSim/Region/Physics/OdePlugin/OdePlugin.cs | 26 ++++++++++++++++++--------
1 file changed, 18 insertions(+), 8 deletions(-)
(limited to 'OpenSim/Region/Physics/OdePlugin')
diff --git a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
index c707a87..1cf4710 100644
--- a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
+++ b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
@@ -123,7 +123,7 @@ namespace OpenSim.Region.Physics.OdePlugin
d.WorldSetContactMaxCorrectingVel(world, 1000.0f);
}
- _heightmap = new double[65536];
+ _heightmap = new double[258*258];
}
// This function blatantly ripped off from BoxStack.cs
@@ -393,13 +393,23 @@ namespace OpenSim.Region.Physics.OdePlugin
public override void SetTerrain(float[] heightMap)
{
- for (int i = 0; i < 65536; i++)
+ // this._heightmap[i] = (double)heightMap[i];
+ // dbm (danx0r) -- heightmap x,y must be swapped for Ode (should fix ODE, but for now...)
+ // also, creating a buffer zone of one extra sample all around
+ for (int x = 0; x < 258; x++)
{
- // this._heightmap[i] = (double)heightMap[i];
- // dbm (danx0r) -- heightmap x,y must be swapped for Ode (should fix ODE, but for now...)
- int x = i & 0xff;
- int y = i >> 8;
- _heightmap[i] = (double)heightMap[x * 256 + y];
+ for (int y = 0; y < 258; y++)
+ {
+ int xx = x-1;
+ if (xx < 0) xx = 0;
+ if (xx > 255) xx = 255;
+ 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;
+ }
}
lock (OdeLock)
@@ -409,7 +419,7 @@ namespace OpenSim.Region.Physics.OdePlugin
d.SpaceRemove(space, LandGeom);
}
IntPtr HeightmapData = d.GeomHeightfieldDataCreate();
- d.GeomHeightfieldDataBuildDouble(HeightmapData, _heightmap, 0, 256, 256, 256, 256, 1.0f, 0.0f, 2.0f, 1);
+ 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";
--
cgit v1.1
From 3d8219f6c7faa256d6a13ab7925f75d83af95b78 Mon Sep 17 00:00:00 2001
From: MW
Date: Mon, 29 Oct 2007 21:46:25 +0000
Subject: as per the "Filesystem cleanup for OpenSim repository" mailing list
thread. Have flattened the OpenSim.Framework project/namespace. The problem
is that the namespace is still wrong as its "OpenSim.Framework" while the
directory is "OpenSim\Framework\General" , so we need to decide if we change
the directory or correct the namespace. Note this has lead to a big flat
project, but I think a lot of the files we most likely don't even use any
longer. And others belong in other projects/namespaces anyway.
---
OpenSim/Region/Physics/OdePlugin/Meshing/Meshmerizer.cs | 2 +-
OpenSim/Region/Physics/OdePlugin/OdePlugin.cs | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
(limited to 'OpenSim/Region/Physics/OdePlugin')
diff --git a/OpenSim/Region/Physics/OdePlugin/Meshing/Meshmerizer.cs b/OpenSim/Region/Physics/OdePlugin/Meshing/Meshmerizer.cs
index 17da483..dd18e24 100644
--- a/OpenSim/Region/Physics/OdePlugin/Meshing/Meshmerizer.cs
+++ b/OpenSim/Region/Physics/OdePlugin/Meshing/Meshmerizer.cs
@@ -33,7 +33,7 @@ using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
-using OpenSim.Framework.Types;
+using OpenSim.Framework;
using OpenSim.Region.Physics.Manager;
namespace OpenSim.Region.Physics.OdePlugin
diff --git a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
index 1cf4710..a20452f 100644
--- a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
+++ b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
@@ -33,7 +33,7 @@ using libsecondlife;
using Axiom.Math;
using Ode.NET;
-using OpenSim.Framework.Types;
+using OpenSim.Framework;
using OpenSim.Framework.Console;
using OpenSim.Region.Physics.Manager;
--
cgit v1.1
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
From ecb2305a04588a24c738b37121d0d915a6a37b04 Mon Sep 17 00:00:00 2001
From: Jeff Ames
Date: Tue, 30 Oct 2007 09:56:29 +0000
Subject: temporary fix for sitting collisions in ODE
---
OpenSim/Region/Physics/OdePlugin/OdePlugin.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'OpenSim/Region/Physics/OdePlugin')
diff --git a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
index c9af6dd..27c3a6a 100644
--- a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
+++ b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
@@ -503,7 +503,7 @@ namespace OpenSim.Region.Physics.OdePlugin
public override PhysicsVector Size
{
- get { return new PhysicsVector(0, 0, 0); }
+ get { return new PhysicsVector(CAPSULE_RADIUS*2, CAPSULE_RADIUS*2, CAPSULE_LENGTH); }
set { }
}
--
cgit v1.1
From 33d6222e8dc40331e98c3549a040d3d206eed338 Mon Sep 17 00:00:00 2001
From: Charles Krinke
Date: Wed, 31 Oct 2007 04:18:34 +0000
Subject: Thank you Teravus, very much, for a 'jump', 'crouch' and 'inertia'
patch for all three physics plugins.
---
OpenSim/Region/Physics/OdePlugin/OdePlugin.cs | 132 +++++++++++++++++++-------
1 file changed, 98 insertions(+), 34 deletions(-)
(limited to 'OpenSim/Region/Physics/OdePlugin')
diff --git a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
index 27c3a6a..4afe784 100644
--- a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
+++ b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
@@ -83,8 +83,10 @@ namespace OpenSim.Region.Physics.OdePlugin
private List _characters = new List();
private List _prims = new List();
public Dictionary geom_name_map = new Dictionary();
+ public Dictionary actor_name_map = new Dictionary();
private d.ContactGeom[] contacts = new d.ContactGeom[30];
private d.Contact contact;
+ private PhysicsActor PANull = new NullPhysicsActor();
private float step_time = 0.0f;
public IntPtr world;
public IntPtr space;
@@ -117,36 +119,33 @@ namespace OpenSim.Region.Physics.OdePlugin
}
_heightmap = new double[258*258];
+
}
// This function blatantly ripped off from BoxStack.cs
private void near(IntPtr space, IntPtr g1, IntPtr g2)
{
// no lock here! It's invoked from within Simulate(), which is thread-locked
+ IntPtr b1 = d.GeomGetBody(g1);
+ IntPtr b2 = d.GeomGetBody(g2);
+
+
if (g1 == g2)
return; // Can't collide with yourself
+
- IntPtr b1 = d.GeomGetBody(g1);
- IntPtr b2 = d.GeomGetBody(g2);
if (b1 != IntPtr.Zero && b2 != IntPtr.Zero && d.AreConnectedExcluding(b1, b2, d.JointType.Contact))
return;
+
d.GeomClassID id = d.GeomGetClass(g1);
if (id == d.GeomClassID.TriMeshClass)
{
- String name1 = null;
- String name2 = null;
- if (!geom_name_map.TryGetValue(g1, out name1))
- {
- name1 = "null";
- }
- if (!geom_name_map.TryGetValue(g2, out name2))
- {
- name2 = "null";
- }
+
-// MainLog.Instance.Verbose("near: A collision was detected between {1} and {2}", 0, name1, name2);
+// MainLog.Instance.Verbose("near: A collision was detected between {1} and {2}", 0, name1, name2);
+ //System.Console.WriteLine("near: A collision was detected between {1} and {2}", 0, name1, name2);
}
int count = d.Collide(g1, g2, contacts.GetLength(0), contacts, d.ContactGeom.SizeOf);
@@ -155,6 +154,22 @@ namespace OpenSim.Region.Physics.OdePlugin
contact.geom = contacts[i];
IntPtr joint = d.JointCreateContact(world, contactgroup, ref contact);
d.JointAttach(joint, b1, b2);
+ PhysicsActor p1;
+ PhysicsActor p2;
+
+
+ if (!actor_name_map.TryGetValue(g1, out p1))
+ {
+ p1 = PANull;
+ }
+ if (!actor_name_map.TryGetValue(g2, out p2))
+ {
+ p2 = PANull;
+ }
+
+ p1.IsColliding = true;
+ p2.IsColliding = true;
+ //System.Console.WriteLine("near: A collision was detected between {1} and {2}", 0, name1, name2);
}
}
@@ -162,10 +177,19 @@ namespace OpenSim.Region.Physics.OdePlugin
{
foreach (OdeCharacter chr in _characters)
{
+ chr.IsColliding = false;
+ }
+ 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
- {
+ {
+
+
d.SpaceCollide2(chr.Shell, ch2.Shell, IntPtr.Zero, nearCallback);
}
}
@@ -333,8 +357,9 @@ namespace OpenSim.Region.Physics.OdePlugin
{
foreach (OdeCharacter actor in _characters)
{
- actor.Move(timeStep);
+ actor.Move(timeStep);
}
+
collision_optimized();
d.WorldQuickStep(world, ODE_STEPSIZE);
d.JointGroupEmpty(contactgroup);
@@ -457,6 +482,8 @@ namespace OpenSim.Region.Physics.OdePlugin
public static float CAPSULE_RADIUS = 0.5f;
public static float CAPSULE_LENGTH = 0.9f;
private bool flying = false;
+ private bool iscolliding = false;
+ private bool jumping = false;
//private float gravityAccel;
public IntPtr Body;
private OdeScene _parent_scene;
@@ -480,6 +507,7 @@ namespace OpenSim.Region.Physics.OdePlugin
d.GeomSetBody(Shell, Body);
}
parent_scene.geom_name_map[Shell] = avName;
+ parent_scene.actor_name_map[Shell] = (PhysicsActor)this;
}
public override bool Flying
@@ -487,7 +515,12 @@ namespace OpenSim.Region.Physics.OdePlugin
get { return flying; }
set { flying = value; }
}
-
+ public override bool IsColliding
+ {
+ get { return iscolliding; }
+ set
+ {iscolliding = value;}
+ }
public override PhysicsVector Position
{
get { return _position; }
@@ -538,12 +571,35 @@ namespace OpenSim.Region.Physics.OdePlugin
public override void AddForce(PhysicsVector force)
{
+
+ _target_velocity.X += force.X;
+ _target_velocity.Y += force.Y;
+ _target_velocity.Z += force.Z;
+
+
}
+ public void doForce(PhysicsVector force)
+ {
+ d.BodyAddForce(Body, force.X, force.Y, force.Z);
+
+ // ok -- let's stand up straight!
+ d.Vector3 feet;
+ d.Vector3 head;
+ d.BodyGetRelPointPos(Body, 0.0f, 0.0f, -1.0f, out feet);
+ d.BodyGetRelPointPos(Body, 0.0f, 0.0f, 1.0f, out head);
+ float posture = head.Z - feet.Z;
+ // restoring force proportional to lack of posture:
+ 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);
+
+ }
public override void SetMomentum(PhysicsVector momentum)
{
- }
+ }
+
public void Move(float timeStep)
{
// no lock; for now it's only called from within Simulate()
@@ -551,7 +607,7 @@ namespace OpenSim.Region.Physics.OdePlugin
d.Vector3 vel = d.BodyGetLinearVel(Body);
// if velocity is zero, use position control; otherwise, velocity control
- if (_target_velocity.X == 0.0f & _target_velocity.Y == 0.0f & _target_velocity.Z == 0.0f)
+ if (_target_velocity.X == 0.0f & _target_velocity.Y == 0.0f & _target_velocity.Z == 0.0f & iscolliding)
{
// keep track of where we stopped. No more slippin' & slidin'
if (!_zeroFlag)
@@ -569,9 +625,19 @@ namespace OpenSim.Region.Physics.OdePlugin
}
else
{
+
_zeroFlag = false;
- vec.X = (_target_velocity.X - vel.X)*PID_D;
- vec.Y = (_target_velocity.Y - vel.Y)*PID_D;
+ if (iscolliding || flying)
+ {
+ vec.X = (_target_velocity.X - vel.X) * PID_D;
+ vec.Y = (_target_velocity.Y - vel.Y) * PID_D;
+ }
+ if (iscolliding && !flying && _target_velocity.Z > 0.0f)
+ {
+ d.Vector3 pos = d.BodyGetPosition(Body);
+ vec.Z = (_target_velocity.Z - vel.Z) * PID_D + (_zeroPosition.Z - pos.Z) * PID_P;
+ }
+
if (flying)
{
vec.Z = (_target_velocity.Z - vel.Z)*PID_D;
@@ -581,19 +647,7 @@ namespace OpenSim.Region.Physics.OdePlugin
{
vec.Z += 10.0f;
}
- d.BodyAddForce(Body, vec.X, vec.Y, vec.Z);
-
- // ok -- let's stand up straight!
- d.Vector3 feet;
- d.Vector3 head;
- d.BodyGetRelPointPos(Body, 0.0f, 0.0f, -1.0f, out feet);
- d.BodyGetRelPointPos(Body, 0.0f, 0.0f, 1.0f, out head);
- float posture = head.Z - feet.Z;
-
- // restoring force proportional to lack of posture:
- 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);
+ doForce(vec);
}
public void UpdatePositionAndVelocity()
@@ -649,6 +703,7 @@ namespace OpenSim.Region.Physics.OdePlugin
private OdeScene _parent_scene;
public IntPtr prim_geom;
public IntPtr _triMeshData;
+ private bool iscolliding = false;
public OdePrim(String primName, OdeScene parent_scene, PhysicsVector pos, PhysicsVector size,
Quaternion rotation, Mesh mesh, PrimitiveBaseShape pbs)
@@ -661,6 +716,7 @@ namespace OpenSim.Region.Physics.OdePlugin
_mesh = mesh;
_pbs = pbs;
_parent_scene = parent_scene;
+
lock (OdeScene.OdeLock)
{
@@ -681,6 +737,7 @@ namespace OpenSim.Region.Physics.OdePlugin
myrot.Z = rotation.z;
d.GeomSetQuaternion(prim_geom, ref myrot);
parent_scene.geom_name_map[prim_geom] = primName;
+ parent_scene.actor_name_map[prim_geom] = (PhysicsActor) this;
// don't do .add() here; old geoms get recycled with the same hash
}
}
@@ -708,6 +765,13 @@ namespace OpenSim.Region.Physics.OdePlugin
set { }
}
+ public override bool IsColliding
+ {
+ get { return iscolliding; }
+ set { iscolliding = value; }
+ }
+
+
public override PhysicsVector Position
{
get { return _position; }
@@ -793,4 +857,4 @@ namespace OpenSim.Region.Physics.OdePlugin
{
}
}
-}
\ No newline at end of file
+}
--
cgit v1.1
From 7f0d836d35e579632413e1b06d5f5e6e6981ca05 Mon Sep 17 00:00:00 2001
From: Jeff Ames
Date: Wed, 31 Oct 2007 05:29:51 +0000
Subject: made illogical bitwise operations logical
---
OpenSim/Region/Physics/OdePlugin/OdePlugin.cs | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
(limited to 'OpenSim/Region/Physics/OdePlugin')
diff --git a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
index 4afe784..82b94db 100644
--- a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
+++ b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
@@ -333,13 +333,13 @@ namespace OpenSim.Region.Physics.OdePlugin
step_time += timeStep;
lock (OdeLock)
{
- if (_characters.Count > 0 & RENDER_FLAG)
+ if (_characters.Count > 0 && RENDER_FLAG)
{
Console.WriteLine("RENDER: frame");
}
foreach (OdePrim p in _prims)
{
- if (_characters.Count > 0 & RENDER_FLAG)
+ if (_characters.Count > 0 && RENDER_FLAG)
{
Vector3 rx, ry, rz;
p.Orientation.ToAxes(out rx, out ry, out rz);
@@ -607,7 +607,7 @@ namespace OpenSim.Region.Physics.OdePlugin
d.Vector3 vel = d.BodyGetLinearVel(Body);
// if velocity is zero, use position control; otherwise, velocity control
- if (_target_velocity.X == 0.0f & _target_velocity.Y == 0.0f & _target_velocity.Z == 0.0f & iscolliding)
+ if (_target_velocity.X == 0.0f && _target_velocity.Y == 0.0f && _target_velocity.Z == 0.0f && iscolliding)
{
// keep track of where we stopped. No more slippin' & slidin'
if (!_zeroFlag)
--
cgit v1.1
From f8e0cf0f1de3cabded7bce2e438cc37ce4bb989c Mon Sep 17 00:00:00 2001
From: darok
Date: Sat, 3 Nov 2007 10:25:43 +0000
Subject: Changes in BulletXPlugin: Added new class BulletXActor class inherits
from PhysicsActor and it's the ancestor for BulletXCharacter and
BulletXPrim.Physical modifications: Changes for pass the value of Physical
flag in the SceneObjectPart class to the Physics engines. New call for
AddPrimShape so it has a new parameter called "isPhysical". The old call will
be obselete soon (i believe). PhysActor and its descendants have a new
property called IsPhysical. By the way no new special funcionallity added.
It's more like preparing the way for new modifications.
---
OpenSim/Region/Physics/OdePlugin/OdePlugin.cs | 19 ++++++++++++++++++-
1 file changed, 18 insertions(+), 1 deletion(-)
(limited to 'OpenSim/Region/Physics/OdePlugin')
diff --git a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
index 82b94db..f1db034 100644
--- a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
+++ b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
@@ -300,7 +300,12 @@ namespace OpenSim.Region.Physics.OdePlugin
public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, PhysicsVector position,
- PhysicsVector size, Quaternion rotation)
+ PhysicsVector size, Quaternion rotation) //To be removed
+ {
+ return this.AddPrimShape(primName, pbs, position, size, rotation, false);
+ }
+ public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, PhysicsVector position,
+ PhysicsVector size, Quaternion rotation, bool isPhysical)
{
PhysicsActor result;
@@ -510,6 +515,12 @@ namespace OpenSim.Region.Physics.OdePlugin
parent_scene.actor_name_map[Shell] = (PhysicsActor)this;
}
+ public override bool IsPhysical
+ {
+ get { return false; }
+ set { return; }
+ }
+
public override bool Flying
{
get { return flying; }
@@ -758,6 +769,12 @@ namespace OpenSim.Region.Physics.OdePlugin
prim_geom = d.CreateTriMesh(parent_scene.space, _triMeshData, parent_scene.triCallback, null, null);
}
+ public override bool IsPhysical
+ {
+ get { return false; }
+ set { return; }
+ }
+
public override bool Flying
{
get { return false; //no flying prims for you
--
cgit v1.1
From fdb57b28b164f239de0f976b967b79dc2ca5f6ae Mon Sep 17 00:00:00 2001
From: dan miller
Date: Mon, 5 Nov 2007 12:25:53 +0000
Subject: prim cuts in ODE Much thanks to Gerhard! Merged with Darok's recent
changes re: physical prims
---
.../Physics/OdePlugin/Meshing/HelperTypes.cs | 158 ++++---
.../Physics/OdePlugin/Meshing/Meshmerizer.cs | 514 +++++++--------------
OpenSim/Region/Physics/OdePlugin/OdePlugin.cs | 121 +++--
3 files changed, 333 insertions(+), 460 deletions(-)
(limited to 'OpenSim/Region/Physics/OdePlugin')
diff --git a/OpenSim/Region/Physics/OdePlugin/Meshing/HelperTypes.cs b/OpenSim/Region/Physics/OdePlugin/Meshing/HelperTypes.cs
index 13184e2..3b20af7 100644
--- a/OpenSim/Region/Physics/OdePlugin/Meshing/HelperTypes.cs
+++ b/OpenSim/Region/Physics/OdePlugin/Meshing/HelperTypes.cs
@@ -30,37 +30,63 @@ using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
+using OpenSim.Framework.Console;
using OpenSim.Region.Physics.Manager;
-public class Vertex : IComparable
+using OpenSim.Region.Physics.OdePlugin.Meshing;
+
+public class Vertex : PhysicsVector, IComparable
{
- public String name;
- public PhysicsVector point;
+ public Vertex(float x, float y, float z)
+ : base(x, y, z)
+ {
+ }
+
+ public Vertex(PhysicsVector v)
+ : base(v.X, v.Y, v.Z)
+ {
+ }
+
+ public Vertex Clone()
+ {
+ return new Vertex(X, Y, Z);
+ }
+
+ public static Vertex FromAngle(double angle)
+ {
+ return new Vertex((float)Math.Cos(angle), (float)Math.Sin(angle), 0.0f);
+ }
+
- public Vertex(String name, float x, float y, float z)
+ public virtual bool Equals(Vertex v, float tolerance)
{
- this.name = name;
- point = new PhysicsVector(x, y, z);
+ PhysicsVector diff = this - v;
+ float d = diff.length();
+ if (d < tolerance)
+ return true;
+
+ return false;
}
+
public int CompareTo(Vertex other)
{
- if (point.X < other.point.X)
+ if (X < other.X)
return -1;
- if (point.X > other.point.X)
+ if (X > other.X)
return 1;
- if (point.Y < other.point.Y)
+ if (Y < other.Y)
return -1;
- if (point.Y > other.point.Y)
+ if (Y > other.Y)
return 1;
- if (point.Z < other.point.Z)
+ if (Z < other.Z)
return -1;
- if (point.Z > other.point.Z)
+ if (Z > other.Z)
return 1;
return 0;
@@ -75,51 +101,24 @@ public class Vertex : IComparable
{
return me.CompareTo(other) < 0;
}
-}
-
-public class Simplex : IComparable
-{
- public Vertex v1;
- public Vertex v2;
-
- public Simplex(Vertex _v1, Vertex _v2)
- {
- // Presort indices to make sorting (comparing) easier
- if (_v1 > _v2)
- {
- v1 = _v1;
- v2 = _v2;
- }
- else
- {
- v1 = _v2;
- v2 = _v1;
- }
- }
-
- public int CompareTo(Simplex other)
+ public String ToRaw()
{
- if (v1 > other.v1)
- {
- return 1;
- }
- if (v1 < other.v1)
- {
- return -1;
- }
+ // Why this stuff with the number formatter?
+ // Well, the raw format uses the english/US notation of numbers
+ // where the "," separates groups of 1000 while the "." marks the border between 1 and 10E-1.
+ // The german notation uses these characters exactly vice versa!
+ // The Float.ToString() routine is a localized one, giving different results depending on the country
+ // settings your machine works with. Unusable for a machine readable file format :-(
+ NumberFormatInfo nfi = new NumberFormatInfo();
+ nfi.NumberDecimalSeparator = ".";
+ nfi.NumberDecimalDigits = 3;
- if (v2 > other.v2)
- {
- return 1;
- }
- if (v2 < other.v2)
- {
- return -1;
- }
+ String s1 = X.ToString("N2", nfi) + " " + Y.ToString("N2", nfi) + " " + Z.ToString("N2", nfi);
- return 0;
+ return s1;
}
-} ;
+
+}
public class Triangle
{
@@ -155,6 +154,12 @@ public class Triangle
return false;
}
+ public bool isDegraded()
+ {
+ // This means, the vertices of this triangle are somewhat strange.
+ // They either line up or at least two of them are identical
+ return (radius_square == 0.0);
+ }
private void CalcCircle()
{
@@ -184,14 +189,14 @@ public class Triangle
double rx, ry;
// Readout the three points, the triangle consists of
- p1x = v1.point.X;
- p1y = v1.point.Y;
+ p1x = v1.X;
+ p1y = v1.Y;
- p2x = v2.point.X;
- p2y = v2.point.Y;
+ p2x = v2.X;
+ p2y = v2.Y;
- p3x = v3.point.X;
- p3y = v3.point.Y;
+ p3x = v3.X;
+ p3y = v3.Y;
/* calc helping values first */
c1 = (p1x*p1x + p1y*p1y - p2x*p2x - p2y*p2y)/2;
@@ -253,12 +258,9 @@ public class Triangle
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.X.ToString(nfi) + "," + v1.Y.ToString(nfi) + "," + v1.Z.ToString(nfi) + ">";
+ String s2 = "<" + v2.X.ToString(nfi) + "," + v2.Y.ToString(nfi) + "," + v2.Z.ToString(nfi) + ">";
+ String s3 = "<" + v3.X.ToString(nfi) + "," + v3.Y.ToString(nfi) + "," + v3.Z.ToString(nfi) + ">";
return s1 + ";" + s2 + ";" + s3;
}
@@ -271,23 +273,17 @@ public class Triangle
PhysicsVector e1;
PhysicsVector e2;
- e1 = new PhysicsVector(v1.point.X - v2.point.X, v1.point.Y - v2.point.Y, v1.point.Z - v2.point.Z);
- e2 = new PhysicsVector(v1.point.X - v3.point.X, v1.point.Y - v3.point.Y, v1.point.Z - v3.point.Z);
+ e1 = new PhysicsVector(v1.X - v2.X, v1.Y - v2.Y, v1.Z - v2.Z);
+ e2 = new PhysicsVector(v1.X - v3.X, v1.Y - v3.Y, v1.Z - v3.Z);
// 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;
+ PhysicsVector n = PhysicsVector.cross(e1, e2);
// Length
- float l = (float) Math.Sqrt(n.X*n.X + n.Y*n.Y + n.Z*n.Z);
+ float l = n.length();
// Normalized "normal"
- n.X /= l;
- n.Y /= l;
- n.Z /= l;
+ n = n / l;
return n;
}
@@ -299,4 +295,12 @@ public class Triangle
v1 = v2;
v2 = vt;
}
-}
\ No newline at end of file
+
+ // Dumps a triangle in the "raw faces" format, blender can import. This is for visualisation and
+ // debugging purposes
+ public String ToStringRaw()
+ {
+ String output = v1.ToRaw() + " " + v2.ToRaw() + " " +v3.ToRaw();
+ return output;
+ }
+}
diff --git a/OpenSim/Region/Physics/OdePlugin/Meshing/Meshmerizer.cs b/OpenSim/Region/Physics/OdePlugin/Meshing/Meshmerizer.cs
index 46de15e..2a304cb 100644
--- a/OpenSim/Region/Physics/OdePlugin/Meshing/Meshmerizer.cs
+++ b/OpenSim/Region/Physics/OdePlugin/Meshing/Meshmerizer.cs
@@ -27,109 +27,70 @@
*/
using System;
+using System.IO;
+using System.Globalization;
+using System.Diagnostics;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using OpenSim.Framework;
+using OpenSim.Framework.Console;
using OpenSim.Region.Physics.Manager;
-namespace OpenSim.Region.Physics.OdePlugin
+namespace OpenSim.Region.Physics.OdePlugin.Meshing
{
- public class Mesh
- {
- public List vertices;
- public List triangles;
-
- public float[] normals;
-
- public Mesh()
- {
- vertices = new List();
- triangles = new List();
- }
-
- public void Add(Triangle triangle)
- {
- int i;
- i = vertices.IndexOf(triangle.v1);
- if (i < 0)
- throw new ArgumentException("Vertex v1 not known to mesh");
- i = vertices.IndexOf(triangle.v2);
- if (i < 0)
- throw new ArgumentException("Vertex v2 not known to mesh");
- i = vertices.IndexOf(triangle.v3);
- if (i < 0)
- throw new ArgumentException("Vertex v3 not known to mesh");
-
- triangles.Add(triangle);
- }
-
- public void Add(Vertex v)
- {
- vertices.Add(v);
- }
-
-
- public float[] getVertexListAsFloat()
- {
- 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;
- }
- GCHandle.Alloc(result, GCHandleType.Pinned);
- return result;
- }
- public int[] getIndexListAsInt()
- {
- int[] result = new int[triangles.Count*3];
- for (int i = 0; i < triangles.Count; i++)
+ public class Meshmerizer
+ {
+ // Setting baseDir to a path will enable the dumping of raw files
+ // raw files can be imported by blender so a visual inspection of the results can be done
+ // const string baseDir = "rawFiles";
+ const string baseDir = null;
+
+ static void IntersectionParameterPD(PhysicsVector p1, PhysicsVector r1, PhysicsVector p2, PhysicsVector r2, ref float lambda, ref float mu)
+ {
+ // p1, p2, points on the straight
+ // r1, r2, directional vectors of the straight. Not necessarily of length 1!
+ // note, that l, m can be scaled such, that the range 0..1 is mapped to the area between two points,
+ // thus allowing to decide whether an intersection is between two points
+
+ float r1x = r1.X;
+ float r1y = r1.Y;
+ float r2x = r2.X;
+ float r2y = r2.Y;
+
+ float denom = r1y*r2x - r1x*r2y;
+
+ if (denom == 0.0)
{
- 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);
+ lambda = Single.NaN;
+ mu = Single.NaN;
+ return;
}
- GCHandle.Alloc(result, GCHandleType.Pinned);
- return result;
- }
-
- public void Append(Mesh newMesh)
- {
- foreach (Vertex v in newMesh.vertices)
- vertices.Add(v);
-
- foreach (Triangle t in newMesh.triangles)
- Add(t);
+ float p1x = p1.X;
+ float p1y = p1.Y;
+ float p2x = p2.X;
+ float p2y = p2.Y;
+ lambda = (-p2x * r2y + p1x * r2y + (p2y - p1y) * r2x) / denom;
+ mu = (-p2x * r1y + p1x * r1y + (p2y - p1y) * r1x) / denom;
+
}
- }
-
- public class Meshmerizer
- {
private static List FindInfluencedTriangles(List triangles, Vertex v)
{
List influenced = new List();
foreach (Triangle t in triangles)
{
- float dx, dy;
-
- if (t.isInCircle(v.point.X, v.point.Y))
+ if (t.isInCircle(v.X, v.Y))
{
influenced.Add(t);
}
}
return influenced;
}
-
-
- private static void InsertVertices(List vertices, int usedForSeed, List triangles,
- List innerBorders)
+
+
+ private static void InsertVertices(List vertices, int usedForSeed, List triangles)
{
// This is a variant of the delaunay algorithm
// each time a new vertex is inserted, all triangles that are influenced by it are deleted
@@ -148,8 +109,10 @@ 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];
+ if (v == null)
+ continue; // Null is polygon stop marker. Ignore it
+ List influencedTriangles=FindInfluencedTriangles(triangles, v);
List simplices = new List();
@@ -163,11 +126,12 @@ namespace OpenSim.Region.Physics.OdePlugin
simplices.AddRange(newSimplices);
triangles.Remove(t);
}
- // Now sort the simplices. That will make identical ones side by side in the list
+ // Now sort the simplices. That will make identical ones reside side by side in the list
simplices.Sort();
// Look for duplicate simplices here.
- // Remember, they are directly side by side in the list right now
+ // Remember, they are directly side by side in the list right now,
+ // So we only check directly neighbours
int iSimplex;
List innerSimplices = new List();
for (iSimplex = 1; iSimplex < simplices.Count; iSimplex++) // Startindex=1, so we can refer backwards
@@ -186,310 +150,145 @@ namespace OpenSim.Region.Physics.OdePlugin
// each simplex still in the list belongs to the hull of the region in question
// The new vertex (yes, we still deal with verices here :-) ) forms a triangle
- // With each of these simplices. Build the new triangles and add them to the list
+ // with each of these simplices. Build the new triangles and add them to the list
foreach (Simplex s in simplices)
{
Triangle t = new Triangle(s.v1, s.v2, vertices[iCurrentVertex]);
- triangles.Add(t);
+ if (!t.isDegraded())
+ {
+ triangles.Add(t);
+ }
}
}
- // At this point all vertices should be inserted into the mesh
- // But the areas, that should be kept free still are filled with triangles
- // We have to remove them. For this we have a list of indices to vertices.
- // Each triangle that solemnly constists of vertices from the inner border
- // are deleted
-
- List innerTriangles = new List();
- foreach (Triangle t in triangles)
- {
- if (
- innerBorders.Contains(vertices.IndexOf(t.v1))
- && innerBorders.Contains(vertices.IndexOf(t.v2))
- && innerBorders.Contains(vertices.IndexOf(t.v3))
- )
- innerTriangles.Add(t);
- }
- foreach (Triangle t in innerTriangles)
- {
- triangles.Remove(t);
- }
}
-
- private static Mesh CreateBoxMeshX(PrimitiveBaseShape primShape, PhysicsVector size)
- // Builds the x (+ and -) surfaces of a box shaped prim
+
+ static Mesh CreateBoxMesh(String primName, PrimitiveBaseShape primShape, PhysicsVector size)
+ // Builds the z (+ 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 Triangle(meshMX.vertices[0], meshMX.vertices[2], meshMX.vertices[1]));
- meshMX.Add(new Triangle(meshMX.vertices[1], meshMX.vertices[2], meshMX.vertices[3]));
-
-
- 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 Triangle(meshPX.vertices[0], meshPX.vertices[1], meshPX.vertices[2]));
- meshPX.Add(new Triangle(meshPX.vertices[2], meshPX.vertices[1], meshPX.vertices[3]));
-
-
- if (hollowFactor > 0)
+ UInt16 profileBegin = primShape.ProfileBegin;
+ UInt16 profileEnd = primShape.ProfileEnd;
+
+ // Procedure: This is based on the fact that the upper (plus) and lower (minus) Z-surface
+ // of a block are basically the same
+ // They may be warped differently but the shape is identical
+ // So we only create one surface as a model and derive both plus and minus surface of the block from it
+ // This is done in a model space where the block spans from -.5 to +.5 in X and Y
+ // The mapping to Scene space is done later during the "extrusion" phase
+
+ // Base
+ Vertex MM = new Vertex(-0.5f, -0.5f, 0.0f);
+ Vertex PM = new Vertex(+0.5f, -0.5f, 0.0f);
+ Vertex MP = new Vertex(-0.5f, +0.5f, 0.0f);
+ Vertex PP = new Vertex(+0.5f, +0.5f, 0.0f);
+
+ Meshing.SimpleHull outerHull = new SimpleHull();
+ outerHull.AddVertex(MM);
+ outerHull.AddVertex(PM);
+ outerHull.AddVertex(PP);
+ outerHull.AddVertex(MP);
+
+ // Deal with cuts now
+ if ((profileBegin != 0) || (profileEnd != 0))
{
- 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);
-
- meshMX.Add(IPP);
- meshMX.Add(IPM);
- meshMX.Add(IMP);
- meshMX.Add(IMM);
-
- meshMX.Add(new Triangle(IPP, IMP, IPM));
- meshMX.Add(new Triangle(IPM, IMP, IMM));
-
- foreach (Triangle t in meshMX.triangles)
- {
- PhysicsVector n = t.getNormal();
+ double fProfileBeginAngle = profileBegin / 50000.0 * 360.0; // In degree, for easier debugging and understanding
+ fProfileBeginAngle -= (90.0 + 45.0); // for some reasons, the SL client counts from the corner -X/-Y
+ double fProfileEndAngle = 360.0 - profileEnd / 50000.0 * 360.0; // Pathend comes as complement to 1.0
+ fProfileEndAngle -= (90.0 + 45.0);
+ if (fProfileBeginAngle < fProfileEndAngle)
+ fProfileEndAngle -= 360.0;
+
+ // Note, that we don't want to cut out a triangle, even if this is a
+ // good approximation for small cuts. Indeed we want to cut out an arc
+ // and we approximate this arc by a polygon chain
+ // Also note, that these vectors are of length 1.0 and thus their endpoints lay outside the model space
+ // So it can easily be subtracted from the outer hull
+ int iSteps = (int)(((fProfileBeginAngle - fProfileEndAngle) / 45.0) + .5); // how many steps do we need with approximately 45 degree
+ double dStepWidth=(fProfileBeginAngle-fProfileEndAngle)/iSteps;
+
+ Vertex origin = new Vertex(0.0f, 0.0f, 0.0f);
+
+ // Note the sequence of vertices here. It's important to have the other rotational sense than in outerHull
+ SimpleHull cutHull = new SimpleHull();
+ cutHull.AddVertex(origin);
+ for (int i=0; i 0)
{
float hollowFactorF = (float) hollowFactor/(float) 50000;
+ Vertex IMM = new Vertex(-0.5f * hollowFactorF, -0.5f * hollowFactorF, 0.0f);
+ Vertex IPM = new Vertex(+0.5f * hollowFactorF, -0.5f * hollowFactorF, 0.0f);
+ Vertex IMP = new Vertex(-0.5f * hollowFactorF, +0.5f * hollowFactorF, 0.0f);
+ Vertex IPP = new Vertex(+0.5f * hollowFactorF, +0.5f * hollowFactorF, 0.0f);
- Vertex IPP;
- Vertex IPM;
- Vertex IMP;
- Vertex IMM;
+ SimpleHull holeHull = new SimpleHull();
- 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);
+ holeHull.AddVertex(IMM);
+ holeHull.AddVertex(IMP);
+ holeHull.AddVertex(IPP);
+ holeHull.AddVertex(IPM);
- MeshMY.Add(IPP);
- MeshMY.Add(IPM);
- MeshMY.Add(IMP);
- MeshMY.Add(IMM);
+ SimpleHull hollowedHull = SimpleHull.SubtractHull(outerHull, holeHull);
- MeshMY.Add(new Triangle(IPP, IPM, IMP));
- MeshMY.Add(new Triangle(IMP, IPM, IMM));
+ outerHull = hollowedHull;
- foreach (Triangle t in MeshMY.triangles)
- {
- PhysicsVector n = t.getNormal();
- }
-
-
- 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);
- MeshPY.Add(IMP);
- MeshPY.Add(IMM);
-
- MeshPY.Add(new Triangle(IPM, IPP, IMP));
- MeshPY.Add(new Triangle(IMP, IMM, IPM));
-
- foreach (Triangle t in MeshPY.triangles)
- {
- PhysicsVector n = t.getNormal();
- }
}
+ Mesh m = new Mesh();
- Mesh result = new Mesh();
- result.Append(MeshMY);
- result.Append(MeshPY);
-
- return result;
- }
-
- private static Mesh CreateBoxMeshZ(PrimitiveBaseShape primShape, PhysicsVector size)
- // Builds the z (+ and -) surfaces of a box shaped prim
- {
- UInt16 hollowFactor = primShape.ProfileHollow;
-
- // Base, i.e. outer shape
- // (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));
+ Vertex Seed1 = new Vertex(0.0f, -10.0f, 0.0f);
+ Vertex Seed2 = new Vertex(-10.0f, 10.0f, 0.0f);
+ Vertex Seed3 = new Vertex(10.0f, 10.0f, 0.0f);
+ m.Add(Seed1);
+ m.Add(Seed2);
+ m.Add(Seed3);
- MZ.Add(new Triangle(MZ.vertices[1], MZ.vertices[0], MZ.vertices[2]));
- MZ.Add(new Triangle(MZ.vertices[1], MZ.vertices[2], MZ.vertices[3]));
+ m.Add(new Triangle(Seed1, Seed2, Seed3));
+ m.Add(outerHull.getVertices());
- // (P)lus Z
- Mesh PZ = new Mesh();
+ InsertVertices(m.vertices, 3, m.triangles);
+ m.DumpRaw(baseDir, primName, "Proto first 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));
+ m.Remove(Seed1);
+ m.Remove(Seed2);
+ m.Remove(Seed3);
+ m.DumpRaw(baseDir, primName, "Proto seeds removed");
+
+ m.RemoveTrianglesOutside(outerHull);
+ m.DumpRaw(baseDir, primName, "Proto outsides removed");
- // Surface 5, +Z
- PZ.Add(new Triangle(PZ.vertices[0], PZ.vertices[1], PZ.vertices[2]));
- PZ.Add(new Triangle(PZ.vertices[2], PZ.vertices[1], PZ.vertices[3]));
-
- if (hollowFactor > 0)
- {
- 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));
-
- List innerBorders = new List();
- innerBorders.Add(4);
- innerBorders.Add(5);
- innerBorders.Add(6);
- innerBorders.Add(7);
-
- 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));
-
- innerBorders = new List();
- innerBorders.Add(4);
- innerBorders.Add(5);
- innerBorders.Add(6);
- innerBorders.Add(7);
-
- InsertVertices(PZ.vertices, 4, PZ.triangles, innerBorders);
- }
-
- foreach (Vertex v in PZ.vertices)
- {
- v.point.Z = size.Z/2.0f;
- }
- foreach (Vertex v in MZ.vertices)
- {
- v.point.Z = -size.Z/2.0f;
- }
-
- foreach (Triangle t in MZ.triangles)
- {
- PhysicsVector n = t.getNormal();
- if (n.Z > 0.0)
- t.invertNormal();
- }
-
- foreach (Triangle t in PZ.triangles)
+ foreach (Triangle t in m.triangles)
{
PhysicsVector n = t.getNormal();
if (n.Z < 0.0)
t.invertNormal();
}
- Mesh result = new Mesh();
- result.Append(MZ);
- result.Append(PZ);
+ Extruder extr = new Extruder();
- return result;
- }
-
- private static Mesh CreateBoxMesh(PrimitiveBaseShape primShape, PhysicsVector size)
- {
- Mesh result = new Mesh();
-
-
- Mesh MeshX = CreateBoxMeshX(primShape, size);
- Mesh MeshY = CreateBoxMeshY(primShape, size);
- Mesh MeshZ = CreateBoxMeshZ(primShape, size);
-
- result.Append(MeshX);
- result.Append(MeshY);
- result.Append(MeshZ);
+ extr.size = size;
+ Mesh result = extr.Extrude(m);
+ result.DumpRaw(baseDir, primName, "Z extruded");
return result;
}
-
public static void CalcNormals(Mesh mesh)
{
int iTriangles = mesh.triangles.Count;
@@ -503,17 +302,18 @@ namespace OpenSim.Region.Physics.OdePlugin
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.X;
+ uy = t.v1.Y;
+ uz = t.v1.Z;
+
+ vx = t.v2.X;
+ vy = t.v2.Y;
+ vz = t.v2.Z;
- vx = t.v2.point.X;
- vy = t.v2.point.Y;
- vz = t.v2.point.Z;
+ wx = t.v3.X;
+ wy = t.v3.Y;
+ wz = t.v3.Z;
- wx = t.v3.point.X;
- wy = t.v3.point.Y;
- wz = t.v3.point.Z;
// Vectors for edges
float e1x, e1y, e1z;
@@ -550,14 +350,14 @@ namespace OpenSim.Region.Physics.OdePlugin
}
}
- public static Mesh CreateMesh(PrimitiveBaseShape primShape, PhysicsVector size)
+ public static Mesh CreateMesh(String primName, PrimitiveBaseShape primShape, PhysicsVector size)
{
Mesh mesh = null;
switch (primShape.ProfileShape)
{
case ProfileShape.Square:
- mesh = CreateBoxMesh(primShape, size);
+ mesh=CreateBoxMesh(primName, primShape, size);
CalcNormals(mesh);
break;
default:
@@ -568,4 +368,4 @@ namespace OpenSim.Region.Physics.OdePlugin
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 f1db034..9ac43bf 100644
--- a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
+++ b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
@@ -32,6 +32,8 @@ using Axiom.Math;
using Ode.NET;
using OpenSim.Framework;
using OpenSim.Region.Physics.Manager;
+using OpenSim.Region.Physics.OdePlugin.Meshing;
+
namespace OpenSim.Region.Physics.OdePlugin
{
@@ -274,6 +276,7 @@ namespace OpenSim.Region.Physics.OdePlugin
public int TriCallback(IntPtr trimesh, IntPtr refObject, int triangleIndex)
{
+/*
String name1 = null;
String name2 = null;
@@ -294,45 +297,52 @@ namespace OpenSim.Region.Physics.OdePlugin
d.GeomTriMeshGetTriangle(trimesh, 0, ref v0, ref v1, ref v2);
// MainLog.Instance.Debug("Triangle {0} is <{1},{2},{3}>, <{4},{5},{6}>, <{7},{8},{9}>", triangleIndex, v0.X, v0.Y, v0.Z, v1.X, v1.Y, v1.Z, v2.X, v2.Y, v2.Z);
-
+*/
return 1;
}
+
+ public bool needsMeshing(PrimitiveBaseShape pbs)
+ {
+ if (pbs.ProfileHollow != 0)
+ return true;
+
+ if ((pbs.ProfileBegin != 0) || pbs.ProfileEnd != 0)
+ return true;
+
+ return false;
+ }
public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, PhysicsVector position,
PhysicsVector size, Quaternion rotation) //To be removed
{
return this.AddPrimShape(primName, pbs, position, size, rotation, false);
}
+
public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, PhysicsVector position,
PhysicsVector size, Quaternion rotation, bool isPhysical)
{
PhysicsActor result;
+ Mesh mesh = null;
switch (pbs.ProfileShape)
{
case ProfileShape.Square:
/// support simple box & hollow box now; later, more shapes
- if (pbs.ProfileHollow == 0)
- {
- result = AddPrim(primName, position, size, rotation, null, null);
- }
- else
+ if (needsMeshing(pbs))
{
- Mesh mesh = Meshmerizer.CreateMesh(pbs, size);
- result = AddPrim(primName, position, size, rotation, mesh, pbs);
+ mesh = Meshmerizer.CreateMesh(primName, pbs, size);
}
- break;
-
- default:
- result = AddPrim(primName, position, size, rotation, null, null);
+
break;
}
+
+ result = AddPrim(primName, position, size, rotation, mesh, pbs);
+
return result;
}
-
public override void Simulate(float timeStep)
{
step_time += timeStep;
@@ -551,6 +561,13 @@ namespace OpenSim.Region.Physics.OdePlugin
set { }
}
+ public override PrimitiveBaseShape Shape
+ {
+ set
+ {
+ return;
+ }
+ }
public override PhysicsVector Velocity
{
@@ -753,6 +770,12 @@ namespace OpenSim.Region.Physics.OdePlugin
}
}
+ public override bool IsPhysical
+ {
+ get { return false; }
+ set { return; }
+ }
+
public void setMesh(OdeScene parent_scene, Mesh mesh)
{
float[] vertexList = mesh.getVertexListAsFloat(); // Note, that vertextList is pinned in memory
@@ -769,12 +792,6 @@ namespace OpenSim.Region.Physics.OdePlugin
prim_geom = d.CreateTriMesh(parent_scene.space, _triMeshData, parent_scene.triCallback, null, null);
}
- public override bool IsPhysical
- {
- get { return false; }
- set { return; }
- }
-
public override bool Flying
{
get { return false; //no flying prims for you
@@ -810,18 +827,70 @@ namespace OpenSim.Region.Physics.OdePlugin
_size = value;
lock (OdeScene.OdeLock)
{
- if (_mesh != null) // We deal with a mesh here
+ string oldname = _parent_scene.geom_name_map[prim_geom];
+
+ // Cleanup of old prim geometry
+ d.GeomDestroy(prim_geom);
+ if (_mesh != null)
{
- string oldname = _parent_scene.geom_name_map[prim_geom];
- d.GeomDestroy(prim_geom);
- Mesh mesh = Meshmerizer.CreateMesh(_pbs, _size);
+ // Cleanup meshing here
+ }
+
+ // Construction of new prim
+ if (this._parent_scene.needsMeshing(_pbs))
+ {
+ Mesh mesh = Meshmerizer.CreateMesh(oldname, _pbs, _size);
setMesh(_parent_scene, mesh);
- _parent_scene.geom_name_map[prim_geom] = oldname;
+ } else {
+ prim_geom = d.CreateBox(_parent_scene.space, _size.X, _size.Y, _size.Z);
+ }
+ _parent_scene.geom_name_map[prim_geom] = oldname;
+
+ d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
+ d.Quaternion myrot = new d.Quaternion();
+ myrot.W = _orientation.w;
+ myrot.X = _orientation.x;
+ myrot.Y = _orientation.y;
+ myrot.Z = _orientation.z;
+ d.GeomSetQuaternion(prim_geom, ref myrot);
+ }
+ }
+ }
+
+ public override PrimitiveBaseShape Shape
+ {
+ set
+ {
+ _pbs = value;
+ lock (OdeScene.OdeLock)
+ {
+ string oldname = _parent_scene.geom_name_map[prim_geom];
+
+ // Cleanup of old prim geometry
+ d.GeomDestroy(prim_geom);
+ if (_mesh != null)
+ {
+ // Cleanup meshing here
}
- else
+
+ // Construction of new prim
+ if (this._parent_scene.needsMeshing(_pbs))
{
- d.GeomBoxSetLengths(prim_geom, _size.X, _size.Y, _size.Z);
+ Mesh mesh = Meshmerizer.CreateMesh(oldname, _pbs, _size);
+ setMesh(_parent_scene, mesh);
+ } else {
+ prim_geom = d.CreateBox(_parent_scene.space, _size.X, _size.Y, _size.Z);
}
+ _parent_scene.geom_name_map[prim_geom] = oldname;
+
+ d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
+ d.Quaternion myrot = new d.Quaternion();
+ myrot.W = _orientation.w;
+ myrot.X = _orientation.x;
+ myrot.Y = _orientation.y;
+ myrot.Z = _orientation.z;
+ d.GeomSetQuaternion(prim_geom, ref myrot);
+
}
}
}
--
cgit v1.1
From c1d05740e5f36bea303db7c810a81382663b7e13 Mon Sep 17 00:00:00 2001
From: dan miller
Date: Mon, 5 Nov 2007 18:05:21 +0000
Subject: adding missing ODE files for mesh
---
.../Region/Physics/OdePlugin/Meshing/Extruder.cs | 83 +++++
OpenSim/Region/Physics/OdePlugin/Meshing/Mesh.cs | 197 +++++++++++
.../Region/Physics/OdePlugin/Meshing/SimpleHull.cs | 363 +++++++++++++++++++++
.../Region/Physics/OdePlugin/Meshing/Simplex.cs | 198 +++++++++++
4 files changed, 841 insertions(+)
create mode 100755 OpenSim/Region/Physics/OdePlugin/Meshing/Extruder.cs
create mode 100755 OpenSim/Region/Physics/OdePlugin/Meshing/Mesh.cs
create mode 100755 OpenSim/Region/Physics/OdePlugin/Meshing/SimpleHull.cs
create mode 100755 OpenSim/Region/Physics/OdePlugin/Meshing/Simplex.cs
(limited to 'OpenSim/Region/Physics/OdePlugin')
diff --git a/OpenSim/Region/Physics/OdePlugin/Meshing/Extruder.cs b/OpenSim/Region/Physics/OdePlugin/Meshing/Extruder.cs
new file mode 100755
index 0000000..497e039
--- /dev/null
+++ b/OpenSim/Region/Physics/OdePlugin/Meshing/Extruder.cs
@@ -0,0 +1,83 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace OpenSim.Region.Physics.OdePlugin.Meshing
+{
+ class Extruder
+ {
+ public float startParameter;
+ public float stopParameter;
+ public Manager.PhysicsVector size;
+
+ public Mesh Extrude(Mesh m)
+ {
+ // Currently only works for iSteps=1;
+ Mesh result = new Mesh();
+
+ Mesh workingPlus = m.Clone();
+ Mesh workingMinus = m.Clone();
+
+ foreach (Vertex v in workingPlus.vertices)
+ {
+ if (v == null)
+ continue;
+
+ v.Z = +.5f;
+ v.X *= size.X;
+ v.Y *= size.Y;
+ v.Z *= size.Z;
+ }
+
+ foreach (Vertex v in workingMinus.vertices)
+ {
+ if (v == null)
+ continue;
+
+ v.Z = -.5f;
+ v.X *= size.X;
+ v.Y *= size.Y;
+ v.Z *= size.Z;
+ }
+
+ foreach (Triangle t in workingMinus.triangles)
+ {
+ t.invertNormal();
+ }
+
+ result.Append(workingMinus);
+ result.Append(workingPlus);
+
+ int iLastNull = 0;
+ for (int i = 0; i < workingPlus.vertices.Count; i++)
+ {
+ int iNext = (i + 1);
+
+ if (workingPlus.vertices[i] == null) // Can't make a simplex here
+ {
+ iLastNull = i+1;
+ continue;
+ }
+
+ if (i == workingPlus.vertices.Count-1) // End of list
+ {
+ iNext = iLastNull;
+ }
+
+ if (workingPlus.vertices[iNext] == null) // Null means wrap to begin of last segment
+ {
+ iNext = iLastNull;
+ }
+
+ Triangle tSide;
+ tSide = new Triangle(workingPlus.vertices[i], workingMinus.vertices[i], workingPlus.vertices[iNext]);
+ result.Add(tSide);
+
+ tSide = new Triangle(workingPlus.vertices[iNext], workingMinus.vertices[i], workingMinus.vertices[iNext]);
+ result.Add(tSide);
+ }
+
+ return result;
+ }
+ }
+}
diff --git a/OpenSim/Region/Physics/OdePlugin/Meshing/Mesh.cs b/OpenSim/Region/Physics/OdePlugin/Meshing/Mesh.cs
new file mode 100755
index 0000000..5a51703
--- /dev/null
+++ b/OpenSim/Region/Physics/OdePlugin/Meshing/Mesh.cs
@@ -0,0 +1,197 @@
+using System;
+using System.IO;
+using System.Collections.Generic;
+using System.Text;
+
+using System.Runtime.InteropServices;
+
+
+using OpenSim.Region.Physics.Manager;
+
+namespace OpenSim.Region.Physics.OdePlugin.Meshing
+{
+ public class Mesh
+ {
+ public List vertices;
+ public List triangles;
+
+ public float[] normals;
+
+ public Mesh()
+ {
+ vertices = new List();
+ triangles = new List();
+ }
+
+ public Mesh Clone()
+ {
+ Mesh result = new Mesh();
+
+ foreach (Vertex v in vertices)
+ {
+ if (v == null)
+ result.vertices.Add(null);
+ else
+ result.vertices.Add(v.Clone());
+ }
+
+ foreach (Triangle t in triangles)
+ {
+ int iV1, iV2, iV3;
+ iV1 = this.vertices.IndexOf(t.v1);
+ iV2 = this.vertices.IndexOf(t.v2);
+ iV3 = this.vertices.IndexOf(t.v3);
+
+ Triangle newT = new Triangle(result.vertices[iV1], result.vertices[iV2], result.vertices[iV3]);
+ result.Add(newT);
+ }
+
+ return result;
+ }
+
+
+
+ public void Add(Triangle triangle)
+ {
+ int i;
+ i = vertices.IndexOf(triangle.v1);
+ if (i < 0)
+ throw new ArgumentException("Vertex v1 not known to mesh");
+ i = vertices.IndexOf(triangle.v2);
+ if (i < 0)
+ throw new ArgumentException("Vertex v2 not known to mesh");
+ i = vertices.IndexOf(triangle.v3);
+ if (i < 0)
+ throw new ArgumentException("Vertex v3 not known to mesh");
+
+ triangles.Add(triangle);
+ }
+
+ public void Add(Vertex v)
+ {
+ vertices.Add(v);
+ }
+
+ public void Remove(Vertex v)
+ {
+ int i;
+
+ // First, remove all triangles that are build on v
+ for (i = 0; i < triangles.Count; i++)
+ {
+ Triangle t = triangles[i];
+ if (t.v1 == v || t.v2 == v || t.v3 == v)
+ {
+ triangles.RemoveAt(i);
+ i--;
+ }
+ }
+
+ // Second remove v itself
+ vertices.Remove(v);
+ }
+
+ public void RemoveTrianglesOutside(SimpleHull hull)
+ {
+ int i;
+
+ for (i = 0; i < triangles.Count; i++)
+ {
+ Triangle t = triangles[i];
+ Vertex v1 = t.v1;
+ Vertex v2 = t.v2;
+ Vertex v3 = t.v3;
+ PhysicsVector m = v1 + v2 + v3;
+ m /= 3.0f;
+ if (!hull.IsPointIn(new Vertex(m)))
+ {
+ triangles.RemoveAt(i);
+ i--;
+ }
+ }
+ }
+
+
+ public void Add(List lv)
+ {
+ foreach (Vertex v in lv)
+ {
+ vertices.Add(v);
+ }
+ }
+
+ public float[] getVertexListAsFloat()
+ {
+ float[] result = new float[vertices.Count * 3];
+ for (int i = 0; i < vertices.Count; i++)
+ {
+ Vertex v = vertices[i];
+ if (v == null)
+ continue;
+ result[3 * i + 0] = v.X;
+ result[3 * i + 1] = v.Y;
+ result[3 * i + 2] = v.Z;
+ }
+ GCHandle.Alloc(result, GCHandleType.Pinned);
+ return result;
+ }
+
+ public int[] getIndexListAsInt()
+ {
+ 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);
+ }
+ GCHandle.Alloc(result, GCHandleType.Pinned);
+ return result;
+ }
+
+
+ public void Append(Mesh newMesh)
+ {
+ foreach (Vertex v in newMesh.vertices)
+ vertices.Add(v);
+
+ foreach (Triangle t in newMesh.triangles)
+ Add(t);
+
+ }
+
+ // Do a linear transformation of mesh.
+ public void TransformLinear(float[,] matrix, float[] offset)
+ {
+ foreach (Vertex v in vertices)
+ {
+ if (v == null)
+ continue;
+ float x, y, z;
+ x = v.X * matrix[0, 0] + v.Y * matrix[1, 0] + v.Z * matrix[2, 0];
+ y = v.X * matrix[0, 1] + v.Y * matrix[1, 1] + v.Z * matrix[2, 1];
+ z = v.X * matrix[0, 2] + v.Y * matrix[1, 2] + v.Z * matrix[2, 2];
+ v.X = x + offset[0];
+ v.Y = y + offset[1];
+ v.Z = z + offset[2];
+ }
+ }
+
+ public void DumpRaw(String path, String name, String title)
+ {
+ if (path == null)
+ return;
+ String fileName = name + "_" + title + ".raw";
+ String completePath = Path.Combine(path, fileName);
+ StreamWriter sw = new StreamWriter(completePath);
+ foreach (Triangle t in triangles)
+ {
+ String s = t.ToStringRaw();
+ sw.WriteLine(s);
+ }
+ sw.Close();
+ }
+ }
+
+}
diff --git a/OpenSim/Region/Physics/OdePlugin/Meshing/SimpleHull.cs b/OpenSim/Region/Physics/OdePlugin/Meshing/SimpleHull.cs
new file mode 100755
index 0000000..2caa818
--- /dev/null
+++ b/OpenSim/Region/Physics/OdePlugin/Meshing/SimpleHull.cs
@@ -0,0 +1,363 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+using OpenSim.Framework.Console;
+
+namespace OpenSim.Region.Physics.OdePlugin.Meshing
+{
+ // A simple hull is a set of vertices building up to simplices that border a region
+ // The word simple referes to the fact, that this class assumes, that all simplices
+ // do not intersect
+ // Simple hulls can be added and subtracted.
+ // Vertices can be checked to lie inside a hull
+ // Also note, that the sequence of the vertices is important and defines if the region that
+ // is defined by the hull lies inside or outside the simplex chain
+ public class SimpleHull
+ {
+ List vertices = new List();
+ List holeVertices = new List(); // Only used, when the hull is hollow
+
+ // Adds a vertex to the end of the list
+ public void AddVertex(Vertex v) {
+ vertices.Add(v);
+ }
+
+ override public String ToString()
+ {
+ String result="";
+ foreach (Vertex v in vertices)
+ {
+ result += "b:" + v.ToString() + "\n";
+ }
+
+ return result;
+ }
+
+
+ public List getVertices() {
+ List newVertices = new List();
+
+ newVertices.AddRange(vertices);
+ newVertices.Add(null);
+ newVertices.AddRange(holeVertices);
+
+ return newVertices;
+ }
+
+ public SimpleHull Clone()
+ {
+ SimpleHull result = new SimpleHull();
+ foreach (Vertex v in vertices)
+ {
+ result.AddVertex(v.Clone());
+ }
+
+ foreach (Vertex v in this.holeVertices)
+ {
+ result.holeVertices.Add(v.Clone());
+ }
+
+ return result;
+ }
+
+ public bool IsPointIn(Vertex v1)
+ {
+ int iCounter=0;
+ List simplices=buildSimplexList();
+ foreach (Simplex s in simplices)
+ {
+ // Send a ray along the positive X-Direction
+ // Note, that this direction must correlate with the "below" interpretation
+ // of handling for the special cases below
+ Manager.PhysicsVector intersection = s.RayIntersect(v1, new Manager.PhysicsVector(1.0f, 0.0f, 0.0f), true);
+
+ if (intersection == null)
+ continue; // No intersection. Done. More tests to follow otherwise
+
+ // Did we hit the end of a simplex?
+ // Then this can be one of two special cases:
+ // 1. we go through a border exactly at a joint
+ // 2. we have just marginally touched a corner
+ // 3. we can slide along a border
+ // Solution: If the other vertex is "below" the ray, we don't count it
+ // Thus corners pointing down are counted twice, corners pointing up are not counted
+ // borders are counted once
+ if (intersection.IsIdentical(s.v1, 0.001f)) {
+ if (s.v2.Y < v1.Y)
+ continue;
+ }
+ // Do this for the other vertex two
+ if (intersection.IsIdentical(s.v2, 0.001f)) {
+ if (s.v1.Y buildSimplexList() {
+
+ List result = new List();
+
+ // Not asserted but assumed: at least three vertices
+ for (int i=0; i simple = buildSimplexList();
+ foreach (Simplex sTest in simple)
+ {
+ Manager.PhysicsVector vvTemp = Simplex.Intersect(sTest, s, -.001f, -.001f, 0.999f, .999f);
+
+ Vertex vTemp=null;
+ if (vvTemp != null)
+ vTemp = new Vertex(vvTemp);
+
+ if (vTemp!=null) {
+
+ Manager.PhysicsVector diff=(s.v1-vTemp);
+ float distTemp=diff.length();
+
+ if (bestIntersection==null || distTemp
+ {
+ public Vertex v1;
+ public Vertex v2;
+
+ public Simplex(Vertex _v1, Vertex _v2)
+ {
+ v1 = _v1;
+ v2 = _v2;
+ }
+
+ public int CompareTo(Simplex other)
+ {
+
+ Vertex lv1, lv2, ov1, ov2, temp;
+
+ lv1 = v1;
+ lv2 = v2;
+ ov1 = other.v1;
+ ov2 = other.v2;
+
+ if (lv1 > lv2)
+ {
+ temp = lv1;
+ lv1 = lv2;
+ lv2 = temp;
+ }
+
+ if (ov1 > ov2)
+ {
+ temp = ov1;
+ ov1 = ov2;
+ ov2 = temp;
+ }
+
+ if (lv1 > ov1)
+ {
+ return 1;
+ }
+ if (lv1 < ov1)
+ {
+ return -1;
+ }
+
+ if (lv2 > ov2)
+ {
+ return 1;
+ }
+ if (lv2 < ov2)
+ {
+ return -1;
+ }
+
+ return 0;
+ }
+
+ private static void intersectParameter(PhysicsVector p1, PhysicsVector r1, PhysicsVector p2, PhysicsVector r2, ref float lambda, ref float mu)
+ {
+ // Intersects two straights
+ // p1, p2, points on the straight
+ // r1, r2, directional vectors of the straight. Not necessarily of length 1!
+ // note, that l, m can be scaled such, that the range 0..1 is mapped to the area between two points,
+ // thus allowing to decide whether an intersection is between two points
+
+ float r1x = r1.X;
+ float r1y = r1.Y;
+ float r2x = r2.X;
+ float r2y = r2.Y;
+
+ float denom = r1y*r2x - r1x*r2y;
+
+ float p1x = p1.X;
+ float p1y = p1.Y;
+ float p2x = p2.X;
+ float p2y = p2.Y;
+
+ float z1=-p2x * r2y + p1x * r2y + (p2y - p1y) * r2x;
+ float z2=-p2x * r1y + p1x * r1y + (p2y - p1y) * r1x;
+
+ if (denom == 0.0f) // Means the straights are parallel. Either no intersection or an infinite number of them
+ {
+ if (z1==0.0f) {// Means they are identical -> many, many intersections
+ lambda = Single.NaN;
+ mu = Single.NaN;
+ } else {
+ lambda = Single.PositiveInfinity;
+ mu = Single.PositiveInfinity;
+ }
+ return;
+
+ }
+
+
+
+ lambda = z1 / denom;
+ mu = z2 / denom;
+
+ }
+
+
+ // Intersects the simplex with another one.
+ // the borders are used to deal with float inaccuracies
+ // As a rule of thumb, the borders are
+ // lowerBorder1 : 0.0
+ // lowerBorder2 : 0.0
+ // upperBorder1 : 1.0
+ // upperBorder2 : 1.0
+ // Set these to values near the given parameters (e.g. 0.001 instead of 1 to exclude simplex starts safely, or to -0.001 to include them safely)
+ public static PhysicsVector Intersect(
+ Simplex s1,
+ Simplex s2,
+ float lowerBorder1,
+ float lowerBorder2,
+ float upperBorder1,
+ float upperBorder2)
+ {
+ PhysicsVector firstSimplexDirection = s1.v2 - s1.v1;
+ PhysicsVector secondSimplexDirection = s2.v2 - s2.v1;
+
+ float lambda = 0.0f;
+ float mu = 0.0f;
+
+ // Give us the parameters of an intersection. This subroutine does *not* take the constraints
+ // (intersection must be between v1 and v2 and it must be in the positive direction of the ray)
+ // into account. We do that afterwards.
+ intersectParameter(s1.v1, firstSimplexDirection, s2.v1, secondSimplexDirection, ref lambda, ref mu);
+
+ if (Single.IsInfinity(lambda)) // Special case. No intersection at all. directions parallel.
+ return null;
+
+ if (Single.IsNaN(lambda)) // Special case. many, many intersections.
+ return null;
+
+ if (lambda > upperBorder1) // We're behind v2
+ return null;
+
+ if (lambda < lowerBorder1)
+ return null;
+
+ if (mu < lowerBorder2) // outside simplex 2
+ return null;
+
+ if (mu > upperBorder2) // outside simplex 2
+ return null;
+
+ return s1.v1 + lambda * firstSimplexDirection;
+
+ }
+
+ // Intersects the simplex with a ray. The ray is defined as all p=origin + lambda*direction
+ // where lambda >= 0
+ public PhysicsVector RayIntersect(Vertex origin, PhysicsVector direction, bool bEndsIncluded)
+ {
+ PhysicsVector simplexDirection = v2 - v1;
+
+ float lambda = 0.0f;
+ float mu = 0.0f;
+
+ // Give us the parameters of an intersection. This subroutine does *not* take the constraints
+ // (intersection must be between v1 and v2 and it must be in the positive direction of the ray)
+ // into account. We do that afterwards.
+ intersectParameter(v1, simplexDirection, origin, direction, ref lambda, ref mu);
+
+ if (Single.IsInfinity(lambda)) // Special case. No intersection at all. directions parallel.
+ return null;
+
+ if (Single.IsNaN(lambda)) // Special case. many, many intersections.
+ return null;
+
+ if (mu < 0.0) // We're on the wrong side of the ray
+ return null;
+
+ if (lambda > 1.0) // We're behind v2
+ return null;
+
+ if (lambda == 1.0 && !bEndsIncluded)
+ return null; // The end of the simplices are not included
+
+ if (lambda < 0.0f) // we're before v1;
+ return null;
+
+ return this.v1 + lambda * simplexDirection;
+
+ }
+
+
+ }
+}
--
cgit v1.1
From 62a43affe419314eff1f46cee32adc31e3eaf3b4 Mon Sep 17 00:00:00 2001
From: dan miller
Date: Mon, 5 Nov 2007 22:18:12 +0000
Subject: physical prims
---
OpenSim/Region/Physics/OdePlugin/OdePlugin.cs | 527 ++++++++++++++++++++++----
1 file changed, 452 insertions(+), 75 deletions(-)
(limited to 'OpenSim/Region/Physics/OdePlugin')
diff --git a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
index 9ac43bf..4bd36aa 100644
--- a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
+++ b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
@@ -34,7 +34,6 @@ using OpenSim.Framework;
using OpenSim.Region.Physics.Manager;
using OpenSim.Region.Physics.OdePlugin.Meshing;
-
namespace OpenSim.Region.Physics.OdePlugin
{
///
@@ -84,13 +83,18 @@ namespace OpenSim.Region.Physics.OdePlugin
public d.TriArrayCallback triArrayCallback;
private List _characters = new List();
private List _prims = new List();
+ private List _activeprims = new List();
public Dictionary geom_name_map = new Dictionary();
public Dictionary actor_name_map = new Dictionary