aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorRobert Adams2012-07-18 08:36:41 -0700
committerRobert Adams2012-07-20 14:02:27 -0700
commitcda67a68de11790ff7f3f19937b4d08309bc1e89 (patch)
tree7c4df7a4ffd035a043856b2698518e9dc8c868d6
parentCorrect namespace of BinaryLoggingModule (a cut-and-paste error). Add a simpl... (diff)
downloadopensim-SC_OLD-cda67a68de11790ff7f3f19937b4d08309bc1e89.zip
opensim-SC_OLD-cda67a68de11790ff7f3f19937b4d08309bc1e89.tar.gz
opensim-SC_OLD-cda67a68de11790ff7f3f19937b4d08309bc1e89.tar.bz2
opensim-SC_OLD-cda67a68de11790ff7f3f19937b4d08309bc1e89.tar.xz
BulletSim: Add very detailed logging to BSDynamics for vehicle debugging
-rw-r--r--OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs130
-rw-r--r--OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs1
-rw-r--r--OpenSim/Region/Physics/BulletSPlugin/BSScene.cs60
3 files changed, 146 insertions, 45 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs
index eb20eb3..bef7aec 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs
@@ -131,8 +131,9 @@ namespace OpenSim.Region.Physics.BulletSPlugin
131 m_type = Vehicle.TYPE_NONE; 131 m_type = Vehicle.TYPE_NONE;
132 } 132 }
133 133
134 internal void ProcessFloatVehicleParam(Vehicle pParam, float pValue) 134 internal void ProcessFloatVehicleParam(Vehicle pParam, float pValue, float timestep)
135 { 135 {
136 DetailLog("{0},ProcessFloatVehicleParam,param={1},val={2}", m_prim.LocalID, pParam, pValue);
136 switch (pParam) 137 switch (pParam)
137 { 138 {
138 case Vehicle.ANGULAR_DEFLECTION_EFFICIENCY: 139 case Vehicle.ANGULAR_DEFLECTION_EFFICIENCY:
@@ -229,8 +230,9 @@ namespace OpenSim.Region.Physics.BulletSPlugin
229 } 230 }
230 }//end ProcessFloatVehicleParam 231 }//end ProcessFloatVehicleParam
231 232
232 internal void ProcessVectorVehicleParam(Vehicle pParam, Vector3 pValue) 233 internal void ProcessVectorVehicleParam(Vehicle pParam, Vector3 pValue, float timestep)
233 { 234 {
235 DetailLog("{0},ProcessVectorVehicleParam,param={1},val={2}", m_prim.LocalID, pParam, pValue);
234 switch (pParam) 236 switch (pParam)
235 { 237 {
236 case Vehicle.ANGULAR_FRICTION_TIMESCALE: 238 case Vehicle.ANGULAR_FRICTION_TIMESCALE:
@@ -265,6 +267,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
265 267
266 internal void ProcessRotationVehicleParam(Vehicle pParam, Quaternion pValue) 268 internal void ProcessRotationVehicleParam(Vehicle pParam, Quaternion pValue)
267 { 269 {
270 DetailLog("{0},ProcessRotationalVehicleParam,param={1},val={2}", m_prim.LocalID, pParam, pValue);
268 switch (pParam) 271 switch (pParam)
269 { 272 {
270 case Vehicle.REFERENCE_FRAME: 273 case Vehicle.REFERENCE_FRAME:
@@ -278,6 +281,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
278 281
279 internal void ProcessVehicleFlags(int pParam, bool remove) 282 internal void ProcessVehicleFlags(int pParam, bool remove)
280 { 283 {
284 DetailLog("{0},ProcessVehicleFlags,param={1},remove={2}", m_prim.LocalID, pParam, remove);
281 if (remove) 285 if (remove)
282 { 286 {
283 if (pParam == -1) 287 if (pParam == -1)
@@ -434,6 +438,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
434 438
435 internal void ProcessTypeChange(Vehicle pType) 439 internal void ProcessTypeChange(Vehicle pType)
436 { 440 {
441 DetailLog("{0},ProcessTypeChange,type={1}", m_prim.LocalID, pType);
437 // Set Defaults For Type 442 // Set Defaults For Type
438 m_type = pType; 443 m_type = pType;
439 switch (pType) 444 switch (pType)
@@ -594,7 +599,6 @@ namespace OpenSim.Region.Physics.BulletSPlugin
594 m_flags |= (VehicleFlag.LIMIT_ROLL_ONLY); 599 m_flags |= (VehicleFlag.LIMIT_ROLL_ONLY);
595 m_Hoverflags |= (VehicleFlag.HOVER_GLOBAL_HEIGHT); 600 m_Hoverflags |= (VehicleFlag.HOVER_GLOBAL_HEIGHT);
596 break; 601 break;
597
598 } 602 }
599 }//end SetDefaultsForType 603 }//end SetDefaultsForType
600 604
@@ -609,12 +613,17 @@ namespace OpenSim.Region.Physics.BulletSPlugin
609 MoveLinear(pTimestep, pParentScene); 613 MoveLinear(pTimestep, pParentScene);
610 MoveAngular(pTimestep); 614 MoveAngular(pTimestep);
611 LimitRotation(pTimestep); 615 LimitRotation(pTimestep);
616 DetailLog("{0},step,pos={1},force={2},velocity={3},angvel={4}",
617 m_prim.LocalID, m_prim.Position, m_prim.Force, m_prim.Velocity, m_prim.RotationalVelocity);
612 }// end Step 618 }// end Step
613 619
614 private void MoveLinear(float pTimestep, BSScene _pParentScene) 620 private void MoveLinear(float pTimestep, BSScene _pParentScene)
615 { 621 {
616 if (!m_linearMotorDirection.ApproxEquals(Vector3.Zero, 0.01f)) // requested m_linearMotorDirection is significant 622 if (!m_linearMotorDirection.ApproxEquals(Vector3.Zero, 0.01f)) // requested m_linearMotorDirection is significant
617 { 623 {
624 Vector3 origDir = m_linearMotorDirection;
625 Vector3 origVel = m_lastLinearVelocityVector;
626
618 // add drive to body 627 // add drive to body
619 Vector3 addAmount = m_linearMotorDirection/(m_linearMotorTimescale/pTimestep); 628 Vector3 addAmount = m_linearMotorDirection/(m_linearMotorTimescale/pTimestep);
620 m_lastLinearVelocityVector += (addAmount*10); // lastLinearVelocityVector is the current body velocity vector? 629 m_lastLinearVelocityVector += (addAmount*10); // lastLinearVelocityVector is the current body velocity vector?
@@ -630,9 +639,10 @@ namespace OpenSim.Region.Physics.BulletSPlugin
630 639
631 // decay applied velocity 640 // decay applied velocity
632 Vector3 decayfraction = ((Vector3.One/(m_linearMotorDecayTimescale/pTimestep))); 641 Vector3 decayfraction = ((Vector3.One/(m_linearMotorDecayTimescale/pTimestep)));
633 //Console.WriteLine("decay: " + decayfraction);
634 m_linearMotorDirection -= m_linearMotorDirection * decayfraction * 0.5f; 642 m_linearMotorDirection -= m_linearMotorDirection * decayfraction * 0.5f;
635 //Console.WriteLine("actual: " + m_linearMotorDirection); 643
644 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);
636 } 646 }
637 else 647 else
638 { // requested is not significant 648 { // requested is not significant
@@ -643,63 +653,66 @@ namespace OpenSim.Region.Physics.BulletSPlugin
643 653
644 // convert requested object velocity to world-referenced vector 654 // convert requested object velocity to world-referenced vector
645 m_dir = m_lastLinearVelocityVector; 655 m_dir = m_lastLinearVelocityVector;
646 Quaternion rot = m_prim.Orientation; 656 m_dir *= m_prim.Orientation;
647 Quaternion rotq = new Quaternion(rot.X, rot.Y, rot.Z, rot.W); // rotq = rotation of object 657
648 m_dir *= rotq; // apply obj rotation to velocity vector 658 // Add the various forces into m_dir which will be our new direction vector (velocity)
649 659
650 // add Gravity andBuoyancy 660 // add Gravity and Buoyancy
651 // KF: So far I have found no good method to combine a script-requested 661 // KF: So far I have found no good method to combine a script-requested
652 // .Z velocity and gravity. Therefore only 0g will used script-requested 662 // .Z velocity and gravity. Therefore only 0g will used script-requested
653 // .Z velocity. >0g (m_VehicleBuoyancy < 1) will used modified gravity only. 663 // .Z velocity. >0g (m_VehicleBuoyancy < 1) will used modified gravity only.
654 Vector3 grav = Vector3.Zero; 664 Vector3 grav = Vector3.Zero;
655 // There is some gravity, make a gravity force vector 665 // There is some gravity, make a gravity force vector that is applied after object velocity.
656 // that is applied after object velocity.
657 float objMass = m_prim.Mass;
658 // m_VehicleBuoyancy: -1=2g; 0=1g; 1=0g; 666 // m_VehicleBuoyancy: -1=2g; 0=1g; 1=0g;
659 grav.Z = _pParentScene.DefaultGravity.Z * objMass * (1f - m_VehicleBuoyancy); 667 grav.Z = _pParentScene.DefaultGravity.Z * m_prim.Mass * (1f - m_VehicleBuoyancy);
660 // Preserve the current Z velocity 668 // Preserve the current Z velocity
661 Vector3 vel_now = m_prim.Velocity; 669 Vector3 vel_now = m_prim.Velocity;
662 m_dir.Z = vel_now.Z; // Preserve the accumulated falling velocity 670 m_dir.Z = vel_now.Z; // Preserve the accumulated falling velocity
663 671
664 Vector3 pos = m_prim.Position; 672 Vector3 pos = m_prim.Position;
673 Vector3 posChange = pos;
665// Vector3 accel = new Vector3(-(m_dir.X - m_lastLinearVelocityVector.X / 0.1f), -(m_dir.Y - m_lastLinearVelocityVector.Y / 0.1f), m_dir.Z - m_lastLinearVelocityVector.Z / 0.1f); 674// Vector3 accel = new Vector3(-(m_dir.X - m_lastLinearVelocityVector.X / 0.1f), -(m_dir.Y - m_lastLinearVelocityVector.Y / 0.1f), m_dir.Z - m_lastLinearVelocityVector.Z / 0.1f);
666 Vector3 posChange = new Vector3();
667 posChange.X = pos.X - m_lastPositionVector.X;
668 posChange.Y = pos.Y - m_lastPositionVector.Y;
669 posChange.Z = pos.Z - m_lastPositionVector.Z;
670 double Zchange = Math.Abs(posChange.Z); 675 double Zchange = Math.Abs(posChange.Z);
671 if (m_BlockingEndPoint != Vector3.Zero) 676 if (m_BlockingEndPoint != Vector3.Zero)
672 { 677 {
678 bool changed = false;
673 if (pos.X >= (m_BlockingEndPoint.X - (float)1)) 679 if (pos.X >= (m_BlockingEndPoint.X - (float)1))
674 { 680 {
675 pos.X -= posChange.X + 1; 681 pos.X -= posChange.X + 1;
676 m_prim.Position = pos; 682 changed = true;
677 } 683 }
678 if (pos.Y >= (m_BlockingEndPoint.Y - (float)1)) 684 if (pos.Y >= (m_BlockingEndPoint.Y - (float)1))
679 { 685 {
680 pos.Y -= posChange.Y + 1; 686 pos.Y -= posChange.Y + 1;
681 m_prim.Position = pos; 687 changed = true;
682 } 688 }
683 if (pos.Z >= (m_BlockingEndPoint.Z - (float)1)) 689 if (pos.Z >= (m_BlockingEndPoint.Z - (float)1))
684 { 690 {
685 pos.Z -= posChange.Z + 1; 691 pos.Z -= posChange.Z + 1;
686 m_prim.Position = pos; 692 changed = true;
687 } 693 }
688 if (pos.X <= 0) 694 if (pos.X <= 0)
689 { 695 {
690 pos.X += posChange.X + 1; 696 pos.X += posChange.X + 1;
691 m_prim.Position = pos; 697 changed = true;
692 } 698 }
693 if (pos.Y <= 0) 699 if (pos.Y <= 0)
694 { 700 {
695 pos.Y += posChange.Y + 1; 701 pos.Y += posChange.Y + 1;
702 changed = true;
703 }
704 if (changed)
705 {
696 m_prim.Position = pos; 706 m_prim.Position = pos;
707 DetailLog("{0},MoveLinear,blockingEndPoint,block={1},origPos={2},pos={3}",
708 m_prim.LocalID, m_BlockingEndPoint, posChange, pos);
697 } 709 }
698 } 710 }
699 if (pos.Z < _pParentScene.GetTerrainHeightAtXY(pos.X, pos.Y)) 711 if (pos.Z < _pParentScene.GetTerrainHeightAtXY(pos.X, pos.Y))
700 { 712 {
701 pos.Z = _pParentScene.GetTerrainHeightAtXY(pos.X, pos.Y) + 2; 713 pos.Z = _pParentScene.GetTerrainHeightAtXY(pos.X, pos.Y) + 2;
702 m_prim.Position = pos; 714 m_prim.Position = pos;
715 DetailLog("{0},MoveLinear,terrainHeight,pos={1}", m_prim.LocalID, pos);
703 } 716 }
704 717
705 // Check if hovering 718 // Check if hovering
@@ -746,6 +759,8 @@ namespace OpenSim.Region.Physics.BulletSPlugin
746 } 759 }
747 } 760 }
748 761
762 DetailLog("{0},MoveLinear,hover,pos={1},dir={2},height={3},target={4}", m_prim.LocalID, pos, m_dir, m_VhoverHeight, m_VhoverTargetHeight);
763
749// m_VhoverEfficiency = 0f; // 0=boucy, 1=Crit.damped 764// m_VhoverEfficiency = 0f; // 0=boucy, 1=Crit.damped
750// m_VhoverTimescale = 0f; // time to acheive height 765// m_VhoverTimescale = 0f; // time to acheive height
751// pTimestep is time since last frame,in secs 766// pTimestep is time since last frame,in secs
@@ -774,12 +789,13 @@ namespace OpenSim.Region.Physics.BulletSPlugin
774 { 789 {
775 grav.Z = (float)(grav.Z * 1.125); 790 grav.Z = (float)(grav.Z * 1.125);
776 } 791 }
777 float terraintemp = _pParentScene.GetTerrainHeightAtXY(pos.X, pos.Y); 792 float terraintemp = _pParentScene.GetTerrainHeightAtXYZ(pos);
778 float postemp = (pos.Z - terraintemp); 793 float postemp = (pos.Z - terraintemp);
779 if (postemp > 2.5f) 794 if (postemp > 2.5f)
780 { 795 {
781 grav.Z = (float)(grav.Z * 1.037125); 796 grav.Z = (float)(grav.Z * 1.037125);
782 } 797 }
798 DetailLog("{0},MoveLinear,limitMotorUp,grav={1}", m_prim.LocalID, grav);
783 //End Experimental Values 799 //End Experimental Values
784 } 800 }
785 if ((m_flags & (VehicleFlag.NO_X)) != 0) 801 if ((m_flags & (VehicleFlag.NO_X)) != 0)
@@ -803,29 +819,35 @@ namespace OpenSim.Region.Physics.BulletSPlugin
803 m_prim.Force = grav; 819 m_prim.Force = grav;
804 820
805 821
806 // apply friction 822 // Apply friction
807 Vector3 decayamount = Vector3.One / (m_linearFrictionTimescale / pTimestep); 823 Vector3 decayamount = Vector3.One / (m_linearFrictionTimescale / pTimestep);
808 m_lastLinearVelocityVector -= m_lastLinearVelocityVector * decayamount; 824 m_lastLinearVelocityVector -= m_lastLinearVelocityVector * decayamount;
825
826 DetailLog("{0},MoveLinear,done,pos={1},vel={2},force={3},decay={4}",
827 m_prim.LocalID, m_lastPositionVector, m_dir, grav, decayamount);
828
809 } // end MoveLinear() 829 } // end MoveLinear()
810 830
811 private void MoveAngular(float pTimestep) 831 private void MoveAngular(float pTimestep)
812 { 832 {
813 /* 833 // m_angularMotorDirection // angular velocity requested by LSL motor
814 private Vector3 m_angularMotorDirection = Vector3.Zero; // angular velocity requested by LSL motor 834 // m_angularMotorApply // application frame counter
815 private int m_angularMotorApply = 0; // application frame counter 835 // m_angularMotorVelocity // current angular motor velocity (ramps up and down)
816 private float m_angularMotorVelocity = 0; // current angular motor velocity (ramps up and down) 836 // m_angularMotorTimescale // motor angular velocity ramp up rate
817 private float m_angularMotorTimescale = 0; // motor angular velocity ramp up rate 837 // m_angularMotorDecayTimescale // motor angular velocity decay rate
818 private float m_angularMotorDecayTimescale = 0; // motor angular velocity decay rate 838 // m_angularFrictionTimescale // body angular velocity decay rate
819 private Vector3 m_angularFrictionTimescale = Vector3.Zero; // body angular velocity decay rate 839 // m_lastAngularVelocity // what was last applied to body
820 private Vector3 m_lastAngularVelocity = Vector3.Zero; // what was last applied to body
821 */
822 840
823 // Get what the body is doing, this includes 'external' influences 841 // Get what the body is doing, this includes 'external' influences
824 Vector3 angularVelocity = m_prim.RotationalVelocity; 842 Vector3 angularVelocity = m_prim.RotationalVelocity;
825 // Vector3 angularVelocity = Vector3.Zero;
826 843
827 if (m_angularMotorApply > 0) 844 if (m_angularMotorApply > 0)
828 { 845 {
846 // Rather than snapping the angular motor velocity from the old value to
847 // a newly set velocity, this routine steps the value from the previous
848 // value (m_angularMotorVelocity) to the requested value (m_angularMotorDirection).
849 // There are m_angularMotorApply steps.
850 Vector3 origAngularVelocity = m_angularMotorVelocity;
829 // ramp up to new value 851 // ramp up to new value
830 // current velocity += error / (time to get there / step interval) 852 // current velocity += error / (time to get there / step interval)
831 // requested speed - last motor speed 853 // requested speed - last motor speed
@@ -833,23 +855,21 @@ namespace OpenSim.Region.Physics.BulletSPlugin
833 m_angularMotorVelocity.Y += (m_angularMotorDirection.Y - m_angularMotorVelocity.Y) / (m_angularMotorTimescale / pTimestep); 855 m_angularMotorVelocity.Y += (m_angularMotorDirection.Y - m_angularMotorVelocity.Y) / (m_angularMotorTimescale / pTimestep);
834 m_angularMotorVelocity.Z += (m_angularMotorDirection.Z - m_angularMotorVelocity.Z) / (m_angularMotorTimescale / pTimestep); 856 m_angularMotorVelocity.Z += (m_angularMotorDirection.Z - m_angularMotorVelocity.Z) / (m_angularMotorTimescale / pTimestep);
835 857
858 DetailLog("{0},MoveAngular,angularMotorApply,apply={1},origvel={2},dir={3},vel={4}",
859 m_prim.LocalID,m_angularMotorApply,origAngularVelocity, m_angularMotorDirection, m_angularMotorVelocity);
860
836 m_angularMotorApply--; // This is done so that if script request rate is less than phys frame rate the expected 861 m_angularMotorApply--; // This is done so that if script request rate is less than phys frame rate the expected
837 // velocity may still be acheived. 862 // velocity may still be acheived.
838 } 863 }
839 else 864 else
840 { 865 {
841 // no motor recently applied, keep the body velocity 866 // No motor recently applied, keep the body velocity
842 /* m_angularMotorVelocity.X = angularVelocity.X;
843 m_angularMotorVelocity.Y = angularVelocity.Y;
844 m_angularMotorVelocity.Z = angularVelocity.Z; */
845
846 // and decay the velocity 867 // and decay the velocity
847 m_angularMotorVelocity -= m_angularMotorVelocity / (m_angularMotorDecayTimescale / pTimestep); 868 m_angularMotorVelocity -= m_angularMotorVelocity / (m_angularMotorDecayTimescale / pTimestep);
848 } // end motor section 869 } // end motor section
849 870
850 // Vertical attractor section 871 // Vertical attractor section
851 Vector3 vertattr = Vector3.Zero; 872 Vector3 vertattr = Vector3.Zero;
852
853 if (m_verticalAttractionTimescale < 300) 873 if (m_verticalAttractionTimescale < 300)
854 { 874 {
855 float VAservo = 0.2f / (m_verticalAttractionTimescale * pTimestep); 875 float VAservo = 0.2f / (m_verticalAttractionTimescale * pTimestep);
@@ -871,7 +891,6 @@ namespace OpenSim.Region.Physics.BulletSPlugin
871 // Error is 0 (no error) to +/- 2 (max error) 891 // Error is 0 (no error) to +/- 2 (max error)
872 // scale it by VAservo 892 // scale it by VAservo
873 verterr = verterr * VAservo; 893 verterr = verterr * VAservo;
874//if (frcount == 0) Console.WriteLine("VAerr=" + verterr);
875 894
876 // As the body rotates around the X axis, then verterr.Y increases; Rotated around Y then .X increases, so 895 // As the body rotates around the X axis, then verterr.Y increases; Rotated around Y then .X increases, so
877 // Change Body angular velocity X based on Y, and Y based on X. Z is not changed. 896 // Change Body angular velocity X based on Y, and Y based on X. Z is not changed.
@@ -884,11 +903,15 @@ namespace OpenSim.Region.Physics.BulletSPlugin
884 vertattr.X += bounce * angularVelocity.X; 903 vertattr.X += bounce * angularVelocity.X;
885 vertattr.Y += bounce * angularVelocity.Y; 904 vertattr.Y += bounce * angularVelocity.Y;
886 905
906 DetailLog("{0},MoveAngular,verticalAttraction,verterr={1},bounce={2},vertattr={3}",
907 m_prim.LocalID, verterr, bounce, vertattr);
908
887 } // else vertical attractor is off 909 } // else vertical attractor is off
888 910
889 // m_lastVertAttractor = vertattr; 911 // m_lastVertAttractor = vertattr;
890 912
891 // Bank section tba 913 // Bank section tba
914
892 // Deflection section tba 915 // Deflection section tba
893 916
894 // Sum velocities 917 // Sum velocities
@@ -898,11 +921,13 @@ namespace OpenSim.Region.Physics.BulletSPlugin
898 { 921 {
899 m_lastAngularVelocity.X = 0; 922 m_lastAngularVelocity.X = 0;
900 m_lastAngularVelocity.Y = 0; 923 m_lastAngularVelocity.Y = 0;
924 DetailLog("{0},MoveAngular,noDeflectionUp,lastAngular={1}", m_prim.LocalID, m_lastAngularVelocity);
901 } 925 }
902 926
903 if (m_lastAngularVelocity.ApproxEquals(Vector3.Zero, 0.01f)) 927 if (m_lastAngularVelocity.ApproxEquals(Vector3.Zero, 0.01f))
904 { 928 {
905 m_lastAngularVelocity = Vector3.Zero; // Reduce small value to zero. 929 m_lastAngularVelocity = Vector3.Zero; // Reduce small value to zero.
930 DetailLog("{0},MoveAngular,zeroSmallValues,lastAngular={1}", m_prim.LocalID, m_lastAngularVelocity);
906 } 931 }
907 932
908 // apply friction 933 // apply friction
@@ -912,10 +937,13 @@ namespace OpenSim.Region.Physics.BulletSPlugin
912 // Apply to the body 937 // Apply to the body
913 m_prim.RotationalVelocity = m_lastAngularVelocity; 938 m_prim.RotationalVelocity = m_lastAngularVelocity;
914 939
940 DetailLog("{0},MoveAngular,done,decay={1},lastAngular={2}", m_prim.LocalID, decayamount, m_lastAngularVelocity);
941 } //end MoveAngular
942
915 } //end MoveAngular 943 } //end MoveAngular
916 internal void LimitRotation(float timestep) 944 internal void LimitRotation(float timestep)
917 { 945 {
918 Quaternion rotq = m_prim.Orientation; // rotq = rotation of object 946 Quaternion rotq = m_prim.Orientation;
919 Quaternion m_rot = rotq; 947 Quaternion m_rot = rotq;
920 bool changed = false; 948 bool changed = false;
921 if (m_RollreferenceFrame != Quaternion.Identity) 949 if (m_RollreferenceFrame != Quaternion.Identity)
@@ -923,18 +951,22 @@ namespace OpenSim.Region.Physics.BulletSPlugin
923 if (rotq.X >= m_RollreferenceFrame.X) 951 if (rotq.X >= m_RollreferenceFrame.X)
924 { 952 {
925 m_rot.X = rotq.X - (m_RollreferenceFrame.X / 2); 953 m_rot.X = rotq.X - (m_RollreferenceFrame.X / 2);
954 changed = true;
926 } 955 }
927 if (rotq.Y >= m_RollreferenceFrame.Y) 956 if (rotq.Y >= m_RollreferenceFrame.Y)
928 { 957 {
929 m_rot.Y = rotq.Y - (m_RollreferenceFrame.Y / 2); 958 m_rot.Y = rotq.Y - (m_RollreferenceFrame.Y / 2);
959 changed = true;
930 } 960 }
931 if (rotq.X <= -m_RollreferenceFrame.X) 961 if (rotq.X <= -m_RollreferenceFrame.X)
932 { 962 {
933 m_rot.X = rotq.X + (m_RollreferenceFrame.X / 2); 963 m_rot.X = rotq.X + (m_RollreferenceFrame.X / 2);
964 changed = true;
934 } 965 }
935 if (rotq.Y <= -m_RollreferenceFrame.Y) 966 if (rotq.Y <= -m_RollreferenceFrame.Y)
936 { 967 {
937 m_rot.Y = rotq.Y + (m_RollreferenceFrame.Y / 2); 968 m_rot.Y = rotq.Y + (m_RollreferenceFrame.Y / 2);
969 changed = true;
938 } 970 }
939 changed = true; 971 changed = true;
940 } 972 }
@@ -944,8 +976,22 @@ namespace OpenSim.Region.Physics.BulletSPlugin
944 m_rot.Y = 0; 976 m_rot.Y = 0;
945 changed = true; 977 changed = true;
946 } 978 }
979 if ((m_flags & VehicleFlag.LOCK_ROTATION) != 0)
980 {
981 m_rot.X = 0;
982 m_rot.Y = 0;
983 changed = true;
984 }
947 if (changed) 985 if (changed)
948 m_prim.Orientation = m_rot; 986 m_prim.Orientation = m_rot;
987
988 DetailLog("{0},LimitRotation,done,changed={1},orig={2},new={3}", m_prim.LocalID, changed, rotq, m_rot);
989 }
990
991 // Invoke the detailed logger and output something if it's enabled.
992 private void DetailLog(string msg, params Object[] args)
993 {
994 m_prim.Scene.VehicleLogging.Write(msg, args);
949 } 995 }
950 } 996 }
951} 997}
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
index 23b276e..227696e 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
@@ -52,6 +52,7 @@ public sealed class BSPrim : PhysicsActor
52 private List<ConvexResult> _hulls; 52 private List<ConvexResult> _hulls;
53 53
54 private BSScene _scene; 54 private BSScene _scene;
55 public BSScene Scene { get { return _scene; } }
55 private String _avName; 56 private String _avName;
56 private uint _localID = 0; 57 private uint _localID = 0;
57 58
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs
index 150326e..c4b4332 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs
@@ -29,12 +29,13 @@ using System.Collections.Generic;
29using System.Runtime.InteropServices; 29using System.Runtime.InteropServices;
30using System.Text; 30using System.Text;
31using System.Threading; 31using System.Threading;
32using Nini.Config;
33using log4net;
34using OpenSim.Framework; 32using OpenSim.Framework;
33using OpenSim.Region.CoreModules.Framework.Statistics.Logging;
34using OpenSim.Region.Framework;
35using OpenSim.Region.Physics.Manager; 35using OpenSim.Region.Physics.Manager;
36using Nini.Config;
37using log4net;
36using OpenMetaverse; 38using OpenMetaverse;
37using OpenSim.Region.Framework;
38 39
39// TODOs for BulletSim (for BSScene, BSPrim, BSCharacter and BulletSim) 40// TODOs for BulletSim (for BSScene, BSPrim, BSCharacter and BulletSim)
40// Debug linkset 41// Debug linkset
@@ -158,6 +159,19 @@ public class BSScene : PhysicsScene, IPhysicsParameters
158 159
159 private BulletSimAPI.DebugLogCallback m_DebugLogCallbackHandle; 160 private BulletSimAPI.DebugLogCallback m_DebugLogCallbackHandle;
160 161
162 // Sometimes you just have to log everything.
163 public LogWriter PhysicsLogging;
164 private bool m_physicsLoggingEnabled;
165 private string m_physicsLoggingDir;
166 private string m_physicsLoggingPrefix;
167 private int m_physicsLoggingFileMinutes;
168
169 public LogWriter VehicleLogging;
170 private bool m_vehicleLoggingEnabled;
171 private string m_vehicleLoggingDir;
172 private string m_vehicleLoggingPrefix;
173 private int m_vehicleLoggingFileMinutes;
174
161 public BSScene(string identifier) 175 public BSScene(string identifier)
162 { 176 {
163 m_initialized = false; 177 m_initialized = false;
@@ -178,6 +192,26 @@ public class BSScene : PhysicsScene, IPhysicsParameters
178 m_updateArray = new EntityProperties[m_maxUpdatesPerFrame]; 192 m_updateArray = new EntityProperties[m_maxUpdatesPerFrame];
179 m_updateArrayPinnedHandle = GCHandle.Alloc(m_updateArray, GCHandleType.Pinned); 193 m_updateArrayPinnedHandle = GCHandle.Alloc(m_updateArray, GCHandleType.Pinned);
180 194
195 // Enable very detailed logging.
196 // By creating an empty logger when not logging, the log message invocation code
197 // can be left in and every call doesn't have to check for null.
198 if (m_physicsLoggingEnabled)
199 {
200 PhysicsLogging = new LogWriter(m_physicsLoggingDir, m_physicsLoggingPrefix, m_physicsLoggingFileMinutes);
201 }
202 else
203 {
204 PhysicsLogging = new LogWriter();
205 }
206 if (m_vehicleLoggingEnabled)
207 {
208 VehicleLogging = new LogWriter(m_vehicleLoggingDir, m_vehicleLoggingPrefix, m_vehicleLoggingFileMinutes);
209 }
210 else
211 {
212 VehicleLogging = new LogWriter();
213 }
214
181 // Get the version of the DLL 215 // Get the version of the DLL
182 // TODO: this doesn't work yet. Something wrong with marshaling the returned string. 216 // TODO: this doesn't work yet. Something wrong with marshaling the returned string.
183 // BulletSimVersion = BulletSimAPI.GetVersion(); 217 // BulletSimVersion = BulletSimAPI.GetVersion();
@@ -321,6 +355,17 @@ public class BSScene : PhysicsScene, IPhysicsParameters
321 parms.shouldSplitSimulationIslands = ParamBoolean(pConfig, "ShouldSplitSimulationIslands", parms.shouldSplitSimulationIslands); 355 parms.shouldSplitSimulationIslands = ParamBoolean(pConfig, "ShouldSplitSimulationIslands", parms.shouldSplitSimulationIslands);
322 parms.shouldEnableFrictionCaching = ParamBoolean(pConfig, "ShouldEnableFrictionCaching", parms.shouldEnableFrictionCaching); 356 parms.shouldEnableFrictionCaching = ParamBoolean(pConfig, "ShouldEnableFrictionCaching", parms.shouldEnableFrictionCaching);
323 parms.numberOfSolverIterations = pConfig.GetFloat("NumberOfSolverIterations", parms.numberOfSolverIterations); 357 parms.numberOfSolverIterations = pConfig.GetFloat("NumberOfSolverIterations", parms.numberOfSolverIterations);
358
359 // Very detailed logging for physics debugging
360 m_physicsLoggingEnabled = pConfig.GetBoolean("PhysicsLoggingEnabled", false);
361 m_physicsLoggingDir = pConfig.GetString("PhysicsLoggingDir", ".");
362 m_physicsLoggingPrefix = pConfig.GetString("PhysicsLoggingPrefix", "physics-");
363 m_physicsLoggingFileMinutes = pConfig.GetInt("PhysicsLoggingFileMinutes", 5);
364 // Very detailed logging for vehicle debugging
365 m_vehicleLoggingEnabled = pConfig.GetBoolean("VehicleLoggingEnabled", false);
366 m_vehicleLoggingDir = pConfig.GetString("VehicleLoggingDir", ".");
367 m_vehicleLoggingPrefix = pConfig.GetString("VehicleLoggingPrefix", "vehicle-");
368 m_vehicleLoggingFileMinutes = pConfig.GetInt("VehicleLoggingFileMinutes", 5);
324 } 369 }
325 } 370 }
326 m_params[0] = parms; 371 m_params[0] = parms;
@@ -560,8 +605,17 @@ public class BSScene : PhysicsScene, IPhysicsParameters
560 }); 605 });
561 } 606 }
562 607
608 // Someday we will have complex terrain with caves and tunnels
609 // For the moment, it's flat and convex
610 public float GetTerrainHeightAtXYZ(Vector3 loc)
611 {
612 return GetTerrainHeightAtXY(loc.X, loc.Y);
613 }
614
563 public float GetTerrainHeightAtXY(float tX, float tY) 615 public float GetTerrainHeightAtXY(float tX, float tY)
564 { 616 {
617 if (tX < 0 || tX >= Constants.RegionSize || tY < 0 || tY >= Constants.RegionSize)
618 return 30;
565 return m_heightMap[((int)tX) * Constants.RegionSize + ((int)tY)]; 619 return m_heightMap[((int)tX) * Constants.RegionSize + ((int)tY)];
566 } 620 }
567 621