Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Give Drawables a 3D rotation + add perspective #6062

Draft
wants to merge 14 commits into
base: master
Choose a base branch
from
426 changes: 213 additions & 213 deletions osu.Framework.Tests/Primitives/QuadTest.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public void TestParentPadding()
};
});

AddAssert("inner box stops at edge of right box", () => Precision.AlmostEquals(fullBox.ScreenSpaceDrawQuad.TopRight, innerBox.ScreenSpaceDrawQuad.TopRight));
AddAssert("inner box stops at edge of right box", () => Precision.AlmostEquals(fullBox.ScreenSpaceDrawQuad.TopRight.Xy, innerBox.ScreenSpaceDrawQuad.TopRight.Xy));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public void TestContentAnchors()
});

AddStep("Scroll to 0", () => scrollContainer.ScrollTo(0, false));
AddAssert("Content position at top", () => Precision.AlmostEquals(scrollContainer.ScreenSpaceDrawQuad.TopLeft, scrollContainer.ScrollContent.ScreenSpaceDrawQuad.TopLeft));
AddAssert("Content position at top", () => Precision.AlmostEquals(scrollContainer.ScreenSpaceDrawQuad.TopLeft.Xy, scrollContainer.ScrollContent.ScreenSpaceDrawQuad.TopLeft.Xy));
}

[Test]
Expand Down Expand Up @@ -245,9 +245,9 @@ public void TestClampedScrollbarDrag()
InputManager.MoveMouseTo(clampedContainer.Scrollbar.ToScreenSpace(clampedContainer.Scrollbar.LayoutRectangle.Centre + new Vector2(0, -10f)));
});

AddStep("Move mouse up", () => InputManager.MoveMouseTo(scrollContainer.ScreenSpaceDrawQuad.TopRight - new Vector2(0, 20)));
AddStep("Move mouse up", () => InputManager.MoveMouseTo(scrollContainer.ScreenSpaceDrawQuad.TopRight.Xy - new Vector2(0, 20)));
checkScrollbarPosition(0);
AddStep("Move mouse down", () => InputManager.MoveMouseTo(scrollContainer.ScreenSpaceDrawQuad.BottomRight + new Vector2(0, 20)));
AddStep("Move mouse down", () => InputManager.MoveMouseTo(scrollContainer.ScreenSpaceDrawQuad.BottomRight.Xy + new Vector2(0, 20)));
checkScrollbarPosition(250);
AddStep("Release mouse button", () => InputManager.ReleaseButton(MouseButton.Left));
checkScrollbarPosition(250);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,25 +128,25 @@ protected override void Draw(IRenderer renderer)
{
vertices.Add(new ColourIndexedVertex
{
Position = areas[i].BottomLeft,
Position = areas[i].BottomLeft.Xy, // TODO: WRONG
ColourIndex = i % colourBuffer.Size
});

vertices.Add(new ColourIndexedVertex
{
Position = areas[i].BottomRight,
Position = areas[i].BottomRight.Xy, // TODO: WRONG
ColourIndex = i % colourBuffer.Size
});

vertices.Add(new ColourIndexedVertex
{
Position = areas[i].TopRight,
Position = areas[i].TopRight.Xy, // TODO: WRONG
ColourIndex = i % colourBuffer.Size
});

vertices.Add(new ColourIndexedVertex
{
Position = areas[i].TopLeft,
Position = areas[i].TopLeft.Xy, // TODO: WRONG
ColourIndex = i % colourBuffer.Size
});
}
Expand Down Expand Up @@ -219,25 +219,25 @@ protected override void Draw(IRenderer renderer)

vertices.Add(new ColourIndexedVertex
{
Position = areas[i].BottomLeft,
Position = areas[i].BottomLeft.Xy, // TODO: WRONG
ColourIndex = colourIndex
});

vertices.Add(new ColourIndexedVertex
{
Position = areas[i].BottomRight,
Position = areas[i].BottomRight.Xy, // TODO: WRONG
ColourIndex = colourIndex
});

vertices.Add(new ColourIndexedVertex
{
Position = areas[i].TopRight,
Position = areas[i].TopRight.Xy, // TODO: WRONG
ColourIndex = colourIndex
});

vertices.Add(new ColourIndexedVertex
{
Position = areas[i].TopLeft,
Position = areas[i].TopLeft.Xy, // TODO: WRONG
ColourIndex = colourIndex
});

Expand Down
38 changes: 19 additions & 19 deletions osu.Framework.Tests/Visual/Input/TestSceneMouseStates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,26 +140,26 @@ public void BasicMovement()
{
initTestScene();

AddStep("push move", () => InputManager.MoveMouseTo(marginBox.ScreenSpaceDrawQuad.TopLeft));
AddStep("push move", () => InputManager.MoveMouseTo(marginBox.ScreenSpaceDrawQuad.TopLeft.Xy));
checkEventCount(move, 1);
checkEventCount(scroll);

AddStep("push move", () => InputManager.MoveMouseTo(marginBox.ScreenSpaceDrawQuad.TopRight));
AddStep("push move", () => InputManager.MoveMouseTo(marginBox.ScreenSpaceDrawQuad.TopRight.Xy));
checkEventCount(move, 1);
checkEventCount(scroll);
checkLastPositionDelta(() => marginBox.ScreenSpaceDrawQuad.Width);

AddStep("push move", () => InputManager.MoveMouseTo(marginBox.ScreenSpaceDrawQuad.BottomRight));
AddStep("push move", () => InputManager.MoveMouseTo(marginBox.ScreenSpaceDrawQuad.BottomRight.Xy));
checkEventCount(move, 1);
checkLastPositionDelta(() => marginBox.ScreenSpaceDrawQuad.Height);

AddStep("push two moves", () =>
{
InputManager.MoveMouseTo(marginBox.ScreenSpaceDrawQuad.TopLeft);
InputManager.MoveMouseTo(marginBox.ScreenSpaceDrawQuad.BottomLeft);
InputManager.MoveMouseTo(marginBox.ScreenSpaceDrawQuad.TopLeft.Xy);
InputManager.MoveMouseTo(marginBox.ScreenSpaceDrawQuad.BottomLeft.Xy);
});
checkEventCount(move, 2);
checkLastPositionDelta(() => Vector2.Distance(marginBox.ScreenSpaceDrawQuad.TopLeft, marginBox.ScreenSpaceDrawQuad.BottomLeft));
checkLastPositionDelta(() => Vector2.Distance(marginBox.ScreenSpaceDrawQuad.TopLeft.Xy, marginBox.ScreenSpaceDrawQuad.BottomLeft.Xy));
}

[Test]
Expand Down Expand Up @@ -220,12 +220,12 @@ public void Drag()
checkEventCount(mouse_down, 1);
checkIsDragged(false);

AddStep("move bottom left", () => InputManager.MoveMouseTo(marginBox.ScreenSpaceDrawQuad.BottomLeft));
AddStep("move bottom left", () => InputManager.MoveMouseTo(marginBox.ScreenSpaceDrawQuad.BottomLeft.Xy));
checkEventCount(drag_start, 1);
checkEventCount(drag, 1);
checkIsDragged(true);

AddStep("move bottom right", () => InputManager.MoveMouseTo(marginBox.ScreenSpaceDrawQuad.BottomRight));
AddStep("move bottom right", () => InputManager.MoveMouseTo(marginBox.ScreenSpaceDrawQuad.BottomRight.Xy));
checkEventCount(drag_start, 0);
checkEventCount(drag, 1);
checkIsDragged(true);
Expand Down Expand Up @@ -259,7 +259,7 @@ public void DragWithDraggedDrawableRemovedMidDrag()
checkEventCount(mouse_down, 1);
checkIsDragged(false);

AddStep("move bottom left", () => InputManager.MoveMouseTo(marginBox.ScreenSpaceDrawQuad.BottomLeft));
AddStep("move bottom left", () => InputManager.MoveMouseTo(marginBox.ScreenSpaceDrawQuad.BottomLeft.Xy));
checkEventCount(drag_start, 1);
checkEventCount(drag, 1);
checkIsDragged(true);
Expand All @@ -270,7 +270,7 @@ public void DragWithDraggedDrawableRemovedMidDrag()
checkEventCount(drag_end, 0);
checkIsDragged(false);

AddStep("move bottom right", () => InputManager.MoveMouseTo(marginBox.ScreenSpaceDrawQuad.BottomRight));
AddStep("move bottom right", () => InputManager.MoveMouseTo(marginBox.ScreenSpaceDrawQuad.BottomRight.Xy));
AddStep("release left button", () => InputManager.ReleaseButton(MouseButton.Left));

checkEventCount(drag_start, 0);
Expand All @@ -285,7 +285,7 @@ public void CombinationChanges()
{
initTestScene();

AddStep("push move", () => InputManager.MoveMouseTo(marginBox.ScreenSpaceDrawQuad.BottomLeft));
AddStep("push move", () => InputManager.MoveMouseTo(marginBox.ScreenSpaceDrawQuad.BottomLeft.Xy));
checkEventCount(move, 1);

AddStep("push move and scroll", () =>
Expand All @@ -297,7 +297,7 @@ public void CombinationChanges()
checkEventCount(move, 1);
checkEventCount(scroll, 1);
checkLastScrollDelta(new Vector2(1, 2));
checkLastPositionDelta(() => Vector2.Distance(marginBox.ScreenSpaceDrawQuad.BottomLeft, marginBox.ScreenSpaceDrawQuad.Centre));
checkLastPositionDelta(() => Vector2.Distance(marginBox.ScreenSpaceDrawQuad.BottomLeft.Xy, marginBox.ScreenSpaceDrawQuad.Centre));

AddStep("Move mouse to out of bounds", () => InputManager.MoveMouseTo(Vector2.Zero));

Expand All @@ -321,7 +321,7 @@ public void DragAndClick()
initTestScene();

// mouseDown on a non-draggable -> mouseUp on a distant position: drag-clicking
AddStep("move mouse", () => InputManager.MoveMouseTo(outerMarginBox.ScreenSpaceDrawQuad.TopLeft));
AddStep("move mouse", () => InputManager.MoveMouseTo(outerMarginBox.ScreenSpaceDrawQuad.TopLeft.Xy));
AddStep("press left button", () => InputManager.PressButton(MouseButton.Left));
checkEventCount(drag_start);
AddStep("drag non-draggable", () => InputManager.MoveMouseTo(marginBox));
Expand All @@ -331,12 +331,12 @@ public void DragAndClick()
checkEventCount(drag_end);

// mouseDown on a draggable -> mouseUp on the original position: no drag-clicking
AddStep("move mouse", () => InputManager.MoveMouseTo(marginBox.ScreenSpaceDrawQuad.TopLeft));
AddStep("move mouse", () => InputManager.MoveMouseTo(marginBox.ScreenSpaceDrawQuad.TopLeft.Xy));
AddStep("press left button", () => InputManager.PressButton(MouseButton.Left));
AddStep("drag draggable", () => InputManager.MoveMouseTo(outerMarginBox.ScreenSpaceDrawQuad.BottomRight));
AddStep("drag draggable", () => InputManager.MoveMouseTo(outerMarginBox.ScreenSpaceDrawQuad.BottomRight.Xy));
checkEventCount(drag_start, 1);
checkIsDragged(true);
AddStep("return mouse position", () => InputManager.MoveMouseTo(marginBox.ScreenSpaceDrawQuad.TopLeft));
AddStep("return mouse position", () => InputManager.MoveMouseTo(marginBox.ScreenSpaceDrawQuad.TopLeft.Xy));
checkIsDragged(true);
checkEventCount(drag_end);
AddStep("release left button", () => InputManager.ReleaseButton(MouseButton.Left));
Expand All @@ -346,7 +346,7 @@ public void DragAndClick()

// mouseDown on a draggable -> mouseUp on a distant position: no drag-clicking
AddStep("press left button", () => InputManager.PressButton(MouseButton.Left));
AddStep("drag draggable", () => InputManager.MoveMouseTo(marginBox.ScreenSpaceDrawQuad.BottomRight));
AddStep("drag draggable", () => InputManager.MoveMouseTo(marginBox.ScreenSpaceDrawQuad.BottomRight.Xy));
AddStep("release left button", () => InputManager.ReleaseButton(MouseButton.Left));
checkEventCount(drag_start, 1);
checkEventCount(drag_end, 1);
Expand Down Expand Up @@ -399,7 +399,7 @@ public void ClickAndDoubleClick()
{
InputManager.Click(MouseButton.Left);
InputManager.PressButton(MouseButton.Left);
InputManager.MoveMouseTo(outerMarginBox.ScreenSpaceDrawQuad.TopLeft);
InputManager.MoveMouseTo(outerMarginBox.ScreenSpaceDrawQuad.TopLeft.Xy);
});
checkEventCount(click, 1);
checkEventCount(double_click, 1);
Expand All @@ -413,7 +413,7 @@ public void SeparateMouseDown()

AddStep("right down", () => InputManager.PressButton(MouseButton.Right));
checkEventCount(mouse_down, 1);
AddStep("move away", () => InputManager.MoveMouseTo(outerMarginBox.ScreenSpaceDrawQuad.TopLeft));
AddStep("move away", () => InputManager.MoveMouseTo(outerMarginBox.ScreenSpaceDrawQuad.TopLeft.Xy));
AddStep("left click", () => InputManager.Click(MouseButton.Left));
checkEventCount(mouse_down, 1, true);
checkEventCount(mouse_up, 1, true);
Expand Down
74 changes: 74 additions & 0 deletions osu.Framework.Tests/Visual/TestScenePerspectiveContainer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using System;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures;
using osuTK;

namespace osu.Framework.Tests.Visual
{
public partial class TestScenePerspectiveContainer : FrameworkTestScene
{
private readonly Container target;
private readonly Sprite sprite;

private float xRotation;
private float yRotation;
private float zRotation;

public TestScenePerspectiveContainer()
{
Add(target = new Container
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
Size = new Vector2(0.5f),
Child = sprite = new Sprite
{
RelativeSizeAxes = Axes.Both
}
});

AddSliderStep("X Rotation", -MathF.PI, MathF.PI, 0, v =>
{
xRotation = v;
updateRotation();
});

AddSliderStep("Y Rotation", -MathF.PI, MathF.PI, 0, v =>
{
yRotation = v;
updateRotation();
});

AddSliderStep("Z Rotation", -MathF.PI, MathF.PI, 0, v =>
{
zRotation = v;
updateRotation();
});

AddSliderStep("fov", 0, 90f, 45f, updateFov);
}

private void updateFov(float fov)
{
target.Camera = new Camera(fov, new Vector2(0.5f));
}

[BackgroundDependencyLoader]
private void load(TextureStore textures)
{
sprite.Texture = textures.Get(@"sample-texture");
}

private void updateRotation()
{
target.TransformTo(nameof(Rotation3D), new Quaternion(xRotation, yRotation, zRotation), 500, Easing.OutQuint);
}
}
}
12 changes: 6 additions & 6 deletions osu.Framework.Tests/Visual/UserInterface/TestSceneContextMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ private void clickOutsideStep()
{
AddStep("click outside", () =>
{
InputManager.MoveMouseTo(InputManager.ScreenSpaceDrawQuad.TopLeft);
InputManager.MoveMouseTo(InputManager.ScreenSpaceDrawQuad.TopLeft.Xy);
InputManager.Click(MouseButton.Right);
});
}
Expand All @@ -305,17 +305,17 @@ private void assertMenuState(bool opened)
=> AddAssert($"menu {(opened ? "opened" : "closed")}", () => (contextMenuContainer.CurrentMenu?.State == MenuState.Open) == opened);

private void assertMenuInCentre(Func<Drawable> getBoxFunc)
=> AddAssert("menu in centre of box", () => Precision.AlmostEquals(contextMenuContainer.CurrentMenu.ScreenSpaceDrawQuad.TopLeft, getBoxFunc().ScreenSpaceDrawQuad.Centre));
=> AddAssert("menu in centre of box", () => Precision.AlmostEquals(contextMenuContainer.CurrentMenu.ScreenSpaceDrawQuad.TopLeft.Xy, getBoxFunc().ScreenSpaceDrawQuad.Centre));

private void assertMenuOnScreen(bool expected) => AddAssert($"menu {(expected ? "on" : "off")} screen", () =>
{
var inputQuad = InputManager.ScreenSpaceDrawQuad;
var menuQuad = contextMenuContainer.CurrentMenu.ScreenSpaceDrawQuad;

bool result = inputQuad.Contains(menuQuad.TopLeft + new Vector2(1, 1))
&& inputQuad.Contains(menuQuad.TopRight + new Vector2(-1, 1))
&& inputQuad.Contains(menuQuad.BottomLeft + new Vector2(1, -1))
&& inputQuad.Contains(menuQuad.BottomRight + new Vector2(-1, -1));
bool result = inputQuad.Contains(menuQuad.TopLeft.Xy + new Vector2(1, 1))
&& inputQuad.Contains(menuQuad.TopRight.Xy + new Vector2(-1, 1))
&& inputQuad.Contains(menuQuad.BottomLeft.Xy + new Vector2(1, -1))
&& inputQuad.Contains(menuQuad.BottomRight.Xy + new Vector2(-1, -1));

return result == expected;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void TestClickDismiss()

AddStep("click outside", () =>
{
InputManager.MoveMouseTo(overlayContainer.ScreenSpaceDrawQuad.TopLeft - new Vector2(20));
InputManager.MoveMouseTo(overlayContainer.ScreenSpaceDrawQuad.TopLeft.Xy - new Vector2(20));
InputManager.PressButton(MouseButton.Left);
InputManager.ReleaseButton(MouseButton.Left);
});
Expand Down Expand Up @@ -85,7 +85,7 @@ public void TestPositionalBlocking(bool isBlocking)
parentContainer.MouseMoveReceived == initialMoveCount &&
parentContainer.HoverReceived == initialHoverCount);

AddStep("move outside", () => InputManager.MoveMouseTo(overlayContainer.ScreenSpaceDrawQuad.TopLeft - new Vector2(20)));
AddStep("move outside", () => InputManager.MoveMouseTo(overlayContainer.ScreenSpaceDrawQuad.TopLeft.Xy - new Vector2(20)));

// we block positional input screen-wide, therefore parent should still not receive input outside overlay's bounds.
AddAssert("move not received by parent", () =>
Expand All @@ -98,7 +98,7 @@ public void TestPositionalBlocking(bool isBlocking)
parentContainer.MouseMoveReceived == ++initialMoveCount &&
parentContainer.HoverReceived == ++initialHoverCount);

AddStep("move outside", () => InputManager.MoveMouseTo(overlayContainer.ScreenSpaceDrawQuad.TopLeft - new Vector2(20)));
AddStep("move outside", () => InputManager.MoveMouseTo(overlayContainer.ScreenSpaceDrawQuad.TopLeft.Xy - new Vector2(20)));

AddAssert("only move received by parent", () =>
parentContainer.MouseMoveReceived == ++initialMoveCount &&
Expand Down Expand Up @@ -142,7 +142,7 @@ public void TestScrollBlocking(bool isBlocking)

AddStep("scroll outside", () =>
{
InputManager.MoveMouseTo(overlayContainer.ScreenSpaceDrawQuad.TopLeft - new Vector2(20));
InputManager.MoveMouseTo(overlayContainer.ScreenSpaceDrawQuad.TopLeft.Xy - new Vector2(20));
InputManager.ScrollVerticalBy(1);
});

Expand Down
Loading
Loading