private void PathObject() // Page 50
        {
            ArrayList lineArray = new ArrayList();

            int[]         Point1     = { 100, 100 };
            int[]         Point2     = { 150, 200 };
            Document      docRef     = appRef.Documents.Add(5000, 7000, 72, "Simple Line");
            PathPointInfo LineArray0 = new PathPointInfo();

            LineArray0.Kind           = PsPointKind.psCornerPoint;
            LineArray0.Anchor         = Point1;
            LineArray0.LeftDirection  = LineArray0.Anchor;
            LineArray0.RightDirection = LineArray0.Anchor;
            PathPointInfo LineArray1 = new PathPointInfo();

            LineArray1.Kind           = PsPointKind.psCornerPoint;
            LineArray1.Anchor         = Point2;
            LineArray1.LeftDirection  = LineArray1.Anchor;
            LineArray1.RightDirection = LineArray1.Anchor;
            lineArray.Add(LineArray0);
            lineArray.Add(LineArray1);
            SubPathInfo LineSubPathArray0 = new SubPathInfo();

            LineSubPathArray0.Operation     = PsShapeOperation.psShapeXOR;
            LineSubPathArray0.Closed        = false;
            LineSubPathArray0.EntireSubPath = lineArray;
            PathItem myPathItem = docRef.PathItems.Add("A Line", LineSubPathArray0);

            myPathItem.StrokePath(PsToolType.psBrush);
        }
Esempio n. 2
0
    void OnDrawGizmos()
    {
        PathPointInfo goal          = currentPath.FindClosestLeadingPoint(car.position, guidePointDistance);
        Vector3       perpendicular = new Vector3(goal.direction.z, 0, -goal.direction.x);
        Vector3       carPos        = car.position;

        carPos.y = goal.point.y;

        // draw goal point feeler
        Vector3 intersect = VectorUtil.GetLineIntersectionPoint(car.position, car.position + car.forward, goal.point, goal.point + perpendicular, out bool found);

        if (found && Vector3.Dot(car.forward, intersect - carPos) >= 0)
        {
            Vector3 vehiclePoint = car.position;
            vehiclePoint.y = intersect.y = goal.point.y;
            Gizmos.color   = Color.red;
            Gizmos.DrawLine(goal.point, intersect);
            Gizmos.DrawWireSphere(intersect, feelerRadius);
            Gizmos.color = Color.blue;
            Gizmos.DrawLine(vehiclePoint, intersect);
        }

        Gizmos.color = Color.white;
        Gizmos.DrawWireSphere(goal.point, 0.25f);
        Gizmos.DrawLine(goal.point, goal.point + goal.direction);
    }
Esempio n. 3
0
    public float PathFollowInput()
    {
        PathPointInfo goal = currentPath.FindClosestLeadingPoint(car.position, guidePointDistance);

        // match car height to goal height
        Vector3 carPos = car.position;

        carPos.y = goal.point.y;

        // get perpendicular line to the guide point's direction
        Vector3 perpendicular = new Vector3(goal.direction.z, 0, -goal.direction.x);

        bool doTurn = false;

        // find the intersection between the car's heading and perpendicular to the track
        Vector3 intersect = VectorUtil.GetLineIntersectionPoint(carPos, carPos + car.forward, goal.point, goal.point + perpendicular, out bool found);

        // also turn if the intercept is behind the car, this means the car is backward
        if (found && Vector3.Dot(car.forward, intersect - carPos) >= 0)
        {
            // if there is an intercept, that is the feeler
            // check if the feeler falls outside the path
            intersect.y = goal.point.y;
            float feelerDistance = (intersect - goal.point).magnitude;
            if (feelerDistance + feelerRadius > currentPath.radius)
            {
                // if it does, we're going to hit a wall, time to correct
                doTurn = true;
            }
        }
        else
        {
            // no intercept found, steer toward the goal
            doTurn = true;
        }

        // if we do need to turn, return the direction
        if (doTurn)
        {
            float dir = Vector3.Dot(car.right, goal.point - carPos);
            if (Mathf.Abs(dir) > Mathf.Epsilon)
            {
                return(dir / Mathf.Abs(dir));
            }
        }

        // don't need to turn
        return(0);
    }