Replace Matrix3 with System.Numerics.Matrix3x2 (#27443)

Replace Matrix3 with Matrix3x2
This commit is contained in:
eoineoineoin
2024-06-02 05:07:41 +01:00
committed by GitHub
parent 21d0b1fd55
commit b44b159431
58 changed files with 236 additions and 215 deletions

View File

@@ -25,7 +25,7 @@ public sealed class ExplosionDebugOverlay : Overlay
public override OverlaySpace Space => OverlaySpace.WorldSpace | OverlaySpace.ScreenSpace; public override OverlaySpace Space => OverlaySpace.WorldSpace | OverlaySpace.ScreenSpace;
public Matrix3 SpaceMatrix; public Matrix3x2 SpaceMatrix;
public MapId Map; public MapId Map;
private readonly Font _font; private readonly Font _font;
@@ -78,7 +78,8 @@ public sealed class ExplosionDebugOverlay : Overlay
if (SpaceTiles == null) if (SpaceTiles == null)
return; return;
gridBounds = Matrix3.Invert(SpaceMatrix).TransformBox(args.WorldBounds); Matrix3x2.Invert(SpaceMatrix, out var invSpace);
gridBounds = invSpace.TransformBox(args.WorldBounds);
DrawText(handle, gridBounds, SpaceMatrix, SpaceTiles, SpaceTileSize); DrawText(handle, gridBounds, SpaceMatrix, SpaceTiles, SpaceTileSize);
} }
@@ -86,7 +87,7 @@ public sealed class ExplosionDebugOverlay : Overlay
private void DrawText( private void DrawText(
DrawingHandleScreen handle, DrawingHandleScreen handle,
Box2 gridBounds, Box2 gridBounds,
Matrix3 transform, Matrix3x2 transform,
Dictionary<int, List<Vector2i>> tileSets, Dictionary<int, List<Vector2i>> tileSets,
ushort tileSize) ushort tileSize)
{ {
@@ -103,7 +104,7 @@ public sealed class ExplosionDebugOverlay : Overlay
if (!gridBounds.Contains(centre)) if (!gridBounds.Contains(centre))
continue; continue;
var worldCenter = transform.Transform(centre); var worldCenter = Vector2.Transform(centre, transform);
var screenCenter = _eyeManager.WorldToScreen(worldCenter); var screenCenter = _eyeManager.WorldToScreen(worldCenter);
@@ -119,7 +120,7 @@ public sealed class ExplosionDebugOverlay : Overlay
if (tileSets.TryGetValue(0, out var set)) if (tileSets.TryGetValue(0, out var set))
{ {
var epicenter = set.First(); var epicenter = set.First();
var worldCenter = transform.Transform((epicenter + Vector2Helpers.Half) * tileSize); var worldCenter = Vector2.Transform((epicenter + Vector2Helpers.Half) * tileSize, transform);
var screenCenter = _eyeManager.WorldToScreen(worldCenter) + new Vector2(-24, -24); var screenCenter = _eyeManager.WorldToScreen(worldCenter) + new Vector2(-24, -24);
var text = $"{Intensity[0]:F2}\nΣ={TotalIntensity:F1}\nΔ={Slope:F1}"; var text = $"{Intensity[0]:F2}\nΣ={TotalIntensity:F1}\nΔ={Slope:F1}";
handle.DrawString(_font, screenCenter, text); handle.DrawString(_font, screenCenter, text);
@@ -148,11 +149,12 @@ public sealed class ExplosionDebugOverlay : Overlay
if (SpaceTiles == null) if (SpaceTiles == null)
return; return;
gridBounds = Matrix3.Invert(SpaceMatrix).TransformBox(args.WorldBounds).Enlarged(2); Matrix3x2.Invert(SpaceMatrix, out var invSpace);
gridBounds = invSpace.TransformBox(args.WorldBounds).Enlarged(2);
handle.SetTransform(SpaceMatrix); handle.SetTransform(SpaceMatrix);
DrawTiles(handle, gridBounds, SpaceTiles, SpaceTileSize); DrawTiles(handle, gridBounds, SpaceTiles, SpaceTileSize);
handle.SetTransform(Matrix3.Identity); handle.SetTransform(Matrix3x2.Identity);
} }
private void DrawTiles( private void DrawTiles(

View File

@@ -66,7 +66,7 @@ public sealed class AtmosDebugOverlay : Overlay
DrawData(msg, handle); DrawData(msg, handle);
} }
handle.SetTransform(Matrix3.Identity); handle.SetTransform(Matrix3x2.Identity);
} }
private void DrawData(DebugMessage msg, private void DrawData(DebugMessage msg,

View File

@@ -190,7 +190,7 @@ namespace Content.Client.Atmos.Overlays
var (_, _, worldMatrix, invMatrix) = gridXform.GetWorldPositionRotationMatrixWithInv(); var (_, _, worldMatrix, invMatrix) = gridXform.GetWorldPositionRotationMatrixWithInv();
state.drawHandle.SetTransform(worldMatrix); state.drawHandle.SetTransform(worldMatrix);
var floatBounds = invMatrix.TransformBox(in state.WorldBounds).Enlarged(grid.TileSize); var floatBounds = invMatrix.TransformBox(state.WorldBounds).Enlarged(grid.TileSize);
var localBounds = new Box2i( var localBounds = new Box2i(
(int) MathF.Floor(floatBounds.Left), (int) MathF.Floor(floatBounds.Left),
(int) MathF.Floor(floatBounds.Bottom), (int) MathF.Floor(floatBounds.Bottom),
@@ -249,7 +249,7 @@ namespace Content.Client.Atmos.Overlays
}); });
drawHandle.UseShader(null); drawHandle.UseShader(null);
drawHandle.SetTransform(Matrix3.Identity); drawHandle.SetTransform(Matrix3x2.Identity);
} }
private void DrawMapOverlay( private void DrawMapOverlay(

View File

@@ -38,9 +38,9 @@ namespace Content.Client.Clickable
renderOrder = sprite.RenderOrder; renderOrder = sprite.RenderOrder;
var (spritePos, spriteRot) = transform.GetWorldPositionRotation(xformQuery); var (spritePos, spriteRot) = transform.GetWorldPositionRotation(xformQuery);
var spriteBB = sprite.CalculateRotatedBoundingBox(spritePos, spriteRot, eye.Rotation); var spriteBB = sprite.CalculateRotatedBoundingBox(spritePos, spriteRot, eye.Rotation);
bottom = Matrix3.CreateRotation(eye.Rotation).TransformBox(spriteBB).Bottom; bottom = Matrix3Helpers.CreateRotation(eye.Rotation).TransformBox(spriteBB).Bottom;
var invSpriteMatrix = Matrix3.Invert(sprite.GetLocalMatrix()); Matrix3x2.Invert(sprite.GetLocalMatrix(), out var invSpriteMatrix);
// This should have been the rotation of the sprite relative to the screen, but this is not the case with no-rot or directional sprites. // This should have been the rotation of the sprite relative to the screen, but this is not the case with no-rot or directional sprites.
var relativeRotation = (spriteRot + eye.Rotation).Reduced().FlipPositive(); var relativeRotation = (spriteRot + eye.Rotation).Reduced().FlipPositive();
@@ -48,8 +48,8 @@ namespace Content.Client.Clickable
Angle cardinalSnapping = sprite.SnapCardinals ? relativeRotation.GetCardinalDir().ToAngle() : Angle.Zero; Angle cardinalSnapping = sprite.SnapCardinals ? relativeRotation.GetCardinalDir().ToAngle() : Angle.Zero;
// First we get `localPos`, the clicked location in the sprite-coordinate frame. // First we get `localPos`, the clicked location in the sprite-coordinate frame.
var entityXform = Matrix3.CreateInverseTransform(transform.WorldPosition, sprite.NoRotation ? -eye.Rotation : spriteRot - cardinalSnapping); var entityXform = Matrix3Helpers.CreateInverseTransform(transform.WorldPosition, sprite.NoRotation ? -eye.Rotation : spriteRot - cardinalSnapping);
var localPos = invSpriteMatrix.Transform(entityXform.Transform(worldPos)); var localPos = Vector2.Transform(Vector2.Transform(worldPos, entityXform), invSpriteMatrix);
// Check explicitly defined click-able bounds // Check explicitly defined click-able bounds
if (CheckDirBound(sprite, relativeRotation, localPos)) if (CheckDirBound(sprite, relativeRotation, localPos))
@@ -79,8 +79,8 @@ namespace Content.Client.Clickable
// convert to layer-local coordinates // convert to layer-local coordinates
layer.GetLayerDrawMatrix(dir, out var matrix); layer.GetLayerDrawMatrix(dir, out var matrix);
var inverseMatrix = Matrix3.Invert(matrix); Matrix3x2.Invert(matrix, out var inverseMatrix);
var layerLocal = inverseMatrix.Transform(localPos); var layerLocal = Vector2.Transform(localPos, inverseMatrix);
// Convert to image coordinates // Convert to image coordinates
var layerImagePos = (Vector2i) (layerLocal * EyeManager.PixelsPerMeter * new Vector2(1, -1) + rsiState.Size / 2f); var layerImagePos = (Vector2i) (layerLocal * EyeManager.PixelsPerMeter * new Vector2(1, -1) + rsiState.Size / 2f);

View File

@@ -1,3 +1,4 @@
using System.Numerics;
using Content.Shared.Decals; using Content.Shared.Decals;
using Robust.Client.GameObjects; using Robust.Client.GameObjects;
using Robust.Client.Graphics; using Robust.Client.Graphics;
@@ -113,7 +114,7 @@ namespace Content.Client.Decals.Overlays
handle.DrawTexture(cache.Texture, decal.Coordinates, angle, decal.Color); handle.DrawTexture(cache.Texture, decal.Coordinates, angle, decal.Color);
} }
handle.SetTransform(Matrix3.Identity); handle.SetTransform(Matrix3x2.Identity);
} }
} }
} }

View File

@@ -51,7 +51,7 @@ public sealed class DecalPlacementOverlay : Overlay
var handle = args.WorldHandle; var handle = args.WorldHandle;
handle.SetTransform(worldMatrix); handle.SetTransform(worldMatrix);
var localPos = invMatrix.Transform(mousePos.Position); var localPos = Vector2.Transform(mousePos.Position, invMatrix);
if (snap) if (snap)
{ {
@@ -63,6 +63,6 @@ public sealed class DecalPlacementOverlay : Overlay
var box = new Box2Rotated(aabb, rotation, localPos); var box = new Box2Rotated(aabb, rotation, localPos);
handle.DrawTextureRect(_sprite.Frame0(decal.Sprite), box, color); handle.DrawTextureRect(_sprite.Frame0(decal.Sprite), box, color);
handle.SetTransform(Matrix3.Identity); handle.SetTransform(Matrix3x2.Identity);
} }
} }

View File

@@ -56,8 +56,8 @@ public sealed class DoAfterOverlay : Overlay
// If you use the display UI scale then need to set max(1f, displayscale) because 0 is valid. // If you use the display UI scale then need to set max(1f, displayscale) because 0 is valid.
const float scale = 1f; const float scale = 1f;
var scaleMatrix = Matrix3.CreateScale(new Vector2(scale, scale)); var scaleMatrix = Matrix3Helpers.CreateScale(new Vector2(scale, scale));
var rotationMatrix = Matrix3.CreateRotation(-rotation); var rotationMatrix = Matrix3Helpers.CreateRotation(-rotation);
var curTime = _timing.CurTime; var curTime = _timing.CurTime;
@@ -91,9 +91,9 @@ public sealed class DoAfterOverlay : Overlay
? curTime - _meta.GetPauseTime(uid, meta) ? curTime - _meta.GetPauseTime(uid, meta)
: curTime; : curTime;
var worldMatrix = Matrix3.CreateTranslation(worldPosition); var worldMatrix = Matrix3Helpers.CreateTranslation(worldPosition);
Matrix3.Multiply(scaleMatrix, worldMatrix, out var scaledWorld); var scaledWorld = Matrix3x2.Multiply(scaleMatrix, worldMatrix);
Matrix3.Multiply(rotationMatrix, scaledWorld, out var matty); var matty = Matrix3x2.Multiply(rotationMatrix, scaledWorld);
handle.SetTransform(matty); handle.SetTransform(matty);
var offset = 0f; var offset = 0f;
@@ -151,7 +151,7 @@ public sealed class DoAfterOverlay : Overlay
} }
handle.UseShader(null); handle.UseShader(null);
handle.SetTransform(Matrix3.Identity); handle.SetTransform(Matrix3x2.Identity);
} }
public Color GetProgressColor(float progress, float alpha = 1f) public Color GetProgressColor(float progress, float alpha = 1f)

View File

@@ -48,7 +48,7 @@ public sealed class ExplosionOverlay : Overlay
DrawExplosion(drawHandle, args.WorldBounds, visuals, index, xforms, textures); DrawExplosion(drawHandle, args.WorldBounds, visuals, index, xforms, textures);
} }
drawHandle.SetTransform(Matrix3.Identity); drawHandle.SetTransform(Matrix3x2.Identity);
drawHandle.UseShader(null); drawHandle.UseShader(null);
} }
@@ -78,7 +78,8 @@ public sealed class ExplosionOverlay : Overlay
if (visuals.SpaceTiles == null) if (visuals.SpaceTiles == null)
return; return;
gridBounds = Matrix3.Invert(visuals.SpaceMatrix).TransformBox(worldBounds).Enlarged(2); Matrix3x2.Invert(visuals.SpaceMatrix, out var invSpace);
gridBounds = invSpace.TransformBox(worldBounds).Enlarged(2);
drawHandle.SetTransform(visuals.SpaceMatrix); drawHandle.SetTransform(visuals.SpaceMatrix);
DrawTiles(drawHandle, gridBounds, index, visuals.SpaceTiles, visuals, visuals.SpaceTileSize, textures); DrawTiles(drawHandle, gridBounds, index, visuals.SpaceTiles, visuals, visuals.SpaceTileSize, textures);

View File

@@ -1,4 +1,5 @@
using Content.Shared.FixedPoint; using System.Numerics;
using Content.Shared.FixedPoint;
using Robust.Client.Graphics; using Robust.Client.Graphics;
using Robust.Client.ResourceManagement; using Robust.Client.ResourceManagement;
using Robust.Shared.Enums; using Robust.Shared.Enums;
@@ -73,7 +74,7 @@ public sealed class PuddleOverlay : Overlay
} }
} }
drawHandle.SetTransform(Matrix3.Identity); drawHandle.SetTransform(Matrix3x2.Identity);
} }
private void DrawScreen(in OverlayDrawArgs args) private void DrawScreen(in OverlayDrawArgs args)
@@ -99,7 +100,7 @@ public sealed class PuddleOverlay : Overlay
if (!gridBounds.Contains(centre)) if (!gridBounds.Contains(centre))
continue; continue;
var screenCenter = _eyeManager.WorldToScreen(matrix.Transform(centre)); var screenCenter = _eyeManager.WorldToScreen(Vector2.Transform(centre, matrix));
drawHandle.DrawString(_font, screenCenter, debugOverlayData.CurrentVolume.ToString(), Color.White); drawHandle.DrawString(_font, screenCenter, debugOverlayData.CurrentVolume.ToString(), Color.White);
} }

View File

@@ -101,7 +101,7 @@ public sealed class GridDraggingSystem : SharedGridDraggingSystem
if (!_mapManager.TryFindGridAt(mousePos, out var gridUid, out var grid)) if (!_mapManager.TryFindGridAt(mousePos, out var gridUid, out var grid))
return; return;
StartDragging(gridUid, Transform(gridUid).InvWorldMatrix.Transform(mousePos.Position)); StartDragging(gridUid, Vector2.Transform(mousePos.Position, Transform(gridUid).InvWorldMatrix));
} }
if (!TryComp(_dragging, out TransformComponent? xform)) if (!TryComp(_dragging, out TransformComponent? xform))
@@ -116,7 +116,7 @@ public sealed class GridDraggingSystem : SharedGridDraggingSystem
return; return;
} }
var localToWorld = xform.WorldMatrix.Transform(_localPosition); var localToWorld = Vector2.Transform(_localPosition, xform.WorldMatrix);
if (localToWorld.EqualsApprox(mousePos.Position, 0.01f)) return; if (localToWorld.EqualsApprox(mousePos.Position, 0.01f)) return;

View File

@@ -223,7 +223,7 @@ namespace Content.Client.NPC
foreach (var crumb in chunk.Value) foreach (var crumb in chunk.Value)
{ {
var crumbMapPos = worldMatrix.Transform(_system.GetCoordinate(chunk.Key, crumb.Coordinates)); var crumbMapPos = Vector2.Transform(_system.GetCoordinate(chunk.Key, crumb.Coordinates), worldMatrix);
var distance = (crumbMapPos - mouseWorldPos.Position).Length(); var distance = (crumbMapPos - mouseWorldPos.Position).Length();
if (distance < nearestDistance) if (distance < nearestDistance)
@@ -292,7 +292,7 @@ namespace Content.Client.NPC
foreach (var poly in tile) foreach (var poly in tile)
{ {
if (poly.Box.Contains(invGridMatrix.Transform(mouseWorldPos.Position))) if (poly.Box.Contains(Vector2.Transform(mouseWorldPos.Position, invGridMatrix)))
{ {
nearest = poly; nearest = poly;
break; break;
@@ -488,7 +488,7 @@ namespace Content.Client.NPC
if (neighborMap.MapId != args.MapId) if (neighborMap.MapId != args.MapId)
continue; continue;
neighborPos = invMatrix.Transform(neighborMap.Position); neighborPos = Vector2.Transform(neighborMap.Position, invMatrix);
} }
else else
{ {
@@ -576,7 +576,7 @@ namespace Content.Client.NPC
} }
} }
worldHandle.SetTransform(Matrix3.Identity); worldHandle.SetTransform(Matrix3x2.Identity);
} }
} }
} }

View File

@@ -199,7 +199,7 @@ namespace Content.Client.NodeContainer
} }
handle.SetTransform(Matrix3.Identity); handle.SetTransform(Matrix3x2.Identity);
_gridIndex.Clear(); _gridIndex.Clear();
} }

View File

@@ -42,8 +42,8 @@ public sealed class EntityHealthBarOverlay : Overlay
var xformQuery = _entManager.GetEntityQuery<TransformComponent>(); var xformQuery = _entManager.GetEntityQuery<TransformComponent>();
const float scale = 1f; const float scale = 1f;
var scaleMatrix = Matrix3.CreateScale(new Vector2(scale, scale)); var scaleMatrix = Matrix3Helpers.CreateScale(new Vector2(scale, scale));
var rotationMatrix = Matrix3.CreateRotation(-rotation); var rotationMatrix = Matrix3Helpers.CreateRotation(-rotation);
var query = _entManager.AllEntityQueryEnumerator<MobThresholdsComponent, MobStateComponent, DamageableComponent, SpriteComponent>(); var query = _entManager.AllEntityQueryEnumerator<MobThresholdsComponent, MobStateComponent, DamageableComponent, SpriteComponent>();
while (query.MoveNext(out var uid, while (query.MoveNext(out var uid,
@@ -83,10 +83,10 @@ public sealed class EntityHealthBarOverlay : Overlay
continue; continue;
var worldPosition = _transform.GetWorldPosition(xform); var worldPosition = _transform.GetWorldPosition(xform);
var worldMatrix = Matrix3.CreateTranslation(worldPosition); var worldMatrix = Matrix3Helpers.CreateTranslation(worldPosition);
Matrix3.Multiply(scaleMatrix, worldMatrix, out var scaledWorld); var scaledWorld = Matrix3x2.Multiply(scaleMatrix, worldMatrix);
Matrix3.Multiply(rotationMatrix, scaledWorld, out var matty); var matty = Matrix3x2.Multiply(rotationMatrix, scaledWorld);
handle.SetTransform(matty); handle.SetTransform(matty);
@@ -115,7 +115,7 @@ public sealed class EntityHealthBarOverlay : Overlay
handle.DrawRect(pixelDarken, Black.WithAlpha(128)); handle.DrawRect(pixelDarken, Black.WithAlpha(128));
} }
handle.SetTransform(Matrix3.Identity); handle.SetTransform(Matrix3x2.Identity);
} }
/// <summary> /// <summary>

View File

@@ -7,7 +7,7 @@ namespace Content.Client.Overlays;
public sealed partial class StencilOverlay public sealed partial class StencilOverlay
{ {
private void DrawRestrictedRange(in OverlayDrawArgs args, RestrictedRangeComponent rangeComp, Matrix3 invMatrix) private void DrawRestrictedRange(in OverlayDrawArgs args, RestrictedRangeComponent rangeComp, Matrix3x2 invMatrix)
{ {
var worldHandle = args.WorldHandle; var worldHandle = args.WorldHandle;
var renderScale = args.Viewport.RenderScale.X; var renderScale = args.Viewport.RenderScale.X;
@@ -16,7 +16,7 @@ public sealed partial class StencilOverlay
var length = zoom.X; var length = zoom.X;
var bufferRange = MathF.Min(10f, rangeComp.Range); var bufferRange = MathF.Min(10f, rangeComp.Range);
var pixelCenter = invMatrix.Transform(rangeComp.Origin); var pixelCenter = Vector2.Transform(rangeComp.Origin, invMatrix);
// Something something offset? // Something something offset?
var vertical = args.Viewport.Size.Y; var vertical = args.Viewport.Size.Y;
@@ -44,7 +44,7 @@ public sealed partial class StencilOverlay
worldHandle.DrawRect(localAABB, Color.White); worldHandle.DrawRect(localAABB, Color.White);
}, Color.Transparent); }, Color.Transparent);
worldHandle.SetTransform(Matrix3.Identity); worldHandle.SetTransform(Matrix3x2.Identity);
worldHandle.UseShader(_protoManager.Index<ShaderPrototype>("StencilMask").Instance()); worldHandle.UseShader(_protoManager.Index<ShaderPrototype>("StencilMask").Instance());
worldHandle.DrawTextureRect(_blep!.Texture, worldBounds); worldHandle.DrawTextureRect(_blep!.Texture, worldBounds);
var curTime = _timing.RealTime; var curTime = _timing.RealTime;

View File

@@ -10,7 +10,7 @@ public sealed partial class StencilOverlay
{ {
private List<Entity<MapGridComponent>> _grids = new(); private List<Entity<MapGridComponent>> _grids = new();
private void DrawWeather(in OverlayDrawArgs args, WeatherPrototype weatherProto, float alpha, Matrix3 invMatrix) private void DrawWeather(in OverlayDrawArgs args, WeatherPrototype weatherProto, float alpha, Matrix3x2 invMatrix)
{ {
var worldHandle = args.WorldHandle; var worldHandle = args.WorldHandle;
var mapId = args.MapId; var mapId = args.MapId;
@@ -32,7 +32,7 @@ public sealed partial class StencilOverlay
foreach (var grid in _grids) foreach (var grid in _grids)
{ {
var matrix = _transform.GetWorldMatrix(grid, xformQuery); var matrix = _transform.GetWorldMatrix(grid, xformQuery);
Matrix3.Multiply(in matrix, in invMatrix, out var matty); var matty = Matrix3x2.Multiply(matrix, invMatrix);
worldHandle.SetTransform(matty); worldHandle.SetTransform(matty);
foreach (var tile in grid.Comp.GetTilesIntersecting(worldAABB)) foreach (var tile in grid.Comp.GetTilesIntersecting(worldAABB))
@@ -52,7 +52,7 @@ public sealed partial class StencilOverlay
}, Color.Transparent); }, Color.Transparent);
worldHandle.SetTransform(Matrix3.Identity); worldHandle.SetTransform(Matrix3x2.Identity);
worldHandle.UseShader(_protoManager.Index<ShaderPrototype>("StencilMask").Instance()); worldHandle.UseShader(_protoManager.Index<ShaderPrototype>("StencilMask").Instance());
worldHandle.DrawTextureRect(_blep!.Texture, worldBounds); worldHandle.DrawTextureRect(_blep!.Texture, worldBounds);
var curTime = _timing.RealTime; var curTime = _timing.RealTime;
@@ -62,7 +62,7 @@ public sealed partial class StencilOverlay
worldHandle.UseShader(_protoManager.Index<ShaderPrototype>("StencilDraw").Instance()); worldHandle.UseShader(_protoManager.Index<ShaderPrototype>("StencilDraw").Instance());
_parallax.DrawParallax(worldHandle, worldAABB, sprite, curTime, position, Vector2.Zero, modulate: (weatherProto.Color ?? Color.White).WithAlpha(alpha)); _parallax.DrawParallax(worldHandle, worldAABB, sprite, curTime, position, Vector2.Zero, modulate: (weatherProto.Color ?? Color.White).WithAlpha(alpha));
worldHandle.SetTransform(Matrix3.Identity); worldHandle.SetTransform(Matrix3x2.Identity);
worldHandle.UseShader(null); worldHandle.UseShader(null);
} }
} }

View File

@@ -1,3 +1,4 @@
using System.Numerics;
using Content.Client.Parallax; using Content.Client.Parallax;
using Content.Client.Weather; using Content.Client.Weather;
using Content.Shared.Salvage; using Content.Shared.Salvage;
@@ -72,6 +73,6 @@ public sealed partial class StencilOverlay : Overlay
} }
args.WorldHandle.UseShader(null); args.WorldHandle.UseShader(null);
args.WorldHandle.SetTransform(Matrix3.Identity); args.WorldHandle.SetTransform(Matrix3x2.Identity);
} }
} }

View File

@@ -50,7 +50,7 @@ public sealed partial class StampLabel : Label
base.Draw(handle); base.Draw(handle);
// Restore a sane transform+shader // Restore a sane transform+shader
handle.SetTransform(Matrix3.Identity); handle.SetTransform(Matrix3x2.Identity);
handle.UseShader(null); handle.UseShader(null);
} }
} }

View File

@@ -53,7 +53,7 @@ public sealed partial class StampWidget : PanelContainer
base.Draw(handle); base.Draw(handle);
// Restore a sane transform+shader // Restore a sane transform+shader
handle.SetTransform(Matrix3.Identity); handle.SetTransform(Matrix3x2.Identity);
handle.UseShader(null); handle.UseShader(null);
} }
} }

View File

@@ -218,7 +218,7 @@ public partial class NavMapControl : MapGridControl
// Convert to a world position // Convert to a world position
var unscaledPosition = (localPosition - MidPointVector) / MinimapScale; var unscaledPosition = (localPosition - MidPointVector) / MinimapScale;
var worldPosition = _transformSystem.GetWorldMatrix(_xform).Transform(new Vector2(unscaledPosition.X, -unscaledPosition.Y) + offset); var worldPosition = Vector2.Transform(new Vector2(unscaledPosition.X, -unscaledPosition.Y) + offset, _transformSystem.GetWorldMatrix(_xform));
// Find closest tracked entity in range // Find closest tracked entity in range
var closestEntity = NetEntity.Invalid; var closestEntity = NetEntity.Invalid;
@@ -401,7 +401,7 @@ public partial class NavMapControl : MapGridControl
if (mapPos.MapId != MapId.Nullspace) if (mapPos.MapId != MapId.Nullspace)
{ {
var position = _transformSystem.GetInvWorldMatrix(_xform).Transform(mapPos.Position) - offset; var position = Vector2.Transform(mapPos.Position, _transformSystem.GetInvWorldMatrix(_xform)) - offset;
position = ScalePosition(new Vector2(position.X, -position.Y)); position = ScalePosition(new Vector2(position.X, -position.Y));
handle.DrawCircle(position, float.Sqrt(MinimapScale) * 2f, value.Color); handle.DrawCircle(position, float.Sqrt(MinimapScale) * 2f, value.Color);
@@ -422,7 +422,7 @@ public partial class NavMapControl : MapGridControl
if (mapPos.MapId != MapId.Nullspace) if (mapPos.MapId != MapId.Nullspace)
{ {
var position = _transformSystem.GetInvWorldMatrix(_xform).Transform(mapPos.Position) - offset; var position = Vector2.Transform(mapPos.Position, _transformSystem.GetInvWorldMatrix(_xform)) - offset;
position = ScalePosition(new Vector2(position.X, -position.Y)); position = ScalePosition(new Vector2(position.X, -position.Y));
var scalingCoefficient = MinmapScaleModifier * float.Sqrt(MinimapScale); var scalingCoefficient = MinmapScaleModifier * float.Sqrt(MinimapScale);

View File

@@ -1,3 +1,4 @@
using System.Numerics;
using Content.Shared.Examine; using Content.Shared.Examine;
using Robust.Client.Graphics; using Robust.Client.Graphics;
using Robust.Client.Player; using Robust.Client.Player;
@@ -55,7 +56,7 @@ public sealed class PopupOverlay : Overlay
if (args.ViewportControl == null) if (args.ViewportControl == null)
return; return;
args.DrawingHandle.SetTransform(Matrix3.Identity); args.DrawingHandle.SetTransform(Matrix3x2.Identity);
args.DrawingHandle.UseShader(_shader); args.DrawingHandle.UseShader(_shader);
var scale = _configManager.GetCVar(CVars.DisplayUIScale); var scale = _configManager.GetCVar(CVars.DisplayUIScale);
@@ -90,7 +91,7 @@ public sealed class PopupOverlay : Overlay
e => e == popup.InitialPos.EntityId || e == ourEntity, entMan: _entManager)) e => e == popup.InitialPos.EntityId || e == ourEntity, entMan: _entManager))
continue; continue;
var pos = matrix.Transform(mapPos.Position); var pos = Vector2.Transform(mapPos.Position, matrix);
_controller.DrawPopup(popup, worldHandle, pos, scale); _controller.DrawPopup(popup, worldHandle, pos, scale);
} }
} }

View File

@@ -1,3 +1,4 @@
using System.Numerics;
using Content.Shared.Shuttles.Events; using Content.Shared.Shuttles.Events;
using Content.Shared.Shuttles.Systems; using Content.Shared.Shuttles.Systems;
using Robust.Client.Graphics; using Robust.Client.Graphics;
@@ -75,6 +76,6 @@ public sealed class EmergencyShuttleOverlay : Overlay
args.WorldHandle.SetTransform(xform.WorldMatrix); args.WorldHandle.SetTransform(xform.WorldMatrix);
args.WorldHandle.DrawRect(Position.Value, Color.Red.WithAlpha(100)); args.WorldHandle.DrawRect(Position.Value, Color.Red.WithAlpha(100));
args.WorldHandle.SetTransform(Matrix3.Identity); args.WorldHandle.SetTransform(Matrix3x2.Identity);
} }
} }

View File

@@ -1,3 +1,4 @@
using System.Numerics;
using Content.Client.UserInterface.Controls; using Content.Client.UserInterface.Controls;
using Content.Shared.Shuttles.Components; using Content.Shared.Shuttles.Components;
using Robust.Client.AutoGenerated; using Robust.Client.AutoGenerated;
@@ -115,7 +116,7 @@ public partial class BaseShuttleControl : MapGridControl
} }
} }
protected void DrawGrid(DrawingHandleScreen handle, Matrix3 matrix, Entity<MapGridComponent> grid, Color color, float alpha = 0.01f) protected void DrawGrid(DrawingHandleScreen handle, Matrix3x2 matrix, Entity<MapGridComponent> grid, Color color, float alpha = 0.01f)
{ {
var rator = Maps.GetAllTilesEnumerator(grid.Owner, grid.Comp); var rator = Maps.GetAllTilesEnumerator(grid.Owner, grid.Comp);
var minimapScale = MinimapScale; var minimapScale = MinimapScale;
@@ -289,7 +290,7 @@ public partial class BaseShuttleControl : MapGridControl
public float MinimapScale; public float MinimapScale;
public Vector2 MidPoint; public Vector2 MidPoint;
public Matrix3 Matrix; public Matrix3x2 Matrix;
public List<Vector2> Vertices; public List<Vector2> Vertices;
public Vector2[] ScaledVertices; public Vector2[] ScaledVertices;
@@ -297,7 +298,7 @@ public partial class BaseShuttleControl : MapGridControl
public void Execute(int index) public void Execute(int index)
{ {
var vert = Vertices[index]; var vert = Vertices[index];
var adjustedVert = Matrix.Transform(vert); var adjustedVert = Vector2.Transform(vert, Matrix);
adjustedVert = adjustedVert with { Y = -adjustedVert.Y }; adjustedVert = adjustedVert with { Y = -adjustedVert.Y };
var scaledVert = ScalePosition(adjustedVert, MinimapScale, MidPoint); var scaledVert = ScalePosition(adjustedVert, MinimapScale, MidPoint);

View File

@@ -1,3 +1,4 @@
using System.Numerics;
using Content.Shared.Shuttles.BUIStates; using Content.Shared.Shuttles.BUIStates;
using Robust.Client.AutoGenerated; using Robust.Client.AutoGenerated;
using Robust.Client.Graphics; using Robust.Client.Graphics;
@@ -68,7 +69,7 @@ public sealed partial class NavScreen : BoxContainer
} }
var (_, worldRot, worldMatrix) = _xformSystem.GetWorldPositionRotationMatrix(gridXform); var (_, worldRot, worldMatrix) = _xformSystem.GetWorldPositionRotationMatrix(gridXform);
var worldPos = worldMatrix.Transform(gridBody.LocalCenter); var worldPos = Vector2.Transform(gridBody.LocalCenter, worldMatrix);
// Get the positive reduced angle. // Get the positive reduced angle.
var displayRot = -worldRot.Reduced(); var displayRot = -worldRot.Reduced();

View File

@@ -108,10 +108,10 @@ public sealed partial class ShuttleDockControl : BaseShuttleControl
var gridNent = EntManager.GetNetEntity(GridEntity); var gridNent = EntManager.GetNetEntity(GridEntity);
var mapPos = _xformSystem.ToMapCoordinates(_coordinates.Value); var mapPos = _xformSystem.ToMapCoordinates(_coordinates.Value);
var ourGridMatrix = _xformSystem.GetWorldMatrix(gridXform.Owner); var ourGridMatrix = _xformSystem.GetWorldMatrix(gridXform.Owner);
var dockMatrix = Matrix3.CreateTransform(_coordinates.Value.Position, Angle.Zero); var dockMatrix = Matrix3Helpers.CreateTransform(_coordinates.Value.Position, Angle.Zero);
Matrix3.Multiply(dockMatrix, ourGridMatrix, out var offsetMatrix); var worldFromDock = Matrix3x2.Multiply(dockMatrix, ourGridMatrix);
offsetMatrix = offsetMatrix.Invert(); Matrix3x2.Invert(worldFromDock, out var offsetMatrix);
// Draw nearby grids // Draw nearby grids
var controlBounds = PixelSizeBox; var controlBounds = PixelSizeBox;
@@ -137,7 +137,7 @@ public sealed partial class ShuttleDockControl : BaseShuttleControl
continue; continue;
var gridMatrix = _xformSystem.GetWorldMatrix(grid.Owner); var gridMatrix = _xformSystem.GetWorldMatrix(grid.Owner);
Matrix3.Multiply(in gridMatrix, in offsetMatrix, out var matty); var matty = Matrix3x2.Multiply(gridMatrix, offsetMatrix);
var color = _shuttles.GetIFFColor(grid.Owner, grid.Owner == GridEntity, component: iffComp); var color = _shuttles.GetIFFColor(grid.Owner, grid.Owner == GridEntity, component: iffComp);
DrawGrid(handle, matty, grid, color); DrawGrid(handle, matty, grid, color);
@@ -151,23 +151,23 @@ public sealed partial class ShuttleDockControl : BaseShuttleControl
if (ViewedDock == dock.Entity) if (ViewedDock == dock.Entity)
continue; continue;
var position = matty.Transform(dock.Coordinates.Position); var position = Vector2.Transform(dock.Coordinates.Position, matty);
var otherDockRotation = Matrix3.CreateRotation(dock.Angle); var otherDockRotation = Matrix3Helpers.CreateRotation(dock.Angle);
var scaledPos = ScalePosition(position with {Y = -position.Y}); var scaledPos = ScalePosition(position with {Y = -position.Y});
if (!controlBounds.Contains(scaledPos.Floored())) if (!controlBounds.Contains(scaledPos.Floored()))
continue; continue;
// Draw the dock's collision // Draw the dock's collision
var collisionBL = matty.Transform(dock.Coordinates.Position + var collisionBL = Vector2.Transform(dock.Coordinates.Position +
otherDockRotation.Transform(new Vector2(-0.2f, -0.7f))); Vector2.Transform(new Vector2(-0.2f, -0.7f), otherDockRotation), matty);
var collisionBR = matty.Transform(dock.Coordinates.Position + var collisionBR = Vector2.Transform(dock.Coordinates.Position +
otherDockRotation.Transform(new Vector2(0.2f, -0.7f))); Vector2.Transform(new Vector2(0.2f, -0.7f), otherDockRotation), matty);
var collisionTR = matty.Transform(dock.Coordinates.Position + var collisionTR = Vector2.Transform(dock.Coordinates.Position +
otherDockRotation.Transform(new Vector2(0.2f, -0.5f))); Vector2.Transform(new Vector2(0.2f, -0.5f), otherDockRotation), matty);
var collisionTL = matty.Transform(dock.Coordinates.Position + var collisionTL = Vector2.Transform(dock.Coordinates.Position +
otherDockRotation.Transform(new Vector2(-0.2f, -0.5f))); Vector2.Transform(new Vector2(-0.2f, -0.5f), otherDockRotation), matty);
var verts = new[] var verts = new[]
{ {
@@ -195,10 +195,10 @@ public sealed partial class ShuttleDockControl : BaseShuttleControl
handle.DrawPrimitives(DrawPrimitiveTopology.LineList, verts, otherDockConnection); handle.DrawPrimitives(DrawPrimitiveTopology.LineList, verts, otherDockConnection);
// Draw the dock itself // Draw the dock itself
var dockBL = matty.Transform(dock.Coordinates.Position + new Vector2(-0.5f, -0.5f)); var dockBL = Vector2.Transform(dock.Coordinates.Position + new Vector2(-0.5f, -0.5f), matty);
var dockBR = matty.Transform(dock.Coordinates.Position + new Vector2(0.5f, -0.5f)); var dockBR = Vector2.Transform(dock.Coordinates.Position + new Vector2(0.5f, -0.5f), matty);
var dockTR = matty.Transform(dock.Coordinates.Position + new Vector2(0.5f, 0.5f)); var dockTR = Vector2.Transform(dock.Coordinates.Position + new Vector2(0.5f, 0.5f), matty);
var dockTL = matty.Transform(dock.Coordinates.Position + new Vector2(-0.5f, 0.5f)); var dockTL = Vector2.Transform(dock.Coordinates.Position + new Vector2(-0.5f, 0.5f), matty);
verts = new[] verts = new[]
{ {
@@ -308,14 +308,14 @@ public sealed partial class ShuttleDockControl : BaseShuttleControl
// Draw the dock's collision // Draw the dock's collision
var invertedPosition = Vector2.Zero; var invertedPosition = Vector2.Zero;
invertedPosition.Y = -invertedPosition.Y; invertedPosition.Y = -invertedPosition.Y;
var rotation = Matrix3.CreateRotation(-_angle.Value + MathF.PI); var rotation = Matrix3Helpers.CreateRotation(-_angle.Value + MathF.PI);
var ourDockConnection = new UIBox2( var ourDockConnection = new UIBox2(
ScalePosition(rotation.Transform(new Vector2(-0.2f, -0.7f))), ScalePosition(Vector2.Transform(new Vector2(-0.2f, -0.7f), rotation)),
ScalePosition(rotation.Transform(new Vector2(0.2f, -0.5f)))); ScalePosition(Vector2.Transform(new Vector2(0.2f, -0.5f), rotation)));
var ourDock = new UIBox2( var ourDock = new UIBox2(
ScalePosition(rotation.Transform(new Vector2(-0.5f, 0.5f))), ScalePosition(Vector2.Transform(new Vector2(-0.5f, 0.5f), rotation)),
ScalePosition(rotation.Transform(new Vector2(0.5f, -0.5f)))); ScalePosition(Vector2.Transform(new Vector2(0.5f, -0.5f), rotation)));
var dockColor = Color.Magenta; var dockColor = Color.Magenta;
var connectionColor = Color.Pink; var connectionColor = Color.Pink;

View File

@@ -114,7 +114,7 @@ public sealed partial class ShuttleMapControl : BaseShuttleControl
var beaconsOnly = EntManager.TryGetComponent(mapUid, out FTLDestinationComponent? destComp) && var beaconsOnly = EntManager.TryGetComponent(mapUid, out FTLDestinationComponent? destComp) &&
destComp.BeaconsOnly; destComp.BeaconsOnly;
var mapTransform = Matrix3.CreateInverseTransform(Offset, Angle.Zero); var mapTransform = Matrix3Helpers.CreateInverseTransform(Offset, Angle.Zero);
if (beaconsOnly && TryGetBeacon(_beacons, mapTransform, args.RelativePixelPosition, PixelRect, out var foundBeacon, out _)) if (beaconsOnly && TryGetBeacon(_beacons, mapTransform, args.RelativePixelPosition, PixelRect, out var foundBeacon, out _))
{ {
@@ -203,7 +203,7 @@ public sealed partial class ShuttleMapControl : BaseShuttleControl
/// </summary> /// </summary>
/// <param name="mapObjects"></param> /// <param name="mapObjects"></param>
/// <returns></returns> /// <returns></returns>
private List<IMapObject> GetViewportMapObjects(Matrix3 matty, List<IMapObject> mapObjects) private List<IMapObject> GetViewportMapObjects(Matrix3x2 matty, List<IMapObject> mapObjects)
{ {
var results = new List<IMapObject>(); var results = new List<IMapObject>();
var enlargement = new Vector2i((int) (16 * UIScale), (int) (16 * UIScale)); var enlargement = new Vector2i((int) (16 * UIScale), (int) (16 * UIScale));
@@ -217,7 +217,7 @@ public sealed partial class ShuttleMapControl : BaseShuttleControl
var mapCoords = _shuttles.GetMapCoordinates(mapObj); var mapCoords = _shuttles.GetMapCoordinates(mapObj);
var relativePos = matty.Transform(mapCoords.Position); var relativePos = Vector2.Transform(mapCoords.Position, matty);
relativePos = relativePos with { Y = -relativePos.Y }; relativePos = relativePos with { Y = -relativePos.Y };
var uiPosition = ScalePosition(relativePos); var uiPosition = ScalePosition(relativePos);
@@ -250,7 +250,7 @@ public sealed partial class ShuttleMapControl : BaseShuttleControl
DrawParallax(handle); DrawParallax(handle);
var viewedMapUid = _mapManager.GetMapEntityId(ViewingMap); var viewedMapUid = _mapManager.GetMapEntityId(ViewingMap);
var matty = Matrix3.CreateInverseTransform(Offset, Angle.Zero); var matty = Matrix3Helpers.CreateInverseTransform(Offset, Angle.Zero);
var realTime = _timing.RealTime; var realTime = _timing.RealTime;
var viewBox = new Box2(Offset - WorldRangeVector, Offset + WorldRangeVector); var viewBox = new Box2(Offset - WorldRangeVector, Offset + WorldRangeVector);
var viewportObjects = GetViewportMapObjects(matty, mapObjects); var viewportObjects = GetViewportMapObjects(matty, mapObjects);
@@ -267,7 +267,7 @@ public sealed partial class ShuttleMapControl : BaseShuttleControl
var (gridPos, gridRot) = _xformSystem.GetWorldPositionRotation(shuttleXform); var (gridPos, gridRot) = _xformSystem.GetWorldPositionRotation(shuttleXform);
gridPos = Maps.GetGridPosition((gridUid, gridPhysics), gridPos, gridRot); gridPos = Maps.GetGridPosition((gridUid, gridPhysics), gridPos, gridRot);
var gridRelativePos = matty.Transform(gridPos); var gridRelativePos = Vector2.Transform(gridPos, matty);
gridRelativePos = gridRelativePos with { Y = -gridRelativePos.Y }; gridRelativePos = gridRelativePos with { Y = -gridRelativePos.Y };
var gridUiPos = ScalePosition(gridRelativePos); var gridUiPos = ScalePosition(gridRelativePos);
@@ -296,7 +296,7 @@ public sealed partial class ShuttleMapControl : BaseShuttleControl
continue; continue;
} }
var adjustedPos = matty.Transform(mapCoords.Position); var adjustedPos = Vector2.Transform(mapCoords.Position, matty);
var localPos = ScalePosition(adjustedPos with { Y = -adjustedPos.Y}); var localPos = ScalePosition(adjustedPos with { Y = -adjustedPos.Y});
handle.DrawCircle(localPos, exclusion.Range * MinimapScale, exclusionColor.WithAlpha(0.05f)); handle.DrawCircle(localPos, exclusion.Range * MinimapScale, exclusionColor.WithAlpha(0.05f));
handle.DrawCircle(localPos, exclusion.Range * MinimapScale, exclusionColor, filled: false); handle.DrawCircle(localPos, exclusion.Range * MinimapScale, exclusionColor, filled: false);
@@ -319,7 +319,7 @@ public sealed partial class ShuttleMapControl : BaseShuttleControl
foreach (var (beaconName, coords, mapO) in GetBeacons(viewportObjects, matty, controlLocalBounds)) foreach (var (beaconName, coords, mapO) in GetBeacons(viewportObjects, matty, controlLocalBounds))
{ {
var localPos = matty.Transform(coords.Position); var localPos = Vector2.Transform(coords.Position, matty);
localPos = localPos with { Y = -localPos.Y }; localPos = localPos with { Y = -localPos.Y };
var beaconUiPos = ScalePosition(localPos); var beaconUiPos = ScalePosition(localPos);
var mapObject = GetMapObject(localPos, Angle.Zero, scale: 0.75f, scalePosition: true); var mapObject = GetMapObject(localPos, Angle.Zero, scale: 0.75f, scalePosition: true);
@@ -360,7 +360,7 @@ public sealed partial class ShuttleMapControl : BaseShuttleControl
var (gridPos, gridRot) = _xformSystem.GetWorldPositionRotation(grid.Owner); var (gridPos, gridRot) = _xformSystem.GetWorldPositionRotation(grid.Owner);
gridPos = Maps.GetGridPosition((grid, gridPhysics), gridPos, gridRot); gridPos = Maps.GetGridPosition((grid, gridPhysics), gridPos, gridRot);
var gridRelativePos = matty.Transform(gridPos); var gridRelativePos = Vector2.Transform(gridPos, matty);
gridRelativePos = gridRelativePos with { Y = -gridRelativePos.Y }; gridRelativePos = gridRelativePos with { Y = -gridRelativePos.Y };
var gridUiPos = ScalePosition(gridRelativePos); var gridUiPos = ScalePosition(gridRelativePos);
@@ -439,7 +439,7 @@ public sealed partial class ShuttleMapControl : BaseShuttleControl
var color = ftlFree ? Color.LimeGreen : Color.Magenta; var color = ftlFree ? Color.LimeGreen : Color.Magenta;
var gridRelativePos = matty.Transform(gridPos); var gridRelativePos = Vector2.Transform(gridPos, matty);
gridRelativePos = gridRelativePos with { Y = -gridRelativePos.Y }; gridRelativePos = gridRelativePos with { Y = -gridRelativePos.Y };
var gridUiPos = ScalePosition(gridRelativePos); var gridUiPos = ScalePosition(gridRelativePos);
@@ -512,7 +512,7 @@ public sealed partial class ShuttleMapControl : BaseShuttleControl
/// <summary> /// <summary>
/// Returns the beacons that intersect the viewport. /// Returns the beacons that intersect the viewport.
/// </summary> /// </summary>
private IEnumerable<(string Beacon, MapCoordinates Coordinates, IMapObject MapObject)> GetBeacons(List<IMapObject> mapObjs, Matrix3 mapTransform, UIBox2i area) private IEnumerable<(string Beacon, MapCoordinates Coordinates, IMapObject MapObject)> GetBeacons(List<IMapObject> mapObjs, Matrix3x2 mapTransform, UIBox2i area)
{ {
foreach (var mapO in mapObjs) foreach (var mapO in mapObjs)
{ {
@@ -520,7 +520,7 @@ public sealed partial class ShuttleMapControl : BaseShuttleControl
continue; continue;
var beaconCoords = EntManager.GetCoordinates(beacon.Coordinates).ToMap(EntManager, _xformSystem); var beaconCoords = EntManager.GetCoordinates(beacon.Coordinates).ToMap(EntManager, _xformSystem);
var position = mapTransform.Transform(beaconCoords.Position); var position = Vector2.Transform(beaconCoords.Position, mapTransform);
var localPos = ScalePosition(position with {Y = -position.Y}); var localPos = ScalePosition(position with {Y = -position.Y});
// If beacon not on screen then ignore it. // If beacon not on screen then ignore it.
@@ -557,7 +557,7 @@ public sealed partial class ShuttleMapControl : BaseShuttleControl
return mapObj; return mapObj;
} }
private bool TryGetBeacon(IEnumerable<IMapObject> mapObjects, Matrix3 mapTransform, Vector2 mousePos, UIBox2i area, out ShuttleBeaconObject foundBeacon, out Vector2 foundLocalPos) private bool TryGetBeacon(IEnumerable<IMapObject> mapObjects, Matrix3x2 mapTransform, Vector2 mousePos, UIBox2i area, out ShuttleBeaconObject foundBeacon, out Vector2 foundLocalPos)
{ {
// In pixels // In pixels
const float BeaconSnapRange = 32f; const float BeaconSnapRange = 32f;
@@ -579,7 +579,7 @@ public sealed partial class ShuttleMapControl : BaseShuttleControl
if (!_shuttles.CanFTLBeacon(beaconObj.Coordinates)) if (!_shuttles.CanFTLBeacon(beaconObj.Coordinates))
continue; continue;
var position = mapTransform.Transform(beaconCoords.Position); var position = Vector2.Transform(beaconCoords.Position, mapTransform);
var localPos = ScalePosition(position with {Y = -position.Y}); var localPos = ScalePosition(position with {Y = -position.Y});
// If beacon not on screen then ignore it. // If beacon not on screen then ignore it.

View File

@@ -137,10 +137,10 @@ public sealed partial class ShuttleNavControl : BaseShuttleControl
var mapPos = _transform.ToMapCoordinates(_coordinates.Value); var mapPos = _transform.ToMapCoordinates(_coordinates.Value);
var offset = _coordinates.Value.Position; var offset = _coordinates.Value.Position;
var posMatrix = Matrix3.CreateTransform(offset, _rotation.Value); var posMatrix = Matrix3Helpers.CreateTransform(offset, _rotation.Value);
var (_, ourEntRot, ourEntMatrix) = _transform.GetWorldPositionRotationMatrix(_coordinates.Value.EntityId); var (_, ourEntRot, ourEntMatrix) = _transform.GetWorldPositionRotationMatrix(_coordinates.Value.EntityId);
Matrix3.Multiply(posMatrix, ourEntMatrix, out var ourWorldMatrix); var ourWorldMatrix = Matrix3x2.Multiply(posMatrix, ourEntMatrix);
var ourWorldMatrixInvert = ourWorldMatrix.Invert(); Matrix3x2.Invert(ourWorldMatrix, out var ourWorldMatrixInvert);
// Draw our grid in detail // Draw our grid in detail
var ourGridId = xform.GridUid; var ourGridId = xform.GridUid;
@@ -148,7 +148,7 @@ public sealed partial class ShuttleNavControl : BaseShuttleControl
fixturesQuery.HasComponent(ourGridId.Value)) fixturesQuery.HasComponent(ourGridId.Value))
{ {
var ourGridMatrix = _transform.GetWorldMatrix(ourGridId.Value); var ourGridMatrix = _transform.GetWorldMatrix(ourGridId.Value);
Matrix3.Multiply(in ourGridMatrix, in ourWorldMatrixInvert, out var matrix); var matrix = Matrix3x2.Multiply(ourGridMatrix, ourWorldMatrixInvert);
var color = _shuttles.GetIFFColor(ourGridId.Value, self: true); var color = _shuttles.GetIFFColor(ourGridId.Value, self: true);
DrawGrid(handle, matrix, (ourGridId.Value, ourGrid), color); DrawGrid(handle, matrix, (ourGridId.Value, ourGrid), color);
@@ -194,7 +194,7 @@ public sealed partial class ShuttleNavControl : BaseShuttleControl
continue; continue;
var gridMatrix = _transform.GetWorldMatrix(gUid); var gridMatrix = _transform.GetWorldMatrix(gUid);
Matrix3.Multiply(in gridMatrix, in ourWorldMatrixInvert, out var matty); var matty = Matrix3x2.Multiply(gridMatrix, ourWorldMatrixInvert);
var color = _shuttles.GetIFFColor(grid, self: false, iff); var color = _shuttles.GetIFFColor(grid, self: false, iff);
// Others default: // Others default:
@@ -207,7 +207,7 @@ public sealed partial class ShuttleNavControl : BaseShuttleControl
{ {
var gridBounds = grid.Comp.LocalAABB; var gridBounds = grid.Comp.LocalAABB;
var gridCentre = matty.Transform(gridBody.LocalCenter); var gridCentre = Vector2.Transform(gridBody.LocalCenter, matty);
gridCentre.Y = -gridCentre.Y; gridCentre.Y = -gridCentre.Y;
var distance = gridCentre.Length(); var distance = gridCentre.Length();
var labelText = Loc.GetString("shuttle-console-iff-label", ("name", labelName), var labelText = Loc.GetString("shuttle-console-iff-label", ("name", labelName),
@@ -242,7 +242,7 @@ public sealed partial class ShuttleNavControl : BaseShuttleControl
} }
} }
private void DrawDocks(DrawingHandleScreen handle, EntityUid uid, Matrix3 matrix) private void DrawDocks(DrawingHandleScreen handle, EntityUid uid, Matrix3x2 matrix)
{ {
if (!ShowDocks) if (!ShowDocks)
return; return;
@@ -255,7 +255,7 @@ public sealed partial class ShuttleNavControl : BaseShuttleControl
foreach (var state in docks) foreach (var state in docks)
{ {
var position = state.Coordinates.Position; var position = state.Coordinates.Position;
var uiPosition = matrix.Transform(position); var uiPosition = Vector2.Transform(position, matrix);
if (uiPosition.Length() > (WorldRange * 2f) - DockScale) if (uiPosition.Length() > (WorldRange * 2f) - DockScale)
continue; continue;
@@ -264,10 +264,10 @@ public sealed partial class ShuttleNavControl : BaseShuttleControl
var verts = new[] var verts = new[]
{ {
matrix.Transform(position + new Vector2(-DockScale, -DockScale)), Vector2.Transform(position + new Vector2(-DockScale, -DockScale), matrix),
matrix.Transform(position + new Vector2(DockScale, -DockScale)), Vector2.Transform(position + new Vector2(DockScale, -DockScale), matrix),
matrix.Transform(position + new Vector2(DockScale, DockScale)), Vector2.Transform(position + new Vector2(DockScale, DockScale), matrix),
matrix.Transform(position + new Vector2(-DockScale, DockScale)), Vector2.Transform(position + new Vector2(-DockScale, DockScale), matrix),
}; };
for (var i = 0; i < verts.Length; i++) for (var i = 0; i < verts.Length; i++)

View File

@@ -39,8 +39,8 @@ public sealed class StatusIconOverlay : Overlay
var eyeRot = args.Viewport.Eye?.Rotation ?? default; var eyeRot = args.Viewport.Eye?.Rotation ?? default;
var xformQuery = _entity.GetEntityQuery<TransformComponent>(); var xformQuery = _entity.GetEntityQuery<TransformComponent>();
var scaleMatrix = Matrix3.CreateScale(new Vector2(1, 1)); var scaleMatrix = Matrix3Helpers.CreateScale(new Vector2(1, 1));
var rotationMatrix = Matrix3.CreateRotation(-eyeRot); var rotationMatrix = Matrix3Helpers.CreateRotation(-eyeRot);
var query = _entity.AllEntityQueryEnumerator<StatusIconComponent, SpriteComponent, TransformComponent, MetaDataComponent>(); var query = _entity.AllEntityQueryEnumerator<StatusIconComponent, SpriteComponent, TransformComponent, MetaDataComponent>();
while (query.MoveNext(out var uid, out var comp, out var sprite, out var xform, out var meta)) while (query.MoveNext(out var uid, out var comp, out var sprite, out var xform, out var meta))
@@ -59,9 +59,9 @@ public sealed class StatusIconOverlay : Overlay
if (icons.Count == 0) if (icons.Count == 0)
continue; continue;
var worldMatrix = Matrix3.CreateTranslation(worldPos); var worldMatrix = Matrix3Helpers.CreateTranslation(worldPos);
Matrix3.Multiply(scaleMatrix, worldMatrix, out var scaledWorld); var scaledWorld = Matrix3x2.Multiply(scaleMatrix, worldMatrix);
Matrix3.Multiply(rotationMatrix, scaledWorld, out var matty); var matty = Matrix3x2.Multiply(rotationMatrix, scaledWorld);
handle.SetTransform(matty); handle.SetTransform(matty);
var countL = 0; var countL = 0;

View File

@@ -1,4 +1,5 @@
using System.Linq; using System.Linq;
using System.Numerics;
using Content.Client.Animations; using Content.Client.Animations;
using Content.Shared.Hands; using Content.Shared.Hands;
using Content.Shared.Storage; using Content.Shared.Storage;
@@ -149,7 +150,7 @@ public sealed class StorageSystem : SharedStorageSystem
} }
var finalMapPos = finalCoords.ToMapPos(EntityManager, TransformSystem); var finalMapPos = finalCoords.ToMapPos(EntityManager, TransformSystem);
var finalPos = TransformSystem.GetInvWorldMatrix(initialCoords.EntityId).Transform(finalMapPos); var finalPos = Vector2.Transform(finalMapPos, TransformSystem.GetInvWorldMatrix(initialCoords.EntityId));
_entityPickupAnimation.AnimateEntityPickup(item, initialCoords, finalPos, initialAngle); _entityPickupAnimation.AnimateEntityPickup(item, initialCoords, finalPos, initialAngle);
} }

View File

@@ -65,7 +65,7 @@ public sealed class DirectionIcon : TextureRect
if (_rotation != null) if (_rotation != null)
{ {
var offset = (-_rotation.Value).RotateVec(Size * UIScale / 2) - Size * UIScale / 2; var offset = (-_rotation.Value).RotateVec(Size * UIScale / 2) - Size * UIScale / 2;
handle.SetTransform(Matrix3.CreateTransform(GlobalPixelPosition - offset, -_rotation.Value)); handle.SetTransform(Matrix3Helpers.CreateTransform(GlobalPixelPosition - offset, -_rotation.Value));
} }
base.Draw(handle); base.Draw(handle);

View File

@@ -169,7 +169,7 @@ public partial class MapGridControl : LayoutContainer
var inversePos = (value - MidPointVector) / MinimapScale; var inversePos = (value - MidPointVector) / MinimapScale;
inversePos = inversePos with { Y = -inversePos.Y }; inversePos = inversePos with { Y = -inversePos.Y };
inversePos = Matrix3.CreateTransform(Offset, Angle.Zero).Transform(inversePos); inversePos = Vector2.Transform(inversePos, Matrix3Helpers.CreateTransform(Offset, Angle.Zero));
return inversePos; return inversePos;
} }

View File

@@ -277,8 +277,8 @@ namespace Content.Client.Viewport
EnsureViewportCreated(); EnsureViewportCreated();
var matrix = Matrix3.Invert(GetLocalToScreenMatrix()); Matrix3x2.Invert(GetLocalToScreenMatrix(), out var matrix);
coords = matrix.Transform(coords); coords = Vector2.Transform(coords, matrix);
return _viewport!.LocalToWorld(coords); return _viewport!.LocalToWorld(coords);
} }
@@ -291,8 +291,8 @@ namespace Content.Client.Viewport
EnsureViewportCreated(); EnsureViewportCreated();
var matrix = Matrix3.Invert(GetLocalToScreenMatrix()); Matrix3x2.Invert(GetLocalToScreenMatrix(), out var matrix);
coords = matrix.Transform(coords); coords = Vector2.Transform(coords, matrix);
var ev = new PixelToMapEvent(coords, this, _viewport!); var ev = new PixelToMapEvent(coords, this, _viewport!);
_entityManager.EventBus.RaiseEvent(EventSource.Local, ref ev); _entityManager.EventBus.RaiseEvent(EventSource.Local, ref ev);
@@ -311,16 +311,16 @@ namespace Content.Client.Viewport
var matrix = GetLocalToScreenMatrix(); var matrix = GetLocalToScreenMatrix();
return matrix.Transform(vpLocal); return Vector2.Transform(vpLocal, matrix);
} }
public Matrix3 GetWorldToScreenMatrix() public Matrix3x2 GetWorldToScreenMatrix()
{ {
EnsureViewportCreated(); EnsureViewportCreated();
return _viewport!.GetWorldToLocalMatrix() * GetLocalToScreenMatrix(); return _viewport!.GetWorldToLocalMatrix() * GetLocalToScreenMatrix();
} }
public Matrix3 GetLocalToScreenMatrix() public Matrix3x2 GetLocalToScreenMatrix()
{ {
EnsureViewportCreated(); EnsureViewportCreated();
@@ -329,9 +329,9 @@ namespace Content.Client.Viewport
if (scaleFactor.X == 0 || scaleFactor.Y == 0) if (scaleFactor.X == 0 || scaleFactor.Y == 0)
// Basically a nonsense scenario, at least make sure to return something that can be inverted. // Basically a nonsense scenario, at least make sure to return something that can be inverted.
return Matrix3.Identity; return Matrix3x2.Identity;
return Matrix3.CreateTransform(GlobalPixelPosition + drawBox.TopLeft, 0, scaleFactor); return Matrix3Helpers.CreateTransform(GlobalPixelPosition + drawBox.TopLeft, 0, scaleFactor);
} }
private void EnsureViewportCreated() private void EnsureViewportCreated()

View File

@@ -81,7 +81,7 @@ public sealed partial class MeleeWeaponSystem
case WeaponArcAnimation.None: case WeaponArcAnimation.None:
var (mapPos, mapRot) = TransformSystem.GetWorldPositionRotation(userXform); var (mapPos, mapRot) = TransformSystem.GetWorldPositionRotation(userXform);
var worldPos = mapPos + (mapRot - userXform.LocalRotation).RotateVec(localPos); var worldPos = mapPos + (mapRot - userXform.LocalRotation).RotateVec(localPos);
var newLocalPos = TransformSystem.GetInvWorldMatrix(xform.ParentUid).Transform(worldPos); var newLocalPos = Vector2.Transform(worldPos, TransformSystem.GetInvWorldMatrix(xform.ParentUid));
TransformSystem.SetLocalPositionNoLerp(animationUid, newLocalPos, xform); TransformSystem.SetLocalPositionNoLerp(animationUid, newLocalPos, xform);
if (arcComponent.Fadeout) if (arcComponent.Fadeout)
_animation.Play(animationUid, GetFadeAnimation(sprite, 0f, 0.15f), FadeAnimationKey); _animation.Play(animationUid, GetFadeAnimation(sprite, 0f, 0.15f), FadeAnimationKey);

View File

@@ -1,4 +1,4 @@
using System.Numerics; using System.Numerics;
using Content.Client.Resources; using Content.Client.Resources;
using Robust.Client.Graphics; using Robust.Client.Graphics;
using Robust.Client.ResourceManagement; using Robust.Client.ResourceManagement;
@@ -53,7 +53,7 @@ public abstract class BaseBulletRenderer : Control
{ {
// Scale rendering in this control by UIScale. // Scale rendering in this control by UIScale.
var currentTransform = handle.GetTransform(); var currentTransform = handle.GetTransform();
handle.SetTransform(Matrix3.CreateScale(new Vector2(UIScale)) * currentTransform); handle.SetTransform(Matrix3Helpers.CreateScale(new Vector2(UIScale)) * currentTransform);
var countPerRow = CountPerRow(Size.X); var countPerRow = CountPerRow(Size.X);

View File

@@ -14,7 +14,7 @@ public sealed class ExplosionGridTileFlood : ExplosionTileFlood
public MapGridComponent Grid; public MapGridComponent Grid;
private bool _needToTransform = false; private bool _needToTransform = false;
private Matrix3 _matrix = Matrix3.Identity; private Matrix3x2 _matrix = Matrix3x2.Identity;
private Vector2 _offset; private Vector2 _offset;
// Tiles which neighbor an exploding tile, but have not yet had the explosion spread to them due to an // Tiles which neighbor an exploding tile, but have not yet had the explosion spread to them due to an
@@ -44,7 +44,7 @@ public sealed class ExplosionGridTileFlood : ExplosionTileFlood
int typeIndex, int typeIndex,
Dictionary<Vector2i, NeighborFlag> edgeTiles, Dictionary<Vector2i, NeighborFlag> edgeTiles,
EntityUid? referenceGrid, EntityUid? referenceGrid,
Matrix3 spaceMatrix, Matrix3x2 spaceMatrix,
Angle spaceAngle) Angle spaceAngle)
{ {
Grid = grid; Grid = grid;
@@ -72,9 +72,10 @@ public sealed class ExplosionGridTileFlood : ExplosionTileFlood
var transform = IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(Grid.Owner); var transform = IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(Grid.Owner);
var size = (float) Grid.TileSize; var size = (float) Grid.TileSize;
_matrix.R0C2 = size / 2; _matrix.M31 = size / 2;
_matrix.R1C2 = size / 2; _matrix.M32 = size / 2;
_matrix *= transform.WorldMatrix * Matrix3.Invert(spaceMatrix); Matrix3x2.Invert(spaceMatrix, out var invSpace);
_matrix *= transform.WorldMatrix * invSpace;
var relativeAngle = transform.WorldRotation - spaceAngle; var relativeAngle = transform.WorldRotation - spaceAngle;
_offset = relativeAngle.RotateVec(new Vector2(size / 4, size / 4)); _offset = relativeAngle.RotateVec(new Vector2(size / 4, size / 4));
} }
@@ -228,7 +229,7 @@ public sealed class ExplosionGridTileFlood : ExplosionTileFlood
return; return;
} }
var center = _matrix.Transform(tile); var center = Vector2.Transform(tile, _matrix);
SpaceJump.Add(new((int) MathF.Floor(center.X + _offset.X), (int) MathF.Floor(center.Y + _offset.Y))); SpaceJump.Add(new((int) MathF.Floor(center.X + _offset.X), (int) MathF.Floor(center.Y + _offset.Y)));
SpaceJump.Add(new((int) MathF.Floor(center.X - _offset.Y), (int) MathF.Floor(center.Y + _offset.X))); SpaceJump.Add(new((int) MathF.Floor(center.X - _offset.Y), (int) MathF.Floor(center.Y + _offset.X)));
SpaceJump.Add(new((int) MathF.Floor(center.X - _offset.X), (int) MathF.Floor(center.Y - _offset.Y))); SpaceJump.Add(new((int) MathF.Floor(center.X - _offset.X), (int) MathF.Floor(center.Y - _offset.Y)));

View File

@@ -60,7 +60,7 @@ public sealed partial class ExplosionSystem : EntitySystem
{ {
Dictionary<Vector2i, BlockedSpaceTile> transformedEdges = new(); Dictionary<Vector2i, BlockedSpaceTile> transformedEdges = new();
var targetMatrix = Matrix3.Identity; var targetMatrix = Matrix3x2.Identity;
Angle targetAngle = new(); Angle targetAngle = new();
var tileSize = DefaultTileSize; var tileSize = DefaultTileSize;
var maxDistanceSq = (int) (maxDistance * maxDistance); var maxDistanceSq = (int) (maxDistance * maxDistance);
@@ -75,9 +75,9 @@ public sealed partial class ExplosionSystem : EntitySystem
tileSize = targetGrid.TileSize; tileSize = targetGrid.TileSize;
} }
var offsetMatrix = Matrix3.Identity; var offsetMatrix = Matrix3x2.Identity;
offsetMatrix.R0C2 = tileSize / 2f; offsetMatrix.M31 = tileSize / 2f;
offsetMatrix.R1C2 = tileSize / 2f; offsetMatrix.M32 = tileSize / 2f;
// Here we can end up with a triple nested for loop: // Here we can end up with a triple nested for loop:
// foreach other grid // foreach other grid
@@ -106,7 +106,7 @@ public sealed partial class ExplosionSystem : EntitySystem
var xform = xforms.GetComponent(gridToTransform); var xform = xforms.GetComponent(gridToTransform);
var (_, gridWorldRotation, gridWorldMatrix, invGridWorldMatrid) = xform.GetWorldPositionRotationMatrixWithInv(xforms); var (_, gridWorldRotation, gridWorldMatrix, invGridWorldMatrid) = xform.GetWorldPositionRotationMatrixWithInv(xforms);
var localEpicentre = (Vector2i) invGridWorldMatrid.Transform(epicentre.Position); var localEpicentre = (Vector2i) Vector2.Transform(epicentre.Position, invGridWorldMatrid);
var matrix = offsetMatrix * gridWorldMatrix * targetMatrix; var matrix = offsetMatrix * gridWorldMatrix * targetMatrix;
var angle = gridWorldRotation - targetAngle; var angle = gridWorldRotation - targetAngle;
@@ -119,7 +119,7 @@ public sealed partial class ExplosionSystem : EntitySystem
if (delta.X * delta.X + delta.Y * delta.Y > maxDistanceSq) // no Vector2.Length??? if (delta.X * delta.X + delta.Y * delta.Y > maxDistanceSq) // no Vector2.Length???
continue; continue;
var center = matrix.Transform(tile); var center = Vector2.Transform(tile, matrix);
if ((dir & NeighborFlag.Cardinal) == 0) if ((dir & NeighborFlag.Cardinal) == 0)
{ {

View File

@@ -298,8 +298,8 @@ public sealed partial class ExplosionSystem
/// Same as <see cref="ExplodeTile"/>, but for SPAAAAAAACE. /// Same as <see cref="ExplodeTile"/>, but for SPAAAAAAACE.
/// </summary> /// </summary>
internal void ExplodeSpace(BroadphaseComponent lookup, internal void ExplodeSpace(BroadphaseComponent lookup,
Matrix3 spaceMatrix, Matrix3x2 spaceMatrix,
Matrix3 invSpaceMatrix, Matrix3x2 invSpaceMatrix,
Vector2i tile, Vector2i tile,
float throwForce, float throwForce,
DamageSpecifier damage, DamageSpecifier damage,
@@ -341,7 +341,7 @@ public sealed partial class ExplosionSystem
} }
private static bool SpaceQueryCallback( private static bool SpaceQueryCallback(
ref (List<(EntityUid, TransformComponent)> List, HashSet<EntityUid> Processed, Matrix3 InvSpaceMatrix, EntityUid LookupOwner, EntityQuery<TransformComponent> XformQuery, Box2 GridBox, SharedTransformSystem System) state, ref (List<(EntityUid, TransformComponent)> List, HashSet<EntityUid> Processed, Matrix3x2 InvSpaceMatrix, EntityUid LookupOwner, EntityQuery<TransformComponent> XformQuery, Box2 GridBox, SharedTransformSystem System) state,
in EntityUid uid) in EntityUid uid)
{ {
if (state.Processed.Contains(uid)) if (state.Processed.Contains(uid))
@@ -352,7 +352,7 @@ public sealed partial class ExplosionSystem
if (xform.ParentUid == state.LookupOwner) if (xform.ParentUid == state.LookupOwner)
{ {
// parented directly to the map, use local position // parented directly to the map, use local position
if (state.GridBox.Contains(state.InvSpaceMatrix.Transform(xform.LocalPosition))) if (state.GridBox.Contains(Vector2.Transform(xform.LocalPosition, state.InvSpaceMatrix)))
state.List.Add((uid, xform)); state.List.Add((uid, xform));
return true; return true;
@@ -360,14 +360,14 @@ public sealed partial class ExplosionSystem
// finally check if it intersects our tile // finally check if it intersects our tile
var wpos = state.System.GetWorldPosition(xform); var wpos = state.System.GetWorldPosition(xform);
if (state.GridBox.Contains(state.InvSpaceMatrix.Transform(wpos))) if (state.GridBox.Contains(Vector2.Transform(wpos, state.InvSpaceMatrix)))
state.List.Add((uid, xform)); state.List.Add((uid, xform));
return true; return true;
} }
private static bool SpaceQueryCallback( private static bool SpaceQueryCallback(
ref (List<(EntityUid, TransformComponent)> List, HashSet<EntityUid> Processed, Matrix3 InvSpaceMatrix, EntityUid LookupOwner, EntityQuery<TransformComponent> XformQuery, Box2 GridBox, SharedTransformSystem System) state, ref (List<(EntityUid, TransformComponent)> List, HashSet<EntityUid> Processed, Matrix3x2 InvSpaceMatrix, EntityUid LookupOwner, EntityQuery<TransformComponent> XformQuery, Box2 GridBox, SharedTransformSystem System) state,
in FixtureProxy proxy) in FixtureProxy proxy)
{ {
var uid = proxy.Entity; var uid = proxy.Entity;
@@ -585,12 +585,12 @@ sealed class Explosion
/// <summary> /// <summary>
/// The matrix that defines the reference frame for the explosion in space. /// The matrix that defines the reference frame for the explosion in space.
/// </summary> /// </summary>
private readonly Matrix3 _spaceMatrix; private readonly Matrix3x2 _spaceMatrix;
/// <summary> /// <summary>
/// Inverse of <see cref="_spaceMatrix"/> /// Inverse of <see cref="_spaceMatrix"/>
/// </summary> /// </summary>
private readonly Matrix3 _invSpaceMatrix; private readonly Matrix3x2 _invSpaceMatrix;
/// <summary> /// <summary>
/// Have all the tiles on all the grids been processed? /// Have all the tiles on all the grids been processed?
@@ -656,7 +656,7 @@ sealed class Explosion
List<ExplosionGridTileFlood> gridData, List<ExplosionGridTileFlood> gridData,
List<float> tileSetIntensity, List<float> tileSetIntensity,
MapCoordinates epicenter, MapCoordinates epicenter,
Matrix3 spaceMatrix, Matrix3x2 spaceMatrix,
int area, int area,
float tileBreakScale, float tileBreakScale,
int maxTileBreak, int maxTileBreak,
@@ -695,7 +695,7 @@ sealed class Explosion
}); });
_spaceMatrix = spaceMatrix; _spaceMatrix = spaceMatrix;
_invSpaceMatrix = Matrix3.Invert(spaceMatrix); Matrix3x2.Invert(spaceMatrix, out _invSpaceMatrix);
} }
foreach (var grid in gridData) foreach (var grid in gridData)

View File

@@ -26,7 +26,7 @@ public sealed partial class ExplosionSystem : EntitySystem
/// <param name="maxIntensity">The maximum intensity that the explosion can have at any given tile. This /// <param name="maxIntensity">The maximum intensity that the explosion can have at any given tile. This
/// effectively caps the damage that this explosion can do.</param> /// effectively caps the damage that this explosion can do.</param>
/// <returns>A list of tile-sets and a list of intensity values which describe the explosion.</returns> /// <returns>A list of tile-sets and a list of intensity values which describe the explosion.</returns>
private (int, List<float>, ExplosionSpaceTileFlood?, Dictionary<EntityUid, ExplosionGridTileFlood>, Matrix3)? GetExplosionTiles( private (int, List<float>, ExplosionSpaceTileFlood?, Dictionary<EntityUid, ExplosionGridTileFlood>, Matrix3x2)? GetExplosionTiles(
MapCoordinates epicenter, MapCoordinates epicenter,
string typeID, string typeID,
float totalIntensity, float totalIntensity,
@@ -84,7 +84,7 @@ public sealed partial class ExplosionSystem : EntitySystem
Dictionary<EntityUid, HashSet<Vector2i>>? previousGridJump; Dictionary<EntityUid, HashSet<Vector2i>>? previousGridJump;
// variables for transforming between grid and space-coordinates // variables for transforming between grid and space-coordinates
var spaceMatrix = Matrix3.Identity; var spaceMatrix = Matrix3x2.Identity;
var spaceAngle = Angle.Zero; var spaceAngle = Angle.Zero;
if (referenceGrid != null) if (referenceGrid != null)
{ {

View File

@@ -1,3 +1,4 @@
using System.Numerics;
using Content.Shared.Explosion; using Content.Shared.Explosion;
using Content.Shared.Explosion.Components; using Content.Shared.Explosion.Components;
using Robust.Server.GameObjects; using Robust.Server.GameObjects;
@@ -35,7 +36,7 @@ public sealed partial class ExplosionSystem : EntitySystem
/// <summary> /// <summary>
/// Constructor for the shared <see cref="ExplosionEvent"/> using the server-exclusive explosion classes. /// Constructor for the shared <see cref="ExplosionEvent"/> using the server-exclusive explosion classes.
/// </summary> /// </summary>
private EntityUid CreateExplosionVisualEntity(MapCoordinates epicenter, string prototype, Matrix3 spaceMatrix, ExplosionSpaceTileFlood? spaceData, IEnumerable<ExplosionGridTileFlood> gridData, List<float> iterationIntensity) private EntityUid CreateExplosionVisualEntity(MapCoordinates epicenter, string prototype, Matrix3x2 spaceMatrix, ExplosionSpaceTileFlood? spaceData, IEnumerable<ExplosionGridTileFlood> gridData, List<float> iterationIntensity)
{ {
var explosionEntity = Spawn(null, MapCoordinates.Nullspace); var explosionEntity = Spawn(null, MapCoordinates.Nullspace);
var comp = AddComp<ExplosionVisualsComponent>(explosionEntity); var comp = AddComp<ExplosionVisualsComponent>(explosionEntity);

View File

@@ -1,3 +1,4 @@
using System.Numerics;
using Content.Server.Chemistry.Containers.EntitySystems; using Content.Server.Chemistry.Containers.EntitySystems;
using Content.Server.Popups; using Content.Server.Popups;
using Content.Shared.Chemistry.Components; using Content.Shared.Chemistry.Components;
@@ -317,7 +318,7 @@ public sealed class AbsorbentSystem : SharedAbsorbentSystem
var userXform = Transform(user); var userXform = Transform(user);
var targetPos = _transform.GetWorldPosition(target); var targetPos = _transform.GetWorldPosition(target);
var localPos = _transform.GetInvWorldMatrix(userXform).Transform(targetPos); var localPos = Vector2.Transform(targetPos, _transform.GetInvWorldMatrix(userXform));
localPos = userXform.LocalRotation.RotateVec(localPos); localPos = userXform.LocalRotation.RotateVec(localPos);
_melee.DoLunge(user, used, Angle.Zero, localPos, null, false); _melee.DoLunge(user, used, Angle.Zero, localPos, null, false);

View File

@@ -417,7 +417,7 @@ namespace Content.Server.GameTicking
{ {
var gridXform = Transform(gridUid); var gridXform = Transform(gridUid);
return new EntityCoordinates(gridUid, gridXform.InvWorldMatrix.Transform(toMap.Position)); return new EntityCoordinates(gridUid, Vector2.Transform(toMap.Position, gridXform.InvWorldMatrix));
} }
return spawn; return spawn;

View File

@@ -1,3 +1,4 @@
using System.Numerics;
using Content.Server.Access.Systems; using Content.Server.Access.Systems;
using Content.Server.DeviceNetwork; using Content.Server.DeviceNetwork;
using Content.Server.DeviceNetwork.Components; using Content.Server.DeviceNetwork.Components;
@@ -366,8 +367,8 @@ public sealed class SuitSensorSystem : EntitySystem
if (transform.GridUid != null) if (transform.GridUid != null)
{ {
coordinates = new EntityCoordinates(transform.GridUid.Value, coordinates = new EntityCoordinates(transform.GridUid.Value,
_transform.GetInvWorldMatrix(xformQuery.GetComponent(transform.GridUid.Value), xformQuery) Vector2.Transform(_transform.GetWorldPosition(transform, xformQuery),
.Transform(_transform.GetWorldPosition(transform, xformQuery))); _transform.GetInvWorldMatrix(xformQuery.GetComponent(transform.GridUid.Value), xformQuery)));
} }
else if (transform.MapUid != null) else if (transform.MapUid != null)
{ {

View File

@@ -36,7 +36,7 @@ public sealed partial class PathfindingSystem
return Vector2.Zero; return Vector2.Zero;
} }
endPos = startXform.InvWorldMatrix.Transform(endXform.WorldMatrix.Transform(endPos)); endPos = Vector2.Transform(Vector2.Transform(endPos, endXform.WorldMatrix), startXform.InvWorldMatrix);
} }
// TODO: Numerics when we changeover. // TODO: Numerics when we changeover.

View File

@@ -395,7 +395,7 @@ public sealed partial class PathfindingSystem
private Vector2i GetOrigin(EntityCoordinates coordinates, EntityUid gridUid) private Vector2i GetOrigin(EntityCoordinates coordinates, EntityUid gridUid)
{ {
var localPos = _transform.GetInvWorldMatrix(gridUid).Transform(coordinates.ToMapPos(EntityManager, _transform)); var localPos = Vector2.Transform(coordinates.ToMapPos(EntityManager, _transform), _transform.GetInvWorldMatrix(gridUid));
return new Vector2i((int) Math.Floor(localPos.X / ChunkSize), (int) Math.Floor(localPos.Y / ChunkSize)); return new Vector2i((int) Math.Floor(localPos.X / ChunkSize), (int) Math.Floor(localPos.Y / ChunkSize));
} }

View File

@@ -405,7 +405,7 @@ namespace Content.Server.NPC.Pathfinding
return null; return null;
} }
var localPos = xform.InvWorldMatrix.Transform(coordinates.ToMapPos(EntityManager, _transform)); var localPos = Vector2.Transform(coordinates.ToMapPos(EntityManager, _transform), xform.InvWorldMatrix);
var origin = GetOrigin(localPos); var origin = GetOrigin(localPos);
if (!TryGetChunk(origin, comp, out var chunk)) if (!TryGetChunk(origin, comp, out var chunk))

View File

@@ -19,7 +19,7 @@ public sealed partial class DungeonJob
var gen = _prototype.Index<DungeonPresetPrototype>(preset); var gen = _prototype.Index<DungeonPresetPrototype>(preset);
var dungeonRotation = _dungeon.GetDungeonRotation(seed); var dungeonRotation = _dungeon.GetDungeonRotation(seed);
var dungeonTransform = Matrix3.CreateTransform(_position, dungeonRotation); var dungeonTransform = Matrix3Helpers.CreateTransform(_position, dungeonRotation);
var roomPackProtos = new Dictionary<Vector2i, List<DungeonRoomPackPrototype>>(); var roomPackProtos = new Dictionary<Vector2i, List<DungeonRoomPackPrototype>>();
foreach (var pack in _prototype.EnumeratePrototypes<DungeonRoomPackPrototype>()) foreach (var pack in _prototype.EnumeratePrototypes<DungeonRoomPackPrototype>())
@@ -69,7 +69,7 @@ public sealed partial class DungeonJob
var dungeon = new Dungeon(); var dungeon = new Dungeon();
var availablePacks = new List<DungeonRoomPackPrototype>(); var availablePacks = new List<DungeonRoomPackPrototype>();
var chosenPacks = new DungeonRoomPackPrototype?[gen.RoomPacks.Count]; var chosenPacks = new DungeonRoomPackPrototype?[gen.RoomPacks.Count];
var packTransforms = new Matrix3[gen.RoomPacks.Count]; var packTransforms = new Matrix3x2[gen.RoomPacks.Count];
var packRotations = new Angle[gen.RoomPacks.Count]; var packRotations = new Angle[gen.RoomPacks.Count];
// Actually pick the room packs and rooms // Actually pick the room packs and rooms
@@ -97,7 +97,7 @@ public sealed partial class DungeonJob
// Iterate every pack // Iterate every pack
random.Shuffle(availablePacks); random.Shuffle(availablePacks);
Matrix3 packTransform = default!; Matrix3x2 packTransform = default!;
var found = false; var found = false;
DungeonRoomPackPrototype pack = default!; DungeonRoomPackPrototype pack = default!;
@@ -128,7 +128,7 @@ public sealed partial class DungeonJob
var aRotation = dir.AsDir().ToAngle(); var aRotation = dir.AsDir().ToAngle();
// Use this pack // Use this pack
packTransform = Matrix3.CreateTransform(bounds.Center, aRotation); packTransform = Matrix3Helpers.CreateTransform(bounds.Center, aRotation);
packRotations[i] = aRotation; packRotations[i] = aRotation;
pack = aPack; pack = aPack;
break; break;
@@ -168,7 +168,7 @@ public sealed partial class DungeonJob
{ {
var roomDimensions = new Vector2i(roomSize.Width, roomSize.Height); var roomDimensions = new Vector2i(roomSize.Width, roomSize.Height);
Angle roomRotation = Angle.Zero; Angle roomRotation = Angle.Zero;
Matrix3 matty; Matrix3x2 matty;
if (!roomProtos.TryGetValue(roomDimensions, out var roomProto)) if (!roomProtos.TryGetValue(roomDimensions, out var roomProto))
{ {
@@ -176,13 +176,13 @@ public sealed partial class DungeonJob
if (!roomProtos.TryGetValue(roomDimensions, out roomProto)) if (!roomProtos.TryGetValue(roomDimensions, out roomProto))
{ {
Matrix3.Multiply(packTransform, dungeonTransform, out matty); matty = Matrix3x2.Multiply(packTransform, dungeonTransform);
for (var x = roomSize.Left; x < roomSize.Right; x++) for (var x = roomSize.Left; x < roomSize.Right; x++)
{ {
for (var y = roomSize.Bottom; y < roomSize.Top; y++) for (var y = roomSize.Bottom; y < roomSize.Top; y++)
{ {
var index = matty.Transform(new Vector2(x, y) + grid.TileSizeHalfVector - packCenter).Floored(); var index = Vector2.Transform(new Vector2(x, y) + grid.TileSizeHalfVector - packCenter, matty).Floored();
tiles.Add((index, new Tile(_tileDefManager["FloorPlanetGrass"].TileId))); tiles.Add((index, new Tile(_tileDefManager["FloorPlanetGrass"].TileId)));
} }
} }
@@ -209,10 +209,10 @@ public sealed partial class DungeonJob
roomRotation += Math.PI; roomRotation += Math.PI;
} }
var roomTransform = Matrix3.CreateTransform(roomSize.Center - packCenter, roomRotation); var roomTransform = Matrix3Helpers.CreateTransform(roomSize.Center - packCenter, roomRotation);
Matrix3.Multiply(roomTransform, packTransform, out matty); matty = Matrix3x2.Multiply(roomTransform, packTransform);
Matrix3.Multiply(matty, dungeonTransform, out var dungeonMatty); var dungeonMatty = Matrix3x2.Multiply(matty, dungeonTransform);
// The expensive bit yippy. // The expensive bit yippy.
_dungeon.SpawnRoom(gridUid, grid, dungeonMatty, room); _dungeon.SpawnRoom(gridUid, grid, dungeonMatty, room);
@@ -232,7 +232,7 @@ public sealed partial class DungeonJob
continue; continue;
} }
var tilePos = dungeonMatty.Transform(new Vector2i(x + room.Offset.X, y + room.Offset.Y) + tileOffset); var tilePos = Vector2.Transform(new Vector2i(x + room.Offset.X, y + room.Offset.Y) + tileOffset, dungeonMatty);
exterior.Add(tilePos.Floored()); exterior.Add(tilePos.Floored());
} }
} }
@@ -244,7 +244,7 @@ public sealed partial class DungeonJob
for (var y = 0; y < room.Size.Y; y++) for (var y = 0; y < room.Size.Y; y++)
{ {
var roomTile = new Vector2i(x + room.Offset.X, y + room.Offset.Y); var roomTile = new Vector2i(x + room.Offset.X, y + room.Offset.Y);
var tilePos = dungeonMatty.Transform(roomTile + tileOffset); var tilePos = Vector2.Transform(roomTile + tileOffset, dungeonMatty);
var tileIndex = tilePos.Floored(); var tileIndex = tilePos.Floored();
roomTiles.Add(tileIndex); roomTiles.Add(tileIndex);

View File

@@ -67,7 +67,7 @@ public sealed partial class DungeonSystem
bool clearExisting = false, bool clearExisting = false,
bool rotation = false) bool rotation = false)
{ {
var originTransform = Matrix3.CreateTranslation(origin); var originTransform = Matrix3Helpers.CreateTranslation(origin.X, origin.Y);
var roomRotation = Angle.Zero; var roomRotation = Angle.Zero;
if (rotation) if (rotation)
@@ -75,8 +75,8 @@ public sealed partial class DungeonSystem
roomRotation = GetRoomRotation(room, random); roomRotation = GetRoomRotation(room, random);
} }
var roomTransform = Matrix3.CreateTransform((Vector2) room.Size / 2f, roomRotation); var roomTransform = Matrix3Helpers.CreateTransform((Vector2) room.Size / 2f, roomRotation);
Matrix3.Multiply(roomTransform, originTransform, out var finalTransform); var finalTransform = Matrix3x2.Multiply(roomTransform, originTransform);
SpawnRoom(gridUid, grid, finalTransform, room, clearExisting); SpawnRoom(gridUid, grid, finalTransform, room, clearExisting);
} }
@@ -101,7 +101,7 @@ public sealed partial class DungeonSystem
public void SpawnRoom( public void SpawnRoom(
EntityUid gridUid, EntityUid gridUid,
MapGridComponent grid, MapGridComponent grid,
Matrix3 roomTransform, Matrix3x2 roomTransform,
DungeonRoomPrototype room, DungeonRoomPrototype room,
bool clearExisting = false) bool clearExisting = false)
{ {
@@ -116,7 +116,7 @@ public sealed partial class DungeonSystem
// go BRRNNTTT on existing stuff // go BRRNNTTT on existing stuff
if (clearExisting) if (clearExisting)
{ {
var gridBounds = new Box2(roomTransform.Transform(Vector2.Zero), roomTransform.Transform(room.Size)); var gridBounds = new Box2(Vector2.Transform(Vector2.Zero, roomTransform), Vector2.Transform(room.Size, roomTransform));
_entitySet.Clear(); _entitySet.Clear();
// Polygon skin moment // Polygon skin moment
gridBounds = gridBounds.Enlarged(-0.05f); gridBounds = gridBounds.Enlarged(-0.05f);
@@ -148,7 +148,7 @@ public sealed partial class DungeonSystem
var indices = new Vector2i(x + room.Offset.X, y + room.Offset.Y); var indices = new Vector2i(x + room.Offset.X, y + room.Offset.Y);
var tileRef = _maps.GetTileRef(templateMapUid, templateGrid, indices); var tileRef = _maps.GetTileRef(templateMapUid, templateGrid, indices);
var tilePos = roomTransform.Transform(indices + tileOffset); var tilePos = Vector2.Transform(indices + tileOffset, roomTransform);
var rounded = tilePos.Floored(); var rounded = tilePos.Floored();
_tiles.Add((rounded, tileRef.Tile)); _tiles.Add((rounded, tileRef.Tile));
} }
@@ -164,7 +164,7 @@ public sealed partial class DungeonSystem
foreach (var templateEnt in _lookup.GetEntitiesIntersecting(templateMapUid, bounds, LookupFlags.Uncontained)) foreach (var templateEnt in _lookup.GetEntitiesIntersecting(templateMapUid, bounds, LookupFlags.Uncontained))
{ {
var templateXform = _xformQuery.GetComponent(templateEnt); var templateXform = _xformQuery.GetComponent(templateEnt);
var childPos = roomTransform.Transform(templateXform.LocalPosition - roomCenter); var childPos = Vector2.Transform(templateXform.LocalPosition - roomCenter, roomTransform);
var childRot = templateXform.LocalRotation + finalRoomRotation; var childRot = templateXform.LocalRotation + finalRoomRotation;
var protoId = _metaQuery.GetComponent(templateEnt).EntityPrototype?.ID; var protoId = _metaQuery.GetComponent(templateEnt).EntityPrototype?.ID;
@@ -192,7 +192,7 @@ public sealed partial class DungeonSystem
// Offset by 0.5 because decals are offset from bot-left corner // Offset by 0.5 because decals are offset from bot-left corner
// So we convert it to center of tile then convert it back again after transform. // So we convert it to center of tile then convert it back again after transform.
// Do these shenanigans because 32x32 decals assume as they are centered on bottom-left of tiles. // Do these shenanigans because 32x32 decals assume as they are centered on bottom-left of tiles.
var position = roomTransform.Transform(decal.Coordinates + Vector2Helpers.Half - roomCenter); var position = Vector2.Transform(decal.Coordinates + Vector2Helpers.Half - roomCenter, roomTransform);
position -= Vector2Helpers.Half; position -= Vector2Helpers.Half;
// Umm uhh I love decals so uhhhh idk what to do about this // Umm uhh I love decals so uhhhh idk what to do about this

View File

@@ -195,11 +195,11 @@ public partial class RadiationSystem
Vector2 srcLocal = sourceTrs.ParentUid == grid.Owner Vector2 srcLocal = sourceTrs.ParentUid == grid.Owner
? sourceTrs.LocalPosition ? sourceTrs.LocalPosition
: gridTrs.InvLocalMatrix.Transform(ray.Source); : Vector2.Transform(ray.Source, gridTrs.InvLocalMatrix);
Vector2 dstLocal = destTrs.ParentUid == grid.Owner Vector2 dstLocal = destTrs.ParentUid == grid.Owner
? destTrs.LocalPosition ? destTrs.LocalPosition
: gridTrs.InvLocalMatrix.Transform(ray.Destination); : Vector2.Transform(ray.Destination, gridTrs.InvLocalMatrix);
Vector2i sourceGrid = new( Vector2i sourceGrid = new(
(int) Math.Floor(srcLocal.X / grid.Comp.TileSize), (int) Math.Floor(srcLocal.X / grid.Comp.TileSize),

View File

@@ -1,3 +1,4 @@
using System.Numerics;
using Content.Shared.Salvage.Fulton; using Content.Shared.Salvage.Fulton;
using Robust.Shared.Containers; using Robust.Shared.Containers;
using Robust.Shared.Map; using Robust.Shared.Map;
@@ -61,8 +62,9 @@ public sealed class FultonSystem : SharedFultonSystem
var metadata = MetaData(uid); var metadata = MetaData(uid);
var oldCoords = xform.Coordinates; var oldCoords = xform.Coordinates;
var offset = _random.NextVector2(1.5f); var offset = _random.NextVector2(1.5f);
var localPos = TransformSystem.GetInvWorldMatrix(beaconXform.ParentUid) var localPos = Vector2.Transform(
.Transform(TransformSystem.GetWorldPosition(beaconXform)) + offset; TransformSystem.GetWorldPosition(beaconXform),
TransformSystem.GetInvWorldMatrix(beaconXform.ParentUid)) + offset;
TransformSystem.SetCoordinates(uid, new EntityCoordinates(beaconXform.ParentUid, localPos)); TransformSystem.SetCoordinates(uid, new EntityCoordinates(beaconXform.ParentUid, localPos));

View File

@@ -1,3 +1,4 @@
using System.Numerics;
using Robust.Shared.Map; using Robust.Shared.Map;
namespace Content.Server.Shuttles.Events; namespace Content.Server.Shuttles.Events;
@@ -6,4 +7,4 @@ namespace Content.Server.Shuttles.Events;
/// Raised when a shuttle has moved to FTL space. /// Raised when a shuttle has moved to FTL space.
/// </summary> /// </summary>
[ByRefEvent] [ByRefEvent]
public readonly record struct FTLStartedEvent(EntityUid Entity, EntityCoordinates TargetCoordinates, EntityUid? FromMapUid, Matrix3 FTLFrom, Angle FromRotation); public readonly record struct FTLStartedEvent(EntityUid Entity, EntityCoordinates TargetCoordinates, EntityUid? FromMapUid, Matrix3x2 FTLFrom, Angle FromRotation);

View File

@@ -1,4 +1,5 @@
using System.Linq; using System.Linq;
using System.Numerics;
using Content.Server.Administration; using Content.Server.Administration;
using Content.Server.DeviceNetwork.Components; using Content.Server.DeviceNetwork.Components;
using Content.Server.DeviceNetwork.Systems; using Content.Server.DeviceNetwork.Systems;
@@ -277,7 +278,7 @@ public sealed class ArrivalsSystem : EntitySystem
foreach (var (ent, xform) in toDump) foreach (var (ent, xform) in toDump)
{ {
var rotation = xform.LocalRotation; var rotation = xform.LocalRotation;
_transform.SetCoordinates(ent, new EntityCoordinates(args.FromMapUid!.Value, args.FTLFrom.Transform(xform.LocalPosition))); _transform.SetCoordinates(ent, new EntityCoordinates(args.FromMapUid!.Value, Vector2.Transform(xform.LocalPosition, args.FTLFrom)));
_transform.SetWorldRotation(ent, args.FromRotation + rotation); _transform.SetWorldRotation(ent, args.FromRotation + rotation);
} }
} }

View File

@@ -46,13 +46,13 @@ public sealed partial class DockingSystem
FixturesComponent shuttleFixtures, FixturesComponent shuttleFixtures,
MapGridComponent grid, MapGridComponent grid,
bool isMap, bool isMap,
out Matrix3 matty, out Matrix3x2 matty,
out Box2 shuttleDockedAABB, out Box2 shuttleDockedAABB,
out Angle gridRotation) out Angle gridRotation)
{ {
shuttleDockedAABB = Box2.UnitCentered; shuttleDockedAABB = Box2.UnitCentered;
gridRotation = Angle.Zero; gridRotation = Angle.Zero;
matty = Matrix3.Identity; matty = Matrix3x2.Identity;
if (shuttleDock.Docked || if (shuttleDock.Docked ||
gridDock.Docked || gridDock.Docked ||
@@ -71,9 +71,9 @@ public sealed partial class DockingSystem
var gridDockAngle = gridDockXform.LocalRotation.Opposite(); var gridDockAngle = gridDockXform.LocalRotation.Opposite();
var offsetAngle = gridDockAngle - shuttleDockAngle; var offsetAngle = gridDockAngle - shuttleDockAngle;
var stationDockMatrix = Matrix3.CreateInverseTransform(stationDockPos, shuttleDockAngle); var stationDockMatrix = Matrix3Helpers.CreateInverseTransform(stationDockPos, shuttleDockAngle);
var gridXformMatrix = Matrix3.CreateTransform(gridDockXform.LocalPosition, gridDockAngle); var gridXformMatrix = Matrix3Helpers.CreateTransform(gridDockXform.LocalPosition, gridDockAngle);
Matrix3.Multiply(in stationDockMatrix, in gridXformMatrix, out matty); matty = Matrix3x2.Multiply(stationDockMatrix, gridXformMatrix);
if (!ValidSpawn(grid, matty, offsetAngle, shuttleFixtures, isMap)) if (!ValidSpawn(grid, matty, offsetAngle, shuttleFixtures, isMap))
return false; return false;
@@ -193,7 +193,7 @@ public sealed partial class DockingSystem
} }
// Can't just use the AABB as we want to get bounds as tight as possible. // Can't just use the AABB as we want to get bounds as tight as possible.
var gridPosition = new EntityCoordinates(targetGrid, matty.Transform(Vector2.Zero)); var gridPosition = new EntityCoordinates(targetGrid, Vector2.Transform(Vector2.Zero, matty));
var spawnPosition = new EntityCoordinates(targetGridXform.MapUid!.Value, gridPosition.ToMapPos(EntityManager, _transform)); var spawnPosition = new EntityCoordinates(targetGridXform.MapUid!.Value, gridPosition.ToMapPos(EntityManager, _transform));
// TODO: use tight bounds // TODO: use tight bounds
@@ -303,9 +303,9 @@ public sealed partial class DockingSystem
/// <summary> /// <summary>
/// Checks whether the shuttle can warp to the specified position. /// Checks whether the shuttle can warp to the specified position.
/// </summary> /// </summary>
private bool ValidSpawn(MapGridComponent grid, Matrix3 matty, Angle angle, FixturesComponent shuttleFixturesComp, bool isMap) private bool ValidSpawn(MapGridComponent grid, Matrix3x2 matty, Angle angle, FixturesComponent shuttleFixturesComp, bool isMap)
{ {
var transform = new Transform(matty.Transform(Vector2.Zero), angle); var transform = new Transform(Vector2.Transform(Vector2.Zero, matty), angle);
// Because some docking bounds are tight af need to check each chunk individually // Because some docking bounds are tight af need to check each chunk individually
foreach (var fix in shuttleFixturesComp.Fixtures.Values) foreach (var fix in shuttleFixturesComp.Fixtures.Values)

View File

@@ -1,3 +1,4 @@
using System.Numerics;
using Content.Server.Shuttles.Components; using Content.Server.Shuttles.Components;
using Content.Shared.Audio; using Content.Shared.Audio;
using Robust.Shared.Audio; using Robust.Shared.Audio;
@@ -38,8 +39,8 @@ public sealed partial class ShuttleSystem
var otherXform = Transform(args.OtherEntity); var otherXform = Transform(args.OtherEntity);
var ourPoint = ourXform.InvWorldMatrix.Transform(args.WorldPoint); var ourPoint = Vector2.Transform(args.WorldPoint, ourXform.InvWorldMatrix);
var otherPoint = otherXform.InvWorldMatrix.Transform(args.WorldPoint); var otherPoint = Vector2.Transform(args.WorldPoint, otherXform.InvWorldMatrix);
var ourVelocity = _physics.GetLinearVelocity(uid, ourPoint, ourBody, ourXform); var ourVelocity = _physics.GetLinearVelocity(uid, ourPoint, ourBody, ourXform);
var otherVelocity = _physics.GetLinearVelocity(args.OtherEntity, otherPoint, otherBody, otherXform); var otherVelocity = _physics.GetLinearVelocity(args.OtherEntity, otherPoint, otherBody, otherXform);

View File

@@ -1,3 +1,4 @@
using System.Numerics;
using Content.Server.Atmos.Components; using Content.Server.Atmos.Components;
using Content.Server.Singularity.Components; using Content.Server.Singularity.Components;
using Content.Shared.Ghost; using Content.Shared.Ghost;
@@ -126,7 +127,7 @@ public sealed class GravityWellSystem : SharedGravityWellSystem
/// <param name="minRange">The minimum distance at which entities can be affected by the gravity pulse.</param> /// <param name="minRange">The minimum distance at which entities can be affected by the gravity pulse.</param>
/// <param name="baseMatrixDeltaV">The base velocity added to any entities within affected by the gravity pulse scaled by the displacement of those entities from the epicenter.</param> /// <param name="baseMatrixDeltaV">The base velocity added to any entities within affected by the gravity pulse scaled by the displacement of those entities from the epicenter.</param>
/// <param name="xform">(optional) The transform of the entity at the epicenter of the gravitational pulse.</param> /// <param name="xform">(optional) The transform of the entity at the epicenter of the gravitational pulse.</param>
public void GravPulse(EntityUid uid, float maxRange, float minRange, in Matrix3 baseMatrixDeltaV, TransformComponent? xform = null) public void GravPulse(EntityUid uid, float maxRange, float minRange, in Matrix3x2 baseMatrixDeltaV, TransformComponent? xform = null)
{ {
if (Resolve(uid, ref xform)) if (Resolve(uid, ref xform))
GravPulse(xform.Coordinates, maxRange, minRange, in baseMatrixDeltaV); GravPulse(xform.Coordinates, maxRange, minRange, in baseMatrixDeltaV);
@@ -154,7 +155,7 @@ public sealed class GravityWellSystem : SharedGravityWellSystem
/// <param name="maxRange">The maximum distance at which entities can be affected by the gravity pulse.</param> /// <param name="maxRange">The maximum distance at which entities can be affected by the gravity pulse.</param>
/// <param name="minRange">The minimum distance at which entities can be affected by the gravity pulse.</param> /// <param name="minRange">The minimum distance at which entities can be affected by the gravity pulse.</param>
/// <param name="baseMatrixDeltaV">The base velocity added to any entities within affected by the gravity pulse scaled by the displacement of those entities from the epicenter.</param> /// <param name="baseMatrixDeltaV">The base velocity added to any entities within affected by the gravity pulse scaled by the displacement of those entities from the epicenter.</param>
public void GravPulse(EntityCoordinates entityPos, float maxRange, float minRange, in Matrix3 baseMatrixDeltaV) public void GravPulse(EntityCoordinates entityPos, float maxRange, float minRange, in Matrix3x2 baseMatrixDeltaV)
=> GravPulse(entityPos.ToMap(EntityManager, _transform), maxRange, minRange, in baseMatrixDeltaV); => GravPulse(entityPos.ToMap(EntityManager, _transform), maxRange, minRange, in baseMatrixDeltaV);
/// <summary> /// <summary>
@@ -175,7 +176,7 @@ public sealed class GravityWellSystem : SharedGravityWellSystem
/// <param name="maxRange">The maximum distance at which entities can be affected by the gravity pulse.</param> /// <param name="maxRange">The maximum distance at which entities can be affected by the gravity pulse.</param>
/// <param name="minRange">The minimum distance at which entities can be affected by the gravity pulse. Exists to prevent div/0 errors.</param> /// <param name="minRange">The minimum distance at which entities can be affected by the gravity pulse. Exists to prevent div/0 errors.</param>
/// <param name="baseMatrixDeltaV">The base velocity added to any entities within affected by the gravity pulse scaled by the displacement of those entities from the epicenter.</param> /// <param name="baseMatrixDeltaV">The base velocity added to any entities within affected by the gravity pulse scaled by the displacement of those entities from the epicenter.</param>
public void GravPulse(MapCoordinates mapPos, float maxRange, float minRange, in Matrix3 baseMatrixDeltaV) public void GravPulse(MapCoordinates mapPos, float maxRange, float minRange, in Matrix3x2 baseMatrixDeltaV)
{ {
if (mapPos == MapCoordinates.Nullspace) if (mapPos == MapCoordinates.Nullspace)
return; // No gravpulses in nullspace please. return; // No gravpulses in nullspace please.
@@ -205,7 +206,7 @@ public sealed class GravityWellSystem : SharedGravityWellSystem
continue; continue;
var scaling = (1f / distance2) * physics.Mass; // TODO: Variable falloff gradiants. var scaling = (1f / distance2) * physics.Mass; // TODO: Variable falloff gradiants.
_physics.ApplyLinearImpulse(entity, (displacement * baseMatrixDeltaV) * scaling, body: physics); _physics.ApplyLinearImpulse(entity, Vector2.Transform(displacement, baseMatrixDeltaV) * scaling, body: physics);
} }
} }
@@ -218,10 +219,9 @@ public sealed class GravityWellSystem : SharedGravityWellSystem
/// <param name="baseRadialDeltaV">The base amount of velocity that will be added to entities in range towards the epicenter of the pulse.</param> /// <param name="baseRadialDeltaV">The base amount of velocity that will be added to entities in range towards the epicenter of the pulse.</param>
/// <param name="baseTangentialDeltaV">The base amount of velocity that will be added to entities in range counterclockwise relative to the epicenter of the pulse.</param> /// <param name="baseTangentialDeltaV">The base amount of velocity that will be added to entities in range counterclockwise relative to the epicenter of the pulse.</param>
public void GravPulse(MapCoordinates mapPos, float maxRange, float minRange = 0.0f, float baseRadialDeltaV = 0.0f, float baseTangentialDeltaV = 0.0f) public void GravPulse(MapCoordinates mapPos, float maxRange, float minRange = 0.0f, float baseRadialDeltaV = 0.0f, float baseTangentialDeltaV = 0.0f)
=> GravPulse(mapPos, maxRange, minRange, new Matrix3( => GravPulse(mapPos, maxRange, minRange, new Matrix3x2(
baseRadialDeltaV, +baseTangentialDeltaV, 0.0f, baseRadialDeltaV, -baseTangentialDeltaV, 0.0f,
-baseTangentialDeltaV, baseRadialDeltaV, 0.0f, +baseTangentialDeltaV, baseRadialDeltaV, 0.0f
0.0f, 0.0f, 1.0f
)); ));
#endregion GravPulse #endregion GravPulse

View File

@@ -396,7 +396,7 @@ public sealed partial class GunSystem : SharedGunSystem
var (_, gridRot, gridInvMatrix) = TransformSystem.GetWorldPositionRotationInvMatrix(gridXform, xformQuery); var (_, gridRot, gridInvMatrix) = TransformSystem.GetWorldPositionRotationInvMatrix(gridXform, xformQuery);
fromCoordinates = new EntityCoordinates(gridUid.Value, fromCoordinates = new EntityCoordinates(gridUid.Value,
gridInvMatrix.Transform(fromCoordinates.ToMapPos(EntityManager, TransformSystem))); Vector2.Transform(fromCoordinates.ToMapPos(EntityManager, TransformSystem), gridInvMatrix));
// Use the fallback angle I guess? // Use the fallback angle I guess?
angle -= gridRot; angle -= gridRot;

View File

@@ -1,3 +1,4 @@
using System.Numerics;
using Robust.Shared.GameStates; using Robust.Shared.GameStates;
using Robust.Shared.Map; using Robust.Shared.Map;
using Robust.Shared.Serialization; using Robust.Shared.Serialization;
@@ -15,7 +16,7 @@ public sealed partial class ExplosionVisualsComponent : Component
public Dictionary<EntityUid, Dictionary<int, List<Vector2i>>> Tiles = new(); public Dictionary<EntityUid, Dictionary<int, List<Vector2i>>> Tiles = new();
public List<float> Intensity = new(); public List<float> Intensity = new();
public string ExplosionType = string.Empty; public string ExplosionType = string.Empty;
public Matrix3 SpaceMatrix; public Matrix3x2 SpaceMatrix;
public ushort SpaceTileSize; public ushort SpaceTileSize;
} }
@@ -27,7 +28,7 @@ public sealed class ExplosionVisualsState : ComponentState
public Dictionary<NetEntity, Dictionary<int, List<Vector2i>>> Tiles; public Dictionary<NetEntity, Dictionary<int, List<Vector2i>>> Tiles;
public List<float> Intensity; public List<float> Intensity;
public string ExplosionType = string.Empty; public string ExplosionType = string.Empty;
public Matrix3 SpaceMatrix; public Matrix3x2 SpaceMatrix;
public ushort SpaceTileSize; public ushort SpaceTileSize;
public ExplosionVisualsState( public ExplosionVisualsState(
@@ -36,7 +37,7 @@ public sealed class ExplosionVisualsState : ComponentState
List<float> intensity, List<float> intensity,
Dictionary<int, List<Vector2i>>? spaceTiles, Dictionary<int, List<Vector2i>>? spaceTiles,
Dictionary<NetEntity, Dictionary<int, List<Vector2i>>> tiles, Dictionary<NetEntity, Dictionary<int, List<Vector2i>>> tiles,
Matrix3 spaceMatrix, Matrix3x2 spaceMatrix,
ushort spaceTileSize) ushort spaceTileSize)
{ {
Epicenter = epicenter; Epicenter = epicenter;

View File

@@ -192,7 +192,7 @@ public abstract class SharedItemSystem : EntitySystem
var shapes = GetItemShape(entity); var shapes = GetItemShape(entity);
var boundingShape = shapes.GetBoundingBox(); var boundingShape = shapes.GetBoundingBox();
var boundingCenter = ((Box2) boundingShape).Center; var boundingCenter = ((Box2) boundingShape).Center;
var matty = Matrix3.CreateTransform(boundingCenter, rotation); var matty = Matrix3Helpers.CreateTransform(boundingCenter, rotation);
var drift = boundingShape.BottomLeft - matty.TransformBox(boundingShape).BottomLeft; var drift = boundingShape.BottomLeft - matty.TransformBox(boundingShape).BottomLeft;
var adjustedShapes = new List<Box2i>(); var adjustedShapes = new List<Box2i>();

View File

@@ -44,7 +44,7 @@ public sealed class TurfSystem : EntitySystem
var size = grid.TileSize; var size = grid.TileSize;
var localPos = new Vector2(indices.X * size + (size / 2f), indices.Y * size + (size / 2f)); var localPos = new Vector2(indices.X * size + (size / 2f), indices.Y * size + (size / 2f));
var worldPos = matrix.Transform(localPos); var worldPos = Vector2.Transform(localPos, matrix);
// This is scaled to 95 % so it doesn't encompass walls on other tiles. // This is scaled to 95 % so it doesn't encompass walls on other tiles.
var tileAabb = Box2.UnitCentered.Scale(0.95f * size); var tileAabb = Box2.UnitCentered.Scale(0.95f * size);

View File

@@ -751,7 +751,7 @@ public abstract class SharedMeleeWeaponSystem : EntitySystem
return; return;
var invMatrix = TransformSystem.GetInvWorldMatrix(userXform); var invMatrix = TransformSystem.GetInvWorldMatrix(userXform);
var localPos = invMatrix.Transform(coordinates.Position); var localPos = Vector2.Transform(coordinates.Position, invMatrix);
if (localPos.LengthSquared() <= 0f) if (localPos.LengthSquared() <= 0f)
return; return;