Beispiel #1
0
        public override void InitializeVisibility()
        {
            ObjectsSortedByStart        = StaticObjectStates.Select((x, i) => new { Index = i, Distance = x.StartingDistance }).OrderBy(x => x.Distance).Select(x => x.Index).ToArray();
            ObjectsSortedByEnd          = StaticObjectStates.Select((x, i) => new { Index = i, Distance = x.EndingDistance }).OrderBy(x => x.Distance).Select(x => x.Index).ToArray();
            ObjectsSortedByStartPointer = 0;
            ObjectsSortedByEndPointer   = 0;

            double p = CameraTrackFollower.TrackPosition + Camera.Alignment.Position.Z;

            foreach (ObjectState state in StaticObjectStates.Where(recipe => recipe.StartingDistance <= p + Camera.ForwardViewingDistance & recipe.EndingDistance >= p - Camera.BackwardViewingDistance))
            {
                VisibleObjects.ShowObject(state, ObjectType.Static);
            }
        }
Beispiel #2
0
        public override void UpdateVisibility(double TrackPosition)
        {
            double d = TrackPosition - LastUpdatedTrackPosition;
            int    n = ObjectsSortedByStart.Length;
            double p = CameraTrackFollower.TrackPosition + Camera.Alignment.Position.Z;

            if (d < 0.0)
            {
                if (ObjectsSortedByStartPointer >= n)
                {
                    ObjectsSortedByStartPointer = n - 1;
                }

                if (ObjectsSortedByEndPointer >= n)
                {
                    ObjectsSortedByEndPointer = n - 1;
                }

                // dispose
                while (ObjectsSortedByStartPointer >= 0)
                {
                    int o = ObjectsSortedByStart[ObjectsSortedByStartPointer];

                    if (StaticObjectStates[o].StartingDistance > p + Camera.ForwardViewingDistance)
                    {
                        VisibleObjects.HideObject(StaticObjectStates[o]);
                        ObjectsSortedByStartPointer--;
                    }
                    else
                    {
                        break;
                    }
                }

                // introduce
                while (ObjectsSortedByEndPointer >= 0)
                {
                    int o = ObjectsSortedByEnd[ObjectsSortedByEndPointer];

                    if (StaticObjectStates[o].EndingDistance >= p - Camera.BackwardViewingDistance)
                    {
                        if (StaticObjectStates[o].StartingDistance <= p + Camera.ForwardViewingDistance)
                        {
                            VisibleObjects.ShowObject(StaticObjectStates[o], ObjectType.Static);
                        }

                        ObjectsSortedByEndPointer--;
                    }
                    else
                    {
                        break;
                    }
                }
            }
            else if (d > 0.0)
            {
                if (ObjectsSortedByStartPointer < 0)
                {
                    ObjectsSortedByStartPointer = 0;
                }

                if (ObjectsSortedByEndPointer < 0)
                {
                    ObjectsSortedByEndPointer = 0;
                }

                // dispose
                while (ObjectsSortedByEndPointer < n)
                {
                    int o = ObjectsSortedByEnd[ObjectsSortedByEndPointer];

                    if (StaticObjectStates[o].EndingDistance < p - Camera.BackwardViewingDistance)
                    {
                        VisibleObjects.HideObject(StaticObjectStates[o]);
                        ObjectsSortedByEndPointer++;
                    }
                    else
                    {
                        break;
                    }
                }

                // introduce
                while (ObjectsSortedByStartPointer < n)
                {
                    int o = ObjectsSortedByStart[ObjectsSortedByStartPointer];

                    if (StaticObjectStates[o].StartingDistance <= p + Camera.ForwardViewingDistance)
                    {
                        if (StaticObjectStates[o].EndingDistance >= p - Camera.BackwardViewingDistance)
                        {
                            VisibleObjects.ShowObject(StaticObjectStates[o], ObjectType.Static);
                        }

                        ObjectsSortedByStartPointer++;
                    }
                    else
                    {
                        break;
                    }
                }
            }

            LastUpdatedTrackPosition = TrackPosition;
        }