Esempio n. 1
0
        public static Geometry <V> ExtrudeToScale <V> (this Geometry <V> plane, float depth, float targetScale,
                                                       float steepness, int numSteps, bool includeFrontFace = true, bool includeBackFace = true,
                                                       Vec3 scaleAround = new Vec3())
            where V : struct, IVertex3D
        {
            if (depth <= 0f)
            {
                throw new ArgumentException(
                          "Depth needs to be greater than zero.", "depth");
            }
            if (steepness <= 0)
            {
                throw new ArgumentException(
                          "Steepness parameter needs to be greater than zero.", "steepness");
            }

            var normal     = plane.Vertices[0].normal;
            var step       = depth / numSteps;
            var scaleRange = 1f - targetScale;
            var exponent   = scaleRange < 0 ? 1f / steepness : steepness;
            var transforms =
                from s in EnumerableExt.Range(step, depth, step)
                let factor                       = (1f - (s / depth).Pow(exponent)) * scaleRange + targetScale
                                        let offs = -normal * s
                                                   select Mat.Translation <Mat4> (offs.X, offs.Y, offs.Z) *
                                                   Mat.ScalingPerpendicularTo(normal, new Vec2(factor)).RelativeTo(scaleAround);

            return(plane.Stretch(transforms, includeFrontFace, includeBackFace));
        }
        public IEnumerable <JGram.Entry> Lookup(string key)
        {
            int limit = 50;

            var(start, end) = index.EqualRange(key, kvp => kvp.Key);
            var outOfBoundLimit = (limit - (end - start)) / 2;

            start = Math.Max(0, start - outOfBoundLimit);
            end   = Math.Min(entries.Count, end + outOfBoundLimit);
            var mid = (start + end) / 2;

            var resultEntries = EnumerableExt.Range(start, end - start)
                                .OrderBy(i => Math.Abs(i - mid))
                                .Select(i => index[i])
                                .Select(indexEntry =>
            {
                var indexKey   = indexEntry.Key;
                var entryKey   = indexEntry.Value;
                var(entry, id) = entries.BinarySearch(entryKey, e => e.Id);
                return((indexKey, entry).SomeWhen(_ => id != -1));
            })
                                .Values()
                                .OrderByDescending(r => CommonPrefixLength(r.indexKey, key))
                                .Where(r => CommonPrefixLength(r.indexKey, key) != 0)
                                .Select(r => r.entry);

            return(EnumerableExt.DistinctBy(resultEntries, entry => entry.Id));
        }
Esempio n. 3
0
        public static Geometry <EntityVertex> SineS()
        {
            var range   = MathHelper.PiOver2;
            var step    = MathHelper.Pi / 20f;
            var contour =
                (from x in EnumerableExt.Range(-range, range, step)
                 select new Vec2(x, x.Sin() + 1f))
                .Concat(
                    from x in EnumerableExt.Range(range, -range, -step)
                    select new Vec2(x, x.Sin() - 1f)).ToArray();

            return(Polygon <EntityVertex> .FromVec2s(contour)
                   .Extrude(2f, true)
                   .Smoothen(0.9f));
        }
Esempio n. 4
0
            public Exhaust(Rear rear, float length)
            {
                var plateSide = Quadrilateral <V> .Trapezoid(0.38f, length, 0f, -0.1f);

                //var nozzlePlate = Composite.Create (plateSide, plateSide.ReflectZ ());
                var nozzlePlate = plateSide.Extrude(0.05f);
                var plateCnt    = 12;
                var plates      = new Geometry <V> [plateCnt];
                var angle       = 0f;

                for (int i = 0; i < plateCnt; i++, angle += MathHelper.TwoPi / plateCnt)
                {
                    plates[i] = nozzlePlate
                                .Translate(0f, length / 2f, 0f)
                                .RotateX(-105f.Radians())
                                .Translate(0f, 0.62f, 0f)
                                .RotateZ(angle);
                }
                var snapToVertex = rear.Geometry.Vertices.Furthest(Dir3D.Back).Furthest(Dir3D.Up).First();
                var exhaust      = Composite.Create(plates);

                Geometry = exhaust
                           .SnapTo(exhaust.Vertices.Furthest(Dir3D.Up).First().position, snapToVertex.position,
                                   Axes.Y | Axes.Z)
                           .Translate(0f, -0.02f, 0.02f)
                           .Color(VertexColor <Vec3> .BlackPlastic);

                FlangeXSection = new Path <P, Vec3> (
                    from n in rear.RearXSection.Vertices
                    where n.position.X < -0.65f && n.position.Y < 0.4f
                    select n)
                                 .Close();
                FlangeEndXSection = new Path <P, Vec3> (
                    from n in FlangeXSection.Vertices
                    select new P()
                {
                    position = new Vec3(n.position.X, n.position.Y.Clamp(-0.2f, 0.1f), n.position.Z)
                });
                var center = FlangeEndXSection.Vertices.Center <P, Vec3> ();

                StabilizerFlange = FlangeXSection.MorphTo(FlangeEndXSection,
                                                          EnumerableExt.Range(0f, -1.25f, -0.25f).Select(s => Mat.Translation <Mat4> (0f, 0f, s) *
                                                                                                         Mat.Scaling <Mat4> (1f, 1f - (s * 0.3f).Pow(2f)).RelativeTo(center)))
                                   .Extrude <V, P> (false, true)
                                   .Color(_color);
            }
Esempio n. 5
0
            public MainFuselage(CockpitFuselage cockpitFuselage)
            {
                XSection = CrossSection(
                    cockpitFuselage.XSectionStart.position,
                    cockpitFuselage.XSection.Vertices.Furthest(Dir3D.Up).First().position.Y,
                    cockpitFuselage.XSection.Vertices.Length);

                var transforms = from z in EnumerableExt.Range(0f, -2f, -0.25f)
                                 select Mat.Translation <Mat4> (0f, 0f, z);

                var paths = EnumerableExt.Append(
                    cockpitFuselage.XSection.MorphTo(XSection, transforms),
                    XSection.Translate(0f, 0f, -6.75f));

                RearXSection = paths.Last();
                Fuselage     = paths.Extrude <V, P> (false, false)
                               .Color(_color);
            }
Esempio n. 6
0
            public Rear(MainFuselage fuselage, Underside underside)
            {
                var pos1 = new P()
                {
                    position = fuselage.RearXSection.Vertices.First().position + new Vec3(0f, -0.1f, 0f)
                };
                var pos2 = new P()
                {
                    position = fuselage.RearXSection.Vertices.Last().position + new Vec3(0f, -0.1f, 0f)
                };

                XSection     = +(fuselage.RearXSection + pos2 + underside.RearXSection + pos1);
                RearXSection = +(fuselage.RearXSection.Scale(1f, 0.9f) + pos2 +
                                 BottomXSection(underside.RearXSection) + pos1);
                var transforms =
                    from s in EnumerableExt.Range(0f, 2.5f, 0.5f)
                    select Mat.Translation <Mat4> (0f, s / 25f, -s);

                var paths = XSection.MorphTo(RearXSection, transforms);
                var rear  = paths.Extrude <V, P> (false, false);

                RearXSection   = paths.Last();
                EngineXSection = new Path <P, Vec3> (
                    from n in RearXSection.Vertices
                    where n.position.X >= -0.9f && n.position.X <= 0.9f
                    select new P()
                {
                    position = new Vec3(n.position.X.Clamp(-0.75f, 0.75f), n.position.Y, n.position.Z)
                })
                                 .Close();
                ExhaustXSection = EngineXSection.Scale(0.8f, 0.7f);
                transforms      =
                    from s in EnumerableExt.Range(0f, 1f, 0.5f)
                    select Mat.Translation <Mat4> (0f, s / 10f, -s);

                var engine = EngineXSection.MorphTo(ExhaustXSection, transforms)
                             .Extrude <V, P> (false, true);

                Geometry = Composite.Create(rear, engine)
                           .Color(_color);
            }
Esempio n. 7
0
            public Underside(EngineIntake intake)
            {
                var nodes =
                    from n in intake.RearXSection.ReverseWinding().Vertices
                    where n.position.Y <= -0.2f
                    select n;

                XSection = new Path <P, Vec3> (nodes);
                var firstNode = XSection.Vertices.First();
                var paths     =
                    from s in EnumerableExt.Range(0f, 4f, 1f)
                    let scaleFactor = (0.15f * s).Pow(2f)
                                      select XSection.Transform(
                        Mat.Translation <Mat4> (0f, 0f, -s) *
                        Mat.Scaling <Mat4> (1f - (scaleFactor * 0.25f), 1f - scaleFactor, 1f)
                        .RelativeTo(new Vec3(0f, firstNode.position.Y, 0f)));

                RearXSection = paths.Last();
                Geometry     = paths.Extrude <V, P> (false, false)
                               .Color(_color);
            }
Esempio n. 8
0
            public EngineIntake(CockpitFuselage cockpitFuselage)
            {
                var startNode = cockpitFuselage.XSectionStart;

                XSection = CrossSection(startNode.position,
                                        -cockpitFuselage.XSection.Vertices.Furthest(Dir3D.Up).First().position.Y, 20);

                var transforms =
                    from s in EnumerableExt.Range(0.25f, 2f, 0.25f)
                    let scaleFactor = 1f + (0.2f * s.Pow(0.5f))
                                      select Mat.Translation <Mat4> (0f, 0f, -s) *
                                      Mat.Scaling <Mat4> (scaleFactor, scaleFactor, 1f)
                                      .RelativeTo(new Vec3(0f, startNode.position.Y, 0f));

                Intake = XSection
                         .Inset <P, V> (0.9f, 0.9f)
                         .Stretch(transforms, true, false)
                         .Color(_color);
                RearXSection = XSection.Transform(transforms.Last());

                BellyXSection = Path <P, Vec3> .FromVecs(
                    from v in cockpitFuselage.Fuselage.Vertices.Furthest (Dir3D.Back)
                    where v.position.Y < -0.1f
                    select v.position);

                var scalePoint = new Vec3(0f, BellyXSection.Vertices.First().position.Y, 0f);

                Belly = EnumerableExt.Enumerate(BellyXSection,
                                                BellyXSection.Transform(Mat.Translation <Mat4> (0f, 0f, -1f) *
                                                                        Mat.Scaling <Mat4> (1.45f, 1f, 1f).RelativeTo(scalePoint)),
                                                BellyXSection.Transform(Mat.Translation <Mat4> (0f, 0f, -2f) *
                                                                        Mat.Scaling <Mat4> (1.9f, 1.25f, 1f).RelativeTo(scalePoint)),
                                                BellyXSection.Transform(Mat.Translation <Mat4> (0f, 0f, -3f) *
                                                                        Mat.Scaling <Mat4> (1.9f, 1.3f, 1f).RelativeTo(scalePoint)))
                        .Extrude <V, P> (false, false)
                        .Color(_color);
            }