aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs')
-rw-r--r--OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs52
1 files changed, 37 insertions, 15 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs
index 4c5bc85..c197e61 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs
@@ -613,23 +613,30 @@ namespace OpenSim.Region.Physics.BulletSPlugin
613 MoveAngular(pTimestep); 613 MoveAngular(pTimestep);
614 LimitRotation(pTimestep); 614 LimitRotation(pTimestep);
615 615
616 DetailLog("{0},step,done,pos={1},force={2},velocity={3},angvel={4}", 616 DetailLog("{0},Dynamics,done,pos={1},force={2},velocity={3},angvel={4}",
617 m_prim.LocalID, m_prim.Position, m_prim.Force, m_prim.Velocity, m_prim.RotationalVelocity); 617 m_prim.LocalID, m_prim.Position, m_prim.Force, m_prim.Velocity, m_prim.RotationalVelocity);
618 }// end Step 618 }// end Step
619 619
620 private void MoveLinear(float pTimestep) 620 private void MoveLinear(float pTimestep)
621 { 621 {
622 if (!m_linearMotorDirection.ApproxEquals(Vector3.Zero, 0.01f)) // requested m_linearMotorDirection is significant 622 // requested m_linearMotorDirection is significant
623 // if (!m_linearMotorDirection.ApproxEquals(Vector3.Zero, 0.01f))
624 if (m_linearMotorDirection.LengthSquared() > 0.0001f)
623 { 625 {
624 Vector3 origDir = m_linearMotorDirection; 626 Vector3 origDir = m_linearMotorDirection;
625 Vector3 origVel = m_lastLinearVelocityVector; 627 Vector3 origVel = m_lastLinearVelocityVector;
626 628
627 // add drive to body 629 // add drive to body
628 Vector3 addAmount = m_linearMotorDirection/(m_linearMotorTimescale/pTimestep); 630 // Vector3 addAmount = m_linearMotorDirection/(m_linearMotorTimescale/pTimestep);
629 m_lastLinearVelocityVector += (addAmount*10); // lastLinearVelocityVector is the current body velocity vector? 631 Vector3 addAmount = m_linearMotorDirection/(m_linearMotorTimescale);
632 // lastLinearVelocityVector is the current body velocity vector?
633 // RA: Not sure what the *10 is for. A correction for pTimestep?
634 // m_lastLinearVelocityVector += (addAmount*10);
635 m_lastLinearVelocityVector += addAmount;
630 636
631 // This will work temporarily, but we really need to compare speed on an axis 637 // This will work temporarily, but we really need to compare speed on an axis
632 // KF: Limit body velocity to applied velocity? 638 // KF: Limit body velocity to applied velocity?
639 // Limit the velocity vector to less than the last set linear motor direction
633 if (Math.Abs(m_lastLinearVelocityVector.X) > Math.Abs(m_linearMotorDirectionLASTSET.X)) 640 if (Math.Abs(m_lastLinearVelocityVector.X) > Math.Abs(m_linearMotorDirectionLASTSET.X))
634 m_lastLinearVelocityVector.X = m_linearMotorDirectionLASTSET.X; 641 m_lastLinearVelocityVector.X = m_linearMotorDirectionLASTSET.X;
635 if (Math.Abs(m_lastLinearVelocityVector.Y) > Math.Abs(m_linearMotorDirectionLASTSET.Y)) 642 if (Math.Abs(m_lastLinearVelocityVector.Y) > Math.Abs(m_linearMotorDirectionLASTSET.Y))
@@ -641,19 +648,30 @@ namespace OpenSim.Region.Physics.BulletSPlugin
641 Vector3 decayfraction = ((Vector3.One/(m_linearMotorDecayTimescale/pTimestep))); 648 Vector3 decayfraction = ((Vector3.One/(m_linearMotorDecayTimescale/pTimestep)));
642 m_linearMotorDirection -= m_linearMotorDirection * decayfraction * 0.5f; 649 m_linearMotorDirection -= m_linearMotorDirection * decayfraction * 0.5f;
643 650
651 /*
652 Vector3 addAmount = (m_linearMotorDirection - m_lastLinearVelocityVector)/m_linearMotorTimescale;
653 m_lastLinearVelocityVector += addAmount;
654
655 float decayfraction = (1.0f - 1.0f / m_linearMotorDecayTimescale);
656 m_linearMotorDirection *= decayfraction;
657
658 */
659
644 DetailLog("{0},MoveLinear,nonZero,origdir={1},origvel={2},add={3},decay={4},dir={5},vel={6}", 660 DetailLog("{0},MoveLinear,nonZero,origdir={1},origvel={2},add={3},decay={4},dir={5},vel={6}",
645 m_prim.LocalID, origDir, origVel, addAmount, decayfraction, m_linearMotorDirection, m_lastLinearVelocityVector); 661 m_prim.LocalID, origDir, origVel, addAmount, decayfraction, m_linearMotorDirection, m_lastLinearVelocityVector);
646 } 662 }
647 else 663 else
648 { // requested is not significant 664 {
649 // if what remains of applied is small, zero it. 665 // if what remains of applied is small, zero it.
650 if (m_lastLinearVelocityVector.ApproxEquals(Vector3.Zero, 0.01f)) 666 // if (m_lastLinearVelocityVector.ApproxEquals(Vector3.Zero, 0.01f))
651 m_lastLinearVelocityVector = Vector3.Zero; 667 // m_lastLinearVelocityVector = Vector3.Zero;
668 m_linearMotorDirection = Vector3.Zero;
669 m_lastLinearVelocityVector = Vector3.Zero;
652 } 670 }
653 671
654 // convert requested object velocity to world-referenced vector 672 // convert requested object velocity to world-referenced vector
655 m_dir = m_lastLinearVelocityVector; 673 Quaternion rotq = m_prim.Orientation;
656 m_dir *= m_prim.Orientation; 674 m_dir = m_lastLinearVelocityVector * rotq;
657 675
658 // Add the various forces into m_dir which will be our new direction vector (velocity) 676 // Add the various forces into m_dir which will be our new direction vector (velocity)
659 677
@@ -708,9 +726,11 @@ namespace OpenSim.Region.Physics.BulletSPlugin
708 m_prim.LocalID, m_BlockingEndPoint, posChange, pos); 726 m_prim.LocalID, m_BlockingEndPoint, posChange, pos);
709 } 727 }
710 } 728 }
711 if (pos.Z < m_prim.Scene.GetTerrainHeightAtXY(pos.X, pos.Y)) 729
730 // If below the terrain, move us above the ground a little.
731 if (pos.Z < m_prim.Scene.GetTerrainHeightAtXYZ(pos))
712 { 732 {
713 pos.Z = m_prim.Scene.GetTerrainHeightAtXY(pos.X, pos.Y) + 2; 733 pos.Z = m_prim.Scene.GetTerrainHeightAtXYZ(pos) + 2;
714 m_prim.Position = pos; 734 m_prim.Position = pos;
715 DetailLog("{0},MoveLinear,terrainHeight,pos={1}", m_prim.LocalID, pos); 735 DetailLog("{0},MoveLinear,terrainHeight,pos={1}", m_prim.LocalID, pos);
716 } 736 }
@@ -816,8 +836,9 @@ namespace OpenSim.Region.Physics.BulletSPlugin
816 // Apply velocity 836 // Apply velocity
817 m_prim.Velocity = m_dir; 837 m_prim.Velocity = m_dir;
818 // apply gravity force 838 // apply gravity force
819 m_prim.Force = grav; 839 // Why is this set here? The physics engine already does gravity.
820 840 // m_prim.AddForce(grav, false);
841 // m_prim.Force = grav;
821 842
822 // Apply friction 843 // Apply friction
823 Vector3 decayamount = Vector3.One / (m_linearFrictionTimescale / pTimestep); 844 Vector3 decayamount = Vector3.One / (m_linearFrictionTimescale / pTimestep);
@@ -990,7 +1011,8 @@ namespace OpenSim.Region.Physics.BulletSPlugin
990 // Invoke the detailed logger and output something if it's enabled. 1011 // Invoke the detailed logger and output something if it's enabled.
991 private void DetailLog(string msg, params Object[] args) 1012 private void DetailLog(string msg, params Object[] args)
992 { 1013 {
993 m_prim.Scene.VehicleLogging.Write(msg, args); 1014 if (m_prim.Scene.VehicleLoggingEnabled)
1015 m_prim.Scene.PhysicsLogging.Write(msg, args);
994 } 1016 }
995 } 1017 }
996} 1018}