示例#1
0
    public bool ShouldClipTriangle(IEnumerable <Vector2> points)
    {
        if (points.Min(p => p.x) > bounds.xMax)
        {
            return(false);
        }
        if (points.Max(p => p.x) < bounds.xMin)
        {
            return(false);
        }
        if (points.Min(p => p.y) > bounds.yMax)
        {
            return(false);
        }
        if (points.Max(p => p.y) < bounds.yMin)
        {
            return(false);
        }
        var v0 = points.Last();

        foreach (var v1 in points)
        {
            if (PSEdge.PointDistanceToEdge(position, v0, v1) <= radius)
            {
                return(true);
            }
        }
        return(false);
    }
示例#2
0
    private void DrawEdge(PSEdge edge, Vector2 offset)
    {
        var v0            = edge.v0 + offset;
        var v1            = edge.v1 + offset;
        var arrow         = 0.9f * v1 + 0.1f * v0;
        var perpendicular = 0.1f * Vector2.Perpendicular(v1 - v0);

        Gizmos.DrawLine(v0, v1);
        Gizmos.DrawLine(arrow + perpendicular, v1);
        Gizmos.DrawLine(arrow - perpendicular, v1);
    }
    void LateUpdate()
    {
        var h             = rb.position.magnitude;
        var positionDelta = rb.position - previousPosition;

        previousPosition = rb.position;
        var positionNormalized = rb.position.normalized;
        var t = positionDelta - (positionNormalized * Vector2.Dot(positionDelta, positionNormalized));

        rb.rotation -= Mathf.Atan(t.magnitude / h) * Mathf.Sign(PSEdge.Cross(t, positionNormalized)) * Mathf.Rad2Deg;
    }
示例#4
0
    public bool ShouldClipTriangle(IEnumerable <Vector2> points)
    {
        var v0 = points.Last();

        foreach (var v1 in points)
        {
            if (PSEdge.SegmentsCross(start, direction, v0, v1 - v0))
            {
                return(true);
            }
        }
        if (startCircle.ShouldClipTriangle(points))
        {
            return(true);
        }
        if (endCircle.ShouldClipTriangle(points))
        {
            return(true);
        }
        return(false);
    }
    void FixedUpdate()
    {
        float turn = Input.GetAxis(turnAxis);

        var   h = rb.position.magnitude;
        var   positionNormalized     = rb.position.normalized;
        float thursterForceMagnitude = 0f;
        var   afterBurnerOn          = afterBurner.isEmitting;
        var   forwardSpeed           = Vector2.Dot(rb.velocity, transform.up);

        if (forwardSpeed < (afterBurnerOn ? afterBurnerMaxSpeed : maxSpeed))
        {
            float thrust = Mathf.Max(Input.GetAxis(thrustAxis), 0f);
            float athmosphereCoefficient = Mathf.Clamp((120f - h) / 20f, 0f, 1f);
            thursterForceMagnitude = athmosphereCoefficient * (afterBurnerOn ? afterBurnerThrustPower : thrust * maxThrustPower);
        }

        Vector2 gravity   = positionNormalized * gravityForceMagnitude;
        Vector2 thrusters = transform.up * thursterForceMagnitude;

        var forwardVelocity    = forwardSpeed * (Vector2)transform.up;
        var orthogonalVelocity = rb.velocity - forwardVelocity;

        rb.AddForce(-orthogonalVelocity * orthogonalVelocity.magnitude * (airDrag + orthogonalDrag));
        rb.AddForce(-forwardVelocity * forwardVelocity.magnitude * airDrag);

        rb.AddForce(thrusters + gravity);
        rb.angularVelocity = -turn * 300f;

        var positionDelta = rb.position - previousPosition;

        previousPosition = rb.position;
        var t = positionDelta - (positionNormalized * Vector2.Dot(positionDelta, positionNormalized));

        rb.rotation -= Mathf.Atan(t.magnitude / h) * Mathf.Sign(PSEdge.Cross(t, positionNormalized)) * Mathf.Rad2Deg;
    }