public void Multiply() { for (int c = 0; c < 3; c++) { for (int r = 0; r < 3; r++) { _matrix[_targetMatrix, c, r] = _matrix[2, 0, r] * _matrix[_sourceMatrix, c, 0] + _matrix[2, 1, r] * _matrix[_sourceMatrix, c, 1] + _matrix[2, 2, r] * _matrix[_sourceMatrix, c, 2]; } } PGEMath.Swap(_targetMatrix, _sourceMatrix); _dirty = true; // Any transform multiply dirties the inversion }
public void DrawSprite(Sprite sprite, Transform2D transform) { if (sprite == null) { return; } // Work out bounding rectangle of sprite float ex = 0.0f, ey = 0.0f; vec2d_f s = transform.Forward(0.0f, 0.0f); vec2d_f p = new vec2d_f(s); s.x = Math.Min(s.x, p.x); s.y = Math.Min(s.y, p.y); ex = Math.Max(ex, p.x); ey = Math.Max(ey, p.y); transform.Forward(sprite.Width, sprite.Height); s.x = Math.Min(s.x, p.x); s.y = Math.Min(s.y, p.y); ex = Math.Max(ex, p.x); ey = Math.Max(ey, p.y); p = transform.Forward(0.0f, sprite.Height); s.x = Math.Min(s.x, p.x); s.y = Math.Min(s.y, p.y); ex = Math.Max(ex, p.x); ey = Math.Max(ey, p.y); p = transform.Forward(sprite.Width, 0.0f); s.x = Math.Min(s.x, p.x); s.y = Math.Min(s.y, p.y); ex = Math.Max(ex, p.x); ey = Math.Max(ey, p.y); // Perform inversion of transform if required transform.Invert(); float sx = s.x; float sy = s.y; if (ex < sx) { PGEMath.Swap(ref ex, ref sx); } if (ey < sy) { PGEMath.Swap(ref ey, ref sy); } s.x = sx; s.y = sy; // Iterate through render space, and sample Sprite from suitable texel location for (float i = s.x; i < ex; i++) { for (float j = s.y; j < ey; j++) { vec2d_f o = transform.Backward(i, j); pge.Draw((uint)i, (uint)j, sprite.GetPixel((uint)(o.x + 0.5f), (uint)(o.y + 0.5f))); } } }