diff options
author | Robert Adams | 2012-10-12 16:03:03 -0700 |
---|---|---|
committer | Robert Adams | 2012-10-19 10:51:58 -0700 |
commit | fd7a097849b8a405bdd62cfe6d4ee2bbf0a3961c (patch) | |
tree | 93606a507aa16538a73e10956735a66f4306fe18 /OpenSim/Region/Physics | |
parent | minor: Increase attachment name field from 36 to 50 chars in "attachments sho... (diff) | |
download | opensim-SC-fd7a097849b8a405bdd62cfe6d4ee2bbf0a3961c.zip opensim-SC-fd7a097849b8a405bdd62cfe6d4ee2bbf0a3961c.tar.gz opensim-SC-fd7a097849b8a405bdd62cfe6d4ee2bbf0a3961c.tar.bz2 opensim-SC-fd7a097849b8a405bdd62cfe6d4ee2bbf0a3961c.tar.xz |
BulletSim: Update BSCharacter to use API2 interface.
Add capsule shape to BSShapeCollection().
Remember last updated values so inter frame diffs can be computed.
Parameterize avatarStandingFriction and reduce to 10 from 999.
The latter high value made avatars very hard to push.
Set CCD parameters for prims and characters of specified.
Diffstat (limited to 'OpenSim/Region/Physics')
-rw-r--r-- | OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs | 182 | ||||
-rwxr-xr-x | OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs | 12 | ||||
-rw-r--r-- | OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | 66 | ||||
-rw-r--r-- | OpenSim/Region/Physics/BulletSPlugin/BSScene.cs | 21 | ||||
-rwxr-xr-x | OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs | 51 | ||||
-rw-r--r-- | OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs | 11 |
6 files changed, 250 insertions, 93 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs index 2e6b2da..7c2f856 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs | |||
@@ -41,8 +41,6 @@ public class BSCharacter : BSPhysObject | |||
41 | 41 | ||
42 | // private bool _stopped; | 42 | // private bool _stopped; |
43 | private OMV.Vector3 _size; | 43 | private OMV.Vector3 _size; |
44 | private OMV.Vector3 _scale; | ||
45 | private PrimitiveBaseShape _pbs; | ||
46 | private bool _grabbed; | 44 | private bool _grabbed; |
47 | private bool _selected; | 45 | private bool _selected; |
48 | private OMV.Vector3 _position; | 46 | private OMV.Vector3 _position; |
@@ -67,6 +65,10 @@ public class BSCharacter : BSPhysObject | |||
67 | private bool _kinematic; | 65 | private bool _kinematic; |
68 | private float _buoyancy; | 66 | private float _buoyancy; |
69 | 67 | ||
68 | // The friction and velocity of the avatar is modified depending on whether walking or not. | ||
69 | private OMV.Vector3 _appliedVelocity; // the last velocity applied to the avatar | ||
70 | private float _currentFriction; // the friction currently being used (changed by setVelocity). | ||
71 | |||
70 | private OMV.Vector3 _PIDTarget; | 72 | private OMV.Vector3 _PIDTarget; |
71 | private bool _usePID; | 73 | private bool _usePID; |
72 | private float _PIDTau; | 74 | private float _PIDTau; |
@@ -84,13 +86,15 @@ public class BSCharacter : BSPhysObject | |||
84 | _flying = isFlying; | 86 | _flying = isFlying; |
85 | _orientation = OMV.Quaternion.Identity; | 87 | _orientation = OMV.Quaternion.Identity; |
86 | _velocity = OMV.Vector3.Zero; | 88 | _velocity = OMV.Vector3.Zero; |
89 | _appliedVelocity = OMV.Vector3.Zero; | ||
87 | _buoyancy = ComputeBuoyancyFromFlying(isFlying); | 90 | _buoyancy = ComputeBuoyancyFromFlying(isFlying); |
91 | _currentFriction = PhysicsScene.Params.avatarStandingFriction; | ||
88 | 92 | ||
89 | // The dimensions of the avatar capsule are kept in the scale. | 93 | // The dimensions of the avatar capsule are kept in the scale. |
90 | // Physics creates a unit capsule which is scaled by the physics engine. | 94 | // Physics creates a unit capsule which is scaled by the physics engine. |
91 | ComputeAvatarScale(_size); | 95 | ComputeAvatarScale(_size); |
92 | _avatarDensity = PhysicsScene.Params.avatarDensity; | 96 | _avatarDensity = PhysicsScene.Params.avatarDensity; |
93 | // set _avatarVolume and _mass based on capsule size, _density and _scale | 97 | // set _avatarVolume and _mass based on capsule size, _density and Scale |
94 | ComputeAvatarVolumeAndMass(); | 98 | ComputeAvatarVolumeAndMass(); |
95 | 99 | ||
96 | ShapeData shapeData = new ShapeData(); | 100 | ShapeData shapeData = new ShapeData(); |
@@ -99,24 +103,24 @@ public class BSCharacter : BSPhysObject | |||
99 | shapeData.Position = _position; | 103 | shapeData.Position = _position; |
100 | shapeData.Rotation = _orientation; | 104 | shapeData.Rotation = _orientation; |
101 | shapeData.Velocity = _velocity; | 105 | shapeData.Velocity = _velocity; |
102 | shapeData.Scale = _scale; | 106 | shapeData.Scale = Scale; |
103 | shapeData.Mass = _mass; | 107 | shapeData.Mass = _mass; |
104 | shapeData.Buoyancy = _buoyancy; | 108 | shapeData.Buoyancy = _buoyancy; |
105 | shapeData.Static = ShapeData.numericFalse; | 109 | shapeData.Static = ShapeData.numericFalse; |
106 | shapeData.Friction = PhysicsScene.Params.avatarFriction; | 110 | shapeData.Friction = PhysicsScene.Params.avatarStandingFriction; |
107 | shapeData.Restitution = PhysicsScene.Params.avatarRestitution; | 111 | shapeData.Restitution = PhysicsScene.Params.avatarRestitution; |
108 | 112 | ||
109 | // do actual create at taint time | 113 | // do actual create at taint time |
110 | PhysicsScene.TaintedObject("BSCharacter.create", delegate() | 114 | PhysicsScene.TaintedObject("BSCharacter.create", delegate() |
111 | { | 115 | { |
112 | DetailLog("{0},BSCharacter.create,taint", LocalID); | 116 | DetailLog("{0},BSCharacter.create,taint", LocalID); |
113 | BulletSimAPI.CreateObject(PhysicsScene.WorldID, shapeData); | 117 | PhysicsScene.Shapes.GetBodyAndShape(true, PhysicsScene.World, this, shapeData, null, null, null); |
118 | |||
119 | SetPhysicalProperties(); | ||
114 | 120 | ||
115 | // Set the buoyancy for flying. This will be refactored when all the settings happen in C#. | 121 | // Set the buoyancy for flying. This will be refactored when all the settings happen in C#. |
116 | // If not set at creation, the avatar will stop flying when created after crossing a region boundry. | 122 | // If not set at creation, the avatar will stop flying when created after crossing a region boundry. |
117 | BulletSimAPI.SetObjectBuoyancy(PhysicsScene.WorldID, LocalID, _buoyancy); | 123 | ForceBuoyancy = _buoyancy; |
118 | |||
119 | BSBody = new BulletBody(LocalID, BulletSimAPI.GetBodyHandle2(PhysicsScene.World.ptr, LocalID)); | ||
120 | 124 | ||
121 | // This works here because CreateObject has already put the character into the physical world. | 125 | // This works here because CreateObject has already put the character into the physical world. |
122 | BulletSimAPI.SetCollisionFilterMask2(BSBody.ptr, | 126 | BulletSimAPI.SetCollisionFilterMask2(BSBody.ptr, |
@@ -131,10 +135,40 @@ public class BSCharacter : BSPhysObject | |||
131 | DetailLog("{0},BSCharacter.Destroy", LocalID); | 135 | DetailLog("{0},BSCharacter.Destroy", LocalID); |
132 | PhysicsScene.TaintedObject("BSCharacter.destroy", delegate() | 136 | PhysicsScene.TaintedObject("BSCharacter.destroy", delegate() |
133 | { | 137 | { |
134 | BulletSimAPI.DestroyObject(PhysicsScene.WorldID, LocalID); | 138 | PhysicsScene.Shapes.DereferenceBody(BSBody, true, null); |
139 | PhysicsScene.Shapes.DereferenceShape(BSShape, true, null); | ||
135 | }); | 140 | }); |
136 | } | 141 | } |
137 | 142 | ||
143 | private void SetPhysicalProperties() | ||
144 | { | ||
145 | BulletSimAPI.RemoveObjectFromWorld2(PhysicsScene.World.ptr, BSBody.ptr); | ||
146 | |||
147 | ZeroMotion(); | ||
148 | |||
149 | OMV.Vector3 localInertia = BulletSimAPI.CalculateLocalInertia2(BSBody.ptr, MassRaw); | ||
150 | BulletSimAPI.SetMassProps2(BSBody.ptr, MassRaw, localInertia); | ||
151 | |||
152 | // Set the velocity and compute the proper friction | ||
153 | ForceVelocity = _velocity; | ||
154 | |||
155 | BulletSimAPI.SetFriction2(BSBody.ptr, _currentFriction); | ||
156 | BulletSimAPI.SetRestitution2(BSBody.ptr, PhysicsScene.Params.avatarRestitution); | ||
157 | |||
158 | BulletSimAPI.SetLocalScaling2(BSShape.ptr, Scale); | ||
159 | BulletSimAPI.SetContactProcessingThreshold2(BSBody.ptr, PhysicsScene.Params.contactProcessingThreshold); | ||
160 | |||
161 | if (PhysicsScene.Params.ccdMotionThreshold > 0f) | ||
162 | { | ||
163 | BulletSimAPI.SetCcdMotionThreshold2(BSBody.ptr, PhysicsScene.Params.ccdMotionThreshold); | ||
164 | BulletSimAPI.SetCcdSweepSphereRadius2(BSBody.ptr, PhysicsScene.Params.ccdSweptSphereRadius); | ||
165 | } | ||
166 | |||
167 | BulletSimAPI.SetActivationState2(BSBody.ptr, (int)ActivationState.DISABLE_DEACTIVATION); | ||
168 | |||
169 | BulletSimAPI.AddObjectToWorld2(PhysicsScene.World.ptr, BSBody.ptr); | ||
170 | } | ||
171 | |||
138 | public override void RequestPhysicsterseUpdate() | 172 | public override void RequestPhysicsterseUpdate() |
139 | { | 173 | { |
140 | base.RequestPhysicsterseUpdate(); | 174 | base.RequestPhysicsterseUpdate(); |
@@ -147,7 +181,7 @@ public class BSCharacter : BSPhysObject | |||
147 | get | 181 | get |
148 | { | 182 | { |
149 | // Avatar capsule size is kept in the scale parameter. | 183 | // Avatar capsule size is kept in the scale parameter. |
150 | return new OMV.Vector3(_scale.X * 2, _scale.Y * 2, _scale.Z); | 184 | return new OMV.Vector3(Scale.X * 2, Scale.Y * 2, Scale.Z); |
151 | } | 185 | } |
152 | 186 | ||
153 | set { | 187 | set { |
@@ -162,22 +196,25 @@ public class BSCharacter : BSPhysObject | |||
162 | 196 | ||
163 | PhysicsScene.TaintedObject("BSCharacter.setSize", delegate() | 197 | PhysicsScene.TaintedObject("BSCharacter.setSize", delegate() |
164 | { | 198 | { |
165 | BulletSimAPI.SetObjectScaleMass(PhysicsScene.WorldID, LocalID, _scale, _mass, true); | 199 | BulletSimAPI.SetLocalScaling2(BSBody.ptr, Scale); |
200 | OMV.Vector3 localInertia = BulletSimAPI.CalculateLocalInertia2(BSBody.ptr, MassRaw); | ||
201 | BulletSimAPI.SetMassProps2(BSBody.ptr, MassRaw, localInertia); | ||
166 | }); | 202 | }); |
167 | 203 | ||
168 | } | 204 | } |
169 | } | 205 | } |
170 | public override PrimitiveBaseShape Shape { | 206 | public override OMV.Vector3 Scale { get; set; } |
171 | set { _pbs = value; | 207 | private PrimitiveBaseShape _pbs; |
172 | } | 208 | public override PrimitiveBaseShape Shape |
209 | { | ||
210 | set { _pbs = value;} | ||
173 | } | 211 | } |
212 | |||
174 | public override bool Grabbed { | 213 | public override bool Grabbed { |
175 | set { _grabbed = value; | 214 | set { _grabbed = value; } |
176 | } | ||
177 | } | 215 | } |
178 | public override bool Selected { | 216 | public override bool Selected { |
179 | set { _selected = value; | 217 | set { _selected = value; } |
180 | } | ||
181 | } | 218 | } |
182 | public override void CrossingFailure() { return; } | 219 | public override void CrossingFailure() { return; } |
183 | public override void link(PhysicsActor obj) { return; } | 220 | public override void link(PhysicsActor obj) { return; } |
@@ -204,7 +241,7 @@ public class BSCharacter : BSPhysObject | |||
204 | 241 | ||
205 | public override OMV.Vector3 Position { | 242 | public override OMV.Vector3 Position { |
206 | get { | 243 | get { |
207 | // _position = BulletSimAPI.GetObjectPosition(Scene.WorldID, _localID); | 244 | // _position = BulletSimAPI.GetObjectPosition2(Scene.World.ptr, LocalID); |
208 | return _position; | 245 | return _position; |
209 | } | 246 | } |
210 | set { | 247 | set { |
@@ -214,7 +251,7 @@ public class BSCharacter : BSPhysObject | |||
214 | PhysicsScene.TaintedObject("BSCharacter.setPosition", delegate() | 251 | PhysicsScene.TaintedObject("BSCharacter.setPosition", delegate() |
215 | { | 252 | { |
216 | DetailLog("{0},BSCharacter.SetPosition,taint,pos={1},orient={2}", LocalID, _position, _orientation); | 253 | DetailLog("{0},BSCharacter.SetPosition,taint,pos={1},orient={2}", LocalID, _position, _orientation); |
217 | BulletSimAPI.SetObjectTranslation(PhysicsScene.WorldID, LocalID, _position, _orientation); | 254 | BulletSimAPI.SetTranslation2(BSBody.ptr, _position, _orientation); |
218 | }); | 255 | }); |
219 | } | 256 | } |
220 | } | 257 | } |
@@ -273,7 +310,7 @@ public class BSCharacter : BSPhysObject | |||
273 | BSScene.TaintCallback sanityOperation = delegate() | 310 | BSScene.TaintCallback sanityOperation = delegate() |
274 | { | 311 | { |
275 | DetailLog("{0},BSCharacter.PositionSanityCheck,taint,pos={1},orient={2}", LocalID, _position, _orientation); | 312 | DetailLog("{0},BSCharacter.PositionSanityCheck,taint,pos={1},orient={2}", LocalID, _position, _orientation); |
276 | BulletSimAPI.SetObjectTranslation(PhysicsScene.WorldID, LocalID, _position, _orientation); | 313 | BulletSimAPI.SetTranslation2(BSBody.ptr, _position, _orientation); |
277 | }; | 314 | }; |
278 | if (inTaintTime) | 315 | if (inTaintTime) |
279 | sanityOperation(); | 316 | sanityOperation(); |
@@ -284,11 +321,7 @@ public class BSCharacter : BSPhysObject | |||
284 | return ret; | 321 | return ret; |
285 | } | 322 | } |
286 | 323 | ||
287 | public override float Mass { | 324 | public override float Mass { get { return _mass; } } |
288 | get { | ||
289 | return _mass; | ||
290 | } | ||
291 | } | ||
292 | 325 | ||
293 | // used when we only want this prim's mass and not the linkset thing | 326 | // used when we only want this prim's mass and not the linkset thing |
294 | public override float MassRaw { get {return _mass; } } | 327 | public override float MassRaw { get {return _mass; } } |
@@ -301,15 +334,13 @@ public class BSCharacter : BSPhysObject | |||
301 | PhysicsScene.TaintedObject("BSCharacter.SetForce", delegate() | 334 | PhysicsScene.TaintedObject("BSCharacter.SetForce", delegate() |
302 | { | 335 | { |
303 | DetailLog("{0},BSCharacter.setForce,taint,force={1}", LocalID, _force); | 336 | DetailLog("{0},BSCharacter.setForce,taint,force={1}", LocalID, _force); |
304 | BulletSimAPI.SetObjectForce(PhysicsScene.WorldID, LocalID, _force); | 337 | BulletSimAPI.SetObjectForce2(BSBody.ptr, _force); |
305 | }); | 338 | }); |
306 | } | 339 | } |
307 | } | 340 | } |
308 | 341 | ||
309 | public override int VehicleType { | 342 | // Avatars don't do vehicles |
310 | get { return 0; } | 343 | public override int VehicleType { get { return 0; } set { return; } } |
311 | set { return; } | ||
312 | } | ||
313 | public override void VehicleFloatParam(int param, float value) { } | 344 | public override void VehicleFloatParam(int param, float value) { } |
314 | public override void VehicleVectorParam(int param, OMV.Vector3 value) {} | 345 | public override void VehicleVectorParam(int param, OMV.Vector3 value) {} |
315 | public override void VehicleRotationParam(int param, OMV.Quaternion rotation) { } | 346 | public override void VehicleRotationParam(int param, OMV.Quaternion rotation) { } |
@@ -328,15 +359,35 @@ public class BSCharacter : BSPhysObject | |||
328 | PhysicsScene.TaintedObject("BSCharacter.setVelocity", delegate() | 359 | PhysicsScene.TaintedObject("BSCharacter.setVelocity", delegate() |
329 | { | 360 | { |
330 | DetailLog("{0},BSCharacter.setVelocity,taint,vel={1}", LocalID, _velocity); | 361 | DetailLog("{0},BSCharacter.setVelocity,taint,vel={1}", LocalID, _velocity); |
331 | BulletSimAPI.SetObjectVelocity(PhysicsScene.WorldID, LocalID, _velocity); | 362 | ForceVelocity = _velocity; |
332 | }); | 363 | }); |
333 | } | 364 | } |
334 | } | 365 | } |
335 | public override OMV.Vector3 ForceVelocity { | 366 | public override OMV.Vector3 ForceVelocity { |
336 | get { return _velocity; } | 367 | get { return _velocity; } |
337 | set { | 368 | set { |
369 | // Depending on whether the avatar is moving or not, change the friction | ||
370 | // to keep the avatar from slipping around | ||
371 | if (_velocity.Length() == 0) | ||
372 | { | ||
373 | if (_currentFriction != PhysicsScene.Params.avatarStandingFriction) | ||
374 | { | ||
375 | _currentFriction = PhysicsScene.Params.avatarStandingFriction; | ||
376 | BulletSimAPI.SetFriction2(BSBody.ptr, _currentFriction); | ||
377 | } | ||
378 | } | ||
379 | else | ||
380 | { | ||
381 | if (_currentFriction == 999f) | ||
382 | { | ||
383 | _currentFriction = PhysicsScene.Params.avatarFriction; | ||
384 | BulletSimAPI.SetFriction2(BSBody.ptr, _currentFriction); | ||
385 | } | ||
386 | } | ||
338 | _velocity = value; | 387 | _velocity = value; |
339 | BulletSimAPI.SetObjectVelocity(PhysicsScene.WorldID, LocalID, _velocity); | 388 | _appliedVelocity = value; |
389 | BulletSimAPI.SetLinearVelocity2(BSBody.ptr, _velocity); | ||
390 | BulletSimAPI.Activate2(BSBody.ptr, true); | ||
340 | } | 391 | } |
341 | } | 392 | } |
342 | public override OMV.Vector3 Torque { | 393 | public override OMV.Vector3 Torque { |
@@ -360,8 +411,8 @@ public class BSCharacter : BSPhysObject | |||
360 | // m_log.DebugFormat("{0}: set orientation to {1}", LogHeader, _orientation); | 411 | // m_log.DebugFormat("{0}: set orientation to {1}", LogHeader, _orientation); |
361 | PhysicsScene.TaintedObject("BSCharacter.setOrientation", delegate() | 412 | PhysicsScene.TaintedObject("BSCharacter.setOrientation", delegate() |
362 | { | 413 | { |
363 | // _position = BulletSimAPI.GetObjectPosition(Scene.WorldID, _localID); | 414 | // _position = BulletSimAPI.GetPosition2(BSBody.ptr); |
364 | BulletSimAPI.SetObjectTranslation(PhysicsScene.WorldID, LocalID, _position, _orientation); | 415 | BulletSimAPI.SetTranslation2(BSBody.ptr, _position, _orientation); |
365 | }); | 416 | }); |
366 | } | 417 | } |
367 | } | 418 | } |
@@ -389,12 +440,18 @@ public class BSCharacter : BSPhysObject | |||
389 | set { _isPhysical = value; | 440 | set { _isPhysical = value; |
390 | } | 441 | } |
391 | } | 442 | } |
443 | public override bool IsSolid { | ||
444 | get { return true; } | ||
445 | } | ||
446 | public override bool IsStatic { | ||
447 | get { return false; } | ||
448 | } | ||
392 | public override bool Flying { | 449 | public override bool Flying { |
393 | get { return _flying; } | 450 | get { return _flying; } |
394 | set { | 451 | set { |
395 | _flying = value; | 452 | _flying = value; |
396 | // simulate flying by changing the effect of gravity | 453 | // simulate flying by changing the effect of gravity |
397 | this.Buoyancy = ComputeBuoyancyFromFlying(_flying); | 454 | Buoyancy = ComputeBuoyancyFromFlying(_flying); |
398 | } | 455 | } |
399 | } | 456 | } |
400 | // Flying is implimented by changing the avatar's buoyancy. | 457 | // Flying is implimented by changing the avatar's buoyancy. |
@@ -454,10 +511,19 @@ public class BSCharacter : BSPhysObject | |||
454 | PhysicsScene.TaintedObject("BSCharacter.setBuoyancy", delegate() | 511 | PhysicsScene.TaintedObject("BSCharacter.setBuoyancy", delegate() |
455 | { | 512 | { |
456 | DetailLog("{0},BSCharacter.setBuoyancy,taint,buoy={1}", LocalID, _buoyancy); | 513 | DetailLog("{0},BSCharacter.setBuoyancy,taint,buoy={1}", LocalID, _buoyancy); |
457 | BulletSimAPI.SetObjectBuoyancy(PhysicsScene.WorldID, LocalID, _buoyancy); | 514 | ForceBuoyancy = _buoyancy; |
458 | }); | 515 | }); |
459 | } | 516 | } |
460 | } | 517 | } |
518 | public override float ForceBuoyancy { | ||
519 | get { return _buoyancy; } | ||
520 | set { _buoyancy = value; | ||
521 | DetailLog("{0},BSCharacter.setForceBuoyancy,taint,buoy={1}", LocalID, _buoyancy); | ||
522 | // Buoyancy is faked by changing the gravity applied to the object | ||
523 | float grav = PhysicsScene.Params.gravity * (1f - _buoyancy); | ||
524 | BulletSimAPI.SetGravity2(BSBody.ptr, new OMV.Vector3(0f, 0f, grav)); | ||
525 | } | ||
526 | } | ||
461 | 527 | ||
462 | // Used for MoveTo | 528 | // Used for MoveTo |
463 | public override OMV.Vector3 PIDTarget { | 529 | public override OMV.Vector3 PIDTarget { |
@@ -518,27 +584,29 @@ public class BSCharacter : BSPhysObject | |||
518 | 584 | ||
519 | private void ComputeAvatarScale(OMV.Vector3 size) | 585 | private void ComputeAvatarScale(OMV.Vector3 size) |
520 | { | 586 | { |
521 | _scale.X = PhysicsScene.Params.avatarCapsuleRadius; | 587 | OMV.Vector3 newScale = OMV.Vector3.Zero; |
522 | _scale.Y = PhysicsScene.Params.avatarCapsuleRadius; | 588 | newScale.X = PhysicsScene.Params.avatarCapsuleRadius; |
589 | newScale.Y = PhysicsScene.Params.avatarCapsuleRadius; | ||
523 | 590 | ||
524 | // The 1.15 came from ODE but it seems to cause the avatar to float off the ground | 591 | // The 1.15 came from ODE but it seems to cause the avatar to float off the ground |
525 | // _scale.Z = (_size.Z * 1.15f) - (_scale.X + _scale.Y); | 592 | // Scale.Z = (_size.Z * 1.15f) - (Scale.X + Scale.Y); |
526 | _scale.Z = (_size.Z) - (_scale.X + _scale.Y); | 593 | newScale.Z = (_size.Z) - (Scale.X + Scale.Y); |
594 | Scale = newScale; | ||
527 | } | 595 | } |
528 | 596 | ||
529 | // set _avatarVolume and _mass based on capsule size, _density and _scale | 597 | // set _avatarVolume and _mass based on capsule size, _density and Scale |
530 | private void ComputeAvatarVolumeAndMass() | 598 | private void ComputeAvatarVolumeAndMass() |
531 | { | 599 | { |
532 | _avatarVolume = (float)( | 600 | _avatarVolume = (float)( |
533 | Math.PI | 601 | Math.PI |
534 | * _scale.X | 602 | * Scale.X |
535 | * _scale.Y // the area of capsule cylinder | 603 | * Scale.Y // the area of capsule cylinder |
536 | * _scale.Z // times height of capsule cylinder | 604 | * Scale.Z // times height of capsule cylinder |
537 | + 1.33333333f | 605 | + 1.33333333f |
538 | * Math.PI | 606 | * Math.PI |
539 | * _scale.X | 607 | * Scale.X |
540 | * Math.Min(_scale.X, _scale.Y) | 608 | * Math.Min(Scale.X, Scale.Y) |
541 | * _scale.Y // plus the volume of the capsule end caps | 609 | * Scale.Y // plus the volume of the capsule end caps |
542 | ); | 610 | ); |
543 | _mass = _avatarDensity * _avatarVolume; | 611 | _mass = _avatarDensity * _avatarVolume; |
544 | } | 612 | } |
@@ -555,6 +623,22 @@ public class BSCharacter : BSPhysObject | |||
555 | // Do some sanity checking for the avatar. Make sure it's above ground and inbounds. | 623 | // Do some sanity checking for the avatar. Make sure it's above ground and inbounds. |
556 | PositionSanityCheck2(true); | 624 | PositionSanityCheck2(true); |
557 | 625 | ||
626 | // remember the current and last set values | ||
627 | LastEntityProperties = CurrentEntityProperties; | ||
628 | CurrentEntityProperties = entprop; | ||
629 | |||
630 | if (entprop.Velocity != LastEntityProperties.Velocity) | ||
631 | { | ||
632 | // Changes in the velocity are suppressed in avatars. | ||
633 | // That's just the way they are defined. | ||
634 | OMV.Vector3 avVel = new OMV.Vector3(_appliedVelocity.X, _appliedVelocity.Y, entprop.Velocity.Z); | ||
635 | _velocity = avVel; | ||
636 | BulletSimAPI.SetLinearVelocity2(BSBody.ptr, avVel); | ||
637 | } | ||
638 | |||
639 | // Tell the linkset about this | ||
640 | Linkset.UpdateProperties(this); | ||
641 | |||
558 | // Avatars don't report their changes the usual way. Changes are checked for in the heartbeat loop. | 642 | // Avatars don't report their changes the usual way. Changes are checked for in the heartbeat loop. |
559 | // base.RequestPhysicsterseUpdate(); | 643 | // base.RequestPhysicsterseUpdate(); |
560 | 644 | ||
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs index cae599c..34dec26 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs | |||
@@ -69,6 +69,16 @@ public abstract class BSPhysObject : PhysicsActor | |||
69 | // Reference to the physical shape (btCollisionShape) of this object | 69 | // Reference to the physical shape (btCollisionShape) of this object |
70 | public BulletShape BSShape; | 70 | public BulletShape BSShape; |
71 | 71 | ||
72 | // When the physical properties are updated, an EntityProperty holds the update values. | ||
73 | // Keep the current and last EntityProperties to enable computation of differences | ||
74 | // between the current update and the previous values. | ||
75 | public EntityProperties CurrentEntityProperties { get; set; } | ||
76 | public EntityProperties LastEntityProperties { get; set; } | ||
77 | |||
78 | public abstract OMV.Vector3 Scale { get; set; } | ||
79 | public abstract bool IsSolid { get; } | ||
80 | public abstract bool IsStatic { get; } | ||
81 | |||
72 | // Stop all physical motion. | 82 | // Stop all physical motion. |
73 | public abstract void ZeroMotion(); | 83 | public abstract void ZeroMotion(); |
74 | 84 | ||
@@ -89,6 +99,8 @@ public abstract class BSPhysObject : PhysicsActor | |||
89 | 99 | ||
90 | public abstract OMV.Vector3 ForceRotationalVelocity { get; set; } | 100 | public abstract OMV.Vector3 ForceRotationalVelocity { get; set; } |
91 | 101 | ||
102 | public abstract float ForceBuoyancy { get; set; } | ||
103 | |||
92 | #region Collisions | 104 | #region Collisions |
93 | 105 | ||
94 | // Requested number of milliseconds between collision events. Zero means disabled. | 106 | // Requested number of milliseconds between collision events. Zero means disabled. |
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs index 6a4365c..3421e30 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | |||
@@ -172,11 +172,8 @@ public sealed class BSPrim : BSPhysObject | |||
172 | } | 172 | } |
173 | // Scale is what we set in the physics engine. It is different than 'size' in that | 173 | // Scale is what we set in the physics engine. It is different than 'size' in that |
174 | // 'size' can be encorporated into the mesh. In that case, the scale is <1,1,1>. | 174 | // 'size' can be encorporated into the mesh. In that case, the scale is <1,1,1>. |
175 | public OMV.Vector3 Scale | 175 | public override OMV.Vector3 Scale { get; set; } |
176 | { | 176 | |
177 | get { return _scale; } | ||
178 | set { _scale = value; } | ||
179 | } | ||
180 | public override PrimitiveBaseShape Shape { | 177 | public override PrimitiveBaseShape Shape { |
181 | set { | 178 | set { |
182 | _pbs = value; | 179 | _pbs = value; |
@@ -325,9 +322,9 @@ public sealed class BSPrim : BSPhysObject | |||
325 | } | 322 | } |
326 | 323 | ||
327 | // A version of the sanity check that also makes sure a new position value is | 324 | // A version of the sanity check that also makes sure a new position value is |
328 | // pushed back to the physics engine. This routine would be used by anyone | 325 | // pushed to the physics engine. This routine would be used by anyone |
329 | // who is not already pushing the value. | 326 | // who is not already pushing the value. |
330 | private bool PositionSanityCheck2(bool inTaintTime) | 327 | private bool PositionSanityCheck(bool inTaintTime) |
331 | { | 328 | { |
332 | bool ret = false; | 329 | bool ret = false; |
333 | if (PositionSanityCheck()) | 330 | if (PositionSanityCheck()) |
@@ -336,8 +333,8 @@ public sealed class BSPrim : BSPhysObject | |||
336 | // just assign to "Position" because of potential call loops. | 333 | // just assign to "Position" because of potential call loops. |
337 | BSScene.TaintCallback sanityOperation = delegate() | 334 | BSScene.TaintCallback sanityOperation = delegate() |
338 | { | 335 | { |
339 | DetailLog("{0},BSPrim.PositionSanityCheck,taint,pos={1},orient={2}", LocalID, _position, _orientation); | 336 | DetailLog("{0},BSPrim.PositionSanityCheck,taint,pos={1},orient={2}", LocalID, _position, _orientation); |
340 | BulletSimAPI.SetObjectTranslation(PhysicsScene.WorldID, LocalID, _position, _orientation); | 337 | ForcePosition = _position; |
341 | }; | 338 | }; |
342 | if (inTaintTime) | 339 | if (inTaintTime) |
343 | sanityOperation(); | 340 | sanityOperation(); |
@@ -547,13 +544,13 @@ public sealed class BSPrim : BSPhysObject | |||
547 | } | 544 | } |
548 | 545 | ||
549 | // An object is static (does not move) if selected or not physical | 546 | // An object is static (does not move) if selected or not physical |
550 | private bool IsStatic | 547 | public override bool IsStatic |
551 | { | 548 | { |
552 | get { return _isSelected || !IsPhysical; } | 549 | get { return _isSelected || !IsPhysical; } |
553 | } | 550 | } |
554 | 551 | ||
555 | // An object is solid if it's not phantom and if it's not doing VolumeDetect | 552 | // An object is solid if it's not phantom and if it's not doing VolumeDetect |
556 | public bool IsSolid | 553 | public override bool IsSolid |
557 | { | 554 | { |
558 | get { return !IsPhantom && !_isVolumeDetect; } | 555 | get { return !IsPhantom && !_isVolumeDetect; } |
559 | } | 556 | } |
@@ -631,6 +628,12 @@ public sealed class BSPrim : BSPhysObject | |||
631 | BulletSimAPI.SetMassProps2(BSBody.ptr, 0f, OMV.Vector3.Zero); | 628 | BulletSimAPI.SetMassProps2(BSBody.ptr, 0f, OMV.Vector3.Zero); |
632 | // There is no inertia in a static object | 629 | // There is no inertia in a static object |
633 | BulletSimAPI.UpdateInertiaTensor2(BSBody.ptr); | 630 | BulletSimAPI.UpdateInertiaTensor2(BSBody.ptr); |
631 | // Set collision detection parameters | ||
632 | if (PhysicsScene.Params.ccdMotionThreshold > 0f) | ||
633 | { | ||
634 | BulletSimAPI.SetCcdMotionThreshold2(BSBody.ptr, PhysicsScene.Params.ccdMotionThreshold); | ||
635 | BulletSimAPI.SetCcdSweepSphereRadius2(BSBody.ptr, PhysicsScene.Params.ccdSweptSphereRadius); | ||
636 | } | ||
634 | // There can be special things needed for implementing linksets | 637 | // There can be special things needed for implementing linksets |
635 | Linkset.MakeStatic(this); | 638 | Linkset.MakeStatic(this); |
636 | // The activation state is 'disabled' so Bullet will not try to act on it. | 639 | // The activation state is 'disabled' so Bullet will not try to act on it. |
@@ -662,6 +665,13 @@ public sealed class BSPrim : BSPhysObject | |||
662 | BulletSimAPI.SetMassProps2(BSBody.ptr, _mass, inertia); | 665 | BulletSimAPI.SetMassProps2(BSBody.ptr, _mass, inertia); |
663 | BulletSimAPI.UpdateInertiaTensor2(BSBody.ptr); | 666 | BulletSimAPI.UpdateInertiaTensor2(BSBody.ptr); |
664 | 667 | ||
668 | // Set collision detection parameters | ||
669 | if (PhysicsScene.Params.ccdMotionThreshold > 0f) | ||
670 | { | ||
671 | BulletSimAPI.SetCcdMotionThreshold2(BSBody.ptr, PhysicsScene.Params.ccdMotionThreshold); | ||
672 | BulletSimAPI.SetCcdSweepSphereRadius2(BSBody.ptr, PhysicsScene.Params.ccdSweptSphereRadius); | ||
673 | } | ||
674 | |||
665 | // Various values for simulation limits | 675 | // Various values for simulation limits |
666 | BulletSimAPI.SetDamping2(BSBody.ptr, PhysicsScene.Params.linearDamping, PhysicsScene.Params.angularDamping); | 676 | BulletSimAPI.SetDamping2(BSBody.ptr, PhysicsScene.Params.linearDamping, PhysicsScene.Params.angularDamping); |
667 | BulletSimAPI.SetDeactivationTime2(BSBody.ptr, PhysicsScene.Params.deactivationTime); | 677 | BulletSimAPI.SetDeactivationTime2(BSBody.ptr, PhysicsScene.Params.deactivationTime); |
@@ -812,14 +822,21 @@ public sealed class BSPrim : BSPhysObject | |||
812 | set { | 822 | set { |
813 | _buoyancy = value; | 823 | _buoyancy = value; |
814 | PhysicsScene.TaintedObject("BSPrim.setBuoyancy", delegate() | 824 | PhysicsScene.TaintedObject("BSPrim.setBuoyancy", delegate() |
815 | { | 825 | { |
816 | // DetailLog("{0},BSPrim.SetBuoyancy,taint,buoy={1}", LocalID, _buoyancy); | 826 | ForceBuoyancy = _buoyancy; |
817 | // Buoyancy is faked by changing the gravity applied to the object | ||
818 | float grav = PhysicsScene.Params.gravity * (1f - _buoyancy); | ||
819 | BulletSimAPI.SetGravity2(BSBody.ptr, new OMV.Vector3(0f, 0f, grav)); | ||
820 | }); | 827 | }); |
821 | } | 828 | } |
822 | } | 829 | } |
830 | public override float ForceBuoyancy { | ||
831 | get { return _buoyancy; } | ||
832 | set { | ||
833 | _buoyancy = value; | ||
834 | // DetailLog("{0},BSPrim.setForceBuoyancy,taint,buoy={1}", LocalID, _buoyancy); | ||
835 | // Buoyancy is faked by changing the gravity applied to the object | ||
836 | float grav = PhysicsScene.Params.gravity * (1f - _buoyancy); | ||
837 | BulletSimAPI.SetGravity2(BSBody.ptr, new OMV.Vector3(0f, 0f, grav)); | ||
838 | } | ||
839 | } | ||
823 | 840 | ||
824 | // Used for MoveTo | 841 | // Used for MoveTo |
825 | public override OMV.Vector3 PIDTarget { | 842 | public override OMV.Vector3 PIDTarget { |
@@ -1269,8 +1286,8 @@ public sealed class BSPrim : BSPhysObject | |||
1269 | const float VELOCITY_TOLERANCE = 0.001f; | 1286 | const float VELOCITY_TOLERANCE = 0.001f; |
1270 | const float POSITION_TOLERANCE = 0.05f; | 1287 | const float POSITION_TOLERANCE = 0.05f; |
1271 | const float ACCELERATION_TOLERANCE = 0.01f; | 1288 | const float ACCELERATION_TOLERANCE = 0.01f; |
1272 | const float ROTATIONAL_VELOCITY_TOLERANCE = 0.01f; | 1289 | const float ROTATIONAL_VELOCITY_TOLERANCE = 0.01f; |
1273 | 1290 | ||
1274 | public override void UpdateProperties(EntityProperties entprop) | 1291 | public override void UpdateProperties(EntityProperties entprop) |
1275 | { | 1292 | { |
1276 | /* | 1293 | /* |
@@ -1326,11 +1343,13 @@ public sealed class BSPrim : BSPhysObject | |||
1326 | _orientation = entprop.Rotation; | 1343 | _orientation = entprop.Rotation; |
1327 | _velocity = entprop.Velocity; | 1344 | _velocity = entprop.Velocity; |
1328 | _acceleration = entprop.Acceleration; | 1345 | _acceleration = entprop.Acceleration; |
1329 | _rotationalVelocity = entprop.RotationalVelocity; | 1346 | _rotationalVelocity = entprop.RotationalVelocity; |
1347 | |||
1348 | // remember the current and last set values | ||
1349 | LastEntityProperties = CurrentEntityProperties; | ||
1350 | CurrentEntityProperties = entprop; | ||
1330 | 1351 | ||
1331 | PositionSanityCheck2(true); | 1352 | PositionSanityCheck(true); |
1332 | |||
1333 | Linkset.UpdateProperties(this); | ||
1334 | 1353 | ||
1335 | DetailLog("{0},BSPrim.UpdateProperties,call,pos={1},orient={2},vel={3},accel={4},rotVel={5}", | 1354 | DetailLog("{0},BSPrim.UpdateProperties,call,pos={1},orient={2},vel={3},accel={4},rotVel={5}", |
1336 | LocalID, _position, _orientation, _velocity, _acceleration, _rotationalVelocity); | 1355 | LocalID, _position, _orientation, _velocity, _acceleration, _rotationalVelocity); |
@@ -1348,6 +1367,9 @@ public sealed class BSPrim : BSPhysObject | |||
1348 | entprop.Acceleration, entprop.RotationalVelocity); | 1367 | entprop.Acceleration, entprop.RotationalVelocity); |
1349 | } | 1368 | } |
1350 | */ | 1369 | */ |
1370 | // The linkset implimentation might want to know about this. | ||
1371 | |||
1372 | Linkset.UpdateProperties(this); | ||
1351 | } | 1373 | } |
1352 | } | 1374 | } |
1353 | } | 1375 | } |
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs index 2c3c481..5158011 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs | |||
@@ -256,10 +256,10 @@ public class BSScene : PhysicsScene, IPhysicsParameters | |||
256 | Vector3 worldExtent = new Vector3(Constants.RegionSize, Constants.RegionSize, Constants.RegionHeight); | 256 | Vector3 worldExtent = new Vector3(Constants.RegionSize, Constants.RegionSize, Constants.RegionHeight); |
257 | 257 | ||
258 | // m_log.DebugFormat("{0}: Initialize: Calling BulletSimAPI.Initialize.", LogHeader); | 258 | // m_log.DebugFormat("{0}: Initialize: Calling BulletSimAPI.Initialize.", LogHeader); |
259 | WorldID = BulletSimAPI.Initialize(worldExtent, m_paramsHandle.AddrOfPinnedObject(), | 259 | World = new BulletSim(0, this, BulletSimAPI.Initialize2(worldExtent, m_paramsHandle.AddrOfPinnedObject(), |
260 | m_maxCollisionsPerFrame, m_collisionArrayPinnedHandle.AddrOfPinnedObject(), | 260 | m_maxCollisionsPerFrame, m_collisionArrayPinnedHandle.AddrOfPinnedObject(), |
261 | m_maxUpdatesPerFrame, m_updateArrayPinnedHandle.AddrOfPinnedObject(), | 261 | m_maxUpdatesPerFrame, m_updateArrayPinnedHandle.AddrOfPinnedObject(), |
262 | m_DebugLogCallbackHandle); | 262 | m_DebugLogCallbackHandle)); |
263 | 263 | ||
264 | // Initialization to support the transition to a new API which puts most of the logic | 264 | // Initialization to support the transition to a new API which puts most of the logic |
265 | // into the C# code so it is easier to modify and add to. | 265 | // into the C# code so it is easier to modify and add to. |
@@ -360,7 +360,7 @@ public class BSScene : PhysicsScene, IPhysicsParameters | |||
360 | } | 360 | } |
361 | 361 | ||
362 | // Anything left in the unmanaged code should be cleaned out | 362 | // Anything left in the unmanaged code should be cleaned out |
363 | BulletSimAPI.Shutdown(WorldID); | 363 | BulletSimAPI.Shutdown2(World.ptr); |
364 | 364 | ||
365 | // Not logging any more | 365 | // Not logging any more |
366 | PhysicsLogging.Close(); | 366 | PhysicsLogging.Close(); |
@@ -498,7 +498,7 @@ public class BSScene : PhysicsScene, IPhysicsParameters | |||
498 | { | 498 | { |
499 | if (PhysicsLogging.Enabled) beforeTime = Util.EnvironmentTickCount(); | 499 | if (PhysicsLogging.Enabled) beforeTime = Util.EnvironmentTickCount(); |
500 | 500 | ||
501 | numSubSteps = BulletSimAPI.PhysicsStep(WorldID, timeStep, m_maxSubSteps, m_fixedTimeStep, | 501 | numSubSteps = BulletSimAPI.PhysicsStep2(World.ptr, timeStep, m_maxSubSteps, m_fixedTimeStep, |
502 | out updatedEntityCount, out updatedEntitiesPtr, out collidersCount, out collidersPtr); | 502 | out updatedEntityCount, out updatedEntitiesPtr, out collidersCount, out collidersPtr); |
503 | 503 | ||
504 | if (PhysicsLogging.Enabled) simTime = Util.EnvironmentTickCountSubtract(beforeTime); | 504 | if (PhysicsLogging.Enabled) simTime = Util.EnvironmentTickCountSubtract(beforeTime); |
@@ -1011,6 +1011,11 @@ public class BSScene : PhysicsScene, IPhysicsParameters | |||
1011 | (s,cf,p,v) => { s.m_params[0].avatarFriction = cf.GetFloat(p, v); }, | 1011 | (s,cf,p,v) => { s.m_params[0].avatarFriction = cf.GetFloat(p, v); }, |
1012 | (s) => { return s.m_params[0].avatarFriction; }, | 1012 | (s) => { return s.m_params[0].avatarFriction; }, |
1013 | (s,p,l,v) => { s.UpdateParameterObject(ref s.m_params[0].avatarFriction, p, l, v); } ), | 1013 | (s,p,l,v) => { s.UpdateParameterObject(ref s.m_params[0].avatarFriction, p, l, v); } ), |
1014 | new ParameterDefn("AvatarStandingFriction", "Avatar friction when standing. Changed on avatar recreation.", | ||
1015 | 10f, | ||
1016 | (s,cf,p,v) => { s.m_params[0].avatarStandingFriction = cf.GetFloat(p, v); }, | ||
1017 | (s) => { return s.m_params[0].avatarStandingFriction; }, | ||
1018 | (s,p,l,v) => { s.m_params[0].avatarStandingFriction = v; } ), | ||
1014 | new ParameterDefn("AvatarDensity", "Density of an avatar. Changed on avatar recreation.", | 1019 | new ParameterDefn("AvatarDensity", "Density of an avatar. Changed on avatar recreation.", |
1015 | 60f, | 1020 | 60f, |
1016 | (s,cf,p,v) => { s.m_params[0].avatarDensity = cf.GetFloat(p, v); }, | 1021 | (s,cf,p,v) => { s.m_params[0].avatarDensity = cf.GetFloat(p, v); }, |
@@ -1246,7 +1251,9 @@ public class BSScene : PhysicsScene, IPhysicsParameters | |||
1246 | case PhysParameterEntry.APPLY_TO_NONE: | 1251 | case PhysParameterEntry.APPLY_TO_NONE: |
1247 | defaultLoc = val; // setting only the default value | 1252 | defaultLoc = val; // setting only the default value |
1248 | break; | 1253 | break; |
1249 | case PhysParameterEntry.APPLY_TO_ALL: | 1254 | case PhysParameterEntry.APPLY_TO_ALL: |
1255 | m_log.ErrorFormat("{0} Cannot change parameters of multiple objects. Someday it will be added.", LogHeader); | ||
1256 | /* | ||
1250 | defaultLoc = val; // setting ALL also sets the default value | 1257 | defaultLoc = val; // setting ALL also sets the default value |
1251 | List<uint> objectIDs = lIDs; | 1258 | List<uint> objectIDs = lIDs; |
1252 | string xparm = parm.ToLower(); | 1259 | string xparm = parm.ToLower(); |
@@ -1257,6 +1264,7 @@ public class BSScene : PhysicsScene, IPhysicsParameters | |||
1257 | BulletSimAPI.UpdateParameter(WorldID, lID, xparm, xval); | 1264 | BulletSimAPI.UpdateParameter(WorldID, lID, xparm, xval); |
1258 | } | 1265 | } |
1259 | }); | 1266 | }); |
1267 | */ | ||
1260 | break; | 1268 | break; |
1261 | default: | 1269 | default: |
1262 | // setting only one localID | 1270 | // setting only one localID |
@@ -1268,12 +1276,15 @@ public class BSScene : PhysicsScene, IPhysicsParameters | |||
1268 | // schedule the actual updating of the paramter to when the phys engine is not busy | 1276 | // schedule the actual updating of the paramter to when the phys engine is not busy |
1269 | protected void TaintedUpdateParameter(string parm, uint localID, float val) | 1277 | protected void TaintedUpdateParameter(string parm, uint localID, float val) |
1270 | { | 1278 | { |
1279 | m_log.ErrorFormat("{0} Cannot change parameters of base objects. Someday it will be added.", LogHeader); | ||
1280 | /* | ||
1271 | uint xlocalID = localID; | 1281 | uint xlocalID = localID; |
1272 | string xparm = parm.ToLower(); | 1282 | string xparm = parm.ToLower(); |
1273 | float xval = val; | 1283 | float xval = val; |
1274 | TaintedObject("BSScene.TaintedUpdateParameter", delegate() { | 1284 | TaintedObject("BSScene.TaintedUpdateParameter", delegate() { |
1275 | BulletSimAPI.UpdateParameter(WorldID, xlocalID, xparm, xval); | 1285 | BulletSimAPI.UpdateParameter(WorldID, xlocalID, xparm, xval); |
1276 | }); | 1286 | }); |
1287 | */ | ||
1277 | } | 1288 | } |
1278 | 1289 | ||
1279 | // Get parameter. | 1290 | // Get parameter. |
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs index d189f1d..7d0f84a 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs | |||
@@ -93,7 +93,7 @@ public class BSShapeCollection : IDisposable | |||
93 | // sure the body is of the right type. | 93 | // sure the body is of the right type. |
94 | // Return 'true' if either the body or the shape changed. | 94 | // Return 'true' if either the body or the shape changed. |
95 | // Called at taint-time!! | 95 | // Called at taint-time!! |
96 | public bool GetBodyAndShape(bool forceRebuild, BulletSim sim, BSPrim prim, | 96 | public bool GetBodyAndShape(bool forceRebuild, BulletSim sim, BSPhysObject prim, |
97 | ShapeData shapeData, PrimitiveBaseShape pbs, | 97 | ShapeData shapeData, PrimitiveBaseShape pbs, |
98 | ShapeDestructionCallback shapeCallback, BodyDestructionCallback bodyCallback) | 98 | ShapeDestructionCallback shapeCallback, BodyDestructionCallback bodyCallback) |
99 | { | 99 | { |
@@ -351,19 +351,30 @@ public class BSShapeCollection : IDisposable | |||
351 | 351 | ||
352 | // Create the geometry information in Bullet for later use. | 352 | // Create the geometry information in Bullet for later use. |
353 | // The objects needs a hull if it's physical otherwise a mesh is enough. | 353 | // The objects needs a hull if it's physical otherwise a mesh is enough. |
354 | // No locking here because this is done when we know physics is not simulating. | 354 | // if 'forceRebuild' is true, the geometry is unconditionally rebuilt. For meshes and hulls, |
355 | // if 'forceRebuild' is true, the geometry is rebuilt. Otherwise a previously built version is used. | 355 | // shared geometries will be used. If the parameters of the existing shape are the same |
356 | // as this request, the shape is not rebuilt. | ||
357 | // Info in prim.BSShape is updated to the new shape. | ||
356 | // Returns 'true' if the geometry was rebuilt. | 358 | // Returns 'true' if the geometry was rebuilt. |
357 | // Called at taint-time! | 359 | // Called at taint-time! |
358 | private bool CreateGeom(bool forceRebuild, BSPrim prim, ShapeData shapeData, | 360 | private bool CreateGeom(bool forceRebuild, BSPhysObject prim, ShapeData shapeData, |
359 | PrimitiveBaseShape pbs, ShapeDestructionCallback shapeCallback) | 361 | PrimitiveBaseShape pbs, ShapeDestructionCallback shapeCallback) |
360 | { | 362 | { |
361 | bool ret = false; | 363 | bool ret = false; |
362 | bool haveShape = false; | 364 | bool haveShape = false; |
363 | bool nativeShapePossible = true; | 365 | bool nativeShapePossible = true; |
364 | 366 | ||
367 | if (shapeData.Type == ShapeData.PhysicsShapeType.SHAPE_AVATAR) | ||
368 | { | ||
369 | // an avatar capsule is close to a native shape (it is not shared) | ||
370 | ret = GetReferenceToNativeShape(prim, shapeData, ShapeData.PhysicsShapeType.SHAPE_AVATAR, | ||
371 | ShapeData.FixedShapeKey.KEY_CAPSULE, shapeCallback); | ||
372 | haveShape = true; | ||
373 | } | ||
365 | // If the prim attributes are simple, this could be a simple Bullet native shape | 374 | // If the prim attributes are simple, this could be a simple Bullet native shape |
366 | if (nativeShapePossible | 375 | if (!haveShape |
376 | && pbs != null | ||
377 | && nativeShapePossible | ||
367 | && ((pbs.SculptEntry && !PhysicsScene.ShouldMeshSculptedPrim) | 378 | && ((pbs.SculptEntry && !PhysicsScene.ShouldMeshSculptedPrim) |
368 | || (pbs.ProfileBegin == 0 && pbs.ProfileEnd == 0 | 379 | || (pbs.ProfileBegin == 0 && pbs.ProfileEnd == 0 |
369 | && pbs.ProfileHollow == 0 | 380 | && pbs.ProfileHollow == 0 |
@@ -406,7 +417,7 @@ public class BSShapeCollection : IDisposable | |||
406 | // If a simple shape is not happening, create a mesh and possibly a hull. | 417 | // If a simple shape is not happening, create a mesh and possibly a hull. |
407 | // Note that if it's a native shape, the check for physical/non-physical is not | 418 | // Note that if it's a native shape, the check for physical/non-physical is not |
408 | // made. Native shapes are best used in either case. | 419 | // made. Native shapes are best used in either case. |
409 | if (!haveShape) | 420 | if (!haveShape && pbs != null) |
410 | { | 421 | { |
411 | if (prim.IsPhysical && PhysicsScene.ShouldUseHullsForPhysicalObjects) | 422 | if (prim.IsPhysical && PhysicsScene.ShouldUseHullsForPhysicalObjects) |
412 | { | 423 | { |
@@ -425,8 +436,9 @@ public class BSShapeCollection : IDisposable | |||
425 | return ret; | 436 | return ret; |
426 | } | 437 | } |
427 | 438 | ||
428 | // Creates a native shape and assignes it to prim.BSShape | 439 | // Creates a native shape and assignes it to prim.BSShape. |
429 | private bool GetReferenceToNativeShape( BSPrim prim, ShapeData shapeData, | 440 | // "Native" shapes are never shared. they are created here and destroyed in DereferenceShape(). |
441 | private bool GetReferenceToNativeShape(BSPhysObject prim, ShapeData shapeData, | ||
430 | ShapeData.PhysicsShapeType shapeType, ShapeData.FixedShapeKey shapeKey, | 442 | ShapeData.PhysicsShapeType shapeType, ShapeData.FixedShapeKey shapeKey, |
431 | ShapeDestructionCallback shapeCallback) | 443 | ShapeDestructionCallback shapeCallback) |
432 | { | 444 | { |
@@ -440,10 +452,19 @@ public class BSShapeCollection : IDisposable | |||
440 | // release any previous shape | 452 | // release any previous shape |
441 | DereferenceShape(prim.BSShape, true, shapeCallback); | 453 | DereferenceShape(prim.BSShape, true, shapeCallback); |
442 | 454 | ||
443 | // Native shapes are always built independently. | 455 | if (shapeType == ShapeData.PhysicsShapeType.SHAPE_AVATAR) |
444 | newShape = new BulletShape(BulletSimAPI.BuildNativeShape2(PhysicsScene.World.ptr, shapeData), shapeType); | 456 | { |
445 | newShape.shapeKey = (System.UInt64)shapeKey; | 457 | newShape = new BulletShape(BulletSimAPI.BuildCapsuleShape2(PhysicsScene.World.ptr, shapeData), shapeType); |
446 | newShape.isNativeShape = true; | 458 | newShape.shapeKey = (System.UInt64)shapeKey; |
459 | newShape.isNativeShape = true; | ||
460 | } | ||
461 | else | ||
462 | { | ||
463 | // Native shapes are always built independently. | ||
464 | newShape = new BulletShape(BulletSimAPI.BuildNativeShape2(PhysicsScene.World.ptr, shapeData), shapeType); | ||
465 | newShape.shapeKey = (System.UInt64)shapeKey; | ||
466 | newShape.isNativeShape = true; | ||
467 | } | ||
447 | 468 | ||
448 | // Don't need to do a 'ReferenceShape()' here because native shapes are not tracked. | 469 | // Don't need to do a 'ReferenceShape()' here because native shapes are not tracked. |
449 | // DetailLog("{0},BSShapeCollection.AddNativeShapeToPrim,create,newshape={1}", shapeData.ID, newShape); | 470 | // DetailLog("{0},BSShapeCollection.AddNativeShapeToPrim,create,newshape={1}", shapeData.ID, newShape); |
@@ -456,7 +477,7 @@ public class BSShapeCollection : IDisposable | |||
456 | // Dereferences previous shape in BSShape and adds a reference for this new shape. | 477 | // Dereferences previous shape in BSShape and adds a reference for this new shape. |
457 | // Returns 'true' of a mesh was actually built. Otherwise . | 478 | // Returns 'true' of a mesh was actually built. Otherwise . |
458 | // Called at taint-time! | 479 | // Called at taint-time! |
459 | private bool GetReferenceToMesh(BSPrim prim, ShapeData shapeData, PrimitiveBaseShape pbs, | 480 | private bool GetReferenceToMesh(BSPhysObject prim, ShapeData shapeData, PrimitiveBaseShape pbs, |
460 | ShapeDestructionCallback shapeCallback) | 481 | ShapeDestructionCallback shapeCallback) |
461 | { | 482 | { |
462 | BulletShape newShape = new BulletShape(IntPtr.Zero); | 483 | BulletShape newShape = new BulletShape(IntPtr.Zero); |
@@ -526,7 +547,7 @@ public class BSShapeCollection : IDisposable | |||
526 | 547 | ||
527 | // See that hull shape exists in the physical world and update prim.BSShape. | 548 | // See that hull shape exists in the physical world and update prim.BSShape. |
528 | // We could be creating the hull because scale changed or whatever. | 549 | // We could be creating the hull because scale changed or whatever. |
529 | private bool GetReferenceToHull(BSPrim prim, ShapeData shapeData, PrimitiveBaseShape pbs, | 550 | private bool GetReferenceToHull(BSPhysObject prim, ShapeData shapeData, PrimitiveBaseShape pbs, |
530 | ShapeDestructionCallback shapeCallback) | 551 | ShapeDestructionCallback shapeCallback) |
531 | { | 552 | { |
532 | BulletShape newShape; | 553 | BulletShape newShape; |
@@ -694,7 +715,7 @@ public class BSShapeCollection : IDisposable | |||
694 | // Updates prim.BSBody with the information about the new body if one is created. | 715 | // Updates prim.BSBody with the information about the new body if one is created. |
695 | // Returns 'true' if an object was actually created. | 716 | // Returns 'true' if an object was actually created. |
696 | // Called at taint-time. | 717 | // Called at taint-time. |
697 | private bool CreateBody(bool forceRebuild, BSPrim prim, BulletSim sim, BulletShape shape, | 718 | private bool CreateBody(bool forceRebuild, BSPhysObject prim, BulletSim sim, BulletShape shape, |
698 | ShapeData shapeData, BodyDestructionCallback bodyCallback) | 719 | ShapeData shapeData, BodyDestructionCallback bodyCallback) |
699 | { | 720 | { |
700 | bool ret = false; | 721 | bool ret = false; |
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs b/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs index 276111c..30754a7 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs | |||
@@ -223,6 +223,7 @@ public struct ShapeData | |||
223 | KEY_SPHERE = 2, | 223 | KEY_SPHERE = 2, |
224 | KEY_CONE = 3, | 224 | KEY_CONE = 3, |
225 | KEY_CYLINDER = 4, | 225 | KEY_CYLINDER = 4, |
226 | KEY_CAPSULE = 5, | ||
226 | } | 227 | } |
227 | } | 228 | } |
228 | [StructLayout(LayoutKind.Sequential)] | 229 | [StructLayout(LayoutKind.Sequential)] |
@@ -282,6 +283,7 @@ public struct ConfigurationParameters | |||
282 | public float terrainHitFraction; | 283 | public float terrainHitFraction; |
283 | public float terrainRestitution; | 284 | public float terrainRestitution; |
284 | public float avatarFriction; | 285 | public float avatarFriction; |
286 | public float avatarStandingFriction; | ||
285 | public float avatarDensity; | 287 | public float avatarDensity; |
286 | public float avatarRestitution; | 288 | public float avatarRestitution; |
287 | public float avatarCapsuleRadius; | 289 | public float avatarCapsuleRadius; |
@@ -428,6 +430,7 @@ public delegate void DebugLogCallback([MarshalAs(UnmanagedType.LPStr)]string msg | |||
428 | [return: MarshalAs(UnmanagedType.LPStr)] | 430 | [return: MarshalAs(UnmanagedType.LPStr)] |
429 | public static extern string GetVersion(); | 431 | public static extern string GetVersion(); |
430 | 432 | ||
433 | /* Remove the linkage to the old api methods | ||
431 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | 434 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] |
432 | public static extern uint Initialize(Vector3 maxPosition, IntPtr parms, | 435 | public static extern uint Initialize(Vector3 maxPosition, IntPtr parms, |
433 | int maxCollisions, IntPtr collisionArray, | 436 | int maxCollisions, IntPtr collisionArray, |
@@ -531,7 +534,7 @@ public static extern Vector3 RecoverFromPenetration(uint worldID, uint id); | |||
531 | // =============================================================================== | 534 | // =============================================================================== |
532 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | 535 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] |
533 | public static extern void DumpBulletStatistics(); | 536 | public static extern void DumpBulletStatistics(); |
534 | 537 | */ | |
535 | // Log a debug message | 538 | // Log a debug message |
536 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | 539 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] |
537 | public static extern void SetDebugLogCallback(DebugLogCallback callback); | 540 | public static extern void SetDebugLogCallback(DebugLogCallback callback); |
@@ -562,7 +565,8 @@ public static extern IntPtr GetBodyHandle2(IntPtr world, uint id); | |||
562 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | 565 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] |
563 | public static extern IntPtr Initialize2(Vector3 maxPosition, IntPtr parms, | 566 | public static extern IntPtr Initialize2(Vector3 maxPosition, IntPtr parms, |
564 | int maxCollisions, IntPtr collisionArray, | 567 | int maxCollisions, IntPtr collisionArray, |
565 | int maxUpdates, IntPtr updateArray); | 568 | int maxUpdates, IntPtr updateArray, |
569 | DebugLogCallback logRoutine); | ||
566 | 570 | ||
567 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | 571 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] |
568 | public static extern bool UpdateParameter2(IntPtr world, uint localID, String parm, float value); | 572 | public static extern bool UpdateParameter2(IntPtr world, uint localID, String parm, float value); |
@@ -604,6 +608,9 @@ public static extern IntPtr BuildNativeShape2(IntPtr world, ShapeData shapeData) | |||
604 | public static extern bool IsNativeShape2(IntPtr shape); | 608 | public static extern bool IsNativeShape2(IntPtr shape); |
605 | 609 | ||
606 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | 610 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] |
611 | public static extern IntPtr BuildCapsuleShape2(IntPtr world, ShapeData shapeData); | ||
612 | |||
613 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
607 | public static extern IntPtr CreateCompoundShape2(IntPtr sim); | 614 | public static extern IntPtr CreateCompoundShape2(IntPtr sim); |
608 | 615 | ||
609 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | 616 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] |