aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/BulletSPlugin
diff options
context:
space:
mode:
authorRobert Adams2013-07-30 15:23:33 -0700
committerRobert Adams2013-07-30 15:23:33 -0700
commit0d189165a83bb97f243a1f29cfa6896936ca6db0 (patch)
treeefbe0bba730c57150f1d02841a8e55949cafdbed /OpenSim/Region/Physics/BulletSPlugin
parentBulletSim: test method for debugging of extended physics script operations. (diff)
downloadopensim-SC-0d189165a83bb97f243a1f29cfa6896936ca6db0.zip
opensim-SC-0d189165a83bb97f243a1f29cfa6896936ca6db0.tar.gz
opensim-SC-0d189165a83bb97f243a1f29cfa6896936ca6db0.tar.bz2
opensim-SC-0d189165a83bb97f243a1f29cfa6896936ca6db0.tar.xz
BulletSim: distribute vehicle physical settings to all members of
a linkset. Enables constraint based linksets. Rename some internal variables to clarify whether values world or vehicle relative.
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin')
-rw-r--r--OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs75
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs18
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs11
3 files changed, 61 insertions, 43 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs
index 82d7c44..f0d17d3 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs
@@ -589,10 +589,10 @@ namespace OpenSim.Region.Physics.BulletSPlugin
589 m_vehicleMass = ControllingPrim.TotalMass; 589 m_vehicleMass = ControllingPrim.TotalMass;
590 590
591 // Friction affects are handled by this vehicle code 591 // Friction affects are handled by this vehicle code
592 m_physicsScene.PE.SetFriction(ControllingPrim.PhysBody, BSParam.VehicleFriction); 592 // m_physicsScene.PE.SetFriction(ControllingPrim.PhysBody, BSParam.VehicleFriction);
593 m_physicsScene.PE.SetRestitution(ControllingPrim.PhysBody, BSParam.VehicleRestitution); 593 // m_physicsScene.PE.SetRestitution(ControllingPrim.PhysBody, BSParam.VehicleRestitution);
594 // ControllingPrim.Linkset.SetPhysicalFriction(BSParam.VehicleFriction); 594 ControllingPrim.Linkset.SetPhysicalFriction(BSParam.VehicleFriction);
595 // ControllingPrim.Linkset.SetPhysicalRestitution(BSParam.VehicleRestitution); 595 ControllingPrim.Linkset.SetPhysicalRestitution(BSParam.VehicleRestitution);
596 596
597 // Moderate angular movement introduced by Bullet. 597 // Moderate angular movement introduced by Bullet.
598 // TODO: possibly set AngularFactor and LinearFactor for the type of vehicle. 598 // TODO: possibly set AngularFactor and LinearFactor for the type of vehicle.
@@ -602,21 +602,21 @@ namespace OpenSim.Region.Physics.BulletSPlugin
602 m_physicsScene.PE.SetAngularFactorV(ControllingPrim.PhysBody, BSParam.VehicleAngularFactor); 602 m_physicsScene.PE.SetAngularFactorV(ControllingPrim.PhysBody, BSParam.VehicleAngularFactor);
603 603
604 // Vehicles report collision events so we know when it's on the ground 604 // Vehicles report collision events so we know when it's on the ground
605 m_physicsScene.PE.AddToCollisionFlags(ControllingPrim.PhysBody, CollisionFlags.BS_VEHICLE_COLLISIONS); 605 // m_physicsScene.PE.AddToCollisionFlags(ControllingPrim.PhysBody, CollisionFlags.BS_VEHICLE_COLLISIONS);
606 // ControllingPrim.Linkset.SetPhysicalCollisionFlags(CollisionFlags.BS_VEHICLE_COLLISIONS); 606 ControllingPrim.Linkset.AddToPhysicalCollisionFlags(CollisionFlags.BS_VEHICLE_COLLISIONS);
607 607
608 Vector3 inertia = m_physicsScene.PE.CalculateLocalInertia(ControllingPrim.PhysShape.physShapeInfo, m_vehicleMass); 608 // Vector3 inertia = m_physicsScene.PE.CalculateLocalInertia(ControllingPrim.PhysShape.physShapeInfo, m_vehicleMass);
609 ControllingPrim.Inertia = inertia * BSParam.VehicleInertiaFactor; 609 // ControllingPrim.Inertia = inertia * BSParam.VehicleInertiaFactor;
610 m_physicsScene.PE.SetMassProps(ControllingPrim.PhysBody, m_vehicleMass, ControllingPrim.Inertia); 610 // m_physicsScene.PE.SetMassProps(ControllingPrim.PhysBody, m_vehicleMass, ControllingPrim.Inertia);
611 m_physicsScene.PE.UpdateInertiaTensor(ControllingPrim.PhysBody); 611 // m_physicsScene.PE.UpdateInertiaTensor(ControllingPrim.PhysBody);
612 // ControllingPrim.Linkset.ComputeLocalInertia(BSParam.VehicleInertiaFactor); 612 ControllingPrim.Linkset.ComputeAndSetLocalInertia(BSParam.VehicleInertiaFactor, m_vehicleMass);
613 613
614 // Set the gravity for the vehicle depending on the buoyancy 614 // Set the gravity for the vehicle depending on the buoyancy
615 // TODO: what should be done if prim and vehicle buoyancy differ? 615 // TODO: what should be done if prim and vehicle buoyancy differ?
616 m_VehicleGravity = ControllingPrim.ComputeGravity(m_VehicleBuoyancy); 616 m_VehicleGravity = ControllingPrim.ComputeGravity(m_VehicleBuoyancy);
617 // The actual vehicle gravity is set to zero in Bullet so we can do all the application of same. 617 // The actual vehicle gravity is set to zero in Bullet so we can do all the application of same.
618 m_physicsScene.PE.SetGravity(ControllingPrim.PhysBody, Vector3.Zero); 618 // m_physicsScene.PE.SetGravity(ControllingPrim.PhysBody, Vector3.Zero);
619 // ControllingPrim.Linkset.SetPhysicalGravity(Vector3.Zero); 619 ControllingPrim.Linkset.SetPhysicalGravity(Vector3.Zero);
620 620
621 VDetailLog("{0},BSDynamics.SetPhysicalParameters,mass={1},inert={2},vehGrav={3},aDamp={4},frict={5},rest={6},lFact={7},aFact={8}", 621 VDetailLog("{0},BSDynamics.SetPhysicalParameters,mass={1},inert={2},vehGrav={3},aDamp={4},frict={5},rest={6},lFact={7},aFact={8}",
622 ControllingPrim.LocalID, m_vehicleMass, ControllingPrim.Inertia, m_VehicleGravity, 622 ControllingPrim.LocalID, m_vehicleMass, ControllingPrim.Inertia, m_VehicleGravity,
@@ -1121,7 +1121,6 @@ namespace OpenSim.Region.Physics.BulletSPlugin
1121 { 1121 {
1122 m_VhoverTargetHeight = m_VhoverHeight; 1122 m_VhoverTargetHeight = m_VhoverHeight;
1123 } 1123 }
1124
1125 if ((m_flags & VehicleFlag.HOVER_UP_ONLY) != 0) 1124 if ((m_flags & VehicleFlag.HOVER_UP_ONLY) != 0)
1126 { 1125 {
1127 // If body is already heigher, use its height as target height 1126 // If body is already heigher, use its height as target height
@@ -1170,7 +1169,6 @@ namespace OpenSim.Region.Physics.BulletSPlugin
1170 m_VhoverTimescale, m_VhoverHeight, m_VhoverTargetHeight, 1169 m_VhoverTimescale, m_VhoverHeight, m_VhoverTargetHeight,
1171 verticalError, verticalCorrection); 1170 verticalError, verticalCorrection);
1172 } 1171 }
1173
1174 } 1172 }
1175 } 1173 }
1176 1174
@@ -1357,6 +1355,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
1357 private void ComputeAngularTurning(float pTimestep) 1355 private void ComputeAngularTurning(float pTimestep)
1358 { 1356 {
1359 // The user wants this many radians per second angular change? 1357 // The user wants this many radians per second angular change?
1358 Vector3 origVehicleRotationalVelocity = VehicleRotationalVelocity; // DEBUG DEBUG
1360 Vector3 currentAngularV = VehicleRotationalVelocity * Quaternion.Inverse(VehicleOrientation); 1359 Vector3 currentAngularV = VehicleRotationalVelocity * Quaternion.Inverse(VehicleOrientation);
1361 Vector3 angularMotorContributionV = m_angularMotor.Step(pTimestep, currentAngularV); 1360 Vector3 angularMotorContributionV = m_angularMotor.Step(pTimestep, currentAngularV);
1362 1361
@@ -1369,20 +1368,20 @@ namespace OpenSim.Region.Physics.BulletSPlugin
1369 // TODO: This is here because this is where ODE put it but documentation says it 1368 // TODO: This is here because this is where ODE put it but documentation says it
1370 // is a linear effect. Where should this check go? 1369 // is a linear effect. Where should this check go?
1371 //if ((m_flags & (VehicleFlag.NO_DEFLECTION_UP)) != 0) 1370 //if ((m_flags & (VehicleFlag.NO_DEFLECTION_UP)) != 0)
1372 // { 1371 // {
1373 // angularMotorContributionV.X = 0f; 1372 // angularMotorContributionV.X = 0f;
1374 // angularMotorContributionV.Y = 0f; 1373 // angularMotorContributionV.Y = 0f;
1375 // } 1374 // }
1376 1375
1377 // Reduce any velocity by friction. 1376 // Reduce any velocity by friction.
1378 Vector3 frictionFactorW = ComputeFrictionFactor(m_angularFrictionTimescale, pTimestep); 1377 Vector3 frictionFactorW = ComputeFrictionFactor(m_angularFrictionTimescale, pTimestep);
1379 angularMotorContributionV -= (currentAngularV * frictionFactorW); 1378 angularMotorContributionV -= (currentAngularV * frictionFactorW);
1380 1379
1381 VehicleRotationalVelocity += angularMotorContributionV * VehicleOrientation; 1380 Vector3 angularMotorContributionW = angularMotorContributionV * VehicleOrientation;
1382 1381 VehicleRotationalVelocity += angularMotorContributionW;
1383
1384 1382
1385 VDetailLog("{0}, MoveAngular,angularTurning,angContribV={1}", ControllingPrim.LocalID, angularMotorContributionV); 1383 VDetailLog("{0}, MoveAngular,angularTurning,curAngVelV={1},origVehRotVel={2},vehRotVel={3},frictFact={4}, angContribV={5},angContribW={6}",
1384 ControllingPrim.LocalID, currentAngularV, origVehicleRotationalVelocity, VehicleRotationalVelocity, frictionFactorW, angularMotorContributionV, angularMotorContributionW);
1386 } 1385 }
1387 1386
1388 // From http://wiki.secondlife.com/wiki/Linden_Vehicle_Tutorial: 1387 // From http://wiki.secondlife.com/wiki/Linden_Vehicle_Tutorial:
@@ -1409,7 +1408,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
1409 1408
1410 // Flipping what was originally a timescale into a speed variable and then multiplying it by 2 1409 // Flipping what was originally a timescale into a speed variable and then multiplying it by 2
1411 // since only computing half the distance between the angles. 1410 // since only computing half the distance between the angles.
1412 float VerticalAttractionSpeed = (1 / m_verticalAttractionTimescale) * 2.0f; 1411 float verticalAttractionSpeed = (1 / m_verticalAttractionTimescale) * 2.0f;
1413 1412
1414 // Make a prediction of where the up axis will be when this is applied rather then where it is now as 1413 // Make a prediction of where the up axis will be when this is applied rather then where it is now as
1415 // this makes for a smoother adjustment and less fighting between the various forces. 1414 // this makes for a smoother adjustment and less fighting between the various forces.
@@ -1419,12 +1418,13 @@ namespace OpenSim.Region.Physics.BulletSPlugin
1419 Vector3 torqueVector = Vector3.Cross(predictedUp, Vector3.UnitZ); 1418 Vector3 torqueVector = Vector3.Cross(predictedUp, Vector3.UnitZ);
1420 1419
1421 // Scale vector by our timescale since it is an acceleration it is r/s^2 or radians a timescale squared 1420 // Scale vector by our timescale since it is an acceleration it is r/s^2 or radians a timescale squared
1422 Vector3 vertContributionV = torqueVector * VerticalAttractionSpeed * VerticalAttractionSpeed; 1421 Vector3 vertContributionV = torqueVector * verticalAttractionSpeed * verticalAttractionSpeed;
1423 1422
1424 VehicleRotationalVelocity += vertContributionV; 1423 VehicleRotationalVelocity += vertContributionV;
1425 1424
1426 VDetailLog("{0}, MoveAngular,verticalAttraction,upAxis={1},PredictedUp={2},torqueVector={3},contrib={4}", 1425 VDetailLog("{0}, MoveAngular,verticalAttraction,vertAttrSpeed={1},upAxis={2},PredictedUp={3},torqueVector={4},contrib={5}",
1427 ControllingPrim.LocalID, 1426 ControllingPrim.LocalID,
1427 verticalAttractionSpeed,
1428 vehicleUpAxis, 1428 vehicleUpAxis,
1429 predictedUp, 1429 predictedUp,
1430 torqueVector, 1430 torqueVector,
@@ -1437,37 +1437,38 @@ namespace OpenSim.Region.Physics.BulletSPlugin
1437 // http://stackoverflow.com/questions/14939657/computing-vector-from-quaternion-works-computing-quaternion-from-vector-does-no 1437 // http://stackoverflow.com/questions/14939657/computing-vector-from-quaternion-works-computing-quaternion-from-vector-does-no
1438 1438
1439 // Create a rotation that is only the vehicle's rotation around Z 1439 // Create a rotation that is only the vehicle's rotation around Z
1440 Vector3 currentEuler = Vector3.Zero; 1440 Vector3 currentEulerW = Vector3.Zero;
1441 VehicleOrientation.GetEulerAngles(out currentEuler.X, out currentEuler.Y, out currentEuler.Z); 1441 VehicleOrientation.GetEulerAngles(out currentEulerW.X, out currentEulerW.Y, out currentEulerW.Z);
1442 Quaternion justZOrientation = Quaternion.CreateFromAxisAngle(Vector3.UnitZ, currentEuler.Z); 1442 Quaternion justZOrientation = Quaternion.CreateFromAxisAngle(Vector3.UnitZ, currentEulerW.Z);
1443 1443
1444 // Create the axis that is perpendicular to the up vector and the rotated up vector. 1444 // Create the axis that is perpendicular to the up vector and the rotated up vector.
1445 Vector3 differenceAxis = Vector3.Cross(Vector3.UnitZ * justZOrientation, Vector3.UnitZ * VehicleOrientation); 1445 Vector3 differenceAxisW = Vector3.Cross(Vector3.UnitZ * justZOrientation, Vector3.UnitZ * VehicleOrientation);
1446 // Compute the angle between those to vectors. 1446 // Compute the angle between those to vectors.
1447 double differenceAngle = Math.Acos((double)Vector3.Dot(Vector3.UnitZ, Vector3.Normalize(Vector3.UnitZ * VehicleOrientation))); 1447 double differenceAngle = Math.Acos((double)Vector3.Dot(Vector3.UnitZ, Vector3.Normalize(Vector3.UnitZ * VehicleOrientation)));
1448 // 'differenceAngle' is the angle to rotate and 'differenceAxis' is the plane to rotate in to get the vehicle vertical 1448 // 'differenceAngle' is the angle to rotate and 'differenceAxis' is the plane to rotate in to get the vehicle vertical
1449 1449
1450 // Reduce the change by the time period it is to change in. Timestep is handled when velocity is applied. 1450 // Reduce the change by the time period it is to change in. Timestep is handled when velocity is applied.
1451 // TODO: add 'efficiency'. 1451 // TODO: add 'efficiency'.
1452 differenceAngle /= m_verticalAttractionTimescale; 1452 // differenceAngle /= m_verticalAttractionTimescale;
1453 1453
1454 // Create the quaterian representing the correction angle 1454 // Create the quaterian representing the correction angle
1455 Quaternion correctionRotation = Quaternion.CreateFromAxisAngle(differenceAxis, (float)differenceAngle); 1455 Quaternion correctionRotationW = Quaternion.CreateFromAxisAngle(differenceAxisW, (float)differenceAngle);
1456 1456
1457 // Turn that quaternion into Euler values to make it into velocities to apply. 1457 // Turn that quaternion into Euler values to make it into velocities to apply.
1458 Vector3 vertContributionV = Vector3.Zero; 1458 Vector3 vertContributionW = Vector3.Zero;
1459 correctionRotation.GetEulerAngles(out vertContributionV.X, out vertContributionV.Y, out vertContributionV.Z); 1459 correctionRotationW.GetEulerAngles(out vertContributionW.X, out vertContributionW.Y, out vertContributionW.Z);
1460 vertContributionV *= -1f; 1460 vertContributionW *= -1f;
1461 vertContributionW /= m_verticalAttractionTimescale;
1461 1462
1462 VehicleRotationalVelocity += vertContributionV; 1463 VehicleRotationalVelocity += vertContributionW;
1463 1464
1464 VDetailLog("{0}, MoveAngular,verticalAttraction,upAxis={1},diffAxis={2},diffAng={3},corrRot={4},contrib={5}", 1465 VDetailLog("{0}, MoveAngular,verticalAttraction,upAxis={1},diffAxis={2},diffAng={3},corrRot={4},contrib={5}",
1465 ControllingPrim.LocalID, 1466 ControllingPrim.LocalID,
1466 vehicleUpAxis, 1467 vehicleUpAxis,
1467 differenceAxis, 1468 differenceAxisW,
1468 differenceAngle, 1469 differenceAngle,
1469 correctionRotation, 1470 correctionRotationW,
1470 vertContributionV); 1471 vertContributionW);
1471 break; 1472 break;
1472 } 1473 }
1473 case 2: 1474 case 2:
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs b/OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs
index 960c0b4..7f94666 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs
@@ -309,16 +309,18 @@ public abstract class BSLinkset
309 } 309 }
310 ); 310 );
311 } 311 }
312 public virtual void ComputeLocalInertia(OMV.Vector3 inertiaFactor) 312 public virtual void ComputeAndSetLocalInertia(OMV.Vector3 inertiaFactor, float linksetMass)
313 { 313 {
314 ForEachMember((member) => 314 ForEachMember((member) =>
315 { 315 {
316 if (member.PhysBody.HasPhysicalBody) 316 if (member.PhysBody.HasPhysicalBody)
317 { 317 {
318 OMV.Vector3 inertia = m_physicsScene.PE.CalculateLocalInertia(member.PhysShape.physShapeInfo, member.Mass); 318 OMV.Vector3 inertia = m_physicsScene.PE.CalculateLocalInertia(member.PhysShape.physShapeInfo, linksetMass);
319 member.Inertia = inertia * inertiaFactor; 319 member.Inertia = inertia * inertiaFactor;
320 m_physicsScene.PE.SetMassProps(member.PhysBody, member.Mass, member.Inertia); 320 m_physicsScene.PE.SetMassProps(member.PhysBody, linksetMass, member.Inertia);
321 m_physicsScene.PE.UpdateInertiaTensor(member.PhysBody); 321 m_physicsScene.PE.UpdateInertiaTensor(member.PhysBody);
322 DetailLog("{0},BSLinkset.ComputeAndSetLocalInertia,m.mass={1}, inertia={2}", member.LocalID, linksetMass, member.Inertia);
323
322 } 324 }
323 return false; // 'false' says to continue looping 325 return false; // 'false' says to continue looping
324 } 326 }
@@ -334,6 +336,16 @@ public abstract class BSLinkset
334 } 336 }
335 ); 337 );
336 } 338 }
339 public virtual void AddToPhysicalCollisionFlags(CollisionFlags collFlags)
340 {
341 ForEachMember((member) =>
342 {
343 if (member.PhysBody.HasPhysicalBody)
344 m_physicsScene.PE.AddToCollisionFlags(member.PhysBody, collFlags);
345 return false; // 'false' says to continue looping
346 }
347 );
348 }
337 public virtual void RemoveFromPhysicalCollisionFlags(CollisionFlags collFlags) 349 public virtual void RemoveFromPhysicalCollisionFlags(CollisionFlags collFlags)
338 { 350 {
339 ForEachMember((member) => 351 ForEachMember((member) =>
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs
index 33ae5a5..6359046 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs
@@ -61,11 +61,11 @@ public sealed class BSLinksetCompound : BSLinkset
61 if (LinksetRoot.PhysBody.HasPhysicalBody) 61 if (LinksetRoot.PhysBody.HasPhysicalBody)
62 m_physicsScene.PE.SetGravity(LinksetRoot.PhysBody, gravity); 62 m_physicsScene.PE.SetGravity(LinksetRoot.PhysBody, gravity);
63 } 63 }
64 public override void ComputeLocalInertia(OMV.Vector3 inertiaFactor) 64 public override void ComputeAndSetLocalInertia(OMV.Vector3 inertiaFactor, float linksetMass)
65 { 65 {
66 OMV.Vector3 inertia = m_physicsScene.PE.CalculateLocalInertia(LinksetRoot.PhysShape.physShapeInfo, LinksetRoot.Mass); 66 OMV.Vector3 inertia = m_physicsScene.PE.CalculateLocalInertia(LinksetRoot.PhysShape.physShapeInfo, linksetMass);
67 LinksetRoot.Inertia = inertia * inertiaFactor; 67 LinksetRoot.Inertia = inertia * inertiaFactor;
68 m_physicsScene.PE.SetMassProps(LinksetRoot.PhysBody, LinksetRoot.Mass, LinksetRoot.Inertia); 68 m_physicsScene.PE.SetMassProps(LinksetRoot.PhysBody, linksetMass, LinksetRoot.Inertia);
69 m_physicsScene.PE.UpdateInertiaTensor(LinksetRoot.PhysBody); 69 m_physicsScene.PE.UpdateInertiaTensor(LinksetRoot.PhysBody);
70 } 70 }
71 public override void SetPhysicalCollisionFlags(CollisionFlags collFlags) 71 public override void SetPhysicalCollisionFlags(CollisionFlags collFlags)
@@ -73,6 +73,11 @@ public sealed class BSLinksetCompound : BSLinkset
73 if (LinksetRoot.PhysBody.HasPhysicalBody) 73 if (LinksetRoot.PhysBody.HasPhysicalBody)
74 m_physicsScene.PE.SetCollisionFlags(LinksetRoot.PhysBody, collFlags); 74 m_physicsScene.PE.SetCollisionFlags(LinksetRoot.PhysBody, collFlags);
75 } 75 }
76 public override void AddToPhysicalCollisionFlags(CollisionFlags collFlags)
77 {
78 if (LinksetRoot.PhysBody.HasPhysicalBody)
79 m_physicsScene.PE.AddToCollisionFlags(LinksetRoot.PhysBody, collFlags);
80 }
76 public override void RemoveFromPhysicalCollisionFlags(CollisionFlags collFlags) 81 public override void RemoveFromPhysicalCollisionFlags(CollisionFlags collFlags)
77 { 82 {
78 if (LinksetRoot.PhysBody.HasPhysicalBody) 83 if (LinksetRoot.PhysBody.HasPhysicalBody)