Camera2DScreenSpace FromPixelSpace Method (Vector2D)Delta Engine Documentation

Namespace: DeltaEngine.ScreenSpaces
Assembly: DeltaEngine (in DeltaEngine.dll) Version: 1.1.1.0 (1.1.1)
Syntax

public override Vector2D FromPixelSpace(
	Vector2D pixelPosition
)

Return Value

Type: Vector2D
Remarks

Tests: DeltaEngine.Tests.ScreenSpaces.Camera2DScreenSpaceTests
Examples

3 unit tests call DeltaEngine.ScreenSpaces.Camera2DScreenSpace.FromPixelSpace(DeltaEngine.Datatypes.Vector2D)
[Test]
public void IfCameraNotAdjustedItBehavesIdenticallyToQuadraticScreenSpace()
{
    var q = new QuadraticScreenSpace(window);
    var c = new Camera2DScreenSpace(window);
    Assert.IsTrue(
        c.FromPixelSpace(new Vector2D(1, 2)).IsNearlyEqual(q.FromPixelSpace(new Vector2D(1, 2))));
    Assert.IsTrue(
        c.FromPixelSpace(new Size(-3, 4)).IsNearlyEqual(q.FromPixelSpace(new Size(-3, 4))));
    Assert.IsTrue(
        c.ToPixelSpace(new Vector2D(2, 6)).IsNearlyEqual(q.ToPixelSpace(new Vector2D(2, 6))));
    Assert.IsTrue(c.ToPixelSpace(new Size(-2, 0)).IsNearlyEqual(q.ToPixelSpace(new Size(-2, 0))));
}
[Test]
public void LoopingToAndFromPixelSpaceLeavesAPointUnchanged()
{
    var camera = new Camera2DScreenSpace(window)
    {
        LookAt = new Vector2D(-0.5f, 0.6f),
        Zoom = 3.0f
    };
    Assert.IsTrue(
        camera.ToPixelSpace(camera.FromPixelSpace(new Vector2D(1.2f, 3.4f))).IsNearlyEqual(
            new Vector2D(1.2f, 3.4f)));
    Assert.IsTrue(
        camera.FromPixelSpace(camera.ToPixelSpace(new Vector2D(1.2f, 3.4f))).IsNearlyEqual(
            new Vector2D(1.2f, 3.4f)));
}
[Test]
public void FromPixelSpace()
{
    var camera = new Camera2DScreenSpace(window)
    {
        LookAt = new Vector2D(-0.5f, 0.6f),
        Zoom = 2.0f
    };
    Assert.IsTrue(
        camera.FromPixelSpace(Vector2D.Zero).IsNearlyEqual(new Vector2D(-0.75f, 0.459375f)));
    Assert.IsTrue(
        camera.FromPixelSpace((Vector2D)window.ViewportPixelSize).IsNearlyEqual(new Vector2D(
            -0.25f, 0.740625f)));
    Assert.AreEqual(camera.LookAt, camera.FromPixelSpace((Vector2D)window.ViewportPixelSize / 2));
}
See Also