Beispiel #1
0
        /// <summary>Creates a mirrored copy of the prototype object</summary>
        /// <param name="Prototype">The prototype</param>
        /// <returns>The mirrored copy</returns>
        private static StaticObject GetMirroredStaticObject(StaticObject Prototype)
        {
            StaticObject Result = (StaticObject)Prototype.Clone();

            for (int i = 0; i < Result.Mesh.Vertices.Length; i++)
            {
                Result.Mesh.Vertices[i].Coordinates.X = -Result.Mesh.Vertices[i].Coordinates.X;
            }
            for (int i = 0; i < Result.Mesh.Faces.Length; i++)
            {
                for (int k = 0; k < Result.Mesh.Faces[i].Vertices.Length; k++)
                {
                    Result.Mesh.Faces[i].Vertices[k].Normal.X = -Result.Mesh.Faces[i].Vertices[k].Normal.X;
                }
                Result.Mesh.Faces[i].Flip();
            }
            return(Result);
        }
Beispiel #2
0
        public override void Create(Vector3 wpos, Transformation RailTransformation, Transformation LocalTransformation, int SectionIndex, double StartingDistance, double EndingDistance, double TrackPosition, double Brightness)
        {
            if (SignalTextures.Length != 0)
            {
                int m  = Math.Max(SignalTextures.Length, GlowTextures.Length);
                int zn = 0;
                for (int l = 0; l < m; l++)
                {
                    if (l < SignalTextures.Length && SignalTextures[l] != null || l < GlowTextures.Length && GlowTextures[l] != null)
                    {
                        zn++;
                    }
                }

                AnimatedObjectCollection aoc = new AnimatedObjectCollection(Plugin.CurrentHost)
                {
                    Objects = new[]
                    {
                        new AnimatedObject(Plugin.CurrentHost)
                        {
                            States = new ObjectState[zn]
                        }
                    }
                };

                int    zi   = 0;
                string expr = "";
                for (int l = 0; l < m; l++)
                {
                    bool         qs = l < SignalTextures.Length && SignalTextures[l] != null;
                    bool         qg = l < GlowTextures.Length && GlowTextures[l] != null;
                    StaticObject so = new StaticObject(Plugin.CurrentHost);
                    StaticObject go = null;
                    if (qs & qg)
                    {
                        if (BaseObject != null)
                        {
                            so = BaseObject.Clone(SignalTextures[l], null);
                        }

                        if (GlowObject != null)
                        {
                            go = GlowObject.Clone(GlowTextures[l], null);
                        }

                        so.JoinObjects(go);
                        aoc.Objects[0].States[zi] = new ObjectState(so);
                    }
                    else if (qs)
                    {
                        if (BaseObject != null)
                        {
                            so = BaseObject.Clone(SignalTextures[l], null);
                        }

                        aoc.Objects[0].States[zi] = new ObjectState(so);
                    }
                    else if (qg)
                    {
                        if (GlowObject != null)
                        {
                            go = GlowObject.Clone(GlowTextures[l], null);
                        }

                        //BUG: Should we join the glow object here? Test what BVE4 does with missing state, but provided glow
                        aoc.Objects[0].States[zi] = new ObjectState(so);
                    }

                    if (qs | qg)
                    {
                        CultureInfo Culture = CultureInfo.InvariantCulture;
                        if (zi < zn - 1)
                        {
                            expr += "section " + l.ToString(Culture) + " <= " + zi.ToString(Culture) + " ";
                        }
                        else
                        {
                            expr += zi.ToString(Culture);
                        }

                        zi++;
                    }
                }

                for (int l = 0; l < zn - 1; l++)
                {
                    expr += " ?";
                }

                aoc.Objects[0].StateFunction = new FunctionScript(Plugin.CurrentHost, expr, false);
                aoc.Objects[0].RefreshRate   = 1.0 + 0.01 * Plugin.RandomNumberGenerator.NextDouble();
                aoc.CreateObject(wpos, RailTransformation, LocalTransformation, SectionIndex, StartingDistance, EndingDistance, TrackPosition, 1.0);
            }
        }
Beispiel #3
0
        private static void CreateTouchElement(TrainManager.ElementsGroup Group, Vector3 Position, Vector3 Size, int ScreenIndex, int SoundIndex, Translations.Command Command, int CommandOption)
        {
            Vertex       t0     = new Vertex(Size.X, Size.Y, -Size.Z);
            Vertex       t1     = new Vertex(Size.X, -Size.Y, -Size.Z);
            Vertex       t2     = new Vertex(-Size.X, -Size.Y, -Size.Z);
            Vertex       t3     = new Vertex(-Size.X, Size.Y, -Size.Z);
            Vertex       t4     = new Vertex(Size.X, Size.Y, Size.Z);
            Vertex       t5     = new Vertex(Size.X, -Size.Y, Size.Z);
            Vertex       t6     = new Vertex(-Size.X, -Size.Y, Size.Z);
            Vertex       t7     = new Vertex(-Size.X, Size.Y, Size.Z);
            StaticObject Object = new StaticObject(Program.CurrentHost);

            Object.Mesh.Vertices                      = new VertexTemplate[] { t0, t1, t2, t3, t4, t5, t6, t7 };
            Object.Mesh.Faces                         = new MeshFace[] { new MeshFace(new int[] { 0, 1, 2, 3 }), new MeshFace(new int[] { 0, 4, 5, 1 }), new MeshFace(new int[] { 0, 3, 7, 4 }), new MeshFace(new int[] { 6, 5, 4, 7 }), new MeshFace(new int[] { 6, 7, 3, 2 }), new MeshFace(new int[] { 6, 2, 1, 5 }) };
            Object.Mesh.Materials                     = new MeshMaterial[1];
            Object.Mesh.Materials[0].Flags            = 0;
            Object.Mesh.Materials[0].Color            = Color32.White;
            Object.Mesh.Materials[0].TransparentColor = Color24.Blue;
            Object.Mesh.Materials[0].DaytimeTexture   = null;
            Object.Mesh.Materials[0].NighttimeTexture = null;
            Object.Dynamic = true;
            if (Group.TouchElements == null)
            {
                Group.TouchElements = new TrainManager.TouchElement[0];
            }
            int n = Group.TouchElements.Length;

            Array.Resize(ref Group.TouchElements, n + 1);
            Group.TouchElements[n] = new TrainManager.TouchElement
            {
                Element         = new ObjectManager.AnimatedObject(),
                JumpScreenIndex = ScreenIndex,
                SoundIndex      = SoundIndex,
                Command         = Command,
                CommandOption   = CommandOption
            };
            Group.TouchElements[n].Element.States             = new AnimatedObjectState[1];
            Group.TouchElements[n].Element.States[0].Position = Position;
            Group.TouchElements[n].Element.States[0].Object   = Object;
            Group.TouchElements[n].Element.CurrentState       = 0;
            Group.TouchElements[n].Element.ObjectIndex        = ObjectManager.CreateDynamicObject();
            ObjectManager.Objects[Group.TouchElements[n].Element.ObjectIndex] = (StaticObject)Object.Clone();
            int m = Interface.CurrentControls.Length;

            Array.Resize(ref Interface.CurrentControls, m + 1);
            Interface.CurrentControls[m].Command = Command;
            Interface.CurrentControls[m].Method  = Interface.ControlMethod.Touch;
            Interface.CurrentControls[m].Option  = CommandOption;
        }
Beispiel #4
0
        /// <summary>Creates a transformed copy of the provided prototype object (e.g. Platform top, roof etc.)</summary>
        /// <param name="Prototype">The prototype</param>
        /// /// <param name="NearDistance">The object's width at the start of the block</param>
        /// /// <param name="FarDistance">The object's width at the end of the block</param>
        /// <returns>The transformed copy</returns>
        private static StaticObject GetTransformedStaticObject(StaticObject Prototype, double NearDistance, double FarDistance)
        {
            StaticObject Result = (StaticObject)Prototype.Clone();
            int          n = 0;
            double       x2 = 0.0, x3 = 0.0, x6 = 0.0, x7 = 0.0;

            for (int i = 0; i < Result.Mesh.Vertices.Length; i++)
            {
                if (n == 2)
                {
                    x2 = Result.Mesh.Vertices[i].Coordinates.X;
                }
                else if (n == 3)
                {
                    x3 = Result.Mesh.Vertices[i].Coordinates.X;
                }
                else if (n == 6)
                {
                    x6 = Result.Mesh.Vertices[i].Coordinates.X;
                }
                else if (n == 7)
                {
                    x7 = Result.Mesh.Vertices[i].Coordinates.X;
                }
                n++;
                if (n == 8)
                {
                    break;
                }
            }
            if (n >= 4)
            {
                int m = 0;
                for (int i = 0; i < Result.Mesh.Vertices.Length; i++)
                {
                    if (m == 0)
                    {
                        Result.Mesh.Vertices[i].Coordinates.X = NearDistance - x3;
                    }
                    else if (m == 1)
                    {
                        Result.Mesh.Vertices[i].Coordinates.X = FarDistance - x2;
                        if (n < 8)
                        {
                            break;
                        }
                    }
                    else if (m == 4)
                    {
                        Result.Mesh.Vertices[i].Coordinates.X = NearDistance - x7;
                    }
                    else if (m == 5)
                    {
                        Result.Mesh.Vertices[i].Coordinates.X = NearDistance - x6;
                        break;
                    }
                    m++;
                    if (m == 8)
                    {
                        break;
                    }
                }
            }
            return(Result);
        }