public FreeMovementRenderableAsset(IGraphicsContext context)
 {
     _texture = context.LoadTexture2D("freeMovementWidget");
     _boundingBox = new AxisAlignedBoundingBox2D(0, 0, _texture.Height, _texture.Width);
     RenderingOffset = -AABoundingBox.Center;
     Origin = AABoundingBox.Center;
 }
        public void BiggerRectangleIntersectsSmallerNonTouchingRectangle()
        {
            var bigger = new AxisAlignedBoundingBox2D(0.0f, 0.0f, 5.0f);
            var smaller = new AxisAlignedBoundingBox2D(1.0f, 1.0f, 2.0f);

            Assert.IsTrue(bigger.Intersects(smaller));
        }
        public void RectangleContainsAnotherSmallerOne()
        {
            var bigger = new AxisAlignedBoundingBox2D(0, 0, 5.0f);
            var smaller = new AxisAlignedBoundingBox2D(1.0f, 1.0f, 2.0f);

            Assert.IsTrue(bigger.Contains(smaller));
        }
 public RotateWidgetRenderableAsset(IGraphicsContext context)
 {
     _texture = context.LoadTexture2D("RotationWidget");
     _boundingBox = new AxisAlignedBoundingBox2D(0, 0, _texture.Height, _texture.Width);
     RenderingOffset = - _boundingBox.Center;
     Origin = _boundingBox.Center;
 }
        public void RectangleCombinationIsTheSameAsBoth()
        {
            var rec1 = new AxisAlignedBoundingBox2D(1.0f, 1.0f, 2.0f);
            var rec2 = new AxisAlignedBoundingBox2D(1.0f, 1.0f, 2.0f);
            var combined = rec1.Combine(rec2);

            Assert.IsTrue(combined.Equals(rec1));
            Assert.IsTrue(combined.Equals(rec2));
        }
        public void RectangleCombinationWithNonIntersectedRectangles()
        {
            var rec1 = new AxisAlignedBoundingBox2D(1.0f, 1.0f, 3.0f);
            var rec2 = new AxisAlignedBoundingBox2D(5.0f, 6.0f, 4.0f, 1.0f);
            var combined = rec1.Combine(rec2);

            Assert.AreEqual(10.0f, combined.Top);
            Assert.AreEqual(1.0f, combined.Left);
            Assert.AreEqual(1.0f, combined.Bottom);
            Assert.AreEqual(6.0f, combined.Right);
        }
        public void RectangleCombinationWithContainedRectangle()
        {
            var rec1 = new AxisAlignedBoundingBox2D(1.0f, 1.0f, 5.0f);
            var rec2 = new AxisAlignedBoundingBox2D(2.0f, 2.0f, 1.0f, 1.0f);
            var combined = rec1.Combine(rec2);

            Assert.AreEqual(6.0f, combined.Top);
            Assert.AreEqual(1.0f, combined.Left);
            Assert.AreEqual(1.0f, combined.Bottom);
            Assert.AreEqual(6.0f, combined.Right);
        }
 public TranslateWidgetRenderableAsset(IGraphicsContext context, TranslateArrowDirection direction)
 {
     if (direction == TranslateArrowDirection.Horizontal)
     {
         _texture = context.LoadTexture2D("ArrowHorizontal");
         RenderingOffset = - new Vector2(0, _texture.Height / 2);
     }
     else
     {
         _texture = context.LoadTexture2D("ArrowVertical");
         RenderingOffset = - new Vector2(_texture.Width / 2, 0);
     }
     _boundingBox = new AxisAlignedBoundingBox2D(0, 0, _texture.Height, _texture.Width);
 }
示例#9
0
        public void DataIsQueriableAsDesired()
        {
            var qtree = new Quadtree<BoundableDummy>();
            var dummy = new BoundableDummy(
                new AxisAlignedBoundingBox2D(10.0f, 10.0f, 20.0f)
                );

            qtree.Add(dummy);
            var searchBox = new AxisAlignedBoundingBox2D(0, 0, 50.0f);
            var hitCount = 0;
            Action<BoundableDummy> hitAction = (BoundableDummy) => hitCount++;

            qtree.Query(searchBox, hitAction);
            Assert.AreEqual(1, hitCount);
        }
        public static AxisAlignedBoundingBox2D Combine(this AxisAlignedBoundingBox2D rec1, AxisAlignedBoundingBox2D rec2)
        {
            float combinedTop, combinedBottom, combinedLeft, combinedRight;

            combinedTop = rec1.Top.BiggerOrEqualThan(rec2.Top);
            combinedBottom = rec1.Bottom.SmallerOrEqualThan(rec2.Bottom);
            combinedLeft = rec1.Left.SmallerOrEqualThan(rec2.Left);
            combinedRight = rec1.Right.BiggerOrEqualThan(rec2.Right);

            return new AxisAlignedBoundingBox2D(
                combinedLeft,
                combinedBottom,
                combinedTop - combinedBottom,
                combinedRight - combinedLeft
            );
        }
        public MoveWidgetRenderableAsset(IGraphicsContext context)
        {
            _verticalArrow = context.LoadTexture2D("ArrowVertical");
            _horizontalArrow = context.LoadTexture2D("ArrowHorizontal");
            _verticalArrowBox =
                new AxisAlignedBoundingBox2D(
                    -_verticalArrow.Width / 2,
                    0,
                    _verticalArrow.Height,
                    _verticalArrow.Width);

            _horizontalArrowBox =
                new AxisAlignedBoundingBox2D(
                    0,
                    -_horizontalArrow.Height / 2,
                    _horizontalArrow.Height,
                    _horizontalArrow.Width);
        }
示例#12
0
            public void Render(ITexture2D texture, Matrix transformation, AxisAlignedBoundingBox2D boundingBox)
            {
                var tex = _xnaGD._gContentManager.GetTexture(texture);
                var worldMatrixPreTransform = _xnaGD._basicEffect.World;

                _xnaGD._basicEffect.Texture = tex;
                _xnaGD._basicEffect.World *= transformation * RendererTransformation();
                _xnaGD._basicEffect.View = _xnaGD.ViewMatrix;
                _xnaGD._basicEffect.Projection = _xnaGD.ProjectionMatrix;

                foreach (var pass in _xnaGD._basicEffect.CurrentTechnique.Passes)
                {
                    pass.Apply();
                    _xnaGD._gd.DrawUserPrimitives(PrimitiveType.TriangleStrip, GetVerticesFor(boundingBox), 0, 2);
                }
                _xnaGD._basicEffect.World = worldMatrixPreTransform;
            }
        public void RectangleDoesntContainerABiggerTotallyOutside()
        {
            var rec1 = new AxisAlignedBoundingBox2D(1.0f, 1.0f, 5.0f);
            var rec2 = new AxisAlignedBoundingBox2D(0, 0, 10.0f);

            Assert.IsFalse(rec1.Contains(rec2));
        }
        public void RectangleDoesntContainAPointSomewhereOutside()
        {
            var rec = new AxisAlignedBoundingBox2D(1.0f, 1.0f, 5.0f);
            var point = new Vector2(0.0f, 0.0f);

            Assert.IsFalse(rec.Contains(point));
        }
        public bool Equals(AxisAlignedBoundingBox2D rec)
        {
            if (Top != rec.Top) return false;
            if (Bottom != rec.Bottom) return false;
            if (Left != rec.Left) return false;
            if (Right != rec.Right) return false;

            return true;
        }
 public bool Intersects(AxisAlignedBoundingBox2D rec)
 {
     if (ContainsAnyVerticesFrom(rec)) return true;
     if (rec.Contains(this)) return true;
     return false;
 }
        public void RectangleContainsAPointAsAVertice()
        {
            var rec = new AxisAlignedBoundingBox2D(1.0f, 1.0f, 5.0f);
            var point = new Vector2(1.0f, 1.0f);

            Assert.IsTrue(rec.Contains(point));
        }
 public bool ContainsAnyVerticesFrom(AxisAlignedBoundingBox2D rec)
 {
     if (Contains(rec.TopLeft)) return true;
     if (Contains(rec.TopRight)) return true;
     if (Contains(rec.BottomLeft)) return true;
     if (Contains(rec.BottomRight)) return true;
     return false;
 }
 public void Add(BoneAttachedRenderableAsset asset)
 {
     _renderables.Add(asset);
     _box = _renderables.Select(r => r.AABoundingBox).Combine();
     RaiseOnBoundingBoxChanges();
 }
        public void RectangleIntersectsTouchingRectangle()
        {
            var rec1 = new AxisAlignedBoundingBox2D(2.0f, 2.0f, 5.0f);
            var rec2 = new AxisAlignedBoundingBox2D(1.0f, 1.0f, 2.0f);

            Assert.IsTrue(rec1.Intersects(rec2));
        }
        public void RectanglesDontIntersectEachOther()
        {
            var rec1 = new AxisAlignedBoundingBox2D(10.0f, 10.0f, 5.0f);
            var rec2 = new AxisAlignedBoundingBox2D(1.0f, 1.0f, 2.0f);

            Assert.IsFalse(rec1.Intersects(rec2));
        }
示例#22
0
        public void QueryQuadtreeWithTwoDummiesAndObtainNone()
        {
            var qtree = new Quadtree<BoundableDummy>();
            var dummy1 = new BoundableDummy(
                new AxisAlignedBoundingBox2D(10.0f, 10.0f, 20.0f)
                );
            var dummy2 = new BoundableDummy(
                new AxisAlignedBoundingBox2D(100.0f, 100.0f, 20.0f)
                );

            qtree.Add(dummy1);
            qtree.Add(dummy2);
            var searchBox = new AxisAlignedBoundingBox2D(50.0f, 50.0f, 5.0f);
            var hitDummies = new List<BoundableDummy>();
            Action<BoundableDummy> hitAction = (bd) => hitDummies.Add(bd);

            qtree.Query(searchBox, hitAction);
            Assert.AreEqual(0, hitDummies.Count);
        }
示例#23
0
 public BoundableDummy(AxisAlignedBoundingBox2D boundingBox)
 {
     _boundingBox = boundingBox;
 }
        public void RectangleContainsAPointSomewhereInside()
        {
            var rec = new AxisAlignedBoundingBox2D(1.0f, 1.0f, 5.0f);
            var point = new Vector2(2.0f, 2.0f);

            Assert.IsTrue(rec.Contains(point));
        }
        protected void Render(IRenderer renderer, ITexture2D texture, AxisAlignedBoundingBox2D boundingBox)
        {
            if (!IsVisible) return;

            renderer.Render(texture, Transformation, boundingBox);
        }
示例#26
0
            private VertexPositionTexture[] GetVerticesFor(AxisAlignedBoundingBox2D boundingBox)
            {
                _vertices[0].Position.X = boundingBox.X;
                _vertices[0].Position.Y = boundingBox.Height;

                _vertices[1].Position.X = boundingBox.X;
                _vertices[1].Position.Y = boundingBox.Y;

                _vertices[2].Position.X = boundingBox.Width;
                _vertices[2].Position.Y = boundingBox.Height;

                _vertices[3].Position.X = boundingBox.Width;
                _vertices[3].Position.Y = boundingBox.Y;

                return _vertices;
            }
        public bool Contains(AxisAlignedBoundingBox2D rec)
        {
            var TopLeftCorner = new Vector2(rec.Left, rec.Top);
            if (!Contains(TopLeftCorner))
                return false;

            var BottomRightCorner = new Vector2(rec.Right, rec.Bottom);
            if (!Contains(BottomRightCorner))
                return false;

            return true;
        }
示例#28
0
 /*private void AssetOnBoundingBoxChangesHandler(IBoundingBoxable boundingBoxable)
 {
     UpdateBounds();
 }*/
 private void UpdateBounds()
 {
     var currentBox = _renderables.Select(r => r.AABoundingBox).Combine();
     if (currentBox.Equals(_box))
     {
         return;
     }
     _box = currentBox;
     RaiseBoundingBoxChanges();
 }
        public void RectangleContainsAnotherWithTheSameSize()
        {
            var rec1 = new AxisAlignedBoundingBox2D(0, 0, 5.0f);
            var rec2 = new AxisAlignedBoundingBox2D(0, 0, 5.0f);

            Assert.IsTrue(rec1.Contains(rec2));
        }