예제 #1
0
 /// <summary>
 ///     Actualiza la posicion e inclinacion del cilindro
 /// </summary>
 public void updateValues()
 {
     BoundingCylinder.Radius = FastMath.Max(
         FastMath.Abs(TopRadius), FastMath.Abs(BottomRadius));
     BoundingCylinder.updateValues();
     updateDraw();
 }
예제 #2
0
        /// <inheritdoc />
        public override void Initialize()
        {
            Game.Background = Color.CornflowerBlue;

            // Creates a Static Camera pointing to the center
            Camera = new StaticCamera(GraphicsDevice.Viewport.AspectRatio,
                                      Vector3.Forward * 100f + Vector3.Up * 100f,
                                      -Vector3.Normalize(Vector3.Forward + Vector3.Up),
                                      Vector3.Up);

            // Robot position and matrix initialization
            RobotPosition = Vector3.Zero;
            RobotWorld    = Matrix.CreateScale(0.3f);


            // Chair position and matrix initialization
            ChairAngle       = MathHelper.PiOver4;
            ChairScale       = Matrix.CreateScale(0.5f);
            ChairTranslation = Matrix.CreateTranslation(Vector3.UnitX * 50f);
            ChairWorld       = ChairScale * Matrix.CreateRotationY(ChairAngle) * ChairTranslation;

            // Tank position and matrix initialization
            TankPosition = -Vector3.UnitX * 10f + Vector3.UnitZ * 10f;
            TankWorld    = Matrix.CreateScale(3f) * Matrix.CreateTranslation(TankPosition);

            // Robot two position and matrix initialization
            var robotTwoPosition = Vector3.UnitX * -50f + Vector3.UnitZ * 10f;

            RobotTwoWorld    = Matrix.CreateScale(0.25f) * Matrix.CreateRotationY(MathHelper.PiOver4 + MathHelper.PiOver2) * Matrix.CreateTranslation(robotTwoPosition);
            RobotTwoCylinder = new BoundingCylinder(robotTwoPosition, 5f, 10f);

            base.Initialize();
        }
예제 #3
0
        public void BoundingCylinder_Ray_Test()
        {
            BoundingCylinder cyl = new BoundingCylinder (sideA: Vector3.Zero, sideB: Vector3.Up * 100, radius: 100f);
            Ray ray;
            ray = new Ray (position: new Vector3 (0, 0, 0), direction: Vector3.Up);
            Assert.IsNotNull (ray.Intersects (cyl));
            ray = new Ray (position: new Vector3 (0, 0, 0), direction: Vector3.Down);
            Assert.IsNotNull (ray.Intersects (cyl));

            ray = new Ray (position: new Vector3 (0, 0, 0), direction: Vector3.Forward);
            Assert.IsNotNull (ray.Intersects (cyl));
            ray = new Ray (position: new Vector3 (0, 0, 0), direction: Vector3.Left);
            Assert.IsNotNull (ray.Intersects (cyl));
            ray = new Ray (position: new Vector3 (0, -1, 0), direction: Vector3.Forward);
            Assert.IsNull (ray.Intersects (cyl));
            ray = new Ray (position: new Vector3 (0, -1, 0), direction: Vector3.Left);
            Assert.IsNull (ray.Intersects (cyl));

            // hier sollte eigentlich (0,100,0) auch noch drin sein, nicht nur (0,99,0),
            // also wie bei SideA!
            ray = new Ray (position: new Vector3 (0, 99, 0), direction: Vector3.Forward);
            Assert.IsNotNull (ray.Intersects (cyl));
            ray = new Ray (position: new Vector3 (0, 99, 0), direction: Vector3.Left);
            Assert.IsNotNull (ray.Intersects (cyl));
            ray = new Ray (position: new Vector3 (0, 101, 0), direction: Vector3.Forward);
            Assert.IsNull (ray.Intersects (cyl));
            ray = new Ray (position: new Vector3 (0, 101, 0), direction: Vector3.Left);
            Assert.IsNull (ray.Intersects (cyl));
        }
        public bool IntersectsAny(DrawableGameComponent component, Vector3 offset)
        {
            BoundingCylinder cylinder = component.GetBoundingCylinder();

            cylinder.Point += offset;

            return(vegetationList.Any(v => cylinder.Intersects(v.GetBoundingCylinder())));
        }
예제 #5
0
 public void Dispose()
 {
     if (texture != null)
     {
         texture.dispose();
     }
     sideTrianglesVertices = null;
     BoundingCylinder.Dispose();
 }
예제 #6
0
        public override BoundingCylinder GetBoundingCylinder()
        {
            BoundingCylinder cylinder = base.GetBoundingCylinder();

            cylinder.Point  += Vector3.Down * cylinder.Height;
            cylinder.Height *= 2;

            return(cylinder);
        }
예제 #7
0
        private bool CheckPigEscape(BoundingCylinder cylinder, float elapsed, Vector3 velocity)
        {
            BoundingCylinder pigCylinder = Pig.GetBoundingCylinder();

            BoundingCylinder newPigCylinder = pigCylinder;

            newPigCylinder.Point = Pig.Position + velocity * elapsed;

            return(cylinder.Contains(pigCylinder) && !cylinder.Contains(newPigCylinder));
        }
예제 #8
0
        private bool TestTerrainCollisionCylinder(Vector3 velocity, out Vector3 adjustedVelocity, List <ColoredBoundingBox> boxes)
        {
            adjustedVelocity = velocity;

            var testBox = GetAABBVelocityBox(velocity);

            var testCylinder = new BoundingCylinder(testBox.Min, testBox.Max,
                                                    Entity.Width / 2f);

            bool collision = false;

            for (int x = (int)(Math.Floor(testBox.Min.X)); x <= (int)(Math.Ceiling(testBox.Max.X)); x++)
            {
                for (int z = (int)(Math.Floor(testBox.Min.Z)); z <= (int)(Math.Ceiling(testBox.Max.Z)); z++)
                {
                    for (int y = (int)(Math.Floor(testBox.Min.Y)); y <= (int)(Math.Ceiling(testBox.Max.Y)); y++)
                    {
                        var blockState = Entity.Level.GetBlockState(x, y, z);
                        if (!blockState.Block.Solid)
                        {
                            continue;
                        }

                        var coords = new Vector3(x, y, z);

                        foreach (var box in blockState.Block.GetBoundingBoxes(coords))
                        {
                            if (testCylinder.Intersects(box))
                            {
                                if (testBox.Intersects(box))
                                {
                                    if (boxes != null)
                                    {
                                        boxes.Add(new ColoredBoundingBox(box, Color.Orange));
                                    }

                                    collision = true;

                                    AdjustVelocityForCollision(ref velocity, box);

                                    testBox      = GetAABBVelocityBox(velocity);
                                    testCylinder = new BoundingCylinder(
                                        testBox.Min, testBox.Max,
                                        Entity.Width / 2f);

                                    adjustedVelocity = velocity;
                                }
                            }
                        }
                    }
                }
            }

            return(collision);
        }
예제 #9
0
 public void TestIntersectsBox()
 {
     //   x
     //  /
     // x
     var cylinder = new BoundingCylinder(Vector3.Zero, Vector3.One * 10, 3);
     var doesNotIntersect = new BoundingBox(Vector3.One * 10 + 5, Vector3.One * 10 + 5);
     Assert.IsFalse(cylinder.Intersects(doesNotIntersect));
     var intersects = new BoundingBox(Vector3.Zero, Vector3.One);
     Assert.IsTrue(cylinder.Intersects(intersects));
 }
예제 #10
0
파일: Actor.cs 프로젝트: Doom2fan/PokesYou
 protected Actor()
 {
     maxHealth = health = 1000;
     prevPos   = bCylinder.Position = vel = Vector3k.Zero;
     speed     = angle = pitch = Accum.Zero;
     prevAngle = prevPitch = Accum.Zero;
     flags     = 0;
     gravity   = Accum.One;
     bCylinder = new BoundingCylinder(new Accum(16), new Accum(20), new Vector3k(Accum.Zero, Accum.Zero, Accum.Zero));
     cam       = new Camera();
 }
예제 #11
0
 public void TestIntersectsPoint()
 {
     //   x
     //  /
     // x
     var cylinder = new BoundingCylinder(Vector3.Zero, Vector3.One, 1);
     Assert.IsTrue(cylinder.Intersects(cylinder.Min));
     Assert.IsTrue(cylinder.Intersects(cylinder.Max));
     Assert.IsTrue(cylinder.Intersects(cylinder.Min + (Vector3.One / 2)));
     Assert.IsTrue(cylinder.Intersects(cylinder.Max - (Vector3.One / 2)));
     Assert.IsTrue(cylinder.Intersects(new Vector3(0.25, 0, 0)));
     Assert.IsFalse(cylinder.Intersects(new Vector3(5, 5, 5)));
 }
예제 #12
0
        public void TestIntersectsBox()
        {
            //   x
            //  /
            // x
            var cylinder         = new BoundingCylinder(Vector3.Zero, Vector3.One * 10, 3);
            var doesNotIntersect = new BoundingBox(Vector3.One * 10f + new Vector3(5, 5, 5), Vector3.One * 10f + new Vector3(5, 5, 5));

            Assert.IsFalse(cylinder.Intersects(doesNotIntersect));
            var intersects = new BoundingBox(Vector3.Zero, Vector3.One);

            Assert.IsTrue(cylinder.Intersects(intersects));
        }
예제 #13
0
        public void TestIntersectsPoint()
        {
            //   x
            //  /
            // x
            var cylinder = new BoundingCylinder(Vector3.Zero, Vector3.One, 1);

            Assert.IsTrue(cylinder.Intersects(cylinder.Min));
            Assert.IsTrue(cylinder.Intersects(cylinder.Max));
            Assert.IsTrue(cylinder.Intersects(cylinder.Min + Vector3.One / 2));
            Assert.IsTrue(cylinder.Intersects(cylinder.Max - Vector3.One / 2));
            Assert.IsTrue(cylinder.Intersects(new Vector3(0.25f, 0, 0)));
            Assert.IsFalse(cylinder.Intersects(new Vector3(5, 5, 5)));
        }
예제 #14
0
        public bool TestTerrainCollisionCylinder(Entity entity, out Vector3 collisionPoint)
        {
            collisionPoint = Vector3.Zero;
            var testBox      = GetAABBVelocityBox(entity);
            var testCylinder = new BoundingCylinder(testBox.Min, testBox.Max,
                                                    Vector3.Distance(entity.BoundingBox.Min, entity.BoundingBox.Max));

            bool collision = false;

            for (int x = (int)(Math.Floor(testBox.Min.X)); x <= (int)(Math.Ceiling(testBox.Max.X)); x++)
            {
                for (int z = (int)(Math.Floor(testBox.Min.Z)); z <= (int)(Math.Ceiling(testBox.Max.Z)); z++)
                {
                    for (int y = (int)(Math.Floor(testBox.Min.Y)); y <= (int)(Math.Ceiling(testBox.Max.Y)); y++)
                    {
                        var blockState = entity.Level.GetBlockState(x, y, z);
                        if (blockState?.Model == null || !blockState.Block.Solid)
                        {
                            continue;
                        }

                        var coords = new Vector3(x, y, z);

                        foreach (var box in blockState.Model.GetBoundingBoxes(coords))
                        {
                            if (testCylinder.Intersects(box))
                            {
                                if (testBox.Intersects(box))
                                {
                                    collision = true;
                                    AdjustVelocityForCollision(entity, box);
                                    testBox = GetAABBVelocityBox(entity);

                                    testCylinder = new BoundingCylinder(
                                        testBox.Min, testBox.Max,
                                        Vector3.Distance(entity.BoundingBox.Min, entity.BoundingBox.Max));

                                    collisionPoint = coords;
                                }
                            }
                        }
                    }
                }
            }
            return(collision);
        }
예제 #15
0
        public bool TestTerrainCollisionCylinder(IAABBEntity entity, out Vector3 collisionPoint)
        {
            collisionPoint = Vector3.Zero;
            var testBox      = GetAABBVelocityBox(entity);
            var testCylinder = new BoundingCylinder(testBox.Min, testBox.Max,
                                                    entity.BoundingBox.Min.DistanceTo(entity.BoundingBox.Max));

            var collision = false;

            for (var x = (int)Math.Floor(testBox.Min.X); x <= (int)Math.Ceiling(testBox.Max.X); x++)
            {
                for (var z = (int)Math.Floor(testBox.Min.Z); z <= (int)Math.Ceiling(testBox.Max.Z); z++)
                {
                    for (var y = (int)Math.Floor(testBox.Min.Y); y <= (int)Math.Ceiling(testBox.Max.Y); y++)
                    {
                        var coords = new Coordinates3D(x, y, z);
                        if (!World.IsValidPosition(coords))
                        {
                            continue;
                        }

                        var _box = BlockPhysicsProvider.GetBoundingBox(World, coords);
                        if (_box == null)
                        {
                            continue;
                        }

                        var box = _box.Value.OffsetBy(coords.AsVector3());
                        if (testCylinder.Intersects(box))
                        {
                            if (testBox.Intersects(box))
                            {
                                collision = true;
                                AdjustVelocityForCollision(entity, box);
                                testBox      = GetAABBVelocityBox(entity);
                                testCylinder = new BoundingCylinder(testBox.Min, testBox.Max,
                                                                    entity.BoundingBox.Min.DistanceTo(entity.BoundingBox.Max));
                                collisionPoint = coords.AsVector3();
                            }
                        }
                    }
                }
            }

            return(collision);
        }
예제 #16
0
        /// <inheritdoc />
        public override void Initialize()
        {
            Game.Background = Color.Black;


            // Robot position and matrix initialization
            RobotPosition = Vector3.UnitX * 30f;
            RobotScale    = Matrix.CreateScale(0.3f);
            RobotRotation = Matrix.Identity;

            // Create the BoundingCylinder enclosing the Robot
            RobotCylinder = new BoundingCylinder(RobotPosition, 10f, 20f);

            // Create the Camera
            Camera = new TargetCamera(GraphicsDevice.Viewport.AspectRatio, Vector3.One * 100f, Vector3.Zero);

            // Create the Matrices for drawing the Floor and Walls
            FloorWorld        = Matrix.CreateScale(200f);
            WallWorldMatrices = new Matrix[5];
            var scale = new Vector3(200f, 1f, 200f);

            WallWorldMatrices[0] = Matrix.CreateScale(scale) * Matrix.CreateRotationX(MathHelper.PiOver2) * Matrix.CreateTranslation(-Vector3.UnitZ * 200f + Vector3.UnitY * 200f);
            WallWorldMatrices[1] = Matrix.CreateScale(scale) * Matrix.CreateRotationX(-MathHelper.PiOver2) * Matrix.CreateTranslation(Vector3.UnitZ * 200f + Vector3.UnitY * 200f);
            WallWorldMatrices[2] = Matrix.CreateScale(scale) * Matrix.CreateRotationZ(MathHelper.PiOver2) * Matrix.CreateTranslation(Vector3.UnitX * 200f + Vector3.UnitY * 200f);
            WallWorldMatrices[3] = Matrix.CreateScale(scale) * Matrix.CreateRotationZ(-MathHelper.PiOver2) * Matrix.CreateTranslation(-Vector3.UnitX * 200f + Vector3.UnitY * 200f);
            WallWorldMatrices[4] = Matrix.CreateScale(new Vector3(100f, 1f, 100f)) * Matrix.CreateRotationZ(MathHelper.PiOver2) * Matrix.CreateTranslation(Vector3.UnitZ * 100f + Vector3.UnitY * 100f);


            // Create Bounding Boxes to enclose the Walls,
            // and to test the Robot and Camera against them
            WallBoxes = new BoundingBox[5];

            var minVector = Vector3.One * 0.25f;

            WallBoxes[0] = new BoundingBox(new Vector3(-200f, 0f, -200f) - minVector, new Vector3(200f, 200f, -200f) + minVector);
            WallBoxes[1] = new BoundingBox(new Vector3(-200f, 0f, 200f) - minVector, new Vector3(200f, 200f, 200f) + minVector);
            WallBoxes[2] = new BoundingBox(new Vector3(200f, 0f, -200f) - minVector, new Vector3(200f, 200f, 200f) + minVector);
            WallBoxes[3] = new BoundingBox(new Vector3(-200f, 0f, -200f) - minVector, new Vector3(-200f, 200f, 200f) + minVector);
            WallBoxes[4] = new BoundingBox(new Vector3(0f, 0f, 0f) - minVector, new Vector3(0f, 200f, 200f) + minVector);


            base.Initialize();
        }
예제 #17
0
        public bool TestTerrainCollisionCylinder(IAABBEntity entity, out Vector3 collisionPoint)
        {
            collisionPoint = Vector3.Zero;
            var testBox = GetAABBVelocityBox(entity);
            var testCylinder = new BoundingCylinder(testBox.Min, testBox.Max,
                entity.BoundingBox.Min.DistanceTo(entity.BoundingBox.Max));

            bool collision = false;
            for (int x = (int)(Math.Floor(testBox.Min.X)); x <= (int)(Math.Ceiling(testBox.Max.X)); x++)
            {
                for (int z = (int)(Math.Floor(testBox.Min.Z)); z <= (int)(Math.Ceiling(testBox.Max.Z)); z++)
                {
                    for (int y = (int)(Math.Floor(testBox.Min.Y)); y <= (int)(Math.Ceiling(testBox.Max.Y)); y++)
                    {
                        var coords = new Coordinates3D(x, y, z);
                        if (!World.IsValidPosition(coords))
                            continue;

                        var _box = BlockPhysicsProvider.GetBoundingBox(World, coords);
                        if (_box == null)
                            continue;

                        var box = _box.Value.OffsetBy(coords);
                        if (testCylinder.Intersects(box))
                        {
                            if (testBox.Intersects(box))
                            {
                                collision = true;
                                AdjustVelocityForCollision(entity, box);
                                testBox = GetAABBVelocityBox(entity);
                                testCylinder = new BoundingCylinder(testBox.Min, testBox.Max,
                                    entity.BoundingBox.Min.DistanceTo(entity.BoundingBox.Max));
                                collisionPoint = coords;
                            }
                        }
                    }
                }
            }
            return collision;
        }
예제 #18
0
        public void BoundingCylinder_Equals_Test()
        {
            BoundingCylinder cyl1 = new BoundingCylinder (sideA: Vector3.Zero, sideB: Vector3.Up * 100, radius: 100f);
            BoundingCylinder cyl2 = new BoundingCylinder (sideA: Vector3.Up * 100, sideB: Vector3.Zero, radius: 100f);
            IsEqual (cyl1, cyl1);
            IsEqual (cyl1, cyl2);
            IsEqual (cyl2, cyl1);

            BoundingCylinder cyl3 = new BoundingCylinder (sideA: Vector3.Up * 100, sideB: Vector3.Zero, radius: 200f);
            IsNotEqual (cyl1, cyl3);
            IsNotEqual (cyl2, cyl3);
            IsNotEqual (cyl3, cyl1);
            IsNotEqual (cyl3, cyl2);

            BoundingCylinder cyl4 = new BoundingCylinder (sideA: Vector3.Up * 50, sideB: Vector3.Down * 50, radius: 100f);
            IsNotEqual (cyl1, cyl4);
            IsNotEqual (cyl2, cyl4);
            IsNotEqual (cyl4, cyl1);
            IsNotEqual (cyl4, cyl2);

            Assert.IsTrue (cyl1.Equals ((object)cyl1));
            Assert.IsFalse (cyl1.Equals ((object)cyl4));
            Assert.IsFalse (cyl1.Equals ((object)null));
        }
예제 #19
0
 public void Move(float x, float y, float z)
 {
     BoundingCylinder.move(x, y, z);
 }
예제 #20
0
 public void Move(TGCVector3 v)
 {
     BoundingCylinder.move(v);
 }
예제 #21
0
        /// <inheritdoc />
        public override void Initialize()
        {
            Game.Background = Color.Black;

            // Set the ground flag to false, as the Robot starts in the air
            OnGround = false;

            // Robot position and matrix initialization
            RobotPosition = Vector3.UnitX * 30f;
            RobotScale    = Matrix.CreateScale(0.3f);

            RobotCylinder       = new BoundingCylinder(RobotPosition, 10f, 15f);
            RobotRotation       = Matrix.Identity;
            RobotFrontDirection = Vector3.Backward;

            // Create the Camera
            Camera = new TargetCamera(GraphicsDevice.Viewport.AspectRatio, Vector3.One * 100f, Vector3.Zero);

            // Create World matrices for our stairs
            StairsWorld = new Matrix[]
            {
                Matrix.CreateScale(70f, 6f, 15f) * Matrix.CreateTranslation(0f, 3f, 125f),
                Matrix.CreateScale(70f, 6f, 15f) * Matrix.CreateTranslation(0f, 9f, 140f),
                Matrix.CreateScale(70f, 6f, 15f) * Matrix.CreateTranslation(0f, 15f, 155f),
                Matrix.CreateScale(70f, 6f, 40f) * Matrix.CreateTranslation(0f, 21f, 182.5f),
                Matrix.CreateScale(15f, 6f, 40f) * Matrix.CreateTranslation(-42.5f, 27f, 182.5f),
                Matrix.CreateScale(15f, 6f, 40f) * Matrix.CreateTranslation(-57.5f, 33f, 182.5f),
                Matrix.CreateScale(15f, 6f, 40f) * Matrix.CreateTranslation(-72.5f, 39f, 182.5f),
                Matrix.CreateScale(100f, 6f, 100f) * Matrix.CreateTranslation(-130f, 45f, 152.5f),
            };

            // Create World matrices for the Floor and Box
            FloorWorld = Matrix.CreateScale(200f, 0.001f, 200f);
            BoxWorld   = Matrix.CreateScale(30f) * Matrix.CreateTranslation(85f, 15f, -15f);

            // Create Bounding Boxes for the static geometries
            // Stairs + Floor + Box
            Colliders = new BoundingBox[StairsWorld.Length + 2];

            // Instantiate Bounding Boxes for the stairs
            int index = 0;

            for (; index < StairsWorld.Length; index++)
            {
                Colliders[index] = BoundingVolumesExtensions.FromMatrix(StairsWorld[index]);
            }

            // Instantiate a BoundingBox for the Box
            Colliders[index] = BoundingVolumesExtensions.FromMatrix(BoxWorld);
            index++;
            // Instantiate a BoundingBox for the Floor. Note that the height is almost zero
            Colliders[index] = new BoundingBox(new Vector3(-200f, -0.001f, -200f), new Vector3(200f, 0f, 200f));

            // Set the Acceleration (which in this case won't change) to the Gravity pointing down
            RobotAcceleration = Vector3.Down * Gravity;

            // Initialize the Velocity as zero
            RobotVelocity = Vector3.Zero;


            base.Initialize();
        }
예제 #22
0
 public static float? Intersects(this Ray ray, BoundingCylinder cylinder)
 {
     Vector3 dirAB = cylinder.SideB - cylinder.SideA;
     // Raystart innerhalb des Zylinders
     if (Vector3.Cross ((ray.Position - cylinder.SideA), ray.Direction).Length () < cylinder.Radius && !(Vector3.Dot (dirAB, ray.Position - cylinder.SideA) < 0 || Vector3.Dot (dirAB, cylinder.SideB - ray.Position) < 0)) {
         return 0.0f;
     }
     Vector3 perpendicular = Vector3.Cross (dirAB, ray.Direction);
     // if !(Ray Parallel zum Zylinder)
     if (perpendicular.Length () > 0.0000001f) {
         perpendicular.Normalize ();
         if (Vector3.Dot (perpendicular, ray.Direction) > 0) {
             perpendicular = -perpendicular;
         }
         Vector3 perpendicular2 = Vector3.Cross (dirAB, perpendicular);
         // If (Ray Senkrecht zum Zylinder)
         if (perpendicular2.Length () < 0.0000001f) {
             if (Vector3.Dot (dirAB, ray.Position - cylinder.SideA) < 0 || Vector3.Dot (dirAB, cylinder.SideB - ray.Position) < 0) {
                 return null;
             }
             float? result = Vector3.Cross ((ray.Position - cylinder.SideA), ray.Direction).Length () - cylinder.Radius;
             if (result < 0) {
                 result = 0.0f;
             }
             return result;
         }
         if (Vector3.Dot (perpendicular2, ray.Direction) > 0) {
             perpendicular2 = -perpendicular2;
         }
         perpendicular2.Normalize ();
         float minDist = System.Math.Abs (Vector3.Dot (cylinder.SideA - ray.Position, perpendicular));
         if (minDist > cylinder.Radius) {
             return null;
         }
         Vector3 plainNorm = perpendicular * minDist + (float)System.Math.Sqrt (cylinder.Radius * cylinder.Radius - minDist * minDist) * perpendicular2;
         plainNorm.Normalize ();
         float? other_result = ray.Intersects (new Plane (plainNorm, Vector3.Dot (plainNorm, cylinder.SideA + plainNorm * cylinder.Radius)));
         if (other_result == null) {
             return null;
         }
         Vector3 cutA = ray.Position + ray.Direction * (float)other_result - cylinder.SideA;
         Vector3 cutB = ray.Position + ray.Direction * (float)other_result - cylinder.SideB;
         if (Vector3.Dot (dirAB, cutA) > 0 && Vector3.Dot (-dirAB, cutB) > 0) {
             return other_result;
         }
     }
     if (Vector3.Distance (ray.Position, cylinder.SideA) < Vector3.Distance (ray.Position, cylinder.SideB)) {
         dirAB.Normalize ();
         float? result = ray.Intersects (new Plane (dirAB, Vector3.Dot (dirAB, cylinder.SideA)));
         if (result == null || Vector3.Distance (ray.Position + ray.Direction * (float)result, cylinder.SideA) > cylinder.Radius) {
             return null;
         }
         return result;
     }
     else {
         dirAB.Normalize ();
         dirAB = -dirAB;
         float? result = ray.Intersects (new Plane (dirAB, Vector3.Dot (dirAB, cylinder.SideB)));
         if (result == null || Vector3.Distance (ray.Position + ray.Direction * (float)result, cylinder.SideB) > cylinder.Radius) {
             return null;
         }
         return result;
     }
     /*
     Vector3 diffA = capsule.CornerA - ray.Position;
     Vector3 diffB = capsule.CornerB - ray.Position;
     float diffASquared = diffA.LengthSquared ();
     float diffBSquared = diffB.LengthSquared ();
     float radiusSquared = capsule.Radius * capsule.Radius;
     // Startpunkt innerhalb der Eckkugeln
     if (diffASquared < radiusSquared || diffBSquared < radiusSquared)
     {
         return 0.0f;
     }
     Vector3 dirBA = (capsule.CornerA - capsule.CornerB);
     float distAlongAB = Vector3.Dot (diffA, dirBA) / dirBA.Length ();
     // Startpunkt innerhalb des Zylinders
     if (distAlongAB > 0 && distAlongAB < dirBA.Length () && (distAlongAB * distAlongAB + radiusSquared - diffA.LengthSquared () < 0))
     {
         return 0.0f;
     }
     float distAlongRayA = Vector3.Dot (ray.Direction, diffA);
     float distAlongRayB = Vector3.Dot (ray.Direction, diffB);
     // Richtung geht weg von der Kapsel
     if (distAlongRayA < 0 && distAlongRayB < 0)
         return null;
     Vector3 perpendicular = Vector3.Cross (ray.Direction, dirBA);
     perpendicular.Normalize ();
     float minDistance = Math.Abs (Vector3.Dot (diffA, perpendicular));
     // Kommt selbst der Geraden nie nahe genug.
     if (minDistance > capsule.Radius)
     {
         return null;
     }
     Vector3 normDirAB = -dirBA;
     normDirAB.Normalize ();
     Vector3 extensionToBase = Vector3.Cross (normDirAB, perpendicular);
     extensionToBase.Normalize ();
     Matrix transformation = new Matrix (normDirAB.X, normDirAB.Y, normDirAB.Z, 0, perpendicular.X, perpendicular.Y, perpendicular.Z, 0, extensionToBase.X, extensionToBase.Y, extensionToBase.Z, 0, capsule.CornerA.X, capsule.CornerA.Y, capsule.CornerA.Z, 1);
     transformation = Matrix.Invert (transformation);
      */
 }
예제 #23
0
 private void IsEqual(BoundingCylinder a, BoundingCylinder b)
 {
     Assert.IsTrue (a.Equals (b));
     Assert.IsTrue (a == b);
 }
예제 #24
0
 private void IsNotEqual(BoundingCylinder a, BoundingCylinder b)
 {
     Assert.IsTrue (!a.Equals (b));
     Assert.IsTrue (a != b);
 }
예제 #25
0
 public void rotateY(float angle)
 {
     BoundingCylinder.rotateY(angle);
 }
예제 #26
0
 public void RotateZ(float angle)
 {
     BoundingCylinder.rotateZ(angle);
 }
예제 #27
0
 /// <summary>
 /// Adds a cylinder obstacle
 /// </summary>
 /// <param name="cylinder">Bounding Cylinder</param>
 /// <returns>Returns the obstacle id</returns>
 public int AddObstacle(BoundingCylinder cylinder)
 {
     return(-1);
 }
예제 #28
0
        public void Start()
        {
            string ip = ((IPEndPoint)Socket.RemoteEndPoint).Address.ToString();

            Console.WriteLine("Client connected from {0}", ip);

            var packet = new NetworkPacket();

            Vector3 leprechaunPosition = Server.Terrain.GetHeight(Config.PlayerPositions[PlayerId]);

            try
            {
                Send(new NetworkPacketWelcome(PlayerId, Config.PlayerColors[PlayerId], leprechaunPosition, Config.RainbowPositions[PlayerId]));

                Server.ItemsManager.SendAll(this);
                Server.TrapManager.AddPlayer(this);

                const float goldpotRadius = Config.GoldpotCylinderRadius * Config.GoldpotScale;
                const float goldpotHeight = Config.GoldpotCylinderHeight * Config.GoldpotScale;

                Rainbow = new BoundingCylinder(Config.RainbowCylinderRadius, Config.RainbowCylinderHeight, Config.RainbowPositions[PlayerId]);
                Goldpot = new BoundingCylinder(goldpotRadius, goldpotHeight, Config.GoldpotPosition);

                var buffer = new byte[Config.BufferSize];

                while (true)
                {
                    if (Socket.Receive(buffer, 1, SocketFlags.None) == 0)
                    {
                        return;
                    }

                    packet.Type = buffer[0];

                    if (Socket.Receive(buffer, 1, SocketFlags.None) == 0)
                    {
                        return;
                    }

                    packet.Size = buffer[0];

                    int received = 0;

                    while (received < packet.Size)
                    {
                        int count;

                        if ((count = Socket.Receive(packet.Data, received, packet.Size - received, SocketFlags.None)) == 0)
                        {
                            return;
                        }

                        received += count;
                    }

                    ProcessPacket(packet);

                    Server.Send(packet, this);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                Console.WriteLine("Client disconnected from {0}", ip);

                Server.OnClientFinish(this);
            }
        }
예제 #29
0
 public void move(Vector3 v)
 {
     BoundingCylinder.move(v);
 }