@Override public float approxLength (int samples) { float tempLength = 0; for(int i = 0; i < samples; ++i) { tmp2.set(tmp3); valueAt(tmp3, (i)/((float)samples-1)); if(i>0) tempLength += tmp2.dst(tmp3); } return tempLength; } }
@Override public float approxLength (int samples) { float tempLength = 0; for (int i = 0; i < samples; ++i) { tmp2.set(tmp3); valueAt(tmp3, (i) / ((float)samples - 1)); if (i > 0) tempLength += tmp2.dst(tmp3); } return tempLength; } }
@Override public float approxLength (int samples) { float tempLength = 0; for (int i = 0; i < samples; ++i) { tmp2.set(tmp3); valueAt(tmp3, (i) / ((float)samples - 1)); if (i > 0) tempLength += tmp2.dst(tmp3); } return tempLength; } }
@Override public float approxLength (int samples) { float tempLength = 0; for (int i = 0; i < samples; ++i) { tmp2.set(tmp3); valueAt(tmp3, (i) / ((float)samples - 1)); if (i > 0) tempLength += tmp2.dst(tmp3); } return tempLength; } }
@Override public float approxLength (int samples) { float tempLength = 0; for (int i = 0; i < samples; ++i) { tmp2.set(tmp3); valueAt(tmp3, (i) / ((float)samples - 1)); if (i > 0) tempLength += tmp2.dst(tmp3); } return tempLength; } }
@Override public float approxLength (int samples) { float tempLength = 0; for(int i = 0; i < samples; ++i) { tmp2.set(tmp3); valueAt(tmp3, (i)/((float)samples-1)); if(i>0) tempLength += tmp2.dst(tmp3); } return tempLength; } }
/** Creates a {@code Segment} for the 2 given points. * @param begin * @param end */ Segment (T begin, T end) { this.begin = begin; this.end = end; this.length = begin.dst(end); }
@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; }
/** Creates a {@code Segment} for the 2 given points. * @param begin * @param end */ Segment (T begin, T end) { this.begin = begin; this.end = end; this.length = begin.dst(end); }
@Override protected SteeringAcceleration<T> calculateRealSteering (SteeringAcceleration<T> steering) { // First we need to figure out where the two agents are going to be at // time T in the future. This is approximated by determining the time // taken by the owner to reach the desired point between the 2 agents // at the current time at the max speed. This desired point P is given by // P = posA + interpositionRatio * (posB - posA) internalTargetPosition.set(agentB.getPosition()).sub(agentA.getPosition()).scl(interpositionRatio) .add(agentA.getPosition()); float timeToTargetPosition = owner.getPosition().dst(internalTargetPosition) / getActualLimiter().getMaxLinearSpeed(); // Now we have the time, we assume that agent A and agent B will continue on a // straight trajectory and extrapolate to get their future positions. // Note that here we are reusing steering.linear vector as agentA future position // and targetPosition as agentB future position. steering.linear.set(agentA.getPosition()).mulAdd(agentA.getLinearVelocity(), timeToTargetPosition); internalTargetPosition.set(agentB.getPosition()).mulAdd(agentB.getLinearVelocity(), timeToTargetPosition); // Calculate the target position between these predicted positions internalTargetPosition.sub(steering.linear).scl(interpositionRatio).add(steering.linear); // Finally delegate to Arrive return arrive(steering, internalTargetPosition); }
@Override public float approxLength (int samples) { float tempLength = 0; for (int i = 0; i < samples; ++i) { tmp2.set(tmp3); valueAt(tmp3, (i) / ((float)samples - 1)); if (i > 0) tempLength += tmp2.dst(tmp3); } return tempLength; } }
@Override public float approxLength (int samples) { float tempLength = 0; for(int i = 0; i < samples; ++i) { tmp2.set(tmp3); valueAt(tmp3, (i)/((float)samples-1)); if(i>0) tempLength += tmp2.dst(tmp3); } return tempLength; } }
@Override public float approxLength (int samples) { float tempLength = 0; for (int i = 0; i < samples; ++i) { tmp2.set(tmp3); valueAt(tmp3, (i) / ((float)samples - 1)); if (i > 0) tempLength += tmp2.dst(tmp3); } return tempLength; } }
@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; }
@Override protected SteeringAcceleration<T> calculateRealSteering (SteeringAcceleration<T> steering) { // First we need to figure out where the two agents are going to be at // time T in the future. This is approximated by determining the time // taken by the owner to reach the desired point between the 2 agents // at the current time at the max speed. This desired point P is given by // P = posA + interpositionRatio * (posB - posA) internalTargetPosition.set(agentB.getPosition()).sub(agentA.getPosition()).scl(interpositionRatio) .add(agentA.getPosition()); float timeToTargetPosition = owner.getPosition().dst(internalTargetPosition) / getActualLimiter().getMaxLinearSpeed(); // Now we have the time, we assume that agent A and agent B will continue on a // straight trajectory and extrapolate to get their future positions. // Note that here we are reusing steering.linear vector as agentA future position // and targetPosition as agentB future position. steering.linear.set(agentA.getPosition()).mulAdd(agentA.getLinearVelocity(), timeToTargetPosition); internalTargetPosition.set(agentB.getPosition()).mulAdd(agentB.getLinearVelocity(), timeToTargetPosition); // Calculate the target position between these predicted positions internalTargetPosition.sub(steering.linear).scl(interpositionRatio).add(steering.linear); // Finally delegate to Arrive return arrive(steering, internalTargetPosition); }