public BitmapBounds(System.Numerics.Matrix3x2 srcXform, float srcW, float srcH) { var a = srcXform.Translation; var b = XY.Transform(new XY(srcW, 0), srcXform); var c = XY.Transform(new XY(srcW, srcH), srcXform); var d = XY.Transform(new XY(0, srcH), srcXform); var min = XY.Min(XY.Min(XY.Min(a, b), c), d); var max = XY.Max(XY.Max(XY.Max(a, b), c), d); this.X = (int)min.X; this.Y = (int)min.Y; this.Width = (int)max.X + 1 - this.X; this.Height = (int)max.Y + 1 - this.Y; }
private void PushSprite(Texture2D texture, Vector2 destination, Vector2 destinationSize, Color color, Vector2 origin, float rotation, float depth, byte effects) { // out of space, flush if (_numSprites >= MAX_SPRITES) { FlushBatch(); } if (!_shouldIgnoreRoundingDestinations && ShouldRoundDestinations) { destination.X = Mathf.Round(destination.X); destination.Y = Mathf.Round(destination.Y); } // Source/Destination/Origin Calculations var source = Vector2.Zero; var sourceSize = Vector2.One; var tOrigin = origin * (Vector2.One / texture.Bounds.Size.ToSimd()); destinationSize *= texture.Bounds.Size.ToSimd(); // Rotation Calculations var matrix = System.Numerics.Matrix3x2.Identity; if (!Mathf.WithinEpsilon(rotation)) { matrix = System.Numerics.Matrix3x2.CreateRotation(rotation); } matrix.Translation = destination; // calculate vertices // top-left var corner = -tOrigin * destinationSize; var result = Vector2.Transform(corner, matrix); _vertexInfo[_numSprites].Position0 = new System.Numerics.Vector3(result, depth); // top-right corner = (_cornerOffset[1] - tOrigin) * destinationSize; result = Vector2.Transform(corner, matrix); _vertexInfo[_numSprites].Position1 = new System.Numerics.Vector3(result, depth); // bottom-left corner = (_cornerOffset[2] - tOrigin) * destinationSize; result = Vector2.Transform(corner, matrix); _vertexInfo[_numSprites].Position2 = new System.Numerics.Vector3(result, depth); // bottom-right corner = (_cornerOffset[3] - tOrigin) * destinationSize; result = Vector2.Transform(corner, matrix); _vertexInfo[_numSprites].Position3 = new System.Numerics.Vector3(result, depth); _vertexInfo[_numSprites].TextureCoordinate0 = (_cornerOffset[0 ^ effects] * sourceSize) + source; _vertexInfo[_numSprites].TextureCoordinate1 = (_cornerOffset[1 ^ effects] * sourceSize) + source; _vertexInfo[_numSprites].TextureCoordinate2 = (_cornerOffset[2 ^ effects] * sourceSize) + source; _vertexInfo[_numSprites].TextureCoordinate3 = (_cornerOffset[3 ^ effects] * sourceSize) + source; _vertexInfo[_numSprites].Color0 = color; _vertexInfo[_numSprites].Color1 = color; _vertexInfo[_numSprites].Color2 = color; _vertexInfo[_numSprites].Color3 = color; if (_disableBatching) { _vertexBuffer.SetData(0, _vertexInfo, 0, 1, VertexPositionColorTexture4.RealStride, SetDataOptions.None); DrawPrimitives(texture, 0, 1); } else { _textureInfo[_numSprites] = texture; _numSprites += 1; } }