コード例 #1
0
        /// <summary>
        /// Converti la spline en ligne si elle rentre dans la tolérance
        /// </summary>
        /// <param name="Absolu">En absolu ou pourcentage de la longueur de la spline</param>
        /// <returns></returns>
        public iLine?EnLigne()
        {
            try
            {
                // Si les points de control sont alignés dans la tolérance, on remplace par une ligne
                bool EstDroite = true;
                {
                    // Recupération des points de control
                    var LstControlPoint = Spline.ListeControlPoint();

                    // On défini la ligne reliant le début et la fin de la spline
                    var      s     = LstControlPoint[0];
                    var      e     = LstControlPoint[LstControlPoint.Count - 1];
                    MathLine ligne = MathHelper.Mu.CreateLine(s.X, s.Y, s.Z, e.X, e.Y, e.Z, dsMathLineType_e.dsMathLineType_Bounded);

                    // On supprime les points de départ et d'arrivée de la liste
                    LstControlPoint.RemoveAt(0);
                    LstControlPoint.RemoveAt(LstControlPoint.Count - 1);

                    // On vérifie la déviation de chaque point par rapport à la ligne.
                    // Si elle est supérieur, on sort
                    foreach (var iPt in LstControlPoint)
                    {
                        MathPoint dsResultPoint1, dsResultPoint2;
                        var       d = MathHelper.Mu.Distance(iPt.MathPoint(), ligne, out dsResultPoint1, out dsResultPoint2);
                        if (d > deviation)
                        {
                            EstDroite = false;
                            break;
                        }
                    }
                }

                // Si la spline est droite, on la remplace par une ligne.
                if (EstDroite)
                {
                    return(new iLine(StartPoint, EndPoint));
                }
            }
            catch (Exception e)
            { Log.Write(e); }

            return(null);
        }
コード例 #2
0
    Godot.Vector2 getFlyableLaunchForce()
    {
        GeoLib.Vector2 mousePos   = new GeoLib.Vector2(flyable.GetGlobalMousePosition().x, flyable.GetGlobalMousePosition().y);
        GeoLib.Vector2 flyablePos = new GeoLib.Vector2(flyable.Position.x, flyable.Position.y);

        MathLine strikeLine = new MathLine(mousePos, flyablePos);
        double   angle      = strikeLine.GetAcuteAngle();

        float xForce = Flyable.FORCE * (float)Math.Cos(angle);
        float yForce = Flyable.FORCE * (float)Math.Sin(angle);

        Godot.Vector2 hitForce = new Godot.Vector2(xForce, yForce);

        if (mousePos.X < flyablePos.X)
        {
            hitForce *= -1;
        }

        return(hitForce);
    }
コード例 #3
0
ファイル: LineController.cs プロジェクト: t1mmmmY/Vectrosity
	private static void GetIntersectionPoint(Vector2 center, Vector2 originDirection, IEnumerable<KeyValuePair<SideType,MathLine>> sides, MathLine inputLine, out SideType intersectionSide, out Vector2 intersectionPoint)
	{
		intersectionSide = SideType.None;
		intersectionPoint = new Vector2(Mathf.Infinity, Mathf.Infinity);

		float sqrDistance = Mathf.Infinity;
		
		foreach (var side in sides)
		{
			SideType sideType = side.Key;
			MathLine line = side.Value;
			
			Vector2 point = line.GetIntersectionPoint(inputLine.Coefficients);
			Vector2 direction = point - center;
			float distance = Vector2.SqrMagnitude(direction);
			
			if (distance <= sqrDistance && Vector2.Dot(direction, originDirection) > 0)
			{
				sqrDistance = distance;
				intersectionSide = sideType;
				intersectionPoint = point;
			}
		}
	}
コード例 #4
0
ファイル: LineController.cs プロジェクト: t1mmmmY/Vectrosity
	public void DrawLine()
	{
		IsEnabled = true;

		// Cleanup old Line
		VectorLine.Destroy(ref _line);
		
		// Create new Line
		_line = new VectorLine("Line", new List<Vector2>(), null, LineWidth, LineType.Discrete, Joins.Weld);
		_line.color = LineColor;
		_line.drawDepth = LineOrder;

		Vector2 lastPoint = Vector2.zero;
		// Draw all segments and connection lines
		for(var i = 0; i < Cells.Length; i++)
        {
			var cell = Cells[i];
			// Part 0
			// Add Line's Head
			if (i == 0)
			{
				lastPoint = GetLineStart(cell);
			}

			// Part 1
			_line.points2.Add(lastPoint);
			MathLine line = new MathLine().CalculateLineByPoints(lastPoint, cell.Center);
			SideType side = SideType.None;

			if (cell.Visible)
			{
				cell.GetExternalIntersectionPoint(line, cell.Center, lastPoint - cell.Center, 0f, out side, out lastPoint);
			}
			else
			{
				// Prepare line for Stump
				cell.GetExternalIntersectionPoint(line, cell.Center, lastPoint - cell.Center, LineWidth / 3f, out side, out lastPoint);
			}
			_line.points2.Add(lastPoint);

			// Part 2
			if (cell.Visible)
			{
				// Draw line through cell center
				_line.points2.Add(lastPoint);
				_line.points2.Add(cell.Center);
			}
			else
			{
				// Draw Stump to have nice line ending
				_line.points2.Add(lastPoint);
				_line.points2.Add(lastPoint + LineWidth / 4f * GetStumpVector(side));
			}

			// Part 3
			Vector2 nextPoint;
			// If current point is the last one, take Right Cell's point
			if (i == Cells.Length - 1)
			{
				nextPoint = GetLineEnding(cell);
			}
			// Otherwise take next Cell's center as point
			else 
			{
				Cell nextCell = Cells[i + 1];
				nextPoint = nextCell.Center;
			}
			line = new MathLine().CalculateLineByPoints(cell.Center, nextPoint);

			if (cell.Visible)
            {
				cell.GetInternalIntersectionPoint(line, cell.Center, nextPoint - cell.Center, 0f, out side, out lastPoint);
				// Start line from Cell's center
				_line.points2.Add(cell.Center);
				_line.points2.Add(lastPoint); 
			}
			else
			{
				cell.GetInternalIntersectionPoint(line, cell.Center, nextPoint - cell.Center, LineWidth / 3f, out side, out lastPoint);
				// Draw Stump
				_line.points2.Add(lastPoint + LineWidth / 4f * GetStumpVector(side));
				_line.points2.Add(lastPoint);
			}

			// Part 4
			// Add Line tail
			if (i == Cells.Length - 1)
			{
				_line.points2.Add(lastPoint);
				_line.points2.Add(nextPoint);
			}
        }
        
        _line.Draw();
	}
コード例 #5
0
ファイル: LineController.cs プロジェクト: t1mmmmY/Vectrosity
	public static void GetInternalIntersectionPoint(this Cell cell, MathLine inputLine, Vector2 center, Vector2 direction, float offset, out SideType intersectionSide, out Vector2 intersectionPoint)
	{
		// Exclude Left side from calculations
		var sides = cell.GetCellSides(offset).Where(i => i.Key != SideType.Left);
		// Get best intersection data
		GetIntersectionPoint(center, direction, sides, inputLine, out intersectionSide, out intersectionPoint);
	}