Exemplo n.º 1
0
        public void DrawAgroLine(SlimDX.Vector3 newCenter, float heading, float width, float height, Color color, Color pointColor)
        {
            float heightBack = width;

            float diag = (float)Math.Sqrt(height * height + (width * width) / 4);
            float diagBack = (float)Math.Sqrt(heightBack * heightBack + width * width) / 2;

            float subangle = (float)Math.Atan2(width / 2, height / 2);


            float h = (float)(((Math.PI * 2) - heading) + (Math.PI / 2));

            float r1 = h - subangle;
            float r2 = h + ((float)Math.PI / 4) + (float)Math.PI;
            float r3 = h - ((float)Math.PI / 4) + (float)Math.PI;
            float r4 = h + subangle;

            _vertexBuffer[0] = new ColoredVertex(newCenter, pointColor);
            _vertexBuffer[1] = new ColoredVertex(newCenter + new Vector3((float)Math.Cos(r1) * diag, 0, (float)Math.Sin(r1) * diag), pointColor);
            _vertexBuffer[2] = new ColoredVertex(newCenter + new Vector3((float)Math.Cos(r2) * diagBack, 0, (float)Math.Sin(r2) * diagBack), color);
            _vertexBuffer[3] = new ColoredVertex(newCenter + new Vector3((float)Math.Cos(r3) * diagBack, 0, (float)Math.Sin(r3) * diagBack), color);
            _vertexBuffer[4] = new ColoredVertex(newCenter + new Vector3((float)Math.Cos(r4) * diag, 0, (float)Math.Sin(r4) * diag), pointColor);
            _vertexBuffer[5] = _vertexBuffer[1];

            SetDeclaration();
            Device.DrawUserPrimitives(PrimitiveType.TriangleFan, 4, _vertexBuffer);
        }
Exemplo n.º 2
0
        public void DrawCircleWithPoint(SlimDX.Vector3 center, float heading, float radius, Color color, Color pointColor)
        {
            int slices = 30;
            var radsPerSlice = (float)(Math.PI * 2 / slices);

            _vertexBuffer[0] = new ColoredVertex(center, color);
            _vertexBuffer[1] = new ColoredVertex(center + new Vector3(radius, 0, 0), color);

            double h = ((Math.PI * 2) - heading) + (Math.PI / 2);
            if (h > (Math.PI * 2))
                h = h - (Math.PI * 2);

            for (int i = 0; i < slices; i++)
            {
                bool watchAt = (i * radsPerSlice) < h && h < ((i + 1) * radsPerSlice);

                var sine = (float)Math.Sin((i + 1) * radsPerSlice);
                var cosine = (float)Math.Cos((i + 1) * radsPerSlice);

                _vertexBuffer[2 + i] =
                    new ColoredVertex(center + new Vector3(cosine * radius, 0, sine * radius),
                        watchAt ? pointColor.ToArgb() : color.ToArgb());
            }

            SetDeclaration();
            Device.DrawUserPrimitives(PrimitiveType.TriangleFan, slices, _vertexBuffer);
        }