diff options
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs')
-rw-r--r-- | OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | 138 |
1 files changed, 127 insertions, 11 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs index 826261c..94b63e5 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | |||
@@ -66,9 +66,6 @@ public sealed class BSPrim : BSPhysObject | |||
66 | private float _restitution; | 66 | private float _restitution; |
67 | private bool _setAlwaysRun; | 67 | private bool _setAlwaysRun; |
68 | private bool _throttleUpdates; | 68 | private bool _throttleUpdates; |
69 | private bool _isColliding; | ||
70 | private bool _collidingGround; | ||
71 | private bool _collidingObj; | ||
72 | private bool _floatOnWater; | 69 | private bool _floatOnWater; |
73 | private OMV.Vector3 _rotationalVelocity; | 70 | private OMV.Vector3 _rotationalVelocity; |
74 | private bool _kinematic; | 71 | private bool _kinematic; |
@@ -76,13 +73,14 @@ public sealed class BSPrim : BSPhysObject | |||
76 | 73 | ||
77 | private BSDynamics _vehicle; | 74 | private BSDynamics _vehicle; |
78 | 75 | ||
76 | private BSVMotor _targetMotor; | ||
79 | private OMV.Vector3 _PIDTarget; | 77 | private OMV.Vector3 _PIDTarget; |
80 | private bool _usePID; | ||
81 | private float _PIDTau; | 78 | private float _PIDTau; |
82 | private bool _useHoverPID; | 79 | |
80 | private BSFMotor _hoverMotor; | ||
83 | private float _PIDHoverHeight; | 81 | private float _PIDHoverHeight; |
84 | private PIDHoverType _PIDHoverType; | 82 | private PIDHoverType _PIDHoverType; |
85 | private float _PIDHoverTao; | 83 | private float _PIDHoverTau; |
86 | 84 | ||
87 | public BSPrim(uint localID, String primName, BSScene parent_scene, OMV.Vector3 pos, OMV.Vector3 size, | 85 | public BSPrim(uint localID, String primName, BSScene parent_scene, OMV.Vector3 pos, OMV.Vector3 size, |
88 | OMV.Quaternion rotation, PrimitiveBaseShape pbs, bool pisPhysical) | 86 | OMV.Quaternion rotation, PrimitiveBaseShape pbs, bool pisPhysical) |
@@ -564,6 +562,11 @@ public sealed class BSPrim : BSPhysObject | |||
564 | } | 562 | } |
565 | return; | 563 | return; |
566 | } | 564 | } |
565 | public OMV.Vector3 RawVelocity | ||
566 | { | ||
567 | get { return _velocity; } | ||
568 | set { _velocity = value; } | ||
569 | } | ||
567 | public override OMV.Vector3 Velocity { | 570 | public override OMV.Vector3 Velocity { |
568 | get { return _velocity; } | 571 | get { return _velocity; } |
569 | set { | 572 | set { |
@@ -1004,13 +1007,99 @@ public sealed class BSPrim : BSPhysObject | |||
1004 | set { _PIDTau = value; } | 1007 | set { _PIDTau = value; } |
1005 | } | 1008 | } |
1006 | public override bool PIDActive { | 1009 | public override bool PIDActive { |
1007 | set { _usePID = value; } | 1010 | set { |
1011 | if (value) | ||
1012 | { | ||
1013 | // We're taking over after this. | ||
1014 | ZeroMotion(true); | ||
1015 | |||
1016 | _targetMotor = new BSVMotor("BSPrim.PIDTarget", | ||
1017 | _PIDTau, // timeScale | ||
1018 | BSMotor.Infinite, // decay time scale | ||
1019 | BSMotor.InfiniteVector, // friction timescale | ||
1020 | 1f // efficiency | ||
1021 | ); | ||
1022 | _targetMotor.PhysicsScene = PhysicsScene; // DEBUG DEBUG so motor will output detail log messages. | ||
1023 | _targetMotor.SetTarget(_PIDTarget); | ||
1024 | _targetMotor.SetCurrent(RawPosition); | ||
1025 | /* | ||
1026 | _targetMotor = new BSPIDVMotor("BSPrim.PIDTarget"); | ||
1027 | _targetMotor.PhysicsScene = PhysicsScene; // DEBUG DEBUG so motor will output detail log messages. | ||
1028 | |||
1029 | _targetMotor.SetTarget(_PIDTarget); | ||
1030 | _targetMotor.SetCurrent(RawPosition); | ||
1031 | _targetMotor.TimeScale = _PIDTau; | ||
1032 | _targetMotor.Efficiency = 1f; | ||
1033 | */ | ||
1034 | |||
1035 | RegisterPreStepAction("BSPrim.PIDTarget", LocalID, delegate(float timeStep) | ||
1036 | { | ||
1037 | OMV.Vector3 origPosition = RawPosition; // DEBUG DEBUG (for printout below) | ||
1038 | |||
1039 | // 'movePosition' is where we'd like the prim to be at this moment. | ||
1040 | OMV.Vector3 movePosition = _targetMotor.Step(timeStep); | ||
1041 | |||
1042 | // If we are very close to our target, turn off the movement motor. | ||
1043 | if (_targetMotor.ErrorIsZero()) | ||
1044 | { | ||
1045 | DetailLog("{0},BSPrim.PIDTarget,zeroMovement,movePos={1},pos={2},mass={3}", | ||
1046 | LocalID, movePosition, RawPosition, Mass); | ||
1047 | ForcePosition = _targetMotor.TargetValue; | ||
1048 | _targetMotor.Enabled = false; | ||
1049 | } | ||
1050 | else | ||
1051 | { | ||
1052 | ForcePosition = movePosition; | ||
1053 | } | ||
1054 | DetailLog("{0},BSPrim.PIDTarget,move,fromPos={1},movePos={2}", LocalID, origPosition, movePosition); | ||
1055 | }); | ||
1056 | } | ||
1057 | else | ||
1058 | { | ||
1059 | // Stop any targetting | ||
1060 | UnRegisterPreStepAction("BSPrim.PIDTarget", LocalID); | ||
1061 | } | ||
1062 | } | ||
1008 | } | 1063 | } |
1009 | 1064 | ||
1010 | // Used for llSetHoverHeight and maybe vehicle height | 1065 | // Used for llSetHoverHeight and maybe vehicle height |
1011 | // Hover Height will override MoveTo target's Z | 1066 | // Hover Height will override MoveTo target's Z |
1012 | public override bool PIDHoverActive { | 1067 | public override bool PIDHoverActive { |
1013 | set { _useHoverPID = value; } | 1068 | set { |
1069 | if (value) | ||
1070 | { | ||
1071 | // Turning the target on | ||
1072 | _hoverMotor = new BSFMotor("BSPrim.Hover", | ||
1073 | _PIDHoverTau, // timeScale | ||
1074 | BSMotor.Infinite, // decay time scale | ||
1075 | BSMotor.Infinite, // friction timescale | ||
1076 | 1f // efficiency | ||
1077 | ); | ||
1078 | _hoverMotor.SetTarget(ComputeCurrentPIDHoverHeight()); | ||
1079 | _hoverMotor.SetCurrent(RawPosition.Z); | ||
1080 | _hoverMotor.PhysicsScene = PhysicsScene; // DEBUG DEBUG so motor will output detail log messages. | ||
1081 | |||
1082 | RegisterPreStepAction("BSPrim.Hover", LocalID, delegate(float timeStep) | ||
1083 | { | ||
1084 | _hoverMotor.SetCurrent(RawPosition.Z); | ||
1085 | _hoverMotor.SetTarget(ComputeCurrentPIDHoverHeight()); | ||
1086 | float targetHeight = _hoverMotor.Step(timeStep); | ||
1087 | |||
1088 | // 'targetHeight' is where we'd like the Z of the prim to be at this moment. | ||
1089 | // Compute the amount of force to push us there. | ||
1090 | float moveForce = (targetHeight - RawPosition.Z) * Mass; | ||
1091 | // Undo anything the object thinks it's doing at the moment | ||
1092 | moveForce = -RawVelocity.Z * Mass; | ||
1093 | |||
1094 | PhysicsScene.PE.ApplyCentralImpulse(PhysBody, new OMV.Vector3(0f, 0f, moveForce)); | ||
1095 | DetailLog("{0},BSPrim.Hover,move,targHt={1},moveForce={2},mass={3}", LocalID, targetHeight, moveForce, Mass); | ||
1096 | }); | ||
1097 | } | ||
1098 | else | ||
1099 | { | ||
1100 | UnRegisterPreStepAction("BSPrim.Hover", LocalID); | ||
1101 | } | ||
1102 | } | ||
1014 | } | 1103 | } |
1015 | public override float PIDHoverHeight { | 1104 | public override float PIDHoverHeight { |
1016 | set { _PIDHoverHeight = value; } | 1105 | set { _PIDHoverHeight = value; } |
@@ -1019,8 +1108,35 @@ public sealed class BSPrim : BSPhysObject | |||
1019 | set { _PIDHoverType = value; } | 1108 | set { _PIDHoverType = value; } |
1020 | } | 1109 | } |
1021 | public override float PIDHoverTau { | 1110 | public override float PIDHoverTau { |
1022 | set { _PIDHoverTao = value; } | 1111 | set { _PIDHoverTau = value; } |
1023 | } | 1112 | } |
1113 | // Based on current position, determine what we should be hovering at now. | ||
1114 | // Must recompute often. What if we walked offa cliff> | ||
1115 | private float ComputeCurrentPIDHoverHeight() | ||
1116 | { | ||
1117 | float ret = _PIDHoverHeight; | ||
1118 | float groundHeight = PhysicsScene.TerrainManager.GetTerrainHeightAtXYZ(RawPosition); | ||
1119 | |||
1120 | switch (_PIDHoverType) | ||
1121 | { | ||
1122 | case PIDHoverType.Ground: | ||
1123 | ret = groundHeight + _PIDHoverHeight; | ||
1124 | break; | ||
1125 | case PIDHoverType.GroundAndWater: | ||
1126 | float waterHeight = PhysicsScene.TerrainManager.GetWaterLevelAtXYZ(RawPosition); | ||
1127 | if (groundHeight > waterHeight) | ||
1128 | { | ||
1129 | ret = groundHeight + _PIDHoverHeight; | ||
1130 | } | ||
1131 | else | ||
1132 | { | ||
1133 | ret = waterHeight + _PIDHoverHeight; | ||
1134 | } | ||
1135 | break; | ||
1136 | } | ||
1137 | return ret; | ||
1138 | } | ||
1139 | |||
1024 | 1140 | ||
1025 | // For RotLookAt | 1141 | // For RotLookAt |
1026 | public override OMV.Quaternion APIDTarget { set { return; } } | 1142 | public override OMV.Quaternion APIDTarget { set { return; } } |
@@ -1037,7 +1153,7 @@ public sealed class BSPrim : BSPhysObject | |||
1037 | // This added force will only last the next simulation tick. | 1153 | // This added force will only last the next simulation tick. |
1038 | public void AddForce(OMV.Vector3 force, bool pushforce, bool inTaintTime) { | 1154 | public void AddForce(OMV.Vector3 force, bool pushforce, bool inTaintTime) { |
1039 | // for an object, doesn't matter if force is a pushforce or not | 1155 | // for an object, doesn't matter if force is a pushforce or not |
1040 | if (force.IsFinite()) | 1156 | if (!IsStatic && force.IsFinite()) |
1041 | { | 1157 | { |
1042 | float magnitude = force.Length(); | 1158 | float magnitude = force.Length(); |
1043 | if (magnitude > BSParam.MaxAddForceMagnitude) | 1159 | if (magnitude > BSParam.MaxAddForceMagnitude) |
@@ -1047,7 +1163,7 @@ public sealed class BSPrim : BSPhysObject | |||
1047 | } | 1163 | } |
1048 | 1164 | ||
1049 | OMV.Vector3 addForce = force; | 1165 | OMV.Vector3 addForce = force; |
1050 | DetailLog("{0},BSPrim.addForce,call,force={1}", LocalID, addForce); | 1166 | // DetailLog("{0},BSPrim.addForce,call,force={1}", LocalID, addForce); |
1051 | 1167 | ||
1052 | PhysicsScene.TaintedObject(inTaintTime, "BSPrim.AddForce", delegate() | 1168 | PhysicsScene.TaintedObject(inTaintTime, "BSPrim.AddForce", delegate() |
1053 | { | 1169 | { |