Ejemplo n.º 1
0
        public static void DrawWireframe(PrimitiveDrawer primitiveDrawer,
			Matrix cameraView, Matrix cameraProjection,
			BoundingFrustum frustum, Color color)
        {
            // The points returned correspond to the corners of the BoundingFrustum faces that are
            // perpendicular to the z-axis. The near face is the face with the larger z value, and
            // the far face is the face with the smaller z value. Points 0 to 3 correspond to the
            // near face in a clockwise order starting at its upper-left corner when looking toward
            // the origin from the positive z direction. Points 4 to 7 correspond to the far face
            // in a clockwise order starting at its upper-left corner when looking toward the
            // origin from the positive z direction.
            frustum.GetCorners(Corners);

            FrustumVertices[6].Position = Corners[0];
            FrustumVertices[7].Position = Corners[1];
            FrustumVertices[5].Position = Corners[2];
            FrustumVertices[4].Position = Corners[3];
            FrustumVertices[2].Position = Corners[4];
            FrustumVertices[3].Position = Corners[5];
            FrustumVertices[1].Position = Corners[6];
            FrustumVertices[0].Position = Corners[7];

            primitiveDrawer.Draw(Matrix.Identity, cameraView, cameraProjection, color, null,
                PrimitiveType.LineList, FrustumVertices, WireFrustumIndices, false);
        }
Ejemplo n.º 2
0
        public static void DrawWireframe(PrimitiveDrawer primitiveDrawer,
                                         Matrix cameraView, Matrix cameraProjection,
                                         BoundingFrustum frustum, Color color)
        {
            // The points returned correspond to the corners of the BoundingFrustum faces that are
            // perpendicular to the z-axis. The near face is the face with the larger z value, and
            // the far face is the face with the smaller z value. Points 0 to 3 correspond to the
            // near face in a clockwise order starting at its upper-left corner when looking toward
            // the origin from the positive z direction. Points 4 to 7 correspond to the far face
            // in a clockwise order starting at its upper-left corner when looking toward the
            // origin from the positive z direction.
            frustum.GetCorners(Corners);

            FrustumVertices[6].Position = Corners[0];
            FrustumVertices[7].Position = Corners[1];
            FrustumVertices[5].Position = Corners[2];
            FrustumVertices[4].Position = Corners[3];
            FrustumVertices[2].Position = Corners[4];
            FrustumVertices[3].Position = Corners[5];
            FrustumVertices[1].Position = Corners[6];
            FrustumVertices[0].Position = Corners[7];

            primitiveDrawer.Draw(Matrix.Identity, cameraView, cameraProjection, color, null,
                                 PrimitiveType.LineList, FrustumVertices, WireFrustumIndices, false);
        }
Ejemplo n.º 3
0
        public static void DrawWireframe(PrimitiveDrawer primitiveDrawer, Vector3 cameraPosition, Matrix cameraView, Matrix cameraProjection,
                                         Vector3 center, Vector3 size, Quaternion rotation, Color color)
        {
            var world = Matrix.CreateScale(size) * Matrix.CreateFromQuaternion(rotation) * Matrix.CreateTranslation(center);

            var vertices = new VertexPositionColor[WireframeLines.Length * 2];

            for (int i = 0; i < WireframeLines.Length; i++)
            {
                var     transformedLine = WireframeLine.Transform(WireframeLines[i], world);
                Vector3 cameraToLine    = Vector3.Normalize(((transformedLine.Point1 + transformedLine.Point2) / 2) - cameraPosition);

                Color lineColor = color;
                if (!IsCameraFacing(cameraToLine, transformedLine.FaceNormal1) && !IsCameraFacing(cameraToLine, transformedLine.FaceNormal2))
                {
                    lineColor = Color.FromNonPremultiplied(color.R, color.G, color.B, 25);
                }

                vertices[i * 2]       = new VertexPositionColor(transformedLine.Point1, lineColor);
                vertices[(i * 2) + 1] = new VertexPositionColor(transformedLine.Point2, lineColor);
            }

            primitiveDrawer.Draw(Matrix.Identity, cameraView, cameraProjection,
                                 Color.White, null, PrimitiveType.LineList, vertices, false);
        }
Ejemplo n.º 4
0
        public static void Draw(
			PrimitiveDrawer primitiveDrawer, Matrix cameraView, Matrix cameraProjection,
			Vector3 start, Vector3 end, Color color)
        {
            var vertices = new[]
            {
                new VertexPositionColor(start, Color.White),
                new VertexPositionColor(end, Color.White)
            };
            primitiveDrawer.Draw(Matrix.Identity, cameraView, cameraProjection,
                color, null, PrimitiveType.LineList, vertices, false);
        }
Ejemplo n.º 5
0
        public static void Draw(
            PrimitiveDrawer primitiveDrawer, Matrix cameraView, Matrix cameraProjection,
            Vector3 start, Vector3 end, Color color)
        {
            var vertices = new[]
            {
                new VertexPositionColor(start, Color.White),
                new VertexPositionColor(end, Color.White)
            };

            primitiveDrawer.Draw(Matrix.Identity, cameraView, cameraProjection,
                                 color, null, PrimitiveType.LineList, vertices, false);
        }
Ejemplo n.º 6
0
        public static void DrawSolid(PrimitiveDrawer primitiveDrawer, Matrix cameraView, Matrix cameraProjection,
			Vector3[] corners, Color color)
        {
            if (corners == null || corners.Length != 4)
                throw new ArgumentException("corners");

            Vertices[0].Position = corners[0];
            Vertices[1].Position = corners[1];
            Vertices[2].Position = corners[2];
            Vertices[3].Position = corners[3];

            primitiveDrawer.Draw(Matrix.Identity, cameraView, cameraProjection, color, null,
                PrimitiveType.TriangleList, Vertices, SolidIndices, false);
        }
Ejemplo n.º 7
0
        public static void DrawWireframe(
            PrimitiveDrawer primitiveDrawer, Vector3 cameraPosition,
            Matrix cameraView, Matrix cameraProjection,
            Vector3 center, Vector3 normal, float radius,
            Color color, bool fadeBackFace)
        {
            // Calculate basis vectors.
            Vector3 from = Vector3.Cross(normal, Vector3.Up);

            if (from.LengthSquared() < 0.0001f)
            {
                from = Vector3.Cross(normal, Vector3.Right);
            }
            from.Normalize();

            // We need two vertices per line, so we can allocate our vertices.
            const int numSegments = 64;
            const int numLines    = numSegments + 1;
            var       vertices    = new VertexPositionColor[numLines * 2];

            // Calculate initial orientation.
            Quaternion rotation = Quaternion.CreateFromAxisAngle(normal, MathHelper.TwoPi / (numSegments - 1));

            // Compute vertex positions.
            Vector3 edge = from * radius;

            for (int i = 0; i < numSegments; i++)
            {
                // Calculate line positions.
                Vector3 start = center + edge;
                edge = Vector3.Transform(edge, rotation);
                Vector3 end = center + edge;

                // Calculate line normal.
                Vector3 cameraToEdge = start - cameraPosition;
                var     lineColor    = color;
                if (fadeBackFace && Vector3.Dot(cameraToEdge, edge) > 0)
                {
                    lineColor = Color.FromNonPremultiplied(color.R, color.G, color.B, 25);
                }

                vertices[(i * 2) + 0] = new VertexPositionColor(start, lineColor);
                vertices[(i * 2) + 1] = new VertexPositionColor(end, lineColor);
            }

            primitiveDrawer.Draw(Matrix.Identity, cameraView, cameraProjection,
                                 Color.White, null, PrimitiveType.LineList, vertices, false);
        }
Ejemplo n.º 8
0
        public static void DrawSolid(PrimitiveDrawer primitiveDrawer, Matrix cameraView, Matrix cameraProjection,
                                     Vector3[] corners, Color color)
        {
            if (corners == null || corners.Length != 4)
            {
                throw new ArgumentException("corners");
            }

            Vertices[0].Position = corners[0];
            Vertices[1].Position = corners[1];
            Vertices[2].Position = corners[2];
            Vertices[3].Position = corners[3];

            primitiveDrawer.Draw(Matrix.Identity, cameraView, cameraProjection, color, null,
                                 PrimitiveType.TriangleList, Vertices, SolidIndices, false);
        }
Ejemplo n.º 9
0
        public static void DrawWireframe(
			PrimitiveDrawer primitiveDrawer, Vector3 cameraPosition,
			Matrix cameraView, Matrix cameraProjection,
			Vector3 center, Vector3 normal, float radius,
			Color color, bool fadeBackFace)
        {
            // Calculate basis vectors.
            Vector3 from = Vector3.Cross(normal, Vector3.Up);
            if (from.LengthSquared() < 0.0001f)
                from = Vector3.Cross(normal, Vector3.Right);
            from.Normalize();

            // We need two vertices per line, so we can allocate our vertices.
            const int numSegments = 64;
            const int numLines = numSegments + 1;
            var vertices = new VertexPositionColor[numLines * 2];

            // Calculate initial orientation.
            Quaternion rotation = Quaternion.CreateFromAxisAngle(normal, MathHelper.TwoPi / (numSegments - 1));

            // Compute vertex positions.
            Vector3 edge = from * radius;
            for (int i = 0; i < numSegments; i++)
            {
                // Calculate line positions.
                Vector3 start = center + edge;
                edge = Vector3.Transform(edge, rotation);
                Vector3 end = center + edge;

                // Calculate line normal.
                Vector3 cameraToEdge = start - cameraPosition;
                var lineColor = color;
                if (fadeBackFace && Vector3.Dot(cameraToEdge, edge) > 0)
                    lineColor = Color.FromNonPremultiplied(color.R, color.G, color.B, 25);

                vertices[(i * 2) + 0] = new VertexPositionColor(start, lineColor);
                vertices[(i * 2) + 1] = new VertexPositionColor(end, lineColor);
            }

            primitiveDrawer.Draw(Matrix.Identity, cameraView, cameraProjection,
                Color.White, null, PrimitiveType.LineList, vertices, false);
        }
Ejemplo n.º 10
0
        public static void DrawWireframe(PrimitiveDrawer primitiveDrawer, Vector3 cameraPosition, Matrix cameraView, Matrix cameraProjection,
			Vector3 center, Vector3 size, Quaternion rotation, Color color)
        {
            var world = Matrix.CreateScale(size) * Matrix.CreateFromQuaternion(rotation) * Matrix.CreateTranslation(center);

            var vertices = new VertexPositionColor[WireframeLines.Length * 2];
            for (int i = 0; i < WireframeLines.Length; i++)
            {
                var transformedLine = WireframeLine.Transform(WireframeLines[i], world);
                Vector3 cameraToLine = Vector3.Normalize(((transformedLine.Point1 + transformedLine.Point2) / 2) - cameraPosition);

                Color lineColor = color;
                if (!IsCameraFacing(cameraToLine, transformedLine.FaceNormal1) && !IsCameraFacing(cameraToLine, transformedLine.FaceNormal2))
                    lineColor = Color.FromNonPremultiplied(color.R, color.G, color.B, 25);

                vertices[i * 2] = new VertexPositionColor(transformedLine.Point1, lineColor);
                vertices[(i * 2) + 1] = new VertexPositionColor(transformedLine.Point2, lineColor);
            }

            primitiveDrawer.Draw(Matrix.Identity, cameraView, cameraProjection,
                Color.White, null, PrimitiveType.LineList, vertices, false);
        }