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.
parent
107469ed93
commit
9a8742e838
|
@ -503,6 +503,11 @@ namespace OpenSim.Region.Environment.Scenes
|
||||||
foreach (SceneObjectGroup prim in PrimsFromDB)
|
foreach (SceneObjectGroup prim in PrimsFromDB)
|
||||||
{
|
{
|
||||||
AddEntityFromStorage(prim);
|
AddEntityFromStorage(prim);
|
||||||
|
// phyScene.AddPrim(
|
||||||
|
// new PhysicsVector(prim.RootPart.AbsolutePosition.X, prim.RootPart.AbsolutePosition.Y, prim.RootPart.AbsolutePosition.Z),
|
||||||
|
// new PhysicsVector(prim.RootPart.Scale.X, prim.RootPart.Scale.Y, prim.RootPart.Scale.Z),
|
||||||
|
// new Axiom.Math.Quaternion(prim.RootPart.RotationOffset.W, prim.RootPart.RotationOffset.X,
|
||||||
|
// prim.RootPart.RotationOffset.Y, prim.RootPart.RotationOffset.Z));
|
||||||
}
|
}
|
||||||
MainLog.Instance.Verbose("Loaded " + PrimsFromDB.Count.ToString() + " SceneObject(s)");
|
MainLog.Instance.Verbose("Loaded " + PrimsFromDB.Count.ToString() + " SceneObject(s)");
|
||||||
}
|
}
|
||||||
|
@ -540,6 +545,8 @@ namespace OpenSim.Region.Environment.Scenes
|
||||||
{
|
{
|
||||||
SceneObjectGroup sceneOb = new SceneObjectGroup(this, this.m_regionHandle, ownerID, PrimIDAllocate(), pos, shape);
|
SceneObjectGroup sceneOb = new SceneObjectGroup(this, this.m_regionHandle, ownerID, PrimIDAllocate(), pos, shape);
|
||||||
AddEntity(sceneOb);
|
AddEntity(sceneOb);
|
||||||
|
//phyScene.AddPrim(new PhysicsVector(pos.X, pos.Y, pos.Z), new PhysicsVector(shape.Scale.X, shape.Scale.Y, shape.Scale.Z),
|
||||||
|
// new Axiom.Math.Quaternion());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RemovePrim(uint localID, LLUUID avatar_deleter)
|
public void RemovePrim(uint localID, LLUUID avatar_deleter)
|
||||||
|
@ -615,6 +622,11 @@ namespace OpenSim.Region.Environment.Scenes
|
||||||
//if we want this to be a import method then we need new uuids for the object to avoid any clashes
|
//if we want this to be a import method then we need new uuids for the object to avoid any clashes
|
||||||
//obj.RegenerateFullIDs();
|
//obj.RegenerateFullIDs();
|
||||||
AddEntity(obj);
|
AddEntity(obj);
|
||||||
|
// phyScene.AddPrim(
|
||||||
|
// new PhysicsVector(obj.RootPart.AbsolutePosition.X, obj.RootPart.AbsolutePosition.Y, obj.RootPart.AbsolutePosition.Z),
|
||||||
|
// new PhysicsVector(obj.RootPart.Scale.X, obj.RootPart.Scale.Y, obj.RootPart.Scale.Z),
|
||||||
|
// new Axiom.Math.Quaternion(obj.RootPart.RotationOffset.W, obj.RootPart.RotationOffset.X,
|
||||||
|
// obj.RootPart.RotationOffset.Y, obj.RootPart.RotationOffset.Z));
|
||||||
primCount++;
|
primCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,6 +57,7 @@ namespace OpenSim.Region.Environment.Scenes
|
||||||
|
|
||||||
public SceneObjectPart RootPart
|
public SceneObjectPart RootPart
|
||||||
{
|
{
|
||||||
|
get { return this.m_rootPart; }
|
||||||
set { m_rootPart = value; }
|
set { m_rootPart = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -93,6 +93,7 @@ namespace OpenSim.Physics.Manager
|
||||||
IPhysicsPlugin plug = (IPhysicsPlugin)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString()));
|
IPhysicsPlugin plug = (IPhysicsPlugin)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString()));
|
||||||
plug.Init();
|
plug.Init();
|
||||||
this._plugins.Add(plug.GetName(),plug);
|
this._plugins.Add(plug.GetName(),plug);
|
||||||
|
Console.WriteLine("-----------------------------------------added physics eng: " + plug.GetName());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
using System;
|
using System;
|
||||||
|
using System.Threading;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Axiom.Math;
|
using Axiom.Math;
|
||||||
using Ode.NET;
|
using Ode.NET;
|
||||||
|
@ -83,7 +84,6 @@ 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 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,24 +92,35 @@ 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));
|
||||||
world = d.WorldCreate();
|
world = d.WorldCreate();
|
||||||
space = d.HashSpaceCreate(IntPtr.Zero);
|
space = d.HashSpaceCreate(IntPtr.Zero);
|
||||||
contactgroup = d.JointGroupCreate(0);
|
contactgroup = d.JointGroupCreate(0);
|
||||||
d.WorldSetGravity(world, 0.0f, 0.0f, -10.0f);
|
d.WorldSetGravity(world, 0.0f, 0.0f, -10.0f);
|
||||||
d.WorldSetAutoDisableFlag(world, false);
|
d.WorldSetAutoDisableFlag(world, false);
|
||||||
d.WorldSetContactSurfaceLayer(world, 0.001f);
|
d.WorldSetContactSurfaceLayer(world, 0.001f);
|
||||||
|
Monitor.Exit(typeof(OdeScene));
|
||||||
|
|
||||||
this._heightmap = new double[65536];
|
this._heightmap = new double[65536];
|
||||||
}
|
}
|
||||||
|
|
||||||
// This function blatantly ripped off from BoxStack.cs
|
// This function blatantly ripped off from BoxStack.cs
|
||||||
static private void near(IntPtr space, IntPtr g1, IntPtr g2)
|
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 b1 = d.GeomGetBody(g1);
|
||||||
IntPtr b2 = d.GeomGetBody(g2);
|
IntPtr b2 = d.GeomGetBody(g2);
|
||||||
if (b1 != IntPtr.Zero && b2 != IntPtr.Zero && d.AreConnectedExcluding(b1, b2, d.JointType.Contact))
|
if (b1 != IntPtr.Zero && b2 != IntPtr.Zero && d.AreConnectedExcluding(b1, b2, d.JointType.Contact))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
int count = d.Collide(g1, g2, 500, contacts, d.ContactGeom.SizeOf);
|
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)
|
for (int i = 0; i < count; ++i)
|
||||||
{
|
{
|
||||||
contact.geom = contacts[i];
|
contact.geom = contacts[i];
|
||||||
|
@ -137,6 +148,7 @@ 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;
|
||||||
|
@ -157,6 +169,11 @@ namespace OpenSim.Region.Physics.OdePlugin
|
||||||
|
|
||||||
public override void Simulate(float timeStep)
|
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)
|
foreach (OdeCharacter actor in _characters)
|
||||||
{
|
{
|
||||||
actor.Move(timeStep);
|
actor.Move(timeStep);
|
||||||
|
@ -172,6 +189,7 @@ namespace OpenSim.Region.Physics.OdePlugin
|
||||||
{
|
{
|
||||||
actor.UpdatePosition();
|
actor.UpdatePosition();
|
||||||
}
|
}
|
||||||
|
Monitor.Exit(typeof(OdeScene));
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void GetResults()
|
public override void GetResults()
|
||||||
|
@ -198,6 +216,8 @@ namespace OpenSim.Region.Physics.OdePlugin
|
||||||
this._heightmap[i] = (double)heightMap[x * 256 + y];
|
this._heightmap[i] = (double)heightMap[x * 256 + y];
|
||||||
}
|
}
|
||||||
IntPtr HeightmapData = d.GeomHeightfieldDataCreate();
|
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.GeomHeightfieldDataBuildDouble(HeightmapData, _heightmap, 0, 256, 256, 256, 256, 1.0f, 0.0f, 2.0f, 0);
|
||||||
d.GeomHeightfieldDataSetBounds(HeightmapData, 256, 256);
|
d.GeomHeightfieldDataSetBounds(HeightmapData, 256, 256);
|
||||||
LandGeom = d.CreateHeightfield(space, HeightmapData, 1);
|
LandGeom = d.CreateHeightfield(space, HeightmapData, 1);
|
||||||
|
@ -216,6 +236,7 @@ namespace OpenSim.Region.Physics.OdePlugin
|
||||||
d.RFromAxisAndAngle(out R, v3.x, v3.y, v3.z, angle);
|
d.RFromAxisAndAngle(out R, v3.x, v3.y, v3.z, angle);
|
||||||
d.GeomSetRotation(LandGeom, ref R);
|
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()
|
public override void DeleteTerrain()
|
||||||
|
@ -240,12 +261,14 @@ namespace OpenSim.Region.Physics.OdePlugin
|
||||||
_velocity = new PhysicsVector();
|
_velocity = new PhysicsVector();
|
||||||
_position = pos;
|
_position = pos;
|
||||||
_acceleration = new PhysicsVector();
|
_acceleration = new PhysicsVector();
|
||||||
|
Monitor.Enter(typeof(OdeScene));
|
||||||
d.MassSetCapsule(out capsule_mass, 50.0f, 3, 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
|
capsule_geom = d.CreateSphere(OdeScene.space, 1.0f); /// not a typo! Spheres roll, capsules tumble
|
||||||
this.BoundingCapsule = d.BodyCreate(OdeScene.world);
|
this.BoundingCapsule = d.BodyCreate(OdeScene.world);
|
||||||
d.BodySetMass(BoundingCapsule, ref capsule_mass);
|
d.BodySetMass(BoundingCapsule, ref capsule_mass);
|
||||||
d.BodySetPosition(BoundingCapsule, pos.X, pos.Y, pos.Z);
|
d.BodySetPosition(BoundingCapsule, pos.X, pos.Y, pos.Z);
|
||||||
d.GeomSetBody(capsule_geom, BoundingCapsule);
|
d.GeomSetBody(capsule_geom, BoundingCapsule);
|
||||||
|
Monitor.Exit(typeof(OdeScene));
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool Flying
|
public override bool Flying
|
||||||
|
@ -345,6 +368,7 @@ namespace OpenSim.Region.Physics.OdePlugin
|
||||||
|
|
||||||
public void Move(float timeStep)
|
public void Move(float timeStep)
|
||||||
{
|
{
|
||||||
|
// no lock; for now it's only called from within Simulate()
|
||||||
PhysicsVector vec = new PhysicsVector();
|
PhysicsVector vec = new PhysicsVector();
|
||||||
d.Vector3 vel = d.BodyGetLinearVel(BoundingCapsule);
|
d.Vector3 vel = d.BodyGetLinearVel(BoundingCapsule);
|
||||||
vec.X = (vel.X - this._velocity.X) * -75000.0f;
|
vec.X = (vel.X - this._velocity.X) * -75000.0f;
|
||||||
|
@ -358,6 +382,7 @@ namespace OpenSim.Region.Physics.OdePlugin
|
||||||
|
|
||||||
public void UpdatePosition()
|
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);
|
d.Vector3 vec = d.BodyGetPosition(BoundingCapsule);
|
||||||
this._position.X = vec.X;
|
this._position.X = vec.X;
|
||||||
this._position.Y = vec.Y;
|
this._position.Y = vec.Y;
|
||||||
|
@ -382,6 +407,7 @@ 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));
|
||||||
d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
|
d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
|
||||||
d.Quaternion myrot = new d.Quaternion();
|
d.Quaternion myrot = new d.Quaternion();
|
||||||
myrot.W = rotation.w;
|
myrot.W = rotation.w;
|
||||||
|
@ -389,6 +415,7 @@ namespace OpenSim.Region.Physics.OdePlugin
|
||||||
myrot.Y = rotation.y;
|
myrot.Y = rotation.y;
|
||||||
myrot.Z = rotation.z;
|
myrot.Z = rotation.z;
|
||||||
d.GeomSetQuaternion(prim_geom, ref myrot);
|
d.GeomSetQuaternion(prim_geom, ref myrot);
|
||||||
|
Monitor.Exit(typeof(OdeScene));
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool Flying
|
public override bool Flying
|
||||||
|
@ -410,8 +437,12 @@ namespace OpenSim.Region.Physics.OdePlugin
|
||||||
}
|
}
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
|
Console.WriteLine("+++++++++++++++++++++++++++++++++++++++++++ setting pos: " + value);
|
||||||
_position = value;
|
_position = value;
|
||||||
|
Monitor.Enter(typeof(OdeScene));
|
||||||
d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
|
d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
|
||||||
|
Monitor.Exit(typeof(OdeScene));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -423,6 +454,7 @@ namespace OpenSim.Region.Physics.OdePlugin
|
||||||
}
|
}
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
|
Console.WriteLine("+++++++++++++++++++++++++++++++++++++++++++ setting size: " + value);
|
||||||
_size = value;
|
_size = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -459,12 +491,14 @@ namespace OpenSim.Region.Physics.OdePlugin
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
_orientation = value;
|
_orientation = value;
|
||||||
|
Monitor.Enter(typeof(OdeScene));
|
||||||
d.Quaternion myrot = new d.Quaternion();
|
d.Quaternion myrot = new d.Quaternion();
|
||||||
myrot.W = _orientation.w;
|
myrot.W = _orientation.w;
|
||||||
myrot.X = _orientation.x;
|
myrot.X = _orientation.x;
|
||||||
myrot.Y = _orientation.y;
|
myrot.Y = _orientation.y;
|
||||||
myrot.Z = _orientation.z;
|
myrot.Z = _orientation.z;
|
||||||
d.GeomSetQuaternion(prim_geom, ref myrot);
|
d.GeomSetQuaternion(prim_geom, ref myrot);
|
||||||
|
Monitor.Exit(typeof(OdeScene));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue