diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index d5e3445c77..ee848bbd2f 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs @@ -61,6 +61,7 @@ namespace OpenSim.Region.Framework.Scenes Time = 0, Distance = 1, SimpleAngularDistance = 2, + FrontBack = 3, } public delegate void SynchronizeSceneHandler(Scene scene); @@ -540,6 +541,9 @@ namespace OpenSim.Region.Framework.Scenes case "simpleangulardistance": m_update_prioritization_scheme = UpdatePrioritizationSchemes.SimpleAngularDistance; break; + case "frontback": + m_update_prioritization_scheme = UpdatePrioritizationSchemes.FrontBack; + break; default: m_log.Warn("[SCENE]: UpdatePrioritizationScheme was not recognized, setting to default settomg of Time"); m_update_prioritization_scheme = UpdatePrioritizationSchemes.Time; diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs index 4f19761607..dd8da2083a 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs @@ -493,8 +493,8 @@ namespace OpenSim.Region.Framework.Scenes public Vector3 GroupScale() { - Vector3 minScale = new Vector3(Constants.RegionSize,Constants.RegionSize,Constants.RegionSize); - Vector3 maxScale = new Vector3(0f,0f,0f); + Vector3 minScale = new Vector3(Constants.RegionSize, Constants.RegionSize, Constants.RegionSize); + Vector3 maxScale = Vector3.Zero; Vector3 finalScale = new Vector3(0.5f, 0.5f, 0.5f); lock (m_parts) @@ -577,7 +577,6 @@ namespace OpenSim.Region.Framework.Scenes { foreach (SceneObjectPart part in m_parts.Values) { - Vector3 worldPos = part.GetWorldPosition(); Vector3 offset = worldPos - AbsolutePosition; Quaternion worldRot; @@ -3366,6 +3365,8 @@ namespace OpenSim.Region.Framework.Scenes return GetPriorityByDistance(client); case Scene.UpdatePrioritizationSchemes.SimpleAngularDistance: return GetPriorityBySimpleAngularDistance(client); + case Scenes.Scene.UpdatePrioritizationSchemes.FrontBack: + return GetPriorityByFrontBack(client); default: throw new InvalidOperationException("UpdatePrioritizationScheme not defined"); } @@ -3398,6 +3399,16 @@ namespace OpenSim.Region.Framework.Scenes return double.NaN; } + private double GetPriorityByFrontBack(IClientAPI client) + { + ScenePresence presence = Scene.GetScenePresence(client.AgentId); + if (presence != null) + { + return GetPriorityByFrontBack(presence.CameraPosition, presence.CameraAtAxis); + } + return double.NaN; + } + public double GetPriorityByDistance(Vector3 position) { return Vector3.Distance(AbsolutePosition, position); @@ -3427,5 +3438,21 @@ namespace OpenSim.Region.Framework.Scenes else return double.MinValue; } + + public double GetPriorityByFrontBack(Vector3 camPosition, Vector3 camAtAxis) + { + // Distance + double priority = Vector3.Distance(camPosition, AbsolutePosition); + + // Scale + //priority -= GroupScale().Length(); + + // Plane equation + float d = -Vector3.Dot(camPosition, camAtAxis); + float p = Vector3.Dot(camAtAxis, AbsolutePosition) + d; + if (p < 0.0f) priority *= 2.0f; + + return priority; + } } } diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs index 77706ace86..a610e42890 100644 --- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs +++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs @@ -297,6 +297,21 @@ namespace OpenSim.Region.Framework.Scenes get { return Util.Axes2Rot(m_CameraAtAxis, m_CameraLeftAxis, m_CameraUpAxis); } } + public Vector3 CameraAtAxis + { + get { return m_CameraAtAxis; } + } + + public Vector3 CameraLeftAxis + { + get { return m_CameraLeftAxis; } + } + + public Vector3 CameraUpAxis + { + get { return m_CameraUpAxis; } + } + public Vector3 Lookat { get @@ -3867,6 +3882,8 @@ namespace OpenSim.Region.Framework.Scenes return GetPriorityByDistance(client); case Scene.UpdatePrioritizationSchemes.SimpleAngularDistance: return GetPriorityByDistance(client); + case Scenes.Scene.UpdatePrioritizationSchemes.FrontBack: + return GetPriorityByFrontBack(client); default: throw new InvalidOperationException("UpdatePrioritizationScheme not defined."); } @@ -3888,11 +3905,34 @@ namespace OpenSim.Region.Framework.Scenes return double.NaN; } + private double GetPriorityByFrontBack(IClientAPI client) + { + ScenePresence presence = Scene.GetScenePresence(client.AgentId); + if (presence != null) + { + return GetPriorityByFrontBack(presence.CameraPosition, presence.CameraAtAxis); + } + return double.NaN; + } + private double GetPriorityByDistance(Vector3 position) { return Vector3.Distance(AbsolutePosition, position); } + private double GetPriorityByFrontBack(Vector3 camPosition, Vector3 camAtAxis) + { + // Distance + double priority = Vector3.Distance(camPosition, AbsolutePosition); + + // Plane equation + float d = -Vector3.Dot(camPosition, camAtAxis); + float p = Vector3.Dot(camAtAxis, AbsolutePosition) + d; + if (p < 0.0f) priority *= 2.0f; + + return priority; + } + private double GetSOGUpdatePriority(SceneObjectGroup sog) { switch (Scene.UpdatePrioritizationScheme) @@ -3903,6 +3943,8 @@ namespace OpenSim.Region.Framework.Scenes return sog.GetPriorityByDistance((IsChildAgent) ? AbsolutePosition : CameraPosition); case Scene.UpdatePrioritizationSchemes.SimpleAngularDistance: return sog.GetPriorityBySimpleAngularDistance((IsChildAgent) ? AbsolutePosition : CameraPosition); + case Scenes.Scene.UpdatePrioritizationSchemes.FrontBack: + return sog.GetPriorityByFrontBack(CameraPosition, CameraAtAxis); default: throw new InvalidOperationException("UpdatePrioritizationScheme not defined"); } @@ -3929,6 +3971,8 @@ namespace OpenSim.Region.Framework.Scenes case Scene.UpdatePrioritizationSchemes.Distance: case Scene.UpdatePrioritizationSchemes.SimpleAngularDistance: return GetPriorityByDistance((IsChildAgent) ? AbsolutePosition : CameraPosition); + case Scenes.Scene.UpdatePrioritizationSchemes.FrontBack: + return GetPriorityByFrontBack(CameraPosition, CameraAtAxis); default: throw new InvalidOperationException("UpdatePrioritizationScheme not defined"); } diff --git a/bin/OpenSim.ini.example b/bin/OpenSim.ini.example index 6ff70fcf28..3dc746ea50 100644 --- a/bin/OpenSim.ini.example +++ b/bin/OpenSim.ini.example @@ -1397,8 +1397,8 @@ [InterestManagement] ; This section controls how state updates are prioritized for each client - ; Valid values are Time, Distance, and SimpleAngularDistance - UpdatePrioritizationScheme = Distance; + ; Valid values are Time, Distance, SimpleAngularDistance, and FrontBack + UpdatePrioritizationScheme = FrontBack; ReprioritizationEnabled = true; ReprioritizationInterval = 2000.0; RootReprioritizationDistance = 10.0;