diff options
author | UbitUmarov | 2016-11-14 03:21:07 +0000 |
---|---|---|
committer | UbitUmarov | 2016-11-14 03:21:07 +0000 |
commit | ae17b5d203677ff99cf0c3ee9d9ec9309600b568 (patch) | |
tree | a6155da7bc16d17f7a68a9eda0b78b4c72e4c9d4 | |
parent | Merge branch 'master' of opensimulator.org:/var/git/opensim (diff) | |
download | opensim-SC-ae17b5d203677ff99cf0c3ee9d9ec9309600b568.zip opensim-SC-ae17b5d203677ff99cf0c3ee9d9ec9309600b568.tar.gz opensim-SC-ae17b5d203677ff99cf0c3ee9d9ec9309600b568.tar.bz2 opensim-SC-ae17b5d203677ff99cf0c3ee9d9ec9309600b568.tar.xz |
reduce calls to physics world cast rays for camera collision check
-rw-r--r-- | OpenSim/Framework/AgentUpdateArgs.cs | 1 | ||||
-rw-r--r-- | OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs | 8 | ||||
-rw-r--r-- | OpenSim/Region/Framework/Scenes/ScenePresence.cs | 97 |
3 files changed, 55 insertions, 51 deletions
diff --git a/OpenSim/Framework/AgentUpdateArgs.cs b/OpenSim/Framework/AgentUpdateArgs.cs index 660bc32..eaa7902 100644 --- a/OpenSim/Framework/AgentUpdateArgs.cs +++ b/OpenSim/Framework/AgentUpdateArgs.cs | |||
@@ -81,6 +81,7 @@ namespace OpenSim.Framework | |||
81 | 81 | ||
82 | public Vector3 ClientAgentPosition; | 82 | public Vector3 ClientAgentPosition; |
83 | public bool UseClientAgentPosition; | 83 | public bool UseClientAgentPosition; |
84 | public bool NeedsCameraCollision; | ||
84 | 85 | ||
85 | public AgentUpdateArgs() | 86 | public AgentUpdateArgs() |
86 | { | 87 | { |
diff --git a/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs b/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs index 99c9049..46c6a19 100644 --- a/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs +++ b/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs | |||
@@ -6263,7 +6263,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
6263 | 6263 | ||
6264 | bool movement = CheckAgentMovementUpdateSignificance(x); | 6264 | bool movement = CheckAgentMovementUpdateSignificance(x); |
6265 | bool camera = CheckAgentCameraUpdateSignificance(x); | 6265 | bool camera = CheckAgentCameraUpdateSignificance(x); |
6266 | 6266 | ||
6267 | // Was there a significant movement/state change? | 6267 | // Was there a significant movement/state change? |
6268 | if (movement) | 6268 | if (movement) |
6269 | { | 6269 | { |
@@ -6274,6 +6274,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
6274 | m_thisAgentUpdateArgs.HeadRotation = x.HeadRotation; | 6274 | m_thisAgentUpdateArgs.HeadRotation = x.HeadRotation; |
6275 | m_thisAgentUpdateArgs.State = x.State; | 6275 | m_thisAgentUpdateArgs.State = x.State; |
6276 | 6276 | ||
6277 | m_thisAgentUpdateArgs.NeedsCameraCollision = !camera; | ||
6278 | |||
6277 | UpdateAgent handlerAgentUpdate = OnAgentUpdate; | 6279 | UpdateAgent handlerAgentUpdate = OnAgentUpdate; |
6278 | UpdateAgent handlerPreAgentUpdate = OnPreAgentUpdate; | 6280 | UpdateAgent handlerPreAgentUpdate = OnPreAgentUpdate; |
6279 | 6281 | ||
@@ -6282,7 +6284,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
6282 | 6284 | ||
6283 | if (handlerAgentUpdate != null) | 6285 | if (handlerAgentUpdate != null) |
6284 | OnAgentUpdate(this, m_thisAgentUpdateArgs); | 6286 | OnAgentUpdate(this, m_thisAgentUpdateArgs); |
6285 | 6287 | ||
6286 | } | 6288 | } |
6287 | 6289 | ||
6288 | // Was there a significant camera(s) change? | 6290 | // Was there a significant camera(s) change? |
@@ -6293,6 +6295,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
6293 | m_thisAgentUpdateArgs.CameraLeftAxis = x.CameraLeftAxis; | 6295 | m_thisAgentUpdateArgs.CameraLeftAxis = x.CameraLeftAxis; |
6294 | m_thisAgentUpdateArgs.CameraUpAxis = x.CameraUpAxis; | 6296 | m_thisAgentUpdateArgs.CameraUpAxis = x.CameraUpAxis; |
6295 | 6297 | ||
6298 | m_thisAgentUpdateArgs.NeedsCameraCollision = true; | ||
6299 | |||
6296 | UpdateAgent handlerAgentCameraUpdate = OnAgentCameraUpdate; | 6300 | UpdateAgent handlerAgentCameraUpdate = OnAgentCameraUpdate; |
6297 | 6301 | ||
6298 | if (handlerAgentCameraUpdate != null) | 6302 | if (handlerAgentCameraUpdate != null) |
diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs index f96fb85..2ca218c 100644 --- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs +++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs | |||
@@ -2297,6 +2297,48 @@ namespace OpenSim.Region.Framework.Scenes | |||
2297 | /// <param name="distance"></param> | 2297 | /// <param name="distance"></param> |
2298 | /// | 2298 | /// |
2299 | 2299 | ||
2300 | private void checkCameraCollision() | ||
2301 | { | ||
2302 | if(!m_scene.PhysicsScene.SupportsRayCast()) | ||
2303 | return; | ||
2304 | |||
2305 | ++m_movementUpdateCount; | ||
2306 | if (m_movementUpdateCount < 1) | ||
2307 | m_movementUpdateCount = 1; | ||
2308 | |||
2309 | if (m_doingCamRayCast || m_movementUpdateCount % NumMovementsBetweenRayCast != 0) | ||
2310 | return; | ||
2311 | |||
2312 | if (m_followCamAuto && !m_mouseLook) | ||
2313 | { | ||
2314 | Vector3 posAdjusted = AbsolutePosition; | ||
2315 | // posAdjusted.Z += 0.5f * Appearance.AvatarSize.Z - 0.5f; | ||
2316 | posAdjusted.Z += 1.0f; // viewer current camera focus point | ||
2317 | Vector3 tocam = CameraPosition - posAdjusted; | ||
2318 | tocam.X = (float)Math.Round(tocam.X, 1); | ||
2319 | tocam.Y = (float)Math.Round(tocam.Y, 1); | ||
2320 | tocam.Z = (float)Math.Round(tocam.Z, 1); | ||
2321 | |||
2322 | float distTocamlen = tocam.Length(); | ||
2323 | if (distTocamlen > 0.3f) | ||
2324 | { | ||
2325 | tocam *= (1.0f / distTocamlen); | ||
2326 | posAdjusted.X = (float)Math.Round(posAdjusted.X, 1); | ||
2327 | posAdjusted.Y = (float)Math.Round(posAdjusted.Y, 1); | ||
2328 | posAdjusted.Z = (float)Math.Round(posAdjusted.Z, 1); | ||
2329 | |||
2330 | m_doingCamRayCast = true; | ||
2331 | m_scene.PhysicsScene.RaycastWorld(posAdjusted, tocam, distTocamlen + 1.0f, RayCastCameraCallback); | ||
2332 | } | ||
2333 | } | ||
2334 | else if (CameraConstraintActive) | ||
2335 | { | ||
2336 | Vector4 plane = new Vector4(0.9f, 0.0f, 0.361f, -10000f); // not right... | ||
2337 | UpdateCameraCollisionPlane(plane); | ||
2338 | CameraConstraintActive = false; | ||
2339 | } | ||
2340 | } | ||
2341 | |||
2300 | private void UpdateCameraCollisionPlane(Vector4 plane) | 2342 | private void UpdateCameraCollisionPlane(Vector4 plane) |
2301 | { | 2343 | { |
2302 | if (m_lastCameraCollisionPlane != plane) | 2344 | if (m_lastCameraCollisionPlane != plane) |
@@ -2442,38 +2484,8 @@ namespace OpenSim.Region.Framework.Scenes | |||
2442 | 2484 | ||
2443 | // Raycast from the avatar's head to the camera to see if there's anything blocking the view | 2485 | // Raycast from the avatar's head to the camera to see if there's anything blocking the view |
2444 | // this exclude checks may not be complete | 2486 | // this exclude checks may not be complete |
2445 | 2487 | if(agentData.NeedsCameraCollision && ParentID == 0) // condition parentID may be wrong | |
2446 | if (m_movementUpdateCount % NumMovementsBetweenRayCast == 0 && m_scene.PhysicsScene.SupportsRayCast()) | 2488 | checkCameraCollision(); |
2447 | { | ||
2448 | if (!m_doingCamRayCast && !m_mouseLook && ParentID == 0) | ||
2449 | { | ||
2450 | Vector3 posAdjusted = AbsolutePosition; | ||
2451 | // posAdjusted.Z += 0.5f * Appearance.AvatarSize.Z - 0.5f; | ||
2452 | posAdjusted.Z += 1.0f; // viewer current camera focus point | ||
2453 | Vector3 tocam = CameraPosition - posAdjusted; | ||
2454 | tocam.X = (float)Math.Round(tocam.X, 1); | ||
2455 | tocam.Y = (float)Math.Round(tocam.Y, 1); | ||
2456 | tocam.Z = (float)Math.Round(tocam.Z, 1); | ||
2457 | |||
2458 | float distTocamlen = tocam.Length(); | ||
2459 | if (distTocamlen > 0.3f) | ||
2460 | { | ||
2461 | tocam *= (1.0f / distTocamlen); | ||
2462 | posAdjusted.X = (float)Math.Round(posAdjusted.X, 1); | ||
2463 | posAdjusted.Y = (float)Math.Round(posAdjusted.Y, 1); | ||
2464 | posAdjusted.Z = (float)Math.Round(posAdjusted.Z, 1); | ||
2465 | |||
2466 | m_doingCamRayCast = true; | ||
2467 | m_scene.PhysicsScene.RaycastWorld(posAdjusted, tocam, distTocamlen + 1.0f, RayCastCameraCallback); | ||
2468 | } | ||
2469 | } | ||
2470 | else if (CameraConstraintActive && (m_mouseLook || ParentID != 0)) | ||
2471 | { | ||
2472 | Vector4 plane = new Vector4(0.9f, 0.0f, 0.361f, -10000f); // not right... | ||
2473 | UpdateCameraCollisionPlane(plane); | ||
2474 | CameraConstraintActive = false; | ||
2475 | } | ||
2476 | } | ||
2477 | 2489 | ||
2478 | uint flagsForScripts = (uint)flags; | 2490 | uint flagsForScripts = (uint)flags; |
2479 | flags = RemoveIgnoredControls(flags, IgnoredControls); | 2491 | flags = RemoveIgnoredControls(flags, IgnoredControls); |
@@ -2742,14 +2754,10 @@ namespace OpenSim.Region.Framework.Scenes | |||
2742 | // Scene.RegionInfo.RegionName, remoteClient.Name, (AgentManager.ControlFlags)agentData.ControlFlags); | 2754 | // Scene.RegionInfo.RegionName, remoteClient.Name, (AgentManager.ControlFlags)agentData.ControlFlags); |
2743 | 2755 | ||
2744 | if (IsChildAgent) | 2756 | if (IsChildAgent) |
2745 | { | ||
2746 | // // m_log.Debug("DEBUG: HandleAgentUpdate: child agent"); | ||
2747 | return; | 2757 | return; |
2748 | } | ||
2749 | 2758 | ||
2750 | ++m_movementUpdateCount; | 2759 | if(IsInTransit) |
2751 | if (m_movementUpdateCount < 1) | 2760 | return; |
2752 | m_movementUpdateCount = 1; | ||
2753 | 2761 | ||
2754 | // AgentManager.ControlFlags flags = (AgentManager.ControlFlags)agentData.ControlFlags; | 2762 | // AgentManager.ControlFlags flags = (AgentManager.ControlFlags)agentData.ControlFlags; |
2755 | 2763 | ||
@@ -2779,17 +2787,8 @@ namespace OpenSim.Region.Framework.Scenes | |||
2779 | m_followCamAuto = ((CameraUpAxis.Z > 0.959f && CameraUpAxis.Z < 0.98f) | 2787 | m_followCamAuto = ((CameraUpAxis.Z > 0.959f && CameraUpAxis.Z < 0.98f) |
2780 | && (Math.Abs(camdif.X) < 0.4f && Math.Abs(camdif.Y) < 0.4f)) ? true : false; | 2788 | && (Math.Abs(camdif.X) < 0.4f && Math.Abs(camdif.Y) < 0.4f)) ? true : false; |
2781 | 2789 | ||
2782 | 2790 | if(agentData.NeedsCameraCollision) | |
2783 | //m_log.DebugFormat("[FollowCam]: {0}", m_followCamAuto); | 2791 | checkCameraCollision(); |
2784 | // Raycast from the avatar's head to the camera to see if there's anything blocking the view | ||
2785 | if ((m_movementUpdateCount % NumMovementsBetweenRayCast) == 0 && m_scene.PhysicsScene.SupportsRayCast()) | ||
2786 | { | ||
2787 | if (m_followCamAuto) | ||
2788 | { | ||
2789 | Vector3 posAdjusted = m_pos + HEAD_ADJUSTMENT; | ||
2790 | m_scene.PhysicsScene.RaycastWorld(m_pos, Vector3.Normalize(CameraPosition - posAdjusted), Vector3.Distance(CameraPosition, posAdjusted) + 0.3f, RayCastCameraCallback); | ||
2791 | } | ||
2792 | } | ||
2793 | 2792 | ||
2794 | TriggerScenePresenceUpdated(); | 2793 | TriggerScenePresenceUpdated(); |
2795 | } | 2794 | } |