public override void draw() { if (_polygonTexture != null) { _level.controller.view.spriteBatch.Draw(_polygonTexture, (_polygonPosition + _level.controller.worldOffset) * _level.controller.scale, _polygonTexture.Bounds, polygonFill, 0f, Vector2.Zero, _level.controller.scale / LevelController.ORIGINAL_SCALE, SpriteEffects.None, _layerDepth + 0.0001f); } // Draw lines and points int count = _headPoint.listCount; Color lineColor = count > 2 ? Color.LightGreen : Color.Red; PointListNode current = _headPoint; while (current != null) { if (current.next != null) { _level.controller.view.drawLine(current.position, current.next.position, lineColor, _layerDepth); } _level.controller.view.drawPoint(current.position, Color.Yellow, _layerDepth); current = current.next; } if (count > 2) { _level.controller.view.drawLine(_headPoint.position, _headPoint.tail.position, Color.Purple, _layerDepth); } }
public EditorRopeActor(EditorLevel level, XElement data) : base(level, data) { _doubleAnchor = Loader.loadBool(data.Attribute("double_anchor"), false); _ropeMaterialUID = Loader.loadString(data.Attribute("rope_material_uid"), "default_rope_material"); _nodeA = new PointListNode(Loader.loadVector2(data.Attribute("point_a"), Vector2.Zero)); _nodeB = new PointListNode(Loader.loadVector2(data.Attribute("point_b"), Vector2.Zero)); _selectedPoints = new List <PointListNode>(); }
public EditorRopeActor(EditorLevel level, XElement data) : base(level, data) { _doubleAnchor = Loader.loadBool(data.Attribute("double_anchor"), false); _ropeMaterialUID = Loader.loadString(data.Attribute("rope_material_uid"), "default_rope_material"); _nodeA = new PointListNode(Loader.loadVector2(data.Attribute("point_a"), Vector2.Zero)); _nodeB = new PointListNode(Loader.loadVector2(data.Attribute("point_b"), Vector2.Zero)); _selectedPoints = new List<PointListNode>(); }
public EditorWaypointActor(EditorLevel level) : base(level, ActorType.Waypoint, level.getUnusedActorId()) { _selectedPoints = new List<PointListNode>(); _layerDepth = 0.1f; _uid = "default_waypoint"; Vector2 worldMouse = level.controller.worldMouse; _headPoint = new PointListNode(worldMouse + new Vector2(-0.5f, 0f)); _selectedPoints.Add(_headPoint); _selectedPoints.Add(_headPoint.tail.insertAfter(worldMouse + new Vector2(0.5f, 0f))); }
public EditorWaypointActor(EditorLevel level) : base(level, ActorType.Waypoint, level.getUnusedActorId()) { _selectedPoints = new List <PointListNode>(); _layerDepth = 0.1f; _uid = "default_waypoint"; Vector2 worldMouse = level.controller.worldMouse; _headPoint = new PointListNode(worldMouse + new Vector2(-0.5f, 0f)); _selectedPoints.Add(_headPoint); _selectedPoints.Add(_headPoint.tail.insertAfter(worldMouse + new Vector2(0.5f, 0f))); }
public EditorRopeActor(EditorLevel level) : base(level, ActorType.Rope, level.controller.getUnusedActorID()) { Vector2 worldMouse = _level.controller.worldMouse; _nodeA = new PointListNode(worldMouse + new Vector2(0f, -0.5f)); _nodeB = new PointListNode(worldMouse + new Vector2(0f, 0.5f)); _selectedPoints = new List <PointListNode>(); _selectedPoints.Add(_nodeA); _selectedPoints.Add(_nodeB); _ropeMaterialUID = "default_rope_material"; _layerDepth = 0.1f; }
public EditorWaypointActor(EditorLevel level, XElement data) : base(level, data) { _selectedPoints = new List<PointListNode>(); _uid = Loader.loadString(data.Attribute("uid"), "default_waypoint"); foreach (XElement pointData in data.Elements("Point")) { if (_headPoint == null) _headPoint = new PointListNode(Loader.loadVector2(pointData, Vector2.Zero)); else _headPoint.tail.insertAfter(Loader.loadVector2(pointData, Vector2.Zero)); } }
public EditorRopeActor(EditorLevel level) : base(level, ActorType.Rope, level.controller.getUnusedActorID()) { Vector2 worldMouse = _level.controller.worldMouse; _nodeA = new PointListNode(worldMouse + new Vector2(0f, -0.5f)); _nodeB = new PointListNode(worldMouse + new Vector2(0f, 0.5f)); _selectedPoints = new List<PointListNode>(); _selectedPoints.Add(_nodeA); _selectedPoints.Add(_nodeB); _ropeMaterialUID = "default_rope_material"; _layerDepth = 0.1f; }
// Remove node from list public void remove() { if (_previous != null) { _previous.next = _next; } if (_next != null) { _next.previous = _previous; } _previous = null; _next = null; }
public EditorPolygonActor(EditorLevel level, ActorType type) : base(level, type, level.controller.getUnusedActorID()) { _selectedPoints = new List <PointListNode>(); _layerDepth = 0.1f; Vector2 worldMouse = level.controller.worldMouse; _headPoint = new PointListNode(worldMouse + new Vector2(0f, -0.5f)); _selectedPoints.Add(_headPoint); _selectedPoints.Add(_headPoint.tail.insertAfter(worldMouse + new Vector2(-0.5f, 0.5f))); _selectedPoints.Add(_headPoint.tail.insertAfter(worldMouse + new Vector2(0.5f, 0.5f))); triangulate(); }
public EditorPolygonActor(EditorLevel level, XElement data) : base(level, data) { _selectedPoints = new List <PointListNode>(); foreach (XElement pointData in data.Elements("Point")) { if (_headPoint == null) { _headPoint = new PointListNode(Loader.loadVector2(pointData, Vector2.Zero)); } else { _headPoint.tail.insertAfter(Loader.loadVector2(pointData, Vector2.Zero)); } } triangulate(); }
// Insert new node (n) after this node (b) // a--b c // \ / // n public PointListNode insertAfter(Vector2 position) { PointListNode n = new PointListNode(position); // Wire up new node n.previous = this; n.next = _next; // Rewire existing links if (_next != null) { _next.previous = n; } _next = n; return(n); }
// Insert new node (n) before this node (c) // a--b c c--b--a // \ / / // n n public PointListNode insertBefore(Vector2 position) { PointListNode n = new PointListNode(position); // Wire up new node n.previous = _previous; n.next = this; // Rewire existing links if (_previous != null) { _previous.next = n; } _previous = n; return(n); }
public EditorWaypointActor(EditorLevel level, XElement data) : base(level, data) { _selectedPoints = new List <PointListNode>(); _uid = Loader.loadString(data.Attribute("uid"), "default_waypoint"); foreach (XElement pointData in data.Elements("Point")) { if (_headPoint == null) { _headPoint = new PointListNode(Loader.loadVector2(pointData, Vector2.Zero)); } else { _headPoint.tail.insertAfter(Loader.loadVector2(pointData, Vector2.Zero)); } } }
public override void draw() { // Draw lines and points int count = _headPoint.listCount; Color lineColor = Color.LightGreen; PointListNode current = _headPoint; while (current != null) { if (current.next != null) { _level.controller.view.drawLine(current.position, current.next.position, lineColor, _layerDepth); } _level.controller.view.drawPoint(current.position, Color.White, _layerDepth); current = current.next; } }
public override bool hitTest(Vector2 testPoint, HitTestCallback callback) { List <IActorComponent> results = new List <IActorComponent>(); // Test points PointListNode current = _headPoint; while (current != null) { if (_level.controller.hitTestPoint(testPoint, current.position)) { results.Add(current); callback(results); return(true); } current = current.next; } // Test line segments current = _headPoint; while (current != null && current.next != null) { PointListNode next = current.next; if (_level.controller.hitTestLine(testPoint, current.position, next.position)) { results.Add(current); results.Add(next); return(callback(results)); } current = current.next; } /* * // Test polygon * if (_level.controller.hitTestPolygon(testPoint, _headPoint.points)) * { * results.Add(this); * return callback(results); * }*/ return(false); }
public override void handleSelectedClick(System.Windows.Forms.MouseButtons button) { // Continue drawing polygon if shift is held if (_level.controller.isKeyHeld(Keys.LeftShift) && _selectedPoints.Count == 1) { if (_selectedPoints[0] == _headPoint) { _headPoint = _headPoint.insertBefore(_level.controller.worldMouse); _selectedPoints.Clear(); _selectedPoints.Add(_headPoint); } else if (_selectedPoints[0] == _headPoint.tail) { _headPoint.tail.insertAfter(_level.controller.worldMouse); _selectedPoints.Clear(); _selectedPoints.Add(_headPoint.tail); } } else { deselect(); } }
public void triangulate() { List <PolygonPoint> points = new List <PolygonPoint>(); PointListNode current = _headPoint; _polygonPosition = current.position; while (current != null) { _polygonPosition = Vector2.Min(current.position, _polygonPosition); points.Add(new PolygonPoint(current.position.X, current.position.Y)); current = current.next; } Polygon polygon = new Polygon(points); P2T.Triangulate(polygon); _primitiveCount = polygon.Triangles.Count; int index = 0; foreach (DelaunayTriangle triangle in polygon.Triangles) { for (int i = 0; i < 3; i++) { _vertices[index++] = new VertexPositionColorTexture( new Vector3(triangle.Points[i].Xf, triangle.Points[i].Yf, 0), Color.White, Vector2.Zero); } } if (_polygonTexture != null) { _polygonTexture.Dispose(); } _polygonTexture = _level.controller.view.renderPolygon(_vertices, _primitiveCount); }
public override void handleSelectedClick(System.Windows.Forms.MouseButtons button) { if ((_selectedConnectionA || _selectedConnectionB) && !_moveActor) { foreach (List <EditorActor> actors in _level.sortedActors.Values) { foreach (EditorActor actor in actors) { if (actor.type == ActorType.Box || actor.type == ActorType.Circle || actor.type == ActorType.Terrain) { PointListNode connectionControl = _selectedConnectionA ? _connectionA : _connectionB; if (actor.hitTest(connectionControl.position, (results) => { if (results.Count > 0) { if (_selectedConnectionA) { _actorA = actor; } else { _actorB = actor; } return(true); } return(false); })) { break; } } } } } deselect(); }
private void initializeControls() { _controlA = new PointListNode(_position + new Vector2(-24f, 0f) / _level.controller.scale); _controlB = new PointListNode(_position + new Vector2(24f, 0f) / _level.controller.scale); }
private void initializeControls(Vector2 pointA, Vector2 pointB) { _nodeA = new PointListNode(pointA); _nodeB = new PointListNode(pointB); }
// Insert new node (n) after this node (b) // a--b c // \ / // n public PointListNode insertAfter(Vector2 position) { PointListNode n = new PointListNode(position); // Wire up new node n.previous = this; n.next = _next; // Rewire existing links if (_next != null) _next.previous = n; _next = n; return n; }
// Insert new node (n) before this node (c) // a--b c c--b--a // \ / / // n n public PointListNode insertBefore(Vector2 position) { PointListNode n = new PointListNode(position); // Wire up new node n.previous = _previous; n.next = this; // Rewire existing links if (_previous != null) _previous.next = n; _previous = n; return n; }
public override void update() { Vector2 worldMouse = _level.controller.worldMouse; Vector2 worldDelta = worldMouse - _level.controller.oldWorldMouse; if (selected) { if (!_level.controller.isKeyHeld(Keys.LeftControl)) { foreach (PointListNode node in _selectedPoints) node.position += worldDelta; } // Insert a point if (_level.controller.isKeyPressed(Keys.OemPlus)) { if (_selectedPoints.Count == 1) { PointListNode newNode = null; if (_selectedPoints[0] == _headPoint) { newNode = _headPoint.insertBefore(worldMouse); _headPoint = newNode; } else if (_selectedPoints[0] == _headPoint.tail) { newNode = _headPoint.tail.insertAfter(worldMouse); } else { newNode = _selectedPoints[0].insertAfter(worldMouse); } _selectedPoints.Clear(); _selectedPoints.Add(newNode); } else if (_selectedPoints.Count == 2) { PointListNode firstNode = _selectedPoints[0].index < _selectedPoints[1].index ? _selectedPoints[0] : _selectedPoints[1]; PointListNode newNode = firstNode.insertAfter(worldMouse); _selectedPoints.Clear(); _selectedPoints.Add(newNode); } } // Remove a point if (_level.controller.isKeyPressed(Keys.OemMinus)) { if (_headPoint.listCount > 3) { if (_selectedPoints.Count == 1) { PointListNode selectionReplacement = null; if (_selectedPoints[0] == _headPoint) { selectionReplacement = _headPoint.next; _headPoint = selectionReplacement; } else if (_selectedPoints[0] == _headPoint.tail) { selectionReplacement = _headPoint.tail.previous; } else { selectionReplacement = _selectedPoints[0].next ?? _selectedPoints[0].previous; } _selectedPoints[0].remove(); _selectedPoints.Clear(); selectionReplacement.position = worldMouse; _selectedPoints.Add(selectionReplacement); } else if (_selectedPoints.Count == 2) { if (_headPoint.listCount > 4) { if (_selectedPoints[0] == _headPoint) _headPoint = _selectedPoints[0].next; else if (_selectedPoints[1] == _headPoint) _headPoint = _selectedPoints[1].next; _selectedPoints[0].remove(); _selectedPoints[1].remove(); deselect(); } } } } // Deselect/delete if (_level.controller.isKeyPressed(Keys.Escape)) deselect(); else if (_level.controller.isKeyPressed(Keys.Delete)) delete(); } else if (_level.controller.selectedActor == null) { // Insert a point if (_level.controller.isKeyPressed(Keys.OemPlus)) { hitTest(worldMouse, (results) => { // Handle insertion on a single point if (results.Count == 1 && results[0] is PointListNode) { (results[0] as PointListNode).insertAfter(worldMouse); return true; } // Handle insertion on line between head and tail if (results.Count == 2 && ((results[0] == _headPoint && results[1] == _headPoint.tail) || (results[0] == _headPoint.tail && results[1] == _headPoint))) { _headPoint.tail.insertAfter(worldMouse); return true; } // Handle insertion on a normal line segment if (results.Count == 2 && results[0] is PointListNode && results[0] is PointListNode) { PointListNode firstNode = ((results[0] as PointListNode).index < (results[1] as PointListNode).index ? results[0] : results[1]) as PointListNode; firstNode.insertAfter(worldMouse); } return false; }); } // Remove a point if (_level.controller.isKeyPressed(Keys.OemMinus)) { if (_headPoint.listCount > 3) { hitTest(worldMouse, (results) => { if (results.Count == 1 && results[0] is PointListNode) { if (results[0] == _headPoint) _headPoint = _headPoint.next; (results[0] as PointListNode).remove(); return true; } return false; }); } } } }
private void initializeControls() { _connectionA = new PointListNode(_position + new Vector2(-24f, 0f) / _level.controller.scale); _connectionB = new PointListNode(_position + new Vector2(24f, 0f) / _level.controller.scale); }
// Remove node from list public void remove() { if (_previous != null) _previous.next = _next; if (_next != null) _next.previous = _previous; _previous = null; _next = null; }
public override void update() { Vector2 worldMouse = _level.controller.worldMouse; Vector2 worldDelta = worldMouse - _level.controller.oldWorldMouse; if (selected) { if (!_level.controller.isKeyHeld(Keys.LeftControl)) { foreach (PointListNode node in _selectedPoints) { node.position += worldDelta; } } // Insert a point if (_level.controller.isKeyPressed(Keys.OemPlus)) { if (_selectedPoints.Count == 1) { PointListNode newNode = null; if (_selectedPoints[0] == _headPoint) { newNode = _headPoint.insertBefore(worldMouse); _headPoint = newNode; } else if (_selectedPoints[0] == _headPoint.tail) { newNode = _headPoint.tail.insertAfter(worldMouse); } else { newNode = _selectedPoints[0].insertAfter(worldMouse); } _selectedPoints.Clear(); _selectedPoints.Add(newNode); } else if (_selectedPoints.Count == 2) { PointListNode firstNode = _selectedPoints[0].index < _selectedPoints[1].index ? _selectedPoints[0] : _selectedPoints[1]; PointListNode newNode = firstNode.insertAfter(worldMouse); _selectedPoints.Clear(); _selectedPoints.Add(newNode); } } // Remove a point if (_level.controller.isKeyPressed(Keys.OemMinus)) { if (_headPoint.listCount > 3) { if (_selectedPoints.Count == 1) { PointListNode selectionReplacement = null; if (_selectedPoints[0] == _headPoint) { selectionReplacement = _headPoint.next; _headPoint = selectionReplacement; } else if (_selectedPoints[0] == _headPoint.tail) { selectionReplacement = _headPoint.tail.previous; } else { selectionReplacement = _selectedPoints[0].next ?? _selectedPoints[0].previous; } _selectedPoints[0].remove(); _selectedPoints.Clear(); selectionReplacement.position = worldMouse; _selectedPoints.Add(selectionReplacement); } else if (_selectedPoints.Count == 2) { if (_headPoint.listCount > 4) { if (_selectedPoints[0] == _headPoint) { _headPoint = _selectedPoints[0].next; } else if (_selectedPoints[1] == _headPoint) { _headPoint = _selectedPoints[1].next; } _selectedPoints[0].remove(); _selectedPoints[1].remove(); deselect(); } } } } // Deselect/delete if (_level.controller.isKeyPressed(Keys.Escape)) { deselect(); } else if (_level.controller.isKeyPressed(Keys.Delete)) { delete(); } } else if (_level.controller.selectedActor == null) { // Insert a point if (_level.controller.isKeyPressed(Keys.OemPlus)) { hitTest(worldMouse, (results) => { // Handle insertion on a single point if (results.Count == 1 && results[0] is PointListNode) { (results[0] as PointListNode).insertAfter(worldMouse); return(true); } // Handle insertion on line between head and tail if (results.Count == 2 && ((results[0] == _headPoint && results[1] == _headPoint.tail) || (results[0] == _headPoint.tail && results[1] == _headPoint))) { _headPoint.tail.insertAfter(worldMouse); return(true); } // Handle insertion on a normal line segment if (results.Count == 2 && results[0] is PointListNode && results[0] is PointListNode) { PointListNode firstNode = ((results[0] as PointListNode).index < (results[1] as PointListNode).index ? results[0] : results[1]) as PointListNode; firstNode.insertAfter(worldMouse); } return(false); }); } // Remove a point if (_level.controller.isKeyPressed(Keys.OemMinus)) { if (_headPoint.listCount > 3) { hitTest(worldMouse, (results) => { if (results.Count == 1 && results[0] is PointListNode) { if (results[0] == _headPoint) { _headPoint = _headPoint.next; } (results[0] as PointListNode).remove(); return(true); } return(false); }); } } } }