mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-14 19:29:36 +01:00
Replace Matrix3 with System.Numerics.Matrix3x2 (#5078)
* Delete Matrix3. Replace with System.Numerics.Matrix3x2 * Feedback * release notes
This commit is contained in:
@@ -35,7 +35,7 @@ END TEMPLATE-->
|
||||
|
||||
### Breaking changes
|
||||
|
||||
*None yet*
|
||||
* `Matrix3` has been replaced with `System.Numerics.Matrix3x2`. Various Matrix related methods have been turned into extension methods in the `Matrix3Helpers` class.
|
||||
|
||||
### New features
|
||||
|
||||
|
||||
@@ -368,7 +368,7 @@ namespace Robust.Client.Debugging
|
||||
}
|
||||
|
||||
worldHandle.UseShader(null);
|
||||
worldHandle.SetTransform(Matrix3.Identity);
|
||||
worldHandle.SetTransform(Matrix3x2.Identity);
|
||||
}
|
||||
|
||||
private void DrawScreen(DrawingHandleScreen screenHandle, OverlayDrawArgs args)
|
||||
@@ -443,7 +443,7 @@ namespace Robust.Client.Debugging
|
||||
}
|
||||
|
||||
screenHandle.UseShader(null);
|
||||
screenHandle.SetTransform(Matrix3.Identity);
|
||||
screenHandle.SetTransform(Matrix3x2.Identity);
|
||||
}
|
||||
|
||||
protected internal override void Draw(in OverlayDrawArgs args)
|
||||
@@ -520,11 +520,11 @@ namespace Robust.Client.Debugging
|
||||
var matrix1 = xform1.WorldMatrix;
|
||||
var matrix2 = xform2.WorldMatrix;
|
||||
|
||||
var xf1 = new Vector2(matrix1.R0C2, matrix1.R1C2);
|
||||
var xf2 = new Vector2(matrix2.R0C2, matrix2.R1C2);
|
||||
var xf1 = new Vector2(matrix1.M31, matrix1.M32);
|
||||
var xf2 = new Vector2(matrix2.M31, matrix2.M32);
|
||||
|
||||
var p1 = matrix1.Transform(joint.LocalAnchorA);
|
||||
var p2 = matrix2.Transform(joint.LocalAnchorB);
|
||||
var p1 = Vector2.Transform(joint.LocalAnchorA, matrix1);
|
||||
var p2 = Vector2.Transform(joint.LocalAnchorB, matrix2);
|
||||
|
||||
var xfa = new Transform(xf1, xform1.WorldRotation);
|
||||
var xfb = new Transform(xf2, xform2.WorldRotation);
|
||||
|
||||
@@ -150,7 +150,7 @@ namespace Robust.Client.GameObjects
|
||||
[DataField("color")]
|
||||
private Color color = Color.White;
|
||||
|
||||
public Matrix3 LocalMatrix = Matrix3.Identity;
|
||||
public Matrix3x2 LocalMatrix = Matrix3x2.Identity;
|
||||
|
||||
[Animatable]
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
@@ -389,10 +389,10 @@ namespace Robust.Client.GameObjects
|
||||
|
||||
internal void UpdateLocalMatrix()
|
||||
{
|
||||
LocalMatrix = Matrix3.CreateTransform(in offset, in rotation, in scale);
|
||||
LocalMatrix = Matrix3Helpers.CreateTransform(in offset, in rotation, in scale);
|
||||
}
|
||||
|
||||
public Matrix3 GetLocalMatrix()
|
||||
public Matrix3x2 GetLocalMatrix()
|
||||
{
|
||||
return LocalMatrix;
|
||||
}
|
||||
@@ -1304,22 +1304,21 @@ namespace Robust.Client.GameObjects
|
||||
|
||||
// worldRotation + eyeRotation should be the angle of the entity on-screen. If no-rot is enabled this is just set to zero.
|
||||
// However, at some point later the eye-matrix is applied separately, so we subtract -eye rotation for now:
|
||||
var entityMatrix = Matrix3.CreateTransform(worldPosition, NoRotation ? -eyeRotation : worldRotation - cardinal);
|
||||
var entityMatrix = Matrix3Helpers.CreateTransform(worldPosition, NoRotation ? -eyeRotation : worldRotation - cardinal);
|
||||
|
||||
Matrix3.Multiply(in LocalMatrix, in entityMatrix, out var transformSprite);
|
||||
var transformSprite = Matrix3x2.Multiply(LocalMatrix, entityMatrix);
|
||||
|
||||
if (GranularLayersRendering)
|
||||
{
|
||||
//Default rendering
|
||||
entityMatrix = Matrix3.CreateTransform(worldPosition, worldRotation);
|
||||
Matrix3.Multiply(in LocalMatrix, in entityMatrix, out var transformDefault);
|
||||
entityMatrix = Matrix3Helpers.CreateTransform(worldPosition, worldRotation);
|
||||
var transformDefault = Matrix3x2.Multiply(LocalMatrix, entityMatrix);
|
||||
//Snap to cardinals
|
||||
entityMatrix = Matrix3.CreateTransform(worldPosition, worldRotation - angle.GetCardinalDir().ToAngle());
|
||||
Matrix3.Multiply(in LocalMatrix, in entityMatrix, out var transformSnap);
|
||||
entityMatrix = Matrix3Helpers.CreateTransform(worldPosition, worldRotation - angle.GetCardinalDir().ToAngle());
|
||||
var transformSnap = Matrix3x2.Multiply(LocalMatrix, entityMatrix);
|
||||
//No rotation
|
||||
entityMatrix = Matrix3.CreateTransform(worldPosition, -eyeRotation);
|
||||
Matrix3.Multiply(in LocalMatrix, in entityMatrix, out var transformNoRot);
|
||||
|
||||
entityMatrix = Matrix3Helpers.CreateTransform(worldPosition, -eyeRotation);
|
||||
var transformNoRot = Matrix3x2.Multiply(LocalMatrix, entityMatrix);
|
||||
|
||||
foreach (var layer in Layers) {
|
||||
switch (layer.RenderingStrategy)
|
||||
@@ -1546,7 +1545,7 @@ namespace Robust.Client.GameObjects
|
||||
private RSI.State? _actualState;
|
||||
[ViewVariables] public RSI.State? ActualState => _actualState;
|
||||
|
||||
public Matrix3 LocalMatrix = Matrix3.Identity;
|
||||
public Matrix3x2 LocalMatrix = Matrix3x2.Identity;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public Vector2 Scale
|
||||
@@ -1692,7 +1691,7 @@ namespace Robust.Client.GameObjects
|
||||
|
||||
internal void UpdateLocalMatrix()
|
||||
{
|
||||
LocalMatrix = Matrix3.CreateTransform(in _offset, in _rotation, in _scale);
|
||||
LocalMatrix = Matrix3Helpers.CreateTransform(in _offset, in _rotation, in _scale);
|
||||
}
|
||||
|
||||
RSI? ISpriteLayer.Rsi { get => RSI; set => SetRsi(value); }
|
||||
@@ -1964,27 +1963,27 @@ namespace Robust.Client.GameObjects
|
||||
/// Given the apparent rotation of an entity on screen (world + eye rotation), get layer's matrix for drawing &
|
||||
/// relevant RSI direction.
|
||||
/// </summary>
|
||||
public void GetLayerDrawMatrix(RsiDirection dir, out Matrix3 layerDrawMatrix)
|
||||
public void GetLayerDrawMatrix(RsiDirection dir, out Matrix3x2 layerDrawMatrix)
|
||||
{
|
||||
if (_parent.NoRotation || dir == RsiDirection.South)
|
||||
layerDrawMatrix = LocalMatrix;
|
||||
else
|
||||
{
|
||||
Matrix3.Multiply(in _rsiDirectionMatrices[(int)dir], in LocalMatrix, out layerDrawMatrix);
|
||||
layerDrawMatrix = Matrix3x2.Multiply(_rsiDirectionMatrices[(int)dir], LocalMatrix);
|
||||
}
|
||||
}
|
||||
|
||||
private static Matrix3[] _rsiDirectionMatrices = new Matrix3[]
|
||||
private static Matrix3x2[] _rsiDirectionMatrices = new Matrix3x2[]
|
||||
{
|
||||
// array order chosen such that this array can be indexed by casing an RSI direction to an int
|
||||
Matrix3.Identity, // should probably just avoid matrix multiplication altogether if the direction is south.
|
||||
Matrix3.CreateRotation(-Direction.North.ToAngle()),
|
||||
Matrix3.CreateRotation(-Direction.East.ToAngle()),
|
||||
Matrix3.CreateRotation(-Direction.West.ToAngle()),
|
||||
Matrix3.CreateRotation(-Direction.SouthEast.ToAngle()),
|
||||
Matrix3.CreateRotation(-Direction.SouthWest.ToAngle()),
|
||||
Matrix3.CreateRotation(-Direction.NorthEast.ToAngle()),
|
||||
Matrix3.CreateRotation(-Direction.NorthWest.ToAngle())
|
||||
Matrix3x2.Identity, // should probably just avoid matrix multiplication altogether if the direction is south.
|
||||
Matrix3Helpers.CreateRotation(-Direction.North.ToAngle()),
|
||||
Matrix3Helpers.CreateRotation(-Direction.East.ToAngle()),
|
||||
Matrix3Helpers.CreateRotation(-Direction.West.ToAngle()),
|
||||
Matrix3Helpers.CreateRotation(-Direction.SouthEast.ToAngle()),
|
||||
Matrix3Helpers.CreateRotation(-Direction.SouthWest.ToAngle()),
|
||||
Matrix3Helpers.CreateRotation(-Direction.NorthEast.ToAngle()),
|
||||
Matrix3Helpers.CreateRotation(-Direction.NorthWest.ToAngle())
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
@@ -2018,7 +2017,7 @@ namespace Robust.Client.GameObjects
|
||||
/// <summary>
|
||||
/// Render a layer. This assumes that the input angle is between 0 and 2pi.
|
||||
/// </summary>
|
||||
internal void Render(DrawingHandleWorld drawingHandle, ref Matrix3 spriteMatrix, Angle angle, Direction? overrideDirection)
|
||||
internal void Render(DrawingHandleWorld drawingHandle, ref Matrix3x2 spriteMatrix, Angle angle, Direction? overrideDirection)
|
||||
{
|
||||
if (!Visible || Blank)
|
||||
return;
|
||||
@@ -2040,7 +2039,7 @@ namespace Robust.Client.GameObjects
|
||||
if (CopyToShaderParameters == null)
|
||||
{
|
||||
// Set the drawing transform for this layer
|
||||
Matrix3.Multiply(in layerMatrix, in spriteMatrix, out var transformMatrix);
|
||||
var transformMatrix = Matrix3x2.Multiply(layerMatrix, spriteMatrix);
|
||||
drawingHandle.SetTransform(in transformMatrix);
|
||||
|
||||
RenderTexture(drawingHandle, texture);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Numerics;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Shared.Console;
|
||||
using Robust.Shared.Containers;
|
||||
@@ -118,7 +119,7 @@ public sealed class EntityLookupOverlay : Overlay
|
||||
//DebugTools.Assert(!ent.IsInContainer(_entityManager));
|
||||
var (entPos, entRot) = _transform.GetWorldPositionRotation(ent);
|
||||
|
||||
var lookupPos = invMatrix.Transform(entPos);
|
||||
var lookupPos = Vector2.Transform(entPos, invMatrix);
|
||||
var lookupRot = entRot - rotation;
|
||||
|
||||
var aabb = _lookup.GetAABB(ent, lookupPos, lookupRot, xform, _xformQuery);
|
||||
@@ -127,6 +128,6 @@ public sealed class EntityLookupOverlay : Overlay
|
||||
}
|
||||
});
|
||||
|
||||
worldHandle.SetTransform(Matrix3.Identity);
|
||||
worldHandle.SetTransform(Matrix3x2.Identity);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,7 +109,7 @@ namespace Robust.Client.GameObjects
|
||||
}
|
||||
}
|
||||
|
||||
worldHandle.SetTransform(Matrix3.Identity);
|
||||
worldHandle.SetTransform(Matrix3x2.Identity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,18 +101,16 @@ namespace Robust.Client.Graphics
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void GetScreenProjectionMatrix(out Matrix3 projMatrix)
|
||||
public void GetScreenProjectionMatrix(out Matrix3x2 projMatrix)
|
||||
{
|
||||
Matrix3 result = default;
|
||||
Matrix3x2 result = default;
|
||||
|
||||
result.R0C0 = PixelsPerMeter;
|
||||
result.R1C1 = -PixelsPerMeter;
|
||||
result.M11 = PixelsPerMeter;
|
||||
result.M22 = -PixelsPerMeter;
|
||||
|
||||
var screenSize = _displayManager.ScreenSize;
|
||||
result.R0C2 = screenSize.X / 2f;
|
||||
result.R1C2 = screenSize.Y / 2f;
|
||||
|
||||
result.R2C2 = 1;
|
||||
result.M31 = screenSize.X / 2f;
|
||||
result.M32 = screenSize.Y / 2f;
|
||||
|
||||
/* column major
|
||||
Sx 0 Tx
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Numerics;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
using Robust.Shared.Graphics;
|
||||
@@ -44,7 +44,7 @@ namespace Robust.Client.Graphics
|
||||
/// to UI screen space.
|
||||
/// </summary>
|
||||
/// <param name="projMatrix"></param>
|
||||
void GetScreenProjectionMatrix(out Matrix3 projMatrix);
|
||||
void GetScreenProjectionMatrix(out Matrix3x2 projMatrix);
|
||||
|
||||
/// <summary>
|
||||
/// Projects a point from world space to UI screen space using the main viewport.
|
||||
|
||||
@@ -367,7 +367,7 @@ namespace Robust.Client.Graphics.Clyde
|
||||
_renderHandle.UseShader(entry.Sprite.PostShader);
|
||||
CalcScreenMatrices(viewport.Size, out var proj, out var view);
|
||||
_renderHandle.SetProjView(proj, view);
|
||||
_renderHandle.SetModelTransform(Matrix3.Identity);
|
||||
_renderHandle.SetModelTransform(Matrix3x2.Identity);
|
||||
|
||||
var rounded = roundedPos - entityPostRenderTarget.Size / 2;
|
||||
|
||||
@@ -530,7 +530,7 @@ namespace Robust.Client.Graphics.Clyde
|
||||
// Because the math is wrong.
|
||||
// So there are distortions from incorrect projection.
|
||||
_renderHandle.UseShader(_fovDebugShaderInstance);
|
||||
_renderHandle.DrawingHandleScreen.SetTransform(Matrix3.Identity);
|
||||
_renderHandle.DrawingHandleScreen.SetTransform(Matrix3x2.Identity);
|
||||
var pos = UIBox2.FromDimensions(viewport.Size / 2 - new Vector2(200, 200), new Vector2(400, 400));
|
||||
_renderHandle.DrawingHandleScreen.DrawTextureRect(FovTexture, pos);
|
||||
}
|
||||
@@ -538,7 +538,7 @@ namespace Robust.Client.Graphics.Clyde
|
||||
if (DebugLayers == ClydeDebugLayers.Light)
|
||||
{
|
||||
_renderHandle.UseShader(null);
|
||||
_renderHandle.DrawingHandleScreen.SetTransform(Matrix3.Identity);
|
||||
_renderHandle.DrawingHandleScreen.SetTransform(Matrix3x2.Identity);
|
||||
_renderHandle.DrawingHandleScreen.DrawTextureRect(
|
||||
viewport.WallBleedIntermediateRenderTarget2.Texture,
|
||||
UIBox2.FromDimensions(Vector2.Zero, viewport.Size), new Color(1, 1, 1, 0.5f));
|
||||
|
||||
@@ -98,28 +98,34 @@ namespace Robust.Client.Graphics.Clyde
|
||||
[FieldOffset(20 * sizeof(float))] public Vector3 ViewMatrixC2;
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public ProjViewMatrices(in Matrix3 projMatrix, in Matrix3 viewMatrix)
|
||||
public ProjViewMatrices(in Matrix3x2 projMatrix, in Matrix3x2 viewMatrix)
|
||||
{
|
||||
ProjMatrixC0 = new Vector3(projMatrix.R0C0, projMatrix.R1C0, projMatrix.R2C0);
|
||||
ProjMatrixC1 = new Vector3(projMatrix.R0C1, projMatrix.R1C1, projMatrix.R2C1);
|
||||
ProjMatrixC2 = new Vector3(projMatrix.R0C2, projMatrix.R1C2, projMatrix.R2C2);
|
||||
// We put the rows of the input matrix into the columns of our GPU matrices
|
||||
// this transpose is required, as in C#, we premultiply vectors with matrices
|
||||
// (vM) while GL postmultiplies vectors with matrices (Mv); however, since
|
||||
// the Matrix3x2 data is stored row-major, and GL uses column-major, the
|
||||
// memory layout is the same (or would be, if Matrix3x2 didn't have an
|
||||
// implicit column)
|
||||
ProjMatrixC0 = new Vector3(projMatrix.M11, projMatrix.M12, 0);
|
||||
ProjMatrixC1 = new Vector3(projMatrix.M21, projMatrix.M22, 0);
|
||||
ProjMatrixC2 = new Vector3(projMatrix.M31, projMatrix.M32, 1);
|
||||
|
||||
ViewMatrixC0 = new Vector3(viewMatrix.R0C0, viewMatrix.R1C0, viewMatrix.R2C0);
|
||||
ViewMatrixC1 = new Vector3(viewMatrix.R0C1, viewMatrix.R1C1, viewMatrix.R2C1);
|
||||
ViewMatrixC2 = new Vector3(viewMatrix.R0C2, viewMatrix.R1C2, viewMatrix.R2C2);
|
||||
ViewMatrixC0 = new Vector3(viewMatrix.M11, viewMatrix.M12, 0);
|
||||
ViewMatrixC1 = new Vector3(viewMatrix.M21, viewMatrix.M22, 0);
|
||||
ViewMatrixC2 = new Vector3(viewMatrix.M31, viewMatrix.M32, 1);
|
||||
}
|
||||
|
||||
public void Apply(Clyde clyde, GLShaderProgram program)
|
||||
{
|
||||
program.SetUniformMaybe("projectionMatrix", new Matrix3(
|
||||
ProjMatrixC0.X, ProjMatrixC1.X, ProjMatrixC2.X,
|
||||
ProjMatrixC0.Y, ProjMatrixC1.Y, ProjMatrixC2.Y,
|
||||
ProjMatrixC0.Z, ProjMatrixC1.Z, ProjMatrixC2.Z
|
||||
program.SetUniformMaybe("projectionMatrix", new Matrix3x2(
|
||||
ProjMatrixC0.X, ProjMatrixC0.Y, // Implicit 0
|
||||
ProjMatrixC1.X, ProjMatrixC1.Y, // Implicit 0
|
||||
ProjMatrixC2.X, ProjMatrixC2.Y // Implicit 1
|
||||
));
|
||||
program.SetUniformMaybe("viewMatrix", new Matrix3(
|
||||
ViewMatrixC0.X, ViewMatrixC1.X, ViewMatrixC2.X,
|
||||
ViewMatrixC0.Y, ViewMatrixC1.Y, ViewMatrixC2.Y,
|
||||
ViewMatrixC0.Z, ViewMatrixC1.Z, ViewMatrixC2.Z
|
||||
program.SetUniformMaybe("viewMatrix", new Matrix3x2(
|
||||
ViewMatrixC0.X, ViewMatrixC0.Y, // Implicit 0
|
||||
ViewMatrixC1.X, ViewMatrixC1.Y, // Implicit 0
|
||||
ViewMatrixC2.X, ViewMatrixC2.Y // Implicit 1
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -492,18 +492,18 @@ namespace Robust.Client.Graphics.Clyde
|
||||
|
||||
var offset = new Vector2(component.Radius, component.Radius);
|
||||
|
||||
Matrix3 matrix;
|
||||
Matrix3x2 matrix;
|
||||
if (mask == null)
|
||||
{
|
||||
matrix = Matrix3.Identity;
|
||||
matrix = Matrix3x2.Identity;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Only apply rotation if a mask is said, because else it doesn't matter.
|
||||
matrix = Matrix3.CreateRotation(rotation);
|
||||
matrix = Matrix3Helpers.CreateRotation(rotation);
|
||||
}
|
||||
|
||||
(matrix.R0C2, matrix.R1C2) = lightPos;
|
||||
(matrix.M31, matrix.M32) = lightPos;
|
||||
|
||||
_drawQuad(-offset, offset, matrix, lightShader);
|
||||
}
|
||||
@@ -692,7 +692,7 @@ namespace Robust.Client.Graphics.Clyde
|
||||
|
||||
// Blur horizontally to _wallBleedIntermediateRenderTarget1.
|
||||
shader.SetUniformMaybe("direction", Vector2.UnitX);
|
||||
_drawQuad(Vector2.Zero, viewport.Size, Matrix3.Identity, shader);
|
||||
_drawQuad(Vector2.Zero, viewport.Size, Matrix3x2.Identity, shader);
|
||||
|
||||
SetTexture(TextureUnit.Texture0, viewport.LightBlurTarget.Texture);
|
||||
|
||||
@@ -700,7 +700,7 @@ namespace Robust.Client.Graphics.Clyde
|
||||
|
||||
// Blur vertically to _wallBleedIntermediateRenderTarget2.
|
||||
shader.SetUniformMaybe("direction", Vector2.UnitY);
|
||||
_drawQuad(Vector2.Zero, viewport.Size, Matrix3.Identity, shader);
|
||||
_drawQuad(Vector2.Zero, viewport.Size, Matrix3x2.Identity, shader);
|
||||
|
||||
SetTexture(TextureUnit.Texture0, viewport.LightRenderTarget.Texture);
|
||||
}
|
||||
@@ -754,14 +754,14 @@ namespace Robust.Client.Graphics.Clyde
|
||||
|
||||
// Blur horizontally to _wallBleedIntermediateRenderTarget1.
|
||||
shader.SetUniformMaybe("direction", Vector2.UnitX);
|
||||
_drawQuad(Vector2.Zero, viewport.Size, Matrix3.Identity, shader);
|
||||
_drawQuad(Vector2.Zero, viewport.Size, Matrix3x2.Identity, shader);
|
||||
|
||||
SetTexture(TextureUnit.Texture0, viewport.WallBleedIntermediateRenderTarget1.Texture);
|
||||
BindRenderTargetFull(viewport.WallBleedIntermediateRenderTarget2);
|
||||
|
||||
// Blur vertically to _wallBleedIntermediateRenderTarget2.
|
||||
shader.SetUniformMaybe("direction", Vector2.UnitY);
|
||||
_drawQuad(Vector2.Zero, viewport.Size, Matrix3.Identity, shader);
|
||||
_drawQuad(Vector2.Zero, viewport.Size, Matrix3x2.Identity, shader);
|
||||
|
||||
SetTexture(TextureUnit.Texture0, viewport.WallBleedIntermediateRenderTarget2.Texture);
|
||||
}
|
||||
@@ -909,13 +909,13 @@ namespace Robust.Client.Graphics.Clyde
|
||||
// Second modification is that output must be fov-centred (difference-space)
|
||||
uZero -= fovCentre;
|
||||
|
||||
var clipToDiff = new Matrix3(in uX, in uY, in uZero);
|
||||
var clipToDiff = new Matrix3x2(uX.X, uX.Y, uY.X, uY.Y, uZero.X, uZero.Y);
|
||||
|
||||
fovShader.SetUniformMaybe("clipToDiff", clipToDiff);
|
||||
_drawQuad(Vector2.Zero, Vector2.One, Matrix3.Identity, fovShader);
|
||||
_drawQuad(Vector2.Zero, Vector2.One, Matrix3x2.Identity, fovShader);
|
||||
}
|
||||
|
||||
private void UpdateOcclusionGeometry(MapId map, Box2 expandedBounds, Matrix3 eyeTransform)
|
||||
private void UpdateOcclusionGeometry(MapId map, Box2 expandedBounds, Matrix3x2 eyeTransform)
|
||||
{
|
||||
using var _ = _prof.Group("UpdateOcclusionGeometry");
|
||||
using var _p = DebugGroup(nameof(UpdateOcclusionGeometry));
|
||||
@@ -968,9 +968,9 @@ namespace Robust.Client.Graphics.Clyde
|
||||
var worldTransform = xformSystem.GetWorldMatrix(transform, xforms);
|
||||
var box = occluder.BoundingBox;
|
||||
|
||||
var tl = worldTransform.Transform(box.TopLeft);
|
||||
var tr = worldTransform.Transform(box.TopRight);
|
||||
var br = worldTransform.Transform(box.BottomRight);
|
||||
var tl = Vector2.Transform(box.TopLeft, worldTransform);
|
||||
var tr = Vector2.Transform(box.TopRight, worldTransform);
|
||||
var br = Vector2.Transform(box.BottomRight, worldTransform);
|
||||
var bl = tl + br - tr;
|
||||
|
||||
// Faces.
|
||||
@@ -1010,9 +1010,9 @@ namespace Robust.Client.Graphics.Clyde
|
||||
//
|
||||
|
||||
// Calculate delta positions from camera.
|
||||
var dTl = eyeTransform.Transform(tl);
|
||||
var dTr = eyeTransform.Transform(tr);
|
||||
var dBl = eyeTransform.Transform(bl);
|
||||
var dTl = Vector2.Transform(tl, eyeTransform);
|
||||
var dTr = Vector2.Transform(tr, eyeTransform);
|
||||
var dBl = Vector2.Transform(bl, eyeTransform);
|
||||
var dBr = dBl + dTr - dTl;
|
||||
|
||||
// Get which neighbors are occluding.
|
||||
|
||||
@@ -33,17 +33,17 @@ namespace Robust.Client.Graphics.Clyde
|
||||
DrawingHandleWorld = new DrawingHandleWorldImpl(white, this);
|
||||
}
|
||||
|
||||
public void SetModelTransform(in Matrix3 matrix)
|
||||
public void SetModelTransform(in Matrix3x2 matrix)
|
||||
{
|
||||
_clyde.DrawSetModelTransform(matrix);
|
||||
}
|
||||
|
||||
public Matrix3 GetModelTransform()
|
||||
public Matrix3x2 GetModelTransform()
|
||||
{
|
||||
return _clyde.DrawGetModelTransform();
|
||||
}
|
||||
|
||||
public void SetProjView(in Matrix3 proj, in Matrix3 view)
|
||||
public void SetProjView(in Matrix3x2 proj, in Matrix3x2 view)
|
||||
{
|
||||
_clyde.DrawSetProjViewTransform(proj, view);
|
||||
}
|
||||
@@ -177,9 +177,9 @@ namespace Robust.Client.Graphics.Clyde
|
||||
var oldModel = _clyde._currentMatrixModel;
|
||||
|
||||
var newModel = oldModel;
|
||||
position += new Vector2(oldModel.R0C2, oldModel.R1C2);
|
||||
newModel.R0C2 = 0;
|
||||
newModel.R1C2 = 0;
|
||||
position += new Vector2(oldModel.M31, oldModel.M32);
|
||||
newModel.M31 = 0;
|
||||
newModel.M32 = 0;
|
||||
SetModelTransform(newModel);
|
||||
|
||||
// Switch rendering to pseudo-world space.
|
||||
@@ -194,7 +194,7 @@ namespace Robust.Client.Graphics.Clyde
|
||||
// Maaaaybe this is meant to have a minus sign.
|
||||
var rot = -(float) eyeRot.Theta;
|
||||
|
||||
var view = Matrix3.CreateTransform(ofsX, ofsY, rot, scale.X, scale.Y);
|
||||
var view = Matrix3Helpers.CreateTransform(ofsX, ofsY, rot, scale.X, scale.Y);
|
||||
SetProjView(proj, view);
|
||||
}
|
||||
|
||||
@@ -297,12 +297,12 @@ namespace Robust.Client.Graphics.Clyde
|
||||
_renderHandle = renderHandle;
|
||||
}
|
||||
|
||||
public override void SetTransform(in Matrix3 matrix)
|
||||
public override void SetTransform(in Matrix3x2 matrix)
|
||||
{
|
||||
_renderHandle.SetModelTransform(matrix);
|
||||
}
|
||||
|
||||
public override Matrix3 GetTransform()
|
||||
public override Matrix3x2 GetTransform()
|
||||
{
|
||||
return _renderHandle.GetModelTransform();
|
||||
}
|
||||
@@ -402,12 +402,12 @@ namespace Robust.Client.Graphics.Clyde
|
||||
_renderHandle = renderHandle;
|
||||
}
|
||||
|
||||
public override void SetTransform(in Matrix3 matrix)
|
||||
public override void SetTransform(in Matrix3x2 matrix)
|
||||
{
|
||||
_renderHandle.SetModelTransform(matrix);
|
||||
}
|
||||
|
||||
public override Matrix3 GetTransform()
|
||||
public override Matrix3x2 GetTransform()
|
||||
{
|
||||
return _renderHandle.GetModelTransform();
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ namespace Robust.Client.Graphics.Clyde
|
||||
// This matrix is applied to most normal geometry coming in.
|
||||
// Some is applied while the batch is being created (e.g. simple texture draw calls).
|
||||
// For DrawPrimitives OTOH the model matrix is passed along with the render command so is applied in the shader.
|
||||
private Matrix3 _currentMatrixModel = Matrix3.Identity;
|
||||
private Matrix3x2 _currentMatrixModel = Matrix3x2.Identity;
|
||||
|
||||
// Buffers and data for the batching system. Written into during (queue) and processed during (submit).
|
||||
private readonly Vertex2D[] BatchVertexData = new Vertex2D[MaxBatchQuads * 4];
|
||||
@@ -84,8 +84,8 @@ namespace Robust.Client.Graphics.Clyde
|
||||
|
||||
// Current projection & view matrices that are being used ot render.
|
||||
// This gets updated to keep track during (queue) and (misc), but not during (submit).
|
||||
private Matrix3 _currentMatrixProj;
|
||||
private Matrix3 _currentMatrixView;
|
||||
private Matrix3x2 _currentMatrixProj;
|
||||
private Matrix3x2 _currentMatrixView;
|
||||
|
||||
// (queue) and (misc), current state of the scissor test. Null if disabled.
|
||||
private UIBox2i? _currentScissorState;
|
||||
@@ -110,25 +110,25 @@ namespace Robust.Client.Graphics.Clyde
|
||||
UniformConstantsUBO.Reallocate(constants);
|
||||
}
|
||||
|
||||
private void CalcScreenMatrices(in Vector2i screenSize, out Matrix3 proj, out Matrix3 view)
|
||||
private void CalcScreenMatrices(in Vector2i screenSize, out Matrix3x2 proj, out Matrix3x2 view)
|
||||
{
|
||||
proj = Matrix3.Identity;
|
||||
proj.R0C0 = 2f / screenSize.X;
|
||||
proj.R1C1 = -2f / screenSize.Y;
|
||||
proj.R0C2 = -1;
|
||||
proj.R1C2 = 1;
|
||||
proj = Matrix3x2.Identity;
|
||||
proj.M11 = 2f / screenSize.X;
|
||||
proj.M22 = -2f / screenSize.Y;
|
||||
proj.M31 = -1;
|
||||
proj.M32 = 1;
|
||||
|
||||
if (_currentRenderTarget.FlipY)
|
||||
{
|
||||
proj.R1C1 *= -1;
|
||||
proj.R1C2 *= -1;
|
||||
proj.M22 *= -1;
|
||||
proj.M32 *= -1;
|
||||
}
|
||||
|
||||
view = Matrix3.Identity;
|
||||
view = Matrix3x2.Identity;
|
||||
}
|
||||
|
||||
private void CalcWorldMatrices(in Vector2i screenSize, in Vector2 renderScale, IEye eye,
|
||||
out Matrix3 proj, out Matrix3 view)
|
||||
out Matrix3x2 proj, out Matrix3x2 view)
|
||||
{
|
||||
eye.GetViewMatrix(out view, renderScale);
|
||||
|
||||
@@ -136,20 +136,20 @@ namespace Robust.Client.Graphics.Clyde
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private void CalcWorldProjMatrix(in Vector2i screenSize, out Matrix3 proj)
|
||||
private void CalcWorldProjMatrix(in Vector2i screenSize, out Matrix3x2 proj)
|
||||
{
|
||||
proj = Matrix3.Identity;
|
||||
proj.R0C0 = EyeManager.PixelsPerMeter * 2f / screenSize.X;
|
||||
proj.R1C1 = EyeManager.PixelsPerMeter * 2f / screenSize.Y;
|
||||
proj = Matrix3x2.Identity;
|
||||
proj.M11 = EyeManager.PixelsPerMeter * 2f / screenSize.X;
|
||||
proj.M22 = EyeManager.PixelsPerMeter * 2f / screenSize.Y;
|
||||
|
||||
if (_currentRenderTarget.FlipY)
|
||||
{
|
||||
proj.R1C1 *= -1;
|
||||
proj.R1C2 *= -1;
|
||||
proj.M22 *= -1;
|
||||
proj.M32 *= -1;
|
||||
}
|
||||
}
|
||||
|
||||
private void SetProjViewBuffer(in Matrix3 proj, in Matrix3 view)
|
||||
private void SetProjViewBuffer(in Matrix3x2 proj, in Matrix3x2 view)
|
||||
{
|
||||
// TODO: Fix perf here.
|
||||
// This immediately causes a glBufferData() call every time this is changed.
|
||||
@@ -160,7 +160,7 @@ namespace Robust.Client.Graphics.Clyde
|
||||
ProjViewUBO.Reallocate(combined);
|
||||
}
|
||||
|
||||
private void SetProjViewFull(in Matrix3 proj, in Matrix3 view)
|
||||
private void SetProjViewFull(in Matrix3x2 proj, in Matrix3x2 view)
|
||||
{
|
||||
_currentMatrixProj = proj;
|
||||
_currentMatrixView = view;
|
||||
@@ -285,21 +285,21 @@ namespace Robust.Client.Graphics.Clyde
|
||||
};
|
||||
}
|
||||
|
||||
private void _drawQuad(Vector2 a, Vector2 b, in Matrix3 modelMatrix, GLShaderProgram program)
|
||||
private void _drawQuad(Vector2 a, Vector2 b, in Matrix3x2 modelMatrix, GLShaderProgram program)
|
||||
{
|
||||
DrawQuadWithVao(QuadVAO, a, b, modelMatrix, program);
|
||||
}
|
||||
|
||||
private void DrawQuadWithVao(GLHandle vao, Vector2 a, Vector2 b, in Matrix3 modelMatrix,
|
||||
private void DrawQuadWithVao(GLHandle vao, Vector2 a, Vector2 b, in Matrix3x2 modelMatrix,
|
||||
GLShaderProgram program)
|
||||
{
|
||||
BindVertexArray(vao.Handle);
|
||||
CheckGlError();
|
||||
|
||||
var rectTransform = Matrix3.Identity;
|
||||
(rectTransform.R0C0, rectTransform.R1C1) = b - a;
|
||||
(rectTransform.R0C2, rectTransform.R1C2) = a;
|
||||
rectTransform.Multiply(modelMatrix);
|
||||
var rectTransform = Matrix3x2.Identity;
|
||||
(rectTransform.M11, rectTransform.M22) = b - a;
|
||||
(rectTransform.M31, rectTransform.M32) = a;
|
||||
rectTransform = rectTransform * modelMatrix;
|
||||
program.SetUniformMaybe(UniIModelMatrix, rectTransform);
|
||||
|
||||
_debugStats.LastGLDrawCalls += 1;
|
||||
@@ -315,7 +315,7 @@ namespace Robust.Client.Graphics.Clyde
|
||||
FlushBatchQueue();
|
||||
|
||||
// Reset renderer state.
|
||||
_currentMatrixModel = Matrix3.Identity;
|
||||
_currentMatrixModel = Matrix3x2.Identity;
|
||||
_queuedShaderInstance = _defaultShader;
|
||||
SetScissorFull(null);
|
||||
}
|
||||
@@ -496,7 +496,7 @@ namespace Robust.Client.Graphics.Clyde
|
||||
case bool b:
|
||||
program.SetUniform(name, b ? 1 : 0);
|
||||
break;
|
||||
case Matrix3 matrix3:
|
||||
case Matrix3x2 matrix3:
|
||||
program.SetUniform(name, matrix3);
|
||||
break;
|
||||
case Matrix4 matrix4:
|
||||
@@ -532,17 +532,17 @@ namespace Robust.Client.Graphics.Clyde
|
||||
return ref command;
|
||||
}
|
||||
|
||||
private void DrawSetModelTransform(in Matrix3 matrix)
|
||||
private void DrawSetModelTransform(in Matrix3x2 matrix)
|
||||
{
|
||||
_currentMatrixModel = matrix;
|
||||
}
|
||||
|
||||
private Matrix3 DrawGetModelTransform()
|
||||
private Matrix3x2 DrawGetModelTransform()
|
||||
{
|
||||
return _currentMatrixModel;
|
||||
}
|
||||
|
||||
private void DrawSetProjViewTransform(in Matrix3 proj, in Matrix3 view)
|
||||
private void DrawSetProjViewTransform(in Matrix3x2 proj, in Matrix3x2 view)
|
||||
{
|
||||
BreakBatch();
|
||||
|
||||
@@ -571,9 +571,9 @@ namespace Robust.Client.Graphics.Clyde
|
||||
EnsureBatchSpaceAvailable(4, GetQuadBatchIndexCount());
|
||||
EnsureBatchState(texture, true, GetQuadBatchPrimitiveType(), _queuedShader);
|
||||
|
||||
bl = _currentMatrixModel.Transform(bl);
|
||||
br = _currentMatrixModel.Transform(br);
|
||||
tr = _currentMatrixModel.Transform(tr);
|
||||
bl = Vector2.Transform(bl, _currentMatrixModel);
|
||||
br = Vector2.Transform(br, _currentMatrixModel);
|
||||
tr = Vector2.Transform(tr, _currentMatrixModel);
|
||||
tl = tr + bl - br;
|
||||
|
||||
// TODO: split batch if necessary.
|
||||
@@ -676,8 +676,8 @@ namespace Robust.Client.Graphics.Clyde
|
||||
EnsureBatchSpaceAvailable(2, 0);
|
||||
EnsureBatchState(_stockTextureWhite.TextureId, false, BatchPrimitiveType.LineList, _queuedShader);
|
||||
|
||||
a = _currentMatrixModel.Transform(a);
|
||||
b = _currentMatrixModel.Transform(b);
|
||||
a = Vector2.Transform(a, _currentMatrixModel);
|
||||
b = Vector2.Transform(b, _currentMatrixModel);
|
||||
|
||||
// TODO: split batch if necessary.
|
||||
var vIdx = BatchVertexIndex;
|
||||
@@ -807,7 +807,7 @@ namespace Robust.Client.Graphics.Clyde
|
||||
command.DrawBatch.ShaderInstance = metaData.ShaderInstance;
|
||||
|
||||
command.DrawBatch.Count = currentIndex - metaData.StartIndex;
|
||||
command.DrawBatch.ModelMatrix = Matrix3.Identity;
|
||||
command.DrawBatch.ModelMatrix = Matrix3x2.Identity;
|
||||
|
||||
_debugStats.LastBatches += 1;
|
||||
}
|
||||
@@ -882,7 +882,7 @@ namespace Robust.Client.Graphics.Clyde
|
||||
_queuedRenderCommands.Clear();
|
||||
_currentViewport = null;
|
||||
_lightingReady = false;
|
||||
_currentMatrixModel = Matrix3.Identity;
|
||||
_currentMatrixModel = Matrix3x2.Identity;
|
||||
SetScissorFull(null);
|
||||
BindRenderTargetFull(_mainWindow!.RenderTarget);
|
||||
_batchMetaData = null;
|
||||
@@ -961,13 +961,13 @@ namespace Robust.Client.Graphics.Clyde
|
||||
public BatchPrimitiveType PrimitiveType;
|
||||
|
||||
// TODO: this makes the render commands so much more large please remove.
|
||||
public Matrix3 ModelMatrix;
|
||||
public Matrix3x2 ModelMatrix;
|
||||
}
|
||||
|
||||
private struct RenderCommandProjViewMatrix
|
||||
{
|
||||
public Matrix3 ProjMatrix;
|
||||
public Matrix3 ViewMatrix;
|
||||
public Matrix3x2 ProjMatrix;
|
||||
public Matrix3x2 ViewMatrix;
|
||||
}
|
||||
|
||||
private struct RenderCommandScissor
|
||||
@@ -1056,11 +1056,11 @@ namespace Robust.Client.Graphics.Clyde
|
||||
|
||||
private readonly struct FullStoredRendererState
|
||||
{
|
||||
public readonly Matrix3 ProjMatrix;
|
||||
public readonly Matrix3 ViewMatrix;
|
||||
public readonly Matrix3x2 ProjMatrix;
|
||||
public readonly Matrix3x2 ViewMatrix;
|
||||
public readonly LoadedRenderTarget RenderTarget;
|
||||
|
||||
public FullStoredRendererState(in Matrix3 projMatrix, in Matrix3 viewMatrix,
|
||||
public FullStoredRendererState(in Matrix3x2 projMatrix, in Matrix3x2 viewMatrix,
|
||||
LoadedRenderTarget renderTarget)
|
||||
{
|
||||
ProjMatrix = projMatrix;
|
||||
|
||||
@@ -506,7 +506,7 @@ namespace Robust.Client.Graphics.Clyde
|
||||
data.Parameters[name] = value;
|
||||
}
|
||||
|
||||
private protected override void SetParameterImpl(string name, in Matrix3 value)
|
||||
private protected override void SetParameterImpl(string name, in Matrix3x2 value)
|
||||
{
|
||||
var data = Parent._shaderInstances[Handle];
|
||||
data.ParametersDirty = true;
|
||||
|
||||
@@ -52,7 +52,7 @@ namespace Robust.Client.Graphics.Clyde
|
||||
|
||||
// view matrix
|
||||
vp.Eye.GetViewMatrixInv(out var viewMatrixInv, vp.RenderScale);
|
||||
point = viewMatrixInv * point;
|
||||
point = Vector2.Transform(point, viewMatrixInv);
|
||||
|
||||
return point;
|
||||
}
|
||||
@@ -136,7 +136,7 @@ namespace Robust.Client.Graphics.Clyde
|
||||
|
||||
// view matrix
|
||||
Eye.GetViewMatrixInv(out var viewMatrixInv, RenderScale);
|
||||
newPoint = viewMatrixInv * newPoint;
|
||||
newPoint = Vector2.Transform(newPoint, viewMatrixInv);
|
||||
|
||||
return new MapCoordinates(newPoint, Eye.Position.MapId);
|
||||
}
|
||||
@@ -150,7 +150,7 @@ namespace Robust.Client.Graphics.Clyde
|
||||
var newPoint = point;
|
||||
|
||||
eye.GetViewMatrix(out var viewMatrix, RenderScale);
|
||||
newPoint = viewMatrix * newPoint;
|
||||
newPoint = Vector2.Transform(newPoint, viewMatrix);
|
||||
|
||||
// (inlined version of UiProjMatrix)
|
||||
newPoint *= new Vector2(1, -1) * EyeManager.PixelsPerMeter;
|
||||
@@ -159,14 +159,14 @@ namespace Robust.Client.Graphics.Clyde
|
||||
return newPoint;
|
||||
}
|
||||
|
||||
public Matrix3 GetWorldToLocalMatrix()
|
||||
public Matrix3x2 GetWorldToLocalMatrix()
|
||||
{
|
||||
if (Eye == null)
|
||||
return Matrix3.Identity;
|
||||
return Matrix3x2.Identity;
|
||||
|
||||
Eye.GetViewMatrix(out var viewMatrix, RenderScale * new Vector2(EyeManager.PixelsPerMeter, -EyeManager.PixelsPerMeter));
|
||||
viewMatrix.R0C2 += Size.X / 2f;
|
||||
viewMatrix.R1C2 += Size.Y / 2f;
|
||||
viewMatrix.M31 += Size.X / 2f;
|
||||
viewMatrix.M32 += Size.Y / 2f;
|
||||
return viewMatrix;
|
||||
}
|
||||
|
||||
|
||||
@@ -361,7 +361,7 @@ namespace Robust.Client.Graphics.Clyde
|
||||
{
|
||||
}
|
||||
|
||||
private protected override void SetParameterImpl(string name, in Matrix3 value)
|
||||
private protected override void SetParameterImpl(string name, in Matrix3x2 value)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -482,7 +482,7 @@ namespace Robust.Client.Graphics.Clyde
|
||||
return default;
|
||||
}
|
||||
|
||||
public Matrix3 GetWorldToLocalMatrix() => default;
|
||||
public Matrix3x2 GetWorldToLocalMatrix() => default;
|
||||
|
||||
public Vector2 WorldToLocal(Vector2 point)
|
||||
{
|
||||
|
||||
@@ -247,28 +247,33 @@ namespace Robust.Client.Graphics.Clyde
|
||||
GL.Uniform1(uniformId, singles.Length, singles);
|
||||
}
|
||||
|
||||
public void SetUniform(string uniformName, in Matrix3 matrix)
|
||||
public void SetUniform(string uniformName, in Matrix3x2 matrix)
|
||||
{
|
||||
var uniformId = GetUniform(uniformName);
|
||||
SetUniformDirect(uniformId, matrix);
|
||||
}
|
||||
|
||||
public void SetUniform(int uniformName, in Matrix3 matrix)
|
||||
public void SetUniform(int uniformName, in Matrix3x2 matrix)
|
||||
{
|
||||
var uniformId = GetUniform(uniformName);
|
||||
SetUniformDirect(uniformId, matrix);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private unsafe void SetUniformDirect(int slot, in Matrix3 value, bool transpose=true)
|
||||
private unsafe void SetUniformDirect(int slot, in Matrix3x2 value)
|
||||
{
|
||||
Matrix3 tmpTranspose = value;
|
||||
if (transpose)
|
||||
{
|
||||
// transposition not supported on GLES2, & no access to _hasGLES
|
||||
tmpTranspose.Transpose();
|
||||
}
|
||||
GL.UniformMatrix3(slot, 1, false, (float*) &tmpTranspose);
|
||||
// We put the rows of the input matrix into the columns of our GPU matrices
|
||||
// this transpose is required, as in C#, we premultiply vectors with matrices
|
||||
// (vM) while GL postmultiplies vectors with matrices (Mv); however, since
|
||||
// the Matrix3x2 data is stored row-major, and GL uses column-major, the
|
||||
// memory layout is the same (or would be, if Matrix3x2 didn't have an
|
||||
// implicit column)
|
||||
var buf = stackalloc float[9]{
|
||||
value.M11, value.M12, 0,
|
||||
value.M21, value.M22, 0,
|
||||
value.M31, value.M32, 1
|
||||
};
|
||||
GL.UniformMatrix3(slot, 1, false, (float*)buf);
|
||||
_clyde.CheckGlError();
|
||||
}
|
||||
|
||||
@@ -474,7 +479,7 @@ namespace Robust.Client.Graphics.Clyde
|
||||
}
|
||||
}
|
||||
|
||||
public void SetUniformMaybe(string uniformName, in Matrix3 value)
|
||||
public void SetUniformMaybe(string uniformName, in Matrix3x2 value)
|
||||
{
|
||||
if (TryGetUniform(uniformName, out var slot))
|
||||
{
|
||||
@@ -490,7 +495,7 @@ namespace Robust.Client.Graphics.Clyde
|
||||
}
|
||||
}
|
||||
|
||||
public void SetUniformMaybe(int uniformName, in Matrix3 value)
|
||||
public void SetUniformMaybe(int uniformName, in Matrix3x2 value)
|
||||
{
|
||||
if (TryGetUniform(uniformName, out var slot))
|
||||
{
|
||||
|
||||
@@ -44,19 +44,19 @@ namespace Robust.Client.Graphics
|
||||
{
|
||||
CheckDisposed();
|
||||
|
||||
var matrix = Matrix3.CreateTransform(in position, in rotation, in scale);
|
||||
var matrix = Matrix3Helpers.CreateTransform(in position, in rotation, in scale);
|
||||
SetTransform(in matrix);
|
||||
}
|
||||
|
||||
public void SetTransform(in Vector2 position, in Angle rotation)
|
||||
{
|
||||
var matrix = Matrix3.CreateTransform(in position, in rotation);
|
||||
var matrix = Matrix3Helpers.CreateTransform(in position, in rotation);
|
||||
SetTransform(in matrix);
|
||||
}
|
||||
|
||||
public abstract void SetTransform(in Matrix3 matrix);
|
||||
public abstract void SetTransform(in Matrix3x2 matrix);
|
||||
|
||||
public abstract Matrix3 GetTransform();
|
||||
public abstract Matrix3x2 GetTransform();
|
||||
|
||||
public abstract void UseShader(ShaderInstance? shader);
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ namespace Robust.Client.Graphics
|
||||
/// <summary>
|
||||
/// Matrix equivalent of <see cref="LocalToWorld(Vector2)"/>.
|
||||
/// </summary>
|
||||
Matrix3 GetWorldToLocalMatrix();
|
||||
Matrix3x2 GetWorldToLocalMatrix();
|
||||
|
||||
/// <summary>
|
||||
/// Converts a point in world-space to the viewport's screen coordinates.
|
||||
|
||||
@@ -148,7 +148,7 @@ namespace Robust.Client.Graphics
|
||||
SetParameterImpl(name, value);
|
||||
}
|
||||
|
||||
public void SetParameter(string name, in Matrix3 value)
|
||||
public void SetParameter(string name, in Matrix3x2 value)
|
||||
{
|
||||
EnsureAlive();
|
||||
EnsureMutable();
|
||||
@@ -219,7 +219,7 @@ namespace Robust.Client.Graphics
|
||||
private protected abstract void SetParameterImpl(string name, int value);
|
||||
private protected abstract void SetParameterImpl(string name, Vector2i value);
|
||||
private protected abstract void SetParameterImpl(string name, bool value);
|
||||
private protected abstract void SetParameterImpl(string name, in Matrix3 value);
|
||||
private protected abstract void SetParameterImpl(string name, in Matrix3x2 value);
|
||||
private protected abstract void SetParameterImpl(string name, in Matrix4 value);
|
||||
private protected abstract void SetParameterImpl(string name, Texture value);
|
||||
private protected abstract void SetStencilImpl(StencilParameters value);
|
||||
|
||||
@@ -176,7 +176,7 @@ namespace Robust.Client.Graphics
|
||||
return node.AsVector4();
|
||||
}
|
||||
case ShaderDataType.Mat3:
|
||||
return node.AsMatrix3();
|
||||
return node.AsMatrix3x2();
|
||||
case ShaderDataType.Mat4:
|
||||
return node.AsMatrix4();
|
||||
default:
|
||||
@@ -219,7 +219,7 @@ namespace Robust.Client.Graphics
|
||||
case bool i:
|
||||
instance.SetParameter(key, i);
|
||||
break;
|
||||
case Matrix3 i:
|
||||
case Matrix3x2 i:
|
||||
instance.SetParameter(key, i);
|
||||
break;
|
||||
case Matrix4 i:
|
||||
|
||||
@@ -120,6 +120,6 @@ public sealed class TileEdgeOverlay : GridOverlay
|
||||
}
|
||||
}
|
||||
|
||||
args.WorldHandle.SetTransform(Matrix3.Identity);
|
||||
args.WorldHandle.SetTransform(Matrix3x2.Identity);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,7 +139,7 @@ namespace Robust.Client.Physics
|
||||
return true;
|
||||
}, true);
|
||||
|
||||
worldHandle.SetTransform(Matrix3.Identity);
|
||||
worldHandle.SetTransform(Matrix3x2.Identity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ using System.Buffers;
|
||||
using System.Collections.Generic;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Map.Components;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Physics.Components;
|
||||
using Robust.Shared.Physics.Dynamics;
|
||||
|
||||
@@ -567,7 +567,7 @@ namespace Robust.Client.UserInterface
|
||||
public Vector2i Position;
|
||||
public Color Modulate;
|
||||
public UIBox2i? ScissorBox;
|
||||
public ref Matrix3 CoordinateTransform;
|
||||
public ref Matrix3x2 CoordinateTransform;
|
||||
}
|
||||
|
||||
protected void RenderControl(ref ControlRenderArguments args, int childIndex, Vector2i position)
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System.Numerics;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.ResourceManagement;
|
||||
using Robust.Shared.IoC;
|
||||
@@ -20,19 +21,19 @@ public sealed class ColorSelectorStyleBox : StyleBoxTexture
|
||||
/// <summary>
|
||||
/// Base background colour.
|
||||
/// </summary>
|
||||
public Vector4 BaseColor;
|
||||
public Robust.Shared.Maths.Vector4 BaseColor;
|
||||
|
||||
/// <summary>
|
||||
/// Colour to add to the background colour along the X-axis.
|
||||
/// I.e., from left to right the background colour will vary from (BaseColour) to (BaseColour + XAxis)
|
||||
/// </summary>
|
||||
public Vector4 XAxis;
|
||||
public Robust.Shared.Maths.Vector4 XAxis;
|
||||
|
||||
/// <summary>
|
||||
/// Colour to add to the background colour along the y-axis.
|
||||
/// I.e., from left to right the background colour will vary from (BaseColour) to (BaseColour + XAxis)
|
||||
/// </summary>
|
||||
public Vector4 YAxis;
|
||||
public Robust.Shared.Maths.Vector4 YAxis;
|
||||
|
||||
/// <summary>
|
||||
/// If true, then <see cref="BaseColor"/>, <see cref="XAxis"/>, and <see cref="YAxis"/> will be interpreted as HSVa
|
||||
@@ -53,7 +54,7 @@ public sealed class ColorSelectorStyleBox : StyleBoxTexture
|
||||
var old = handle.GetShader();
|
||||
handle.UseShader(_shader);
|
||||
|
||||
var globalPixelPos = handle.GetTransform().Transform(default);
|
||||
var globalPixelPos = Vector2.Transform(default, handle.GetTransform());
|
||||
_shader.SetParameter("size", box.Size);
|
||||
_shader.SetParameter("offset", globalPixelPos);
|
||||
_shader.SetParameter("xAxis", XAxis);
|
||||
@@ -92,14 +93,14 @@ public sealed class ColorSelectorStyleBox : StyleBoxTexture
|
||||
{
|
||||
var colorData = Hsv
|
||||
? Color.ToHsv(color)
|
||||
: new Vector4(color.R, color.G, color.B, color.A);
|
||||
: new Robust.Shared.Maths.Vector4(color.R, color.G, color.B, color.A);
|
||||
SetBaseColor(colorData);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Helper method that sets the base color by taking in some color and removing the components that are controlled by the x and y axes.
|
||||
/// </summary>
|
||||
public void SetBaseColor(Vector4 colorData)
|
||||
public void SetBaseColor(Robust.Shared.Maths.Vector4 colorData)
|
||||
{
|
||||
BaseColor = colorData - colorData * XAxis - colorData * YAxis;
|
||||
}
|
||||
|
||||
@@ -43,11 +43,11 @@ namespace Robust.Client.UserInterface.CustomControls
|
||||
/// <remarks>
|
||||
/// This is generally just be a combination of <see cref="IClydeViewport.GetWorldToLocalMatrix"/> and <see cref="GetLocalToScreenMatrix"/>
|
||||
/// </remarks>
|
||||
Matrix3 GetWorldToScreenMatrix();
|
||||
Matrix3x2 GetWorldToScreenMatrix();
|
||||
|
||||
/// <summary>
|
||||
/// Returns a matrix that can be used to transform from view-port local to screen coordinates.
|
||||
/// </summary>
|
||||
Matrix3 GetLocalToScreenMatrix();
|
||||
Matrix3x2 GetLocalToScreenMatrix();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -155,17 +155,17 @@ namespace Robust.Client.UserInterface.CustomControls
|
||||
return WorldToLocalPixel(point) + GlobalPixelPosition;
|
||||
}
|
||||
|
||||
public Matrix3 GetWorldToScreenMatrix()
|
||||
public Matrix3x2 GetWorldToScreenMatrix()
|
||||
{
|
||||
if (Viewport == null)
|
||||
return Matrix3.Identity;
|
||||
return Matrix3x2.Identity;
|
||||
|
||||
return Viewport.GetWorldToLocalMatrix() * GetLocalToScreenMatrix();
|
||||
}
|
||||
|
||||
public Matrix3 GetLocalToScreenMatrix()
|
||||
public Matrix3x2 GetLocalToScreenMatrix()
|
||||
{
|
||||
return Matrix3.CreateTransform(GlobalPixelPosition, 0, Vector2.One / _viewportResolution);
|
||||
return Matrix3Helpers.CreateTransform(GlobalPixelPosition, 0, Vector2.One / _viewportResolution);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Numerics;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.Input;
|
||||
@@ -63,7 +63,7 @@ namespace Robust.Client.UserInterface
|
||||
Color GetMainClearColor();
|
||||
|
||||
void RenderControl(IRenderHandle renderHandle, ref int total, Control control, Vector2i position, Color modulate,
|
||||
UIBox2i? scissorBox, Matrix3 coordinateTransform);
|
||||
UIBox2i? scissorBox, Matrix3x2 coordinateTransform);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -130,9 +130,9 @@ internal sealed partial class UserInterfaceManager
|
||||
{
|
||||
var total = 0;
|
||||
var drawingHandle = renderHandle.DrawingHandleScreen;
|
||||
drawingHandle.SetTransform(Matrix3.Identity);
|
||||
RenderControl(renderHandle, ref total, root, Vector2i.Zero, Color.White, null, Matrix3.Identity);
|
||||
drawingHandle.SetTransform(Matrix3.Identity);
|
||||
drawingHandle.SetTransform(Matrix3x2.Identity);
|
||||
RenderControl(renderHandle, ref total, root, Vector2i.Zero, Color.White, null, Matrix3x2.Identity);
|
||||
drawingHandle.SetTransform(Matrix3x2.Identity);
|
||||
OnPostDrawUIRoot?.Invoke(new PostDrawUIRootEventArgs(root, drawingHandle));
|
||||
|
||||
_prof.WriteValue("Controls rendered", ProfData.Int32(total));
|
||||
|
||||
@@ -330,7 +330,7 @@ namespace Robust.Client.UserInterface
|
||||
}
|
||||
|
||||
public void RenderControl(IRenderHandle renderHandle, ref int total, Control control, Vector2i position, Color modulate,
|
||||
UIBox2i? scissorBox, Matrix3 coordinateTransform)
|
||||
UIBox2i? scissorBox, Matrix3x2 coordinateTransform)
|
||||
{
|
||||
if (!control.Visible)
|
||||
{
|
||||
@@ -378,8 +378,7 @@ namespace Robust.Client.UserInterface
|
||||
|
||||
var handle = renderHandle.DrawingHandleScreen;
|
||||
var oldXform = handle.GetTransform();
|
||||
var xform = oldXform;
|
||||
xform.Multiply(Matrix3.CreateTransform(position, Angle.Zero, Vector2.One));
|
||||
var xform = oldXform * Matrix3Helpers.CreateTransform(position, Angle.Zero, Vector2.One);
|
||||
handle.SetTransform(xform);
|
||||
modulate *= control.Modulate;
|
||||
|
||||
@@ -406,7 +405,7 @@ namespace Robust.Client.UserInterface
|
||||
|
||||
foreach (var child in control.Children)
|
||||
{
|
||||
var pos = position + (Vector2i) coordinateTransform.Transform(child.PixelPosition);
|
||||
var pos = position + (Vector2i)Vector2.Transform(child.PixelPosition, coordinateTransform);
|
||||
control.RenderChildOverride(ref args, child.GetPositionInParent(), pos);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,22 +4,6 @@ namespace Robust.Client.Utility
|
||||
{
|
||||
internal static class OpenTKConversions
|
||||
{
|
||||
public static OpenToolkit.Mathematics.Matrix3 ConvertOpenTK(this Matrix3 matrix)
|
||||
{
|
||||
return new()
|
||||
{
|
||||
M11 = matrix.R0C0,
|
||||
M12 = matrix.R0C1,
|
||||
M13 = matrix.R0C2,
|
||||
M21 = matrix.R1C0,
|
||||
M22 = matrix.R1C1,
|
||||
M23 = matrix.R1C2,
|
||||
M31 = matrix.R2C0,
|
||||
M32 = matrix.R2C1,
|
||||
M33 = matrix.R2C2
|
||||
};
|
||||
}
|
||||
|
||||
public static OpenToolkit.Mathematics.Color4 ConvertOpenTK(this Color color)
|
||||
{
|
||||
return new(color.R, color.G, color.B, color.A);
|
||||
|
||||
@@ -844,7 +844,7 @@ public sealed class MapLoaderSystem : EntitySystem
|
||||
|
||||
if (xformQuery.TryGetComponent(rootEntity, out var xform) && IsRoot(xform, mapQuery) && !HasComp<MapComponent>(rootEntity))
|
||||
{
|
||||
_transform.SetLocalPosition(xform, data.Options.TransformMatrix.Transform(xform.LocalPosition));
|
||||
_transform.SetLocalPosition(xform, Vector2.Transform(xform.LocalPosition, data.Options.TransformMatrix));
|
||||
xform.LocalRotation += data.Options.Rotation;
|
||||
}
|
||||
}
|
||||
@@ -856,7 +856,7 @@ public sealed class MapLoaderSystem : EntitySystem
|
||||
if (xformQuery.TryGetComponent(entity, out var xform) && IsRoot(xform, mapQuery))
|
||||
{
|
||||
// Don't want to trigger events
|
||||
xform._localPosition = data.Options.TransformMatrix.Transform(xform.LocalPosition);
|
||||
xform._localPosition = Vector2.Transform(xform.LocalPosition, data.Options.TransformMatrix);
|
||||
if (!xform.NoLocalRotation)
|
||||
xform._localRotation += data.Options.Rotation;
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ internal sealed class PvsChunk
|
||||
/// <summary>
|
||||
/// The <see cref="Root"/>'s inverse world matrix.
|
||||
/// </summary>
|
||||
public Matrix3 InvWorldMatrix { get; set; }
|
||||
public Matrix3x2 InvWorldMatrix { get; set; }
|
||||
|
||||
// These are only used while populating the chunk. They aren't local variables because the chunks are pooled, so
|
||||
// the same chunk can be repopulated more than once.
|
||||
|
||||
@@ -72,7 +72,7 @@ internal sealed partial class PvsSystem
|
||||
var xform = Transform(chunk.Root);
|
||||
DebugTools.AssertEqual(chunk.Map.Owner, xform.MapUid);
|
||||
chunk.InvWorldMatrix = xform.InvLocalMatrix;
|
||||
var worldPos = xform.LocalMatrix.Transform(chunk.Centre);
|
||||
var worldPos = Vector2.Transform(chunk.Centre, xform.LocalMatrix);
|
||||
chunk.Position = new(worldPos, xform.MapID);
|
||||
chunk.UpdateQueued = false;
|
||||
}
|
||||
@@ -137,7 +137,7 @@ internal sealed partial class PvsSystem
|
||||
|
||||
foreach (var (grid, _) in _grids)
|
||||
{
|
||||
var localPos = _transform.GetInvWorldMatrix(grid).Transform(viewPos);
|
||||
var localPos = Vector2.Transform(viewPos, _transform.GetInvWorldMatrix(grid));
|
||||
var gridChunkEnumerator = new ChunkIndicesEnumerator(localPos, range, ChunkSize);
|
||||
while (gridChunkEnumerator.MoveNext(out var gridChunkIndices))
|
||||
{
|
||||
|
||||
@@ -163,7 +163,7 @@ internal sealed partial class PvsSystem
|
||||
|
||||
dist = Math.Min(dist, (pos.Position - chunk.Position.Position).LengthSquared());
|
||||
|
||||
var relative = chunk.InvWorldMatrix.Transform(pos.Position) - chunk.Centre;
|
||||
var relative = Vector2.Transform(pos.Position, chunk.InvWorldMatrix) - chunk.Centre;
|
||||
relative = Vector2.Abs(relative);
|
||||
chebDist = Math.Min(chebDist, Math.Max(relative.X, relative.Y));
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System.Numerics;
|
||||
using System.Numerics;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Maths;
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace Robust.Server.Maps
|
||||
get => _offset;
|
||||
set
|
||||
{
|
||||
TransformMatrix = Matrix3.CreateTransform(value, Rotation);
|
||||
TransformMatrix = Matrix3Helpers.CreateTransform(value, Rotation);
|
||||
_offset = value;
|
||||
}
|
||||
}
|
||||
@@ -37,14 +37,14 @@ namespace Robust.Server.Maps
|
||||
get => _rotation;
|
||||
set
|
||||
{
|
||||
TransformMatrix = Matrix3.CreateTransform(Offset, value);
|
||||
TransformMatrix = Matrix3Helpers.CreateTransform(Offset, value);
|
||||
_rotation = value;
|
||||
}
|
||||
}
|
||||
|
||||
private Angle _rotation = Angle.Zero;
|
||||
|
||||
public Matrix3 TransformMatrix { get; set; } = Matrix3.Identity;
|
||||
public Matrix3x2 TransformMatrix { get; set; } = Matrix3x2.Identity;
|
||||
|
||||
/// <summary>
|
||||
/// If there is a map entity serialized should we also load it.
|
||||
|
||||
@@ -32,7 +32,7 @@ public sealed partial class GridFixtureSystem
|
||||
TransformComponent? xformA = null,
|
||||
TransformComponent? xformB = null)
|
||||
{
|
||||
var matrix = Matrix3.CreateTransform(offset, rotation);
|
||||
var matrix = Matrix3Helpers.CreateTransform(offset, rotation);
|
||||
Merge(gridAUid, gridBUid, matrix, gridA, gridB, xformA, xformB);
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ public sealed partial class GridFixtureSystem
|
||||
public void Merge(
|
||||
EntityUid gridAUid,
|
||||
EntityUid gridBUid,
|
||||
Matrix3 matrix,
|
||||
Matrix3x2 matrix,
|
||||
MapGridComponent? gridA = null,
|
||||
MapGridComponent? gridB = null,
|
||||
TransformComponent? xformA = null,
|
||||
@@ -63,7 +63,7 @@ public sealed partial class GridFixtureSystem
|
||||
|
||||
while (enumerator.MoveNext(out var tileRef))
|
||||
{
|
||||
var offsetTile = matrix.Transform(new Vector2(tileRef.Value.GridIndices.X, tileRef.Value.GridIndices.Y) + gridA.TileSizeHalfVector);
|
||||
var offsetTile = Vector2.Transform(new Vector2(tileRef.Value.GridIndices.X, tileRef.Value.GridIndices.Y) + gridA.TileSizeHalfVector, matrix);
|
||||
tiles.Add((offsetTile.Floored(), tileRef.Value.Tile));
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ public sealed partial class GridFixtureSystem
|
||||
if (snapgrid == null || snapgrid.Count == 0)
|
||||
continue;
|
||||
|
||||
var offsetTile = matrix.Transform(new Vector2(tileRef.Value.GridIndices.X, tileRef.Value.GridIndices.Y) + gridA.TileSizeHalfVector);
|
||||
var offsetTile = Vector2.Transform(new Vector2(tileRef.Value.GridIndices.X, tileRef.Value.GridIndices.Y) + gridA.TileSizeHalfVector, matrix);
|
||||
var tileIndex = offsetTile.Floored();
|
||||
|
||||
for (var j = snapgrid.Count - 1; j >= 0; j--)
|
||||
@@ -124,7 +124,7 @@ public sealed partial class GridFixtureSystem
|
||||
if (entXform.ParentUid != gridBUid ||
|
||||
!bounds.Contains(entXform.LocalPosition)) continue;
|
||||
|
||||
var newPos = matrix.Transform(entXform.LocalPosition);
|
||||
var newPos = Vector2.Transform(entXform.LocalPosition, matrix);
|
||||
|
||||
_xformSystem.SetCoordinates(ent, entXform, new EntityCoordinates(gridAUid, newPos), entXform.LocalRotation + rotationDiff, oldParent: xformB, newParent: xformA);
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace Robust.Shared.Maths
|
||||
public readonly Vector2 BottomLeft => Origin + Rotation.RotateVec(Box.BottomLeft - Origin);
|
||||
public readonly Vector2 Center => Origin + Rotation.RotateVec((Box.BottomLeft + Box.TopRight)/2 - Origin);
|
||||
|
||||
public Matrix3 Transform => Matrix3.CreateTransform(Origin - Rotation.RotateVec(Origin), Rotation);
|
||||
public Matrix3x2 Transform => Matrix3Helpers.CreateTransform(Origin - Rotation.RotateVec(Origin), Rotation);
|
||||
|
||||
public Box2Rotated(Vector2 bottomLeft, Vector2 topRight)
|
||||
: this(new Box2(bottomLeft, topRight))
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
193
Robust.Shared.Maths/Matrix3Helpers.cs
Normal file
193
Robust.Shared.Maths/Matrix3Helpers.cs
Normal file
@@ -0,0 +1,193 @@
|
||||
using System;
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.Intrinsics;
|
||||
|
||||
|
||||
namespace Robust.Shared.Maths;
|
||||
|
||||
public static class Matrix3Helpers
|
||||
{
|
||||
public static bool EqualsApprox(this Matrix3x2 a, Matrix3x2 b, float tolerance = 1e-6f)
|
||||
{
|
||||
return
|
||||
Math.Abs(a.M11 - b.M11) <= tolerance &&
|
||||
Math.Abs(a.M12 - b.M12) <= tolerance &&
|
||||
Math.Abs(a.M21 - b.M21) <= tolerance &&
|
||||
Math.Abs(a.M22 - b.M22) <= tolerance &&
|
||||
Math.Abs(a.M31 - b.M31) <= tolerance &&
|
||||
Math.Abs(a.M32 - b.M32) <= tolerance;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool EqualsApprox(this Matrix3x2 a, Matrix3x2 b, double tolerance)
|
||||
{
|
||||
return a.EqualsApprox(b, (float) tolerance);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Box2 TransformBox(this Matrix3x2 refFromBox, Box2Rotated box)
|
||||
{
|
||||
return (box.Transform * refFromBox).TransformBox(box.Box);
|
||||
}
|
||||
|
||||
public static Box2 TransformBox(this Matrix3x2 refFromBox, in Box2 box)
|
||||
{
|
||||
// Do transformation on all 4 corners of the box at once.
|
||||
// Then min/max the results to get the new AABB.
|
||||
|
||||
var boxVec = Unsafe.As<Box2, Vector128<float>>(ref Unsafe.AsRef(in box));
|
||||
|
||||
// Convert box into list of X and Y values for each of the 4 corners
|
||||
var allX = Vector128.Shuffle(boxVec, Vector128.Create(0, 0, 2, 2));
|
||||
var allY = Vector128.Shuffle(boxVec, Vector128.Create(1, 3, 3, 1));
|
||||
|
||||
// Transform coordinates
|
||||
var modX = allX * Vector128.Create(refFromBox.M11);
|
||||
var modY = allX * Vector128.Create(refFromBox.M12);
|
||||
modX += allY * Vector128.Create(refFromBox.M21);
|
||||
modY += allY * Vector128.Create(refFromBox.M22);
|
||||
modX += Vector128.Create(refFromBox.M31);
|
||||
modY += Vector128.Create(refFromBox.M32);
|
||||
|
||||
// Get bounding box by finding the min and max X and Y values.
|
||||
var l = SimdHelpers.MinHorizontal128(modX);
|
||||
var b = SimdHelpers.MinHorizontal128(modY);
|
||||
var r = SimdHelpers.MaxHorizontal128(modX);
|
||||
var t = SimdHelpers.MaxHorizontal128(modY);
|
||||
|
||||
var lbrt = SimdHelpers.MergeRows128(l, b, r, t);
|
||||
return Unsafe.As<Vector128<float>, Box2>(ref lbrt);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the rotation of the Matrix. Will have some precision loss.
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Angle Rotation(this Matrix3x2 t)
|
||||
{
|
||||
return new Vector2(t.M11, t.M12).ToAngle();
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix3x2 CreateTransform(float posX, float posY, double angle, float scaleX = 1, float scaleY = 1)
|
||||
{
|
||||
// returns a matrix that is equivalent to returning CreateScale(scale) * CreateRotation(angle) * CreateTranslation(posX, posY)
|
||||
|
||||
var sin = (float) Math.Sin(angle);
|
||||
var cos = (float) Math.Cos(angle);
|
||||
|
||||
return new Matrix3x2
|
||||
{
|
||||
M11 = cos * scaleX,
|
||||
M21 = -sin * scaleY,
|
||||
M31 = posX,
|
||||
M12 = sin * scaleX,
|
||||
M22 = cos * scaleY,
|
||||
M32 = posY,
|
||||
};
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix3x2 CreateTransform(in Vector2 position, in Angle angle)
|
||||
{
|
||||
// Rounding moment
|
||||
return angle.Theta switch
|
||||
{
|
||||
-Math.PI / 2 => new Matrix3x2(0f, -1f, 1, 0, position.X, position.Y),
|
||||
Math.PI / 2 => new Matrix3x2(0f, 1f, -1f, 0f, position.X, position.Y),
|
||||
Math.PI => new Matrix3x2(-1f, 0f, 0f, -1f, position.X, position.Y),
|
||||
_ => CreateTransform(position.X, position.Y, (float) angle.Theta)
|
||||
};
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix3x2 CreateTransform(in Vector2 position, in Angle angle, in Vector2 scale)
|
||||
{
|
||||
return CreateTransform(position.X, position.Y, (float)angle.Theta, scale.X, scale.Y);
|
||||
}
|
||||
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix3x2 CreateInverseTransform(float posX, float posY, double angle, float scaleX = 1, float scaleY = 1)
|
||||
{
|
||||
// returns a matrix that is equivalent to returning CreateTranslation(-posX, -posY) * CreateRotation(-angle) * CreateScale(1/scaleX, 1/scaleY)
|
||||
|
||||
var sin = (float) Math.Sin(angle);
|
||||
var cos = (float) Math.Cos(angle);
|
||||
|
||||
return new Matrix3x2
|
||||
{
|
||||
M11 = cos / scaleX,
|
||||
M21 = sin / scaleX,
|
||||
M31 = - (posX * cos + posY * sin) / scaleX,
|
||||
M12 = -sin / scaleY,
|
||||
M22 = cos / scaleY,
|
||||
M32 = (posX * sin - posY * cos) / scaleY,
|
||||
};
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix3x2 CreateInverseTransform(in Vector2 position, in Angle angle)
|
||||
{
|
||||
return CreateInverseTransform(position.X, position.Y, (float)angle.Theta);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix3x2 CreateInverseTransform(in Vector2 position, in Angle angle, in Vector2 scale)
|
||||
{
|
||||
return CreateInverseTransform(position.X, position.Y, (float)angle.Theta, scale.X, scale.Y);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix3x2 CreateTranslation(float x, float y)
|
||||
{
|
||||
return new Matrix3x2 {
|
||||
M11 = 1,
|
||||
M12 = 0,
|
||||
M21 = 0,
|
||||
M22 = 1,
|
||||
M31 = x,
|
||||
M32 = y
|
||||
};
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix3x2 CreateTranslation(Vector2 vector)
|
||||
{
|
||||
return CreateTranslation(vector.X, vector.Y);
|
||||
}
|
||||
|
||||
public static Matrix3x2 CreateRotation(double angle)
|
||||
{
|
||||
var cos = (float) Math.Cos(angle);
|
||||
var sin = (float) Math.Sin(angle);
|
||||
return new Matrix3x2 {
|
||||
M11 = cos,
|
||||
M12 = sin,
|
||||
M21 = -sin,
|
||||
M22 = cos,
|
||||
M31 = 0,
|
||||
M32 = 0
|
||||
};
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix3x2 CreateScale(float x, float y)
|
||||
{
|
||||
return new Matrix3x2 {
|
||||
M11 = x,
|
||||
M12 = 0,
|
||||
M21 = 0,
|
||||
M22 = y,
|
||||
M31 = 0,
|
||||
M32 = 0
|
||||
};
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix3x2 CreateScale(in Vector2 scale)
|
||||
{
|
||||
return CreateScale(scale.X, scale.Y);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
#region --- License ---
|
||||
#region --- License ---
|
||||
|
||||
/*
|
||||
Copyright (c) 2006 - 2008 The Open Toolkit library.
|
||||
@@ -26,6 +26,7 @@ SOFTWARE.
|
||||
#endregion --- License ---
|
||||
|
||||
using System;
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Xml.Serialization;
|
||||
@@ -73,9 +74,9 @@ namespace Robust.Shared.Maths
|
||||
: this(new Vector3(x, y, z), w) { }
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public Quaternion(ref Matrix3 matrix)
|
||||
public Quaternion(ref Matrix3x2 matrix)
|
||||
{
|
||||
var scale = Math.Pow(matrix.Determinant, 1.0d / 3.0d);
|
||||
var scale = Math.Pow(matrix.GetDeterminant(), 1.0d / 3.0d);
|
||||
float x, y, z;
|
||||
|
||||
w = (float) (Math.Sqrt(Math.Max(0, scale + matrix[0, 0] + matrix[1, 1] + matrix[2, 2])) / 2);
|
||||
|
||||
@@ -357,7 +357,7 @@ public abstract class ComponentTreeSystem<TTreeComp, TComp> : EntitySystem
|
||||
{
|
||||
var (_, treeRot, matrix) = XformSystem.GetWorldPositionRotationInvMatrix(treeUid);
|
||||
var relativeAngle = new Angle(-treeRot.Theta).RotateVec(ray.Direction);
|
||||
var treeRay = new Ray(matrix.Transform(ray.Position), relativeAngle);
|
||||
var treeRay = new Ray(Vector2.Transform(ray.Position, matrix), relativeAngle);
|
||||
comp.Tree.QueryRay(ref queryState, QueryCallback, treeRay);
|
||||
if (returnOnFirstHit && queryState.List.Count > 0)
|
||||
break;
|
||||
|
||||
@@ -56,7 +56,7 @@ internal sealed class TeleportCommand : LocalizedCommands
|
||||
|
||||
if (_map.TryFindGridAt(mapId, position, out var gridUid, out var grid))
|
||||
{
|
||||
var gridPos = xformSystem.GetInvWorldMatrix(gridUid).Transform(position);
|
||||
var gridPos = Vector2.Transform(position, xformSystem.GetInvWorldMatrix(gridUid));
|
||||
|
||||
xformSystem.SetCoordinates(entity, transform, new EntityCoordinates(gridUid, gridPos));
|
||||
}
|
||||
|
||||
@@ -450,6 +450,7 @@ Types:
|
||||
Vector2: { All: True }
|
||||
Vector3: { All: True }
|
||||
Vector4: { All: True }
|
||||
Matrix3x2: { All: True }
|
||||
System.Reflection:
|
||||
Assembly:
|
||||
Methods:
|
||||
|
||||
@@ -57,12 +57,12 @@ namespace Robust.Shared.GameObjects
|
||||
internal BroadphaseData? Broadphase;
|
||||
|
||||
internal bool MatricesDirty = true;
|
||||
private Matrix3 _localMatrix = Matrix3.Identity;
|
||||
private Matrix3 _invLocalMatrix = Matrix3.Identity;
|
||||
private Matrix3x2 _localMatrix = Matrix3x2.Identity;
|
||||
private Matrix3x2 _invLocalMatrix = Matrix3x2.Identity;
|
||||
|
||||
// these should just be system methods, but existing component functions like InvWorldMatrix still rely on
|
||||
// getting these so those have to be fully ECS-ed first.
|
||||
public Matrix3 LocalMatrix
|
||||
public Matrix3x2 LocalMatrix
|
||||
{
|
||||
get
|
||||
{
|
||||
@@ -71,7 +71,7 @@ namespace Robust.Shared.GameObjects
|
||||
return _localMatrix;
|
||||
}
|
||||
}
|
||||
public Matrix3 InvLocalMatrix
|
||||
public Matrix3x2 InvLocalMatrix
|
||||
{
|
||||
get
|
||||
{
|
||||
@@ -218,7 +218,7 @@ namespace Robust.Shared.GameObjects
|
||||
/// Matrix for transforming points from local to world space.
|
||||
/// </summary>
|
||||
[Obsolete("Use the system method instead")]
|
||||
public Matrix3 WorldMatrix
|
||||
public Matrix3x2 WorldMatrix
|
||||
{
|
||||
get
|
||||
{
|
||||
@@ -232,7 +232,7 @@ namespace Robust.Shared.GameObjects
|
||||
var parentMatrix = parentXform.LocalMatrix;
|
||||
parent = parentXform.ParentUid;
|
||||
|
||||
Matrix3.Multiply(in myMatrix, in parentMatrix, out var result);
|
||||
var result = Matrix3x2.Multiply(myMatrix, parentMatrix);
|
||||
myMatrix = result;
|
||||
}
|
||||
|
||||
@@ -244,7 +244,7 @@ namespace Robust.Shared.GameObjects
|
||||
/// Matrix for transforming points from world to local space.
|
||||
/// </summary>
|
||||
[Obsolete("Use the system method instead")]
|
||||
public Matrix3 InvWorldMatrix
|
||||
public Matrix3x2 InvWorldMatrix
|
||||
{
|
||||
get
|
||||
{
|
||||
@@ -258,7 +258,7 @@ namespace Robust.Shared.GameObjects
|
||||
var parentMatrix = parentXform.InvLocalMatrix;
|
||||
parent = parentXform.ParentUid;
|
||||
|
||||
Matrix3.Multiply(in parentMatrix, in myMatrix, out var result);
|
||||
var result = Matrix3x2.Multiply(parentMatrix, myMatrix);
|
||||
myMatrix = result;
|
||||
}
|
||||
|
||||
@@ -280,7 +280,7 @@ namespace Robust.Shared.GameObjects
|
||||
if (_parent.IsValid())
|
||||
{
|
||||
// parent coords to world coords
|
||||
return _entMan.GetComponent<TransformComponent>(ParentUid).WorldMatrix.Transform(_localPosition);
|
||||
return Vector2.Transform(_localPosition, _entMan.GetComponent<TransformComponent>(ParentUid).WorldMatrix);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -296,7 +296,7 @@ namespace Robust.Shared.GameObjects
|
||||
}
|
||||
|
||||
// world coords to parent coords
|
||||
var newPos = _entMan.GetComponent<TransformComponent>(ParentUid).InvWorldMatrix.Transform(value);
|
||||
var newPos = Vector2.Transform(value, _entMan.GetComponent<TransformComponent>(ParentUid).InvWorldMatrix);
|
||||
|
||||
LocalPosition = newPos;
|
||||
}
|
||||
@@ -490,7 +490,7 @@ namespace Robust.Shared.GameObjects
|
||||
/// Get the WorldPosition, WorldRotation, and WorldMatrix of this entity faster than each individually.
|
||||
/// </summary>
|
||||
[Obsolete("Use the system method instead")]
|
||||
public (Vector2 WorldPosition, Angle WorldRotation, Matrix3 WorldMatrix) GetWorldPositionRotationMatrix(EntityQuery<TransformComponent> xforms)
|
||||
public (Vector2 WorldPosition, Angle WorldRotation, Matrix3x2 WorldMatrix) GetWorldPositionRotationMatrix(EntityQuery<TransformComponent> xforms)
|
||||
{
|
||||
var parent = _parent;
|
||||
var worldRot = _localRotation;
|
||||
@@ -502,12 +502,12 @@ namespace Robust.Shared.GameObjects
|
||||
var xform = xforms.GetComponent(parent);
|
||||
worldRot += xform.LocalRotation;
|
||||
var parentMatrix = xform.LocalMatrix;
|
||||
Matrix3.Multiply(in worldMatrix, in parentMatrix, out var result);
|
||||
var result = Matrix3x2.Multiply(worldMatrix, parentMatrix);
|
||||
worldMatrix = result;
|
||||
parent = xform.ParentUid;
|
||||
}
|
||||
|
||||
var worldPosition = new Vector2(worldMatrix.R0C2, worldMatrix.R1C2);
|
||||
var worldPosition = worldMatrix.Translation;
|
||||
|
||||
return (worldPosition, worldRot, worldMatrix);
|
||||
}
|
||||
@@ -516,7 +516,7 @@ namespace Robust.Shared.GameObjects
|
||||
/// Get the WorldPosition, WorldRotation, and WorldMatrix of this entity faster than each individually.
|
||||
/// </summary>
|
||||
[Obsolete("Use the system method instead")]
|
||||
public (Vector2 WorldPosition, Angle WorldRotation, Matrix3 WorldMatrix) GetWorldPositionRotationMatrix()
|
||||
public (Vector2 WorldPosition, Angle WorldRotation, Matrix3x2 WorldMatrix) GetWorldPositionRotationMatrix()
|
||||
{
|
||||
var xforms = _entMan.GetEntityQuery<TransformComponent>();
|
||||
return GetWorldPositionRotationMatrix(xforms);
|
||||
@@ -526,7 +526,7 @@ namespace Robust.Shared.GameObjects
|
||||
/// Get the WorldPosition, WorldRotation, and InvWorldMatrix of this entity faster than each individually.
|
||||
/// </summary>
|
||||
[Obsolete("Use the system method instead")]
|
||||
public (Vector2 WorldPosition, Angle WorldRotation, Matrix3 InvWorldMatrix) GetWorldPositionRotationInvMatrix()
|
||||
public (Vector2 WorldPosition, Angle WorldRotation, Matrix3x2 InvWorldMatrix) GetWorldPositionRotationInvMatrix()
|
||||
{
|
||||
var xformQuery = _entMan.GetEntityQuery<TransformComponent>();
|
||||
return GetWorldPositionRotationInvMatrix(xformQuery);
|
||||
@@ -536,7 +536,7 @@ namespace Robust.Shared.GameObjects
|
||||
/// Get the WorldPosition, WorldRotation, and InvWorldMatrix of this entity faster than each individually.
|
||||
/// </summary>
|
||||
[Obsolete("Use the system method instead")]
|
||||
public (Vector2 WorldPosition, Angle WorldRotation, Matrix3 InvWorldMatrix) GetWorldPositionRotationInvMatrix(EntityQuery<TransformComponent> xformQuery)
|
||||
public (Vector2 WorldPosition, Angle WorldRotation, Matrix3x2 InvWorldMatrix) GetWorldPositionRotationInvMatrix(EntityQuery<TransformComponent> xformQuery)
|
||||
{
|
||||
var (worldPos, worldRot, _, invWorldMatrix) = GetWorldPositionRotationMatrixWithInv(xformQuery);
|
||||
return (worldPos, worldRot, invWorldMatrix);
|
||||
@@ -546,7 +546,7 @@ namespace Robust.Shared.GameObjects
|
||||
/// Get the WorldPosition, WorldRotation, WorldMatrix, and InvWorldMatrix of this entity faster than each individually.
|
||||
/// </summary>
|
||||
[Obsolete("Use the system method instead")]
|
||||
public (Vector2 WorldPosition, Angle WorldRotation, Matrix3 WorldMatrix, Matrix3 InvWorldMatrix) GetWorldPositionRotationMatrixWithInv()
|
||||
public (Vector2 WorldPosition, Angle WorldRotation, Matrix3x2 WorldMatrix, Matrix3x2 InvWorldMatrix) GetWorldPositionRotationMatrixWithInv()
|
||||
{
|
||||
var xformQuery = _entMan.GetEntityQuery<TransformComponent>();
|
||||
return GetWorldPositionRotationMatrixWithInv(xformQuery);
|
||||
@@ -556,7 +556,7 @@ namespace Robust.Shared.GameObjects
|
||||
/// Get the WorldPosition, WorldRotation, WorldMatrix, and InvWorldMatrix of this entity faster than each individually.
|
||||
/// </summary>
|
||||
[Obsolete("Use the system method instead")]
|
||||
public (Vector2 WorldPosition, Angle WorldRotation, Matrix3 WorldMatrix, Matrix3 InvWorldMatrix) GetWorldPositionRotationMatrixWithInv(EntityQuery<TransformComponent> xformQuery)
|
||||
public (Vector2 WorldPosition, Angle WorldRotation, Matrix3x2 WorldMatrix, Matrix3x2 InvWorldMatrix) GetWorldPositionRotationMatrixWithInv(EntityQuery<TransformComponent> xformQuery)
|
||||
{
|
||||
var parent = _parent;
|
||||
var worldRot = _localRotation;
|
||||
@@ -570,17 +570,17 @@ namespace Robust.Shared.GameObjects
|
||||
worldRot += xform.LocalRotation;
|
||||
|
||||
var parentMatrix = xform.LocalMatrix;
|
||||
Matrix3.Multiply(in worldMatrix, in parentMatrix, out var result);
|
||||
var result = Matrix3x2.Multiply(worldMatrix, parentMatrix);
|
||||
worldMatrix = result;
|
||||
|
||||
var parentInvMatrix = xform.InvLocalMatrix;
|
||||
Matrix3.Multiply(in parentInvMatrix, in invMatrix, out var invResult);
|
||||
var invResult = Matrix3x2.Multiply(parentInvMatrix, invMatrix);
|
||||
invMatrix = invResult;
|
||||
|
||||
parent = xform.ParentUid;
|
||||
}
|
||||
|
||||
var worldPosition = new Vector2(worldMatrix.R0C2, worldMatrix.R1C2);
|
||||
var worldPosition = worldMatrix.Translation;
|
||||
|
||||
return (worldPosition, worldRot, worldMatrix, invMatrix);
|
||||
}
|
||||
@@ -591,12 +591,12 @@ namespace Robust.Shared.GameObjects
|
||||
|
||||
if (!_parent.IsValid()) // Root Node
|
||||
{
|
||||
_localMatrix = Matrix3.Identity;
|
||||
_invLocalMatrix = Matrix3.Identity;
|
||||
_localMatrix = Matrix3x2.Identity;
|
||||
_invLocalMatrix = Matrix3x2.Identity;
|
||||
}
|
||||
|
||||
_localMatrix = Matrix3.CreateTransform(_localPosition, _localRotation);
|
||||
_invLocalMatrix = Matrix3.CreateInverseTransform(_localPosition, _localRotation);
|
||||
_localMatrix = Matrix3Helpers.CreateTransform(_localPosition, _localRotation);
|
||||
_invLocalMatrix = Matrix3Helpers.CreateInverseTransform(_localPosition, _localRotation);
|
||||
}
|
||||
|
||||
public string GetDebugString()
|
||||
|
||||
@@ -118,7 +118,7 @@ public sealed partial class EntityLookupSystem
|
||||
return;
|
||||
|
||||
var (_, lookupRot, lookupInvMatrix) = _transform.GetWorldPositionRotationInvMatrix(lookupUid);
|
||||
var lookupTransform = new Transform(lookupInvMatrix.Transform(shapeTransform.Position),
|
||||
var lookupTransform = new Transform(Vector2.Transform(shapeTransform.Position, lookupInvMatrix),
|
||||
shapeTransform.Quaternion2D.Angle - lookupRot);
|
||||
|
||||
var localAABB = shape.ComputeAABB(lookupTransform, 0);
|
||||
@@ -291,7 +291,7 @@ public sealed partial class EntityLookupSystem
|
||||
// Transform is in world terms
|
||||
// Need to convert both back to lookup-local for AABB.
|
||||
var (_, lookupRot, lookupInvMatrix) = _transform.GetWorldPositionRotationInvMatrix(lookupUid);
|
||||
var lookupTransform = new Transform(lookupInvMatrix.Transform(shapeTransform.Position),
|
||||
var lookupTransform = new Transform(Vector2.Transform(shapeTransform.Position, lookupInvMatrix),
|
||||
shapeTransform.Quaternion2D.Angle - lookupRot);
|
||||
|
||||
var localAABB = shape.ComputeAABB(lookupTransform, 0);
|
||||
@@ -902,7 +902,7 @@ public sealed partial class EntityLookupSystem
|
||||
return GetLocalBounds(tileRef.GridIndices, tileSize);
|
||||
}
|
||||
|
||||
public Box2Rotated GetWorldBounds(TileRef tileRef, Matrix3? worldMatrix = null, Angle? angle = null)
|
||||
public Box2Rotated GetWorldBounds(TileRef tileRef, Matrix3x2? worldMatrix = null, Angle? angle = null)
|
||||
{
|
||||
var grid = _gridQuery.GetComponent(tileRef.GridUid);
|
||||
|
||||
@@ -914,7 +914,7 @@ public sealed partial class EntityLookupSystem
|
||||
}
|
||||
|
||||
var expand = new Vector2(0.5f, 0.5f);
|
||||
var center = worldMatrix.Value.Transform(tileRef.GridIndices + expand) * grid.TileSize;
|
||||
var center = Vector2.Transform(tileRef.GridIndices + expand, worldMatrix.Value) * grid.TileSize;
|
||||
var translatedBox = Box2.CenteredAround(center, new Vector2(grid.TileSize, grid.TileSize));
|
||||
|
||||
return new Box2Rotated(translatedBox, -angle.Value, center);
|
||||
|
||||
@@ -145,7 +145,7 @@ public sealed partial class EntityLookupSystem
|
||||
// Transform is in world terms
|
||||
// Need to convert both back to lookup-local for AABB.
|
||||
var (_, lookupRot, lookupInvMatrix) = _transform.GetWorldPositionRotationInvMatrix(lookupUid);
|
||||
var lookupTransform = new Transform(lookupInvMatrix.Transform(shapeTransform.Position),
|
||||
var lookupTransform = new Transform(Vector2.Transform(shapeTransform.Position, lookupInvMatrix),
|
||||
shapeTransform.Quaternion2D.Angle - lookupRot);
|
||||
|
||||
var localAABB = shape.ComputeAABB(lookupTransform, 0);
|
||||
@@ -287,7 +287,7 @@ public sealed partial class EntityLookupSystem
|
||||
return false;
|
||||
|
||||
var (_, lookupRot, lookupInvMatrix) = _transform.GetWorldPositionRotationInvMatrix(lookupUid);
|
||||
var lookupTransform = new Transform(lookupInvMatrix.Transform(shapeTransform.Position),
|
||||
var lookupTransform = new Transform(Vector2.Transform(shapeTransform.Position, lookupInvMatrix),
|
||||
shapeTransform.Quaternion2D.Angle - lookupRot);
|
||||
|
||||
var localAABB = shape.ComputeAABB(lookupTransform, 0);
|
||||
|
||||
@@ -247,7 +247,7 @@ public sealed partial class EntityLookupSystem : EntitySystem
|
||||
var mapTransform = new Transform(worldPos, worldRot);
|
||||
|
||||
var (_, broadWorldRot, _, broadInvMatrix) = _transform.GetWorldPositionRotationMatrixWithInv(broadphase.Owner);
|
||||
var broadphaseTransform = new Transform(broadInvMatrix.Transform(mapTransform.Position), mapTransform.Quaternion2D.Angle - broadWorldRot);
|
||||
var broadphaseTransform = new Transform(Vector2.Transform(mapTransform.Position, broadInvMatrix), mapTransform.Quaternion2D.Angle - broadWorldRot);
|
||||
var tree = body.BodyType == BodyType.Static ? broadphase.StaticTree : broadphase.DynamicTree;
|
||||
DebugTools.Assert(fixture.ProxyCount == 0);
|
||||
|
||||
@@ -391,7 +391,7 @@ public sealed partial class EntityLookupSystem : EntitySystem
|
||||
var mapTransform = new Transform(worldPos, worldRot);
|
||||
|
||||
// TODO BROADPHASE PARENTING this just assumes local = world
|
||||
var broadphaseTransform = new Transform(broadphaseXform.InvLocalMatrix.Transform(mapTransform.Position), mapTransform.Quaternion2D.Angle - broadphaseXform.LocalRotation);
|
||||
var broadphaseTransform = new Transform(Vector2.Transform(mapTransform.Position, broadphaseXform.InvLocalMatrix), mapTransform.Quaternion2D.Angle - broadphaseXform.LocalRotation);
|
||||
|
||||
foreach (var (id, fixture) in manager.Fixtures)
|
||||
{
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System.Numerics;
|
||||
using Robust.Shared.Audio.Components;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Map;
|
||||
@@ -88,7 +89,7 @@ internal sealed class SharedGridTraversalSystem : EntitySystem
|
||||
|
||||
var mapPos = xform.ParentUid == xform.MapUid
|
||||
? xform.LocalPosition
|
||||
: Transform(xform.ParentUid).LocalMatrix.Transform(xform.LocalPosition);
|
||||
: Vector2.Transform(xform.LocalPosition, Transform(xform.ParentUid).LocalMatrix);
|
||||
|
||||
// Change parent if necessary
|
||||
if (_mapManager.TryFindGridAt(map, mapPos, out var gridUid, out _))
|
||||
|
||||
@@ -1292,7 +1292,7 @@ public abstract partial class SharedMapSystem
|
||||
public Vector2 WorldToLocal(EntityUid uid, MapGridComponent grid, Vector2 posWorld)
|
||||
{
|
||||
var matrix = _transform.GetInvWorldMatrix(uid);
|
||||
return matrix.Transform(posWorld);
|
||||
return Vector2.Transform(posWorld, matrix);
|
||||
}
|
||||
|
||||
public EntityCoordinates MapToGrid(EntityUid uid, MapCoordinates posWorld)
|
||||
@@ -1315,7 +1315,7 @@ public abstract partial class SharedMapSystem
|
||||
public Vector2 LocalToWorld(EntityUid uid, MapGridComponent grid, Vector2 posLocal)
|
||||
{
|
||||
var matrix = _transform.GetWorldMatrix(uid);
|
||||
return matrix.Transform(posLocal);
|
||||
return Vector2.Transform(posLocal, matrix);
|
||||
}
|
||||
|
||||
public Vector2i WorldToTile(EntityUid uid, MapGridComponent grid, Vector2 posWorld)
|
||||
@@ -1435,7 +1435,7 @@ public abstract partial class SharedMapSystem
|
||||
var locX = gridTile.X * grid.TileSize + (grid.TileSize / 2f);
|
||||
var locY = gridTile.Y * grid.TileSize + (grid.TileSize / 2f);
|
||||
|
||||
return _transform.GetWorldMatrix(uid).Transform(new Vector2(locX, locY));
|
||||
return Vector2.Transform(new Vector2(locX, locY), _transform.GetWorldMatrix(uid));
|
||||
}
|
||||
|
||||
public MapCoordinates GridTileToWorld(EntityUid uid, MapGridComponent grid, Vector2i gridTile)
|
||||
|
||||
@@ -671,7 +671,7 @@ public abstract partial class SharedTransformSystem
|
||||
|
||||
var (_, parRot, parInvMatrix) = GetWorldPositionRotationInvMatrix(parentXform, xformQuery);
|
||||
var (pos, rot) = GetWorldPositionRotation(xform, xformQuery);
|
||||
var newPos = parInvMatrix.Transform(pos);
|
||||
var newPos = Vector2.Transform(pos, parInvMatrix);
|
||||
var newRot = rot - parRot;
|
||||
|
||||
SetCoordinates(uid, xform, new EntityCoordinates(parent, newPos), newRot, newParent: parentXform);
|
||||
@@ -770,7 +770,7 @@ public abstract partial class SharedTransformSystem
|
||||
#region World Matrix
|
||||
|
||||
[Pure]
|
||||
public Matrix3 GetWorldMatrix(EntityUid uid)
|
||||
public Matrix3x2 GetWorldMatrix(EntityUid uid)
|
||||
{
|
||||
return GetWorldMatrix(XformQuery.GetComponent(uid), XformQuery);
|
||||
}
|
||||
@@ -778,24 +778,24 @@ public abstract partial class SharedTransformSystem
|
||||
// Temporary until it's moved here
|
||||
[Pure]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public Matrix3 GetWorldMatrix(TransformComponent component)
|
||||
public Matrix3x2 GetWorldMatrix(TransformComponent component)
|
||||
{
|
||||
return GetWorldMatrix(component, XformQuery);
|
||||
}
|
||||
|
||||
[Pure]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public Matrix3 GetWorldMatrix(EntityUid uid, EntityQuery<TransformComponent> xformQuery)
|
||||
public Matrix3x2 GetWorldMatrix(EntityUid uid, EntityQuery<TransformComponent> xformQuery)
|
||||
{
|
||||
return GetWorldMatrix(xformQuery.GetComponent(uid), xformQuery);
|
||||
}
|
||||
|
||||
[Pure]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public Matrix3 GetWorldMatrix(TransformComponent component, EntityQuery<TransformComponent> xformQuery)
|
||||
public Matrix3x2 GetWorldMatrix(TransformComponent component, EntityQuery<TransformComponent> xformQuery)
|
||||
{
|
||||
var (pos, rot) = GetWorldPositionRotation(component, xformQuery);
|
||||
return Matrix3.CreateTransform(pos, rot);
|
||||
return Matrix3Helpers.CreateTransform(pos, rot);
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -873,7 +873,7 @@ public abstract partial class SharedTransformSystem
|
||||
_mapManager.TryFindGridAt(mapUid, coordinates.Position, out var targetGrid, out _))
|
||||
{
|
||||
var invWorldMatrix = GetInvWorldMatrix(targetGrid);
|
||||
SetCoordinates(entity, new EntityCoordinates(targetGrid, invWorldMatrix.Transform(coordinates.Position)));
|
||||
SetCoordinates(entity, new EntityCoordinates(targetGrid, Vector2.Transform(coordinates.Position, invWorldMatrix)));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -934,7 +934,7 @@ public abstract partial class SharedTransformSystem
|
||||
// Entity was not actually in the transform hierarchy. This is probably a sign that something is wrong, or that the function is being misused.
|
||||
Log.Warning($"Target entity ({ToPrettyString(relative)}) not in transform hierarchy while calling {nameof(GetRelativePositionRotation)}.");
|
||||
var relXform = query.GetComponent(relative);
|
||||
pos = relXform.InvWorldMatrix.Transform(pos);
|
||||
pos = Vector2.Transform(pos, relXform.InvWorldMatrix);
|
||||
rot = rot - GetWorldRotation(relXform, query);
|
||||
break;
|
||||
}
|
||||
@@ -965,7 +965,7 @@ public abstract partial class SharedTransformSystem
|
||||
// Entity was not actually in the transform hierarchy. This is probably a sign that something is wrong, or that the function is being misused.
|
||||
Log.Warning($"Target entity ({ToPrettyString(relative)}) not in transform hierarchy while calling {nameof(GetRelativePositionRotation)}.");
|
||||
var relXform = query.GetComponent(relative);
|
||||
pos = GetInvWorldMatrix(relXform).Transform(pos);
|
||||
pos = Vector2.Transform(pos, GetInvWorldMatrix(relXform));
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1111,7 +1111,7 @@ public abstract partial class SharedTransformSystem
|
||||
var invLocalMatrix = targetGridXform.InvLocalMatrix;
|
||||
var gridRot = targetGridXform.LocalRotation;
|
||||
var localRot = worldRot - gridRot;
|
||||
SetCoordinates(uid, component, new EntityCoordinates(targetGrid, invLocalMatrix.Transform(worldPos)), rotation: localRot);
|
||||
SetCoordinates(uid, component, new EntityCoordinates(targetGrid, Vector2.Transform(worldPos, invLocalMatrix)), rotation: localRot);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1168,91 +1168,91 @@ public abstract partial class SharedTransformSystem
|
||||
#region Inverse World Matrix
|
||||
|
||||
[Pure]
|
||||
public Matrix3 GetInvWorldMatrix(EntityUid uid)
|
||||
public Matrix3x2 GetInvWorldMatrix(EntityUid uid)
|
||||
{
|
||||
return GetInvWorldMatrix(XformQuery.GetComponent(uid), XformQuery);
|
||||
}
|
||||
|
||||
[Pure]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public Matrix3 GetInvWorldMatrix(TransformComponent component)
|
||||
public Matrix3x2 GetInvWorldMatrix(TransformComponent component)
|
||||
{
|
||||
return GetInvWorldMatrix(component, XformQuery);
|
||||
}
|
||||
|
||||
[Pure]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public Matrix3 GetInvWorldMatrix(EntityUid uid, EntityQuery<TransformComponent> xformQuery)
|
||||
public Matrix3x2 GetInvWorldMatrix(EntityUid uid, EntityQuery<TransformComponent> xformQuery)
|
||||
{
|
||||
return GetInvWorldMatrix(xformQuery.GetComponent(uid), xformQuery);
|
||||
}
|
||||
|
||||
[Pure]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public Matrix3 GetInvWorldMatrix(TransformComponent component, EntityQuery<TransformComponent> xformQuery)
|
||||
public Matrix3x2 GetInvWorldMatrix(TransformComponent component, EntityQuery<TransformComponent> xformQuery)
|
||||
{
|
||||
var (pos, rot) = GetWorldPositionRotation(component, xformQuery);
|
||||
return Matrix3.CreateInverseTransform(pos, rot);
|
||||
return Matrix3Helpers.CreateInverseTransform(pos, rot);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region GetWorldPositionRotationMatrix
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public (Vector2 WorldPosition, Angle WorldRotation, Matrix3 WorldMatrix)
|
||||
public (Vector2 WorldPosition, Angle WorldRotation, Matrix3x2 WorldMatrix)
|
||||
GetWorldPositionRotationMatrix(EntityUid uid)
|
||||
{
|
||||
return GetWorldPositionRotationMatrix(XformQuery.GetComponent(uid), XformQuery);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public (Vector2 WorldPosition, Angle WorldRotation, Matrix3 WorldMatrix)
|
||||
public (Vector2 WorldPosition, Angle WorldRotation, Matrix3x2 WorldMatrix)
|
||||
GetWorldPositionRotationMatrix(TransformComponent xform)
|
||||
{
|
||||
return GetWorldPositionRotationMatrix(xform, XformQuery);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public (Vector2 WorldPosition, Angle WorldRotation, Matrix3 WorldMatrix)
|
||||
public (Vector2 WorldPosition, Angle WorldRotation, Matrix3x2 WorldMatrix)
|
||||
GetWorldPositionRotationMatrix(EntityUid uid, EntityQuery<TransformComponent> xforms)
|
||||
{
|
||||
return GetWorldPositionRotationMatrix(xforms.GetComponent(uid), xforms);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public (Vector2 WorldPosition, Angle WorldRotation, Matrix3 WorldMatrix)
|
||||
public (Vector2 WorldPosition, Angle WorldRotation, Matrix3x2 WorldMatrix)
|
||||
GetWorldPositionRotationMatrix(TransformComponent component, EntityQuery<TransformComponent> xforms)
|
||||
{
|
||||
var (pos, rot) = GetWorldPositionRotation(component, xforms);
|
||||
return (pos, rot, Matrix3.CreateTransform(pos, rot));
|
||||
return (pos, rot, Matrix3Helpers.CreateTransform(pos, rot));
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region GetWorldPositionRotationInvMatrix
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public (Vector2 WorldPosition, Angle WorldRotation, Matrix3 InvWorldMatrix) GetWorldPositionRotationInvMatrix(EntityUid uid)
|
||||
public (Vector2 WorldPosition, Angle WorldRotation, Matrix3x2 InvWorldMatrix) GetWorldPositionRotationInvMatrix(EntityUid uid)
|
||||
{
|
||||
return GetWorldPositionRotationInvMatrix(XformQuery.GetComponent(uid));
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public (Vector2 WorldPosition, Angle WorldRotation, Matrix3 InvWorldMatrix) GetWorldPositionRotationInvMatrix(TransformComponent xform)
|
||||
public (Vector2 WorldPosition, Angle WorldRotation, Matrix3x2 InvWorldMatrix) GetWorldPositionRotationInvMatrix(TransformComponent xform)
|
||||
{
|
||||
return GetWorldPositionRotationInvMatrix(xform, XformQuery);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public (Vector2 WorldPosition, Angle WorldRotation, Matrix3 InvWorldMatrix) GetWorldPositionRotationInvMatrix(EntityUid uid, EntityQuery<TransformComponent> xforms)
|
||||
public (Vector2 WorldPosition, Angle WorldRotation, Matrix3x2 InvWorldMatrix) GetWorldPositionRotationInvMatrix(EntityUid uid, EntityQuery<TransformComponent> xforms)
|
||||
{
|
||||
return GetWorldPositionRotationInvMatrix(xforms.GetComponent(uid), xforms);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public (Vector2 WorldPosition, Angle WorldRotation, Matrix3 InvWorldMatrix) GetWorldPositionRotationInvMatrix(TransformComponent component, EntityQuery<TransformComponent> xforms)
|
||||
public (Vector2 WorldPosition, Angle WorldRotation, Matrix3x2 InvWorldMatrix) GetWorldPositionRotationInvMatrix(TransformComponent component, EntityQuery<TransformComponent> xforms)
|
||||
{
|
||||
var (pos, rot) = GetWorldPositionRotation(component, xforms);
|
||||
return (pos, rot, Matrix3.CreateInverseTransform(pos, rot));
|
||||
return (pos, rot, Matrix3Helpers.CreateInverseTransform(pos, rot));
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -1260,32 +1260,32 @@ public abstract partial class SharedTransformSystem
|
||||
#region GetWorldPositionRotationMatrixWithInv
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public (Vector2 WorldPosition, Angle WorldRotation, Matrix3 WorldMatrix, Matrix3 InvWorldMatrix)
|
||||
public (Vector2 WorldPosition, Angle WorldRotation, Matrix3x2 WorldMatrix, Matrix3x2 InvWorldMatrix)
|
||||
GetWorldPositionRotationMatrixWithInv(EntityUid uid)
|
||||
{
|
||||
return GetWorldPositionRotationMatrixWithInv(XformQuery.GetComponent(uid), XformQuery);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public (Vector2 WorldPosition, Angle WorldRotation, Matrix3 WorldMatrix, Matrix3 InvWorldMatrix)
|
||||
public (Vector2 WorldPosition, Angle WorldRotation, Matrix3x2 WorldMatrix, Matrix3x2 InvWorldMatrix)
|
||||
GetWorldPositionRotationMatrixWithInv(TransformComponent xform)
|
||||
{
|
||||
return GetWorldPositionRotationMatrixWithInv(xform, XformQuery);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public (Vector2 WorldPosition, Angle WorldRotation, Matrix3 WorldMatrix, Matrix3 InvWorldMatrix)
|
||||
public (Vector2 WorldPosition, Angle WorldRotation, Matrix3x2 WorldMatrix, Matrix3x2 InvWorldMatrix)
|
||||
GetWorldPositionRotationMatrixWithInv(EntityUid uid, EntityQuery<TransformComponent> xforms)
|
||||
{
|
||||
return GetWorldPositionRotationMatrixWithInv(xforms.GetComponent(uid), xforms);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public (Vector2 WorldPosition, Angle WorldRotation, Matrix3 WorldMatrix, Matrix3 InvWorldMatrix)
|
||||
public (Vector2 WorldPosition, Angle WorldRotation, Matrix3x2 WorldMatrix, Matrix3x2 InvWorldMatrix)
|
||||
GetWorldPositionRotationMatrixWithInv(TransformComponent component, EntityQuery<TransformComponent> xforms)
|
||||
{
|
||||
var (pos, rot) = GetWorldPositionRotation(component, xforms);
|
||||
return (pos, rot, Matrix3.CreateTransform(pos, rot), Matrix3.CreateInverseTransform(pos, rot));
|
||||
return (pos, rot, Matrix3Helpers.CreateTransform(pos, rot), Matrix3Helpers.CreateInverseTransform(pos, rot));
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -1330,7 +1330,7 @@ public abstract partial class SharedTransformSystem
|
||||
if (newParent == xform.ParentUid || newParent == uid)
|
||||
return;
|
||||
|
||||
var newPos = GetInvWorldMatrix(newParent).Transform(oldPos);
|
||||
var newPos = Vector2.Transform(oldPos, GetInvWorldMatrix(newParent));
|
||||
SetCoordinates(uid, xform, new(newParent, newPos));
|
||||
}
|
||||
|
||||
@@ -1352,7 +1352,7 @@ public abstract partial class SharedTransformSystem
|
||||
if (_mapManager.TryFindGridAt(map, oldPos, out var gridUid, out _))
|
||||
newParent = gridUid;
|
||||
|
||||
coordinates = new(newParent, GetInvWorldMatrix(newParent).Transform(oldPos));
|
||||
coordinates = new(newParent, Vector2.Transform(oldPos, GetInvWorldMatrix(newParent)));
|
||||
return true;
|
||||
}
|
||||
#endregion
|
||||
@@ -1592,7 +1592,7 @@ public abstract partial class SharedTransformSystem
|
||||
if (!_gridQuery.HasComponent(entity1) && _mapManager.TryFindGridAt(mapUid, pos2.Value.Position, out var targetGrid, out _))
|
||||
{
|
||||
var invWorldMatrix = GetInvWorldMatrix(targetGrid);
|
||||
SetCoordinates(entity1, new EntityCoordinates(targetGrid, invWorldMatrix.Transform(pos2.Value.Position)));
|
||||
SetCoordinates(entity1, new EntityCoordinates(targetGrid, Vector2.Transform(pos2.Value.Position, invWorldMatrix)));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1615,7 +1615,7 @@ public abstract partial class SharedTransformSystem
|
||||
if (!_gridQuery.HasComponent(entity1) && _mapManager.TryFindGridAt(mapUid, pos1.Value.Position, out var targetGrid, out _))
|
||||
{
|
||||
var invWorldMatrix = GetInvWorldMatrix(targetGrid);
|
||||
SetCoordinates(entity2, new EntityCoordinates(targetGrid, invWorldMatrix.Transform(pos1.Value.Position)));
|
||||
SetCoordinates(entity2, new EntityCoordinates(targetGrid, Vector2.Transform(pos1.Value.Position, invWorldMatrix)));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using Robust.Shared.Map;
|
||||
|
||||
@@ -52,7 +53,7 @@ public abstract partial class SharedTransformSystem
|
||||
return MapCoordinates.Nullspace;
|
||||
}
|
||||
|
||||
var worldPos = GetWorldMatrix(xform).Transform(coordinates.Position);
|
||||
var worldPos = Vector2.Transform(coordinates.Position, GetWorldMatrix(xform));
|
||||
return new MapCoordinates(worldPos, xform.MapID);
|
||||
}
|
||||
|
||||
@@ -83,7 +84,7 @@ public abstract partial class SharedTransformSystem
|
||||
return default;
|
||||
}
|
||||
|
||||
var localPos = GetInvWorldMatrix(entity.Comp).Transform(coordinates.Position);
|
||||
var localPos = Vector2.Transform(coordinates.Position, GetInvWorldMatrix(entity.Comp));
|
||||
return new EntityCoordinates(entity, localPos);
|
||||
}
|
||||
|
||||
|
||||
@@ -139,7 +139,7 @@ namespace Robust.Shared.GameObjects
|
||||
|
||||
return xform.GridUid == null
|
||||
? new EntityCoordinates(xform.MapUid ?? xform.ParentUid, worldPos)
|
||||
: new EntityCoordinates(xform.GridUid.Value, XformQuery.GetComponent(xform.GridUid.Value).InvLocalMatrix.Transform(worldPos));
|
||||
: new EntityCoordinates(xform.GridUid.Value, Vector2.Transform(worldPos, XformQuery.GetComponent(xform.GridUid.Value).InvLocalMatrix));
|
||||
}
|
||||
|
||||
public EntityCoordinates GetMoverCoordinates(EntityCoordinates coordinates, EntityQuery<TransformComponent> xformQuery)
|
||||
@@ -176,11 +176,11 @@ namespace Robust.Shared.GameObjects
|
||||
DebugTools.Assert(!_mapManager.IsGrid(parentUid) && !_mapManager.IsMap(parentUid));
|
||||
|
||||
// Not parented to grid so convert their pos back to the grid.
|
||||
var worldPos = GetWorldMatrix(parentXform, XformQuery).Transform(coordinates.Position);
|
||||
var worldPos = Vector2.Transform(coordinates.Position, GetWorldMatrix(parentXform, XformQuery));
|
||||
|
||||
return parentXform.GridUid == null
|
||||
? new EntityCoordinates(mapId ?? parentUid, worldPos)
|
||||
: new EntityCoordinates(parentXform.GridUid.Value, XformQuery.GetComponent(parentXform.GridUid.Value).InvLocalMatrix.Transform(worldPos));
|
||||
: new EntityCoordinates(parentXform.GridUid.Value, Vector2.Transform(worldPos, XformQuery.GetComponent(parentXform.GridUid.Value).InvLocalMatrix));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -206,7 +206,7 @@ namespace Robust.Shared.GameObjects
|
||||
|
||||
var coords = xform.GridUid == null
|
||||
? new EntityCoordinates(xform.MapUid ?? xform.ParentUid, pos)
|
||||
: new EntityCoordinates(xform.GridUid.Value, XformQuery.GetComponent(xform.GridUid.Value).InvLocalMatrix.Transform(pos));
|
||||
: new EntityCoordinates(xform.GridUid.Value, Vector2.Transform(pos, XformQuery.GetComponent(xform.GridUid.Value).InvLocalMatrix));
|
||||
|
||||
return (coords, worldRot);
|
||||
}
|
||||
|
||||
@@ -59,9 +59,9 @@ namespace Robust.Shared.Graphics
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void GetViewMatrix(out Matrix3 viewMatrix, Vector2 renderScale)
|
||||
public void GetViewMatrix(out Matrix3x2 viewMatrix, Vector2 renderScale)
|
||||
{
|
||||
viewMatrix = Matrix3.CreateInverseTransform(
|
||||
viewMatrix = Matrix3Helpers.CreateInverseTransform(
|
||||
_coords.Position.X + Offset.X,
|
||||
_coords.Position.Y + Offset.Y,
|
||||
(float)-Rotation.Theta,
|
||||
@@ -69,9 +69,9 @@ namespace Robust.Shared.Graphics
|
||||
1 / (_scale.Y * renderScale.Y));
|
||||
}
|
||||
|
||||
public void GetViewMatrixNoOffset(out Matrix3 viewMatrix, Vector2 renderScale)
|
||||
public void GetViewMatrixNoOffset(out Matrix3x2 viewMatrix, Vector2 renderScale)
|
||||
{
|
||||
viewMatrix = Matrix3.CreateInverseTransform(
|
||||
viewMatrix = Matrix3Helpers.CreateInverseTransform(
|
||||
_coords.Position.X,
|
||||
_coords.Position.Y,
|
||||
(float)-Rotation.Theta,
|
||||
@@ -80,9 +80,9 @@ namespace Robust.Shared.Graphics
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void GetViewMatrixInv(out Matrix3 viewMatrixInv, Vector2 renderScale)
|
||||
public void GetViewMatrixInv(out Matrix3x2 viewMatrixInv, Vector2 renderScale)
|
||||
{
|
||||
viewMatrixInv = Matrix3.CreateTransform(
|
||||
viewMatrixInv = Matrix3Helpers.CreateTransform(
|
||||
_coords.Position.X + Offset.X,
|
||||
_coords.Position.Y + Offset.Y,
|
||||
(float)-Rotation.Theta,
|
||||
|
||||
@@ -53,7 +53,7 @@ namespace Robust.Shared.Graphics
|
||||
/// </summary>
|
||||
/// <param name="viewMatrix">View matrix for this camera.</param>
|
||||
/// <param name="renderScale"></param>
|
||||
void GetViewMatrix(out Matrix3 viewMatrix, Vector2 renderScale);
|
||||
void GetViewMatrix(out Matrix3x2 viewMatrix, Vector2 renderScale);
|
||||
|
||||
/// <summary>
|
||||
/// Returns the inverted view matrix for this eye, used to convert a point from
|
||||
@@ -61,8 +61,8 @@ namespace Robust.Shared.Graphics
|
||||
/// </summary>
|
||||
/// <param name="viewMatrixInv">Inverted view matrix for this camera.</param>
|
||||
/// <param name="renderScale"></param>
|
||||
void GetViewMatrixInv(out Matrix3 viewMatrixInv, Vector2 renderScale);
|
||||
void GetViewMatrixInv(out Matrix3x2 viewMatrixInv, Vector2 renderScale);
|
||||
|
||||
void GetViewMatrixNoOffset(out Matrix3 viewMatrix, Vector2 renderScale);
|
||||
void GetViewMatrixNoOffset(out Matrix3x2 viewMatrix, Vector2 renderScale);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Numerics;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
@@ -307,7 +307,7 @@ internal partial class MapManager
|
||||
|
||||
// Doesn't use WorldBounds because it's just an AABB.
|
||||
var matrix = tuple.xformSystem.GetInvWorldMatrix(iUid);
|
||||
var localPos = matrix.Transform(tuple.worldPos);
|
||||
var localPos = Vector2.Transform(tuple.worldPos, matrix);
|
||||
|
||||
// NOTE:
|
||||
// If you change this to use fixtures instead (i.e. if you want half-tiles) then you need to make sure
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System.Numerics;
|
||||
using System.Numerics;
|
||||
using Robust.Shared.Maths;
|
||||
|
||||
namespace Robust.Shared.Physics
|
||||
@@ -15,7 +15,7 @@ namespace Robust.Shared.Physics
|
||||
public abstract void DrawPolygonShape(Vector2[] vertices, in Color color);
|
||||
public abstract void DrawLine(Vector2 start, Vector2 end, in Color color);
|
||||
|
||||
public abstract void SetTransform(in Matrix3 transform);
|
||||
public abstract void SetTransform(in Matrix3x2 transform);
|
||||
public abstract Color CalcWakeColor(Color color, float wakePercent);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Buffers;
|
||||
using System.Collections.Generic;
|
||||
using System.Numerics;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.ObjectPool;
|
||||
using Robust.Shared.Configuration;
|
||||
@@ -288,8 +289,8 @@ namespace Robust.Shared.Physics.Systems
|
||||
ref (EntityUid gridUid,
|
||||
MapGridComponent grid,
|
||||
Transform transform,
|
||||
Matrix3 worldMatrix,
|
||||
Matrix3 invWorldMatrix,
|
||||
Matrix3x2 worldMatrix,
|
||||
Matrix3x2 invWorldMatrix,
|
||||
SharedMapSystem _map,
|
||||
SharedPhysicsSystem _physicsSystem,
|
||||
SharedTransformSystem xformSystem,
|
||||
@@ -446,7 +447,7 @@ namespace Robust.Shared.Physics.Systems
|
||||
}
|
||||
}
|
||||
|
||||
private void TouchProxies(EntityUid mapId, Matrix3 broadphaseMatrix, Fixture fixture)
|
||||
private void TouchProxies(EntityUid mapId, Matrix3x2 broadphaseMatrix, Fixture fixture)
|
||||
{
|
||||
foreach (var proxy in fixture.Proxies)
|
||||
{
|
||||
|
||||
@@ -246,7 +246,7 @@ public abstract partial class SharedJointSystem : EntitySystem
|
||||
anchorA ??= Vector2.Zero;
|
||||
anchorB ??= Vector2.Zero;
|
||||
|
||||
var length = xformA.WorldMatrix.Transform(anchorA.Value) - xformB.WorldMatrix.Transform(anchorB.Value);
|
||||
var length = Vector2.Transform(anchorA.Value, xformA.WorldMatrix) - Vector2.Transform(anchorB.Value, xformB.WorldMatrix);
|
||||
|
||||
var joint = new DistanceJoint(bodyA, bodyB, anchorA.Value, anchorB.Value, length.Length());
|
||||
id ??= GetJointId(joint);
|
||||
|
||||
@@ -33,6 +33,7 @@ using System.Collections.Generic;
|
||||
using System.Numerics;
|
||||
using Microsoft.Extensions.ObjectPool;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Physics.Collision;
|
||||
using Robust.Shared.Physics.Collision.Shapes;
|
||||
using Robust.Shared.Physics.Components;
|
||||
|
||||
@@ -983,7 +983,7 @@ public abstract partial class SharedPhysicsSystem
|
||||
var q = new Quaternion2D(angle);
|
||||
var adjustedPosition = positions[i] - Physics.Transform.Mul(q, body.LocalCenter);
|
||||
|
||||
var solvedPosition = parentInvMatrix.Transform(adjustedPosition);
|
||||
var solvedPosition = Vector2.Transform(adjustedPosition, parentInvMatrix);
|
||||
solvedPositions[offset + i] = solvedPosition - xform.LocalPosition;
|
||||
solvedAngles[offset + i] = angles[i] - worldRot;
|
||||
}
|
||||
|
||||
@@ -274,7 +274,7 @@ namespace Robust.Shared.Physics.Systems
|
||||
{
|
||||
var (_, rot, matrix, invMatrix) = _transform.GetWorldPositionRotationMatrixWithInv(uid);
|
||||
|
||||
var position = invMatrix.Transform(ray.Position);
|
||||
var position = Vector2.Transform(ray.Position, invMatrix);
|
||||
var gridRot = new Angle(-rot.Theta);
|
||||
var direction = gridRot.RotateVec(ray.Direction);
|
||||
|
||||
@@ -300,7 +300,7 @@ namespace Robust.Shared.Physics.Systems
|
||||
// TODO: Shape raycast here
|
||||
|
||||
// Need to convert it back to world-space.
|
||||
var result = new RayCastResults(distFromOrigin, matrix.Transform(point), proxy.Entity);
|
||||
var result = new RayCastResults(distFromOrigin, Vector2.Transform(point, matrix), proxy.Entity);
|
||||
results.Add(result);
|
||||
#if DEBUG
|
||||
_sharedDebugRaySystem.ReceiveLocalRayFromAnyThread(new(ray, maxLength, result, _netMan.IsServer, mapId));
|
||||
@@ -328,7 +328,7 @@ namespace Robust.Shared.Physics.Systems
|
||||
// TODO: Shape raycast here
|
||||
|
||||
// Need to convert it back to world-space.
|
||||
var result = new RayCastResults(distFromOrigin, matrix.Transform(point), proxy.Entity);
|
||||
var result = new RayCastResults(distFromOrigin, Vector2.Transform(point, matrix), proxy.Entity);
|
||||
results.Add(result);
|
||||
#if DEBUG
|
||||
_sharedDebugRaySystem.ReceiveLocalRayFromAnyThread(new(ray, maxLength, result, _netMan.IsServer, mapId));
|
||||
@@ -385,7 +385,7 @@ namespace Robust.Shared.Physics.Systems
|
||||
{
|
||||
var (_, rot, invMatrix) = _transform.GetWorldPositionRotationInvMatrix(uid);
|
||||
|
||||
var position = invMatrix.Transform(ray.Position);
|
||||
var position = Vector2.Transform(ray.Position, invMatrix);
|
||||
var gridRot = new Angle(-rot.Theta);
|
||||
var direction = gridRot.RotateVec(ray.Direction);
|
||||
|
||||
|
||||
@@ -234,7 +234,7 @@ public abstract partial class SharedPhysicsSystem
|
||||
|
||||
var parent = oldParent;
|
||||
TransformComponent? parentXform = _xformQuery.GetComponent(parent);
|
||||
var localPos = _transform.GetInvWorldMatrix(parentXform).Transform(_transform.GetWorldPosition(xform));
|
||||
var localPos = Vector2.Transform(_transform.GetWorldPosition(xform), _transform.GetInvWorldMatrix(parentXform));
|
||||
|
||||
var oldLinear = physics.LinearVelocity;
|
||||
var oldAngular = physics.AngularVelocity;
|
||||
|
||||
56
Robust.Shared/Serialization/Matrix3x2Serializer.cs
Normal file
56
Robust.Shared/Serialization/Matrix3x2Serializer.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Numerics;
|
||||
using System.Reflection;
|
||||
using System.Reflection.Emit;
|
||||
using NetSerializer;
|
||||
|
||||
namespace Robust.Shared.Serialization;
|
||||
|
||||
internal sealed class Matrix3x2Serializer : IStaticTypeSerializer
|
||||
{
|
||||
public bool Handles(Type type)
|
||||
{
|
||||
return type == typeof(Matrix3x2);
|
||||
}
|
||||
|
||||
public IEnumerable<Type> GetSubtypes(Type type)
|
||||
{
|
||||
return Type.EmptyTypes;
|
||||
}
|
||||
|
||||
public MethodInfo GetStaticWriter(Type type)
|
||||
{
|
||||
return typeof(Matrix3x2Serializer).GetMethod("WritePrimitive",
|
||||
BindingFlags.Static | BindingFlags.Public | BindingFlags.ExactBinding, null,
|
||||
new Type[] { typeof(Stream), type }, null)!;
|
||||
}
|
||||
|
||||
public MethodInfo GetStaticReader(Type type)
|
||||
{
|
||||
return typeof(Matrix3x2Serializer).GetMethod("ReadPrimitive",
|
||||
BindingFlags.Static | BindingFlags.Public | BindingFlags.ExactBinding, null,
|
||||
new Type[] { typeof(Stream), type.MakeByRefType() }, null)!;
|
||||
}
|
||||
|
||||
public static void WritePrimitive(Stream stream, Matrix3x2 value)
|
||||
{
|
||||
Primitives.WritePrimitive(stream, value.M11);
|
||||
Primitives.WritePrimitive(stream, value.M12);
|
||||
Primitives.WritePrimitive(stream, value.M21);
|
||||
Primitives.WritePrimitive(stream, value.M22);
|
||||
Primitives.WritePrimitive(stream, value.M31);
|
||||
Primitives.WritePrimitive(stream, value.M32);
|
||||
}
|
||||
|
||||
public static void ReadPrimitive(Stream stream, out Matrix3x2 value)
|
||||
{
|
||||
Span<float> buf = stackalloc float[6];
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
Primitives.ReadPrimitive(stream, out buf[i]);
|
||||
}
|
||||
value = new Matrix3x2(buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]);
|
||||
}
|
||||
}
|
||||
@@ -90,6 +90,7 @@ namespace Robust.Shared.Serialization
|
||||
{
|
||||
MappedStringSerializer.TypeSerializer,
|
||||
new Vector2Serializer(),
|
||||
new Matrix3x2Serializer(),
|
||||
}
|
||||
};
|
||||
_serializer = new Serializer(types, settings);
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
using System.Globalization;
|
||||
using System.Numerics;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Serialization.Manager;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.Serialization.Markdown;
|
||||
using Robust.Shared.Serialization.Markdown.Validation;
|
||||
using Robust.Shared.Serialization.Markdown.Value;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Interfaces;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Robust.Shared.Serialization.TypeSerializers.Implementations
|
||||
{
|
||||
[TypeSerializer]
|
||||
public sealed class Matrix3x2Serializer : ITypeSerializer<Matrix3x2, ValueDataNode>, ITypeCopyCreator<Matrix3x2>
|
||||
{
|
||||
public Matrix3x2 Read(ISerializationManager serializationManager, ValueDataNode node,
|
||||
IDependencyCollection dependencies,
|
||||
SerializationHookContext hookCtx,
|
||||
ISerializationContext? context = null,
|
||||
ISerializationManager.InstantiationDelegate<Matrix3x2>? instanceProvider = null)
|
||||
{
|
||||
if (!VectorSerializerUtility.TryParseArgs(node.Value, 6, out var args))
|
||||
{
|
||||
throw new InvalidMappingException($"Could not parse {nameof(Matrix3x2)}: '{node.Value}'");
|
||||
}
|
||||
|
||||
var data = new float[6];
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
data[i] = float.Parse(args[i], CultureInfo.InvariantCulture);
|
||||
}
|
||||
return new Matrix3x2(data[0], data[1], data[2], data[3], data[4], data[5]);
|
||||
}
|
||||
|
||||
public ValidationNode Validate(ISerializationManager serializationManager, ValueDataNode node,
|
||||
IDependencyCollection dependencies,
|
||||
ISerializationContext? context = null)
|
||||
{
|
||||
if (!VectorSerializerUtility.TryParseArgs(node.Value, 6, out var args))
|
||||
{
|
||||
throw new InvalidMappingException($"Could not parse {nameof(Matrix3x2)}: '{node.Value}'");
|
||||
}
|
||||
|
||||
return float.TryParse(args[0], NumberStyles.Any, CultureInfo.InvariantCulture, out _) &&
|
||||
float.TryParse(args[1], NumberStyles.Any, CultureInfo.InvariantCulture, out _) &&
|
||||
float.TryParse(args[2], NumberStyles.Any, CultureInfo.InvariantCulture, out _) &&
|
||||
float.TryParse(args[3], NumberStyles.Any, CultureInfo.InvariantCulture, out _) &&
|
||||
float.TryParse(args[4], NumberStyles.Any, CultureInfo.InvariantCulture, out _) &&
|
||||
float.TryParse(args[5], NumberStyles.Any, CultureInfo.InvariantCulture, out _)
|
||||
? new ValidatedValueNode(node)
|
||||
: new ErrorNode(node, "Failed parsing values for Matrix3x2.");
|
||||
}
|
||||
|
||||
public DataNode Write(ISerializationManager serializationManager, Matrix3x2 value,
|
||||
IDependencyCollection dependencies, bool alwaysWrite = false,
|
||||
ISerializationContext? context = null)
|
||||
{
|
||||
return new ValueDataNode($"{value.M11.ToString(CultureInfo.InvariantCulture)}," +
|
||||
$"{value.M12.ToString(CultureInfo.InvariantCulture)}," +
|
||||
$"{value.M21.ToString(CultureInfo.InvariantCulture)}," +
|
||||
$"{value.M22.ToString(CultureInfo.InvariantCulture)}," +
|
||||
$"{value.M31.ToString(CultureInfo.InvariantCulture)}," +
|
||||
$"{value.M32.ToString(CultureInfo.InvariantCulture)}");
|
||||
}
|
||||
|
||||
public Matrix3x2 CreateCopy(ISerializationManager serializationManager, Matrix3x2 source,
|
||||
IDependencyCollection dependencies, SerializationHookContext hookCtx, ISerializationContext? context = null)
|
||||
{
|
||||
return new(source.M11, source.M12, source.M21, source.M22, source.M31, source.M32);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Maths;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
@@ -107,19 +107,19 @@ namespace Robust.Shared.Utility
|
||||
}
|
||||
|
||||
[Pure]
|
||||
public static Matrix3 AsMatrix3(this YamlNode node)
|
||||
public static Matrix3x2 AsMatrix3x2(this YamlNode node)
|
||||
{
|
||||
string raw = AsString(node);
|
||||
string[] args = raw.Split(',');
|
||||
if (args.Length != 12)
|
||||
if (args.Length != 6)
|
||||
{
|
||||
throw new ArgumentException(string.Format("Could not parse {0}: '{1}'", nameof(Matrix3), raw));
|
||||
throw new ArgumentException(string.Format("Could not parse {0}: '{1}'", nameof(Matrix3x2), raw));
|
||||
}
|
||||
float[] parsedArgs = new float[12];
|
||||
for(var i = 0; i < 12; i += 1) {
|
||||
float[] parsedArgs = new float[6];
|
||||
for(var i = 0; i < 6; i += 1) {
|
||||
parsedArgs[i] = float.Parse(args[i],CultureInfo.InvariantCulture);
|
||||
}
|
||||
return new Matrix3(parsedArgs);
|
||||
return new Matrix3x2(parsedArgs[0], parsedArgs[1], parsedArgs[2], parsedArgs[3], parsedArgs[4], parsedArgs[5]);
|
||||
}
|
||||
|
||||
[Pure]
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System.Numerics;
|
||||
using System.Numerics;
|
||||
using NUnit.Framework.Constraints;
|
||||
using Robust.Shared.Maths;
|
||||
|
||||
@@ -49,6 +49,16 @@ namespace Robust.UnitTesting
|
||||
return new ConstraintResult(this, actual, exp.EqualsApprox(act));
|
||||
}
|
||||
|
||||
if (Expected is Matrix3x2 m3x2Expected && actual is Matrix3x2 m3x2Actual)
|
||||
{
|
||||
if (Tolerance != null)
|
||||
{
|
||||
return new ConstraintResult(this, actual, m3x2Expected.EqualsApprox(m3x2Actual, Tolerance.Value));
|
||||
}
|
||||
|
||||
return new ConstraintResult(this, actual, m3x2Expected.EqualsApprox(m3x2Actual));
|
||||
}
|
||||
|
||||
return new ConstraintResult(this, actual, false);
|
||||
}
|
||||
|
||||
|
||||
@@ -367,7 +367,7 @@ namespace Robust.UnitTesting.Server.GameObjects.Components
|
||||
public void TreeComposeWorldMatricesTest()
|
||||
{
|
||||
// Arrange
|
||||
var control = Matrix3.Identity;
|
||||
var control = Matrix3x2.Identity;
|
||||
|
||||
var node1 = EntityManager.SpawnEntity(null, InitialPos);
|
||||
var node2 = EntityManager.SpawnEntity(null, InitialPos);
|
||||
@@ -395,8 +395,8 @@ namespace Robust.UnitTesting.Server.GameObjects.Components
|
||||
var worldMat = XformSystem.GetWorldMatrix(node4Trans);
|
||||
var invWorldMat = XformSystem.GetInvWorldMatrix(node4Trans);
|
||||
|
||||
Matrix3.Multiply(in worldMat, in invWorldMat, out var leftVerifyMatrix);
|
||||
Matrix3.Multiply(in invWorldMat, in worldMat, out var rightVerifyMatrix);
|
||||
var leftVerifyMatrix = Matrix3x2.Multiply(worldMat, invWorldMat);
|
||||
var rightVerifyMatrix = Matrix3x2.Multiply(invWorldMat, worldMat);
|
||||
|
||||
//Assert
|
||||
|
||||
|
||||
@@ -9,20 +9,20 @@ namespace Robust.UnitTesting.Shared.Maths
|
||||
{
|
||||
[TestFixture]
|
||||
[Parallelizable(ParallelScope.All | ParallelScope.Fixtures)]
|
||||
[TestOf(typeof(Matrix3))]
|
||||
[TestOf(typeof(Matrix3x2))]
|
||||
public sealed class Matrix3_Test
|
||||
{
|
||||
[Test]
|
||||
public void GetRotationTest()
|
||||
{
|
||||
Assert.That(Matrix3.Identity.Rotation(), Is.EqualTo(Angle.Zero));
|
||||
Assert.That(Matrix3x2.Identity.Rotation(), Is.EqualTo(Angle.Zero));
|
||||
|
||||
var piOver2 = new Angle(Math.PI / 2);
|
||||
var piOver2Mat = Matrix3.CreateRotation(piOver2.Theta);
|
||||
var piOver2Mat = Matrix3Helpers.CreateRotation(piOver2.Theta);
|
||||
Assert.That(piOver2Mat.Rotation(), Is.EqualTo(piOver2));
|
||||
|
||||
var pi = new Angle(Math.PI);
|
||||
var piMat = Matrix3.CreateRotation(pi.Theta);
|
||||
var piMat = Matrix3Helpers.CreateRotation(pi.Theta);
|
||||
Assert.That(piMat.Rotation(), Is.EqualTo(pi));
|
||||
}
|
||||
|
||||
@@ -30,12 +30,11 @@ namespace Robust.UnitTesting.Shared.Maths
|
||||
public void TranslationTest()
|
||||
{
|
||||
var control = new Vector2(1, 1);
|
||||
var matrix = Matrix3.CreateTranslation(control);
|
||||
var matrix = Matrix3Helpers.CreateTranslation(control);
|
||||
|
||||
var origin = new Vector3(0, 0, 1);
|
||||
Matrix3.Transform(matrix, ref origin);
|
||||
var origin = new Vector2(0, 0);
|
||||
var result = Vector2.Transform(origin, matrix);
|
||||
|
||||
var result = origin.Xy;
|
||||
Assert.That(control == result, Is.True, result.ToString);
|
||||
}
|
||||
|
||||
@@ -57,13 +56,12 @@ namespace Robust.UnitTesting.Shared.Maths
|
||||
{
|
||||
var angle = testCase.Item2;
|
||||
|
||||
var matrix = Matrix3.CreateRotation((float)angle);
|
||||
var matrix = Matrix3Helpers.CreateRotation((float)angle);
|
||||
|
||||
var test = new Vector3(1, 0, 1);
|
||||
Matrix3.Transform(matrix, ref test);
|
||||
var test = new Vector2(1, 0);
|
||||
var result = Vector2.Transform(test, matrix);
|
||||
|
||||
var control = testCase.Item1;
|
||||
var result = test.Xy;
|
||||
|
||||
Assert.That(MathHelper.CloseToPercent(control.X, result.X), Is.True, result.ToString);
|
||||
Assert.That(MathHelper.CloseToPercent(control.Y, result.Y), Is.True, result.ToString);
|
||||
@@ -72,28 +70,28 @@ namespace Robust.UnitTesting.Shared.Maths
|
||||
[Test]
|
||||
public void MultiplyTransformOrder()
|
||||
{
|
||||
var startPoint = new Vector3(1, 0, 1);
|
||||
var startPoint = new Vector2(1, 0);
|
||||
|
||||
Vector2 scale = new Vector2(2, 2);
|
||||
Angle angle = new Angle(System.MathF.PI / 2);
|
||||
Vector2 offset = new Vector2(-5, -3);
|
||||
|
||||
var scaleMatrix = Matrix3.CreateScale(scale);
|
||||
var rotateMatrix = Matrix3.CreateRotation(angle);
|
||||
var translateMatrix = Matrix3.CreateTranslation(offset);
|
||||
var scaleMatrix = Matrix3Helpers.CreateScale(scale);
|
||||
var rotateMatrix = Matrix3Helpers.CreateRotation(angle);
|
||||
var translateMatrix = Matrix3Helpers.CreateTranslation(offset);
|
||||
|
||||
// 1. Take the start point -> ( 1, 0)
|
||||
// 2. Scale it by 2 -> ( 2, 0)
|
||||
// 3. Rotate by +90 degrees -> ( 0, 2)
|
||||
// 4. Translate by (-5, -3) -> (-5,-1)
|
||||
var result = (scaleMatrix * rotateMatrix * translateMatrix) * startPoint;
|
||||
var result = Vector2.Transform(startPoint, scaleMatrix * rotateMatrix * translateMatrix);
|
||||
|
||||
Assert.That(result.X, Is.Approximately(-5f));
|
||||
Assert.That(result.Y, Is.Approximately(-1f));
|
||||
|
||||
// repeat but with CreateTransform()
|
||||
var transform = Matrix3.CreateTransform(offset, angle, scale);
|
||||
result = transform * startPoint;
|
||||
var transform = Matrix3Helpers.CreateTransform(offset, angle, scale);
|
||||
result = Vector2.Transform(startPoint, transform);
|
||||
Assert.That(result.X, Is.Approximately(-5f));
|
||||
Assert.That(result.Y, Is.Approximately(-1f));
|
||||
}
|
||||
@@ -105,54 +103,27 @@ namespace Robust.UnitTesting.Shared.Maths
|
||||
Angle angle = new Angle(System.MathF.PI / 2.21f);
|
||||
Vector2 offset = new Vector2(-5, 3);
|
||||
|
||||
var transform = Matrix3.CreateTransform(offset, angle, scale);
|
||||
var invTransform = Matrix3.CreateInverseTransform(offset, angle, scale);
|
||||
var transform = Matrix3Helpers.CreateTransform(offset, angle, scale);
|
||||
var expectedInv = Matrix3Helpers.CreateInverseTransform(offset, angle, scale);
|
||||
|
||||
Assert.That(Matrix3.Invert(transform).EqualsApprox(invTransform));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InvertTest()
|
||||
{
|
||||
const float epsilon = 1.0E-7f;
|
||||
var control = Matrix3.Identity;
|
||||
|
||||
// take our matrix
|
||||
var normalMatrix = new Matrix3(
|
||||
3, 7, 2,
|
||||
1, 8, 4,
|
||||
2, 1, 9
|
||||
);
|
||||
|
||||
// invert it (1/matrix)
|
||||
var invMatrix = Matrix3.Invert(normalMatrix);
|
||||
|
||||
// multiply it back together
|
||||
Matrix3.Multiply(in normalMatrix, in invMatrix, out var leftVerifyMatrix);
|
||||
Matrix3.Multiply(in invMatrix, in normalMatrix, out var rightVerifyMatrix);
|
||||
|
||||
// these should be the same (A × A-1 = A-1 × A = I)
|
||||
Assert.That(leftVerifyMatrix, new ApproxEqualityConstraint(rightVerifyMatrix, epsilon));
|
||||
|
||||
// verify matrix == identity matrix (or very close to because float precision)
|
||||
Assert.That(leftVerifyMatrix, new ApproxEqualityConstraint(control, epsilon));
|
||||
Matrix3x2.Invert(transform, out var invTransform);
|
||||
Assert.That(invTransform.EqualsApprox(expectedInv));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TranslateMultiplyTest()
|
||||
{
|
||||
// Arrange
|
||||
var mat1 = Matrix3.CreateTranslation(new Vector2(1, 1));
|
||||
var mat2 = Matrix3.CreateTranslation(new Vector2(-2, -2));
|
||||
var mat3 = Matrix3.CreateTranslation(new Vector2(3, 3));
|
||||
var mat1 = Matrix3Helpers.CreateTranslation(new Vector2(1, 1));
|
||||
var mat2 = Matrix3Helpers.CreateTranslation(new Vector2(-2, -2));
|
||||
var mat3 = Matrix3Helpers.CreateTranslation(new Vector2(3, 3));
|
||||
|
||||
mat1.Multiply(in mat2, out var res2);
|
||||
res2.Multiply(in mat3, out var res3);
|
||||
var res2 = Matrix3x2.Multiply(mat1, mat2);
|
||||
var res3 = Matrix3x2.Multiply(res2, mat3);
|
||||
|
||||
// Act
|
||||
Vector3 test = new Vector3(0, 0, 1);
|
||||
Matrix3.Transform(res3, ref test);
|
||||
var result = test.Xy;
|
||||
Vector2 test = new Vector2(0, 0);
|
||||
var result = Vector2.Transform(test, res3);
|
||||
|
||||
// Assert
|
||||
Assert.That(MathHelper.CloseToPercent(result.X, 2), result.ToString);
|
||||
@@ -163,19 +134,19 @@ namespace Robust.UnitTesting.Shared.Maths
|
||||
public void SpaceSwitchTest()
|
||||
{
|
||||
// Arrange
|
||||
var startPoint = new Vector3(2, 0, 1);
|
||||
var rotateMatrix = Matrix3.CreateRotation((float)(System.Math.PI / 6.3967));
|
||||
var translateMatrix = Matrix3.CreateTranslation(new Vector2(5.357f, -37.53854f));
|
||||
var startPoint = new Vector2(2, 0);
|
||||
var rotateMatrix = Matrix3Helpers.CreateRotation((float)(System.Math.PI / 6.3967));
|
||||
var translateMatrix = Matrix3Helpers.CreateTranslation(new Vector2(5.357f, -37.53854f));
|
||||
|
||||
// NOTE: Matrix Product is NOT commutative. OpenTK (and this) uses pre-multiplication, OpenGL and all the tutorials
|
||||
// you will read about it use post-multiplication. So in OpenTK MVP = M*V*P; in OpenGL it is MVP = P*V*M.
|
||||
Matrix3.Multiply(in rotateMatrix, in translateMatrix, out var transformMatrix);
|
||||
var transformMatrix = Matrix3x2.Multiply(rotateMatrix, translateMatrix);
|
||||
|
||||
// Act
|
||||
Matrix3.Transform(in transformMatrix, in startPoint, out var localPoint);
|
||||
var localPoint = Vector2.Transform(startPoint, transformMatrix);
|
||||
|
||||
var invMatrix = Matrix3.Invert(transformMatrix);
|
||||
Matrix3.Transform(in invMatrix, in localPoint, out var result);
|
||||
Matrix3x2.Invert(transformMatrix, out var invMatrix);
|
||||
var result = Vector2.Transform(localPoint, invMatrix);
|
||||
|
||||
// Assert
|
||||
Assert.That(MathHelper.CloseToPercent(startPoint.X, result.X), Is.True, result.ToString);
|
||||
@@ -193,10 +164,9 @@ namespace Robust.UnitTesting.Shared.Maths
|
||||
{
|
||||
var (box, expected) = set;
|
||||
|
||||
var matrix = Matrix3.Identity;
|
||||
matrix.Rotate(Angle.FromDegrees(20));
|
||||
matrix.R0C2 += 10;
|
||||
matrix.R1C2 += 10;
|
||||
var matrix = Matrix3Helpers.CreateRotation(Angle.FromDegrees(-20));
|
||||
matrix.M31 += 10;
|
||||
matrix.M32 += 10;
|
||||
|
||||
var transformed = matrix.TransformBox(box);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user