Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            Ag.initialize();
            Aardvark.Base.Aardvark.Init();

            using (var app = new OpenGlApplication())
            {
                var win = app.CreateSimpleRenderWindow(1);

                var view        = CameraView.LookAt(new V3d(2.0, 2.0, 2.0), V3d.Zero, V3d.OOI);
                var perspective =
                    win.Sizes.Select(s => FrustumModule.perspective(60.0, 0.1, 10.0, ((float)s.X / (float)s.Y)));


                var viewTrafo = DefaultCameraController.control(win.Mouse, win.Keyboard, win.Time, view);

                var index     = new[] { 0, 1, 2, 0, 2, 3 };
                var positions = new[] { new V3f(-1, -1, 0), new V3f(1, -1, 0), new V3f(1, 1, 0), new V3f(-1, 1, 0) };

                var attributes = new SymbolDict <Array>()
                {
                    { DefaultSemantic.Positions, positions }
                };

                var quad = new IndexedGeometry(IndexedGeometryMode.TriangleList,
                                               (Array)index,
                                               attributes,
                                               new SymbolDict <Object>());

                var quadSg = quad.ToSg();

                // This is one of the hardest parts in C#. Our FShade interface is rather generic and
                // works super awesome in F#. In C# however, without proper type inference doing simple function
                // calls suddenly requires a Phd in CS. Therefore, and especially since shaders cannot be written
                // in C# anyways, write application setup and shader code in F# ;)
                // Or don't use FShade. FShade simply does not work in without functional language
                // features such as type inference and function currying.
                Func <DefaultSurfaces.Vertex, FSharpExpr <V4d> > whiteShader =
                    HighFun.ApplyArg0 <C4f, DefaultSurfaces.Vertex, FSharpExpr <V4d> >(
                        DefaultSurfaces.constantColor, C4f.White);
                Func <DefaultSurfaces.Vertex, FSharpExpr <DefaultSurfaces.Vertex> > trafo = c => DefaultSurfaces.trafo(c);

                var sg =
                    quadSg
                    .WithEffects(new[] {
                    FShadeSceneGraph.toEffect(FSharpFuncUtil.Create(trafo)),
                    FShadeSceneGraph.toEffect(FSharpFuncUtil.Create(whiteShader)),
                })
                    .ViewTrafo(viewTrafo.Select(t => t.ViewTrafo))
                    .ProjTrafo(perspective.Select(t => t.ProjTrafo()));

                var task = app.Runtime.CompileRender(win.FramebufferSignature, sg);

                win.RenderTask = DefaultOverlays.withStatistics(task);
                win.Run();
            }
        }
        public void FixedPointTests()
        {
            Test.Begin("fixed point combinator tests");
            var fib = HighFun.Y <int, int>(
                f => n => n > 1 ? f(n - 1) + f(n - 2) : n);
            var fact = HighFun.Y <int, int>(
                f => n => n > 1 ? n * f(n - 1) : 1);
            var factk = HighFun.Y <int, int, int>(
                f => (n, k) => n > 1 ? n * f(n - k, k) : 1);
            var fastfib = HighFun.Y <int, int, int, int>(
                f => (n, a, b) => n < 2 ? b : f(n - 1, b, a + b))
                          .ApplyArg1Arg2(0, 1);

            Test.IsTrue(fib(7) == 13, "fib(7) != 13");
            Test.IsTrue(fastfib(7) == 13, "ffib(7) != 13");
            Test.IsTrue(fib(8) == 21, "fib(8) != 21");
            Test.IsTrue(fastfib(8) == 21, "ffib(8) != 21");
            Test.IsTrue(fact(6) == 720, "fact(6) != 120");
            Test.IsTrue(factk(7, 2) == 105, "factk(7,2) != 105");
            Test.End();
        }