diff options
author | dan miller | 2007-09-01 11:01:11 +0000 |
---|---|---|
committer | dan miller | 2007-09-01 11:01:11 +0000 |
commit | 0901dfded17bc22e81301be8f3dd1b30b8da4305 (patch) | |
tree | 9c77e4da1889725adde3813545c7b81911a68bfe /OpenSim/Region/Physics/OdePlugin | |
parent | oops -- restoring opensim.ini (diff) | |
download | opensim-SC_OLD-0901dfded17bc22e81301be8f3dd1b30b8da4305.zip opensim-SC_OLD-0901dfded17bc22e81301be8f3dd1b30b8da4305.tar.gz opensim-SC_OLD-0901dfded17bc22e81301be8f3dd1b30b8da4305.tar.bz2 opensim-SC_OLD-0901dfded17bc22e81301be8f3dd1b30b8da4305.tar.xz |
umm, nevermind all that -- this is the real ODE region fix. I'll get subversion someday
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/Physics/OdePlugin/OdePlugin.cs | 55 |
1 files changed, 33 insertions, 22 deletions
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 | |||
73 | 73 | ||
74 | public class OdeScene : PhysicsScene | 74 | public class OdeScene : PhysicsScene |
75 | { | 75 | { |
76 | static public IntPtr world; | 76 | private IntPtr contactgroup; |
77 | static public IntPtr space; | 77 | private IntPtr LandGeom; |
78 | static private IntPtr contactgroup; | ||
79 | static private IntPtr LandGeom; | ||
80 | //static private IntPtr Land; | ||
81 | private double[] _heightmap; | 78 | private double[] _heightmap; |
82 | static private d.NearCallback nearCallback = near; | 79 | private d.NearCallback nearCallback; |
83 | private List<OdeCharacter> _characters = new List<OdeCharacter>(); | 80 | private List<OdeCharacter> _characters = new List<OdeCharacter>(); |
84 | private List<OdePrim> _prims = new List<OdePrim>(); | 81 | private List<OdePrim> _prims = new List<OdePrim>(); |
85 | private static d.ContactGeom[] contacts = new d.ContactGeom[30]; | 82 | private d.ContactGeom[] contacts = new d.ContactGeom[30]; |
86 | private static d.Contact contact; | 83 | private d.Contact contact; |
84 | |||
85 | public IntPtr world; | ||
86 | public IntPtr space; | ||
87 | public static Object OdeLock = new Object(); | 87 | public static Object OdeLock = new Object(); |
88 | |||
88 | public OdeScene() | 89 | public OdeScene() |
89 | { | 90 | { |
91 | nearCallback = near; | ||
90 | contact.surface.mode |= d.ContactFlags.Approx1 | d.ContactFlags.SoftCFM | d.ContactFlags.SoftERP; | 92 | contact.surface.mode |= d.ContactFlags.Approx1 | d.ContactFlags.SoftCFM | d.ContactFlags.SoftERP; |
91 | contact.surface.mu = 10.0f; | 93 | contact.surface.mu = 10.0f; |
92 | contact.surface.bounce = 0.9f; | 94 | contact.surface.bounce = 0.9f; |
@@ -103,11 +105,11 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
103 | d.WorldSetContactSurfaceLayer(world, 0.001f); | 105 | d.WorldSetContactSurfaceLayer(world, 0.001f); |
104 | } | 106 | } |
105 | 107 | ||
106 | this._heightmap = new double[65536]; | 108 | _heightmap = new double[65536]; |
107 | } | 109 | } |
108 | 110 | ||
109 | // This function blatantly ripped off from BoxStack.cs | 111 | // This function blatantly ripped off from BoxStack.cs |
110 | static private void near(IntPtr space, IntPtr g1, IntPtr g2) | 112 | private void near(IntPtr space, IntPtr g1, IntPtr g2) |
111 | { | 113 | { |
112 | // no lock here! It's invoked from within Simulate(), which is thread-locked | 114 | // no lock here! It's invoked from within Simulate(), which is thread-locked |
113 | IntPtr b1 = d.GeomGetBody(g1); | 115 | IntPtr b1 = d.GeomGetBody(g1); |
@@ -116,7 +118,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
116 | return; | 118 | return; |
117 | 119 | ||
118 | int count = d.Collide(g1, g2, 500, contacts, d.ContactGeom.SizeOf); | 120 | int count = d.Collide(g1, g2, 500, contacts, d.ContactGeom.SizeOf); |
119 | for (int i = 0; i < count; ++i) | 121 | for (int i = 0; i < count; i++) |
120 | { | 122 | { |
121 | contact.geom = contacts[i]; | 123 | contact.geom = contacts[i]; |
122 | IntPtr joint = d.JointCreateContact(world, contactgroup, ref contact); | 124 | IntPtr joint = d.JointCreateContact(world, contactgroup, ref contact); |
@@ -125,6 +127,14 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
125 | 127 | ||
126 | } | 128 | } |
127 | 129 | ||
130 | private void collision_optimized() | ||
131 | { | ||
132 | foreach (OdeCharacter chr in _characters) | ||
133 | { | ||
134 | d.SpaceCollide2(space, _characters[_characters.Count - 1].capsule_geom, IntPtr.Zero, nearCallback); | ||
135 | } | ||
136 | } | ||
137 | |||
128 | public override PhysicsActor AddAvatar(PhysicsVector position) | 138 | public override PhysicsActor AddAvatar(PhysicsVector position) |
129 | { | 139 | { |
130 | PhysicsVector pos = new PhysicsVector(); | 140 | PhysicsVector pos = new PhysicsVector(); |
@@ -132,7 +142,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
132 | pos.Y = position.Y; | 142 | pos.Y = position.Y; |
133 | pos.Z = position.Z; | 143 | pos.Z = position.Z; |
134 | OdeCharacter newAv = new OdeCharacter(this, pos); | 144 | OdeCharacter newAv = new OdeCharacter(this, pos); |
135 | this._characters.Add(newAv); | 145 | _characters.Add(newAv); |
136 | return newAv; | 146 | return newAv; |
137 | } | 147 | } |
138 | 148 | ||
@@ -147,13 +157,14 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
147 | lock (OdeLock) | 157 | lock (OdeLock) |
148 | { | 158 | { |
149 | d.GeomDestroy(((OdePrim)prim).prim_geom); | 159 | d.GeomDestroy(((OdePrim)prim).prim_geom); |
150 | this._prims.Remove((OdePrim)prim); | 160 | _prims.Remove((OdePrim)prim); |
151 | } | 161 | } |
152 | } | 162 | } |
153 | } | 163 | } |
154 | 164 | ||
155 | public override PhysicsActor AddPrim(PhysicsVector position, PhysicsVector size, Quaternion rotation) | 165 | public override PhysicsActor AddPrim(PhysicsVector position, PhysicsVector size, Quaternion rotation) |
156 | { | 166 | { |
167 | Console.WriteLine("++++++++++++++++++++++++++++++++++ AddPrim: " + position); | ||
157 | PhysicsVector pos = new PhysicsVector(); | 168 | PhysicsVector pos = new PhysicsVector(); |
158 | pos.X = position.X; | 169 | pos.X = position.X; |
159 | pos.Y = position.Y; | 170 | pos.Y = position.Y; |
@@ -172,7 +183,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
172 | { | 183 | { |
173 | newPrim = new OdePrim(this, pos, siz, rot); | 184 | newPrim = new OdePrim(this, pos, siz, rot); |
174 | } | 185 | } |
175 | this._prims.Add(newPrim); | 186 | _prims.Add(newPrim); |
176 | return newPrim; | 187 | return newPrim; |
177 | } | 188 | } |
178 | 189 | ||
@@ -187,7 +198,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
187 | { | 198 | { |
188 | actor.Move(timeStep); | 199 | actor.Move(timeStep); |
189 | } | 200 | } |
190 | d.SpaceCollide(space, IntPtr.Zero, nearCallback); | 201 | collision_optimized(); |
191 | for (int i = 0; i < 50; i++) | 202 | for (int i = 0; i < 50; i++) |
192 | { | 203 | { |
193 | d.WorldQuickStep(world, timeStep * 0.02f); | 204 | d.WorldQuickStep(world, timeStep * 0.02f); |
@@ -222,7 +233,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
222 | // dbm (danx0r) -- heightmap x,y must be swapped for Ode (should fix ODE, but for now...) | 233 | // dbm (danx0r) -- heightmap x,y must be swapped for Ode (should fix ODE, but for now...) |
223 | int x = i & 0xff; | 234 | int x = i & 0xff; |
224 | int y = i >> 8; | 235 | int y = i >> 8; |
225 | this._heightmap[i] = (double)heightMap[x * 256 + y]; | 236 | _heightmap[i] = (double)heightMap[x * 256 + y]; |
226 | } | 237 | } |
227 | 238 | ||
228 | lock (OdeLock) | 239 | lock (OdeLock) |
@@ -263,9 +274,9 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
263 | private bool flying = false; | 274 | private bool flying = false; |
264 | //private float gravityAccel; | 275 | //private float gravityAccel; |
265 | private IntPtr BoundingCapsule; | 276 | private IntPtr BoundingCapsule; |
266 | IntPtr capsule_geom; | ||
267 | d.Mass capsule_mass; | ||
268 | private OdeScene _parent_scene; | 277 | private OdeScene _parent_scene; |
278 | public IntPtr capsule_geom; | ||
279 | public d.Mass capsule_mass; | ||
269 | 280 | ||
270 | public OdeCharacter(OdeScene parent_scene, PhysicsVector pos) | 281 | public OdeCharacter(OdeScene parent_scene, PhysicsVector pos) |
271 | { | 282 | { |
@@ -276,8 +287,8 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
276 | lock (OdeScene.OdeLock) | 287 | lock (OdeScene.OdeLock) |
277 | { | 288 | { |
278 | d.MassSetCapsule(out capsule_mass, 50.0f, 3, 0.5f, 2f); | 289 | d.MassSetCapsule(out capsule_mass, 50.0f, 3, 0.5f, 2f); |
279 | capsule_geom = d.CreateSphere(OdeScene.space, 1.0f); /// not a typo! Spheres roll, capsules tumble | 290 | capsule_geom = d.CreateSphere(parent_scene.space, 1.0f); /// not a typo! Spheres roll, capsules tumble |
280 | this.BoundingCapsule = d.BodyCreate(OdeScene.world); | 291 | BoundingCapsule = d.BodyCreate(parent_scene.world); |
281 | d.BodySetMass(BoundingCapsule, ref capsule_mass); | 292 | d.BodySetMass(BoundingCapsule, ref capsule_mass); |
282 | d.BodySetPosition(BoundingCapsule, pos.X, pos.Y, pos.Z); | 293 | d.BodySetPosition(BoundingCapsule, pos.X, pos.Y, pos.Z); |
283 | d.GeomSetBody(capsule_geom, BoundingCapsule); | 294 | d.GeomSetBody(capsule_geom, BoundingCapsule); |
@@ -370,7 +381,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
370 | } | 381 | } |
371 | public void SetAcceleration(PhysicsVector accel) | 382 | public void SetAcceleration(PhysicsVector accel) |
372 | { | 383 | { |
373 | this._acceleration = accel; | 384 | _acceleration = accel; |
374 | } | 385 | } |
375 | 386 | ||
376 | public override void AddForce(PhysicsVector force) | 387 | public override void AddForce(PhysicsVector force) |
@@ -432,7 +443,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
432 | _orientation = rotation; | 443 | _orientation = rotation; |
433 | lock (OdeScene.OdeLock) | 444 | lock (OdeScene.OdeLock) |
434 | { | 445 | { |
435 | prim_geom = d.CreateBox(OdeScene.space, _size.X, _size.Y, _size.Z); | 446 | prim_geom = d.CreateBox(parent_scene.space, _size.X, _size.Y, _size.Z); |
436 | d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z); | 447 | d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z); |
437 | d.Quaternion myrot = new d.Quaternion(); | 448 | d.Quaternion myrot = new d.Quaternion(); |
438 | myrot.W = rotation.w; | 449 | myrot.W = rotation.w; |