public void TestEqualsObject() { MPoint2 a = new MPoint2(5, 7); MPoint2 b = new MPoint2(5, 7); MPoint2 c = new MPoint2(4, 7); Assert.IsTrue(a.Equals((object)b)); Assert.IsFalse(a.Equals((object)c)); }
private void OnScreenSizeChanged(MPoint2 newScreenSize) { var v = this.ScreenSizeChanged; if(v != null) { v(this, new ScreenSizeChangedEventArgs(newScreenSize)); } }
public void TestEqualsVector() { MPoint2 a = new MPoint2(5, 7); MPoint2 b = new MPoint2(5, 7); MPoint2 c = new MPoint2(4, 7); Assert.IsTrue(a.Equals(b)); Assert.IsFalse(a.Equals(c)); }
/// <summary> /// Creates a new instance of <see cref="MouseInput"/>. /// </summary> public MouseInput() { this.heldTimeByButton = new Dictionary<MouseButton, double>(); this.previousButtons = new HashSet<MouseButton>(); this.currentScrollDirection = MouseScrollDirection.None; this.previousScrollValue = 0; this.mousePosition = new MPoint2(0, 0); }
public void SetScreenSize(MPoint2 size) { this.graphicsDeviceManager.PreferredBackBufferWidth = size.X; this.graphicsDeviceManager.PreferredBackBufferHeight = size.Y; this.ScreenSize = size; // TODO: Remove when PreparingDeviceSettings is received this.ScreenCenter = size / 2; // TODO: Remove when PreparingDeviceSettings is received this.graphicsDeviceManager.ApplyChanges(); this.OnScreenSizeChanged(size); }
public void TestConstructors() { int x = 27, y = -39; MPoint2 v = new MPoint2(x, y); Assert.AreEqual(v.X, x); Assert.AreEqual(v.Y, y); Vector2 xy = new Vector2(-57.28f, 23f); MPoint2 v2 = new MPoint2(xy); Assert.AreEqual(v2.X, (int)xy.X); Assert.AreEqual(v2.Y, (int)xy.Y); }
public void CellRectangle_CorrectNegative() { MPoint2 point = new MPoint2(-1, -2); MRectangle expected = new MRectangle(-cellSize, -2 * cellSize, cellSize, cellSize); Assert.AreEqual(expected, grid.CellRectangle(point)); }
public void TestTranslate() { MPoint2 orig = new MPoint2(-2, -3); Assert.AreEqual(orig, new MPoint2(2, 3).Translate(-4, -6)); Assert.AreEqual(orig.Translate(new MPoint2(1, -2)), orig.Translate(1, -2)); }
public void TestToMVector2() { int x = 23, y = -19; MPoint2 v = new MPoint2(x, y); Assert.AreEqual(new MVector2(x, y), v.ToMVector2()); }
public void SeparationVector_MPoint2_Outside_ZeroVector() { MCircle c1 = new MCircle(new MVector2(-300, 3), 2f); MPoint2 v = new MPoint2(0, 4); MVector2 separated = c1.SeparationVector(v); Assert.AreEqual(MVector2.Zero, separated); }
public void SeparationVector_MPoint2_Correct() { MCircle c1 = new MCircle(new MVector2(0, 3), 2f); MPoint2 v = new MPoint2(0, 4); MVector2 separated = c1.SeparationVector(v); MVector2 expected = new MVector2(0, -1); Assert.AreEqual(expected, separated); }
/// <summary> /// Returns the shortest vector to translate the <see cref="MCircle"/> with in order to separate from the provided <see cref="MPoint2"/>. /// </summary> /// <param name="point">The point to separate from.</param> /// <returns></returns> public MVector2 SeparationVector(MPoint2 point) => this.SeparationVector(new MCircle(point.ToMVector2(), 0));
public void CellFromPoint_CorrectPositive() { MVector2 point = new MVector2(5, 35); MPoint2 expected = new MPoint2(0, 1); Assert.AreEqual(expected, grid.CellFromPoint(point)); }
public void CellFromPoint_CorrectNegative() { MVector2 point = new MVector2(-5, -35); MPoint2 expected = new MPoint2(-1, -2); Assert.AreEqual(expected, grid.CellFromPoint(point)); }
/// <summary> /// Creates a new instance of <see cref="ScreenSizeChangedEventArgs"/>. /// </summary> /// <param name="newScreenSize">The new screen size.</param> public ScreenSizeChangedEventArgs(MPoint2 newScreenSize) { this.NewScreenSize = newScreenSize; }
/// <summary> /// Creates a new instance of <see cref="MouseInput"/> with the given screen size. /// </summary> /// <param name="screenSize"></param> public MouseInput(MPoint2 screenSize) : this() { this.ScreenSize = screenSize; }
/// <summary> /// Updates the component with the specified seconds since last update. /// </summary> /// <param name="seconds">The amount of seconds since last update.</param> public void Update(double seconds) { MouseState currentState = Mouse.GetState(); // Buttons this.previousButtons.Clear(); this.previousButtons.UnionWith(heldTimeByButton.Keys); this.UpdateButton(MouseButton.Left, currentState.LeftButton == ButtonState.Pressed, seconds); this.UpdateButton(MouseButton.Middle, currentState.MiddleButton == ButtonState.Pressed, seconds); this.UpdateButton(MouseButton.Right, currentState.RightButton == ButtonState.Pressed, seconds); this.UpdateButton(MouseButton.XButton1, currentState.XButton1 == ButtonState.Pressed, seconds); this.UpdateButton(MouseButton.XButton2, currentState.XButton2 == ButtonState.Pressed, seconds); // Scroll wheel if (currentState.ScrollWheelValue > previousScrollValue) { this.currentScrollDirection = MouseScrollDirection.Up; } else if (currentState.ScrollWheelValue < previousScrollValue) { this.currentScrollDirection = MouseScrollDirection.Down; } else { this.currentScrollDirection = MouseScrollDirection.None; } this.previousScrollValue = currentState.ScrollWheelValue; // Mouse position this.deltaPosition = this.mousePosition; if (this.VirtualMouseEnabled) { this.mousePosition += new MPoint2(currentState.X, currentState.Y); Mouse.SetPosition(this.ScreenSize.X / 2, ScreenSize.Y / 2); this.mousePosition = new MRectangleInt(ScreenSize.X, ScreenSize.Y).Clamp(this.mousePosition); } else { this.mousePosition = new MPoint2(currentState.X, currentState.Y); } this.deltaPosition = this.mousePosition - this.deltaPosition; }
/// <summary> /// Initiates a new instance of <see cref="Camera2D"/>. /// </summary> /// <param name="size">The <see cref="MPoint2"/> represenetation of the camera size.</param> public Camera2D(MPoint2 size) { this.size = size; }
public void TestLengthSquared() { MPoint2 v = new MPoint2(23, -19); Assert.AreEqual(v.Length(), Math.Sqrt(v.LengthSquared())); }
public void CellRectangle_CorrectPositive() { MPoint2 point = new MPoint2(0, 1); MRectangle expected = new MRectangle(0, cellSize, cellSize, cellSize); Assert.AreEqual(expected, grid.CellRectangle(point)); }
public void Separate_MPoint2_Separated() { MCircle c1 = new MCircle(new MVector2(-64, -64), 30f); MPoint2 v = new MPoint2(-50, -50); MCircle separated = c1.Separate(v); Assert.IsTrue(separated.SeparationVector(v) == MVector2.Zero); }
/// <summary> /// Separates the <see cref="MCircle"/> from the specified <see cref="MPoint2"/>, translating it with the shortest distance that makes them not intersect. /// </summary> /// <param name="point">The point to separate from.</param> /// <returns></returns> public MCircle Separate(MPoint2 point) => this.Translate(this.SeparationVector(point));