Exemple #1
0
        /// <summary>
        /// Add a line segment.
        /// </summary>
        /// <param name="start">Start position</param>
        /// <param name="end">End position</param>
        public void AddSegment(Vector2 start, Vector2 end)
        {
            var segment = new SegmentShape2D()
            {
                A = start,
                B = end
            };
            var shape = new CollisionShape2D()
            {
                Shape = segment
            };

            segments.Add(segment);
            shapes.Add(shape);
            AddChild(shape);

            var lineSprite = new SimpleLineSprite()
            {
                PositionA = GlobalPosition + segment.A,
                PositionB = GlobalPosition + segment.B,
                Modulate  = BaseColor,
                Width     = 2
            };

            lineSprites.Add(lineSprite);
            AddChild(lineSprite);
        }
        public override void UpdateTransforms()
        {
            SegmentShape2D    segment = _data.Segment;
            GizmoLineSlider2D slider  = _data.Slider;

            segment.StartPoint = slider.StartPosition;
            segment.SetEndPtFromStart(slider.Direction, slider.GetRealLength());
        }
Exemple #3
0
    /**
     * Handles inputs for the simulation
     */
    public override void _Input(InputEvent inputEvent)
    {
        //Adds a liquid particle to the mouse's position if the left mouse button is pressed
        if (Input.IsActionPressed("add_liquid_particle") && this._framesUntilNextLiquidParticleCreation == 0)
        {
            var liquidParticleInstance = (Node2D)this._liquidParticleScene.Instance();
            liquidParticleInstance.Position = this.GetViewport().GetMousePosition();
            this.AddChild(liquidParticleInstance);
            this._liquidParticles.Add((LiquidParticle)liquidParticleInstance);
            this._framesUntilNextLiquidParticleCreation = 5;
        }

        //If the right mouse button is being pressed, creates a blocker from the start of the press to the end of the press
        if (Input.IsActionPressed("add_blocker"))
        {
            if (this._blockerSegmentBeingPlaced == null)
            {
                this._blockerSegmentBeingPlaced = new SegmentShape2D {
                    A = this.GetViewport().GetMousePosition(),
                    B = this.GetViewport().GetMousePosition()
                };
                var body = new StaticBody2D();
                body.AddChild(new CollisionShape2D {
                    Shape = this._blockerSegmentBeingPlaced
                });
                this.AddChild(body);
                this._blockers.Add(this._blockerSegmentBeingPlaced);
                this.Update();
            }
            else
            {
                this._blockerSegmentBeingPlaced.B = this.GetViewport().GetMousePosition();
                this.Update();
            }
        }
        else
        {
            this._blockerSegmentBeingPlaced = null;
            this.Update();
        }

        //Removes all children if the escape key is pressed
        if (Input.IsActionPressed("clear_everything"))
        {
            foreach (var child in this.GetChildren())
            {
                this.RemoveChild((Node)child);
            }

            this._liquidParticles.Clear();
            this._springs.Clear();
            this._blockers.Clear();
            this.Update();
        }
    }
 /// <summary>
 /// Converts an EdgeCollection to a List of SegmentShape2Ds that make up that EdgeCollection,
 /// whether it is an open or closed loop.
 /// </summary>
 /// <param name="edgeColl">EdgeCollection to be converted to a list of segments</param>
 /// <returns>A list of segments that make up the edges in the input EdgeCollection</returns>
 private static IEnumerable<SegmentShape2D> _EdgeCollToSegments(EdgeCollection<TileEdge> edgeColl)
 {
     var segments = new List<SegmentShape2D>();
     List<Vector2> simplifiedPolygon = edgeColl.GetSimplifiedPerim();
     for (int thisIndex = 1; thisIndex < simplifiedPolygon.Count; thisIndex++)
     {
         int prevIndex = thisIndex - 1;
         var segment = new SegmentShape2D
         {
             A = simplifiedPolygon[prevIndex],
             B = simplifiedPolygon[thisIndex],
         };
         segments.Add(segment);
     }
     return segments;
 }