Beispiel #1
0
        public override void Update(float dt)
        {
            dt = MathUtils.Min(dt, 0.1f);
            Vector3 zero = Vector3.Zero;

            if (Keyboard.IsKeyDown(Key.A))
            {
                zero.X = -1f;
            }
            if (Keyboard.IsKeyDown(Key.D))
            {
                zero.X = 1f;
            }
            if (Keyboard.IsKeyDown(Key.W))
            {
                zero.Z = 1f;
            }
            if (Keyboard.IsKeyDown(Key.S))
            {
                zero.Z = -1f;
            }
            Vector2 vector    = 0.03f * new Vector2(Mouse.MouseMovement.X, -Mouse.MouseMovement.Y);
            bool    num       = Keyboard.IsKeyDown(Key.Shift);
            bool    flag      = Keyboard.IsKeyDown(Key.Control);
            Vector3 direction = m_direction;
            Vector3 unitY     = Vector3.UnitY;
            Vector3 vector2   = Vector3.Normalize(Vector3.Cross(direction, unitY));
            float   num2      = 8f;

            if (num)
            {
                num2 *= 10f;
            }
            if (flag)
            {
                num2 /= 10f;
            }
            Vector3 zero2 = Vector3.Zero;

            zero2      += num2 * zero.X * vector2;
            zero2      += num2 * zero.Y * unitY;
            zero2      += num2 * zero.Z * direction;
            m_position += zero2 * dt;
            m_direction = Vector3.Transform(m_direction, Matrix.CreateFromAxisAngle(unitY, -4f * vector.X * dt));
            m_direction = Vector3.Transform(m_direction, Matrix.CreateFromAxisAngle(vector2, 4f * vector.Y * dt));
            SetupPerspectiveCamera(m_position, m_direction, Vector3.UnitY);
            Vector2     v           = ViewportSize / 2f;
            FlatBatch2D flatBatch2D = PrimitivesRenderer2D.FlatBatch(0, DepthStencilState.None);
            int         count       = flatBatch2D.LineVertices.Count;

            flatBatch2D.QueueLine(v - new Vector2(5f, 0f), v + new Vector2(5f, 0f), 0f, Color.White);
            flatBatch2D.QueueLine(v - new Vector2(0f, 5f), v + new Vector2(0f, 5f), 0f, Color.White);
            flatBatch2D.TransformLines(ViewportMatrix, count);
            PrimitivesRenderer2D.Flush();
        }
        public static void Draw()
        {
            Vector2  scale    = new Vector2(MathUtils.Round(MathUtils.Clamp(ScreensManager.RootWidget.GlobalScale, 1f, 4f)));
            Viewport viewport = Display.Viewport;

            if (SettingsManager.DisplayFpsCounter)
            {
                if (Time.PeriodicEvent(1.0, 0.0))
                {
                    m_statsString = $"CPUMEM {(float)TotalMemoryUsed / 1024f / 1024f:0}MB, GPUMEM {(float)TotalGpuMemoryUsed / 1024f / 1024f:0}MB, CPU {AverageCpuFrameTime / AverageFrameTime * 100f:0}%, FPS {1f / AverageFrameTime:0.0}";
                }
                m_primitivesRenderer.FontBatch(BitmapFont.DebugFont, 0, null, null, null, SamplerState.PointClamp).QueueText(m_statsString, new Vector2(viewport.Width, 0f), 0f, Color.White, TextAnchor.Right, scale, Vector2.Zero);
            }
            if (SettingsManager.DisplayFpsRibbon)
            {
                float num  = ((float)viewport.Width / scale.X > 480f) ? (scale.X * 2f) : scale.X;
                float num2 = (float)viewport.Height / -0.1f;
                float num3 = viewport.Height - 1;
                float s    = 0.5f;
                int   num4 = MathUtils.Max((int)((float)viewport.Width / num), 1);
                if (m_frameData == null || m_frameData.Length != num4)
                {
                    m_frameData      = new FrameData[num4];
                    m_frameDataIndex = 0;
                }
                m_frameData[m_frameDataIndex] = new FrameData
                {
                    CpuTime   = Program.LastCpuFrameTime,
                    TotalTime = Program.LastFrameTime
                };
                m_frameDataIndex = (m_frameDataIndex + 1) % m_frameData.Length;
                FlatBatch2D flatBatch2D = m_primitivesRenderer.FlatBatch();
                Color       color       = Color.Orange * s;
                Color       color2      = Color.Red * s;
                for (int num5 = m_frameData.Length - 1; num5 >= 0; num5--)
                {
                    int       num6      = (num5 - m_frameData.Length + 1 + m_frameDataIndex + m_frameData.Length) % m_frameData.Length;
                    FrameData frameData = m_frameData[num6];
                    float     x         = (float)num5 * num;
                    float     x2        = (float)(num5 + 1) * num;
                    flatBatch2D.QueueQuad(new Vector2(x, num3), new Vector2(x2, num3 + frameData.CpuTime * num2), 0f, color);
                    flatBatch2D.QueueQuad(new Vector2(x, num3 + frameData.CpuTime * num2), new Vector2(x2, num3 + frameData.TotalTime * num2), 0f, color2);
                }
                flatBatch2D.QueueLine(new Vector2(0f, num3 + 0.0166666675f * num2), new Vector2(viewport.Width, num3 + 0.0166666675f * num2), 0f, Color.Green);
            }
            else
            {
                m_frameData = null;
            }
            m_primitivesRenderer.Flush();
        }
Beispiel #3
0
        public override void Draw(DrawContext dc)
        {
            if (FillColor.A == 0 && (OutlineColor.A == 0 || OutlineThickness <= 0f))
            {
                return;
            }
            DepthStencilState depthStencilState = DepthWriteEnabled ? DepthStencilState.DepthWrite : DepthStencilState.None;
            Matrix            m  = base.GlobalTransform;
            Vector2           v  = Vector2.Zero;
            Vector2           v2 = new Vector2(base.ActualSize.X, 0f);
            Vector2           v3 = base.ActualSize;
            Vector2           v4 = new Vector2(0f, base.ActualSize.Y);

            Vector2.Transform(ref v, ref m, out Vector2 result);
            Vector2.Transform(ref v2, ref m, out Vector2 result2);
            Vector2.Transform(ref v3, ref m, out Vector2 result3);
            Vector2.Transform(ref v4, ref m, out Vector2 result4);
            Color color = FillColor * base.GlobalColorTransform;

            if (color.A != 0)
            {
                if (Subtexture != null)
                {
                    SamplerState    samplerState    = (!TextureWrap) ? (TextureLinearFilter ? SamplerState.LinearClamp : SamplerState.PointClamp) : (TextureLinearFilter ? SamplerState.LinearWrap : SamplerState.PointWrap);
                    TexturedBatch2D texturedBatch2D = dc.PrimitivesRenderer2D.TexturedBatch(Subtexture.Texture, useAlphaTest: false, 0, depthStencilState, null, null, samplerState);
                    Vector2         zero            = default(Vector2);
                    Vector2         texCoord;
                    Vector2         texCoord2 = default(Vector2);
                    Vector2         texCoord3;
                    if (TextureWrap)
                    {
                        zero      = Vector2.Zero;
                        texCoord  = new Vector2(base.ActualSize.X / (float)Subtexture.Texture.Width, 0f);
                        texCoord2 = new Vector2(base.ActualSize.X / (float)Subtexture.Texture.Width, base.ActualSize.Y / (float)Subtexture.Texture.Height);
                        texCoord3 = new Vector2(0f, base.ActualSize.Y / (float)Subtexture.Texture.Height);
                    }
                    else
                    {
                        zero.X      = MathUtils.Lerp(Subtexture.TopLeft.X, Subtexture.BottomRight.X, Texcoord1.X);
                        zero.Y      = MathUtils.Lerp(Subtexture.TopLeft.Y, Subtexture.BottomRight.Y, Texcoord1.Y);
                        texCoord2.X = MathUtils.Lerp(Subtexture.TopLeft.X, Subtexture.BottomRight.X, Texcoord2.X);
                        texCoord2.Y = MathUtils.Lerp(Subtexture.TopLeft.Y, Subtexture.BottomRight.Y, Texcoord2.Y);
                        texCoord    = new Vector2(texCoord2.X, zero.Y);
                        texCoord3   = new Vector2(zero.X, texCoord2.Y);
                    }
                    if (FlipHorizontal)
                    {
                        Utilities.Swap(ref zero.X, ref texCoord.X);
                        Utilities.Swap(ref texCoord2.X, ref texCoord3.X);
                    }
                    if (FlipVertical)
                    {
                        Utilities.Swap(ref zero.Y, ref texCoord2.Y);
                        Utilities.Swap(ref texCoord.Y, ref texCoord3.Y);
                    }
                    texturedBatch2D.QueueQuad(result, result2, result3, result4, Depth, zero, texCoord, texCoord2, texCoord3, color);
                }
                else
                {
                    dc.PrimitivesRenderer2D.FlatBatch(1, depthStencilState).QueueQuad(result, result2, result3, result4, Depth, color);
                }
            }
            Color color2 = OutlineColor * base.GlobalColorTransform;

            if (color2.A != 0 && OutlineThickness > 0f)
            {
                FlatBatch2D flatBatch2D = dc.PrimitivesRenderer2D.FlatBatch(1, depthStencilState);
                Vector2     vector      = Vector2.Normalize(base.GlobalTransform.Right.XY);
                Vector2     v5          = -Vector2.Normalize(base.GlobalTransform.Up.XY);
                int         num         = (int)MathUtils.Max(MathUtils.Round(OutlineThickness * base.GlobalTransform.Right.Length()), 1f);
                for (int i = 0; i < num; i++)
                {
                    flatBatch2D.QueueLine(result, result2, Depth, color2);
                    flatBatch2D.QueueLine(result2, result3, Depth, color2);
                    flatBatch2D.QueueLine(result3, result4, Depth, color2);
                    flatBatch2D.QueueLine(result4, result, Depth, color2);
                    result  += vector - v5;
                    result2 += -vector - v5;
                    result3 += -vector + v5;
                    result4 += vector + v5;
                }
            }
        }
        public override void Draw(DrawContext dc)
        {
            if (Design == null)
            {
                return;
            }
            Matrix matrix;

            if (Mode == ViewMode.Perspective)
            {
                Viewport viewport = Display.Viewport;
                Vector3  vector   = new Vector3(0.5f, 0.5f, 0.5f);
                Matrix   m        = Matrix.CreateLookAt(2.65f * m_direction + vector, vector, Vector3.UnitY);
                Matrix   m2       = Matrix.CreatePerspectiveFieldOfView(1.2f, base.ActualSize.X / base.ActualSize.Y, 0.4f, 4f);
                Matrix   m3       = MatrixUtils.CreateScaleTranslation(base.ActualSize.X, 0f - base.ActualSize.Y, base.ActualSize.X / 2f, base.ActualSize.Y / 2f) * base.GlobalTransform * MatrixUtils.CreateScaleTranslation(2f / (float)viewport.Width, -2f / (float)viewport.Height, -1f, 1f);
                matrix = m * m2 * m3;
                FlatBatch3D flatBatch3D = m_primitivesRenderer3d.FlatBatch(1, DepthStencilState.DepthRead);
                for (int i = 0; i <= Design.Resolution; i++)
                {
                    float num   = (float)i / (float)Design.Resolution;
                    Color color = (i % 2 == 0) ? new Color(56, 56, 56, 56) : new Color(28, 28, 28, 28);
                    color *= base.GlobalColorTransform;
                    flatBatch3D.QueueLine(new Vector3(num, 0f, 0f), new Vector3(num, 0f, 1f), color);
                    flatBatch3D.QueueLine(new Vector3(0f, 0f, num), new Vector3(1f, 0f, num), color);
                    flatBatch3D.QueueLine(new Vector3(0f, num, 0f), new Vector3(0f, num, 1f), color);
                    flatBatch3D.QueueLine(new Vector3(0f, 0f, num), new Vector3(0f, 1f, num), color);
                    flatBatch3D.QueueLine(new Vector3(0f, num, 1f), new Vector3(1f, num, 1f), color);
                    flatBatch3D.QueueLine(new Vector3(num, 0f, 1f), new Vector3(num, 1f, 1f), color);
                }
                Color       color2      = new Color(64, 64, 64, 255) * base.GlobalColorTransform;
                FontBatch3D fontBatch3D = m_primitivesRenderer3d.FontBatch(ContentManager.Get <BitmapFont>("Fonts/Pericles"), 1);
                fontBatch3D.QueueText("Front", new Vector3(0.5f, 0f, 0f), 0.004f * new Vector3(-1f, 0f, 0f), 0.004f * new Vector3(0f, 0f, -1f), color2, TextAnchor.HorizontalCenter);
                fontBatch3D.QueueText("Side", new Vector3(1f, 0f, 0.5f), 0.004f * new Vector3(0f, 0f, -1f), 0.004f * new Vector3(1f, 0f, 0f), color2, TextAnchor.HorizontalCenter);
                if (DrawDebugFurniture)
                {
                    DebugDraw();
                }
            }
            else
            {
                Vector3 position;
                Vector3 up;
                if (Mode == ViewMode.Side)
                {
                    position = new Vector3(1f, 0f, 0f);
                    up       = new Vector3(0f, 1f, 0f);
                }
                else if (Mode != ViewMode.Top)
                {
                    position = new Vector3(0f, 0f, -1f);
                    up       = new Vector3(0f, 1f, 0f);
                }
                else
                {
                    position = new Vector3(0f, 1f, 0f);
                    up       = new Vector3(0f, 0f, 1f);
                }
                Viewport viewport2 = Display.Viewport;
                float    num2      = MathUtils.Min(base.ActualSize.X, base.ActualSize.Y);
                Matrix   m4        = Matrix.CreateLookAt(position, new Vector3(0f, 0f, 0f), up);
                Matrix   m5        = Matrix.CreateOrthographic(2f, 2f, -10f, 10f);
                Matrix   m6        = MatrixUtils.CreateScaleTranslation(num2, 0f - num2, base.ActualSize.X / 2f, base.ActualSize.Y / 2f) * base.GlobalTransform * MatrixUtils.CreateScaleTranslation(2f / (float)viewport2.Width, -2f / (float)viewport2.Height, -1f, 1f);
                matrix = Matrix.CreateTranslation(-0.5f, -0.5f, -0.5f) * m4 * m5 * m6;
                FlatBatch2D flatBatch2D = m_primitivesRenderer2d.FlatBatch();
                Matrix      m7          = base.GlobalTransform;
                for (int j = 1; j < Design.Resolution; j++)
                {
                    float   num3 = (float)j / (float)Design.Resolution;
                    Vector2 v    = new Vector2(base.ActualSize.X * num3, 0f);
                    Vector2 v2   = new Vector2(base.ActualSize.X * num3, base.ActualSize.Y);
                    Vector2 v3   = new Vector2(0f, base.ActualSize.Y * num3);
                    Vector2 v4   = new Vector2(base.ActualSize.X, base.ActualSize.Y * num3);
                    Vector2.Transform(ref v, ref m7, out v);
                    Vector2.Transform(ref v2, ref m7, out v2);
                    Vector2.Transform(ref v3, ref m7, out v3);
                    Vector2.Transform(ref v4, ref m7, out v4);
                    Color color3 = (j % 2 == 0) ? new Color(0, 0, 0, 56) : new Color(0, 0, 0, 28);
                    Color color4 = (j % 2 == 0) ? new Color(56, 56, 56, 56) : new Color(28, 28, 28, 28);
                    color3 *= base.GlobalColorTransform;
                    color4 *= base.GlobalColorTransform;
                    flatBatch2D.QueueLine(v, v2, 0f, (j % 2 == 0) ? color3 : (color3 * 0.75f));
                    flatBatch2D.QueueLine(v + new Vector2(1f, 0f), v2 + new Vector2(1f, 0f), 0f, color4);
                    flatBatch2D.QueueLine(v3, v4, 0f, color3);
                    flatBatch2D.QueueLine(v3 + new Vector2(0f, 1f), v4 + new Vector2(0f, 1f), 0f, color4);
                }
            }
            Matrix            matrix2  = Matrix.Identity;
            FurnitureGeometry geometry = Design.Geometry;

            for (int k = 0; k < 6; k++)
            {
                Color globalColorTransform = base.GlobalColorTransform;
                if (Mode == ViewMode.Perspective)
                {
                    float num4 = LightingManager.LightIntensityByLightValueAndFace[15 + 16 * CellFace.OppositeFace(k)];
                    globalColorTransform *= new Color(num4, num4, num4);
                }
                if (geometry.SubsetOpaqueByFace[k] != null)
                {
                    BlocksManager.DrawMeshBlock(m_primitivesRenderer3d, geometry.SubsetOpaqueByFace[k], globalColorTransform, 1f, ref matrix2, null);
                }
                if (geometry.SubsetAlphaTestByFace[k] != null)
                {
                    BlocksManager.DrawMeshBlock(m_primitivesRenderer3d, geometry.SubsetAlphaTestByFace[k], globalColorTransform, 1f, ref matrix2, null);
                }
            }
            m_primitivesRenderer3d.Flush(matrix);
            m_primitivesRenderer2d.Flush();
        }