import Vector from '../../../math/Vector'; import Ray from '../../../utils/Ray'; import Steerable from '../../Steerable'; import RayConfigurationBase from './RayConfigurationBase'; /** * As the name suggests, a {@code SingleRayConfiguration} uses just one ray cast. *

* This configuration is useful in concave environments but grazes convex obstacles. It is not susceptible to the corner trap, though. * * @param Type of vector, either 2D or 3D, implementing the {@link Vector} interface * * @author davebaol */ class SingleRayConfiguration> extends RayConfigurationBase { private length: number; /** * Creates a {@code SingleRayConfiguration} for the given owner where the ray has the specified length. * @param owner the owner of this configuration * @param length the length of the ray */ public constructor(owner: Steerable, length: number) { super(owner, 1); this.length = length; } public updateRays(): Ray[] { this.rays[0].start.copy(this.owner.getPosition()); this.rays[0].end.copy(this.owner.getLinearVelocity()).nor().scale(this.length).add(this.rays[0].start); return this.rays; } /** Returns the length of the ray. */ public getLength(): number { return this.length; } /** Sets the length of the ray. */ public setLength(length: number): void { this.length = length; } } export default SingleRayConfiguration;