Transitioned from VectorX to floatX

And some trying to update Rigidbody when transform changes
This commit is contained in:
Simon Lübeß
2023-06-25 02:47:33 +02:00
parent 5f5da2ed35
commit 9e1f648aa0
49 changed files with 1281 additions and 871 deletions
@@ -160,16 +160,32 @@ namespace GlitchyEditor.EditWindows
textWidth += ImGui.GetStyle().FramePadding.x * 3.0f;
Vector3 position = transform.Position;
if (ImGui.EditVector3("Position", ref position, .Zero, 0.1f, textWidth))
float3 position = transform.Position;
if (ImGui.Editfloat3("Position", ref position, .Zero, 0.1f, textWidth))
{
transform.Position = position;
Vector3 rotationEuler = MathHelper.ToDegrees(transform.EditorRotationEuler);
if (ImGui.EditVector3("Rotation", ref rotationEuler, .Zero, 0.1f, textWidth))
// if necessary reposition Rigidbody2D
if (entity.TryGetComponent<Rigidbody2DComponent>(let rigidbody2D))
{
rigidbody2D.SetPosition(position.XY);
}
}
float3 rotationEuler = MathHelper.ToDegrees(transform.EditorRotationEuler);
if (ImGui.Editfloat3("Rotation", ref rotationEuler, .Zero, 0.1f, textWidth))
{
transform.EditorRotationEuler = MathHelper.ToRadians(rotationEuler);
// if necessary reposition Rigidbody2D
if (entity.TryGetComponent<Rigidbody2DComponent>(let rigidbody2D))
{
rigidbody2D.SetAngle(rotationEuler.Z);
}
}
Vector3 scale = transform.Scale;
if (ImGui.EditVector3("Scale", ref scale, .One, 0.1f, textWidth))
float3 scale = transform.Scale;
if (ImGui.Editfloat3("Scale", ref scale, .One, 0.1f, textWidth))
transform.Scale = scale;
}
@@ -375,12 +391,12 @@ namespace GlitchyEditor.EditWindows
textWidth += ImGui.GetStyle().FramePadding.x * 3.0f;
Vector2 offset = boxCollider.Offset;
if (ImGui.EditVector2("Offset", ref offset, .Zero, 0.1f, textWidth))
float2 offset = boxCollider.Offset;
if (ImGui.Editfloat2("Offset", ref offset, .Zero, 0.1f, textWidth))
boxCollider.Offset = offset;
Vector2 size = boxCollider.Size;
if (ImGui.EditVector2("Size", ref size, .Zero, 0.1f, textWidth))
float2 size = boxCollider.Size;
if (ImGui.Editfloat2("Size", ref size, .Zero, 0.1f, textWidth))
boxCollider.Size = size;
float density = boxCollider.Density;
@@ -406,8 +422,8 @@ namespace GlitchyEditor.EditWindows
textWidth += ImGui.GetStyle().FramePadding.x * 3.0f;
Vector2 offset = circleCollider.Offset;
if (ImGui.EditVector2("Offset", ref offset, .Zero, 0.1f, textWidth))
float2 offset = circleCollider.Offset;
if (ImGui.Editfloat2("Offset", ref offset, .Zero, 0.1f, textWidth))
circleCollider.Offset = offset;
float radius = circleCollider.Radius;
@@ -542,17 +558,17 @@ namespace GlitchyEditor.EditWindows
if (ImGui.DragScalar(fieldName.ToScopeCStr!(), .Float, &value))
SetFieldValue(scriptInstance, scriptField, value);
case .Vector2:
GetFieldValue<Vector2>(scriptInstance, scriptField, var value);
if (ImGui.EditVector2(fieldName, ref value))
case .float2:
GetFieldValue<float2>(scriptInstance, scriptField, var value);
if (ImGui.Editfloat2(fieldName, ref value))
SetFieldValue(scriptInstance, scriptField, value);
case .Vector3:
GetFieldValue<Vector3>(scriptInstance, scriptField, var value);
if (ImGui.EditVector3(fieldName, ref value))
case .float3:
GetFieldValue<float3>(scriptInstance, scriptField, var value);
if (ImGui.Editfloat3(fieldName, ref value))
SetFieldValue(scriptInstance, scriptField, value);
case .Vector4:
GetFieldValue<Vector4>(scriptInstance, scriptField, var value);
if (ImGui.EditVector4(fieldName, ref value))
case .float4:
GetFieldValue<float4>(scriptInstance, scriptField, var value);
if (ImGui.Editfloat4(fieldName, ref value))
SetFieldValue(scriptInstance, scriptField, value);
case .Double:
@@ -132,9 +132,9 @@ namespace GlitchyEditor.EditWindows
}
}
private static Vector2 DirectoryItemSize = .(110, 110);
private static float2 DirectoryItemSize = .(110, 110);
const Vector2 padding = .(24, 24);
const float2 padding = .(24, 24);
/// Renders the contents of _currentDirectory.
private void DrawCurrentDirectory()
@@ -32,9 +32,9 @@ namespace GlitchyEditor.EditWindows
public uint32 SelectedEntityId {get; private set; }
public bool SelectionChanged { get; private set; }
public Vector2 ViewportSize => (Vector2)_oldViewportSize;
public float2 ViewportSize => (float2)_oldViewportSize;
// Occurs when the viewport is resized.
public Event<EventHandler<Vector2>> ViewportSizeChanged ~ _.Dispose();
public Event<EventHandler<float2>> ViewportSizeChanged ~ _.Dispose();
// Occurs when an entity was clicked.
public Event<EventHandler<uint32>> EntityClicked ~ _.Dispose();
@@ -126,7 +126,7 @@ namespace GlitchyEditor.EditWindows
if(_oldViewportSize != viewportSize)
{
ViewportSizeChanged.Invoke(this, (Vector2)viewportSize);
ViewportSizeChanged.Invoke(this, (float2)viewportSize);
_viewPortChanged = true;
_oldViewportSize = viewportSize;
}
@@ -154,14 +154,14 @@ namespace GlitchyEditor.EditWindows
{
_wrappedCursor = false;
let mousePos = (Vector2)ImGui.GetMousePos();
let winPos = (Vector2)ImGui.GetWindowPos();
let regionMin = winPos + (Vector2)ImGui.GetWindowContentRegionMin();
let regionMax = winPos + (Vector2)ImGui.GetWindowContentRegionMax();
let mousePos = (float2)ImGui.GetMousePos();
let winPos = (float2)ImGui.GetWindowPos();
let regionMin = winPos + (float2)ImGui.GetWindowContentRegionMin();
let regionMax = winPos + (float2)ImGui.GetWindowContentRegionMax();
ImGui.DrawRect((.)regionMin, (.)regionMax, .(0, 255, 0));
Vector2 newMousePos = mousePos;
float2 newMousePos = mousePos;
if (mousePos.X < regionMin.X + 1)
{
@@ -181,7 +181,7 @@ namespace GlitchyEditor.EditWindows
newMousePos.Y = regionMin.Y + 10;
}
if (newMousePos != mousePos)
if (any(newMousePos != mousePos))
{
Input.SetMousePosition((Int2)newMousePos);
// After wrapping the cursor the the other side, the camera controller must not compare the positions,
@@ -195,7 +195,7 @@ namespace GlitchyEditor.EditWindows
/// If the user clicks, the entity beneath the cursor will be selected.
private void MousePicking(ImGui.Vec2 viewportSize, bool gizmoUsed)
{
Vector2 relativeMouse = (Vector2)ImGui.GetMousePos() - (Vector2)ImGui.GetItemRectMin();
float2 relativeMouse = (float2)ImGui.GetMousePos() - (float2)ImGui.GetItemRectMin();
int rtWidth = _editor.EditorSceneRenderer.CompositeTarget.Width;
int rtHeight = _editor.EditorSceneRenderer.CompositeTarget.Height;
@@ -316,9 +316,9 @@ namespace GlitchyEditor.EditWindows
parentView = parentTransformCmp.WorldTransform.Invert();
}
Vector3 snap = .(_snap);
float3 snap = (float3)_snap;
if (_gizmoType.HasFlag(.ROTATE))
snap = .(_angleSnap);
snap = (float3)_angleSnap;
if (ImGuizmo.Manipulate((.)&view, (.)&projection, _gizmoType, _gizmoMode, (.)&worldTransform, null, _doSnap ? (.)&snap : null))
{
@@ -20,9 +20,9 @@ namespace GlitchyEditor.EditWindows
private RenderTargetGroup _renderTarget ~ _?.ReleaseRef();
public Vector2 ViewportSize => (Vector2)_oldViewportSize;
public float2 ViewportSize => (float2)_oldViewportSize;
// Occurs when the viewport is resized.
public Event<EventHandler<Vector2>> ViewportSizeChanged ~ _.Dispose();
public Event<EventHandler<float2>> ViewportSizeChanged ~ _.Dispose();
// Occurs when an entity was clicked.
public Event<EventHandler<uint32>> EntityClicked ~ _.Dispose();
@@ -80,7 +80,7 @@ namespace GlitchyEditor.EditWindows
if(_oldViewportSize != viewportSize)
{
ViewportSizeChanged.Invoke(this, (Vector2)viewportSize);
ViewportSizeChanged.Invoke(this, (float2)viewportSize);
_viewPortChanged = true;
_oldViewportSize = viewportSize;
}