public override void Initialize()
 {
     base.Initialize();
      renderComponent = Entity.GetComponent<RenderComponent>();
      renderComponent.IsCustomRendered = true;
      renderComponent.Render += HandleRender;
 }
Пример #2
0
        /// <summary>
        /// Renders a renderable components and applies its required renderstate if necessary.
        /// </summary>
        void Render(ICamera camera, RenderComponent renderable) {
            RenderState desiredState = renderable.RenderState;

            if (desiredState != null) {
                if (_currentlyEnabledState != desiredState) {
                    if (_currentlyEnabledState != null) {
                        _currentlyEnabledState(false);
                    }

                    desiredState(true);

                    _currentlyEnabledState = desiredState;
                }
            }

            renderable.Render(camera);
        }
Пример #3
0
        public void RenderEntity(Entity entity, RenderComponent renderComponent)
        {
            if (!renderComponent.IsVisible) {
            return;
             }

             if (renderComponent.IsCustomRendered) {
            renderComponent.HandleOnRender(
               new RenderEventArgs {
                  Renderer = this,
                  GraphicsDevice = graphicsDevice,
                  BasicEffect = basicEffect
               }
            );
             } else {
            var positionComponent = entity.GetComponent<PositionComponent>();
            var sizeComponent = entity.GetComponent<SizeComponent>();
            var orientationComponent = entity.GetComponent<OrientationComponent>();
            var boundsComponent = entity.GetComponent<BoundsComponent>();
            var colorComponent = entity.GetComponent<ColorComponent>();
            var commandQueueComponent = entity.GetComponentOrNull<CommandQueueComponent>();
            var zNudge = Vector3.Zero;
            if (sizeComponent.PositioningMode == VerticalPositioningMode.PositionBottom) {
               zNudge.Z = 0.5f;
            }

            var worldMatrix = Matrix.Translation(zNudge) *
                              Matrix.Scaling(sizeComponent.Size) *
                              Matrix.RotationQuaternion(orientationComponent.Orientation) *
                              Matrix.Translation(positionComponent.Position);

            DrawCube(worldMatrix, colorComponent.Color, false);
            DrawOrientedBoundingBox(boundsComponent.Bounds, new Vector4(1, 1, 1, 1));

            if (commandQueueComponent != null) {
               var pathingCommand = commandQueueComponent.CurrentCommand as PathingCommand;
               if (pathingCommand != null) {
                  var points = pathingCommand.Path.Points;
                  for (var i = 0 ; i < points.Length - 1; i++) {
                     DrawDebugLine(points[i], points[i + 1], Color.Cyan);
                  }
               }
            }
             }
        }
        public static RenderComponent CreateComponent()
        {
            RenderComponent component = new RenderComponent();

            return component;
        }