public MainWindow()
        {
            InitializeComponent();
            Loaded += MainWindow_Loaded;
            Aardvark.Base.Aardvark.Init();

            var useAardvark = true;

            if (useAardvark)
            {
                app = new Aardvark.Application.WinForms.OpenGlApplication();

                app.Initialize(rc, 1);

                var renderControl = rc;

                var cone                = IndexedGeometryPrimitives.solidCone(V3d.OOO, V3d.OOI, 1.0, 0.2, 12, C4b.Red).ToSg(); // build object from indexgeometry primitives
                var cube                = SgPrimitives.Sg.box(Mod.Init(C4b.Blue), Mod.Init(Box3d.Unit));                       // or directly using scene graph
                var initialViewTrafo    = CameraViewModule.lookAt(V3d.III * 3.0, V3d.OOO, V3d.OOI);
                var controlledViewTrafo = Aardvark.Application.DefaultCameraController.control(renderControl.Mouse, renderControl.Keyboard,
                                                                                               renderControl.Time, initialViewTrafo);
                var frustum = renderControl.Sizes.Select(size => FrustumModule.perspective(60.0, 0.1, 10.0, size.X / (float)size.Y));

                var whiteShader = Aardvark.Base.Rendering.Effects.SimpleLighting.Effect;
                var trafo       = Effects.Trafo.Effect;

                var currentAngle = 0.0;
                var angle        = renderControl.Time.Select(t =>
                {
                    if (true)
                    {
                        return(currentAngle += 0.001);
                    }
                    else
                    {
                        return(currentAngle);
                    }
                });
                var rotatingTrafo = angle.Select((whyCantShadowName) => Trafo3d.RotationZ(whyCantShadowName));

                var sg =
                    new[] { cone, cube.Trafo(rotatingTrafo) }
                .ToSg()
                .WithEffects(new[] { trafo, whiteShader })
                .ViewTrafo(controlledViewTrafo.Select(c => c.ViewTrafo))
                .ProjTrafo(frustum.Select(f => f.ProjTrafo()));

                renderControl.RenderTask =
                    Aardvark.Base.RenderTask.ofArray(
                        new[] {
                    app.Runtime.CompileClear(renderControl.FramebufferSignature, Mod.Init(C4f.Red)),
                    app.Runtime.CompileRender(renderControl.FramebufferSignature, sg)
                }
                        );

                //var r = new System.Windows.Forms.Form();
                //r.Controls.Add(renderControl);
                //r.Show();
            }
        }
Esempio n. 2
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();
            }
        }
Esempio n. 3
0
        public static void Main(string[] args)
        {
            Aardvark.Base.Aardvark.Init();
            using (var app = /*new VulkanApplication() */ new OpenGlApplication())
            {
                var win = app.CreateGameWindow(samples: 8);

                // build object from indexgeometry primitives
                var cone =
                    IndexedGeometryPrimitives.Cone.solidCone(
                        V3d.OOO, V3d.OOI, 1.0,
                        0.2, 48, C4b.Red
                        ).ToSg();
                // or directly using scene graph
                var cube = SgPrimitives.Sg.box(
                    Mod.Init(C4b.Blue),
                    Mod.Init(Box3d.FromCenterAndSize(V3d.Zero, V3d.III))
                    );
                var initialViewTrafo    = CameraView.LookAt(new V3d(0.2, 1.2, 0.9) * 3.0, V3d.OOO, V3d.OOI);
                var controlledViewTrafo =
                    Aardvark.Application.DefaultCameraController.control(win.Mouse, win.Keyboard,
                                                                         win.Time, initialViewTrafo);
                var frustum =
                    win.Sizes.Map(size =>
                                  FrustumModule.perspective(60.0, 0.1, 10.0, size.X / (float)size.Y)
                                  );

                // of course constructing scene graph nodes manually is tedious. therefore we use
                // convinience extension functions which can be chaned together, each
                // wrapping a node around the previously constructed scene graph
                var scene =
                    cube
                    // next, we apply the shaders (this way, the shader becomes the root node -> all children now use
                    // this so called effect (a pipeline shader which combines all shader stages into one object)
                    .WithEffects(new[] {
                    Aardvark.Base.Rendering.Effects.Trafo.Effect,
                    Aardvark.Base.Rendering.Effects.VertexColor.Effect,
                    Aardvark.Base.Rendering.Effects.SimpleLighting.Effect
                })
                    .ViewTrafo(controlledViewTrafo.Map(vt => vt.ViewTrafo))
                    .ProjTrafo(frustum.Map <Frustum, Trafo3d>(f => f.ProjTrafo()));

                // next we use the aardvark scene graph compiler to construct a so called render task,
                // an optimized representation of the scene graph.
                var renderTask = app.Runtime.CompileRender(win.FramebufferSignature, scene);

                // next, we assign the rendertask to our render window.
                win.RenderTask = renderTask;

                win.Run();
            }
        }
Esempio n. 4
0
        public static void Run()
        {
            using (var app = /*new VulkanApplication() */ new OpenGlApplication())
            {
                var win = app.CreateSimpleRenderWindow(samples: 8);

                var cone                = IndexedGeometryPrimitives.Cone.solidCone(V3d.OOO, V3d.OOI, 1.0, 0.2, 48, C4b.Red).ToSg();                            // build object from indexgeometry primitives
                var cube                = SgPrimitives.Sg.box(AValModule.constant(C4b.Blue), AValModule.constant(Box3d.FromCenterAndSize(V3d.Zero, V3d.III))); // or directly using scene graph
                var initialViewTrafo    = CameraView.LookAt(V3d.III * 3.0, V3d.OOO, V3d.OOI);
                var controlledViewTrafo = Aardvark.Application.DefaultCameraController.control(win.Mouse, win.Keyboard,
                                                                                               win.Time, initialViewTrafo);
                var frustum = win.Sizes.Map(size => FrustumModule.perspective(60.0, 0.1, 10.0, size.X / (float)size.Y));

                var whiteShader = Aardvark.Rendering.Effects.SimpleLighting.Effect;
                var trafo       = Effects.Trafo.Effect;

                var currentAngle = 0.0;
                var angle        = win.Time.Map(t =>
                {
                    return(currentAngle += 0.001);
                });
                var rotatingTrafo = angle.Map(a => Trafo3d.RotationZ(a));

                var sg =
                    new[] {
                    cone.Trafo(AValModule.constant(Trafo3d.Translation(1.0, 1.0, 0.0))),
                    cube.Trafo(rotatingTrafo)
                }
                .ToSg()
                .WithEffects(new[] { trafo, whiteShader })
                .ViewTrafo(controlledViewTrafo.Map(c => c.ViewTrafo))
                .ProjTrafo(frustum.Map(f => f.ProjTrafo()));

                win.RenderTask =
                    Aardvark.Rendering.RenderTask.ofArray(
                        new[] {
                    app.Runtime.CompileClear(win.FramebufferSignature, AValModule.constant(C4f.Gray10)),
                    app.Runtime.CompileRender(win.FramebufferSignature, sg)
                }
                        );

                win.Run();
            }
        }
Esempio n. 5
0
        static IModRef <BackendConfiguration> SetScene(IRenderControl win)
        {
            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();

            var whiteShader = Effects.ConstantColor.Effect(C4f.White);

            var trafo = Effects.Trafo.Effect;

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

            var config = new ModRef <BackendConfiguration>(BackendConfigurationModule.UnmanagedOptimized);
            var task   = ((Aardvark.Rendering.GL.Runtime)win.Runtime).CompileRender(win.FramebufferSignature, config, Aardvark.SceneGraph.Semantics.RenderObjectSemantics.Semantic.renderObjects(sg));

            win.RenderTask = DefaultOverlays.withStatistics(task);

            return(config);
        }