示例#1
0
    public void UpdatePivot()
    {
        if (keyboard[Key.D] && !keyboard[Key.LControl])
        {
            if (keyboard[Key.LControl])
            {
                pivot = new Vector2((float)Math.Round(mouse.Position.X), (float)Math.Round(mouse.Position.Y));
            }
            else if (keyboard[Key.C] && editor.SelectedVertices.Count > 0)
            {
                pivot = null;

                EVertex closestVertex = editor.SelectedVertices[0];
                foreach (EVertex v in editor.SelectedVertices)
                {
                    if ((v.Position - mouse.Position.Xy).Length < (closestVertex.Position - mouse.Position.Xy).Length)
                    {
                        closestVertex = v;
                    }
                }

                pivotVertex = closestVertex;
            }
            else
            {
                pivot = mouse.Position.Xy;
            }
        }
    }
示例#2
0
    public EMesh(Layer l, Editor e)
    {
        editor = e;
        layer  = l;

        mesh = new Mesh(MeshProgram);
        mesh.GetAttribute <Vector3>("vertexPosition").Data = new Vector3[]
        {
            new Vector3(-0.5f, -0.5f, 0f),
            new Vector3(0.5f, -0.5f, 0f),
            new Vector3(0.5f, 0.5f, 0f),
            new Vector3(-0.5f, 0.5f, 0f),
        };

        previewModel = new Model();
        polygon      = new Polygon();

        vertices[0] = new EVertex(editor, this, mesh.Vertices[0], new Vector2(-0.5f, -0.5f));
        vertices[1] = new EVertex(editor, this, mesh.Vertices[1], new Vector2(0.5f, -0.5f));
        vertices[2] = new EVertex(editor, this, mesh.Vertices[2], new Vector2(0.5f, 0.5f));
        vertices[3] = new EVertex(editor, this, mesh.Vertices[3], new Vector2(-0.5f, 0.5f));

        vertices[0].Color = new Vector3(0f, 0f, 0f);
        vertices[1].Color = new Vector3(0f, 0f, 0f);
        vertices[2].Color = new Vector3(1f, 1f, 1f);
        vertices[3].Color = new Vector3(1f, 1f, 1f);
    }
示例#3
0
    void Manipulate()
    {
        Vector2 origin = scaleOrigin.Value;
        Vector2 scale  = tool.ScaleFactor;

        for (int i = 0; i < vertexOriginPosition.Length; i++)
        {
            Vector2 delta = vertexOriginPosition[i] - origin;

            Vector2 scaleX = Vector2.Dot(delta, scaleNormalX.Value) * scaleNormalX.Value;
            Vector2 scaleY = Vector2.Dot(delta, scaleNormalY.Value) * scaleNormalY.Value;

            delta = scaleX * scale.X + scaleY * scale.Y;

            EVertex v = editor.SelectedVertices[i];
            v.Position = origin + delta;
        }
    }
示例#4
0
 public PaintInfo(EVertex v, ColorHSL b, ColorHSL e)
 {
     vertex = v;
     begin  = b;
     end    = e;
 }
示例#5
0
    public override void Logic()
    {
        if (mouse.WheelDelta != 0)
        {
            if (keyboard.HasPrefix(KeyPrefix.Alt))
            {
                brush.Size += mouse.WheelDelta * 0.12f;
                if (brush.Size < 0)
                {
                    brush.Size = 0f;
                }

                if (brushForm != null)
                {
                    brushForm.Size = brush.Size;
                }
            }
            if (keyboard.HasPrefix(KeyPrefix.Control))
            {
                brush.Opacity += mouse.WheelDelta * 0.05f;
                brush.Opacity  = MathHelper.Clamp(brush.Opacity, 0, 1);

                if (brushForm != null)
                {
                    brushForm.Opacity = brush.Opacity;
                }
            }
            if (keyboard.HasPrefix(KeyPrefix.Shift))
            {
                brush.Hardness += mouse.WheelDelta * 0.05f;
                brush.Hardness  = MathHelper.Clamp(brush.Hardness, 0, 1);

                if (brushForm != null)
                {
                    brushForm.Hardness = brush.Hardness;
                }
            }
        }

        if (mouse[MouseButton.Left] && editor.form.Focused)
        {
            foreach (EVertex v in SelectedVertices)
            {
                float weight = 1 - (v.Position - Position).Length / brush.Size;

                if (weight < 1 - brush.Hardness)
                {
                    weight = weight / (1f - brush.Hardness);
                }
                else
                {
                    weight = 1f;
                }

                if (vertexData.ContainsKey(v))
                {
                    if (vertexData[v].Weight > weight)
                    {
                        continue;
                    }

                    vertexData[v].Weight = weight;
                }
                else
                {
                    vertexData.Add(v, new PaintData(weight, v.HSL));
                }

                v.Paint(ColorHSL.Blend(vertexData[v].Origin, brush.HSL, weight * brush.Opacity));

                DebugForm.debugString = "Weight: " + weight.ToString();
            }
        }
        if (!mouse[MouseButton.Left] && vertexData.Count > 0)
        {
            EVertex[]  vertices = new EVertex[vertexData.Count];
            ColorHSL[] begins   = new ColorHSL[vertexData.Count];
            ColorHSL[] ends     = new ColorHSL[vertexData.Count];

            int index = 0;
            foreach (KeyValuePair <EVertex, PaintData> data in vertexData)
            {
                vertices[index] = data.Key;
                begins[index]   = data.Value.Origin;
                ends[index]     = data.Key.HSL;

                index++;
            }

            editor.ActiveLayers[0].History.Add(new PaintAction(vertices, begins, ends, editor.ActiveHistory));
            vertexData.Clear();
        }
    }
示例#6
0
 public void CopyFrom(EVertex v)
 {
     Position = v.Position;
     HSL      = v.HSL;
 }
示例#7
0
 public void ResetPivot()
 {
     pivot       = null;
     pivotVertex = null;
 }
示例#8
0
    public bool Intersects(EVertex v)
    {
        BakePolygon();

        return(v.Intersects(polygon));
    }
 public TranslateInfo(EVertex v, Vector2 b, Vector2 e)
 {
     vertex = v;
     begin  = b;
     end    = e;
 }