aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Scenes/ScenePresence.cs
diff options
context:
space:
mode:
authorCharles Krinke2008-11-27 05:16:47 +0000
committerCharles Krinke2008-11-27 05:16:47 +0000
commit921692a15f7b793da55cd4ddc4d85eae4393964e (patch)
treeebe7565de552bedbd856cd6615bd8107363eea79 /OpenSim/Region/Environment/Scenes/ScenePresence.cs
parentUnconditionally set the slam bit oon all object to agent inventory transfers. (diff)
downloadopensim-SC-921692a15f7b793da55cd4ddc4d85eae4393964e.zip
opensim-SC-921692a15f7b793da55cd4ddc4d85eae4393964e.tar.gz
opensim-SC-921692a15f7b793da55cd4ddc4d85eae4393964e.tar.bz2
opensim-SC-921692a15f7b793da55cd4ddc4d85eae4393964e.tar.xz
Thank you kindly, Nlin for a patch that:
Adds a new method to IClientAPI to allow adding message handlers for GenericMessages (of which "autopilot" is one). Part 2 adds a specific autopilot handler in ScenePresence.cs. 2) Removing unused variables and functions. 3) Simplifying the navigation logic in ScenePresence.cs. The original patch was somewhat complex because it included orientation logic for a future enhancement of orienting the avatar to point towards the direction being walked. Currently this isn't working, though, so I removed the orientation code, which leaves just the smaller and hopefully simpler-to-understand movement code.
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/Environment/Scenes/ScenePresence.cs132
1 files changed, 132 insertions, 0 deletions
diff --git a/OpenSim/Region/Environment/Scenes/ScenePresence.cs b/OpenSim/Region/Environment/Scenes/ScenePresence.cs
index 29c7c3e..998140f 100644
--- a/OpenSim/Region/Environment/Scenes/ScenePresence.cs
+++ b/OpenSim/Region/Environment/Scenes/ScenePresence.cs
@@ -175,6 +175,12 @@ namespace OpenSim.Region.Environment.Scenes
175 175
176 private string m_nextSitAnimation = String.Empty; 176 private string m_nextSitAnimation = String.Empty;
177 177
178 //PauPaw:Proper PID Controler for autopilot************
179 private bool m_moveToPositionInProgress = false;
180 private Vector3 m_moveToPositionTarget = Vector3.Zero;
181 private int m_moveToPositionStateStatus = 0;
182 //*****************************************************
183
178 // Agent's Draw distance. 184 // Agent's Draw distance.
179 protected float m_DrawDistance = 0f; 185 protected float m_DrawDistance = 0f;
180 186
@@ -550,6 +556,7 @@ namespace OpenSim.Region.Environment.Scenes
550 m_controllingClient.OnStopAnim += HandleStopAnim; 556 m_controllingClient.OnStopAnim += HandleStopAnim;
551 m_controllingClient.OnForceReleaseControls += HandleForceReleaseControls; 557 m_controllingClient.OnForceReleaseControls += HandleForceReleaseControls;
552 m_controllingClient.OnAutoPilotGo += DoAutoPilot; 558 m_controllingClient.OnAutoPilotGo += DoAutoPilot;
559 m_controllingClient.AddGenericPacketHandler("autopilot", DoMoveToPosition);
553 560
554 // ControllingClient.OnChildAgentStatus += new StatusChange(this.ChildStatusChange); 561 // ControllingClient.OnChildAgentStatus += new StatusChange(this.ChildStatusChange);
555 // ControllingClient.OnStopMovement += new GenericCall2(this.StopMovement); 562 // ControllingClient.OnStopMovement += new GenericCall2(this.StopMovement);
@@ -1063,10 +1070,13 @@ namespace OpenSim.Region.Environment.Scenes
1063 1070
1064 if (m_parentID == 0) 1071 if (m_parentID == 0)
1065 { 1072 {
1073 bool bAllowUpdateMoveToPosition = false;
1074 bool bResetMoveToPosition = false;
1066 foreach (Dir_ControlFlags DCF in Enum.GetValues(typeof (Dir_ControlFlags))) 1075 foreach (Dir_ControlFlags DCF in Enum.GetValues(typeof (Dir_ControlFlags)))
1067 { 1076 {
1068 if ((flags & (uint) DCF) != 0) 1077 if ((flags & (uint) DCF) != 0)
1069 { 1078 {
1079 bResetMoveToPosition = true;
1070 DCFlagKeyPressed = true; 1080 DCFlagKeyPressed = true;
1071 try 1081 try
1072 { 1082 {
@@ -1090,9 +1100,100 @@ namespace OpenSim.Region.Environment.Scenes
1090 m_movementflag -= (byte) (uint) DCF; 1100 m_movementflag -= (byte) (uint) DCF;
1091 update_movementflag = true; 1101 update_movementflag = true;
1092 } 1102 }
1103 else
1104 {
1105 bAllowUpdateMoveToPosition = true;
1106 }
1093 } 1107 }
1094 i++; 1108 i++;
1095 } 1109 }
1110
1111 //Paupaw:Do Proper PID for Autopilot here
1112 if (bResetMoveToPosition)
1113 {
1114 m_moveToPositionTarget = Vector3.Zero;
1115 m_moveToPositionInProgress = false;
1116 update_movementflag = true;
1117 bAllowUpdateMoveToPosition = false;
1118 }
1119
1120 if (bAllowUpdateMoveToPosition && (m_moveToPositionInProgress && !m_autopilotMoving))
1121 {
1122 //Check the error term of the current position in relation to the target position
1123 if (Util.GetDistanceTo(AbsolutePosition, m_moveToPositionTarget) <= 1.5)
1124 {
1125 // we are close enough to the target
1126 m_moveToPositionTarget = Vector3.Zero;
1127 m_moveToPositionInProgress = false;
1128 update_movementflag = true;
1129 }
1130 else
1131 {
1132 try
1133 {
1134 // move avatar in 2D at one meter/second towards target, in avatar coordinate frame.
1135 // This movement vector gets added to the velocity through AddNewMovement().
1136 // Theoretically we might need a more complex PID approach here if other
1137 // unknown forces are acting on the avatar and we need to adaptively respond
1138 // to such forces, but the following simple approach seems to works fine.
1139 Vector3 LocalVectorToTarget3D =
1140 (m_moveToPositionTarget - AbsolutePosition) // vector from cur. pos to target in global coords
1141 * Matrix4.CreateFromQuaternion(Quaternion.Inverse(bodyRotation)); // change to avatar coords
1142 // Ignore z component of vector
1143 Vector3 LocalVectorToTarget2D = new Vector3((float)(LocalVectorToTarget3D.X), (float)(LocalVectorToTarget3D.Y), 0f);
1144 LocalVectorToTarget2D.Normalize();
1145 agent_control_v3 += LocalVectorToTarget2D;
1146
1147 // update avatar movement flags. the avatar coordinate system is as follows:
1148 //
1149 // +X (forward)
1150 //
1151 // ^
1152 // |
1153 // |
1154 // |
1155 // |
1156 // (left) +Y <--------o--------> -Y
1157 // avatar
1158 // |
1159 // |
1160 // |
1161 // |
1162 // v
1163 // -X
1164 //
1165
1166 // based on the above avatar coordinate system, classify the movement into
1167 // one of left/right/back/forward.
1168 if (LocalVectorToTarget2D.Y > 0)//MoveLeft
1169 {
1170 m_movementflag += (byte)(uint)Dir_ControlFlags.DIR_CONTROL_FLAG_LEFT;
1171 update_movementflag = true;
1172 }
1173 else if (LocalVectorToTarget2D.Y < 0) //MoveRight
1174 {
1175 m_movementflag += (byte)(uint)Dir_ControlFlags.DIR_CONTROL_FLAG_RIGHT;
1176 update_movementflag = true;
1177 }
1178 if (LocalVectorToTarget2D.X < 0) //MoveBack
1179 {
1180 m_movementflag += (byte)(uint)Dir_ControlFlags.DIR_CONTROL_FLAG_BACK;
1181 update_movementflag = true;
1182 }
1183 else if (LocalVectorToTarget2D.X > 0) //Move Forward
1184 {
1185 m_movementflag += (byte)(uint)Dir_ControlFlags.DIR_CONTROL_FLAG_FORWARD;
1186 update_movementflag = true;
1187 }
1188 }
1189 catch (Exception)
1190 {
1191
1192 //Avoid system crash, can be slower but...
1193 }
1194
1195 }
1196 }
1096 } 1197 }
1097 1198
1098 // Cause the avatar to stop flying if it's colliding 1199 // Cause the avatar to stop flying if it's colliding
@@ -1158,6 +1259,37 @@ namespace OpenSim.Region.Environment.Scenes
1158// } 1259// }
1159 } 1260 }
1160 1261
1262 public void DoMoveToPosition(Object sender, string method, List<String> args)
1263 {
1264 try
1265 {
1266 float locx = 0f;
1267 float locy = 0f;
1268 float locz = 0f;
1269 uint regionX = 0;
1270 uint regionY = 0;
1271 try
1272 {
1273 Utils.LongToUInts(Scene.RegionInfo.RegionHandle, out regionX, out regionY);
1274 locx = Convert.ToSingle(args[0]) - (float)regionX;
1275 locy = Convert.ToSingle(args[1]) - (float)regionY;
1276 locz = Convert.ToSingle(args[2]);
1277 }
1278 catch (InvalidCastException)
1279 {
1280 m_log.Error("[CLIENT]: Invalid autopilot request");
1281 return;
1282 }
1283 m_moveToPositionInProgress = true;
1284 m_moveToPositionTarget = new Vector3(locx, locy, locz);
1285 }
1286 catch (Exception ex)
1287 {
1288 //Why did I get this error?
1289 System.Diagnostics.Debug.WriteLine(ex.ToString());
1290 }
1291 }
1292
1161 private void CheckAtSitTarget() 1293 private void CheckAtSitTarget()
1162 { 1294 {
1163 //m_log.Debug("[AUTOPILOT]: " + Util.GetDistanceTo(AbsolutePosition, m_autoPilotTarget).ToString()); 1295 //m_log.Debug("[AUTOPILOT]: " + Util.GetDistanceTo(AbsolutePosition, m_autoPilotTarget).ToString());