diff --git a/Engine.Integration/Engine.Integration.MonoGame/Behaviours/MonoGameCamera2D.cs b/Engine.Integration/Engine.Integration.MonoGame/Behaviours/MonoGameCamera2D.cs index f28deb5..0d6f811 100644 --- a/Engine.Integration/Engine.Integration.MonoGame/Behaviours/MonoGameCamera2D.cs +++ b/Engine.Integration/Engine.Integration.MonoGame/Behaviours/MonoGameCamera2D.cs @@ -73,7 +73,7 @@ public class MonoGameCamera2D : Behaviour, ICamera2D, IFirstFrameUpdate, ILastFr public Vector2D ScreenToWorldPosition(Vector2D screenPosition) { float x = 2f * screenPosition.X / Viewport.Width - 1f; - float y = 2f * screenPosition.Y / Viewport.Height - 1f; + float y = 1f - 2f * screenPosition.Y / Viewport.Height; Vector4D normalizedCoordinates = new(x, y, 0f, 1f); Matrix4x4 invertedViewProjectionMatrix = (ProjectionMatrix * ViewMatrix).Inverse; @@ -97,7 +97,7 @@ public class MonoGameCamera2D : Behaviour, ICamera2D, IFirstFrameUpdate, ILastFr clip /= clip.W; float screenX = (clip.X + 1f) * .5f * Viewport.Width; - float screenY = (clip.Y + 1f) * .5f * Viewport.Height; + float screenY = (1f - clip.Y) * .5f * Viewport.Height; return new(screenX, screenY); } @@ -112,9 +112,9 @@ public class MonoGameCamera2D : Behaviour, ICamera2D, IFirstFrameUpdate, ILastFr public void PreDraw() { - ProjectionMatrix = Matrix4x4.CreateOrthographicViewCentered(Viewport.Width, -Viewport.Height); + ProjectionMatrix = Matrix4x4.CreateOrthographicViewCentered(Viewport.Width, Viewport.Height); ViewMatrix = - Matrix4x4.CreateTranslation(new Vector3D(-Transform.Position.X, Transform.Position.Y, 0f)) + Matrix4x4.CreateTranslation(new Vector3D(-Transform.Position.X, -Transform.Position.Y, 0f)) .ApplyRotationZ(Transform.Rotation * Math.DegreeToRadian) .ApplyScale(Transform.Scale.X.Max(Transform.Scale.Y)) .ApplyScale(Zoom); diff --git a/Engine.Integration/Engine.Integration.MonoGame/Behaviours/SpriteBatchWrapper.cs b/Engine.Integration/Engine.Integration.MonoGame/Behaviours/SpriteBatchWrapper.cs index 8940127..57610d9 100644 --- a/Engine.Integration/Engine.Integration.MonoGame/Behaviours/SpriteBatchWrapper.cs +++ b/Engine.Integration/Engine.Integration.MonoGame/Behaviours/SpriteBatchWrapper.cs @@ -15,49 +15,49 @@ public class SpriteBatchWrapper(GraphicsDevice graphicsDevice) : ISpriteBatch => spriteBatch.Begin(sortMode, blendState, samplerState, depthStencilState, rasterizerState, effect, transformMatrix); public void Draw(Texture2D texture, Vector2D position, AABB2D? sourceAABB, Color color, float rotation, Vector2D origin, Vector2D scale, SpriteEffects effects, float layerDepth) - => spriteBatch.Draw(texture, position.ToDisplayVector2(), sourceAABB?.ToRectangle(), color, rotation, origin.ToDisplayVector2(), scale.ToDisplayVector2(), effects, layerDepth); + => spriteBatch.Draw(texture, position.ToVector2(), sourceAABB?.ToRectangle(), color, rotation, origin.ToVector2(), scale.ToVector2(), effects, layerDepth); public void Draw(Texture2D texture, Vector2D position, AABB2D? sourceAABB, Color color, float rotation, Vector2D origin, float scale, SpriteEffects effects, float layerDepth) - => spriteBatch.Draw(texture, position.ToDisplayVector2(), sourceAABB?.ToRectangle(), color, rotation, origin.ToDisplayVector2(), scale, effects, layerDepth); + => spriteBatch.Draw(texture, position.ToVector2(), sourceAABB?.ToRectangle(), color, rotation, origin.ToVector2(), scale, effects, layerDepth); public void Draw(Texture2D texture, AABB2D destinationAABB, AABB2D? sourceAABB, Color color, float rotation, Vector2D origin, SpriteEffects effects, float layerDepth) - => spriteBatch.Draw(texture, destinationAABB.ToRectangle(), sourceAABB?.ToRectangle(), color, rotation, origin.ToDisplayVector2(), effects, layerDepth); + => spriteBatch.Draw(texture, destinationAABB.ToRectangle(), sourceAABB?.ToRectangle(), color, rotation, origin.ToVector2(), effects, layerDepth); public void Draw(Texture2D texture, Vector2D position, AABB2D? sourceAABB, Color color) - => spriteBatch.Draw(texture, position.ToDisplayVector2(), sourceAABB?.ToRectangle(), color); + => spriteBatch.Draw(texture, position.ToVector2(), sourceAABB?.ToRectangle(), color); public void Draw(Texture2D texture, AABB2D destinationAABB, AABB2D? sourceAABB, Color color) => spriteBatch.Draw(texture, destinationAABB.ToRectangle(), sourceAABB?.ToRectangle(), color); public void Draw(Texture2D texture, Vector2D position, Color color) - => spriteBatch.Draw(texture, position.ToDisplayVector2(), color); + => spriteBatch.Draw(texture, position.ToVector2(), color); public void Draw(Texture2D texture, AABB2D destinationAABB, Color color) => spriteBatch.Draw(texture, destinationAABB.ToRectangle(), color); public void DrawString(SpriteFont spriteFont, string text, Vector2D position, Color color) - => spriteBatch.DrawString(spriteFont, text, position.ToDisplayVector2(), color); + => spriteBatch.DrawString(spriteFont, text, position.ToVector2(), color); public void DrawString(SpriteFont spriteFont, string text, Vector2D position, Color color, float rotation, Vector2D origin, float scale, SpriteEffects effects, float layerDepth) - => spriteBatch.DrawString(spriteFont, text, position.ToDisplayVector2(), color, rotation, origin.ToDisplayVector2(), scale, effects, layerDepth); + => spriteBatch.DrawString(spriteFont, text, position.ToVector2(), color, rotation, origin.ToVector2(), scale, effects, layerDepth); public void DrawString(SpriteFont spriteFont, string text, Vector2D position, Color color, float rotation, Vector2D origin, Vector2D scale, SpriteEffects effects, float layerDepth) - => spriteBatch.DrawString(spriteFont, text, position.ToDisplayVector2(), color, rotation, origin.ToDisplayVector2(), scale.ToDisplayVector2(), effects, layerDepth); + => spriteBatch.DrawString(spriteFont, text, position.ToVector2(), color, rotation, origin.ToVector2(), scale.ToVector2(), effects, layerDepth); public void DrawString(SpriteFont spriteFont, string text, Vector2D position, Color color, float rotation, Vector2D origin, Vector2D scale, SpriteEffects effects, float layerDepth, bool rtl) - => spriteBatch.DrawString(spriteFont, text, position.ToDisplayVector2(), color, rotation, origin.ToDisplayVector2(), scale.ToDisplayVector2(), effects, layerDepth, rtl); + => spriteBatch.DrawString(spriteFont, text, position.ToVector2(), color, rotation, origin.ToVector2(), scale.ToVector2(), effects, layerDepth, rtl); public void DrawString(SpriteFont spriteFont, StringBuilder text, Vector2D position, Color color) - => spriteBatch.DrawString(spriteFont, text, position.ToDisplayVector2(), color); + => spriteBatch.DrawString(spriteFont, text, position.ToVector2(), color); public void DrawString(SpriteFont spriteFont, StringBuilder text, Vector2D position, Color color, float rotation, Vector2D origin, float scale, SpriteEffects effects, float layerDepth) - => spriteBatch.DrawString(spriteFont, text, position.ToDisplayVector2(), color, rotation, origin.ToDisplayVector2(), scale, effects, layerDepth); + => spriteBatch.DrawString(spriteFont, text, position.ToVector2(), color, rotation, origin.ToVector2(), scale, effects, layerDepth); public void DrawString(SpriteFont spriteFont, StringBuilder text, Vector2D position, Color color, float rotation, Vector2D origin, Vector2D scale, SpriteEffects effects, float layerDepth) - => spriteBatch.DrawString(spriteFont, text, position.ToDisplayVector2(), color, rotation, origin.ToDisplayVector2(), scale.ToDisplayVector2(), effects, layerDepth); + => spriteBatch.DrawString(spriteFont, text, position.ToVector2(), color, rotation, origin.ToVector2(), scale.ToVector2(), effects, layerDepth); public void DrawString(SpriteFont spriteFont, StringBuilder text, Vector2D position, Color color, float rotation, Vector2D origin, Vector2D scale, SpriteEffects effects, float layerDepth, bool rtl) - => spriteBatch.DrawString(spriteFont, text, position.ToDisplayVector2(), color, rotation, origin.ToDisplayVector2(), scale.ToDisplayVector2(), effects, layerDepth, rtl); + => spriteBatch.DrawString(spriteFont, text, position.ToVector2(), color, rotation, origin.ToVector2(), scale.ToVector2(), effects, layerDepth, rtl); public void End() => spriteBatch.End(); diff --git a/Engine.Integration/Engine.Integration.MonoGame/EngineConverter.cs b/Engine.Integration/Engine.Integration.MonoGame/EngineConverter.cs index f30cc0c..42d5d49 100644 --- a/Engine.Integration/Engine.Integration.MonoGame/EngineConverter.cs +++ b/Engine.Integration/Engine.Integration.MonoGame/EngineConverter.cs @@ -9,8 +9,6 @@ namespace Engine.Integration.MonoGame; public static class EngineConverterExtensions { - public readonly static Vector2D screenScale = Vector2D.Down + Vector2D.Right; - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static UniverseTime ToEngineTime(this GameTime gameTime) => new(gameTime.TotalGameTime, gameTime.ElapsedGameTime); @@ -60,12 +58,6 @@ public static class EngineConverterExtensions [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Microsoft.Xna.Framework.Quaternion ToXnaQuaternion(this Core.Quaternion quaternion) => new(quaternion.X, quaternion.Y, quaternion.Z, quaternion.W); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Vector2 ToDisplayVector2(this Vector2D vector) => vector.Scale(screenScale).ToVector2(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Vector2D ApplyDisplayScale(this Vector2D vector) => vector.Scale(screenScale); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Rectangle ToDisplayRectangle(this Rectangle rectangle, DisplayMode displayMode) => new() { @@ -78,8 +70,8 @@ public static class EngineConverterExtensions [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Rectangle ToRectangle(this AABB2D aabb) => new() { - X = (int)(aabb.LowerBoundary.X * screenScale.X), - Y = (int)(aabb.LowerBoundary.Y * screenScale.Y), + X = (int)aabb.LowerBoundary.X, + Y = (int)aabb.LowerBoundary.Y, Width = (int)(aabb.UpperBoundary.X - aabb.LowerBoundary.X), Height = (int)(aabb.UpperBoundary.Y - aabb.LowerBoundary.Y) }; diff --git a/Engine.Integration/Engine.Integration.MonoGame/MonoGameTriangleBatch.cs b/Engine.Integration/Engine.Integration.MonoGame/MonoGameTriangleBatch.cs index a6f4c4e..f782028 100644 --- a/Engine.Integration/Engine.Integration.MonoGame/MonoGameTriangleBatch.cs +++ b/Engine.Integration/Engine.Integration.MonoGame/MonoGameTriangleBatch.cs @@ -33,9 +33,9 @@ public class MonoGameTriangleBatch : Behaviour, ITriangleBatch, IFirstFrameUpdat if (verticesIndex + 3 >= vertices.Length) Flush(); - Vector2 A = triangle.A.ToDisplayVector2(); - Vector2 B = triangle.B.ToDisplayVector2(); - Vector2 C = triangle.C.ToDisplayVector2(); + Vector2 A = triangle.A.ToVector2(); + Vector2 B = triangle.B.ToVector2(); + Vector2 C = triangle.C.ToVector2(); Color color = colorRGBA.ToColor(); vertices[verticesIndex++] = new(new(A.X, A.Y, 0f), color);