Exemplo n.º 1
0
        public void DrawDebug(GameTime gameTime, GraphicsDeviceManager graphics)
        {
            short[] indexes = new short[24]
            {
                0, 1, 1, 2, 2, 3, 3, 0,
                4, 5, 5, 6, 6, 7, 7, 4,
                0, 4, 1, 5, 2, 6, 3, 7
            };

            Bounding_Volumes.BoundingBox box = (bound as Bounding_Volumes.BoundingBox);
            if (box != null)
            {
                Vector3[] corners = box.Corners();

                VertexPositionColor[] vertices = new VertexPositionColor[8];
                for (int j = 0; j < 8; ++j)
                {
                    vertices[j] = new VertexPositionColor(corners[j], Color.Green);
                }

                graphics.GraphicsDevice.DrawUserIndexedPrimitives(PrimitiveType.LineList, vertices, 0, 8, indexes, 0, 12);
            }
        }
Exemplo n.º 2
0
        private float?IntersectBox(Bounding_Volumes.BoundingBox bound)
        {
            float tfirst = 0.0f, tlast = Length;

            Plane[] planes = new Plane[3]
            {
                bound.RightFace(), bound.UpFace(), bound.BackFace()
            };
            Vector3[] corners = bound.Corners();

            if (!RaySlabIntersect(Vector3.Dot(StartPosition, planes[0].Normal),
                                  Vector3.Dot(Direction, planes[0].Normal),
                                  Vector3.Dot(corners[1], planes[0].Normal),
                                  Vector3.Dot(corners[0], planes[0].Normal),
                                  ref tfirst, ref tlast))
            {
                return(null);
            }
            if (!RaySlabIntersect(Vector3.Dot(StartPosition, planes[1].Normal),
                                  Vector3.Dot(Direction, planes[1].Normal),
                                  Vector3.Dot(corners[3], planes[1].Normal),
                                  Vector3.Dot(corners[0], planes[1].Normal),
                                  ref tfirst, ref tlast))
            {
                return(null);
            }
            if (!RaySlabIntersect(Vector3.Dot(StartPosition, planes[2].Normal),
                                  Vector3.Dot(Direction, planes[2].Normal),
                                  Vector3.Dot(corners[0], planes[2].Normal),
                                  Vector3.Dot(corners[4], planes[2].Normal),
                                  ref tfirst, ref tlast))
            {
                return(null);
            }

            return(tfirst);
        }