예제 #1
0
        private void SubscribeToManagers(WorldObject worldObject)
        {
            if (worldObject is ICollidable)
            {
                CollisionManager.AddCollidable(worldObject as ICollidable);
            }
            else if (worldObject is IDrawManageable)
            {
                DrawManager.AddDrawable(worldObject as IDrawManageable);
            }

            // subscribe components recursively
            foreach (WorldObject wo in worldObject.GetComponents())
            {
                SubscribeToManagers(wo);
            }
        }
예제 #2
0
        private void UnsubscribeFromManagers(WorldObject worldObject)
        {
            if (worldObject is ICollidable)
            {
                CollisionManager.AddCollidable(worldObject as ICollidable);
            }
            else if (worldObject is IDrawManageable)
            {
                DrawManager.Remove(worldObject as IDrawManageable);
            }

            // unsubscribe the components recursively
            foreach (WorldObject wo in worldObject.GetComponents())
            {
                UnsubscribeFromManagers(wo);
            }
        }
        public void RayCastTest()
        {
            // Arrange
            var box = new Box2(new Vector2(5, 5), new Vector2(10, -5));
            var ray = new Ray(new Vector2(0, 1), Vector2.UnitX);
            var manager = new CollisionManager();

            var mock = new Mock<ICollidable>();
            mock.Setup(foo => foo.WorldAABB).Returns(box);
            manager.AddCollidable(mock.Object);

            // Act
            var result = manager.IntersectRay(ray);

            // Assert
            Assert.That(result.DidHitObject, Is.True);
            Assert.That(result.Distance, Is.EqualTo(5));
            Assert.That(result.HitPos.X, Is.EqualTo(5));
            Assert.That(result.HitPos.Y, Is.EqualTo(1));
        }