Applied danx0r's ODE patch [mantis number 340].

Corrected a few out dated things in the ExtensionsScriptModule.
afrisby
MW 2007-08-28 19:55:42 +00:00
parent 7915adc6c5
commit 3a97f3f597
3 changed files with 105 additions and 87 deletions

View File

@ -47,8 +47,9 @@ namespace OpenSim.Region.ExtensionsScriptModule.CSharp
compilerParams.GenerateExecutable = false; compilerParams.GenerateExecutable = false;
compilerParams.GenerateInMemory = true; compilerParams.GenerateInMemory = true;
compilerParams.IncludeDebugInformation = false; compilerParams.IncludeDebugInformation = false;
compilerParams.ReferencedAssemblies.Add("OpenSim.Region.dll"); compilerParams.ReferencedAssemblies.Add("OpenSim.Region.ClientStack.dll");
compilerParams.ReferencedAssemblies.Add("OpenSim.Region.Environment.dll"); compilerParams.ReferencedAssemblies.Add("OpenSim.Region.Environment.dll");
compilerParams.ReferencedAssemblies.Add("OpenSim.Region.ExtensionsScriptModule.dll");
compilerParams.ReferencedAssemblies.Add("OpenSim.Framework.dll"); compilerParams.ReferencedAssemblies.Add("OpenSim.Framework.dll");
compilerParams.ReferencedAssemblies.Add("libsecondlife.dll"); compilerParams.ReferencedAssemblies.Add("libsecondlife.dll");
compilerParams.ReferencedAssemblies.Add("System.dll"); compilerParams.ReferencedAssemblies.Add("System.dll");

View File

@ -47,8 +47,9 @@ namespace OpenSim.Region.ExtensionsScriptModule.JScript
compilerParams.GenerateExecutable = false; compilerParams.GenerateExecutable = false;
compilerParams.GenerateInMemory = true; compilerParams.GenerateInMemory = true;
compilerParams.IncludeDebugInformation = false; compilerParams.IncludeDebugInformation = false;
compilerParams.ReferencedAssemblies.Add("OpenSim.Region.dll"); compilerParams.ReferencedAssemblies.Add("OpenSim.Region.ClientStack.dll");
compilerParams.ReferencedAssemblies.Add("OpenSim.Region.Environment.dll"); compilerParams.ReferencedAssemblies.Add("OpenSim.Region.Environment.dll");
compilerParams.ReferencedAssemblies.Add("OpenSim.Region.ExtensionsScriptModule.dll");
compilerParams.ReferencedAssemblies.Add("OpenSim.Framework.dll"); compilerParams.ReferencedAssemblies.Add("OpenSim.Framework.dll");
compilerParams.ReferencedAssemblies.Add("libsecondlife.dll"); compilerParams.ReferencedAssemblies.Add("libsecondlife.dll");
compilerParams.ReferencedAssemblies.Add("System.dll"); compilerParams.ReferencedAssemblies.Add("System.dll");

View File

@ -84,6 +84,7 @@ namespace OpenSim.Region.Physics.OdePlugin
private List<OdePrim> _prims = new List<OdePrim>(); private List<OdePrim> _prims = new List<OdePrim>();
private static d.ContactGeom[] contacts = new d.ContactGeom[30]; private static d.ContactGeom[] contacts = new d.ContactGeom[30];
private static d.Contact contact; private static d.Contact contact;
public static Object OdeLock = new Object();
public OdeScene() public OdeScene()
{ {
contact.surface.mode |= d.ContactFlags.Approx1 | d.ContactFlags.SoftCFM | d.ContactFlags.SoftERP; 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_erp = 0.005f;
contact.surface.soft_cfm = 0.00003f; contact.surface.soft_cfm = 0.00003f;
Monitor.Enter(typeof(OdeScene)); lock (OdeLock)
world = d.WorldCreate(); {
space = d.HashSpaceCreate(IntPtr.Zero); world = d.WorldCreate();
contactgroup = d.JointGroupCreate(0); space = d.HashSpaceCreate(IntPtr.Zero);
d.WorldSetGravity(world, 0.0f, 0.0f, -10.0f); contactgroup = d.JointGroupCreate(0);
d.WorldSetAutoDisableFlag(world, false); d.WorldSetGravity(world, 0.0f, 0.0f, -10.0f);
d.WorldSetContactSurfaceLayer(world, 0.001f); d.WorldSetAutoDisableFlag(world, false);
Monitor.Exit(typeof(OdeScene)); d.WorldSetContactSurfaceLayer(world, 0.001f);
}
this._heightmap = new double[65536]; this._heightmap = new double[65536];
} }
@ -128,7 +130,7 @@ namespace OpenSim.Region.Physics.OdePlugin
PhysicsVector pos = new PhysicsVector(); PhysicsVector pos = new PhysicsVector();
pos.X = position.X; pos.X = position.X;
pos.Y = position.Y; pos.Y = position.Y;
pos.Z = position.Z + 20; pos.Z = position.Z;
OdeCharacter newAv = new OdeCharacter(this, pos); OdeCharacter newAv = new OdeCharacter(this, pos);
this._characters.Add(newAv); this._characters.Add(newAv);
return newAv; return newAv;
@ -136,7 +138,6 @@ namespace OpenSim.Region.Physics.OdePlugin
public override void RemoveAvatar(PhysicsActor actor) public override void RemoveAvatar(PhysicsActor actor)
{ {
} }
public override void RemovePrim(PhysicsActor prim) 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) public override PhysicsActor AddPrim(PhysicsVector position, PhysicsVector size, Quaternion rotation)
{ {
//Console.WriteLine("+++++++++++++++++++++++++++++++++AddPrim pos: " + position + " size: " + size + " quat: " + rotation);
PhysicsVector pos = new PhysicsVector(); PhysicsVector pos = new PhysicsVector();
pos.X = position.X; pos.X = position.X;
pos.Y = position.Y; pos.Y = position.Y;
@ -165,7 +165,8 @@ namespace OpenSim.Region.Physics.OdePlugin
rot.y = rotation.y; rot.y = rotation.y;
rot.z = rotation.z; rot.z = rotation.z;
OdePrim newPrim; OdePrim newPrim;
lock(typeof(OdeScene)) { lock (OdeLock)
{
newPrim = new OdePrim(this, pos, siz, rot); newPrim = new OdePrim(this, pos, siz, rot);
} }
this._prims.Add(newPrim); this._prims.Add(newPrim);
@ -174,27 +175,27 @@ namespace OpenSim.Region.Physics.OdePlugin
public override void Simulate(float timeStep) public override void Simulate(float timeStep)
{ {
Monitor.Enter(typeof(OdeScene)); lock (OdeLock)
foreach (OdePrim p in _prims)
{ {
// Console.WriteLine("+++ prim: " + p.Position); foreach (OdePrim p in _prims)
} {
foreach (OdeCharacter actor in _characters) }
{ foreach (OdeCharacter actor in _characters)
actor.Move(timeStep); {
} actor.Move(timeStep);
d.SpaceCollide(space, IntPtr.Zero, nearCallback); }
for (int i = 0; i < 50; i++) d.SpaceCollide(space, IntPtr.Zero, nearCallback);
{ for (int i = 0; i < 50; i++)
d.WorldQuickStep(world, timeStep * 0.02f); {
} d.WorldQuickStep(world, timeStep * 0.02f);
}
d.JointGroupEmpty(contactgroup); d.JointGroupEmpty(contactgroup);
foreach (OdeCharacter actor in _characters) foreach (OdeCharacter actor in _characters)
{ {
actor.UpdatePosition(); actor.UpdatePosition();
}
} }
Monitor.Exit(typeof(OdeScene));
} }
public override void GetResults() public override void GetResults()
@ -222,26 +223,27 @@ namespace OpenSim.Region.Physics.OdePlugin
} }
IntPtr HeightmapData = d.GeomHeightfieldDataCreate(); IntPtr HeightmapData = d.GeomHeightfieldDataCreate();
Monitor.Enter(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); d.GeomHeightfieldDataBuildDouble(HeightmapData, _heightmap, 0, 256, 256, 256, 256, 1.0f, 0.0f, 2.0f, 0);
LandGeom = d.CreateHeightfield(space, HeightmapData, 1); d.GeomHeightfieldDataSetBounds(HeightmapData, 256, 256);
d.Matrix3 R = new d.Matrix3(); 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); Quaternion q1 = Quaternion.FromAngleAxis(1.5707f, new Vector3(1, 0, 0));
d.GeomSetRotation(LandGeom, ref R); Quaternion q2 = Quaternion.FromAngleAxis(1.5707f, new Vector3(0, 1, 0));
d.GeomSetPosition(LandGeom, 128, 128, 0); //Axiom.Math.Quaternion q3 = Axiom.Math.Quaternion.FromAngleAxis(3.14f, new Axiom.Math.Vector3(0, 0, 1));
Monitor.Exit(typeof(OdeScene));
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 override void DeleteTerrain()
@ -260,20 +262,23 @@ namespace OpenSim.Region.Physics.OdePlugin
private IntPtr BoundingCapsule; private IntPtr BoundingCapsule;
IntPtr capsule_geom; IntPtr capsule_geom;
d.Mass capsule_mass; d.Mass capsule_mass;
private OdeScene _parent_scene;
public OdeCharacter(OdeScene parent_scene, PhysicsVector pos) public OdeCharacter(OdeScene parent_scene, PhysicsVector pos)
{ {
_velocity = new PhysicsVector(); _velocity = new PhysicsVector();
_position = pos; _position = pos;
_acceleration = new PhysicsVector(); _acceleration = new PhysicsVector();
Monitor.Enter(typeof(OdeScene)); _parent_scene = parent_scene;
d.MassSetCapsule(out capsule_mass, 50.0f, 3, 0.5f, 2f); lock (OdeScene.OdeLock)
capsule_geom = d.CreateSphere(OdeScene.space, 1.0f); /// not a typo! Spheres roll, capsules tumble {
this.BoundingCapsule = d.BodyCreate(OdeScene.world); d.MassSetCapsule(out capsule_mass, 50.0f, 3, 0.5f, 2f);
d.BodySetMass(BoundingCapsule, ref capsule_mass); capsule_geom = d.CreateSphere(OdeScene.space, 1.0f); /// not a typo! Spheres roll, capsules tumble
d.BodySetPosition(BoundingCapsule, pos.X, pos.Y, pos.Z); this.BoundingCapsule = d.BodyCreate(OdeScene.world);
d.GeomSetBody(capsule_geom, BoundingCapsule); d.BodySetMass(BoundingCapsule, ref capsule_mass);
Monitor.Exit(typeof(OdeScene)); d.BodySetPosition(BoundingCapsule, pos.X, pos.Y, pos.Z);
d.GeomSetBody(capsule_geom, BoundingCapsule);
}
} }
public override bool Flying public override bool Flying
@ -296,7 +301,11 @@ namespace OpenSim.Region.Physics.OdePlugin
} }
set 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! // 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(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.X = vec.X;
this._position.Y = vec.Y; this._position.Y = vec.Y;
this._position.Z = vec.Z; this._position.Z = vec.Z;
@ -412,15 +428,16 @@ namespace OpenSim.Region.Physics.OdePlugin
_acceleration = new PhysicsVector(); _acceleration = new PhysicsVector();
_orientation = rotation; _orientation = rotation;
prim_geom = d.CreateBox(OdeScene.space, _size.X, _size.Y, _size.Z); prim_geom = d.CreateBox(OdeScene.space, _size.X, _size.Y, _size.Z);
Monitor.Enter(typeof(OdeScene)); lock (OdeScene.OdeLock)
d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z); {
d.Quaternion myrot = new d.Quaternion(); d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
myrot.W = rotation.w; d.Quaternion myrot = new d.Quaternion();
myrot.X = rotation.x; myrot.W = rotation.w;
myrot.Y = rotation.y; myrot.X = rotation.x;
myrot.Z = rotation.z; myrot.Y = rotation.y;
d.GeomSetQuaternion(prim_geom, ref myrot); myrot.Z = rotation.z;
Monitor.Exit(typeof(OdeScene)); d.GeomSetQuaternion(prim_geom, ref myrot);
}
} }
public override bool Flying public override bool Flying
@ -442,12 +459,11 @@ namespace OpenSim.Region.Physics.OdePlugin
} }
set set
{ {
//Console.WriteLine("+++++++++++++++++++++++++++++++++++++++++++ setting pos: " + value);
_position = value; _position = value;
Monitor.Enter(typeof(OdeScene)); lock (OdeScene.OdeLock)
d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z); {
Monitor.Exit(typeof(OdeScene)); d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
}
} }
} }
@ -459,11 +475,11 @@ namespace OpenSim.Region.Physics.OdePlugin
} }
set set
{ {
//Console.WriteLine("+++++++++++++++++++++++++++++++++++++++++++ setting size: " + value);
_size = value; _size = value;
Monitor.Enter(typeof(OdeScene)); lock (OdeScene.OdeLock)
d.GeomBoxSetLengths(prim_geom, _size.X, _size.Y, _size.Z); {
Monitor.Exit(typeof(OdeScene)); d.GeomBoxSetLengths(prim_geom, _size.X, _size.Y, _size.Z);
}
} }
} }
@ -498,16 +514,16 @@ namespace OpenSim.Region.Physics.OdePlugin
} }
set set
{ {
//Console.WriteLine("+++++++++++++++++++++++++++++++++++++++++++ setting Orientation");
_orientation = value; _orientation = value;
Monitor.Enter(typeof(OdeScene)); lock (OdeScene.OdeLock)
d.Quaternion myrot = new d.Quaternion(); {
myrot.W = _orientation.w; d.Quaternion myrot = new d.Quaternion();
myrot.X = _orientation.x; myrot.W = _orientation.w;
myrot.Y = _orientation.y; myrot.X = _orientation.x;
myrot.Z = _orientation.z; myrot.Y = _orientation.y;
d.GeomSetQuaternion(prim_geom, ref myrot); myrot.Z = _orientation.z;
Monitor.Exit(typeof(OdeScene)); d.GeomSetQuaternion(prim_geom, ref myrot);
}
} }
} }