Example #1
0
		public override void onAddedToEntity()
		{
			_spriteRenderer = entity.getComponent<RenderableComponent>();
			originalColor = _spriteRenderer.color;
			originalIntensity = originalColor.A;
		}
 public void setTarget(RenderableComponent renderable)
 {
     _renderable = renderable;
 }
Example #3
0
 public void RegisterRenderableComponent(RenderableComponent component)
 {
     RenderableComponents.Add(component);
 }
Example #4
0
 public static ITween <Vector2> tweenLocalOffset(this RenderableComponent self, Vector2 to, float dur, EaseType ease = EaseType.Linear)
 {
     return(self.Tween("LocalOffset", to, dur).SetEaseType(ease));
 }
Example #5
0
 public static RenderableComponent setColorW(this RenderableComponent self, float opacity)
 {
     return(self.SetColor(Color.White * opacity));
 }
Example #6
0
 public static ITween <Color> tweenColorW(this RenderableComponent self, float opacity, float dur, EaseType ease = EaseType.Linear)
 {
     return(self.TweenColorTo(Color.White * opacity, dur));
 }
Example #7
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));
            }
        }
Example #8
0
        public static VisualPolylineObject CreateBox(IContextState context, ElementTag tag, AxisAlignedBox box, Vector4 color)
        {
            var indeces = new List <int>();
            var pos     = new List <Vector3>();

            var xbox = box.GetCornersBox();

            var NearBottomLeft  = xbox.NearBottomLeft;
            var NearBottomRight = xbox.NearBottomRight;
            var NearTopLeft     = xbox.NearTopLeft;
            var NearTopRight    = xbox.NearTopRight;

            var FarBottomLeft  = xbox.FarBottomLeft;
            var FarBottomRight = xbox.FarBottomRight;
            var FarTopLeft     = xbox.FarTopLeft;
            var FarTopRight    = xbox.FarTopRight;

            //top
            pos.Add(NearBottomLeft);
            pos.Add(NearBottomRight);

            pos.Add(NearBottomRight);
            pos.Add(NearTopRight);

            pos.Add(NearTopRight);
            pos.Add(NearTopLeft);

            pos.Add(NearTopLeft);
            pos.Add(NearBottomLeft);
            //side
            pos.Add(NearBottomLeft);
            pos.Add(FarBottomLeft);

            pos.Add(NearBottomRight);
            pos.Add(FarBottomRight);

            pos.Add(NearTopRight);
            pos.Add(FarTopRight);

            pos.Add(NearTopLeft);
            pos.Add(FarTopLeft);
            //bottom

            pos.Add(FarBottomLeft);
            pos.Add(FarBottomRight);

            pos.Add(FarBottomRight);
            pos.Add(FarTopRight);

            pos.Add(FarTopRight);
            pos.Add(FarTopLeft);

            pos.Add(FarTopLeft);
            pos.Add(FarBottomLeft);

            for (var i = 0; i < pos.Count; i++)
            {
                indeces.AddRange(new[] { i, i });
            }

            var manager = context.GetEntityManager();

            var geo = context.GetGeometryPool()
                      .AddGeometry(new ImmutableGeometryData(pos.ToArray(), indeces.ToArray()));

            manager
            .CreateEntity(tag)
            .AddComponent(geo)
            .AddComponent(TransformComponent.Identity())
            .AddComponent(ColorComponent.CreateDiffuse(color))
            .AddComponent(RenderableComponent.AsLineList());

            return(new VisualPolylineObject(tag));
        }