예제 #1
0
        public GameObject DrawCylinder(string key, CylinderDetails cyl)
        {
            var geo = GeometryBuilder.BuildCylinder(cyl.Start, cyl.Axis, cyl.Radius, cyl.Length);

            var en = EntityBuilders.BuildColored(Context, ElementTag.New(key), geo, cyl.Color, SharpDX.Direct3D11.CullMode.None);

            return(new SingleVisualObject(en.Tag, key));
        }
예제 #2
0
        public void LoadGameObject(IFileGeometry3D geo, FileInfo texture, string fileName)
        {
            var em = context.GetEntityManager();

            var box    = AxisAlignedBox.CreateFrom(geo.Positions);
            var center = box.Center;

            var c = (System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#B3B598");

            GraphicEntity en;

            if (geo.TextureCoors.Any())
            {
                en = EntityBuilders.BuildTextured(context, geo.Positions, geo.Indices,
                                                  geo.TextureCoors.ToArray(), texture,
                                                  SharpDX.Direct3D11.CullMode.None);
            }
            else
            {
                en = EntityBuilders.BuildColored(context, geo.Positions, geo.Indices, geo.Normals,
                                                 ToVector4(c), SharpDX.Direct3D11.CullMode.Front);
                en.UpdateComponent(FlatShadingGeometryComponent.Create());
            }
            en.UpdateComponent(TransformComponent.Create(Matrix4x4.CreateTranslation(Vector3.Zero - center)));
            GameObjects.Add(new SingleVisualObject(en.Tag, fileName));

            //var boxlines = PolylineGameObject.Create(
            //    Context,
            //    new ElementTag("poly"),
            //    GeometryBuilder.BuildBox(
            //        new AxisAlignedBox(box.Minimum, box.Maximum)),
            //    V4Colors.Blue
            //    );

            //Context.GetEntityManager().GetEntity(boxlines.Tag)
            //    .UpdateComponent(TransformComponent.Create(Matrix4x4.CreateTranslation(Vector3.Zero - center)));

            //GameObjects.Add(boxlines);
        }
예제 #3
0
        protected override void SceneInitialization(IContextState context, RenderEngine engine, ElementTag camera)
        {
            var smanager = Context.GetSystemManager();

            smanager.CreateSystem <DefaultInputSystem>();
            smanager.CreateSystem <ZoomToAllObjectsSystem>();
            smanager.CreateSystem <MovingSystem>();
            smanager.CreateSystem <CollidingSystem>();
            smanager.CreateSystem <DefaultOrthographicCameraSystem>();
            smanager.CreateSystem <LightsSystem>();

            smanager
            .CreateSystem <RenderSystem>()
            .Init(engine.Graphics)
            .CreateNested <StensilTest_TriangleColoredVertexRenderTechnique <ToolkitRenderProperties> >()
            .CreateNested <LineVertexRenderTechnique <ToolkitRenderProperties> >()
            ;

            var manager = Context.GetEntityManager();

            cameraObject = CameraObject.UpdateOrthographic <RenderSystem>(camera, Context, Surface);

            LightObject.CreateAmbientLight(manager, 0.2f);                                           //0.05f
            LightObject.CreateFollowCameraDirectLight(manager, System.Numerics.Vector3.UnitZ, 0.8f); //0.95f

            InvokeLoaded();

            {
                var pos0 = new[] {
                    new Vector3(0, 40, 0),
                    new Vector3(-30, -20, 0),
                    new Vector3(30, -20, 0),
                };
                var en0 = EntityBuilders.BuildColored(context, pos0,
                                                      new int[] { 0, 1, 2 }, new[] { Vector3.UnitZ, Vector3.UnitZ, Vector3.UnitZ },
                                                      V4Colors.Red, SharpDX.Direct3D11.CullMode.Front);

                var dd = D3DDepthStencilDefinition.Default(0).Description;
                //dd.DepthComparison = Comparison.LessEqual;

                var _default = new D3DDepthStencilDefinition(dd, 0);

                en0.UpdateComponent(RenderableComponent.AsTriangleColoredList(SharpDX.Direct3D11.CullMode.None, _default));
            }
            {
                var pos = new[] {
                    new Vector3(0, 20, 0),
                    new Vector3(-20, 0, 0),
                    new Vector3(20, 0, 0),
                };

                var en1 = EntityBuilders.BuildColored(context, pos,
                                                      new int[] { 0, 1, 2 }, new[] { Vector3.UnitZ, Vector3.UnitZ, Vector3.UnitZ },
                                                      V4Colors.Blue, SharpDX.Direct3D11.CullMode.Front);

                var dd = new DepthStencilStateDescription()
                {
                    IsDepthEnabled   = true,
                    IsStencilEnabled = true,
                    DepthWriteMask   = DepthWriteMask.All,
                    DepthComparison  = Comparison.LessEqual,
                    StencilWriteMask = 0xFF,
                    StencilReadMask  = 0xFF,
                    BackFace         = new DepthStencilOperationDescription()
                    {
                        PassOperation      = StencilOperation.Keep,
                        Comparison         = Comparison.Never,
                        DepthFailOperation = StencilOperation.Keep,
                        FailOperation      = StencilOperation.Replace
                    },
                    FrontFace = new DepthStencilOperationDescription()
                    {
                        PassOperation      = StencilOperation.Increment,
                        Comparison         = Comparison.Never,
                        DepthFailOperation = StencilOperation.Keep,
                        FailOperation      = StencilOperation.Replace
                    }
                };

                var stensilNever = new D3DDepthStencilDefinition(dd, 2);

                en1.UpdateComponent(RenderableComponent.AsTriangleColoredList(SharpDX.Direct3D11.CullMode.None, stensilNever));
            }
            {
                var pos2 = new[] {
                    new Vector3(20, 10, 0),
                    new Vector3(-20, 10, 0),
                    new Vector3(0, -10, 0),
                };
                var en2 = EntityBuilders.BuildColored(context, pos2,
                                                      new int[] { 0, 1, 2 }, new[] { Vector3.UnitZ, Vector3.UnitZ, Vector3.UnitZ },
                                                      V4Colors.Green, SharpDX.Direct3D11.CullMode.Front);

                var ddd = new DepthStencilStateDescription()
                {
                    IsDepthEnabled   = true,
                    IsStencilEnabled = true,
                    DepthWriteMask   = DepthWriteMask.All,
                    DepthComparison  = Comparison.LessEqual,
                    StencilWriteMask = 0xFF,
                    StencilReadMask  = 0xFF,
                    BackFace         = new DepthStencilOperationDescription()
                    {
                        PassOperation      = StencilOperation.Replace,
                        Comparison         = Comparison.Greater,
                        DepthFailOperation = StencilOperation.Keep,
                        FailOperation      = StencilOperation.Replace
                    },
                    FrontFace = new DepthStencilOperationDescription()
                    {
                        PassOperation      = StencilOperation.Increment,
                        Comparison         = Comparison.Greater,
                        DepthFailOperation = StencilOperation.Keep,
                        FailOperation      = StencilOperation.Replace
                    }
                };

                var stensilGrater = new D3DDepthStencilDefinition(ddd, 1);

                en2.UpdateComponent(RenderableComponent.AsTriangleColoredList(SharpDX.Direct3D11.CullMode.None, stensilGrater));
            }
        }