aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Framework/Scenes/ScenePresence.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Framework/Scenes/ScenePresence.cs')
-rw-r--r--OpenSim/Region/Framework/Scenes/ScenePresence.cs113
1 files changed, 96 insertions, 17 deletions
diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
index 732d5ef..cb7422b 100644
--- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs
+++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
@@ -542,10 +542,7 @@ namespace OpenSim.Region.Framework.Scenes
542 542
543 public Vector3 CameraPosition { get; set; } 543 public Vector3 CameraPosition { get; set; }
544 544
545 public Quaternion CameraRotation 545 public Quaternion CameraRotation { get; private set; }
546 {
547 get { return Util.Axes2Rot(CameraAtAxis, CameraLeftAxis, CameraUpAxis); }
548 }
549 546
550 // Use these three vectors to figure out what the agent is looking at 547 // Use these three vectors to figure out what the agent is looking at
551 // Convert it to a Matrix and/or Quaternion 548 // Convert it to a Matrix and/or Quaternion
@@ -1242,6 +1239,14 @@ namespace OpenSim.Region.Framework.Scenes
1242 ParentPart = part; 1239 ParentPart = part;
1243 m_pos = PrevSitOffset; 1240 m_pos = PrevSitOffset;
1244 pos = part.GetWorldPosition(); 1241 pos = part.GetWorldPosition();
1242 PhysicsActor partPhysActor = part.PhysActor;
1243 if(partPhysActor != null)
1244 {
1245 partPhysActor.OnPhysicsRequestingCameraData -=
1246 physActor_OnPhysicsRequestingCameraData;
1247 partPhysActor.OnPhysicsRequestingCameraData +=
1248 physActor_OnPhysicsRequestingCameraData;
1249 }
1245 } 1250 }
1246 ParentUUID = UUID.Zero; 1251 ParentUUID = UUID.Zero;
1247 } 1252 }
@@ -1922,6 +1927,31 @@ namespace OpenSim.Region.Framework.Scenes
1922 return true; 1927 return true;
1923 } 1928 }
1924 1929
1930 public void RotateToLookAt(Vector3 lookAt)
1931 {
1932 if(ParentID == 0)
1933 {
1934 float n = lookAt.X * lookAt.X + lookAt.Y * lookAt.Y;
1935 if(n < 0.0001f)
1936 {
1937 Rotation = Quaternion.Identity;
1938 return;
1939 }
1940 n = lookAt.X/(float)Math.Sqrt(n);
1941 float angle = (float)Math.Acos(n);
1942 angle *= 0.5f;
1943 float s = (float)Math.Sin(angle);
1944 if(lookAt.Y < 0)
1945 s = -s;
1946 Rotation = new Quaternion(
1947 0f,
1948 0f,
1949 s,
1950 (float)Math.Cos(angle)
1951 );
1952 }
1953 }
1954
1925 /// <summary> 1955 /// <summary>
1926 /// Complete Avatar's movement into the region. 1956 /// Complete Avatar's movement into the region.
1927 /// </summary> 1957 /// </summary>
@@ -1958,10 +1988,10 @@ namespace OpenSim.Region.Framework.Scenes
1958 bool flying = ((m_AgentControlFlags & AgentManager.ControlFlags.AGENT_CONTROL_FLY) != 0); 1988 bool flying = ((m_AgentControlFlags & AgentManager.ControlFlags.AGENT_CONTROL_FLY) != 0);
1959 1989
1960 Vector3 look = Lookat; 1990 Vector3 look = Lookat;
1991 look.Z = 0f;
1961 if ((Math.Abs(look.X) < 0.01) && (Math.Abs(look.Y) < 0.01)) 1992 if ((Math.Abs(look.X) < 0.01) && (Math.Abs(look.Y) < 0.01))
1962 { 1993 {
1963 look = Velocity; 1994 look = Velocity;
1964 look.Z = 0;
1965 look.Normalize(); 1995 look.Normalize();
1966 if ((Math.Abs(look.X) < 0.01) && (Math.Abs(look.Y) < 0.01) ) 1996 if ((Math.Abs(look.X) < 0.01) && (Math.Abs(look.Y) < 0.01) )
1967 look = new Vector3(0.99f, 0.042f, 0); 1997 look = new Vector3(0.99f, 0.042f, 0);
@@ -1995,11 +2025,12 @@ namespace OpenSim.Region.Framework.Scenes
1995 m_log.DebugFormat("[CompleteMovement]: Missing COF for {0} is {1}", client.AgentId, COF); 2025 m_log.DebugFormat("[CompleteMovement]: Missing COF for {0} is {1}", client.AgentId, COF);
1996 } 2026 }
1997 2027
2028 if(!gotCrossUpdate)
2029 RotateToLookAt(look);
1998 2030
1999 // Tell the client that we're totally ready 2031 // Tell the client that we're totally ready
2000 ControllingClient.MoveAgentIntoRegion(m_scene.RegionInfo, AbsolutePosition, look); 2032 ControllingClient.MoveAgentIntoRegion(m_scene.RegionInfo, AbsolutePosition, look);
2001 2033
2002
2003 m_log.DebugFormat("[CompleteMovement] MoveAgentIntoRegion: {0}ms", Util.EnvironmentTickCountSubtract(ts)); 2034 m_log.DebugFormat("[CompleteMovement] MoveAgentIntoRegion: {0}ms", Util.EnvironmentTickCountSubtract(ts));
2004 2035
2005 if (!string.IsNullOrEmpty(m_callbackURI)) 2036 if (!string.IsNullOrEmpty(m_callbackURI))
@@ -2696,9 +2727,13 @@ namespace OpenSim.Region.Framework.Scenes
2696 CameraPosition = agentData.CameraCenter; 2727 CameraPosition = agentData.CameraCenter;
2697 // Use these three vectors to figure out what the agent is looking at 2728 // Use these three vectors to figure out what the agent is looking at
2698 // Convert it to a Matrix and/or Quaternion 2729 // Convert it to a Matrix and/or Quaternion
2730
2731 // this my need lock
2699 CameraAtAxis = agentData.CameraAtAxis; 2732 CameraAtAxis = agentData.CameraAtAxis;
2700 CameraLeftAxis = agentData.CameraLeftAxis; 2733 CameraLeftAxis = agentData.CameraLeftAxis;
2701 CameraUpAxis = agentData.CameraUpAxis; 2734 CameraUpAxis = agentData.CameraUpAxis;
2735 Quaternion camRot = Util.Axes2Rot(CameraAtAxis, CameraLeftAxis, CameraUpAxis);
2736 CameraRotation = camRot;
2702 2737
2703 // The Agent's Draw distance setting 2738 // The Agent's Draw distance setting
2704 // When we get to the point of re-computing neighbors everytime this 2739 // When we get to the point of re-computing neighbors everytime this
@@ -3171,9 +3206,9 @@ namespace OpenSim.Region.Framework.Scenes
3171 offset = offset * part.RotationOffset; 3206 offset = offset * part.RotationOffset;
3172 offset += part.OffsetPosition; 3207 offset += part.OffsetPosition;
3173 3208
3174 if (CameraAtAxis == Vector3.Zero && cameraEyeOffset == Vector3.Zero) 3209 if (cameraAtOffset == Vector3.Zero && cameraEyeOffset == Vector3.Zero)
3175 { 3210 {
3176 CameraAtAxis = part.ParentGroup.RootPart.GetCameraAtOffset(); 3211 cameraAtOffset = part.ParentGroup.RootPart.GetCameraAtOffset();
3177 cameraEyeOffset = part.ParentGroup.RootPart.GetCameraEyeOffset(); 3212 cameraEyeOffset = part.ParentGroup.RootPart.GetCameraEyeOffset();
3178 } 3213 }
3179 else 3214 else
@@ -3304,7 +3339,6 @@ namespace OpenSim.Region.Framework.Scenes
3304 Vector3 cameraEyeOffset = part.GetCameraEyeOffset(); 3339 Vector3 cameraEyeOffset = part.GetCameraEyeOffset();
3305 bool forceMouselook = part.GetForceMouselook(); 3340 bool forceMouselook = part.GetForceMouselook();
3306 3341
3307 m_bodyRot = Orientation;
3308 3342
3309 if (!part.IsRoot) 3343 if (!part.IsRoot)
3310 { 3344 {
@@ -3312,9 +3346,9 @@ namespace OpenSim.Region.Framework.Scenes
3312 offset = offset * part.RotationOffset; 3346 offset = offset * part.RotationOffset;
3313 offset += part.OffsetPosition; 3347 offset += part.OffsetPosition;
3314 3348
3315 if (CameraAtAxis == Vector3.Zero && cameraEyeOffset == Vector3.Zero) 3349 if (cameraAtOffset == Vector3.Zero && cameraEyeOffset == Vector3.Zero)
3316 { 3350 {
3317 CameraAtAxis = part.ParentGroup.RootPart.GetCameraAtOffset(); 3351 cameraAtOffset = part.ParentGroup.RootPart.GetCameraAtOffset();
3318 cameraEyeOffset = part.ParentGroup.RootPart.GetCameraEyeOffset(); 3352 cameraEyeOffset = part.ParentGroup.RootPart.GetCameraEyeOffset();
3319 } 3353 }
3320 else 3354 else
@@ -3326,6 +3360,7 @@ namespace OpenSim.Region.Framework.Scenes
3326 } 3360 }
3327 } 3361 }
3328 3362
3363 m_bodyRot = Orientation;
3329 m_pos = offset; 3364 m_pos = offset;
3330 3365
3331 ControllingClient.SendSitResponse( 3366 ControllingClient.SendSitResponse(
@@ -4571,6 +4606,11 @@ namespace OpenSim.Region.Framework.Scenes
4571 CameraAtAxis = cAgent.AtAxis; 4606 CameraAtAxis = cAgent.AtAxis;
4572 CameraLeftAxis = cAgent.LeftAxis; 4607 CameraLeftAxis = cAgent.LeftAxis;
4573 CameraUpAxis = cAgent.UpAxis; 4608 CameraUpAxis = cAgent.UpAxis;
4609
4610 Quaternion camRot = Util.Axes2Rot(CameraAtAxis, CameraLeftAxis, CameraUpAxis);
4611 CameraRotation = camRot;
4612
4613
4574 ParentUUID = cAgent.ParentPart; 4614 ParentUUID = cAgent.ParentPart;
4575 PrevSitOffset = cAgent.SitOffset; 4615 PrevSitOffset = cAgent.SitOffset;
4576 4616
@@ -5429,10 +5469,21 @@ namespace OpenSim.Region.Framework.Scenes
5429 } 5469 }
5430 } 5470 }
5431 5471
5472 CameraData physActor_OnPhysicsRequestingCameraData()
5473 {
5474 return new CameraData
5475 {
5476 Valid = true,
5477 MouseLook = this.m_mouseLook,
5478 CameraRotation = this.CameraRotation,
5479 CameraAtAxis = this.CameraAtAxis
5480 };
5481 }
5482
5432 public void RegisterControlEventsToScript(int controls, int accept, int pass_on, uint Obj_localID, UUID Script_item_UUID) 5483 public void RegisterControlEventsToScript(int controls, int accept, int pass_on, uint Obj_localID, UUID Script_item_UUID)
5433 { 5484 {
5434 SceneObjectPart p = m_scene.GetSceneObjectPart(Obj_localID); 5485 SceneObjectPart part = m_scene.GetSceneObjectPart(Obj_localID);
5435 if (p == null) 5486 if (part == null)
5436 return; 5487 return;
5437 5488
5438 ControllingClient.SendTakeControls(controls, false, false); 5489 ControllingClient.SendTakeControls(controls, false, false);
@@ -5442,7 +5493,7 @@ namespace OpenSim.Region.Framework.Scenes
5442 obj.ignoreControls = ScriptControlled.CONTROL_ZERO; 5493 obj.ignoreControls = ScriptControlled.CONTROL_ZERO;
5443 obj.eventControls = ScriptControlled.CONTROL_ZERO; 5494 obj.eventControls = ScriptControlled.CONTROL_ZERO;
5444 5495
5445 obj.objectID = p.ParentGroup.UUID; 5496 obj.objectID = part.ParentGroup.UUID;
5446 obj.itemID = Script_item_UUID; 5497 obj.itemID = Script_item_UUID;
5447 if (pass_on == 0 && accept == 0) 5498 if (pass_on == 0 && accept == 0)
5448 { 5499 {
@@ -5470,17 +5521,43 @@ namespace OpenSim.Region.Framework.Scenes
5470 { 5521 {
5471 IgnoredControls &= ~(ScriptControlled)controls; 5522 IgnoredControls &= ~(ScriptControlled)controls;
5472 if (scriptedcontrols.ContainsKey(Script_item_UUID)) 5523 if (scriptedcontrols.ContainsKey(Script_item_UUID))
5473 scriptedcontrols.Remove(Script_item_UUID); 5524 RemoveScriptFromControlNotifications(Script_item_UUID, part);
5474 } 5525 }
5475 else 5526 else
5476 { 5527 {
5477 scriptedcontrols[Script_item_UUID] = obj; 5528 AddScriptToControlNotifications(Script_item_UUID, part, ref obj);
5478 } 5529 }
5479 } 5530 }
5480 5531
5481 ControllingClient.SendTakeControls(controls, pass_on == 1 ? true : false, true); 5532 ControllingClient.SendTakeControls(controls, pass_on == 1 ? true : false, true);
5482 } 5533 }
5483 5534
5535 private void AddScriptToControlNotifications(OpenMetaverse.UUID Script_item_UUID, SceneObjectPart part, ref ScriptControllers obj)
5536 {
5537 scriptedcontrols[Script_item_UUID] = obj;
5538
5539 PhysicsActor physActor = part.ParentGroup.RootPart.PhysActor;
5540 if (physActor != null)
5541 {
5542 physActor.OnPhysicsRequestingCameraData -= physActor_OnPhysicsRequestingCameraData;
5543 physActor.OnPhysicsRequestingCameraData += physActor_OnPhysicsRequestingCameraData;
5544 }
5545 }
5546
5547 private void RemoveScriptFromControlNotifications(OpenMetaverse.UUID Script_item_UUID, SceneObjectPart part)
5548 {
5549 scriptedcontrols.Remove(Script_item_UUID);
5550
5551 if (part != null)
5552 {
5553 PhysicsActor physActor = part.ParentGroup.RootPart.PhysActor;
5554 if (physActor != null)
5555 {
5556 physActor.OnPhysicsRequestingCameraData -= physActor_OnPhysicsRequestingCameraData;
5557 }
5558 }
5559 }
5560
5484 public void HandleForceReleaseControls(IClientAPI remoteClient, UUID agentID) 5561 public void HandleForceReleaseControls(IClientAPI remoteClient, UUID agentID)
5485 { 5562 {
5486 IgnoredControls = ScriptControlled.CONTROL_ZERO; 5563 IgnoredControls = ScriptControlled.CONTROL_ZERO;
@@ -5518,6 +5595,7 @@ namespace OpenSim.Region.Framework.Scenes
5518 public void UnRegisterControlEventsToScript(uint Obj_localID, UUID Script_item_UUID) 5595 public void UnRegisterControlEventsToScript(uint Obj_localID, UUID Script_item_UUID)
5519 { 5596 {
5520 ScriptControllers takecontrols; 5597 ScriptControllers takecontrols;
5598 SceneObjectPart part = m_scene.GetSceneObjectPart(Obj_localID);
5521 5599
5522 lock (scriptedcontrols) 5600 lock (scriptedcontrols)
5523 { 5601 {
@@ -5528,7 +5606,7 @@ namespace OpenSim.Region.Framework.Scenes
5528 ControllingClient.SendTakeControls((int)sctc, false, false); 5606 ControllingClient.SendTakeControls((int)sctc, false, false);
5529 ControllingClient.SendTakeControls((int)sctc, true, false); 5607 ControllingClient.SendTakeControls((int)sctc, true, false);
5530 5608
5531 scriptedcontrols.Remove(Script_item_UUID); 5609 RemoveScriptFromControlNotifications(Script_item_UUID, part);
5532 IgnoredControls = ScriptControlled.CONTROL_ZERO; 5610 IgnoredControls = ScriptControlled.CONTROL_ZERO;
5533 foreach (ScriptControllers scData in scriptedcontrols.Values) 5611 foreach (ScriptControllers scData in scriptedcontrols.Values)
5534 { 5612 {
@@ -5947,6 +6025,7 @@ namespace OpenSim.Region.Framework.Scenes
5947 (m_teleportFlags & Constants.TeleportFlags.ViaHGLogin) != 0)) 6025 (m_teleportFlags & Constants.TeleportFlags.ViaHGLogin) != 0))
5948 { 6026 {
5949 pos = land.LandData.UserLocation; 6027 pos = land.LandData.UserLocation;
6028 positionChanged = true;
5950 } 6029 }
5951 } 6030 }
5952 6031