/// <summary> /// Returns color of normal /// </summary> /// <param name="c"></param> /// <param name="normals"></param> /// <param name="material"></param> /// <returns></returns> private Color GetNormalColor(LVDCollision c, Vector2 normals, LVDCollisionMaterial material) { float angle = (float)(Math.Atan2(normals.Y, normals.X) * 180 / Math.PI); if (c.PassThrough) { return(Color.FromArgb(128, Color.Yellow)); } else if (material.GetFlag(4) && ((angle <= 0 && angle >= -70) || (angle <= -110 && angle >= -180) || angle == 180)) { return(Color.FromArgb(128, Color.Purple)); } else if ((angle <= 0 && angle >= -70) || (angle <= -110 && angle >= -180) || angle == 180) { return(Color.FromArgb(128, Color.Lime)); } else if (normals.Y < 0) { return(Color.FromArgb(128, Color.Red)); } else { return(Color.FromArgb(128, Color.Cyan)); } }
/// <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; } }
/// <summary> /// returns color of Collision Material /// </summary> /// <param name="mat"></param> /// <returns></returns> private Color GetMatlColor(LVDCollisionMaterial mat) { if (PropertyGrid.SelectedObject == mat) { return(Color.FromArgb(255, (int)(FlashColor.X * 255), (int)(FlashColor.Y * 255), (int)(FlashColor.Z * 255))); } switch (mat.Physics) { case CollisionMatType.Basic: return(Color.AliceBlue); case CollisionMatType.Brick: return(Color.SaddleBrown); case CollisionMatType.Cloud: return(Color.FromArgb(0xFF, 0xF6, 0x9A, 0xB0)); case CollisionMatType.Alien: return(Color.DarkGreen); case CollisionMatType.Cardboard: return(Color.SandyBrown); case CollisionMatType.Carpet: return(Color.PaleVioletRed); case CollisionMatType.Electroplankton: return(Color.DarkSeaGreen); case CollisionMatType.GameWatch: return(Color.LightGray); case CollisionMatType.Grass: return(Color.ForestGreen); case CollisionMatType.Grate: return(Color.Gray); case CollisionMatType.Hazard2SSEOnly: return(Color.Gray); case CollisionMatType.Hazard3SSEOnly: return(Color.Gray); case CollisionMatType.HeavyMetal: return(Color.LightGray); case CollisionMatType.Homerun: return(Color.LawnGreen); case CollisionMatType.Hurt: return(Color.IndianRed); case CollisionMatType.Ice: return(Color.CornflowerBlue); case CollisionMatType.LightMetal: return(Color.LightGray); case CollisionMatType.MasterFortress: return(Color.DarkSlateGray); case CollisionMatType.NES8Bit: return(Color.Gray); case CollisionMatType.Oil: return(Color.DarkSlateGray); case CollisionMatType.Rock: return(Color.RosyBrown); case CollisionMatType.Sand: return(Color.SandyBrown); case CollisionMatType.Snow: return(Color.LightBlue); case CollisionMatType.Soft: return(Color.LightPink); case CollisionMatType.Soil: return(Color.Brown); case CollisionMatType.SpikesTargetTest: return(Color.IndianRed); case CollisionMatType.Wood: return(Color.Brown); default: return(Color.Black); } }
/// <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(); }
public void Pick(Ray ray) { if (!IsActive) { return; } PropertyGrid.SelectedObject = null; var depthPicked = ray.GetPlaneIntersection(-Vector3.UnitZ, new Vector3(0, 0, -PlatformWidth / 2)); Picked = ray.GetPlaneIntersection(-Vector3.UnitZ, Vector3.Zero); Vector2 nearestLine; float closest = float.MaxValue; LVDCollisionMaterial collisionMat = null; foreach (var point in LVD.GeneralPoints) { if (CrossMath.FastDistance(Picked, new Vector3(point.X, point.Y, point.Z), PickRange * 2.5f)) { PropertyGrid.SelectedObject = point; return; } } foreach (var bound in LVD.CameraBounds) { if (Ray.CheckBoundHit(Picked.Xy, new Vector2(bound.Left, bound.Top), new Vector2(bound.Right, bound.Bottom), PickRange)) { PropertyGrid.SelectedObject = bound; return; } } foreach (var bound in LVD.BlastZoneBounds) { if (Ray.CheckBoundHit(Picked.Xy, new Vector2(bound.Left, bound.Top), new Vector2(bound.Right, bound.Bottom), PickRange)) { PropertyGrid.SelectedObject = bound; return; } } foreach (var bound in LVD.ShrunkBlastZoneBounds) { if (Ray.CheckBoundHit(Picked.Xy, new Vector2(bound.Left, bound.Top), new Vector2(bound.Right, bound.Bottom), PickRange)) { PropertyGrid.SelectedObject = bound; return; } } foreach (var bound in LVD.ShrunkCameraBounds) { if (Ray.CheckBoundHit(Picked.Xy, new Vector2(bound.Left, bound.Top), new Vector2(bound.Right, bound.Bottom), PickRange)) { PropertyGrid.SelectedObject = bound; return; } } foreach (var spawn in LVD.Spawns) { if (CrossMath.FastDistance(Picked, new Vector3(spawn.X, spawn.Y, 0), PickRange * 2.5f)) { PropertyGrid.SelectedObject = spawn; return; } } foreach (var spawn in LVD.Respawns) { if (CrossMath.FastDistance(Picked, new Vector3(spawn.X, spawn.Y, 0), PickRange * 2.5f)) { PropertyGrid.SelectedObject = spawn; return; } } foreach (var col in LVD.Collisions) { for (int i = 0; i < col.Vertices.Count; i++) { var vert = col.Vertices[i]; if (i < col.Materials.Count) { var vert2 = col.Vertices[i + 1]; var dis = Ray.GetDistanceToSegment(depthPicked.Xy, new Vector2(vert.X, vert.Y), new Vector2(vert2.X, vert2.Y), out nearestLine); if (dis < PlatformWidth / 4 & dis < closest) { closest = dis; collisionMat = col.Materials[i]; } } if (CrossMath.FastDistance(Picked, new Vector3(vert.X, vert.Y, 0), PickRange)) { PropertyGrid.SelectedObject = vert; return; } } } if (PropertyGrid.SelectedObject == null && collisionMat != null) { PropertyGrid.SelectedObject = collisionMat; } }