public Vector2 ToWorld(Vector2 screenPoint, float parallax = 1) { /* Vector2 shift = new Vector2(_origin.X * scrWidth, _origin.Y * scrHeight); screenPoint.X -= shift.X; screenPoint.Y -= shift.Y; screenPoint = Vector2.Transform(screenPoint, Quaternion.FromAxisAngle(Vector3.UnitZ, -_rotation));//Vector3.Transform(new Vector3(screenPoint), Matrix4.CreateRotationZ(-_rotation)).Xy; screenPoint /= _scale; //screenPoint.X += shift.X; //screenPoint.Y += shift.Y; screenPoint.X += _position.X * parallax; screenPoint.Y += _position.Y * parallax; */ return screenPoint.Transform(Matrix4.Invert(GetViewMatrix(parallax))); //return screenPoint; }
private void DrawInternal( Texture2D texture, Vector2 destination, int width, int height, Rectangle? source, Color4? tint, Vector2? origin, Vector2? scale, float rotation, float layerDepth) { this.EnsureDrawInProgress(); if (texture == null) throw new ArgumentNullException("texture"); if (texture != this.texture) this.Flush(); this.texture = texture; if (source == null) source = new Rectangle(0, 0, texture.Width, texture.Height); if (tint == null) tint = Color4.White; if (origin == null) origin = Vector2.Zero; if (scale == null) scale = Vector2.One; Vector2 topLeft = new Vector2(-origin.Value.X, -origin.Value.Y); Vector2 topRight = new Vector2(width - origin.Value.X, -origin.Value.Y); Vector2 bottomRight = new Vector2(width - origin.Value.X, height - origin.Value.Y); Vector2 bottomLeft = new Vector2(-origin.Value.X, height - origin.Value.Y); Matrix4 rotationMatrix; Matrix4.CreateRotationZ(rotation, out rotationMatrix); Matrix4 scaleMatrix; Matrix4.CreateScale(scale.Value.X, scale.Value.Y, 1.0f, out scaleMatrix); Matrix4 translationMatrix; Matrix4.CreateTranslation(destination.X, destination.Y, out translationMatrix); Matrix4 identity = Matrix4.Identity; Matrix4 transform1; Matrix4.Multiply(ref identity, ref scaleMatrix, out transform1); Matrix4 transform2; Matrix4.Multiply(ref transform1, ref rotationMatrix, out transform2); Matrix4 transform3; Matrix4.Multiply(ref transform2, ref translationMatrix, out transform3); topLeft = topLeft.Transform(ref transform3); topRight = topRight.Transform(ref transform3); bottomRight = bottomRight.Transform(ref transform3); bottomLeft = bottomLeft.Transform(ref transform3); this.AddQuad( ref topLeft, ref topRight, ref bottomRight, ref bottomLeft, source.Value, tint.Value, layerDepth); }
public Vector2 ToScreen(Vector2 worldPoint, float parallax = 1) { /* Vector2 shift = new Vector2(_origin.X * scrWidth, _origin.Y * scrHeight); worldPoint.X -= _position.X * parallax; worldPoint.Y -= _position.Y * parallax; //worldPoint.X -= shift.X; //worldPoint.Y -= shift.Y; worldPoint = Vector2.Transform(worldPoint, Quaternion.FromAxisAngle(Vector3.UnitZ, -_rotation)); worldPoint *= _scale; worldPoint.X += shift.X; worldPoint.Y += shift.Y; */ return worldPoint.Transform(GetViewMatrix(parallax)); //return worldPoint; }