Beispiel #1
0
 public override void Draw()
 {
     for (int i = 0; i < lineverts.Length; i++)
     {
         lineverts[i].Color = GlobalLineColor.GetValueOrDefault(Color.Black);
     }
     for (int i = 0; i < vertices.Length; i++)
     {
         vertices[i].Color = GlobalFillColor.GetValueOrDefault(Color.Transparent);
     }
     foreach (EffectPass pass in BasicEffect.CurrentTechnique.Passes)
     {
         pass.Apply();
         BasicEffect.GraphicsDevice.DrawUserPrimitives <VertexPositionColor>(PrimitiveType.TriangleList, vertices, 0, 51, VertexPositionColor.VertexDeclaration);
         BasicEffect.GraphicsDevice.DrawUserPrimitives <VertexPositionColor>(PrimitiveType.LineStrip, lineverts, 0, lineverts.Length - 1);
     }
 }
Beispiel #2
0
        // new input for painting color.
        //public Color FillColor;
        //public Color LineColor;

        public CircleAnnotation(float radius, Vector3 startPosition, Vector3 normal)
        {
            Vector3 b1     = Vector3.Cross(normal, Vector3.UnitY);
            float   length = b1.Length();

            if (length < 0.05)
            {
                b1 = Vector3.Cross(normal, Vector3.UnitX);
                b1.Normalize();
            }
            else
            {
                b1 = b1 * (1f / length);
            }
            Vector3 b2 = Vector3.Cross(b1, normal);

            vertices = new VertexPositionColor[153];

            //new code to draw triangle strips
            vertices[0].Position = startPosition;


            vertices[0].Color = GlobalFillColor.GetValueOrDefault(Color.Black);


            for (int i = 1; i < vertices.Length - 1; i++)
            {
                if (i % 3 == 0)
                {
                    vertices[i].Position = startPosition;

                    vertices[i].Color = GlobalFillColor.GetValueOrDefault(Color.Black);
                }
                else if ((i >= 3) && (vertices[i - 1].Position == startPosition))
                {
                    vertices[i].Position = vertices[i - 2].Position;


                    //vertices[i].Color = GlobalFillColor.GetValueOrDefault(Color.Transparent);
                }
                else
                {
                    float angle = (float)(((float)i / (vertices.Length - 1)) * Math.PI * 2);
                    vertices[i].Position = (b1 * (float)Math.Cos(angle) * radius) + (b2 * (float)Math.Sin(angle) * radius) + startPosition;

                    //vertices[i].Color = GlobalFillColor.GetValueOrDefault(Color.Transparent);
                }
            }
            vertices[vertices.Length - 1] = vertices[1];
            vertices[vertices.Length - 2] = vertices[149];
            vertices[vertices.Length - 3] = vertices[0];


            lineverts = new VertexPositionColor[50];
            for (int i = 0; i < lineverts.Length - 1; i++)
            {
                float angle = (float)(((float)i / (lineverts.Length - 1)) * Math.PI * 2);
                lineverts[i].Position = (b1 * (float)Math.Cos(angle) * radius) + (b2 * (float)Math.Sin(angle) * radius) + startPosition;

                //lineverts[i].Color = GlobalLineColor.GetValueOrDefault(Color.Transparent);
            }
            lineverts[lineverts.Length - 1] = lineverts[0];
        }