Ejemplo n.º 1
0
        internal override void recalculateBounds(Collider collider)
        {
            // if we dont have rotation or dont care about TRS we use localOffset as the center so we'll start with that
            center = collider.localOffset;

            if (collider.shouldColliderScaleAndRotateWithTransform)
            {
                var      hasUnitScale = true;
                Matrix2D tempMat;
                var      combinedMatrix = Matrix2D.CreateTranslation(-_polygonCenter);

                if (collider.entity.transform.scale != Vector2.One)
                {
                    Matrix2D.CreateScale(collider.entity.transform.scale.X, collider.entity.transform.scale.Y, out tempMat);
                    Matrix2D.Multiply(ref combinedMatrix, ref tempMat, out combinedMatrix);

                    hasUnitScale = false;
                    // scale our offset and set it as center. If we have rotation also it will be reset below
                    var scaledOffset = collider.localOffset * collider.entity.transform.scale;
                    center = scaledOffset;
                }

                if (collider.entity.transform.rotation != 0)
                {
                    Matrix2D.CreateRotationZ(collider.entity.transform.rotation, out tempMat);
                    Matrix2D.Multiply(ref combinedMatrix, ref tempMat, out combinedMatrix);

                    // to deal with rotation with an offset origin we just move our center in a circle around 0,0 with our offset making the 0 angle
                    // we have to deal with scale here as well so we scale our offset to get the proper length first.
                    var offsetAngle  = Mathf.atan2(collider.localOffset.Y, collider.localOffset.X) * Mathf.rad2Deg;
                    var offsetLength = hasUnitScale ? collider._localOffsetLength : (collider.localOffset * collider.entity.transform.scale).Length();
                    center = Mathf.pointOnCircle(Vector2.Zero, offsetLength, collider.entity.transform.rotationDegrees + offsetAngle);
                }

                Matrix2D.CreateTranslation(ref _polygonCenter, out tempMat);                   // translate back center
                Matrix2D.Multiply(ref combinedMatrix, ref tempMat, out combinedMatrix);

                // finaly transform our original points
                Vector2Ext.Transform(_originalPoints, ref combinedMatrix, points);

                isUnrotated = collider.entity.transform.rotation == 0;

                // we only need to rebuild our edge normals if we rotated
                if (collider._isRotationDirty)
                {
                    _areEdgeNormalsDirty = true;
                }
            }

            position         = collider.entity.transform.position + center;
            bounds           = RectangleF.rectEncompassingPoints(points);
            bounds.location += position;
        }
 private void RecalculateLocalMatrix(out Matrix2D matrix)
 {
     if (Parent != null)
     {
         var parentPosition = Parent.Position;
         matrix = Matrix2D.CreateTranslation(-parentPosition) * Matrix2D.CreateScale(_scale) *
                  Matrix2D.CreateRotationZ(-_rotation) * Matrix2D.CreateTranslation(parentPosition) *
                  Matrix2D.CreateTranslation(_position);
     }
     else
     {
         matrix = Matrix2D.CreateScale(_scale) * Matrix2D.CreateRotationZ(-_rotation) *
                  Matrix2D.CreateTranslation(_position);
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Returns the transform for this group's coordinate system
        /// </summary>
        /// <returns>The transform.</returns>
        protected Matrix2D computeTransform()
        {
            var mat = Matrix2D.Identity;

            if (originX != 0 || originY != 0)
            {
                mat = Matrix2D.Multiply(mat, Matrix2D.CreateTranslation(-originX, -originY, 0));
            }

            if (rotation != 0)
            {
                mat = Matrix2D.Multiply(mat, Matrix2D.CreateRotationZ(MathHelper.ToRadians(rotation)));
            }

            if (scaleX != 1 || scaleY != 1)
            {
                mat = Matrix2D.Multiply(mat, Matrix2D.CreateScale(scaleX, scaleY));
            }

            mat = Matrix2D.Multiply(mat, Matrix2D.CreateTranslation(x + originX, y + originY, 0));

            // Find the first parent that transforms
            Group parentGroup = parent;

            while (parentGroup != null)
            {
                if (parentGroup.transform)
                {
                    break;
                }
                parentGroup = parentGroup.parent;
            }

            if (parentGroup != null)
            {
                mat = Matrix2D.Multiply(mat, parentGroup.computeTransform());
            }

            return(mat);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// old SpriteBatch drawing method. This should probably be removed since SpriteBatch was replaced by Batcher
        /// </summary>
        /// <param name="spriteBatch">Sprite batch.</param>
        /// <param name="text">Text.</param>
        /// <param name="position">Position.</param>
        /// <param name="color">Color.</param>
        /// <param name="rotation">Rotation.</param>
        /// <param name="origin">Origin.</param>
        /// <param name="scale">Scale.</param>
        /// <param name="effect">Effect.</param>
        /// <param name="depth">Depth.</param>
        internal void drawInto(SpriteBatch spriteBatch, ref FontCharacterSource text, Vector2 position, Color color,
                               float rotation, Vector2 origin, Vector2 scale, SpriteEffects effect, float depth)
        {
            var flipAdjustment = Vector2.Zero;

            var flippedVert = (effect & SpriteEffects.FlipVertically) == SpriteEffects.FlipVertically;
            var flippedHorz = (effect & SpriteEffects.FlipHorizontally) == SpriteEffects.FlipHorizontally;

            if (flippedVert || flippedHorz)
            {
                Vector2 size;
                measureString(ref text, out size);

                if (flippedHorz)
                {
                    origin.X        *= -1;
                    flipAdjustment.X = -size.X;
                }

                if (flippedVert)
                {
                    origin.Y        *= -1;
                    flipAdjustment.Y = lineHeight - size.Y;
                }
            }


            var requiresTransformation = flippedHorz || flippedVert || rotation != 0f || scale != Vector2.One;

            if (requiresTransformation)
            {
                Matrix2D temp;
                Matrix2D.CreateTranslation(-origin.X, -origin.Y, out _transformationMatrix);
                Matrix2D.CreateScale((flippedHorz ? -scale.X : scale.X), (flippedVert ? -scale.Y : scale.Y), out temp);
                Matrix2D.Multiply(ref _transformationMatrix, ref temp, out _transformationMatrix);
                Matrix2D.CreateTranslation(flipAdjustment.X, flipAdjustment.Y, out temp);
                Matrix2D.Multiply(ref temp, ref _transformationMatrix, out _transformationMatrix);
                Matrix2D.CreateRotationZ(rotation, out temp);
                Matrix2D.Multiply(ref _transformationMatrix, ref temp, out _transformationMatrix);
                Matrix2D.CreateTranslation(position.X, position.Y, out temp);
                Matrix2D.Multiply(ref _transformationMatrix, ref temp, out _transformationMatrix);
            }

            BitmapFontRegion currentFontRegion = null;
            var offset = requiresTransformation ? Vector2.Zero : position - origin;

            for (var i = 0; i < text.Length; ++i)
            {
                var c = text[i];
                if (c == '\r')
                {
                    continue;
                }

                if (c == '\n')
                {
                    offset.X          = requiresTransformation ? 0f : position.X - origin.X;
                    offset.Y         += lineHeight;
                    currentFontRegion = null;
                    continue;
                }

                if (currentFontRegion != null)
                {
                    offset.X += spacing + currentFontRegion.xAdvance;
                }

                if (!_characterMap.TryGetValue(c, out currentFontRegion))
                {
                    currentFontRegion = defaultCharacterRegion;
                }


                var p = offset;

                if (flippedHorz)
                {
                    p.X += currentFontRegion.width;
                }
                p.X += currentFontRegion.xOffset;

                if (flippedVert)
                {
                    p.Y += currentFontRegion.height - lineHeight;
                }
                p.Y += currentFontRegion.yOffset;

                // transform our point if we need to
                if (requiresTransformation)
                {
                    Vector2Ext.Transform(ref p, ref _transformationMatrix, out p);
                }

                var destRect = RectangleExt.fromFloats
                               (
                    p.X, p.Y,
                    currentFontRegion.width * scale.X,
                    currentFontRegion.height * scale.Y
                               );

                spriteBatch.Draw(currentFontRegion.subtexture, destRect, currentFontRegion.subtexture.sourceRect, color, rotation, Vector2.Zero, effect, depth);
            }
        }
 private void RecalculateLocalMatrix(out Matrix2D matrix)
 {
     matrix = Matrix2D.CreateScale(_scale) *
              Matrix2D.CreateRotationZ(_rotation) *
              Matrix2D.CreateTranslation(_position);
 }
Ejemplo n.º 6
0
        public override void Draw()
        {
            surface.Bind();

            // Clear the screen
            if (Input.Keyboard.Down(KeyCode.Space))
            {
                Graphics.Clear(1d);
            }
            else
            {
                Graphics.Clear(Colour.Black);
            }

            Graphics.State.Reset();
            CullModeState.Set(cullModeState);
            DepthState.LessEqual.Set();
            PolygonModeState.Set(polygonModeState);

            if (Input.Mouse.RightDown)
            {
                Shaders.RendererFog.Bind();
                Shaders.RendererFog.MVP     = Camera.Matrix;
                Shaders.RendererFog.MV      = Camera.ViewMatrix;
                Shaders.RendererFog.FogType = InternalShaders.FogType.Linear;
                //Shaders.RendererFog.FogDensity = 0.013f;
                Shaders.RendererFog.FogColour = Colour.Black;
                Shaders.RendererFog.FogStart  = Camera.zNear;
                Shaders.RendererFog.FogEnd    = Camera.zFar;
            }
            else
            {
                Shaders.Renderer.Bind();
                Shaders.Renderer.MVP = Camera.Matrix;
            }

            Renderer.Draw.ResetTransform();
            Renderer.Draw3D.ResetTransform();

            // Start Drawing

            Renderer.Draw3D.SetTransform(test);
            Renderer.Draw3D.Cube(Colour.Cyan,
                                 Colour.Yellow,
                                 Colour.Red,
                                 Colour.Blue,
                                 Colour.Green,
                                 Colour.Magenta);
            Renderer.Draw3D.ResetTransform();

            Renderer.Draw3D.SetTransform(test2);
            Colour c2 = new Colour(Math.CosNormalized(Time.TotalSeconds * 1.5f), Math.CosNormalized(Time.TotalSeconds * 1.4f), Math.CosNormalized(Time.TotalSeconds * 1.3f), 1f);

            Renderer.Draw3D.CubeWireframe(c2);
            Renderer.Draw3D.ResetTransform();

            Renderer.Draw3D.SetTransform(test3);
            Renderer.Draw3D.Cube(new Colour(0f, 0f, 0f, 1f),
                                 new Colour(1f, 0f, 0f, 1f),
                                 new Colour(0f, 1f, 0f, 1f),
                                 new Colour(1f, 1f, 0f, 1f),
                                 new Colour(0f, 0f, 1f, 1f),
                                 new Colour(1f, 0f, 1f, 1f),
                                 new Colour(0f, 1f, 1f, 1f),
                                 new Colour(1f, 1f, 1f, 1f));
            Renderer.Draw3D.ResetTransform();

            Transform cubeGridTransformParent = new Transform();

            cubeGridTransformParent.Position = new Vector3(80, 0, 80);
            for (int x = 0; x < 5; x++)
            {
                for (int y = 0; y < 5; y++)
                {
                    for (int z = 0; z < 5; z++)
                    {
                        Transform cubeGridTransform = new Transform();
                        cubeGridTransform.Parent   = cubeGridTransformParent;
                        cubeGridTransform.Position = new Vector3(x * 6, y * 6, z * 6);
                        cubeGridTransform.Rotation = Quaternion.CreateFromEuler(new Vector3(-Time.TotalSeconds * 0.3f * x, -Time.TotalSeconds * 0.25f * y, -Time.TotalSeconds * 0.09f * z));
                        cubeGridTransform.Shear    = new Shear3D(Math.Sin(y * Time.TotalSeconds * 1.7f) * 0.2f, z * Math.Sin(Time.TotalSeconds * 1.9f) * 0.4f,
                                                                 Math.Sin(x * Time.TotalSeconds * 1.8f) * 0.3f, z * Math.Sin(Time.TotalSeconds * 1.8f) * 0.3f,
                                                                 Math.Sin(x * Time.TotalSeconds * 1.9f) * 0.4f, y * Math.Sin(Time.TotalSeconds * 1.7f) * 0.2f);
                        Renderer.Draw3D.SetTransform(cubeGridTransform);
                        //Renderer.Draw3D.CubeLines(new Colour(Math.SinNormalized(x + Time.TotalSeconds * 1.5f), Math.SinNormalized(y + Time.TotalSeconds * 1.4f), Math.SinNormalized(z + Time.TotalSeconds * 1.3f), 1f));
                        Renderer.Draw3D.Cube(Colour.Cyan,
                                             Colour.Yellow,
                                             Colour.Red,
                                             Colour.Blue,
                                             Colour.Green,
                                             Colour.Magenta);
                        //Renderer.Draw3D.Cube(new Colour(0f, 0f, 0f, 1f),
                        //						  new Colour(1f, 0f, 0f, 1f),
                        //						  new Colour(0f, 1f, 0f, 1f),
                        //						  new Colour(1f, 1f, 0f, 1f),
                        //						  new Colour(0f, 0f, 1f, 1f),
                        //						  new Colour(1f, 0f, 1f, 1f),
                        //						  new Colour(0f, 1f, 1f, 1f),
                        //						  new Colour(1f, 1f, 1f, 1f));
                    }
                }
            }
            Renderer.Draw3D.ResetTransform();

            Transform2D t2D = new Transform2D();

            //t2D.Rotation = Math.Sin(Time.TotalSeconds) * 0.03f;
            t2D.ShearX = Math.Sin(Time.TotalSeconds) * 0.4f;
            t2D.ShearY = Math.Sin(Time.TotalSeconds * 0.7f) * 0.5f;
            Renderer.Draw.SetTransform(t2D);
            Transform t = new Transform();

            //t.Rotation = Quaternion.CreateRotationZ(Math.Sin(Time.TotalSeconds) * 0.01f);
            //t.Shear = new Shear3D(0, 0, Math.Sin(Time.TotalSeconds * 0.7f) * 0.5f, Math.Cos(Time.TotalSeconds * 0.7f) * 0.5f, 0, 0);
            Renderer.Draw3D.SetTransform(t);

            Colour gridColour = new Colour(0.1f, 0.1f, 0.1f, 1f);
            int    length     = 100;
            //for (int yy = -length; yy <= length; yy++)
            //for (int yy = 0; yy <= 0; yy++)
            //{
            //float yy = cameraPosition.Y - 2f;
            float yy = -5f;

            for (int i = 0; i <= length; i++)
            {
                Renderer.Draw3D.Line(new Vector3(-length, yy, i),
                                     new Vector3(length, yy, i),
                                     gridColour);
                if (i != 0)
                {
                    Renderer.Draw3D.Line(new Vector3(-length, yy, -i),
                                         new Vector3(length, yy, -i),
                                         gridColour);
                }

                Renderer.Draw3D.Line(new Vector3(i, yy, -length),
                                     new Vector3(i, yy, length),
                                     gridColour);
                if (i != 0)
                {
                    Renderer.Draw3D.Line(new Vector3(-i, yy, -length),
                                         new Vector3(-i, yy, length),
                                         gridColour);
                }
            }
            Renderer.Draw3D.Line(new Vector3(-length, yy, -length),
                                 new Vector3(-length, yy + length, -length),
                                 gridColour);
            Renderer.Draw3D.Line(new Vector3(length, yy, -length),
                                 new Vector3(length, yy + length, -length),
                                 gridColour);
            Renderer.Draw3D.Line(new Vector3(-length, yy, length),
                                 new Vector3(-length, yy + length, length),
                                 gridColour);
            Renderer.Draw3D.Line(new Vector3(length, yy, length),
                                 new Vector3(length, yy + length, length),
                                 gridColour);
            //}
            //for (int y = -length; y <= length; y++)
            //{
            //	for (int x = -length; x <= length; x++)
            //	{
            //		for (int z = -length; z <= length; z++)
            //		{
            //			Renderer.Draw.Points.Point(new Vector3(x, y, z), gridColour);
            //		}
            //	}
            //}

            Renderer.Draw.Triangle(new Vector2(0f, 1f),
                                   new Vector2(0f, 1f) * Matrix2D.CreateRotationZ(Rotation.Third),
                                   new Vector2(0f, 1f) * Matrix2D.CreateRotationZ(Rotation.TwoThirds),
                                   Colour.Red,
                                   Colour.Green,
                                   Colour.Blue,
                                   null,
                                   null,
                                   null,
                                   -Time.TotalSeconds * 0.5f,
                                   Vector2.Zero);

            // Right
            Renderer.Draw3D.Triangle(new Vector3(20f, 10f, 0f),
                                     new Vector3(20f, 10f, 0f) * Quaternion.CreateRotationX(Rotation.Third),
                                     new Vector3(20f, 10f, 0f) * Quaternion.CreateRotationX(Rotation.TwoThirds),
                                     Colour.Red,
                                     Colour.Green,
                                     Colour.Blue);
            Renderer.Draw3D.Triangle(new Vector3(50f, 50f, 0f),
                                     new Vector3(50f, 50f, 0f) * Quaternion.CreateRotationX(Rotation.Third),
                                     new Vector3(50f, 50f, 0f) * Quaternion.CreateRotationX(Rotation.TwoThirds),
                                     Colour.Red,
                                     Colour.Green,
                                     Colour.Blue);

            // Left
            Renderer.Draw3D.Triangle(new Vector3(-20f, 10f, 0f),
                                     new Vector3(-20f, 10f, 0f) * Quaternion.CreateRotationX(Rotation.TwoThirds),
                                     new Vector3(-20f, 10f, 0f) * Quaternion.CreateRotationX(Rotation.Third),
                                     Colour.Red,
                                     Colour.Green,
                                     Colour.Blue);
            Renderer.Draw3D.Triangle(new Vector3(-50f, 50f, 0f),
                                     new Vector3(-50f, 50f, 0f) * Quaternion.CreateFromAxisAngle(Vector3.Left, Rotation.Third),
                                     new Vector3(-50f, 50f, 0f) * Quaternion.CreateFromAxisAngle(Vector3.Left, Rotation.TwoThirds),
                                     Colour.Red,
                                     Colour.Green,
                                     Colour.Blue);

            // Forward
            //Renderer.Draw3D.Triangle(new Vector3(0f, 2f, 10f),
            //						 new Vector3(0f, 2f, 10f) * Quaternion.CreateRotationZ(Rotation.Third),
            //						 new Vector3(0f, 2f, 10f) * Quaternion.CreateRotationZ(Rotation.TwoThirds),
            //						 Colour.Red,
            //						 Colour.Green,
            //						 Colour.Blue);
            //Renderer.Draw3D.Triangle(new Vector3(0f, 10f, 20f),
            //						 new Vector3(0f, 10f, 20f) * Quaternion.CreateRotationZ(Rotation.Third),
            //						 new Vector3(0f, 10f, 20f) * Quaternion.CreateRotationZ(Rotation.TwoThirds),
            //						 Colour.Red,
            //						 Colour.Green,
            //						 Colour.Blue);
            //Renderer.Draw3D.Triangle(new Vector3(0f, 50f, 50f),
            //						 new Vector3(0f, 50f, 50f) * Quaternion.CreateRotationZ(Rotation.Third).Matrix,
            //						 new Vector3(0f, 50f, 50f) * Quaternion.CreateRotationZ(Rotation.TwoThirds).Matrix,
            //						 Colour.Red,
            //						 Colour.Green,
            //						 Colour.Blue);
            for (int i = 0; i < 500; i += 5)
            {
                Renderer.Draw3D.Triangle(new Vector3(0f, i * 0.2f, i * 0.5f) * Quaternion.CreateRotationZ(Rotation.Zero + i * 0.001f - Time.TotalSeconds * 0.1f),
                                         new Vector3(0f, i * 0.2f, i * 0.5f) * Quaternion.CreateRotationZ(Rotation.Third + i * 0.001f - Time.TotalSeconds * 0.1f),
                                         new Vector3(0f, i * 0.2f, i * 0.5f) * Quaternion.CreateRotationZ(Rotation.TwoThirds + i * 0.001f - Time.TotalSeconds * 0.1f),
                                         Colour.Red,
                                         Colour.Green,
                                         Colour.Blue);
            }

            // Backward
            Renderer.Draw3D.Triangle(new Vector3(0f, 10f, -20f),
                                     new Vector3(0f, 10f, -20f) * Quaternion.CreateRotationZ(Rotation.TwoThirds),
                                     new Vector3(0f, 10f, -20f) * Quaternion.CreateRotationZ(Rotation.Third),
                                     Colour.Red,
                                     Colour.Green,
                                     Colour.Blue);
            Renderer.Draw3D.Triangle(new Vector3(0f, 50f, -50f),
                                     new Vector3(0f, 50f, -50f) * Quaternion.CreateFromAxisAngle(Vector3.Backward, Rotation.Third),
                                     new Vector3(0f, 50f, -50f) * Quaternion.CreateFromAxisAngle(Vector3.Backward, Rotation.TwoThirds),
                                     Colour.Red,
                                     Colour.Green,
                                     Colour.Blue);

            // Up
            Renderer.Draw3D.Triangle(new Vector3(0f, 20f, -10f),
                                     new Vector3(0f, 20f, -10f) * Quaternion.CreateRotationY(Rotation.Third),
                                     new Vector3(0f, 20f, -10f) * Quaternion.CreateRotationY(Rotation.TwoThirds),
                                     Colour.Red,
                                     Colour.Green,
                                     Colour.Blue);
            Renderer.Draw3D.Triangle(new Vector3(0f, 50f, -50f),
                                     new Vector3(0f, 50f, -50f) * Quaternion.CreateRotationY(Rotation.Third),
                                     new Vector3(0f, 50f, -50f) * Quaternion.CreateRotationY(Rotation.TwoThirds),
                                     Colour.Red,
                                     Colour.Green,
                                     Colour.Blue);

            // Down
            Renderer.Draw3D.Triangle(new Vector3(0f, -20f, -10f),
                                     new Vector3(0f, -20f, -10f) * Quaternion.CreateRotationY(Rotation.TwoThirds),
                                     new Vector3(0f, -20f, -10f) * Quaternion.CreateRotationY(Rotation.Third),
                                     Colour.Red,
                                     Colour.Green,
                                     Colour.Blue);
            Renderer.Draw3D.Triangle(new Vector3(0f, -50f, -50f),
                                     new Vector3(0f, -50f, -50f) * Quaternion.CreateFromAxisAngle(Vector3.Down, Rotation.Third),
                                     new Vector3(0f, -50f, -50f) * Quaternion.CreateFromAxisAngle(Vector3.Down, Rotation.TwoThirds),
                                     Colour.Red,
                                     Colour.Green,
                                     Colour.Blue);

            DepthMaskState.Disabled.Set();
            Textures.Test.Bind();
            Renderer.Draw.Rectangle(2f,
                                    -0.5f,
                                    1f,
                                    1f,
                                    Colour.White,
                                    Colour.White,
                                    Colour.White,
                                    Colour.White,
                                    UV.BottomLeft,
                                    UV.BottomRight,
                                    UV.TopLeft,
                                    UV.TopRight,
                                    -Time.TotalSeconds * 0.5f,
                                    new Vector2(2.5f, 0f));

            Renderer.Draw.Sprite(Sprites.Test1,
                                 new Vector2(4f, -0.5f),
                                 Vector2.One / Sprites.Test1.MaxLength,
                                 Colour.White);

            Renderer.Draw.Sprite(Sprites.Test2,
                                 new Vector2(6f, -0.5f),
                                 Vector2.One / Sprites.Test2.MaxLength,
                                 Colour.White);

            Renderer.Draw.Sprite(Sprites.Test3,
                                 new Vector2(8f, -0.5f),
                                 Vector2.One / Sprites.Test3.MaxLength,
                                 Colour.White);

            Renderer.Draw.Text(SpriteFonts.Font,
                               "|:shadow=0,-1,0.01,0,0,0,0.5:|ABCDEFGHIJKLMNOPQRSTUVWXYZ\nabcdefghijklmnopqrstuvwxyz\n1234567890\n_-+=(){}[]<>\\|/;:'\"?.,!@#$%^&*~`",
                               new Vector2(0f, 4f),
                               Vector2.One / 7f,
                               Colour.White,
                               HAlign.Center,
                               VAlign.Middle);
            DepthMaskState.Reset();

            Renderer.Draw.ResetTransform();

            // Test Geometry Shader
            //Shaders.GeometryTest.Bind();
            //Shaders.GeometryTest.MVP = Camera.Matrix;
            //for (int x = 0; x < 20; x++)
            //{
            //	for (int y = 0; y < 20; y++)
            //	{
            //		Renderer.Draw3D.Point(x * 1.1f, y * 1.1f, 0f, Colour.Red);
            //	}
            //}

            // NoiseShader Test
            Shaders.Noise.Bind();
            Shaders.Noise.MVP  = Camera.Matrix;
            Shaders.Noise.Time = Time.TotalSeconds;

            Renderer.Draw3D.Rectangle(new Vector3(-10f, -5f, -1f),
                                      new Vector3(10f, -5f, -1f),
                                      new Vector3(-10f, 5f, -1f),
                                      new Vector3(10f, 5f, -1f),
                                      Colour.White,
                                      //UV.BottomLeft,
                                      //UV.BottomRight,
                                      //UV.TopLeft,
                                      //UV.TopRight
                                      new Vector2(-1, -0.75f),
                                      new Vector2(1, -0.75f),
                                      new Vector2(-1, 0.75f),
                                      new Vector2(1, 0.75f)
                                      );

            // GUI Layer

            DepthState.Off.Set();
            Scene.Current?.Draw();

            Camera2D.Width  = Framebuffer.Current.Width;
            Camera2D.Height = Framebuffer.Current.Height;
            Shaders.Renderer.Bind();
            Shaders.Renderer.MVP = Camera2D.Matrix;

            //Renderer.Draw.Text(SpriteFonts.Font,
            //				   "|:shadow=0,-1,0.01,0,0,0,0.5:|Test Test\nStill testing...\nhhhheeeelllloooo",
            //				   new Vector2(2, height - 1),
            //				   Vector2.One * (1f + Math.SinNormalized(Time.TotalSeconds * 2f).Clamp(0.001f, 1f)),
            //				   Colour.White,
            //				   HAlign.Left,
            //				   VAlign.Top);

            //Renderer.Draw.Text(SpriteFonts.Font,
            //				   $"|:shadow=0,-1,0.01,0,0,0,0.5:|{Camera.Rotation}\nStill testing...",
            //				   new Vector2(2, 1),
            //				   Vector2.One * (1f + Math.SinNormalized(Time.TotalSeconds * 2f).Clamp(0.001f, 1f)),
            //				   Colour.White,
            //				   HAlign.Left,
            //				   VAlign.Bottom);

            //Renderer.Draw.Text(SpriteFonts.Font,
            //				   "|:shadow=0,-1,0.01,0,0,0,0.5:|Test Test",
            //				   new Vector2(width - 1, 1),
            //				   Vector2.One * (1f + Math.SinNormalized(Time.TotalSeconds * 2f).Clamp(0.001f, 1f)),
            //				   Colour.White,
            //				   HAlign.Right,
            //				   VAlign.Bottom);

            //Renderer.Draw.Text(SpriteFonts.Font,
            //				   "|:shadow=0,-1,0.01,0,0,0,0.5:|Test Test\nStill testing...\nhhhheeeelllloooo",
            //				   new Vector2(width - 1, height - 1),
            //				   Vector2.One * (1f + Math.SinNormalized(Time.TotalSeconds * 2f).Clamp(0.001f, 1f)),
            //				   Colour.White,
            //				   HAlign.Right,
            //				   VAlign.Top);

            //Renderer.Draw.Text(SpriteFonts.Font,
            //				   "|:outline=1,0.01,0,0,0,1:|Test Test Test Test Test Test Test Test Test\nStill testing... ... ...",
            //				   new Vector2(width / 2, height / 2),
            //				   Vector2.One * (1f + Math.SinNormalized(Time.TotalSeconds * 2f).Clamp(0.001f, 1f)),
            //				   Colour.White,
            //				   HAlign.Center,
            //				   VAlign.Middle);

            //Renderer.Draw.Text(SpriteFonts.Font,
            //				   "|:shadow=0,-1,0.01,0,0,0,0.5:|Test Test\nStill testing...",
            //				   new Vector2(width / 2, height / 2 + 50),
            //				   Vector2.One * (1f + Math.SinNormalized(Time.TotalSeconds * 2f).Clamp(0.001f, 1f) * 3f),
            //				   Colour.White,
            //				   HAlign.Center,
            //				   VAlign.Middle);

            //Renderer.Draw.Text(SpriteFonts.Font,
            //				   "|:shadow=0,-1,0.01,0,0,0,0.5:|Test Test\nStill testing...",
            //				   new Vector2(width / 2, height / 2 - 50),
            //				   Vector2.One * (1f + Math.SinNormalized(Time.TotalSeconds * 2f).Clamp(0.001f, 1f) * 2f),
            //				   Colour.White,
            //				   HAlign.Center,
            //				   VAlign.Middle);

            //Renderer.Draw.TriangleListStrip.Begin();
            ////int ii = Random.Range(1000, 10000);
            //for (int i = 0; i < 10000; i++)
            //	Renderer.Draw.TriangleListStrip.AddVertex(new Vector3(Random.Range(-100f, 100f), Random.Range(-100f, 100f), 0.0f),
            //										  new Colour(Random.Range(1f), Random.Range(1f), Random.Range(1f), Random.Range(1f)));
            //Renderer.Draw.TriangleListStrip.End();

            // TODO - LineListStrip
            //Renderer.Draw.LineListStrip.Begin();
            //for (int i = 0; i < 10; i++)
            //	Renderer.Draw.LineListStrip.AddVertex(new Vector3(Random.Range(-6f, -2f), Random.Range(-2f, 2f), 0.0f),
            //									  new Colour(Random.Range(1f), Random.Range(1f), Random.Range(1f), Random.Range(1f)));
            //Renderer.Draw.LineListStrip.End();

            //Renderer.Draw.Circle(new Vector2(0f, -8f), 10f, Colour.Green, Colour.Green.Alpha(0.1f), (int)Math.Lerp(8f, 64f, Math.SinNormalized(Time.TotalSeconds)));

            //for (int i = 0; i < 10000; i++)
            //	Renderer.Draw.PolyPoint(new Vector2(Random.Range(0, width), Random.Range(0, height)),
            //							new Colour(Random.Range(1f), Random.Range(1f), Random.Range(1f), 1f));

            //Framebuffer.Bind(null);
            //Renderer.Draw.Framebuffer(surface, 0,
            //						   -5f, 5f, 0.1f,
            //						   Colour.White);

            //Renderer.Draw.Text(SpriteFonts.Font,
            //				   debugString,
            //				   new Vector2(2, Framebuffer.Current.Height - 1),
            //				   Vector2.One,
            //				   Colour.White,
            //				   HAlign.Left,
            //				   VAlign.Top);

            // Draw Depth Buffer
            if (Input.Keyboard.Down(KeyCode.F1))
            {
                Graphics.State.Reset();
                Shaders.LinearizeDepth.Bind();
                Shaders.LinearizeDepth.MVP   = surface.Matrix;
                Shaders.LinearizeDepth.zNear = Camera.zNear;
                Shaders.LinearizeDepth.zFar  = Camera.zFar;
                Renderer.Draw.Framebuffer(surface, TextureAttachment.Depth, 0, 0, Colour.White);

                Shaders.Renderer.Bind();
                Shaders.Renderer.MVP = Framebuffer.Default.Matrix;
            }

            // Draw to Screen
            Framebuffer.Default.Bind();
            Graphics.Clear(new Colour(0.1f, 0.1f, 0.1f, 1f));
            Graphics.State.Reset();

            scale = Math.Max(1, Math.Min(Window.Width / width, Window.Height / height));

            // Render Framebuffer
            Shaders.Renderer.Bind();
            Shaders.Renderer.MVP = Framebuffer.Default.Matrix;
            Renderer.Draw.Framebuffer(surface, TextureAttachment.Colour0, (Window.Width - width * scale) / 2, (Window.Height - height * scale) / 2, scale, Colour.White);
            //Renderer.Draw.Framebuffer(surface, TextureAttachment.Colour0, (Window.Width - width * scale) / 2, (Window.Height - height * scale) / 2, scale, Math.Sin(Time.TotalSeconds) * 0.03f, new Vector2(Window.Width / 2f, Window.Height / 2f), Colour.White);

            // Blit Framebuffer
            //surface.BlitTextureTo(Framebuffer.Default, TextureAttachment.Colour0, BlitFilter.Nearest, new RectangleI((Window.Width - width * scale) / 2, (Window.Height - height * scale) / 2, width * scale, height * scale));

            Renderer.Draw.Text(SpriteFonts.Font,
                               debugString,
                               new Vector2(2, Framebuffer.Current.Height - 1),
                               Vector2.One * 3f,
                               Colour.White,
                               HAlign.Left,
                               VAlign.Top);

            Renderer.Flush();

            // Screenshot
            if (Input.Keyboard.Pressed(KeyCode.F9))
            {
                string s = "X:/Dropbox/Clint/Gamedev/2018-03-22 CKGL/screenshots/";
                if (!System.IO.Directory.Exists(s))
                {
                    s = "C:/Users/Clint Kilmer/Dropbox/Clint/Gamedev/2018-03-22 CKGL/screenshots/";
                }

                int sequentialNumber = 1;
                while (System.IO.File.Exists($@"{s}{System.DateTime.Now:yyyy-MM-dd HH.mm.ss}-{sequentialNumber} [CKGL].png"))
                {
                    sequentialNumber++;
                }

                surface.SavePNG($@"{s}{System.DateTime.Now:yyyy-MM-dd HH.mm.ss}-{sequentialNumber} [CKGL].png");

                //System.GC.Collect();
            }
        }
Ejemplo n.º 7
0
        public static Vector2 Rotate(this Vector2 v, float radians)
        {
            Matrix2D rotationMatrix = Matrix2D.CreateRotationZ(radians);

            return(Vector2.Transform(v, rotationMatrix));
        }