コード例 #1
0
        /// <summary>
        /// Render the item icons
        /// </summary>
        /// <param name="graphics"></param>
        /// <param name="matrix"></param>
        /// <param name="renderOrigin"></param>
        /// <param name="avatar"></param>
        /// <param name="avatarPainter"></param>
        /// <param name="universe"></param>
        public void DrawItemVoxels(DeviceContext graphics, Matrix4F matrix, Entity avatar)
        {
            if (!this.IsShowing)
            {
                return;
            }

            graphics.PushRenderState();
            Matrix4F projectionMatrix = graphics.GetProjectionMatrix();
            Matrix4F overlayMatrix    = graphics.GetOverlayMatrix();

            graphics.PushShader();
            graphics.SetShader(graphics.GetShader("VoxelOverlayStipple"));

            double rotation    = ClientContext.OverlayController.IsMenuOpen() ? 0 : (DateTime.UtcNow - new DateTime(0L)).TotalMilliseconds * 0.001 % 6.2831853071795862;
            int    activeIndex = avatar.Inventory.ActiveItemIndex();

            for (int i = 0; i < 10; i++)
            {
                ItemStack item = avatar.Inventory.GetHotbarItem(i);
                if (item.Item != Item.NullItem)
                {
                    Vector2F p = HotbarManager.Instance.Controller.GetSlotPosition(i);
                    p *= Constants.UIZoomFactor;

                    Vector2F pp           = graphics.ScreenPosToProjectionPos(p);
                    Matrix4F movedMatrix2 = Matrix4F.CreateTranslation(new Vector3F(pp.X, pp.Y, 0f));
                    movedMatrix2 = Matrix4F.Multiply(overlayMatrix, movedMatrix2);
                    graphics.SetProjectionMatrix(movedMatrix2);

                    Vector2I viewPortSize = graphics.GetViewPortSize();
                    float    itemScale    = Constants.ItemRenderingScale;
                    itemScale *= Constants.UIZoomFactor / ((float)viewPortSize.Y / Constants.ViewPortScaleThreshold.Y);

                    if (i == activeIndex)
                    {
                        graphics.SetShader(graphics.GetShader("VoxelOverlay"));
                    }

                    ClientContext.ItemRendererManager.RenderIcon(item.Item, graphics, Matrix4F.CreateScale(itemScale).Rotate((float)rotation, Vector3F.Up).Rotate(-0.35f, Vector3F.Left)
                                                                 .Translate(new Vector3F(0f, 0f, -0.2f))
                                                                 .Multiply(matrix));

                    if (i == activeIndex)
                    {
                        graphics.SetShader(graphics.GetShader("VoxelOverlayStipple"));
                    }
                }
            }

            graphics.PopShader();
            graphics.SetProjectionMatrix(projectionMatrix);
            graphics.PopRenderState();
        }