コード例 #1
0
ファイル: Wire.cs プロジェクト: xiaomailong/OpenRails
        /// <summary>
        /// WireProfile constructor (default - builds from self-contained data)
        /// </summary>
        public WireProfile(Viewer viewer) // Nasty: void return type is not allowed. (See MSDN for compiler error CS0542.)
            : base(viewer, 0)             //call the dummy base constructor so that no data is pre-populated
        {
            LODMethod = LODMethods.ComponentAdditive;
            LODWire     lod;     // Local LOD instance
            LODItemWire lodItem; // Local LODItem instance
            Polyline    pl;      // Local polyline instance
            Polyline    vertical;

            expectedSegmentLength = 40;    //segment of wire is expected to be 40 meters

            lod     = new LODWire(800.0f); // Create LOD for railsides with specified CutoffRadius
            lodItem = new LODItemWire("Wire");
            var normalvalue = 0.707f;

            if (File.Exists(viewer.Simulator.RoutePath + "\\Textures\\overheadwire.ace"))
            {
                lodItem.TexName = "overheadwire.ace";
            }
            else
            {
                Trace.TraceInformation("Ignored missing overheadwire.ace, using default. You can copy the overheadwire.ace from OR\'s AddOns folder to {0}\\Textures", viewer.Simulator.RoutePath);
                lodItem.TexName = "..\\..\\..\\global\\textures\\dieselsmoke.ace";
            }
            lodItem.ShaderName              = "TexDiff";
            lodItem.LightModelName          = "OptSpecular0";
            lodItem.AlphaTestMode           = 0;
            lodItem.TexAddrModeName         = "Wrap";
            lodItem.ESD_Alternative_Texture = 0;
            lodItem.MipMapLevelOfDetailBias = 0;
            LODItem.LoadMaterial(viewer, lodItem);

            float topHeight = (float)viewer.Simulator.TRK.Tr_RouteFile.OverheadWireHeight;

            float u1 = 0.25f, v1 = 0.25f;

            pl = new Polyline(this, "TopWire", 5);
            pl.DeltaTexCoord = new Vector2(0.00f, 0.00f);

            pl.Vertices.Add(new Vertex(-0.01f, topHeight + 0.02f, 0.0f, -normalvalue, normalvalue, 0f, u1, v1));
            pl.Vertices.Add(new Vertex(0.01f, topHeight + 0.02f, 0.0f, normalvalue, normalvalue, 0f, u1, v1));
            pl.Vertices.Add(new Vertex(0.01f, topHeight, 0.0f, normalvalue, -normalvalue, 0f, u1, v1));
            pl.Vertices.Add(new Vertex(-0.01f, topHeight, 0.0f, -normalvalue, -normalvalue, 0f, u1, v1));
            pl.Vertices.Add(new Vertex(-0.01f, topHeight + 0.02f, 0.0f, -normalvalue, normalvalue, 0f, u1, v1));
            lodItem.Polylines.Add(pl);
            lodItem.Accum(pl.Vertices.Count);

            if (viewer.Settings.DoubleWire)
            {
                pl = new Polyline(this, "TopWire1", 5);
                pl.DeltaTexCoord = new Vector2(0.00f, 0.00f);
                topHeight       += 1.0f;

                pl.Vertices.Add(new Vertex(-0.01f, topHeight + 0.02f, 0.0f, -normalvalue, normalvalue, 0f, u1, v1));
                pl.Vertices.Add(new Vertex(0.01f, topHeight + 0.02f, 0.0f, normalvalue, normalvalue, 0f, u1, v1));
                pl.Vertices.Add(new Vertex(0.01f, topHeight, 0.0f, normalvalue, -normalvalue, 0f, u1, v1));
                pl.Vertices.Add(new Vertex(-0.01f, topHeight, 0.0f, -normalvalue, -normalvalue, 0f, u1, v1));
                pl.Vertices.Add(new Vertex(-0.01f, topHeight + 0.02f, 0.0f, -normalvalue, normalvalue, 0f, u1, v1));
                lodItem.Polylines.Add(pl);
                lodItem.Accum(pl.Vertices.Count);

                vertical = new Polyline(this, "TopWireVertical", 5);
                vertical.DeltaTexCoord = new Vector2(0.00f, 0.00f);

                vertical.Vertices.Add(new Vertex(-0.008f, topHeight, 0.008f, -normalvalue, 0f, normalvalue, u1, v1));
                vertical.Vertices.Add(new Vertex(-.008f, topHeight, -.008f, normalvalue, 0f, normalvalue, u1, v1));
                vertical.Vertices.Add(new Vertex(.008f, topHeight, -.008f, normalvalue, 0f, -normalvalue, u1, v1));
                vertical.Vertices.Add(new Vertex(.008f, topHeight, .008f, -normalvalue, 0f, -normalvalue, u1, v1));
                vertical.Vertices.Add(new Vertex(-.008f, topHeight, .008f, -normalvalue, 0f, normalvalue, u1, v1));
                lodItem.VerticalPolylines = new ArrayList();
                lodItem.VerticalPolylines.Add(vertical);
                lodItem.VerticalAccumulate(vertical.Vertices.Count);
            }


            lod.LODItems.Add(lodItem); // Append to LODItems array
            base.LODs.Add(lod);        // Append this lod to LODs array
        }
コード例 #2
0
ファイル: Wire.cs プロジェクト: pzgulyas/openrails-1
        /// <summary>
        /// WireProfile constructor (default - builds from self-contained data)
        /// </summary>
        public WireProfile(Viewer viewer) // Nasty: void return type is not allowed. (See MSDN for compiler error CS0542.)
            : base(viewer, 0)             //call the dummy base constructor so that no data is pre-populated
        {
            LODMethod = LODMethods.ComponentAdditive;
            LODWire     lod;     // Local LOD instance
            LODItemWire lodItem; // Local LODItem instance
            Polyline    pl;      // Local polyline instance
            Polyline    vertical;

            expectedSegmentLength = 40;    //segment of wire is expected to be 40 meters

            lod     = new LODWire(800.0f); // Create LOD for railsides with specified CutoffRadius
            lodItem = new LODItemWire("Wire");
            if (File.Exists(viewer.Simulator.RoutePath + "\\Textures\\overheadwire.ace"))
            {
                lodItem.TexName = "overheadwire.ace";
            }
            else if (File.Exists(viewer.Simulator.BasePath + "\\global\\textures\\overheadwire.ace"))
            {
                lodItem.TexName = "..\\..\\..\\global\\textures\\overheadwire.ace";
            }
            else
            {
                Trace.TraceInformation("Ignored missing overheadwire.ace, using default. You can copy the overheadwire.ace from OR\'s AddOns folder to {0}\\Textures", viewer.Simulator.RoutePath);
                lodItem.TexName = "..\\..\\..\\global\\textures\\dieselsmoke.ace";
            }
            lodItem.ShaderName              = "TexDiff";
            lodItem.LightModelName          = "DarkShade";
            lodItem.AlphaTestMode           = 0;
            lodItem.TexAddrModeName         = "Wrap";
            lodItem.ESD_Alternative_Texture = 0;
            lodItem.MipMapLevelOfDetailBias = 0;
            LODItem.LoadMaterial(viewer, lodItem);

            bool drawTriphaseWire = (viewer.Simulator.TRK.Tr_RouteFile.TriphaseEnabled == "Off" ? false :
                                     viewer.Simulator.TRK.Tr_RouteFile.TriphaseEnabled == "On");
            bool drawDoubleWire = (viewer.Simulator.TRK.Tr_RouteFile.DoubleWireEnabled == "Off" ? false :
                                   viewer.Simulator.TRK.Tr_RouteFile.DoubleWireEnabled == "On" || viewer.Settings.DoubleWire);
            float topHeight     = (float)viewer.Simulator.TRK.Tr_RouteFile.OverheadWireHeight;
            float topWireOffset = (viewer.Simulator.TRK.Tr_RouteFile.DoubleWireHeight > 0 ?
                                   viewer.Simulator.TRK.Tr_RouteFile.DoubleWireHeight : 1.0f);
            float dist = (viewer.Simulator.TRK.Tr_RouteFile.TriphaseWidth > 0 ?
                          viewer.Simulator.TRK.Tr_RouteFile.TriphaseWidth : 1.0f);

            if (drawTriphaseWire)
            {
                pl = SingleWireProfile("TopWireLeft", topHeight, -dist / 2);
                lodItem.Polylines.Add(pl);
                lodItem.Accum(pl.Vertices.Count);

                pl = SingleWireProfile("TopWireRight", topHeight, dist / 2);
                lodItem.Polylines.Add(pl);
                lodItem.Accum(pl.Vertices.Count);
            }
            else
            {
                pl = SingleWireProfile("TopWire", topHeight);
                lodItem.Polylines.Add(pl);
                lodItem.Accum(pl.Vertices.Count);
            }

            if (drawDoubleWire)
            {
                topHeight += topWireOffset;

                if (drawTriphaseWire)
                {
                    pl = SingleWireProfile("TopWire1Left", topHeight, -dist / 2);
                    lodItem.Polylines.Add(pl);
                    lodItem.Accum(pl.Vertices.Count);
                    pl = SingleWireProfile("TopWire1Right", topHeight, dist / 2);
                    lodItem.Polylines.Add(pl);
                    lodItem.Accum(pl.Vertices.Count);

                    vertical = VerticalWireProfile("TopWireVerticalLeft", topHeight, -dist / 2);
                    lodItem.VerticalPolylines = new ArrayList();
                    lodItem.VerticalPolylines.Add(vertical);
                    lodItem.VerticalAccumulate(vertical.Vertices.Count);
                    vertical = VerticalWireProfile("TopWireVerticalRight", topHeight, dist / 2);
                    lodItem.VerticalPolylines.Add(vertical);
                    lodItem.VerticalAccumulate(vertical.Vertices.Count);
                }
                else
                {
                    pl = SingleWireProfile("TopWire1", topHeight);
                    lodItem.Polylines.Add(pl);
                    lodItem.Accum(pl.Vertices.Count);

                    vertical = VerticalWireProfile("TopWireVertical", topHeight);
                    lodItem.VerticalPolylines = new ArrayList();
                    lodItem.VerticalPolylines.Add(vertical);
                    lodItem.VerticalAccumulate(vertical.Vertices.Count);
                }
            }

            lod.LODItems.Add(lodItem); // Append to LODItems array
            base.LODs.Add(lod);        // Append this lod to LODs array
        }