import Vector from '../../math/Vector'; import Limiter from '../Limiter'; import Steerable from '../Steerable'; import SteerableAdapter from '../SteerableAdapter'; import SteeringAcceleration from '../SteeringAcceleration'; import MatchVelocity from './MatchVelocity'; /** * First the {@code Jump} behavior calculates the linear velocity required to achieve the jump. If the calculated velocity doesn't * exceed the maximum linear velocity the jump is achievable; otherwise it's not. In either cases, the given callback gets * informed through the {@link JumpCallback#reportAchievability(boolean) reportAchievability} method. Also, if the jump is * achievable the run up phase begins and the {@code Jump} behavior will start to produce the linear acceleration required to match * the calculated velocity. Once the jump point and the linear velocity are reached with a precision within the given tolerance * the callback is told to jump through the {@link JumpCallback#takeoff(float, float) takeoff} method. * * @param Type of vector, either 2D or 3D, implementing the {@link Vector} interface * * @author davebaol */ declare class Jump> extends MatchVelocity { static DEBUG_ENABLED: boolean; /** The jump descriptor to use */ protected jumpDescriptor: JumpDescriptor; /** * The gravity vector to use. Notice that this behavior only supports gravity along a single axis, which must be the one * returned by the {@link GravityComponentHandler#getComponent(Vector)} method. */ protected gravity: T; protected gravityComponentHandler: GravityComponentHandler; protected callback: JumpCallback; protected takeoffPositionTolerance: number; protected takeoffVelocityTolerance: number; /** The maximum vertical component of jump velocity, where "vertical" stands for the axis where gravity operates. */ protected maxVerticalVelocity: number; protected airborneTime: number; /** Keeps track of whether the jump is achievable */ private isJumpAchievable; private jumpTarget; private planarVelocity; /** * Creates a {@code Jump} behavior. * @param owner the owner of this behavior * @param jumpDescriptor the descriptor of the jump to make * @param gravity the gravity vector * @param gravityComponentHandler the handler giving access to the vertical axis * @param callback the callback that gets informed about jump achievability and when to jump */ constructor(owner: Steerable, jumpDescriptor: JumpDescriptor, gravity: T, gravityComponentHandler: GravityComponentHandler, callback: JumpCallback); calculateRealSteering(steering: SteeringAcceleration): SteeringAcceleration; /** * Returns the airborne time and sets the {@code outVelocity} vector to the airborne planar velocity required to achieve the * jump. If the jump is not achievable -1 is returned and the {@code outVelocity} vector remains unchanged. *

* Be aware that you should avoid using unlimited or very high max velocity, because this might produce a time of flight close * to 0. Actually, the motion equation for T has 2 solutions and Jump always try to use the fastest time. * @param outVelocity the output vector where the airborne planar velocity is calculated * @param jumpDescriptor the jump descriptor * @param maxLinearSpeed the maximum linear speed that can be used to achieve the jump * @return the time of flight or -1 if the jump is not achievable using the given max linear speed. */ calculateAirborneTimeAndVelocity(outVelocity: T, jumpDescriptor: JumpDescriptor, maxLinearSpeed: number): number; /** Returns the jump descriptor. */ getJumpDescriptor(): JumpDescriptor; /** * Sets the jump descriptor to use. * @param jumpDescriptor the jump descriptor to set * @return this behavior for chaining. */ setJumpDescriptor(jumpDescriptor: JumpDescriptor): Jump; /** Returns the gravity vector. */ getGravity(): T; /** * Sets the gravity vector. * @param gravity the gravity to set * @return this behavior for chaining. */ setGravity(gravity: T): Jump; /** Returns the maximum vertical component of jump velocity, where "vertical" stands for the axis where gravity operates. */ getMaxVerticalVelocity(): number; /** * Sets the maximum vertical component of jump velocity, where "vertical" stands for the axis where gravity operates. * @param maxVerticalVelocity the maximum vertical velocity to set * @return this behavior for chaining. */ setMaxVerticalVelocity(maxVerticalVelocity: number): Jump; /** Returns the tolerance used to check if the owner has reached the takeoff location. */ getTakeoffPositionTolerance(): number; /** * Sets the tolerance used to check if the owner has reached the takeoff location. * @param takeoffPositionTolerance the takeoff position tolerance to set * @return this behavior for chaining. */ setTakeoffPositionTolerance(takeoffPositionTolerance: number): Jump; /** Returns the tolerance used to check if the owner has reached the takeoff velocity. */ getTakeoffVelocityTolerance(): number; /** * Sets the tolerance used to check if the owner has reached the takeoff velocity. * @param takeoffVelocityTolerance the takeoff velocity tolerance to set * @return this behavior for chaining. */ setTakeoffVelocityTolerance(takeoffVelocityTolerance: number): Jump; /** * Sets the the tolerance used to check if the owner has reached the takeoff location with the required velocity. * @param takeoffTolerance the takeoff tolerance for both position and velocity * @return this behavior for chaining. */ setTakeoffTolerance(takeoffTolerance: number): Jump; setOwner(owner: Steerable): Jump; setEnabled(enabled: boolean): Jump; /** * Sets the limiter of this steering behavior. The given limiter must at least take care of the maximum linear acceleration and * speed. * @return this behavior for chaining. */ setLimiter(limiter: Limiter): Jump; /** * Sets the target whose velocity should be matched. Notice that this method is inherited from {@link MatchVelocity}. Usually * with {@code Jump} you should never call it because a specialized internal target has already been created implicitly. * @param target the target to set * @return this behavior for chaining. */ setTarget(target: Steerable): Jump; setTimeToTarget(timeToTarget: number): Jump; /** Works out the trajectory calculation. */ private calculateTarget(); private checkAirborneTimeAndCalculateVelocity(outVelocity, time, jumpDescriptor, maxLinearSpeed); } /** * A {@code GravityComponentHandler} is aware of the axis along which the gravity acts. * * @param Type of vector, either 2D or 3D, implementing the {@link Vector} interface * * @author davebaol */ export interface GravityComponentHandler> { /** * Returns the component of the given vector along which the gravity operates. *

* Assuming a 3D coordinate system where the gravity is acting along the y-axis, this method will be implemented as follows: * *

     * public float getComponent (Vector3 vector) {
     *   return vector.y;
     * }
     * 
* * Of course, the equivalent 2D implementation will use Vector2 instead of Vector3. * @param vector the vector * @return the value of the component affected by gravity. */ getComponent(vector: T): number; /** * Sets the component of the given vector along which the gravity operates. *

* Assuming a 3D coordinate system where the gravity is acting along the y-axis, this method will be implemented as follows: * *

     * public void setComponent (Vector3 vector, float value) {
     *   vector.y = value;
     * }
     * 
* * Of course, the equivalent 2D implementation will use Vector2 instead of Vector3. * @param vector the vector * @param value the value of the component affected by gravity */ setComponent(vector: T, value: number): void; } /** * A {@code JumpDescriptor} contains jump information like the take-off and the landing position. * * @param Type of vector, either 2D or 3D, implementing the {@link Vector} interface * * @author davebaol */ export declare class JumpDescriptor> { /** The position of the takeoff pad */ takeoffPosition: T; /** The position of the landing pad */ landingPosition: T; /** The change in position from takeoff to landing. This is calculated from the other values. */ delta: T; /** * Creates a {@code JumpDescriptor} with the given takeoff and landing positions. * @param takeoffPosition the position of the takeoff pad * @param landingPosition the position of the landing pad */ constructor(takeoffPosition: T, landingPosition: T); /** * Sets this {@code JumpDescriptor} from the given takeoff and landing positions. * @param takeoffPosition the position of the takeoff pad * @param landingPosition the position of the landing pad */ set(takeoffPosition: T, landingPosition: T): void; } /** * The {@code JumpCallback} allows you to know whether a jump is achievable and when to jump. * * @author davebaol */ export interface JumpCallback { /** * Reports whether the jump is achievable or not. *

* A jump is not achievable when the character's maximum linear velocity is not enough, in which case the jump behavior * won't produce any acceleration; you might want to use pathfinding to plan a new path. *

* If the jump is achievable the run up phase will start immediately and the character will try to match the target velocity * toward the takeoff point. This is the right moment to start the run up animation, if needed. * @param achievable whether the jump is achievable or not. */ reportAchievability(achievable: boolean): void; /** * This method is called to notify that both the position and velocity of the character are good enough to jump. * @param maxVerticalVelocity the velocity to set along the vertical axis to achieve the jump * @param time the duration of the jump */ takeoff(maxVerticalVelocity: number, time: number): void; } export declare class JumpTarget> extends SteerableAdapter { position: T; linearVelocity: T; constructor(other: Steerable); getPosition(): T; getLinearVelocity(): T; } export default Jump;