//public void draw(MVector3 pos, MRectangle srcRect, MVector2 scale, // MVector2 translate, MVector3 drawCenter, float angle, MVector4 color) public static void draw(int textureID, int pos, int srcRect, int scale, int translate, int drawCenter, float angle, int color) { //m_graphicHandlerRef.getSpriteBatch().Draw(m_texture, m_graphicHandlerRef.getGameInstance().Window.ClientBounds, Color.White); Rectangle? rect; MRectangle trueRect = MRectangle.getFromStorage(srcRect); if (trueRect != null) { rect = trueRect.getRawData(); } else { rect = null; } Vector2 scaleParam = MVector2.getFromStorage(scale).getRawData(); SpriteEffects sEffect = generateSpriteEffect(ref scaleParam); Vector2 translateParam = MVector3.getFromStorage(pos).getRawAxistedVec2() + MVector2.getFromStorage(translate).getRawData(); m_graphicHandlerRef.getSpriteBatch() .Draw( MTexture.getFromStorage(textureID).m_texture, translateParam, rect, MVector4.getFromStorage(color).getColor(), angle, MVector3.getFromStorage(drawCenter).getRawVec2(), scaleParam, sEffect, 0.0f); }
public void TestClosestPoint() { float distance; MVector2 point = new MVector2(-5, 5); MVector2[] points = new MVector2[] { new MVector2(100, 100), new MVector2(0,0), new MVector2(-1,3), new MVector2(-101, -100), new MVector2(float.MaxValue, float.MaxValue), new MVector2(float.MinValue, float.MinValue) }; MVector2 expected = new MVector2(-1, 3); Assert.AreEqual(expected, point.ClosestPoint(points)); Assert.AreEqual(point.ClosestPoint(points), point.ClosestPoint(points, out distance)); Assert.AreEqual((float)(point - expected).Length(), distance); }
public void SeparationVector_MVector2_Correct() { MCircle c1 = new MCircle(new MVector2(0, 3), 2f); MVector2 v = new MVector2(0, 4); MVector2 separated = c1.SeparationVector(v); MVector2 expected = new MVector2(0, -1); Assert.AreEqual(expected, separated); }
public void SeparationVector_Circle_Correct() { MCircle c1 = new MCircle(new MVector2(0, 3), 2f); MCircle c2 = new MCircle(new MVector2(0, 2), 1f); MVector2 v = c1.SeparationVector(c2); MVector2 expected = new MVector2(0, 2); Assert.AreEqual(expected, v); }
public void Separate_MVector2_Separated() { MCircle c1 = new MCircle(new MVector2(-64, -64), 30f); MVector2 v = new MVector2(-50, -50); MCircle separated = c1.Separate(v); Assert.IsTrue(separated.SeparationVector(v) == MVector2.Zero); }
public void CellFromPoint_CorrectPositive() { MVector2 point = new MVector2(5, 35); MPoint2 expected = new MPoint2(0, 1); Assert.AreEqual(expected, grid.CellFromPoint(point)); }
/// <summary> /// Returns the shortest vector to translate the <see cref="MCircle"/> with in order to separate from the provided <see cref="MRectangle"/>. /// </summary> /// <param name="rectangle">The rectangle to separate from.</param> /// <returns></returns> public MVector2 SeparationVector(MRectangle rectangle) { MVector2 left = new MVector2(rectangle.TopLeft.X - (this.Origin.X + this.Radius), 0); MVector2 right = new MVector2(rectangle.BottomRight.X - (this.Origin.X - this.Radius), 0); MVector2 up = new MVector2(0, rectangle.TopLeft.Y - (this.Origin.Y + this.Radius)); MVector2 down = new MVector2(0, rectangle.BottomRight.Y - (this.Origin.Y - this.Radius)); if (left.X < 0 && right.X > 0 || up.Y < 0 && down.Y > 0) { MVector2 shortest = new MVector2(float.MaxValue, float.MaxValue); if (this.Origin.X < rectangle.Left && this.Origin.Y < rectangle.Top) { shortest = this.SeparationVector(rectangle.TopLeft); } else if (this.Origin.X > rectangle.Right && this.Origin.Y < rectangle.Top) { shortest = this.SeparationVector(rectangle.TopRight); } else if (this.Origin.X < rectangle.Left && this.Origin.Y > rectangle.Bottom) { shortest = this.SeparationVector(rectangle.BottomLeft); } else if (this.Origin.X > rectangle.Right && this.Origin.Y > rectangle.Bottom) { shortest = this.SeparationVector(rectangle.BottomRight); } if (left.X < 0 && left.LengthSquared() < shortest.LengthSquared()) { shortest = left; } if (right.X > 0 && right.LengthSquared() < shortest.LengthSquared()) { shortest = right; } if (up.Y < 0 && up.LengthSquared() < shortest.LengthSquared()) { shortest = up; } if (down.Y > 0 && down.LengthSquared() < shortest.LengthSquared()) { shortest = down; } return shortest; } return MVector2.Zero; }
public void MoveTo_Correct() { MCircle c = new MCircle(new MVector2(-64, -64), 30f); MVector2 position = new MVector2(-32, -32); Assert.AreEqual(new MCircle(position, c.Radius), c.MoveTo(position)); }
public void SeparationVector_Rectangle_Up_Correct() { MCircle c = new MCircle(new MVector2(0, 0), 2f); MRectangle r = new MRectangle(-32, 1, 64, 1); MVector2 sepVector = c.SeparationVector(r); MVector2 expected = new MVector2(0, -1); Assert.AreEqual(expected, sepVector); }
/// <summary> /// Moves the <see cref="MCircle"/> origin to the specified position. /// </summary> /// <param name="position">The position to move to.</param> /// <returns></returns> public MCircle MoveTo(MVector2 position) => new MCircle(position, this.Radius);
/// <summary> /// Determines whether the <see cref="MCircle"/> contains the specified <see cref="MVector2"/> coordinate. /// </summary> /// <param name="coordinate">The coordinate.</param> /// <returns>True if the coordinate is contained; otherwise false.</returns> public bool Contains(MVector2 coordinate) => (coordinate - this.Origin).LengthSquared() <= this.Radius * this.Radius;
/// <summary> /// Initializes a new instance of the <see cref="MCircle" /> struct. /// </summary> /// <param name="origin">The circle origin.</param> /// <param name="radius">The circle radius.</param> public MCircle(MVector2 origin, float radius) { this.Origin = origin; this.Radius = radius < 0f ? -radius : radius; }
/// <summary> /// Translates the <see cref="MCircle"/> with the specified translation. /// </summary> /// <param name="translation">The translation to perform.</param> /// <returns></returns> public MCircle Translate(MVector2 translation) => new MCircle(this.Origin.Translate(translation), this.Radius);
/// <summary> /// Returns the shortest vector to translate the <see cref="MCircle"/> with in order to separate from the provided <see cref="MVector2"/>. /// </summary> /// <param name="point">The point to separate from.</param> /// <returns></returns> public MVector2 SeparationVector(MVector2 point) => this.SeparationVector(new MCircle(point, 0));
public void SeparationVector_MVector2_Outside_ZeroVector() { MCircle c1 = new MCircle(new MVector2(0, 300), 2f); MVector2 v = new MVector2(0, 4); MVector2 separated = c1.SeparationVector(v); Assert.AreEqual(MVector2.Zero, separated); }
public void SeparationVector_Rectangle_Right_Correct() { MCircle c = new MCircle(new MVector2(3, 0), 2f); MRectangle r = new MRectangle(1, -32, 1, 64); MVector2 sepVector = c.SeparationVector(r); MVector2 expected = new MVector2(1, 0); Assert.AreEqual(expected, sepVector); }
/// <summary> /// Sets the current camera center position to the given coordinate. /// </summary> /// <param name="position">The Vector2 coordinate to set to.</param> public void SetPosition(Vector2 position) { this.position = position; this.matrixNeedsUpdate = true; }
public void Translate_Correct() { MCircle c = new MCircle(new MVector2(-64, -64), 30f); MVector2 translation = new MVector2(-32, -32); Assert.AreEqual(new MCircle(c.Origin + translation, c.Radius), c.Translate(translation)); }
/// <summary> /// Inversely transforms a given coordinate, effectively untransforming camera space to world space. /// </summary> /// <param name="coordinate">The coordinate to transform.</param> /// <returns>Transformed coordinate.</returns> public Vector2 TransformInv(MVector2 coordinate) { return Vector2.Transform(coordinate, transformMatrixInv); }
public void CellFromPoint_CorrectNegative() { MVector2 point = new MVector2(-5, -35); MPoint2 expected = new MPoint2(-1, -2); Assert.AreEqual(expected, grid.CellFromPoint(point)); }
/// <summary> /// Separates the <see cref="MCircle"/> from the specified <see cref="MVector2"/>, 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(MVector2 point) => this.Translate(this.SeparationVector(point));