Ejemplo n.º 1
0
        protected void DrawSelectionMarkers(Canvas canvas, IEnumerable<ObjectEditorSelObj> obj)
        {
            // Determine turned Camera axes for angle-independent drawing
            Vector2 catDotX, catDotY;
            float camAngle = this.CameraObj.Transform.Angle;
            MathF.GetTransformDotVec(camAngle, out catDotX, out catDotY);
            Vector3 right = new Vector3(1.0f, 0.0f, 0.0f);
            Vector3 down = new Vector3(0.0f, 1.0f, 0.0f);
            MathF.TransformDotVec(ref right, ref catDotX, ref catDotY);
            MathF.TransformDotVec(ref down, ref catDotX, ref catDotY);

            canvas.PushState();
            canvas.State.ZOffset = -1.0f;
            foreach (ObjectEditorSelObj selObj in obj)
            {
                if (!selObj.HasTransform) continue;
                Vector3 posTemp = selObj.Pos;
                float scaleTemp = 1.0f;
                float radTemp = selObj.BoundRadius;

                if (!canvas.DrawDevice.IsCoordInView(posTemp, radTemp)) continue;

                // Draw selection marker
                if (selObj.ShowPos)
                {
                    canvas.DrawDevice.PreprocessCoords(ref posTemp, ref scaleTemp);
                    posTemp.Z = 0.0f;
                    {
                        ColorRgba color = canvas.State.ColorTint * canvas.State.Material.MainColor;
                        VertexC1P3[] vertices = new VertexC1P3[4];
                        vertices[0].Pos = posTemp - right * 5.0f;
                        vertices[1].Pos = posTemp + right * 5.0f;
                        vertices[2].Pos = posTemp - down * 5.0f;
                        vertices[3].Pos = posTemp + down * 5.0f;
                        vertices[0].Color = color;
                        vertices[1].Color = color;
                        vertices[2].Color = color;
                        vertices[3].Color = color;
                        canvas.DrawDevice.AddVertices(canvas.State.Material, VertexMode.Lines, vertices);
                    }
                }

                // Draw angle marker
                if (selObj.ShowAngle)
                {
                    posTemp = selObj.Pos +
                        radTemp * right * MathF.Sin(selObj.Angle - camAngle) -
                        radTemp * down * MathF.Cos(selObj.Angle - camAngle);
                    canvas.DrawLine(selObj.Pos.X, selObj.Pos.Y, selObj.Pos.Z, posTemp.X, posTemp.Y, posTemp.Z);
                }

                // Draw boundary
                if (selObj.ShowBoundRadius && radTemp > 0.0f)
                    canvas.DrawCircle(selObj.Pos.X, selObj.Pos.Y, selObj.Pos.Z, radTemp);
            }
            canvas.PopState();
        }
Ejemplo n.º 2
0
        private void DrawHorizontalGraph(Canvas canvas, float[] values, ColorRgba[] colors, ref VertexC1P3[] vertices, float x, float y, float w, float h)
        {
            if (h > 0.0f) h--;
            if (h < 0.0f) h++;

            IDrawDevice device = canvas.DrawDevice;

            ColorRgba baseColor = canvas.State.ColorTint * canvas.State.MaterialDirect.MainColor;
            float sampleXRatio = w / (float)(values.Length - 1);

            if (vertices == null)
                vertices = new VertexC1P3[MathF.Max(values.Length, 16)];
            else if (vertices.Length < values.Length)
                vertices = new VertexC1P3[MathF.Max(vertices.Length * 2, values.Length, 16)];

            for (int i = 0; i < values.Length; i++)
            {
                vertices[i].Pos.X = x + 0.5f + i * sampleXRatio;
                vertices[i].Pos.Y = y + 0.5f + (1.0f - values[i]) * h;
                vertices[i].Pos.Z = 0.0f;
                vertices[i].Color = baseColor * colors[i];
            }
            device.AddVertices(canvas.State.MaterialDirect, VertexMode.LineStrip, vertices, values.Length);
        }
Ejemplo n.º 3
0
        protected internal override void OnCollectDrawcalls(Canvas canvas)
        {
            base.OnCollectDrawcalls(canvas);
            IDrawDevice device = canvas.DrawDevice;

            float scaleTemp = 1.0f;
            Vector3 posTemp = Vector3.Zero;
            device.PreprocessCoords(ref posTemp, ref scaleTemp);
            if (posTemp.Z <= canvas.DrawDevice.NearZ) return;

            float alphaTemp = 0.5f;
            alphaTemp *= (float)Math.Min(1.0d, ((posTemp.Z - device.NearZ) / (device.NearZ * 5.0f)));
            if (alphaTemp <= 0.005f) return;

            float stepTemp = 4.0f * this.gridSize * MathF.Max(0.25f, MathF.Pow(2.0f, -MathF.Round(1.0f - MathF.Log(1.0f / scaleTemp, 2.0f))));
            float scaledStep = stepTemp * scaleTemp;
            float viewBoundRad = device.TargetSize.Length * 0.5f;
            int lineCount = (2 + (int)MathF.Ceiling(viewBoundRad * 2 / scaledStep)) * 4;

            ColorRgba gridColor = this.FgColor.WithAlpha(alphaTemp);
            VertexC1P3[] vertices = new VertexC1P3[lineCount * 4];

            float beginPos;
            float pos;
            int lineIndex;
            int vertOff = 0;

            beginPos = posTemp.X % scaledStep - (lineCount / 8) * scaledStep;
            pos = beginPos;
            lineIndex = 0;
            for (int x = 0; x < lineCount; x++)
            {
                bool primaryLine = lineIndex % 4 == 0;
                bool secondaryLine = lineIndex % 4 == 2;

                vertices[vertOff + x * 2 + 0].Color = primaryLine ? gridColor : gridColor.WithAlpha(alphaTemp * (secondaryLine ? 0.5f : 0.25f));

                vertices[vertOff + x * 2 + 0].Pos.X = pos;
                vertices[vertOff + x * 2 + 0].Pos.Y = -viewBoundRad;
                vertices[vertOff + x * 2 + 0].Pos.Z = posTemp.Z + 1;

                vertices[vertOff + x * 2 + 1] = vertices[vertOff + x * 2 + 0];
                vertices[vertOff + x * 2 + 1].Pos.Y = viewBoundRad;

                pos += scaledStep / 4;
                lineIndex++;
            }
            vertOff += lineCount * 2;

            beginPos = posTemp.Y % scaledStep - (lineCount / 8) * scaledStep;
            pos = beginPos;
            lineIndex = 0;
            for (int y = 0; y < lineCount; y++)
            {
                bool primaryLine = lineIndex % 4 == 0;
                bool secondaryLine = lineIndex % 4 == 2;

                vertices[vertOff + y * 2 + 0].Color = primaryLine ? gridColor : gridColor.WithAlpha(alphaTemp * (secondaryLine ? 0.5f : 0.25f));

                vertices[vertOff + y * 2 + 0].Pos.X = -viewBoundRad;
                vertices[vertOff + y * 2 + 0].Pos.Y = pos;
                vertices[vertOff + y * 2 + 0].Pos.Z = posTemp.Z + 1;

                vertices[vertOff + y * 2 + 1] = vertices[vertOff + y * 2 + 0];
                vertices[vertOff + y * 2 + 1].Pos.X = viewBoundRad;

                pos += scaledStep / 4;
                lineIndex++;
            }
            vertOff += lineCount * 2;

            device.AddVertices(new BatchInfo(DrawTechnique.Alpha, ColorRgba.White), VertexMode.Lines, vertices);
        }