diff options
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs')
-rw-r--r-- | OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | 97 |
1 files changed, 29 insertions, 68 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs index caa6c46..62aaf80 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | |||
@@ -253,8 +253,9 @@ public sealed class BSPrim : BSPhysObject | |||
253 | // Zero some other properties in the physics engine | 253 | // Zero some other properties in the physics engine |
254 | PhysicsScene.TaintedObject(inTaintTime, "BSPrim.ZeroMotion", delegate() | 254 | PhysicsScene.TaintedObject(inTaintTime, "BSPrim.ZeroMotion", delegate() |
255 | { | 255 | { |
256 | BulletSimAPI.SetInterpolationAngularVelocity2(PhysBody.ptr, OMV.Vector3.Zero); | 256 | // DetailLog("{0},BSPrim.ZeroAngularMotion,call,rotVel={1}", LocalID, _rotationalVelocity); |
257 | BulletSimAPI.SetAngularVelocity2(PhysBody.ptr, OMV.Vector3.Zero); | 257 | BulletSimAPI.SetInterpolationAngularVelocity2(PhysBody.ptr, _rotationalVelocity); |
258 | BulletSimAPI.SetAngularVelocity2(PhysBody.ptr, _rotationalVelocity); | ||
258 | }); | 259 | }); |
259 | } | 260 | } |
260 | 261 | ||
@@ -329,7 +330,7 @@ public sealed class BSPrim : BSPhysObject | |||
329 | 330 | ||
330 | if ((CurrentCollisionFlags & CollisionFlags.BS_FLOATS_ON_WATER) != 0) | 331 | if ((CurrentCollisionFlags & CollisionFlags.BS_FLOATS_ON_WATER) != 0) |
331 | { | 332 | { |
332 | float waterHeight = PhysicsScene.GetWaterLevelAtXYZ(_position); | 333 | float waterHeight = PhysicsScene.TerrainManager.GetWaterLevelAtXYZ(_position); |
333 | // TODO: a floating motor so object will bob in the water | 334 | // TODO: a floating motor so object will bob in the water |
334 | if (Math.Abs(Position.Z - waterHeight) > 0.1f) | 335 | if (Math.Abs(Position.Z - waterHeight) > 0.1f) |
335 | { | 336 | { |
@@ -347,7 +348,9 @@ public sealed class BSPrim : BSPhysObject | |||
347 | if (ret) | 348 | if (ret) |
348 | { | 349 | { |
349 | // Apply upforce and overcome gravity. | 350 | // Apply upforce and overcome gravity. |
350 | AddForce(upForce - PhysicsScene.DefaultGravity, false, inTaintTime); | 351 | OMV.Vector3 correctionForce = upForce - PhysicsScene.DefaultGravity; |
352 | DetailLog("{0},BSPrim.PositionSanityCheck,applyForce,pos={1},upForce={2},correctionForce={3}", LocalID, _position, upForce, correctionForce); | ||
353 | AddForce(correctionForce, false, inTaintTime); | ||
351 | } | 354 | } |
352 | return ret; | 355 | return ret; |
353 | } | 356 | } |
@@ -643,9 +646,13 @@ public sealed class BSPrim : BSPhysObject | |||
643 | BulletSimAPI.UpdateSingleAabb2(PhysicsScene.World.ptr, PhysBody.ptr); | 646 | BulletSimAPI.UpdateSingleAabb2(PhysicsScene.World.ptr, PhysBody.ptr); |
644 | 647 | ||
645 | // Collision filter can be set only when the object is in the world | 648 | // Collision filter can be set only when the object is in the world |
646 | if (PhysBody.collisionFilter != 0 || PhysBody.collisionMask != 0) | 649 | if (PhysBody.collisionGroup != 0 || PhysBody.collisionMask != 0) |
647 | { | 650 | { |
648 | BulletSimAPI.SetCollisionFilterMask2(PhysBody.ptr, (uint)PhysBody.collisionFilter, (uint)PhysBody.collisionMask); | 651 | if (!BulletSimAPI.SetCollisionGroupMask2(PhysBody.ptr, (uint)PhysBody.collisionGroup, (uint)PhysBody.collisionMask)) |
652 | { | ||
653 | PhysicsScene.Logger.ErrorFormat("{0} Failure setting prim collision mask. localID={1}, grp={2:X}, mask={3:X}", | ||
654 | LogHeader, LocalID, PhysBody.collisionGroup, PhysBody.collisionMask); | ||
655 | } | ||
649 | } | 656 | } |
650 | 657 | ||
651 | // Recompute any linkset parameters. | 658 | // Recompute any linkset parameters. |
@@ -684,11 +691,11 @@ public sealed class BSPrim : BSPhysObject | |||
684 | // There can be special things needed for implementing linksets | 691 | // There can be special things needed for implementing linksets |
685 | Linkset.MakeStatic(this); | 692 | Linkset.MakeStatic(this); |
686 | // The activation state is 'disabled' so Bullet will not try to act on it. | 693 | // The activation state is 'disabled' so Bullet will not try to act on it. |
687 | BulletSimAPI.ForceActivationState2(PhysBody.ptr, ActivationState.DISABLE_SIMULATION); | 694 | // BulletSimAPI.ForceActivationState2(PhysBody.ptr, ActivationState.DISABLE_SIMULATION); |
688 | // Start it out sleeping and physical actions could wake it up. | 695 | // Start it out sleeping and physical actions could wake it up. |
689 | // BulletSimAPI.ForceActivationState2(BSBody.ptr, ActivationState.ISLAND_SLEEPING); | 696 | BulletSimAPI.ForceActivationState2(PhysBody.ptr, ActivationState.ISLAND_SLEEPING); |
690 | 697 | ||
691 | PhysBody.collisionFilter = CollisionFilterGroups.StaticObjectFilter; | 698 | PhysBody.collisionGroup = CollisionFilterGroups.StaticObjectGroup; |
692 | PhysBody.collisionMask = CollisionFilterGroups.StaticObjectMask; | 699 | PhysBody.collisionMask = CollisionFilterGroups.StaticObjectMask; |
693 | } | 700 | } |
694 | else | 701 | else |
@@ -734,7 +741,7 @@ public sealed class BSPrim : BSPhysObject | |||
734 | BulletSimAPI.ForceActivationState2(PhysBody.ptr, ActivationState.ACTIVE_TAG); | 741 | BulletSimAPI.ForceActivationState2(PhysBody.ptr, ActivationState.ACTIVE_TAG); |
735 | // BulletSimAPI.Activate2(BSBody.ptr, true); | 742 | // BulletSimAPI.Activate2(BSBody.ptr, true); |
736 | 743 | ||
737 | PhysBody.collisionFilter = CollisionFilterGroups.ObjectFilter; | 744 | PhysBody.collisionGroup = CollisionFilterGroups.ObjectGroup; |
738 | PhysBody.collisionMask = CollisionFilterGroups.ObjectMask; | 745 | PhysBody.collisionMask = CollisionFilterGroups.ObjectMask; |
739 | } | 746 | } |
740 | } | 747 | } |
@@ -762,7 +769,7 @@ public sealed class BSPrim : BSPhysObject | |||
762 | m_log.ErrorFormat("{0} MakeSolid: physical body of wrong type for non-solidness. id={1}, type={2}", LogHeader, LocalID, bodyType); | 769 | m_log.ErrorFormat("{0} MakeSolid: physical body of wrong type for non-solidness. id={1}, type={2}", LogHeader, LocalID, bodyType); |
763 | } | 770 | } |
764 | CurrentCollisionFlags = BulletSimAPI.AddToCollisionFlags2(PhysBody.ptr, CollisionFlags.CF_NO_CONTACT_RESPONSE); | 771 | CurrentCollisionFlags = BulletSimAPI.AddToCollisionFlags2(PhysBody.ptr, CollisionFlags.CF_NO_CONTACT_RESPONSE); |
765 | PhysBody.collisionFilter = CollisionFilterGroups.VolumeDetectFilter; | 772 | PhysBody.collisionGroup = CollisionFilterGroups.VolumeDetectGroup; |
766 | PhysBody.collisionMask = CollisionFilterGroups.VolumeDetectMask; | 773 | PhysBody.collisionMask = CollisionFilterGroups.VolumeDetectMask; |
767 | } | 774 | } |
768 | } | 775 | } |
@@ -838,15 +845,6 @@ public sealed class BSPrim : BSPhysObject | |||
838 | } | 845 | } |
839 | public override OMV.Vector3 RotationalVelocity { | 846 | public override OMV.Vector3 RotationalVelocity { |
840 | get { | 847 | get { |
841 | /* | ||
842 | OMV.Vector3 pv = OMV.Vector3.Zero; | ||
843 | // if close to zero, report zero | ||
844 | // This is copied from ODE but I'm not sure why it returns zero but doesn't | ||
845 | // zero the property in the physics engine. | ||
846 | if (_rotationalVelocity.ApproxEquals(pv, 0.2f)) | ||
847 | return pv; | ||
848 | */ | ||
849 | |||
850 | return _rotationalVelocity; | 848 | return _rotationalVelocity; |
851 | } | 849 | } |
852 | set { | 850 | set { |
@@ -1012,6 +1010,9 @@ public sealed class BSPrim : BSPhysObject | |||
1012 | }); | 1010 | }); |
1013 | } | 1011 | } |
1014 | // A torque impulse. | 1012 | // A torque impulse. |
1013 | // ApplyTorqueImpulse adds torque directly to the angularVelocity. | ||
1014 | // AddAngularForce accumulates the force and applied it to the angular velocity all at once. | ||
1015 | // Computed as: angularVelocity += impulse * inertia; | ||
1015 | public void ApplyTorqueImpulse(OMV.Vector3 impulse, bool inTaintTime) | 1016 | public void ApplyTorqueImpulse(OMV.Vector3 impulse, bool inTaintTime) |
1016 | { | 1017 | { |
1017 | OMV.Vector3 applyImpulse = impulse; | 1018 | OMV.Vector3 applyImpulse = impulse; |
@@ -1380,54 +1381,16 @@ public sealed class BSPrim : BSPhysObject | |||
1380 | 1381 | ||
1381 | public override void UpdateProperties(EntityProperties entprop) | 1382 | public override void UpdateProperties(EntityProperties entprop) |
1382 | { | 1383 | { |
1383 | /* | 1384 | // Updates only for individual prims and for the root object of a linkset. |
1384 | UpdatedProperties changed = 0; | 1385 | if (Linkset.IsRoot(this)) |
1385 | // assign to the local variables so the normal set action does not happen | ||
1386 | // if (_position != entprop.Position) | ||
1387 | if (!_position.ApproxEquals(entprop.Position, POSITION_TOLERANCE)) | ||
1388 | { | ||
1389 | _position = entprop.Position; | ||
1390 | changed |= UpdatedProperties.Position; | ||
1391 | } | ||
1392 | // if (_orientation != entprop.Rotation) | ||
1393 | if (!_orientation.ApproxEquals(entprop.Rotation, ROTATION_TOLERANCE)) | ||
1394 | { | ||
1395 | _orientation = entprop.Rotation; | ||
1396 | changed |= UpdatedProperties.Rotation; | ||
1397 | } | ||
1398 | // if (_velocity != entprop.Velocity) | ||
1399 | if (!_velocity.ApproxEquals(entprop.Velocity, VELOCITY_TOLERANCE)) | ||
1400 | { | ||
1401 | _velocity = entprop.Velocity; | ||
1402 | changed |= UpdatedProperties.Velocity; | ||
1403 | } | ||
1404 | // if (_acceleration != entprop.Acceleration) | ||
1405 | if (!_acceleration.ApproxEquals(entprop.Acceleration, ACCELERATION_TOLERANCE)) | ||
1406 | { | ||
1407 | _acceleration = entprop.Acceleration; | ||
1408 | changed |= UpdatedProperties.Acceleration; | ||
1409 | } | ||
1410 | // if (_rotationalVelocity != entprop.RotationalVelocity) | ||
1411 | if (!_rotationalVelocity.ApproxEquals(entprop.RotationalVelocity, ROTATIONAL_VELOCITY_TOLERANCE)) | ||
1412 | { | ||
1413 | _rotationalVelocity = entprop.RotationalVelocity; | ||
1414 | changed |= UpdatedProperties.RotationalVel; | ||
1415 | } | ||
1416 | if (changed != 0) | ||
1417 | { | 1386 | { |
1418 | // Only update the position of single objects and linkset roots | 1387 | // A temporary kludge to suppress the rotational effects introduced on vehicles by Bullet |
1419 | if (Linkset.IsRoot(this)) | 1388 | // TODO: handle physics introduced by Bullet with computed vehicle physics. |
1389 | if (_vehicle.IsActive) | ||
1420 | { | 1390 | { |
1421 | base.RequestPhysicsterseUpdate(); | 1391 | entprop.RotationalVelocity = OMV.Vector3.Zero; |
1422 | } | 1392 | } |
1423 | } | ||
1424 | */ | ||
1425 | 1393 | ||
1426 | // Don't check for damping here -- it's done in BulletSim and SceneObjectPart. | ||
1427 | |||
1428 | // Updates only for individual prims and for the root object of a linkset. | ||
1429 | if (Linkset.IsRoot(this)) | ||
1430 | { | ||
1431 | // Assign directly to the local variables so the normal set action does not happen | 1394 | // Assign directly to the local variables so the normal set action does not happen |
1432 | _position = entprop.Position; | 1395 | _position = entprop.Position; |
1433 | _orientation = entprop.Rotation; | 1396 | _orientation = entprop.Rotation; |
@@ -1436,7 +1399,7 @@ public sealed class BSPrim : BSPhysObject | |||
1436 | _rotationalVelocity = entprop.RotationalVelocity; | 1399 | _rotationalVelocity = entprop.RotationalVelocity; |
1437 | 1400 | ||
1438 | // The sanity check can change the velocity and/or position. | 1401 | // The sanity check can change the velocity and/or position. |
1439 | if (PositionSanityCheck(true)) | 1402 | if (IsPhysical && PositionSanityCheck(true)) |
1440 | { | 1403 | { |
1441 | entprop.Position = _position; | 1404 | entprop.Position = _position; |
1442 | entprop.Velocity = _velocity; | 1405 | entprop.Velocity = _velocity; |
@@ -1446,12 +1409,10 @@ public sealed class BSPrim : BSPhysObject | |||
1446 | LastEntityProperties = CurrentEntityProperties; | 1409 | LastEntityProperties = CurrentEntityProperties; |
1447 | CurrentEntityProperties = entprop; | 1410 | CurrentEntityProperties = entprop; |
1448 | 1411 | ||
1449 | OMV.Vector3 direction = OMV.Vector3.UnitX * _orientation; | 1412 | OMV.Vector3 direction = OMV.Vector3.UnitX * _orientation; // DEBUG DEBUG DEBUG |
1450 | DetailLog("{0},BSPrim.UpdateProperties,call,pos={1},orient={2},dir={3},vel={4},rotVel={5}", | 1413 | DetailLog("{0},BSPrim.UpdateProperties,call,pos={1},orient={2},dir={3},vel={4},rotVel={5}", |
1451 | LocalID, _position, _orientation, direction, _velocity, _rotationalVelocity); | 1414 | LocalID, _position, _orientation, direction, _velocity, _rotationalVelocity); |
1452 | 1415 | ||
1453 | // BulletSimAPI.DumpRigidBody2(PhysicsScene.World.ptr, BSBody.ptr); // DEBUG DEBUG DEBUG | ||
1454 | |||
1455 | base.RequestPhysicsterseUpdate(); | 1416 | base.RequestPhysicsterseUpdate(); |
1456 | } | 1417 | } |
1457 | /* | 1418 | /* |