Exemplo n.º 1
0
        public void BoxTransformTest()
        {
            var cnt    = 10000;
            var rnd    = new RandomSystem(1);
            var trafos = new M44d[cnt].SetByIndex(i => new M44d(rnd.CreateUniformDoubleArray(16)));
            //var trafos = new M44d[cnt].SetByIndex(i => M44d.FromBasis(rnd.UniformV3d(), rnd.UniformV3d(), rnd.UniformV3d(), rnd.UniformV3d()));
            //var trafos = new M44d[cnt].SetByIndex(i => M44d.Translation(rnd.UniformV3d()));
            //var trafos = new M44d[cnt].SetByIndex(i => M44d.Rotation(rnd.UniformV3d()) * M44d.Translation(rnd.UniformV3d()));
            var boxes    = new Box3d[cnt].SetByIndex(i => Box3d.FromCenterAndSize(rnd.UniformV3d(), rnd.UniformV3d()));
            var refBoxes = boxes.Map((b, i) => Transform1(b, trafos[i]));

            for (int j = 0; j < 10; j++)
            {
                Report.BeginTimed("Transform Boxes Aardvark");
                for (int i = 0; i < trafos.Length; i++)
                {
                    var test = boxes[i].Transformed(trafos[i]);
                    Assert.IsTrue(test.Min.ApproximateEquals(refBoxes[i].Min, 1e-7) && test.Max.ApproximateEquals(refBoxes[i].Max, 1e-7));
                }
                Report.End();

                Report.BeginTimed("Transform Boxes1");
                for (int i = 0; i < trafos.Length; i++)
                {
                    var test = Transform1(boxes[i], trafos[i]);
                    Assert.IsTrue(test.Min.ApproximateEquals(refBoxes[i].Min, 1e-7) && test.Max.ApproximateEquals(refBoxes[i].Max, 1e-7));
                }
                Report.End();


                Report.BeginTimed("Transform Boxes2");
                for (int i = 0; i < trafos.Length; i++)
                {
                    var test = Transform2(boxes[i], trafos[i]);
                    Assert.IsTrue(test.Min.ApproximateEquals(refBoxes[i].Min, 1e-7) && test.Max.ApproximateEquals(refBoxes[i].Max, 1e-7));
                }
                Report.End();

                Report.BeginTimed("Transform Boxes3");
                for (int i = 0; i < trafos.Length; i++)
                {
                    var test = Transform3(boxes[i], trafos[i]);
                    Assert.IsTrue(test.Min.ApproximateEquals(refBoxes[i].Min, 1e-7) && test.Max.ApproximateEquals(refBoxes[i].Max, 1e-7));
                }
                Report.End();

                Report.BeginTimed("Transform Boxes4");
                for (int i = 0; i < trafos.Length; i++)
                {
                    var test = Transform4(boxes[i], trafos[i]);
                    Assert.IsTrue(test.Min.ApproximateEquals(refBoxes[i].Min, 1e-7) && test.Max.ApproximateEquals(refBoxes[i].Max, 1e-7));
                }
                Report.End();
            }
        }
Exemplo n.º 2
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();
            }
        }
Exemplo n.º 3
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();
            }
        }