示例#1
0
        public override void PrepareFrame(RenderFrame frame, ORTS.Common.ElapsedTime elapsedTime, bool updateFull)
        {
            if (updateFull)
            {
                var labels         = Labels;
                var newLabels      = new Dictionary <TrainCar, LabelPrimitive>(labels.Count);
                var cars           = Owner.Viewer.World.Trains.Cars;
                var cameraLocation = Owner.Viewer.Camera.CameraWorldLocation;
                foreach (var car in cars.Keys)
                {
                    // Calculates distance between camera and platform label.
                    var distance = WorldLocation.GetDistance(car.WorldPosition.WorldLocation, cameraLocation).Length();
                    if (distance <= MaximumDistance)
                    {
                        if ((State == DisplayState.Cars) || (State == DisplayState.Trains && (car.Train == null || car.Train.FirstCar == car)))
                        {
                            if (labels.ContainsKey(car))
                            {
                                newLabels[car] = labels[car];
                            }
                            else
                            {
                                newLabels[car] = new LabelPrimitive(Owner.Label3DMaterial, Color.Blue, Color.White, car.CarHeightM)
                                {
                                    Position = car.WorldPosition
                                }
                            };

                            newLabels[car].Text = State == DisplayState.Cars || car.Train == null ? car.CarID : car.Train.Name;

                            // Change color with distance.
                            var ratio = (MathHelper.Clamp(distance, MinimumDistance, MaximumDistance) - MinimumDistance) / (MaximumDistance - MinimumDistance);
                            newLabels[car].Color.A = newLabels[car].Outline.A = (byte)MathHelper.Lerp(255, 0, ratio);
                        }
                    }
                }
                Labels = newLabels;
            }

            foreach (var primitive in Labels.Values)
            {
                frame.AddPrimitive(Owner.Label3DMaterial, primitive, RenderPrimitiveGroup.Labels, ref Identity);
            }
        }
示例#2
0
        public override void PrepareFrame(RenderFrame frame, ORTS.Common.ElapsedTime elapsedTime, bool updateFull)
        {
            if (updateFull)
            {
                UpdateLabelLists();

                var labels         = Labels;
                var newLabels      = new Dictionary <TrItemLabel, LabelPrimitive>(labels.Count);
                var worldFiles     = Owner.Viewer.World.Scenery.WorldFiles;
                var cameraLocation = Owner.Viewer.Camera.CameraWorldLocation;
                foreach (var worldFile in worldFiles)
                {
                    if ((State & DisplayState.Platforms) != 0 && worldFile.platforms != null)
                    {
                        foreach (var platform in worldFile.platforms)
                        {
                            if (State == DisplayState.Auto && Platforms != null && (!Platforms.ContainsKey(platform.ItemName) || !Platforms[platform.ItemName]))
                            {
                                continue;
                            }

                            // Calculates distance between camera and platform label.
                            var distance = WorldLocation.GetDistance(platform.Location.WorldLocation, cameraLocation).Length();
                            if (distance <= MaximumDistancePlatform)
                            {
                                if (labels.ContainsKey(platform))
                                {
                                    newLabels[platform] = labels[platform];
                                }
                                else
                                {
                                    newLabels[platform] = new LabelPrimitive(Owner.Label3DMaterial, Color.Yellow, Color.Black, 0)
                                    {
                                        Position = platform.Location, Text = platform.ItemName
                                    }
                                };

                                // Change color with distance.
                                var ratio = (MathHelper.Clamp(distance, MinimumDistance, MaximumDistancePlatform) - MinimumDistance) / (MaximumDistancePlatform - MinimumDistance);
                                newLabels[platform].Color.A = newLabels[platform].Outline.A = (byte)MathHelper.Lerp(255, 0, ratio);
                            }
                        }
                    }

                    if ((State & DisplayState.Sidings) != 0 && worldFile.sidings != null)
                    {
                        foreach (var siding in worldFile.sidings)
                        {
                            if (State == DisplayState.Auto && Sidings != null && (!Sidings.ContainsKey(siding.ItemName) || !Sidings[siding.ItemName]))
                            {
                                continue;
                            }

                            // Calculates distance between camera and siding label.
                            var distance = WorldLocation.GetDistance(siding.Location.WorldLocation, cameraLocation).Length();
                            if (distance <= MaximumDistanceSiding)
                            {
                                if (labels.ContainsKey(siding))
                                {
                                    newLabels[siding] = labels[siding];
                                }
                                else
                                {
                                    newLabels[siding] = new LabelPrimitive(Owner.Label3DMaterial, Color.Orange, Color.Black, 0)
                                    {
                                        Position = siding.Location, Text = siding.ItemName
                                    }
                                };

                                // Change color with distance.
                                var ratio = (MathHelper.Clamp(distance, MinimumDistance, MaximumDistanceSiding) - MinimumDistance) / (MaximumDistanceSiding - MinimumDistance);
                                newLabels[siding].Color.A = newLabels[siding].Outline.A = (byte)MathHelper.Lerp(255, 0, ratio);
                            }
                        }
                    }
                }
                Labels = newLabels;
            }

            foreach (var primitive in Labels.Values)
            {
                frame.AddPrimitive(Owner.Label3DMaterial, primitive, RenderPrimitiveGroup.Labels, ref Identity);
            }
        }