Ejemplo n.º 1
0
        public void WorldLocationDistanceZeroTest()
        {
            WorldLocation location1 = new WorldLocation();
            WorldLocation location2 = new WorldLocation();

            Assert.IsTrue(WorldLocation.Within(location1, location2, 0));
            Assert.AreEqual(0, WorldLocation.GetDistanceSquared(location1, location2));
            Assert.AreEqual(Microsoft.Xna.Framework.Vector3.Zero, WorldLocation.GetDistance(location1, location2));
            Assert.AreEqual(Microsoft.Xna.Framework.Vector2.Zero, WorldLocation.GetDistance2D(location1, location2));
        }
Ejemplo n.º 2
0
        public void WorldLocationDistanceTest()
        {
            WorldLocation location1 = new WorldLocation();
            WorldLocation location2 = new WorldLocation(1, -1, Microsoft.Xna.Framework.Vector3.Zero);

            Assert.AreEqual(2048 * 2048 + 2048 * 2048, WorldLocation.GetDistanceSquared(location1, location2));
            Assert.IsTrue(WorldLocation.Within(location1, location2, (float)Math.Sqrt(2048 * 2048 * 2) + 1));

            Assert.AreEqual(new Microsoft.Xna.Framework.Vector3(2048, 0, -2048), WorldLocation.GetDistance(location1, location2));
            Assert.AreEqual(new Microsoft.Xna.Framework.Vector2(2048, -2048), WorldLocation.GetDistance2D(location1, location2));
        }
Ejemplo n.º 3
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);
            }
        }
Ejemplo n.º 4
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);
            }
        }