Java 类com.badlogic.gdx.ai.steer.utils.paths.LinePath.LinePathParam 实例源码

项目:Inspiration    文件:LinePath.java   
@Override
public float calculateDistance (T agentCurrPos, LinePathParam parameter) {
    // Find the nearest segment
    float smallestDistance2 = Float.POSITIVE_INFINITY;
    Segment<T> nearestSegment = null;
    for (int i = 0; i < segments.size; i++) {
        Segment<T> segment = segments.get(i);
        float distance2 = calculatePointSegmentSquareDistance(nearestPointOnCurrentSegment, segment.begin, segment.end,
            agentCurrPos);

        // first point
        if (distance2 < smallestDistance2) {
            nearestPointOnPath.set(nearestPointOnCurrentSegment);
            smallestDistance2 = distance2;
            nearestSegment = segment;
            parameter.segmentIndex = i;
        }
    }

    // Distance from path start
    float lengthOnPath = nearestSegment.cumulativeLength - nearestPointOnPath.dst(nearestSegment.end);

    parameter.setDistance(lengthOnPath);

    return lengthOnPath;
}
项目:gdx-ai    文件:LinePath.java   
@Override
public float calculateDistance (T agentCurrPos, LinePathParam parameter) {
    // Find the nearest segment
    float smallestDistance2 = Float.POSITIVE_INFINITY;
    Segment<T> nearestSegment = null;
    for (int i = 0; i < segments.size; i++) {
        Segment<T> segment = segments.get(i);
        float distance2 = calculatePointSegmentSquareDistance(nearestPointOnCurrentSegment, segment.begin, segment.end,
            agentCurrPos);

        // first point
        if (distance2 < smallestDistance2) {
            nearestPointOnPath.set(nearestPointOnCurrentSegment);
            smallestDistance2 = distance2;
            nearestSegment = segment;
            parameter.segmentIndex = i;
        }
    }

    // Distance from path start
    float lengthOnPath = nearestSegment.cumulativeLength - nearestPointOnPath.dst(nearestSegment.end);

    parameter.setDistance(lengthOnPath);

    return lengthOnPath;
}
项目:Inspiration    文件:LinePath.java   
@Override
public void calculateTargetPosition (T out, LinePathParam param, float targetDistance) {
    if (isOpen) {
        // Open path support
        if (targetDistance < 0) {
            // Clamp target distance to the min
            targetDistance = 0;
        } else if (targetDistance > pathLength) {
            // Clamp target distance to the max
            targetDistance = pathLength;
        }
    } else {
        // Closed path support
        if (targetDistance < 0) {
            // Backwards
            targetDistance = pathLength + (targetDistance % pathLength);
        } else if (targetDistance > pathLength) {
            // Forward
            targetDistance = targetDistance % pathLength;
        }
    }

    // Walk through lines to see on which line we are
    Segment<T> desiredSegment = null;
    for (int i = 0; i < segments.size; i++) {
        Segment<T> segment = segments.get(i);
        if (segment.cumulativeLength >= targetDistance) {
            desiredSegment = segment;
            break;
        }
    }

    // begin-------targetPos-------end
    float distance = desiredSegment.cumulativeLength - targetDistance;

    out.set(desiredSegment.begin).sub(desiredSegment.end).scl(distance / desiredSegment.length).add(desiredSegment.end);
}
项目:GdxDemo3D    文件:FollowPathSteerer.java   
public FollowPathSteerer(final SteerableBody steerableBody) {
    super(steerableBody);

    // At least two points are needed to construct a line path
    Array<Vector3> waypoints = new Array<Vector3>(new Vector3[]{new Vector3(), new Vector3(1, 0, 1)});
    this.linePath = new LinePath<Vector3>(waypoints, true);
    this.followPathSB = new FollowPath<Vector3, LinePath.LinePathParam>(steerableBody, linePath, 1);

    this.prioritySteering.add(followPathSB);
}
项目:gdx-ai    文件:LinePath.java   
@Override
public void calculateTargetPosition (T out, LinePathParam param, float targetDistance) {
    if (isOpen) {
        // Open path support
        if (targetDistance < 0) {
            // Clamp target distance to the min
            targetDistance = 0;
        } else if (targetDistance > pathLength) {
            // Clamp target distance to the max
            targetDistance = pathLength;
        }
    } else {
        // Closed path support
        if (targetDistance < 0) {
            // Backwards
            targetDistance = pathLength + (targetDistance % pathLength);
        } else if (targetDistance > pathLength) {
            // Forward
            targetDistance = targetDistance % pathLength;
        }
    }

    // Walk through lines to see on which line we are
    Segment<T> desiredSegment = null;
    for (int i = 0; i < segments.size; i++) {
        Segment<T> segment = segments.get(i);
        if (segment.cumulativeLength >= targetDistance) {
            desiredSegment = segment;
            break;
        }
    }

    // begin-------targetPos-------end
    float distance = desiredSegment.cumulativeLength - targetDistance;

    out.set(desiredSegment.begin).sub(desiredSegment.end).scl(distance / desiredSegment.length).add(desiredSegment.end);
}
项目:Inspiration    文件:LinePath.java   
@Override
public LinePathParam createParam () {
    return new LinePathParam();
}
项目:gdx-ai    文件:LinePath.java   
@Override
public LinePathParam createParam () {
    return new LinePathParam();
}