示例#1
0
        public static void DrawBBox(BoundingBox box, Matrix Projection, Matrix View, Matrix localWorld,Color color)
        {
            // Use inside a drawing loop

                Vector3[] corners = box.GetCorners();
                VertexPositionColor[] primitiveList = new VertexPositionColor[corners.Length];

                // Assign the 8 box vertices
                for (int i = 0; i < corners.Length; i++)
                {
                    primitiveList[i] = new VertexPositionColor(corners[i], color);
                }

                /* Set your own effect parameters here */

                boxEffect.World = localWorld;
                boxEffect.View = View;
                boxEffect.Projection = Projection;
                boxEffect.TextureEnabled = false;

                // Draw the box with a LineList
                foreach (EffectPass pass in boxEffect.CurrentTechnique.Passes)
                {
                    pass.Apply();
                    device.DrawUserIndexedPrimitives(
                        PrimitiveType.LineList, primitiveList, 0, 8,
                        bBoxIndices, 0, 12);
                }
        }
        /// <summary>
        /// Renders the bounding box for debugging purposes.
        /// </summary>
        /// <param name="box">The box to render.</param>
        /// <param name="graphicsDevice">The graphics device to use when rendering.</param>
        /// <param name="view">The current view matrix.</param>
        /// <param name="projection">The current projection matrix.</param>
        /// <param name="color">The color to use drawing the lines of the box.</param>
        public static void Render(
            BoundingBox box,
            GraphicsDevice graphicsDevice,
            Matrix view,
            Matrix projection,
            Color color)
        {
            if (box.Min == box.Max)
            {
                return;
            }

            if (effect == null)
            {
                effect = new BasicEffect(graphicsDevice)
                             {TextureEnabled = false, VertexColorEnabled = true, LightingEnabled = false};
            }

            Vector3[] corners = box.GetCorners();
            for (int i = 0; i < 8; i++)
            {
                verts[i].Position = corners[i];
                verts[i].Color = color;
            }

            effect.View = view;
            effect.Projection = projection;

            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Apply();
                graphicsDevice.DrawUserIndexedPrimitives(PrimitiveType.LineList, verts, 0, 8, indices, 0,
                                                         indices.Length/2);
            }
        }
        public static void Draw(BoundingBox box, BaseCamera camera, Color color)
        {
            if (effect == null)
            {
                effect = new BasicEffect(YnG.GraphicsDevice);
                effect.VertexColorEnabled = true;
                effect.LightingEnabled = false;
            }

            Vector3 [] corners = box.GetCorners();
            for (int i = 0; i < 8; i++)
            {
                verts [i].Position = corners [i];
                verts [i].Color = color;
            }

            effect.View = camera.View;
            effect.Projection = camera.Projection;

            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Apply();
                YnG.GraphicsDevice.DrawUserIndexedPrimitives(PrimitiveType.LineList, verts, 0, 8, indices, 0, indices.Length / 2);
            }
        }
        public static void Render(BoundingBox box,
                                  GraphicsDevice graphicsDevice,
                                  Matrix view,
                                  Matrix projection,
                                  Color color)
        {
            if (_effect.IsNull())
                _effect = new BasicEffect(graphicsDevice) { VertexColorEnabled = true, LightingEnabled = false };

            var corners = box.GetCorners();

            for (var i = 0; i < 8; i++)
            {
                Vertices[i].Position = corners[i];
                Vertices[i].Color = color;
            }

            _effect.View = view;
            _effect.Projection = projection;

            foreach (var pass in _effect.CurrentTechnique.Passes)
            {
                pass.Apply();
                graphicsDevice.DrawUserIndexedPrimitives(PrimitiveType.LineList,
                                                         Vertices,
                                                         0,
                                                         8,
                                                         Indices,
                                                         0,
                                                         Indices.Length / 2);
            }
        }
示例#5
0
        public static void AddBoundingBox(BoundingBox box, Color color, float life)
        {
            DebugShape shape = GetShapeForLines(12, life);

            box.GetCorners(Corners);

            shape.Vertices[0] = new VertexPositionColor(Corners[0], color);
            shape.Vertices[1] = new VertexPositionColor(Corners[1], color);
            shape.Vertices[2] = new VertexPositionColor(Corners[1], color);
            shape.Vertices[3] = new VertexPositionColor(Corners[2], color);
            shape.Vertices[4] = new VertexPositionColor(Corners[2], color);
            shape.Vertices[5] = new VertexPositionColor(Corners[3], color);
            shape.Vertices[6] = new VertexPositionColor(Corners[3], color);
            shape.Vertices[7] = new VertexPositionColor(Corners[0], color);

            shape.Vertices[8] = new VertexPositionColor(Corners[4], color);
            shape.Vertices[9] = new VertexPositionColor(Corners[5], color);
            shape.Vertices[10] = new VertexPositionColor(Corners[5], color);
            shape.Vertices[11] = new VertexPositionColor(Corners[6], color);
            shape.Vertices[12] = new VertexPositionColor(Corners[6], color);
            shape.Vertices[13] = new VertexPositionColor(Corners[7], color);
            shape.Vertices[14] = new VertexPositionColor(Corners[7], color);
            shape.Vertices[15] = new VertexPositionColor(Corners[4], color);

            shape.Vertices[16] = new VertexPositionColor(Corners[0], color);
            shape.Vertices[17] = new VertexPositionColor(Corners[4], color);
            shape.Vertices[18] = new VertexPositionColor(Corners[1], color);
            shape.Vertices[19] = new VertexPositionColor(Corners[5], color);
            shape.Vertices[20] = new VertexPositionColor(Corners[2], color);
            shape.Vertices[21] = new VertexPositionColor(Corners[6], color);
            shape.Vertices[22] = new VertexPositionColor(Corners[3], color);
            shape.Vertices[23] = new VertexPositionColor(Corners[7], color);
        }
        public static void Draw(BoundingBox box)
        {
            Vector3[] corners = box.GetCorners();
            VertexPositionColor[] primitiveList = new VertexPositionColor[corners.Length];

            // Assign the 8 box vertices
            for (int i = 0; i < corners.Length; i++)
            {
                primitiveList[i] = new VertexPositionColor(corners[i], Color.White);
            }

            /* Set your own effect parameters here */

            boxEffect.World = Matrix.Identity;
            boxEffect.View = Camera.View;
            boxEffect.Projection = Camera.Projection;
            boxEffect.TextureEnabled = false;

            // Draw the box with a LineList
            foreach (EffectPass pass in boxEffect.CurrentTechnique.Passes)
            {
                pass.Apply();
                AssetManager.Singleton.m_GraphicsDevice.DrawUserIndexedPrimitives(
                    PrimitiveType.LineList, primitiveList, 0, 8,
                    bBoxIndices, 0, 12);
            }
        }
示例#7
0
        public static VertexPositionColor[] GetVerticesFromBounds(BoundingBox bounds, Color hitboxColor)
        {
            Vector3[] corners = bounds.GetCorners();
            VertexPositionColor[] debugVerts = new VertexPositionColor[24];
            debugVerts[0] = new VertexPositionColor(corners[0], hitboxColor);
            debugVerts[1] = new VertexPositionColor(corners[1], hitboxColor);
            debugVerts[2] = new VertexPositionColor(corners[1], hitboxColor);
            debugVerts[3] = new VertexPositionColor(corners[5], hitboxColor);
            debugVerts[4] = new VertexPositionColor(corners[5], hitboxColor);
            debugVerts[5] = new VertexPositionColor(corners[4], hitboxColor);
            debugVerts[6] = new VertexPositionColor(corners[4], hitboxColor);
            debugVerts[7] = new VertexPositionColor(corners[0], hitboxColor);

            debugVerts[8] = new VertexPositionColor(corners[3], hitboxColor);
            debugVerts[9] = new VertexPositionColor(corners[2], hitboxColor);
            debugVerts[10] = new VertexPositionColor(corners[2], hitboxColor);
            debugVerts[11] = new VertexPositionColor(corners[6], hitboxColor);
            debugVerts[12] = new VertexPositionColor(corners[6], hitboxColor);
            debugVerts[13] = new VertexPositionColor(corners[7], hitboxColor);
            debugVerts[14] = new VertexPositionColor(corners[7], hitboxColor);
            debugVerts[15] = new VertexPositionColor(corners[3], hitboxColor);

            debugVerts[16] = new VertexPositionColor(corners[3], hitboxColor);
            debugVerts[17] = new VertexPositionColor(corners[0], hitboxColor);
            debugVerts[18] = new VertexPositionColor(corners[2], hitboxColor);
            debugVerts[19] = new VertexPositionColor(corners[1], hitboxColor);
            debugVerts[20] = new VertexPositionColor(corners[6], hitboxColor);
            debugVerts[21] = new VertexPositionColor(corners[5], hitboxColor);
            debugVerts[22] = new VertexPositionColor(corners[7], hitboxColor);
            debugVerts[23] = new VertexPositionColor(corners[4], hitboxColor);

            return debugVerts;
        }
示例#8
0
 public void AddLightVolume(ref BoundingBox boundingBox)
 {
     boundingBox.GetCorners(boundingBoxCorners);
     for (int i = 0; i < boundingBoxCorners.Length; i++)
     {
         additionalLightVolumePoints.Add(boundingBoxCorners[i]);
     }
 }
示例#9
0
 public static bool IsNaN(BoundingBox b)
 {
     Vector3[] corners = new Vector3[8];
       b.GetCorners(corners);
       bool nan = false;
       for (int i = 0; i < CornersInBB && !nan; i++)
       {
     Vector3 v = corners[i];
     nan = nan || float.IsNaN(v.X) || float.IsNaN(v.Y) || float.IsNaN(v.Z);
       }
       return nan;
 }
示例#10
0
        VertexPositionColor[] CreateVertices(BoundingBox boundingBox)
        {
            var vertices = new VertexPositionColor[8];

            Vector3[] corners = boundingBox.GetCorners();
            for (int i = 0; i < 8; i++)
            {
                vertices[i].Position = corners[i];
                vertices[i].Color = Color.Red;
            }

            return vertices;
        }
示例#11
0
        public static BoundingBox Transform(BoundingBox box, Matrix world)
        {
            var vertices = box.GetCorners();
            var minVertex = new Vector3(float.MaxValue);
            var maxVertex = new Vector3(float.MinValue);

            foreach (Vector3 vertex in vertices)
            {
                var transformedVertex = Vector3.Transform(vertex, world);
                minVertex = Vector3.Min(minVertex, transformedVertex);
                maxVertex = Vector3.Max(maxVertex, transformedVertex);
            }

            return new BoundingBox(minVertex, maxVertex);
        }
示例#12
0
		public static IEnumerable<Vector3> GetWorldSpaceFrustumCorners(
			float clipSpaceNear, float clipSpaceFar,
			Matrix viewProjectionInverse)
		{
			var clipSpaceBoundingBox = new BoundingBox(
				new Vector3(-1, -1, clipSpaceNear), 
				new Vector3(1, 1, clipSpaceFar));
			return clipSpaceBoundingBox.GetCorners().Select(v =>
			{
				var vt = Vector4.Transform(v, viewProjectionInverse);
				vt /= vt.W;

				return new Vector3(vt.X, vt.Y, vt.Z);
			});
		}
示例#13
0
        /// <summary>
        /// Renders the bounding box for debugging purposes.
        /// </summary>
        /// <param name="box">The box to render.</param>
        /// <param name="graphicsDevice">The graphics device to use when rendering.</param>
        /// <param name="view">The current view matrix.</param>
        /// <param name="projection">The current projection matrix.</param>
        /// <param name="color">The color to use drawing the lines of the box.</param>
        public static void Render(
            BoundingBox box,
            GraphicsDevice graphicsDevice,
            Matrix view,
            Matrix projection,
            Color color)
        {
            if (effect == null)
            {
                effect = new BasicEffect(graphicsDevice, null);
                effect.VertexColorEnabled = true;
                effect.LightingEnabled = false;
                vertDecl = new VertexDeclaration(graphicsDevice, VertexPositionColor.VertexElements);
            }

            Vector3[] corners = box.GetCorners();
            for (int i = 0; i < 8; i++)
            {
                verts[i].Position = corners[i];
                verts[i].Color = color;
            }

            graphicsDevice.VertexDeclaration = vertDecl;

            effect.View = view;
            effect.Projection = projection;

            effect.Begin();
            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Begin();

                graphicsDevice.DrawUserIndexedPrimitives(
                    PrimitiveType.LineList,
                    verts,
                    0,
                    8,
                    indices,
                    0,
                    indices.Length / 2);

                pass.End();
            }
            effect.End();
        }
示例#14
0
        /// <summary>
        /// Renders the bounding box for debugging purposes.
        /// </summary>
        /// <param name="box">The box to render.</param>
        /// <param name="graphicsDevice">The graphics device to use when rendering.</param>
        /// <param name="view">The current view matrix.</param>
        /// <param name="projection">The current projection matrix.</param>
        /// <param name="color">The color to use for drawing the lines of the box.</param>
        public static void Render(
            BoundingBox box,
            GraphicsDevice graphicsDevice,
            Matrix view,
            Matrix projection,
            Color color)
        {
            if (effect == null)
            {
                effect = new BasicEffect(graphicsDevice);
                effect.VertexColorEnabled = true;
                effect.LightingEnabled = false;
            }

            Vector3[] corners = box.GetCorners();

            for (int i = 0; i < 8; i++)
            {
                verts[i].Position = corners[i];
                verts[i].Color = color;
            }

            vertex_Buffer = new VertexBuffer(graphicsDevice, typeof(VertexPositionColor), verts.Length, BufferUsage.WriteOnly);
            vertex_Buffer.SetData<VertexPositionColor>(verts);
            graphicsDevice.SetVertexBuffer(vertex_Buffer);

            effect.View = view;
            effect.Projection = projection;

            effect.CurrentTechnique.Passes[0].Apply();

            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                graphicsDevice.DrawUserIndexedPrimitives(
                    PrimitiveType.LineList,
                    verts,
                    0,
                    8,
                    indices,
                    0,
                    indices.Length / 2);
            }
        }
示例#15
0
        protected override void LoadContent()
        {
            base.LoadContent();
            BoundingBox box = new BoundingBox(new Vector3(-1,-1,-1),new Vector3(1,1,1) );
            Vector3[] boxCornersVertices = box.GetCorners();

            _boxCorners = new VertexPositionColor[boxCornersVertices.Length];
            for (int i = 0; i < 8; i++)
                _boxCorners[i] = new VertexPositionColor(boxCornersVertices[i], Color.White);

            _boxIndices = new int[24];
            _boxIndices[0] = 0;
            _boxIndices[1] = 1;
            _boxIndices[2] = 1;
            _boxIndices[3] = 2;
            _boxIndices[4] = 2;
            _boxIndices[5] = 3;
            _boxIndices[6] = 3;
            _boxIndices[7] = 0;
            _boxIndices[8] = 0;
            _boxIndices[9] = 4;
            _boxIndices[10] = 3;
            _boxIndices[11] = 7;
            _boxIndices[12] = 2;
            _boxIndices[13] = 6;
            _boxIndices[14] = 1;
            _boxIndices[15] = 5;
            _boxIndices[16] = 4;
            _boxIndices[17] = 5;
            _boxIndices[18] = 5;
            _boxIndices[19] = 6;
            _boxIndices[20] = 6;
            _boxIndices[21] = 7;
            _boxIndices[22] = 7;
            _boxIndices[23] = 4;

            effect = new BasicEffect(GraphicsDevice);
            effect.EnableDefaultLighting();
            effect.AmbientLightColor = new Vector3(150, 0, 0);
            effect.PreferPerPixelLighting = true;
            effect.LightingEnabled = true;
            effect.TextureEnabled = false;
        }
示例#16
0
文件: Debug.cs 项目: Joelone/FFWD
        public static void DrawBBox(ref BoundingBox bbox, Color color)
        {
            Microsoft.Xna.Framework.Vector3[] corners = bbox.GetCorners();

              Debug.DrawLine(corners[0], corners[1], color);
              Debug.DrawLine(corners[1], corners[2], color);
              Debug.DrawLine(corners[2], corners[3], color);
              Debug.DrawLine(corners[3], corners[0], color);

              Debug.DrawLine(corners[4], corners[5], color);
              Debug.DrawLine(corners[5], corners[6], color);
              Debug.DrawLine(corners[6], corners[7], color);
              Debug.DrawLine(corners[7], corners[4], color);

              Debug.DrawLine(corners[0], corners[4], color);
              Debug.DrawLine(corners[1], corners[5], color);
              Debug.DrawLine(corners[2], corners[6], color);
              Debug.DrawLine(corners[3], corners[7], color);
        }
        public static void BoundingBox(GraphicsDevice g, BoundingBox b)
        {
            BasicEffect e = Shaders.Primitive;

            VertexPositionColor[] vertices = new VertexPositionColor[8];
            Vector3[] corners = b.GetCorners();
            for (int i = 0; i < 8; i++)
            {
                vertices[i].Position = corners[i];
                vertices[i].Color = Color.Red;
            }

            short[] indices = new short[] { 0, 1, 1, 2, 2, 3, 3, 0, 4, 5, 5, 6, 6, 7, 7, 4, 0, 4, 1, 5, 2, 6, 3, 7 };

            e.Begin();
            e.CurrentTechnique.Passes[0].Begin();
            g.VertexDeclaration = new VertexDeclaration(g, VertexPositionColor.VertexElements);
            g.DrawUserIndexedPrimitives(PrimitiveType.LineList, vertices, 0, 8, indices, 0, 12);
            e.CurrentTechnique.Passes[0].End();
            e.End();
        }
示例#18
0
        private static Line1D GetProjectedPoints(BoundingBox boundingBox, Vector3 axis)
        {
            var points = boundingBox.GetCorners();

            var min = Vector3.Dot(axis, points[0]);
            var max = min;
            for (var i = 1; i < points.Length; i++)
            {
                var p = Vector3.Dot(axis, points[i]);
                if (p < min)
                {
                    min = p;
                }
                else if (p > max)
                {
                    max = p;
                }
            }

            return new Line1D(min, max);
        }
示例#19
0
        public void Draw(ref BoundingBox box, Effect effect, ref Color vertexColor)
        {
            if (effect == null) throw new ArgumentNullException("effect");

            box.GetCorners(corners);
            for (int i = 0; i < 8; i++)
            {
                vertices[i].Position = corners[i];
                vertices[i].Color = vertexColor;
            }

            effect.CurrentTechnique.Passes[0].Apply();
            graphicsDevice.DrawUserIndexedPrimitives<VertexPositionColor>(
                PrimitiveType.LineList,
                vertices,
                0,
                8,
                indices,
                0,
                primitiveCount);
        }
示例#20
0
        public Cube(Vector3 origin, float width, float height, string type)
        {
            Origin = origin;
            Sides = new Square[6];

            Sides[0] = new Square(origin + new Vector3(0, width / 2, 0), Vector3.UnitY, Vector3.UnitX, height, width, type + "/top");
            Sides[1] = new Square(origin - new Vector3(0, width / 2, 0), Vector3.UnitY, Vector3.UnitX, height, width, type + "/buttom");
            Sides[2] = new Square(origin + new Vector3(0, 0, height / 2), Vector3.UnitZ, Vector3.UnitY, height, width, type + "/side");
            Sides[3] = new Square(origin - new Vector3(0, 0, height / 2), Vector3.UnitZ, Vector3.UnitY, height, width, type + "/side");
            Sides[4] = new Square(origin + new Vector3(width / 2, 0, 0), Vector3.UnitX, Vector3.UnitZ, height, width, type + "/side");
            Sides[5] = new Square(origin - new Vector3(width / 2, 0, 0), Vector3.UnitX, Vector3.UnitZ, height, width, type + "/side");

            Box = new BoundingBox(origin + new Vector3(width / 2, height / 2, width / 2), origin - new Vector3(width / 2, height / 2, width / 2));

            bBoxIndices = new short[] { 0, 1, 1, 2, 2, 3, 3, 0, 4, 5, 5, 6, 6, 7, 7, 4, 0, 4, 1, 5, 2, 6, 3, 7 };
            corners = Box.GetCorners();
            primitiveList = new VertexPositionColor[corners.Length];
            for (int i = 0; i < corners.Length; i++)
            {
                primitiveList[i] = new VertexPositionColor(corners[i], Color.Black);
            }
        }
示例#21
0
        public void Draw(ref BoundingBox box, Effect effect, ref Color vertexColor)
        {
            box.GetCorners(corners);
            for (int i = 0; i < 8; i++)
            {
                vertices[i].Position = corners[i];
                vertices[i].Color = vertexColor;
            }

            foreach (var pass in effect.CurrentTechnique.Passes)
            {
                pass.Apply();
                graphicsDevice.DrawUserIndexedPrimitives<VertexPositionColor>(
                    PrimitiveType.LineList,
                    vertices,
                    0,
                    8,
                    indices,
                    0,
                    primitiveCount);
            }
        }
示例#22
0
        /// <summary>
        /// Renders the bounding box for debugging purposes.
        /// </summary>
        /// <param name="box">The box to render.</param>
        /// <param name="graphicsDevice">The graphics device to use when rendering.</param>
        /// <param name="view">The current view matrix.</param>
        /// <param name="projection">The current projection matrix.</param>
        /// <param name="color">The color to use drawing the lines of the box.</param>
        public static void Render(
            BoundingBox box,
            GraphicsDevice graphicsDevice,
            Matrix view,
            Matrix projection,
            Color color)
        {
            if (effect == null)
            {
                effect = new BasicEffect(graphicsDevice);
                effect.VertexColorEnabled = true;
                effect.LightingEnabled = false;
                vertDecl = new VertexDeclaration(VertexPositionColor.VertexDeclaration.GetVertexElements());
            }

            Vector3[] corners = box.GetCorners();
            for (int i = 0; i < 8; i++)
            {
                verts[i].Position = corners[i];
                verts[i].Color = color;
            }

            VertexBuffer vertexBuffer = new VertexBuffer(graphicsDevice, vertDecl, 8, BufferUsage.None);
            vertexBuffer.SetData(verts);

            IndexBuffer indexBuffer = new IndexBuffer(graphicsDevice, typeof(int), 24, BufferUsage.WriteOnly);
            indexBuffer.SetData(indices);

            effect.View = view;
            effect.Projection = projection;

            graphicsDevice.SetVertexBuffer(vertexBuffer);
            graphicsDevice.Indices = indexBuffer;

            effect.CurrentTechnique.Passes[0].Apply();

            graphicsDevice.DrawIndexedPrimitives(PrimitiveType.LineList, 0, 0, vertexBuffer.VertexCount, 0, indexBuffer.IndexCount / 2);
        }
示例#23
0
        public static void AddBoundingBox(BoundingBox box, Color color, float life = 0f)
        {
            // Get a DebugShape we can use to draw the box
            DebugShape shape = GetShapeForLines(12, life);

            // Get the corners of the box
            box.GetCorners(_corners);

            // Fill in the vertices for the bottom of the box
            shape.Vertices[0] = new VertexPositionColor(_corners[0], color);
            shape.Vertices[1] = new VertexPositionColor(_corners[1], color);
            shape.Vertices[2] = new VertexPositionColor(_corners[1], color);
            shape.Vertices[3] = new VertexPositionColor(_corners[2], color);
            shape.Vertices[4] = new VertexPositionColor(_corners[2], color);
            shape.Vertices[5] = new VertexPositionColor(_corners[3], color);
            shape.Vertices[6] = new VertexPositionColor(_corners[3], color);
            shape.Vertices[7] = new VertexPositionColor(_corners[0], color);

            // Fill in the vertices for the top of the box
            shape.Vertices[8] = new VertexPositionColor(_corners[4], color);
            shape.Vertices[9] = new VertexPositionColor(_corners[5], color);
            shape.Vertices[10] = new VertexPositionColor(_corners[5], color);
            shape.Vertices[11] = new VertexPositionColor(_corners[6], color);
            shape.Vertices[12] = new VertexPositionColor(_corners[6], color);
            shape.Vertices[13] = new VertexPositionColor(_corners[7], color);
            shape.Vertices[14] = new VertexPositionColor(_corners[7], color);
            shape.Vertices[15] = new VertexPositionColor(_corners[4], color);

            // Fill in the vertices for the vertical sides of the box
            shape.Vertices[16] = new VertexPositionColor(_corners[0], color);
            shape.Vertices[17] = new VertexPositionColor(_corners[4], color);
            shape.Vertices[18] = new VertexPositionColor(_corners[1], color);
            shape.Vertices[19] = new VertexPositionColor(_corners[5], color);
            shape.Vertices[20] = new VertexPositionColor(_corners[2], color);
            shape.Vertices[21] = new VertexPositionColor(_corners[6], color);
            shape.Vertices[22] = new VertexPositionColor(_corners[3], color);
            shape.Vertices[23] = new VertexPositionColor(_corners[7], color);
        }
        /// <summary>
        /// Renders the bounding box for debugging purposes.
        /// </summary>
        /// <param name="box">The box to render.</param>
        /// <param name="graphicsDevice">The graphics device to use when rendering.</param>
        /// <param name="view">The current view matrix.</param>
        /// <param name="projection">The current projection matrix.</param>
        /// <param name="color">The color to use drawing the lines of the box.</param>
        public static void Render(
            Game1 game,
            BoundingBox box,
            GraphicsDevice graphicsDevice,
            Matrix view,
            Matrix projection,
            Color color)
        {
            if (effect == null)
            {
                effect = new BasicEffect(graphicsDevice);
                effect.VertexColorEnabled = true;
                effect.LightingEnabled = false;
            }

            Vector3[] corners = box.GetCorners();
            for (int i = 0; i < 4; i++)
            {
                int j = i + 1;
                if (i == 3)
                {
                    j = 0;
                }
                game.drawUtils.DrawLine(corners[i], corners[j], color);
                game.drawUtils.DrawLine(corners[i], corners[i + 4], color);
            }

            for (int i = 4; i < 8; i++)
            {
                int j = i + 1;
                if (i == 7)
                {
                    j = 4;
                }
                game.drawUtils.DrawLine(corners[i], corners[j], color);
            }
        }
示例#25
0
        /// <summary>
        /// Draws the wireframe of a bounding box
        /// </summary>
        /// <param name="bb">Bounding Box</param>
        public static void DrawBoundingBox(BoundingBox bb, Matrix transform)
        {
            VertexPositionColor[] verts = new VertexPositionColor[8];

            Vector3[] corners = bb.GetCorners();

            for (int i = 0; i < 8; i++)
            {
                verts[i].Position = corners[i];
                verts[i].Color = Color.Red;
            }

            int[] indices = new int[]
            {
                0, 1,
                1, 2,
                2, 3,
                3, 0,
                0, 4,
                1, 5,
                2, 6,
                3, 7,
                4, 5,
                5, 6,
                6, 7,
                7, 4,
            };

            _effect.World = transform;
            _effect.View = CameraManager.Instance.View;
            _effect.Projection = CameraManager.Instance.Projection;

            _effect.Techniques[0].Passes[0].Apply();

            GameResources.GraphicsDevice.DrawUserIndexedPrimitives<VertexPositionColor>(PrimitiveType.LineList, verts, 0, verts.Length, indices, 0, indices.Length / 2);
        }
示例#26
0
文件: Player.cs 项目: Gillium/cs204L
        public void HandleTileCollision(Map map, bool collision, GameTime gameTime)
        {
            depthX = depthY = float.MaxValue;
                int i = (int)((PlayerPostion().X + 50) / 100);
                int j = (int)((PlayerPostion().Y + 0) / 100);
                Vector3 pos = new Vector3(map.TileDimensions.X * i, map.TileDimensions.Y * j, 0);
                BoundingBox bb = new BoundingBox(new Vector3(pos.X - (int)(80 * .68), pos.Y, -(int)(80 * .68)), new Vector3(pos.X + (int)(80 * .68), pos.Y + (int)(map.IsPorch(i, j) ? 10 : 140 * .68), (int)(60 * .68)));
                float deltaX, deltaY;

                if (velocity.Y > 0)
                {
                    deltaY = -CollisionBox.GetCorners()[0].Y + bb.GetCorners()[3].Y;
                }
                else if (velocity.Y < 0)
                {
                    deltaY = CollisionBox.GetCorners()[0].Y - bb.GetCorners()[0].Y;
                    deltaY -= 50;
                    gravity = 0f;
                }
                else
                    deltaY = 0;

                if (velocity.X > 0)
                {
                    deltaX = CollisionBox.GetCorners()[1].X - bb.GetCorners()[0].X;
                    deltaY = 0;
                }
                else if (velocity.X < 0)
                {
                    deltaX = CollisionBox.GetCorners()[0].X - bb.GetCorners()[1].X;
                    deltaY = 0;
                }
                else
                    deltaX = 0;

                position.X -= deltaX;
                position.Y += deltaY;
        }
示例#27
0
        // Create and return the (drawable) bounding box
        private BoundingBoxBuffers CreateBoundingBoxBuffers(BoundingBox boundingBox, GraphicsDevice graphicsDevice)
        {
            BoundingBoxBuffers boundingBoxBuffers = new BoundingBoxBuffers();

            boundingBoxBuffers.PrimitiveCount = 24;
            boundingBoxBuffers.VertexCount = 48;

            VertexBuffer vertexBuffer = new VertexBuffer(graphicsDevice,
                typeof(VertexPositionColor), boundingBoxBuffers.VertexCount,
                BufferUsage.WriteOnly);
            List<VertexPositionColor> vertices = new List<VertexPositionColor>();

            const float ratio = 5.0f;

            Vector3 xOffset = new Vector3((boundingBox.Max.X - boundingBox.Min.X) / ratio, 0, 0);
            Vector3 yOffset = new Vector3(0, (boundingBox.Max.Y - boundingBox.Min.Y) / ratio, 0);
            Vector3 zOffset = new Vector3(0, 0, (boundingBox.Max.Z - boundingBox.Min.Z) / ratio);
            Vector3[] corners = boundingBox.GetCorners();

            // Corner 1.
            AddVertex(vertices, corners[0]);
            AddVertex(vertices, corners[0] + xOffset);
            AddVertex(vertices, corners[0]);
            AddVertex(vertices, corners[0] - yOffset);
            AddVertex(vertices, corners[0]);
            AddVertex(vertices, corners[0] - zOffset);

            // Corner 2.
            AddVertex(vertices, corners[1]);
            AddVertex(vertices, corners[1] - xOffset);
            AddVertex(vertices, corners[1]);
            AddVertex(vertices, corners[1] - yOffset);
            AddVertex(vertices, corners[1]);
            AddVertex(vertices, corners[1] - zOffset);

            // Corner 3.
            AddVertex(vertices, corners[2]);
            AddVertex(vertices, corners[2] - xOffset);
            AddVertex(vertices, corners[2]);
            AddVertex(vertices, corners[2] + yOffset);
            AddVertex(vertices, corners[2]);
            AddVertex(vertices, corners[2] - zOffset);

            // Corner 4.
            AddVertex(vertices, corners[3]);
            AddVertex(vertices, corners[3] + xOffset);
            AddVertex(vertices, corners[3]);
            AddVertex(vertices, corners[3] + yOffset);
            AddVertex(vertices, corners[3]);
            AddVertex(vertices, corners[3] - zOffset);

            // Corner 5.
            AddVertex(vertices, corners[4]);
            AddVertex(vertices, corners[4] + xOffset);
            AddVertex(vertices, corners[4]);
            AddVertex(vertices, corners[4] - yOffset);
            AddVertex(vertices, corners[4]);
            AddVertex(vertices, corners[4] + zOffset);

            // Corner 6.
            AddVertex(vertices, corners[5]);
            AddVertex(vertices, corners[5] - xOffset);
            AddVertex(vertices, corners[5]);
            AddVertex(vertices, corners[5] - yOffset);
            AddVertex(vertices, corners[5]);
            AddVertex(vertices, corners[5] + zOffset);

            // Corner 7.
            AddVertex(vertices, corners[6]);
            AddVertex(vertices, corners[6] - xOffset);
            AddVertex(vertices, corners[6]);
            AddVertex(vertices, corners[6] + yOffset);
            AddVertex(vertices, corners[6]);
            AddVertex(vertices, corners[6] + zOffset);

            // Corner 8.
            AddVertex(vertices, corners[7]);
            AddVertex(vertices, corners[7] + xOffset);
            AddVertex(vertices, corners[7]);
            AddVertex(vertices, corners[7] + yOffset);
            AddVertex(vertices, corners[7]);
            AddVertex(vertices, corners[7] + zOffset);

            vertexBuffer.SetData(vertices.ToArray());
            boundingBoxBuffers.Vertices = vertexBuffer;

            IndexBuffer indexBuffer = new IndexBuffer(graphicsDevice, IndexElementSize.SixteenBits, boundingBoxBuffers.VertexCount,
                BufferUsage.WriteOnly);
            indexBuffer.SetData(Enumerable.Range(0, boundingBoxBuffers.VertexCount).Select(i => (short)i).ToArray());
            boundingBoxBuffers.Indices = indexBuffer;

            return boundingBoxBuffers;
        }
示例#28
0
 // Calcule et retourne BoundingBox
 private BoundingBox CalculerBoundingBox(ModelMesh maillage, float[] sommetsDuModèle, int tailleSommetEnFloat, ref int début)
 {
     int nbSommets = 0;
     foreach (ModelMeshPart portionDeMaillage in maillage.MeshParts)
     {
         nbSommets += portionDeMaillage.NumVertices;
     }
     Vector3 maxMaillage = new Vector3(float.MinValue, float.MinValue, float.MinValue);
     Vector3 minMaillage = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue);
     int index = 0;
     Vector3[] positionSommets = new Vector3[nbSommets];
     int fin = début + nbSommets * tailleSommetEnFloat;
     // on parcourt la portion de la liste des sommets correspondant à cette partie du modèle
     for (int indiceSommet = début; indiceSommet < fin && indiceSommet < sommetsDuModèle.Length; indiceSommet += tailleSommetEnFloat)
     {
         Vector3 sommet = new Vector3(sommetsDuModèle[indiceSommet], sommetsDuModèle[indiceSommet + 1], sommetsDuModèle[indiceSommet + 2]);
         positionSommets[index] = sommet;
         minMaillage = Vector3.Min(sommet, minMaillage);
         maxMaillage = Vector3.Max(sommet, maxMaillage);
         ++index;
     }
     début = fin;
     BoundingBox boîte = new BoundingBox(minMaillage, maxMaillage);
     Vector3[] listeDesCoins = boîte.GetCorners();
     Matrix mondeLocal = maillage.ParentBone.Transform;
     mondeLocal *= Matrix.CreateScale(Échelle * ÉchelleBox);
     mondeLocal *= Matrix.CreateFromYawPitchRoll(Rotation.Y, Rotation.X, Rotation.Z);
     mondeLocal *= Matrix.CreateTranslation(Position);
     Vector3.Transform(listeDesCoins, ref mondeLocal, listeDesCoins);
     boîte = BoundingBox.CreateFromPoints(listeDesCoins);
     return boîte;
 }
示例#29
0
 /// <summary>
 /// Renders the outline of an axis-aligned bounding box
 /// </summary>
 /// <param name="box">Bounding box to render</param>
 /// <param name="color">Color of the box lines</param>
 public void DrawWireBox(BoundingBox box, Color color)
 {
     DrawWireShape(box.GetCorners(), cubeIndices, color);
 }
 public override ModelContent Process(NodeContent input, ContentProcessorContext context)
 {
     //allocates list that stores values from the processor to the ScreenModel class
     ToSendInTag = new List<object>();
     CollisionBox = new BoundingBox();
     //code that builds/creates the bounding box for collisions
     //gets the node data from the model-> allows us to go in further through meshes later to find vector sizes
     NodeContentCollection nodeContentCollection = input.Children;
     ModelContent TheContent = base.Process(input, context);
     //CollisionType = new ObjectTypes((int)CollisionArg);
     Enum EnumWrapper = CollisionArg;
     //tags the collision box...allows us to reference them outside...I've used tags before; they are cool and weird
     //As I need to send multiple values through the tag; why not use a list of generic objects?
     //ToSendInTag.Add(EnumWrapper);
     ToSendInTag.Add((int)CollisionArg);
     //only processes the shape of the bounding box when the bounding box is required, saves memory and processing time
     if (CollisionArg == CollisionKind.Box)
     {
         //for objects that are better off using a bounding box
         FindVectorValues(nodeContentCollection);
         ToSendInTag.Add(CollisionBox);
     }
     if (CollisionArg == CollisionKind.Room)
     {
         //calculates bounding collision box
         FindVectorValues(nodeContentCollection);
         //gets the points of the corners; should be 8 of them
         Vector3[] ListOfCorners = CollisionBox.GetCorners();
         //uses maths to get planes from these corners
         // 1  2     5  6
         // 3  4     7  8
         //  up      down
         //needs to get a total of 6 walls
         //create a list of planes to send over that represent the walls of a room
         List<Plane> ListOfWalls = new List<Plane>();
         //6 sides are recieved from using 3 points on each of the planes
         //#1- pts: 1,2,3
         ListOfWalls.Add(new Plane(ListOfCorners[0],ListOfCorners[1],ListOfCorners[2]));
         //#2- pts: 1,5,6
         ListOfWalls.Add(new Plane(ListOfCorners[0], ListOfCorners[4], ListOfCorners[5]));
         //#3- pts: 2,6,8
         ListOfWalls.Add(new Plane(ListOfCorners[1], ListOfCorners[5], ListOfCorners[7]));
         //#4- pts: 4,7,8
         ListOfWalls.Add(new Plane(ListOfCorners[3], ListOfCorners[6], ListOfCorners[7]));
         //#5- pts: 3,5,7
         ListOfWalls.Add(new Plane(ListOfCorners[2], ListOfCorners[4], ListOfCorners[6]));
         //#6- pts: 5,6,8
         ListOfWalls.Add(new Plane(ListOfCorners[4], ListOfCorners[5], ListOfCorners[7]));
         //added to the tag array
         ToSendInTag.Add(ListOfWalls);
     }
     //sends over the list
     TheContent.Tag = ToSendInTag;
     //returns the modified data with the tag (reference) to the bounding box
     return (TheContent);
 }