Ejemplo n.º 1
0
        /// <summary>
        /// adds new point after vector
        /// </summary>
        /// <param name="v"></param>
        private void AddNewPoint(LVDVector2 v)
        {
            foreach (var col in LVD.Collisions)
            {
                int index = col.Vertices.IndexOf(v);
                if (index == -1)
                {
                    continue;
                }

                if (index == col.Vertices.Count - 1)
                {
                    var newPoint    = new LVDVector2(v.X + 3, v.Y);
                    var newMaterial = new LVDCollisionMaterial();
                    newMaterial.Physics = col.Materials[index - 1].Physics;
                    col.Vertices.Add(newPoint);
                    col.Normals.Add(LVDVector2.GenerateNormal(v, newPoint));
                    col.Materials.Add(newMaterial);
                    PropertyGrid.SelectedObject = newPoint;
                }
                else
                {
                    var newPoint    = new LVDVector2((v.X + col.Vertices[index + 1].X) / 2, (v.Y + col.Vertices[index + 1].Y) / 2);
                    var newMaterial = new LVDCollisionMaterial();
                    newMaterial.Physics = col.Materials[index].Physics;
                    var newNormal = LVDVector2.GenerateNormal(newPoint, col.Vertices[index + 1]);
                    col.Normals.Insert(index + 1, newNormal);
                    col.Materials.Insert(index + 1, newMaterial);
                    col.Vertices.Insert(index + 1, newPoint);
                    PropertyGrid.SelectedObject = newPoint;
                }

                break;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// deletes lvdvector2
        /// </summary>
        /// <param name="v"></param>
        private void DeleteVertex(LVDVector2 v)
        {
            LVDCollision remove = null;

            foreach (var col in LVD.Collisions)
            {
                int index = col.Vertices.IndexOf(v);
                if (index == -1)
                {
                    continue;
                }

                if (index >= 1)
                {
                    PropertyGrid.SelectedObject = col.Vertices[index - 1];
                }

                if (col.Normals.Count > 0)
                {
                    if (index == col.Normals.Count)
                    {
                        col.Normals.RemoveAt(index - 1);
                        col.Materials.RemoveAt(index - 1);
                    }
                    else
                    {
                        col.Normals.RemoveAt(index);
                        col.Materials.RemoveAt(index);
                    }
                }

                col.Vertices.RemoveAt(index);

                if (index == col.Vertices.Count)
                {
                    index--;
                }

                if (col.Normals.Count > 0 && index > 0)
                {
                    col.Normals[index - 1] = LVDVector2.GenerateNormal(col.Vertices[index - 1], col.Vertices[index]);
                }

                if (col.Vertices.Count < 2)
                {
                    remove = col;
                }

                break;
            }

            // remove collision that is marked for removal
            if (remove != null)
            {
                LVD.Collisions.Remove(remove);
                RefreshNodes();
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Renders a collision wall
        /// </summary>
        /// <param name="col"></param>
        /// <param name="p1"></param>
        /// <param name="p2"></param>
        /// <param name="mat"></param>
        /// <param name="normal"></param>
        private void RenderWall(LVDCollision col, LVDVector2 p1, LVDVector2 p2, LVDCollisionMaterial mat, Vector2 normal)
        {
            Vector2 v1  = new Vector2(p1.X, p1.Y);
            Vector2 v2  = new Vector2(p2.X, p2.Y);
            Vector2 mid = (v1 + v2) / 2;
            Vector2 nrm = mid + normal * 3;

            Vector3 p1Color = GetElementColor(p1);
            Vector3 p2Color = GetElementColor(p2);

            if (PropertyGrid.SelectedObject == col)
            {
                p1Color = FlashColor;
                p2Color = FlashColor;
            }

            // material
            var materialColor = GetMatlColor(mat);

            GL.Color4(materialColor.R / 255f, materialColor.G / 255f, materialColor.B / 255f, 0.75f);
            GL.Begin(PrimitiveType.Quads);
            GL.Vertex3(p1.X, p1.Y, 0);
            GL.Vertex3(p1.X, p1.Y, -PlatformWidth);
            GL.Vertex3(p2.X, p2.Y, -PlatformWidth);
            GL.Vertex3(p2.X, p2.Y, 0);
            GL.End();

            GL.LineWidth(2f);
            GL.Begin(PrimitiveType.Lines);

            // point line 1
            GL.Color3(p1Color);
            GL.Vertex3(v1.X, v1.Y, 0);
            GL.Color3(p1Color);
            GL.Vertex3(v1.X, v1.Y, -PlatformWidth);

            // point line 2
            GL.Color3(p2Color);
            GL.Vertex3(v2.X, v2.Y, 0);
            GL.Color3(p2Color);
            GL.Vertex3(v2.X, v2.Y, -PlatformWidth);

            // front line
            GL.Color3(p1Color);
            GL.Vertex3(v1.X, v1.Y, 0);
            GL.Color3(p2Color);
            GL.Vertex3(v2.X, v2.Y, 0);

            // back line
            GL.Color3(p1Color);
            GL.Vertex3(v1.X, v1.Y, -PlatformWidth);
            GL.Color3(p2Color);
            GL.Vertex3(v2.X, v2.Y, -PlatformWidth);

            // normal
            GL.Color3(GetNormalColor(col, normal, mat));
            GL.Vertex3(mid.X, mid.Y, -PlatformWidth / 2);
            GL.Color3(GetNormalColor(col, normal, mat));
            GL.Vertex3(nrm.X, nrm.Y, -PlatformWidth / 2);

            GL.End();
        }
Ejemplo n.º 4
0
        public void Step(SBViewport viewport)
        {
            var mouseP     = viewport.GetMousePosition();
            var deltaMouse = PrevMousePosition - mouseP;

            PrevMousePosition = mouseP;
            if (!IsActive)
            {
                return;
            }
            if (Keyboard.GetState().IsKeyDown(Key.AltLeft))
            {
                if (Keyboard.GetState().IsKeyDown(Key.A))
                {
                    if (!ADown)
                    {
                        ADown = true;

                        if (PropertyGrid.SelectedObject is LVDVector2 v)
                        {
                            AddNewPoint(v);
                        }
                    }
                }
                else
                {
                    ADown = false;
                }
                if (Mouse.GetState().IsButtonDown(MouseButton.Left))
                {
                    if (PropertyGrid.SelectedObject is LVDGeneralPoint point)
                    {
                        point.StartPosition.X -= deltaMouse.X / 4;
                        point.StartPosition.Y += deltaMouse.Y / 4;
                        point.X -= deltaMouse.X / 4;
                        point.Y += deltaMouse.Y / 4;
                        PropertyGrid.SelectedObject = PropertyGrid.SelectedObject;
                    }
                    if (PropertyGrid.SelectedObject is LVDSpawn spawn)
                    {
                        spawn.StartPosition.X -= deltaMouse.X / 4;
                        spawn.StartPosition.Y += deltaMouse.Y / 4;
                        spawn.X -= deltaMouse.X / 4;
                        spawn.Y += deltaMouse.Y / 4;
                        PropertyGrid.SelectedObject = PropertyGrid.SelectedObject;
                    }
                    if (PropertyGrid.SelectedObject is LVDVector2 v)
                    {
                        v.X -= deltaMouse.X / 4;
                        v.Y += deltaMouse.Y / 4;

                        // recalculate normals
                        // is there a better way to do this?
                        foreach (var col in LVD.Collisions)
                        {
                            int index = col.Vertices.IndexOf(v);
                            if (index == -1)
                            {
                                continue;
                            }

                            if (index < col.Normals.Count)
                            {
                                col.Normals[index] = LVDVector2.GenerateNormal(v, col.Vertices[index + 1]);
                            }
                            if (index > 0)
                            {
                                col.Normals[index - 1] = LVDVector2.GenerateNormal(col.Vertices[index - 1], v);
                            }
                            break;
                        }
                        PropertyGrid.SelectedObject = PropertyGrid.SelectedObject;
                    }
                }
            }
            if (Keyboard.GetState().IsKeyDown(Key.Delete))
            {
                if (!DeleteDown)
                {
                    DeleteDown = true;

                    if (PropertyGrid.SelectedObject is LVDVector2 v)
                    {
                        DeleteVertex(v);
                    }
                }
            }
            else
            {
                DeleteDown = false;
            }
        }