aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs83
1 files changed, 53 insertions, 30 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs
index 21aa9be..0defb24 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs
@@ -105,12 +105,12 @@ public sealed class BSCharacter : BSPhysObject
105 DetailLog("{0},BSCharacter.create,call,size={1},scale={2},density={3},volume={4},mass={5}", 105 DetailLog("{0},BSCharacter.create,call,size={1},scale={2},density={3},volume={4},mass={5}",
106 LocalID, _size, Scale, _avatarDensity, _avatarVolume, RawMass); 106 LocalID, _size, Scale, _avatarDensity, _avatarVolume, RawMass);
107 107
108 // do actual create at taint time 108 // do actual creation in taint time
109 PhysicsScene.TaintedObject("BSCharacter.create", delegate() 109 PhysicsScene.TaintedObject("BSCharacter.create", delegate()
110 { 110 {
111 DetailLog("{0},BSCharacter.create,taint", LocalID); 111 DetailLog("{0},BSCharacter.create,taint", LocalID);
112 // New body and shape into PhysBody and PhysShape 112 // New body and shape into PhysBody and PhysShape
113 PhysicsScene.Shapes.GetBodyAndShape(true, PhysicsScene.World, this, null, null); 113 PhysicsScene.Shapes.GetBodyAndShape(true, PhysicsScene.World, this);
114 114
115 SetPhysicalProperties(); 115 SetPhysicalProperties();
116 }); 116 });
@@ -124,7 +124,9 @@ public sealed class BSCharacter : BSPhysObject
124 PhysicsScene.TaintedObject("BSCharacter.destroy", delegate() 124 PhysicsScene.TaintedObject("BSCharacter.destroy", delegate()
125 { 125 {
126 PhysicsScene.Shapes.DereferenceBody(PhysBody, true, null); 126 PhysicsScene.Shapes.DereferenceBody(PhysBody, true, null);
127 PhysBody.Clear();
127 PhysicsScene.Shapes.DereferenceShape(PhysShape, true, null); 128 PhysicsScene.Shapes.DereferenceShape(PhysShape, true, null);
129 PhysShape.Clear();
128 }); 130 });
129 } 131 }
130 132
@@ -165,9 +167,8 @@ public sealed class BSCharacter : BSPhysObject
165 BulletSimAPI.UpdateSingleAabb2(PhysicsScene.World.ptr, PhysBody.ptr); 167 BulletSimAPI.UpdateSingleAabb2(PhysicsScene.World.ptr, PhysBody.ptr);
166 168
167 // Do this after the object has been added to the world 169 // Do this after the object has been added to the world
168 BulletSimAPI.SetCollisionGroupMask2(PhysBody.ptr, 170 PhysBody.collisionType = CollisionType.Avatar;
169 (uint)CollisionFilterGroups.AvatarGroup, 171 PhysBody.ApplyCollisionMask();
170 (uint)CollisionFilterGroups.AvatarMask);
171 } 172 }
172 173
173 public override void RequestPhysicsterseUpdate() 174 public override void RequestPhysicsterseUpdate()
@@ -187,6 +188,11 @@ public sealed class BSCharacter : BSPhysObject
187 set { 188 set {
188 // When an avatar's size is set, only the height is changed. 189 // When an avatar's size is set, only the height is changed.
189 _size = value; 190 _size = value;
191 // Old versions of ScenePresence passed only the height. If width and/or depth are zero,
192 // replace with the default values.
193 if (_size.X == 0f) _size.X = PhysicsScene.Params.avatarCapsuleDepth;
194 if (_size.Y == 0f) _size.Y = PhysicsScene.Params.avatarCapsuleWidth;
195
190 ComputeAvatarScale(_size); 196 ComputeAvatarScale(_size);
191 ComputeAvatarVolumeAndMass(); 197 ComputeAvatarVolumeAndMass();
192 DetailLog("{0},BSCharacter.setSize,call,size={1},scale={2},density={3},volume={4},mass={5}", 198 DetailLog("{0},BSCharacter.setSize,call,size={1},scale={2},density={3},volume={4},mass={5}",
@@ -194,15 +200,18 @@ public sealed class BSCharacter : BSPhysObject
194 200
195 PhysicsScene.TaintedObject("BSCharacter.setSize", delegate() 201 PhysicsScene.TaintedObject("BSCharacter.setSize", delegate()
196 { 202 {
197 BulletSimAPI.SetLocalScaling2(PhysShape.ptr, Scale); 203 if (PhysBody.HasPhysicalBody && PhysShape.HasPhysicalShape)
198 UpdatePhysicalMassProperties(RawMass); 204 {
205 BulletSimAPI.SetLocalScaling2(PhysShape.ptr, Scale);
206 UpdatePhysicalMassProperties(RawMass);
207 // Make sure this change appears as a property update event
208 BulletSimAPI.PushUpdate2(PhysBody.ptr);
209 }
199 }); 210 });
200 211
201 } 212 }
202 } 213 }
203 214
204 public override OMV.Vector3 Scale { get; set; }
205
206 public override PrimitiveBaseShape Shape 215 public override PrimitiveBaseShape Shape
207 { 216 {
208 set { BaseShape = value; } 217 set { BaseShape = value; }
@@ -236,7 +245,8 @@ public sealed class BSCharacter : BSPhysObject
236 // Zero some other properties directly into the physics engine 245 // Zero some other properties directly into the physics engine
237 PhysicsScene.TaintedObject(inTaintTime, "BSCharacter.ZeroMotion", delegate() 246 PhysicsScene.TaintedObject(inTaintTime, "BSCharacter.ZeroMotion", delegate()
238 { 247 {
239 BulletSimAPI.ClearAllForces2(PhysBody.ptr); 248 if (PhysBody.HasPhysicalBody)
249 BulletSimAPI.ClearAllForces2(PhysBody.ptr);
240 }); 250 });
241 } 251 }
242 public override void ZeroAngularMotion(bool inTaintTime) 252 public override void ZeroAngularMotion(bool inTaintTime)
@@ -245,10 +255,13 @@ public sealed class BSCharacter : BSPhysObject
245 255
246 PhysicsScene.TaintedObject(inTaintTime, "BSCharacter.ZeroMotion", delegate() 256 PhysicsScene.TaintedObject(inTaintTime, "BSCharacter.ZeroMotion", delegate()
247 { 257 {
248 BulletSimAPI.SetInterpolationAngularVelocity2(PhysBody.ptr, OMV.Vector3.Zero); 258 if (PhysBody.HasPhysicalBody)
249 BulletSimAPI.SetAngularVelocity2(PhysBody.ptr, OMV.Vector3.Zero); 259 {
250 // The next also get rid of applied linear force but the linear velocity is untouched. 260 BulletSimAPI.SetInterpolationAngularVelocity2(PhysBody.ptr, OMV.Vector3.Zero);
251 BulletSimAPI.ClearForces2(PhysBody.ptr); 261 BulletSimAPI.SetAngularVelocity2(PhysBody.ptr, OMV.Vector3.Zero);
262 // The next also get rid of applied linear force but the linear velocity is untouched.
263 BulletSimAPI.ClearForces2(PhysBody.ptr);
264 }
252 }); 265 });
253 } 266 }
254 267
@@ -273,7 +286,8 @@ public sealed class BSCharacter : BSPhysObject
273 PhysicsScene.TaintedObject("BSCharacter.setPosition", delegate() 286 PhysicsScene.TaintedObject("BSCharacter.setPosition", delegate()
274 { 287 {
275 DetailLog("{0},BSCharacter.SetPosition,taint,pos={1},orient={2}", LocalID, _position, _orientation); 288 DetailLog("{0},BSCharacter.SetPosition,taint,pos={1},orient={2}", LocalID, _position, _orientation);
276 BulletSimAPI.SetTranslation2(PhysBody.ptr, _position, _orientation); 289 if (PhysBody.HasPhysicalBody)
290 BulletSimAPI.SetTranslation2(PhysBody.ptr, _position, _orientation);
277 }); 291 });
278 } 292 }
279 } 293 }
@@ -332,7 +346,8 @@ public sealed class BSCharacter : BSPhysObject
332 PhysicsScene.TaintedObject(inTaintTime, "BSCharacter.PositionSanityCheck", delegate() 346 PhysicsScene.TaintedObject(inTaintTime, "BSCharacter.PositionSanityCheck", delegate()
333 { 347 {
334 DetailLog("{0},BSCharacter.PositionSanityCheck,taint,pos={1},orient={2}", LocalID, _position, _orientation); 348 DetailLog("{0},BSCharacter.PositionSanityCheck,taint,pos={1},orient={2}", LocalID, _position, _orientation);
335 BulletSimAPI.SetTranslation2(PhysBody.ptr, _position, _orientation); 349 if (PhysBody.HasPhysicalBody)
350 BulletSimAPI.SetTranslation2(PhysBody.ptr, _position, _orientation);
336 }); 351 });
337 ret = true; 352 ret = true;
338 } 353 }
@@ -359,7 +374,8 @@ public sealed class BSCharacter : BSPhysObject
359 PhysicsScene.TaintedObject("BSCharacter.SetForce", delegate() 374 PhysicsScene.TaintedObject("BSCharacter.SetForce", delegate()
360 { 375 {
361 DetailLog("{0},BSCharacter.setForce,taint,force={1}", LocalID, _force); 376 DetailLog("{0},BSCharacter.setForce,taint,force={1}", LocalID, _force);
362 BulletSimAPI.SetObjectForce2(PhysBody.ptr, _force); 377 if (PhysBody.HasPhysicalBody)
378 BulletSimAPI.SetObjectForce2(PhysBody.ptr, _force);
363 }); 379 });
364 } 380 }
365 } 381 }
@@ -398,7 +414,8 @@ public sealed class BSCharacter : BSPhysObject
398 if (_currentFriction != PhysicsScene.Params.avatarStandingFriction) 414 if (_currentFriction != PhysicsScene.Params.avatarStandingFriction)
399 { 415 {
400 _currentFriction = PhysicsScene.Params.avatarStandingFriction; 416 _currentFriction = PhysicsScene.Params.avatarStandingFriction;
401 BulletSimAPI.SetFriction2(PhysBody.ptr, _currentFriction); 417 if (PhysBody.HasPhysicalBody)
418 BulletSimAPI.SetFriction2(PhysBody.ptr, _currentFriction);
402 } 419 }
403 } 420 }
404 else 421 else
@@ -406,7 +423,8 @@ public sealed class BSCharacter : BSPhysObject
406 if (_currentFriction != PhysicsScene.Params.avatarFriction) 423 if (_currentFriction != PhysicsScene.Params.avatarFriction)
407 { 424 {
408 _currentFriction = PhysicsScene.Params.avatarFriction; 425 _currentFriction = PhysicsScene.Params.avatarFriction;
409 BulletSimAPI.SetFriction2(PhysBody.ptr, _currentFriction); 426 if (PhysBody.HasPhysicalBody)
427 BulletSimAPI.SetFriction2(PhysBody.ptr, _currentFriction);
410 } 428 }
411 } 429 }
412 _velocity = value; 430 _velocity = value;
@@ -443,8 +461,11 @@ public sealed class BSCharacter : BSPhysObject
443 // m_log.DebugFormat("{0}: set orientation to {1}", LogHeader, _orientation); 461 // m_log.DebugFormat("{0}: set orientation to {1}", LogHeader, _orientation);
444 PhysicsScene.TaintedObject("BSCharacter.setOrientation", delegate() 462 PhysicsScene.TaintedObject("BSCharacter.setOrientation", delegate()
445 { 463 {
446 // _position = BulletSimAPI.GetPosition2(BSBody.ptr); 464 if (PhysBody.HasPhysicalBody)
447 BulletSimAPI.SetTranslation2(PhysBody.ptr, _position, _orientation); 465 {
466 // _position = BulletSimAPI.GetPosition2(BSBody.ptr);
467 BulletSimAPI.SetTranslation2(PhysBody.ptr, _position, _orientation);
468 }
448 }); 469 });
449 } 470 }
450 } 471 }
@@ -517,10 +538,13 @@ public sealed class BSCharacter : BSPhysObject
517 _floatOnWater = value; 538 _floatOnWater = value;
518 PhysicsScene.TaintedObject("BSCharacter.setFloatOnWater", delegate() 539 PhysicsScene.TaintedObject("BSCharacter.setFloatOnWater", delegate()
519 { 540 {
520 if (_floatOnWater) 541 if (PhysBody.HasPhysicalBody)
521 CurrentCollisionFlags = BulletSimAPI.AddToCollisionFlags2(PhysBody.ptr, CollisionFlags.BS_FLOATS_ON_WATER); 542 {
522 else 543 if (_floatOnWater)
523 CurrentCollisionFlags = BulletSimAPI.RemoveFromCollisionFlags2(PhysBody.ptr, CollisionFlags.BS_FLOATS_ON_WATER); 544 CurrentCollisionFlags = BulletSimAPI.AddToCollisionFlags2(PhysBody.ptr, CollisionFlags.BS_FLOATS_ON_WATER);
545 else
546 CurrentCollisionFlags = BulletSimAPI.RemoveFromCollisionFlags2(PhysBody.ptr, CollisionFlags.BS_FLOATS_ON_WATER);
547 }
524 }); 548 });
525 } 549 }
526 } 550 }
@@ -553,7 +577,8 @@ public sealed class BSCharacter : BSPhysObject
553 DetailLog("{0},BSCharacter.setForceBuoyancy,taint,buoy={1}", LocalID, _buoyancy); 577 DetailLog("{0},BSCharacter.setForceBuoyancy,taint,buoy={1}", LocalID, _buoyancy);
554 // Buoyancy is faked by changing the gravity applied to the object 578 // Buoyancy is faked by changing the gravity applied to the object
555 float grav = PhysicsScene.Params.gravity * (1f - _buoyancy); 579 float grav = PhysicsScene.Params.gravity * (1f - _buoyancy);
556 BulletSimAPI.SetGravity2(PhysBody.ptr, new OMV.Vector3(0f, 0f, grav)); 580 if (PhysBody.HasPhysicalBody)
581 BulletSimAPI.SetGravity2(PhysBody.ptr, new OMV.Vector3(0f, 0f, grav));
557 } 582 }
558 } 583 }
559 584
@@ -599,7 +624,8 @@ public sealed class BSCharacter : BSPhysObject
599 PhysicsScene.TaintedObject("BSCharacter.AddForce", delegate() 624 PhysicsScene.TaintedObject("BSCharacter.AddForce", delegate()
600 { 625 {
601 DetailLog("{0},BSCharacter.setAddForce,taint,addedForce={1}", LocalID, _force); 626 DetailLog("{0},BSCharacter.setAddForce,taint,addedForce={1}", LocalID, _force);
602 BulletSimAPI.SetObjectForce2(PhysBody.ptr, _force); 627 if (PhysBody.HasPhysicalBody)
628 BulletSimAPI.SetObjectForce2(PhysBody.ptr, _force);
603 }); 629 });
604 } 630 }
605 else 631 else
@@ -616,9 +642,6 @@ public sealed class BSCharacter : BSPhysObject
616 642
617 private void ComputeAvatarScale(OMV.Vector3 size) 643 private void ComputeAvatarScale(OMV.Vector3 size)
618 { 644 {
619 // The 'size' given by the simulator is the mid-point of the avatar
620 // and X and Y are unspecified.
621
622 OMV.Vector3 newScale = size; 645 OMV.Vector3 newScale = size;
623 // newScale.X = PhysicsScene.Params.avatarCapsuleWidth; 646 // newScale.X = PhysicsScene.Params.avatarCapsuleWidth;
624 // newScale.Y = PhysicsScene.Params.avatarCapsuleDepth; 647 // newScale.Y = PhysicsScene.Params.avatarCapsuleDepth;