From 1d52152206874712a09652c650b7a9ebfef6ac03 Mon Sep 17 00:00:00 2001 From: "94756970+waynemwashuma@users.noreply.github.com" <94756970+waynemwashuma@users.noreply.github.com> Date: Sun, 12 Nov 2023 15:25:52 +0300 Subject: [PATCH 01/13] [Physics] `Overlaps.AABBvsSphere` returned incorrect results #fix --- src/physics/AABB/overlap.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/physics/AABB/overlap.js b/src/physics/AABB/overlap.js index d68d44fc..8e47d8f1 100644 --- a/src/physics/AABB/overlap.js +++ b/src/physics/AABB/overlap.js @@ -40,6 +40,6 @@ export const Overlaps = { (x - b.pos.x) * (x - b.pos.x) + (y - b.pos.y) * (y - b.pos.y) - return distance < b.r; + return distance < b.r * b.r; } } \ No newline at end of file From 9b233717eb3f7ce893d2fb04e163dd0665d57d84 Mon Sep 17 00:00:00 2001 From: "94756970+waynemwashuma@users.noreply.github.com" <94756970+waynemwashuma@users.noreply.github.com> Date: Mon, 13 Nov 2023 02:53:46 +0300 Subject: [PATCH 02/13] [events] Added `Signal()` class #new --- src/events/index.js | 3 ++- src/events/signals.js | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 src/events/signals.js diff --git a/src/events/index.js b/src/events/index.js index f6383f3e..ab476dd3 100644 --- a/src/events/index.js +++ b/src/events/index.js @@ -1,4 +1,5 @@ export * from "./eventDispatcher.js" export * from "./DOMEventHandler.js" export * from "./eventHandlers.js" -export * from "./events.js" \ No newline at end of file +export * from "./events.js" +export * from "./signals.js" \ No newline at end of file diff --git a/src/events/signals.js b/src/events/signals.js new file mode 100644 index 00000000..3936d673 --- /dev/null +++ b/src/events/signals.js @@ -0,0 +1,34 @@ +export class Signal { + _listeners = [] + _value = null + constructor(value){ + this._value = value + } + set value(x) { + this._value == x + for (var i = 0; i < this._listeners.length; i++) { + let func = this._listeners[i] + func.listener(this) + if(func.callOnce) + this.removeListener(func.listener) + } + } + get value() { + return this._value + } + addListener(listener,callOnce=false) { + this._listeners.push({ + listener, + callOnce + }) + } + removeListener(listener) { + for (var i = 0; i < this._listeners.length; i++) { + if (this._listeners[i].listener == listener) + return this._detach(i) + } + } + _detach(bindingIndex){ + this._listeners.splice(i, 1) + } +} \ No newline at end of file From 76c5feb48b838fe2baeb018f4a1c27a1bda2f09e Mon Sep 17 00:00:00 2001 From: "94756970+waynemwashuma@users.noreply.github.com" <94756970+waynemwashuma@users.noreply.github.com> Date: Tue, 14 Nov 2023 16:28:54 +0300 Subject: [PATCH 03/13] [Math] Renamed `Vec2()` to `Vector2()` #change --- demos/bridge.js | 14 +- demos/car.js | 6 +- demos/constraints.js | 6 +- demos/marterial.js | 10 +- demos/pathfollower.js | 12 +- demos/seeker.js | 2 +- demos/wanderer.js | 2 +- dist/chaos.module.d.ts | 226 ++++---- dist/chaos.module.js | 546 +++++++++--------- dist/chaos.umd.js | 546 +++++++++--------- docs/AI_agent.js.html | 8 +- docs/AI_behaviourManager.js.html | 10 +- docs/AI_behaviours_arrive.js.html | 14 +- docs/AI_behaviours_behaviour.js.html | 10 +- docs/AI_behaviours_evade.js.html | 12 +- docs/AI_behaviours_flocking.js.html | 8 +- docs/AI_behaviours_path.js.html | 14 +- docs/AI_behaviours_pursuit.js.html | 8 +- docs/AI_behaviours_seek.js.html | 14 +- docs/AI_behaviours_wandering.js.html | 16 +- docs/AI_manager.js.html | 2 +- docs/AI_paths_path.js.html | 16 +- docs/Agent.html | 14 +- docs/AgentManager.html | 2 +- docs/AgentSprite.html | 6 +- docs/Angle.html | 2 +- docs/ArriveBehaviour.html | 16 +- docs/AudioHandler.html | 2 +- docs/Ball.html | 44 +- docs/BasicMaterial.html | 2 +- docs/Behaviour.html | 14 +- docs/BehaviourManager.html | 2 +- docs/Body.html | 44 +- docs/BodySprite.html | 6 +- docs/Bound.html | 2 +- docs/BoundingBox.html | 4 +- docs/BoundingCircle.html | 2 +- docs/Box.html | 44 +- docs/Broadphase.html | 2 +- docs/BufferGeometry_BufferGeometry.html | 4 +- docs/CamController_CamController.html | 2 +- docs/Circle.html | 26 +- docs/CircleGeometry_CircleGeometry.html | 2 +- docs/Clock.html | 2 +- docs/Component.html | 2 +- docs/Composite.html | 14 +- docs/Constraint.html | 6 +- docs/DOMEventHandler.html | 2 +- docs/DistanceConstraint.html | 6 +- docs/Entity.html | 2 +- docs/EulerSolver.html | 2 +- docs/EvadeBehaviour.html | 16 +- docs/EventDispatcher.html | 2 +- docs/Flock.html | 14 +- docs/Geometry.html | 22 +- docs/Grid.html | 2 +- docs/Group.html | 6 +- docs/ImageSprite.html | 2 +- docs/Input.html | 2 +- docs/Keyboard.html | 2 +- docs/Line.html | 4 +- docs/Manager.html | 2 +- docs/Material.html | 2 +- docs/Matrix2.html | 4 +- docs/Mouse.html | 2 +- docs/Movable.html | 2 +- docs/NaiveBroadphase.html | 2 +- docs/Node.html | 2 +- docs/Particle.html | 12 +- docs/ParticleSystemSprite.html | 6 +- docs/PathFollowing.html | 16 +- docs/Pool.html | 2 +- docs/Pursuit.html | 14 +- docs/Rectangle.html | 4 +- docs/Renderer.html | 2 +- docs/Renderer2D.html | 2 +- docs/RungeKuttaSolver.html | 2 +- docs/SATNarrowPhase.html | 2 +- docs/SeekBehaviour.html | 22 +- docs/Sfx.html | 2 +- docs/Shape.html | 30 +- docs/SpringConstraint.html | 6 +- docs/Sprite.html | 6 +- docs/SpriteMaterial.html | 2 +- docs/StaticImageMaterial.html | 2 +- docs/StaticImageSprite.html | 2 +- docs/System.html | 2 +- docs/Touch.html | 2 +- docs/Transform.html | 2 +- docs/Tree.html | 2 +- docs/Triangle.html | 28 +- docs/Trigon_Trigon.html | 2 +- docs/Vector.html | 126 ++-- docs/VectorPool.html | 4 +- docs/VerletSolver.html | 2 +- docs/WanderBehaviour.html | 14 +- docs/WebGLRenderer.html | 2 +- docs/WebGPURenderer.html | 2 +- docs/World.html | 18 +- docs/audio_audio.js.html | 2 +- docs/audio_manager.js.html | 2 +- docs/dataStructures_pools_VectorPool.js.html | 8 +- docs/dataStructures_pools_objectPool.js.html | 2 +- docs/device_index.js.html | 2 +- docs/events_DOMEventHandler.js.html | 2 +- docs/events_eventDispatcher.js.html | 2 +- docs/events_eventHandlers.js.html | 2 +- docs/events_events.js.html | 2 +- docs/global.html | 18 +- docs/index.html | 2 +- docs/inputs_input.js.html | 2 +- docs/inputs_keyboard.js.html | 2 +- docs/inputs_mouse.js.html | 2 +- docs/inputs_touch.js.html | 2 +- docs/manager_boundsComponent.js.html | 2 +- docs/manager_component.js.html | 2 +- docs/manager_entity.js.html | 2 +- docs/manager_manager.js.html | 2 +- docs/manager_movableComponent.js.html | 8 +- docs/manager_system.js.html | 2 +- docs/manager_transformComponent.js.html | 6 +- docs/math_angle.js.html | 2 +- docs/math_math.js.html | 2 +- docs/math_matrix.js.html | 4 +- docs/math_vector.js.html | 118 ++-- docs/module-Cookie.html | 2 +- docs/module-Session.html | 2 +- docs/module-Utils.html | 2 +- docs/physics_AABB_boundingBox.js.html | 4 +- docs/physics_AABB_boundingSphere.js.html | 2 +- docs/physics_AABB_overlap.js.html | 2 +- docs/physics_SAT_index.js.html | 32 +- docs/physics_bodies_ball.js.html | 2 +- docs/physics_bodies_body.js.html | 50 +- docs/physics_bodies_box.js.html | 2 +- docs/physics_bodies_composite.js.html | 16 +- docs/physics_bodies_trigon.js.html | 2 +- docs/physics_broadphases_AABBTree.js.html | 2 +- docs/physics_broadphases_Naive.js.html | 2 +- docs/physics_broadphases_Quadtree.js.html | 2 +- docs/physics_broadphases_SpartialHash.js.html | 2 +- docs/physics_broadphases_broadphase.js.html | 2 +- docs/physics_constraints_constraint.js.html | 16 +- ...ics_constraints_distanceConstraint.js.html | 18 +- ...ysics_constraints_springConstraint.js.html | 26 +- docs/physics_integrators_euler.js.html | 6 +- docs/physics_integrators_rungeKutter.js.html | 6 +- docs/physics_integrators_verlet.js.html | 10 +- ...physics_narrowphase_SATNarrowphase.js.html | 18 +- docs/physics_settings.js.html | 2 +- docs/physics_shapes_circle.js.html | 26 +- docs/physics_shapes_geometry.js.html | 20 +- docs/physics_shapes_line.js.html | 10 +- docs/physics_shapes_rectangle.js.html | 14 +- docs/physics_shapes_shape.js.html | 28 +- docs/physics_shapes_triangle.js.html | 14 +- docs/physics_solvers_contactSolver.js.html | 2 +- docs/physics_solvers_frictionSolver.js.html | 14 +- docs/physics_solvers_impulseSolver.js.html | 12 +- .../physics_solvers_penetrationSolver.js.html | 8 +- docs/physics_world_index.js.html | 10 +- docs/render_camController.js.html | 12 +- docs/render_camera.js.html | 4 +- docs/render_geometry_circlegeometry.js.html | 2 +- docs/render_geometry_geometry.js.html | 8 +- docs/render_material_BasicMaterial.js.html | 2 +- docs/render_material_SpriteMaterial.js.html | 2 +- ...ender_material_StaticImageMaterial.js.html | 2 +- docs/render_material_material.js.html | 2 +- docs/render_renderers_canvas.js.html | 2 +- docs/render_renderers_renderer.js.html | 2 +- docs/render_renderers_webgpurenderer.js.html | 2 +- docs/render_renderers_weglrenderer.js.html | 2 +- docs/render_sprites_AgentSprite.js.html | 10 +- docs/render_sprites_bodysprite.js.html | 8 +- docs/render_sprites_group.js.html | 2 +- docs/render_sprites_imagesprite.js.html | 2 +- docs/render_sprites_particleSystem.js.html | 14 +- docs/render_sprites_sprite.js.html | 12 +- docs/render_sprites_staticimagesprite.js.html | 2 +- docs/render_utils_canvasfunc.js.html | 4 +- docs/storage_cookie.js.html | 2 +- docs/storage_localStorage.js.html | 2 +- docs/storage_sessionStorage.js.html | 2 +- docs/typedef_bounds.js.html | 2 +- docs/typedef_manifold.js.html | 16 +- docs/typedef_vectorlike.js.html | 2 +- docs/utils_clock.js.html | 2 +- docs/utils_common.js.html | 2 +- docs/utils_error.js.html | 2 +- docs/utils_pools_VectorPool.js.html | 8 +- docs/utils_pools_objectPool.js.html | 2 +- src/AI/agent.js | 6 +- src/AI/behaviourManager.js | 8 +- src/AI/behaviours/arrive.js | 12 +- src/AI/behaviours/behaviour.js | 8 +- src/AI/behaviours/evade.js | 10 +- src/AI/behaviours/flocking.js | 6 +- src/AI/behaviours/path.js | 12 +- src/AI/behaviours/pursuit.js | 6 +- src/AI/behaviours/seek.js | 12 +- src/AI/behaviours/wandering.js | 14 +- src/AI/paths/path.js | 14 +- src/dataStructures/pools/VectorPool.js | 6 +- src/ecs/movableComponent.js | 6 +- src/ecs/transformComponent.js | 4 +- src/math/matrix.js | 2 +- src/math/vector.js | 134 +++-- src/physics/AABB/boundingBox.js | 2 +- src/physics/SAT/index.js | 30 +- src/physics/bodies/body.js | 48 +- src/physics/bodies/composite.js | 14 +- src/physics/bodies/heightMap.js | 6 +- src/physics/constraints/constraint.js | 14 +- src/physics/constraints/distanceConstraint.js | 16 +- src/physics/constraints/springConstraint.js | 22 +- src/physics/integrators/euler.js | 4 +- src/physics/integrators/rungeKutter.js | 4 +- src/physics/integrators/verlet.js | 8 +- src/physics/narrowphase/SATNarrowphase.js | 16 +- src/physics/shapes/circle.js | 24 +- src/physics/shapes/geometry.js | 18 +- src/physics/shapes/line.js | 8 +- src/physics/shapes/rectangle.js | 12 +- src/physics/shapes/shape.js | 26 +- src/physics/shapes/triangle.js | 12 +- src/physics/solvers/frictionSolver.js | 12 +- src/physics/solvers/impulseSolver.js | 10 +- src/physics/solvers/penetrationSolver.js | 6 +- src/physics/world/index.js | 8 +- src/render/camController.js | 10 +- src/render/camera.js | 2 +- src/render/geometry/geometry.js | 6 +- src/render/sprites/AgentSprite.js | 8 +- src/render/sprites/bodysprite.js | 6 +- src/render/sprites/particleSystem.js | 12 +- src/render/sprites/sprite.js | 10 +- src/render/utils/canvasfunc.js | 2 +- src/typedef/manifold.js | 14 +- 239 files changed, 1800 insertions(+), 1786 deletions(-) diff --git a/demos/bridge.js b/demos/bridge.js index 6b12ad14..87f76ce5 100644 --- a/demos/bridge.js +++ b/demos/bridge.js @@ -1,5 +1,5 @@ import { - Vec2, + Vector2, Box, DistanceConstraint, Entity, @@ -41,8 +41,8 @@ function createChain(x, y, w, h, number, spacing, pin1, pin2) { for (var i = 1; i < number; i++) { let chain = new Box(w, h) - let an1 = prev.setAnchor(new Vec2(w/2,0)) - let an2 = prev.setAnchor(new Vec2(w/2,0)) + let an1 = prev.setAnchor(new Vector2(w/2,0)) + let an2 = prev.setAnchor(new Vector2(w/2,0)) let constraint = new DistanceConstraint(prev, chain, prev.getAnchor(an1),chain.getAnchor(an2)) bodies.push( @@ -55,15 +55,15 @@ function createChain(x, y, w, h, number, spacing, pin1, pin2) { prev = chain } if (pin1) { - let an1 = pin1.get("body").setAnchor(new Vec2(0,0)) - let an2 = bodies[0].get("body").setAnchor(new Vec2(-w/2,0)) + let an1 = pin1.get("body").setAnchor(new Vector2(0,0)) + let an2 = bodies[0].get("body").setAnchor(new Vector2(-w/2,0)) let constraint = new DistanceConstraint(pin1.get("body"), bodies[0].get("body"), pin1.get("body").getAnchor(an1), bodies[0].get("body").getAnchor(an2)) constraints.push(constraint) pin1.get("body").mask.group = 1 } if (pin2) { - let an1 = pin2.get("body").setAnchor(new Vec2(0,0)) - let an2 = bodies[bodies.length - 1].get("body").setAnchor(new Vec2(w/2,0)) + let an1 = pin2.get("body").setAnchor(new Vector2(0,0)) + let an2 = bodies[bodies.length - 1].get("body").setAnchor(new Vector2(w/2,0)) let constraint = new DistanceConstraint(pin2.get("body"), bodies[bodies.length - 1].get("body"), pin2.get("body").getAnchor(an1), bodies[bodies.length - 1].get("body").getAnchor(an2)) constraints.push(constraint) pin2.get("body").mask.group = 1 diff --git a/demos/car.js b/demos/car.js index 8f9b680a..82602b10 100644 --- a/demos/car.js +++ b/demos/car.js @@ -1,5 +1,5 @@ import { - Vec2, + Vector2, DistanceConstraint, Entity, Box, @@ -27,8 +27,8 @@ function createCar(x, y, tireSize = 20, maskgroup = 1, manager) { let tirebody1 = new Ball(tireSize) let tirebody2 = new Ball(tireSize) let carbody = new Box(100, 50) - let an1 = carbody.setAnchor(new Vec2(30,25)) - let an2 = carbody.setAnchor(new Vec2(-30,25)) + let an1 = carbody.setAnchor(new Vector2(30,25)) + let an2 = carbody.setAnchor(new Vector2(-30,25)) let constraint1 = new DistanceConstraint(carbody, tirebody1,carbody.getAnchor(an1)) let constraint2 = new DistanceConstraint(carbody, tirebody2,carbody.getAnchor(an2)) let carCompositeBody = new Composite() diff --git a/demos/constraints.js b/demos/constraints.js index d43b194e..01a3e997 100644 --- a/demos/constraints.js +++ b/demos/constraints.js @@ -1,5 +1,5 @@ import { - Vec2, + Vector2, Entity, Box, BodySprite, @@ -20,8 +20,8 @@ export function constraint(manager) { box2.attach("body", body2) .attach("sprite", new BodySprite()) - let an1 = body1.setAnchor(new Vec2(25,-25)) - let an2 = body2.setAnchor(new Vec2(-25,-25)) + let an1 = body1.setAnchor(new Vector2(25,-25)) + let an2 = body2.setAnchor(new Vector2(-25,-25)) let constraint1 = new DistanceConstraint(body1,body2,body1.getAnchor(an1),body2.getAnchor(an2)) diff --git a/demos/marterial.js b/demos/marterial.js index b1d6a3ca..acbabcd0 100644 --- a/demos/marterial.js +++ b/demos/marterial.js @@ -4,7 +4,7 @@ import { BasicMaterial, StaticImageMaterial, SpriteMaterial, - Vec2, + Vector2, Entity } from "/src/index.js" const assets = { @@ -15,10 +15,10 @@ const assets = { export function materials(manager) { manager.clear() let geometry = new BufferGeometry([ - new Vec2(-50, -50), - new Vec2(-50, 50), - new Vec2(50, 50), - new Vec2(50, -50) + new Vector2(-50, -50), + new Vector2(-50, 50), + new Vector2(50, 50), + new Vector2(50, -50) ]) //Basic material diff --git a/demos/pathfollower.js b/demos/pathfollower.js index 2eb6e0c3..e9be3b53 100644 --- a/demos/pathfollower.js +++ b/demos/pathfollower.js @@ -7,7 +7,7 @@ import { PathFollowing, WanderBehaviour, Path, - Vec2 + Vector2 } from "/src/index.js" export function pathfollower(manager) { @@ -30,11 +30,11 @@ export function pathfollower(manager) { manager.add(a) - p.add(new Vec2(100,50)) - p.add(new Vec2(300,100)) - p.add(new Vec2(300,400)) - p.add(new Vec2(200,400)) - p.add(new Vec2(100,350)) + p.add(new Vector2(100,50)) + p.add(new Vector2(300,100)) + p.add(new Vector2(300,400)) + p.add(new Vector2(200,400)) + p.add(new Vector2(100,350)) p.loop = true } \ No newline at end of file diff --git a/demos/seeker.js b/demos/seeker.js index 950efa22..fc616ea9 100644 --- a/demos/seeker.js +++ b/demos/seeker.js @@ -4,7 +4,7 @@ import { AgentSprite, SeekBehaviour, EvadeBehaviour, - Vec2, + Vector2, Box, rand } from "/src/index.js" diff --git a/demos/wanderer.js b/demos/wanderer.js index fdb6dfd3..92d6ae42 100644 --- a/demos/wanderer.js +++ b/demos/wanderer.js @@ -4,7 +4,7 @@ import { BodySprite, AgentSprite, WanderBehaviour, - Vec2, + Vector2, Box, rand } from "/src/index.js" diff --git a/dist/chaos.module.d.ts b/dist/chaos.module.d.ts index 9810791d..08c41062 100644 --- a/dist/chaos.module.d.ts +++ b/dist/chaos.module.d.ts @@ -14,13 +14,13 @@ export type Manifold = { stmp: number; impulse: number; persistent: boolean; - ca1: Vec2; - ca2: Vec2; + ca1: Vector2; + ca2: Vector2; restitution: number; staticFriction: number; kineticFriction: number; - velA: Vec2; - velB: Vec2; + velA: Vector2; + velB: Vector2; rotA: number; rotB: number; }; @@ -28,9 +28,9 @@ export type ContactManifold = { lastOverlap: number; overlap: number; done: boolean; - axis: Vec2; - verticesA: Vec2[]; - verticesB: Vec2[]; + axis: Vector2; + verticesA: Vector2[]; + verticesB: Vector2[]; vertShapeA: Shape; vertShapeB: Shape; contactNo: number; @@ -42,9 +42,9 @@ export type Vector_like = { y: number; }; export class Agent implements Component { - position: Vec2; - velocity: Vec2; - acceleration: Vec2; + position: Vector2; + velocity: Vector2; + acceleration: Vector2; orientation: Angle; rotation: Angle; maxSpeed: number; @@ -86,9 +86,9 @@ export class Angle { }; } export class ArriveBehaviour extends Behaviour { - constructor(target: Vec2); + constructor(target: Vector2); radius: number; - target: Vec2; + target: Vector2; } export class AudioHandler { private ctx; @@ -121,13 +121,13 @@ export class BasicMaterial implements Material { render(ctx: CanvasRenderingContext2D, dt: number, path: Path2D): void; } export class Behaviour { - position: Vec2; - velocity: Vec2; + position: Vector2; + velocity: Vector2; maxSpeed: number; maxForce: number; active: boolean; init(agent: Agent): void; - calc(target: Vec2, inv_dt: number): void; + calc(target: Vector2, inv_dt: number): void; draw(renderer: Renderer): void; } export class Body implements Component { @@ -147,7 +147,7 @@ export class Body implements Component { private _type; private _localanchors; private anchors; - lastPosition: Vec2; + lastPosition: Vector2; inv_mass: number; inv_inertia: number; restitution: number; @@ -177,18 +177,18 @@ export class Body implements Component { get physicsType(): number; get CHOAS_CLASSNAME(): string; get CHAOS_OBJ_TYPE(): string; - set acceleration(arg: Vec2); - get acceleration(): Vec2; - set velocity(arg: Vec2); - get velocity(): Vec2; + set acceleration(arg: Vector2); + get acceleration(): Vector2; + set velocity(arg: Vector2); + get velocity(): Vector2; set rotation(arg: Angle); get rotation(): Angle; set angle(arg: number); get angle(): number; set density(arg: number); get density(): number; - set position(arg: Vec2); - get position(): Vec2; + set position(arg: Vector2); + get position(): Vector2; set orientation(arg: Angle); get orientation(): Angle; set angularVelocity(arg: number); @@ -197,10 +197,10 @@ export class Body implements Component { get torque(): number; set angularAcceleration(arg: number); get angularAcceleration(): number; - setAnchor(v: Vec2): number; - getAnchor(index: number): Vec2; - getLocalAnchor(index: number, target?: Vec2): Vec2; - applyForce(force: Vec2, arm?: Vec2): void; + setAnchor(v: Vector2): number; + getAnchor(index: number): Vector2; + getLocalAnchor(index: number, target?: Vector2): Vector2; + applyForce(force: Vector2, arm?: Vector2): void; init(entity: Entity | null, composited?: boolean): void; update(): void; toJson(): { @@ -274,7 +274,7 @@ export class BoundingBox extends Component { min: Vector_like; intersects(bound: BoundingCircle | BoundingBox): boolean; calculateBounds(body: Body, padding?: number): void; - update(pos: Vec2): void; + update(pos: Vector2): void; clone(): BoundingBox; copy(bounds: BoundingBox): void; toJson(): { @@ -305,18 +305,18 @@ export class Box extends Body { constructor(w: number, h: number); } export class BufferGeometry { - constructor(vertices: Vec2[]); - readonly vertices: Vec2[]; + constructor(vertices: Vector2[]); + readonly vertices: Vector2[]; drawable: Path2D | WebGLVertexArrayObject; init(ctx: CanvasRenderingContext2D): void; } export class CamController { constructor(camera: Camera); - readonly offset: Vec2; + readonly offset: Vector2; transform: Transform; targetPosition: any; targetOrientation: Angle; - follow(position: Vec2, orientation?: Angle): void; + follow(position: Vector2, orientation?: Angle): void; followEntity(entity: Entity): void; setOffset(x: number, y: number): void; init(): void; @@ -324,20 +324,20 @@ export class CamController { } export class Camera { readonly transform: Transform; - set position(arg: Vec2); - get position(): Vec2; + set position(arg: Vector2); + get position(): Vector2; update(): void; } export class Circle extends Shape { static calcInertia(mass: number, radius: number): number; - constructor(radius: number, offset: Vec2, offsetAngle: number); + constructor(radius: number, offset: Vector2, offsetAngle: number); radius: number; - vertices: Vec2$1[]; + vertices: Vector2$1[]; type: number; - get position(): Vec2$1; + get position(): Vector2$1; toJson(): { radius: number; - offset: Vec2; + offset: Vector2; offAngle: number; shapeType: number; type: string; @@ -377,10 +377,10 @@ export class Composite { init(entity: Entity | null): void; add(object: Constraint | Body): number; update(): void; - set acceleration(arg: Vec2); - get acceleration(): Vec2; - set velocity(arg: Vec2); - get velocity(): Vec2; + set acceleration(arg: Vector2); + get acceleration(): Vector2; + set velocity(arg: Vector2); + get velocity(): Vector2; set angle(arg: number); get angle(): number; set mass(arg: number); @@ -389,15 +389,15 @@ export class Composite { get type(): number; set density(arg: number); get density(): number; - set position(arg: Vec2); - get position(): Vec2; + set position(arg: Vector2); + get position(): Vector2; set orientation(arg: number); get orientation(): number; set angularVelocity(arg: number); get angularVelocity(): number; } export class Constraint { - constructor(body1: Body, body2: Body, localA: Vec2, localB: Vec2); + constructor(body1: Body, body2: Body, localA: Vector2, localB: Vector2); body1: Body; body2: Body; localA: any; @@ -579,9 +579,9 @@ declare namespace Err$1 { export function assert(test: boolean, errfunc: Function, message: string): boolean; } export class EvadeBehaviour extends Behaviour { - constructor(pursuer: Vec2); + constructor(pursuer: Vector2); radius: number; - pursuer: Vec2; + pursuer: Vector2; } export class EventDispatcher { private handlers; @@ -606,15 +606,15 @@ export class Flock extends Behaviour { neighbours: Agent[]; } export class Geometry { - constructor(vertices: Vec2[]); - vertices: Vec2[]; - normals: Vec2[]; - _dynNormals: Vec2[]; + constructor(vertices: Vector2[]); + vertices: Vector2[]; + normals: Vector2[]; + _dynNormals: Vector2[]; get CHOAS_CLASSNAME(): string; get CHAOS_OBJ_TYPE(): string; - getNormals(rad: number, target: Vec2[]): Vec2[]; + getNormals(rad: number, target: Vector2[]): Vector2[]; private calcFaceNormals; - transform(vertices: Vec2[], pos: Vec2, rad: any, n: number): void; + transform(vertices: Vector2[], pos: Vector2, rad: any, n: number): void; toJson(): { vertices: any[]; }; @@ -656,7 +656,7 @@ export class Keyboard { private _onUp; } export class Line extends Shape { - constructor(length: number, offset: Vec2, offsetAngle: any); + constructor(length: number, offset: Vector2, offsetAngle: any); length: number; } export class Loader { @@ -752,7 +752,7 @@ export class Matrix2 { rotate(radians: number): this; translate(x: number, y: number): this; scale(x: number, y: number): this; - transform(v: Vec2): Vec2; + transform(v: Vector2): Vector2; invert(): this; copy(m: Matrix2): this; clone(): Matrix2; @@ -781,16 +781,16 @@ export class Mouse { export class Movable extends Component implements Component { constructor(x: number, y: number, a: number); entity: any; - velocity: Vec2$1; + velocity: Vector2$1; rotation: Angle; - acceleration: Vec2$1; + acceleration: Vector2$1; toJson(): { - velocity: Vec2$1; + velocity: Vector2$1; rotation: { deg: number; type: string | number; }; - acceleration: Vec2$1; + acceleration: Vector2$1; }; fromJson(obj: any): void; } @@ -808,9 +808,9 @@ export namespace Overlaps { function AABBvsSphere(a: BoundingBox, b: BoundingCircle): boolean; } export class Particle { - constructor(pos: Vec2, radius: number, lifespan?: number); - readonly position: Vec2; - readonly velocity: Vec2; + constructor(pos: Vector2, radius: number, lifespan?: number); + readonly position: Vector2; + readonly velocity: Vector2; active: boolean; radius: number; color: { @@ -847,21 +847,21 @@ export class Path { private _finished; private _lerpedPoint; loop: boolean; - add(point: Vec2): this; + add(point: Vector2): this; clear(): this; advance(): boolean; - update(lerpdist?: number): Vec2$1; + update(lerpdist?: number): Vector2$1; current(): any[]; - point(): Vec2$1; + point(): Vector2$1; get path(): any[]; draw(ctx: CanvasRenderingContext2D): void; } export class PathFollowing extends Behaviour { constructor(path: Path); path: Path; - calc(target: Vec2, inv_dt: number): Vec2; + calc(target: Vector2, inv_dt: number): Vector2; clear(): void; - add(point: Vec2): void; + add(point: Vector2): void; set loop(arg: boolean); get loop(): boolean; setPath(path: Path): void; @@ -869,7 +869,7 @@ export class PathFollowing extends Behaviour { } export class Pursuit extends Behaviour { init(): void; - calc(target: Vec2): void; + calc(target: Vector2): void; } declare class Tree extends Broadphase { constructor(bounds: Bounds, maxdepth?: number); @@ -885,7 +885,7 @@ declare class Tree extends Broadphase { } export class Rectangle extends Shape { static calcInertia(mass: number, width: number, height: number): number; - constructor(width: number, height: number, offset: Vec2, offsetAngle: number); + constructor(width: number, height: number, offset: Vector2, offsetAngle: number); height: number; width: number; } @@ -929,9 +929,9 @@ export class SATNarrowPhase extends NarrowPhase { getCollisionPairs(contactList: CollisionPair[], clmds?: Manifold[]): Manifold[]; } export class SeekBehaviour extends Behaviour { - constructor(target: Vec2); + constructor(target: Vector2); radius: number; - target: Vec2; + target: Vector2; } export namespace Session { function set(k: string, v: any): void; @@ -965,19 +965,19 @@ export class Shape { static calcInertia(): number; static CIRCLE: number; static POLYGON: number; - constructor(vertices: Vec2[], offset?: Vec2, offsetAngle?: number); + constructor(vertices: Vector2[], offset?: Vector2, offsetAngle?: number); readonly type: number; offAngle: number; - offPosition: Vec2; - vertices: Vec2[]; + offPosition: Vector2; + vertices: Vector2[]; geometry: Geometry; get CHOAS_CLASSNAME(): string; get CHAOS_OBJ_TYPE(): string; get area(): number; - getNormals(shape: Shape, target?: Vec2[]): Vec2[]; - update(position: Vec2, angle: number, scale: number): void; + getNormals(shape: Shape, target?: Vector2[]): Vector2[]; + update(position: Vector2, angle: number, scale: number): void; angle: number; - getVertices(axis: Vec2, target: Vec2[]): Vec2[]; + getVertices(axis: Vector2, target: Vector2[]): Vector2[]; toJson(): { type: string; geometry: { @@ -990,8 +990,8 @@ export class Shape { fromJson(obj: any): void; } export class SpringConstraint extends Constraint { - localA: Vec2$1; - localB: Vec2$1; + localA: Vector2$1; + localB: Vector2$1; fixed: boolean; maxDistance: number; } @@ -1005,8 +1005,8 @@ export class Sprite implements Component { parent: Group | null; set angle(arg: number); get angle(): number; - set position(arg: Vec2); - get position(): Vec2; + set position(arg: Vector2); + get position(): Vector2; set orientation(arg: Angle); get orientation(): Angle; render(ctx: any, dt: any): void; @@ -1068,11 +1068,11 @@ export class Touch { export class Transform implements Component { constructor(x: number, y: number, a: number); entity: any; - position: Vec2$1; + position: Vector2$1; orientation: Angle; init(): void; toJson(): { - position: Vec2$1; + position: Vector2$1; orientation: { deg: number; type: string | number; @@ -1082,7 +1082,7 @@ export class Transform implements Component { } export class Triangle extends Shape { static calcInertia(mass: any, base: any, height: any, angle: any): number; - constructor(base: number, height: number, angle: number, offset: Vec2, offsetAngle: number); + constructor(base: number, height: number, angle: number, offset: Vector2, offsetAngle: number); } export class Trigon extends Body { constructor(base: number, height: number, angle?: number); @@ -1099,18 +1099,18 @@ declare namespace Utils$1 { function inheritComponent(component: Function, overrideInit?: boolean, overrideUpdate?: boolean): void; function inheritSystem(system: Function): void; } -declare class Vec2$1 { - static getAbsDegBtwn(v1: Vec2, v2: Vec2): number; - static getAbsRadBtwn(v1: Vec2, v2: Vec2): number; - static getRadBtwn(v1: Vec2, v2: Vec2): number; - static getDegBtwn(v1: Vec2, v2: Vec2): number; - static fromRad(radian: number, target?: Vec2): Vec2; - static fromDeg(degree: number, target?: Vec2): Vec2; - static random(target?: Vec2): Vec2; - static lerp(v1: Vec2, v2: Vec2, t: number, target?: Vec2): Vec2; - static toDeg(v: Vec2): number; - static toRad(v: Vec2): number; - static readonly ZERO: Vec2; +declare class Vector2$1 { + static getAbsDegBtwn(v1: Vector2, v2: Vector2): number; + static getAbsRadBtwn(v1: Vector2, v2: Vector2): number; + static getRadBtwn(v1: Vector2, v2: Vector2): number; + static getDegBtwn(v1: Vector2, v2: Vector2): number; + static fromRad(radian: number, target?: Vector2): Vector2; + static fromDeg(degree: number, target?: Vector2): Vector2; + static random(target?: Vector2): Vector2; + static lerp(v1: Vector2, v2: Vector2, t: number, target?: Vector2): Vector2; + static toDeg(v: Vector2): number; + static toRad(v: Vector2): number; + static readonly ZERO: Vector2; constructor(x: number, y: number); x: number; y: number; @@ -1119,29 +1119,29 @@ declare class Vec2$1 { magnitude(): number; setMagnitude(length: number): void; magnitudeSquared(): number; - distanceTo(v: Vec2): number; - distanceToSquared(v: Vec2): number; - add(v: Vec2): this; + distanceTo(v: Vector2): number; + distanceToSquared(v: Vector2): number; + add(v: Vector2): this; addScalar(n: number): this; - sub(v: Vec2): this; + sub(v: Vector2): this; subScalar(n: number): this; - dot(v: Vec2): number; - cross(v: Vec2): number; + dot(v: Vector2): number; + cross(v: Vector2): number; multiply(n: number): this; divide(n: number): this; normalize(): this; - equals(v: Vec2): boolean; + equals(v: Vector2): boolean; equalsZero(): boolean; - normal(l?: number, target?: Vec2): Vec2; - normalFast(target?: Vec2): Vec2; + normal(l?: number, target?: Vector2): Vector2; + normalFast(target?: Vector2): Vector2; rotate(rad: number): this; toArray(target?: number[], offset?: number): number[]; - clone(): Vec2$1; - copy(v: Vec2): this; + clone(): Vector2$1; + copy(v: Vector2): this; set(x: number, y: number): this; draw(ctx: CanvasRenderingContext2D, x?: number, y?: number, color?: string, scale?: number): this; reverse(): this; - reflect(normal: number, target?: Vec2): Vec2; + reflect(normal: number, target?: Vector2): Vector2; clamp(min?: number, max?: number): this; toJson(): this; fromJson(obj: any): void; @@ -1168,7 +1168,7 @@ export class World { velocitySolverIterations: number; CLMDs: Manifold[]; contactList: CollisionPair[]; - gravitationalAcceleration: Vec2; + gravitationalAcceleration: Vector2; fixedFrameRate: number; perf: { lastTimestamp: number; @@ -1176,8 +1176,8 @@ export class World { }; broadphase: Broadphase; narrowphase: NarrowPhase; - set gravity(arg: Vec2); - get gravity(): Vec2; + set gravity(arg: Vector2); + get gravity(): Vector2; private narrowPhase; broadPhase(): void; private collisionDetection; @@ -1219,7 +1219,7 @@ export function round(number: number, precision?: number): number; export function sq(x: number): number; export function sqrt(x: number): number; export function stroke(ctx: CanvasRenderingContext2D, color?: string, width?: number): void; -export function vertices(ctx: CanvasRenderingContext2D, vertices: Vec2[], close?: boolean): void; +export function vertices(ctx: CanvasRenderingContext2D, vertices: Vector2[], close?: boolean): void; export function wrapAngle(x: any): any; declare class Node { constructor(bounds: { @@ -1265,5 +1265,5 @@ declare class Broadphase { getCollisionPairs(target: CollisionPair[]): CollisionPair[]; query(bounds: Bounds, target: Body[]): Body[]; } -declare let r: Vec2$1; -export { Err$1 as Err, Matrix2 as Matrix, Tree as QuadTreeBroadphase, Utils$1 as Utils, Vec2$1 as Vec2 }; +declare let r: Vector2$1; +export { Err$1 as Err, Matrix2 as Matrix, Tree as QuadTreeBroadphase, Utils$1 as Utils, Vector2$1 as Vector2 }; diff --git a/dist/chaos.module.js b/dist/chaos.module.js index 1b428d30..968b9b2b 100644 --- a/dist/chaos.module.js +++ b/dist/chaos.module.js @@ -570,7 +570,7 @@ class BoundingBox extends Component { /** * Translates this bound to the given position. * - * @param { Vec2} pos + * @param { Vector2} pos */ update(pos) { let dx = pos.x - this.pos.x; @@ -867,7 +867,7 @@ let TWO_PI = Math.PI * 2; * @author Wayne Mwashuma * @license MIT */ -class Vec2$1 { +class Vector2$1 { /** * @param {number} x the x coordinate of the vector * @param {number} y the y coordinate of the vector @@ -913,28 +913,28 @@ class Vec2$1 { } /** *Calculates length of this vector to another vector - * @param { Vec2} v the other vector + * @param { Vector2} v the other vector */ distanceTo(v) { obj$1.x = this.x - v.x; obj$1.y = this.y - v.y; - return Math.sqrt( Vec2$1.prototype.magnitudeSquared.call(obj$1)) + return Math.sqrt( Vector2$1.prototype.magnitudeSquared.call(obj$1)) } /** *Calculates length squared of this vector to another vector * - * @param { Vec2} v the other vector + * @param { Vector2} v the other vector * @returns {number} */ distanceToSquared(v) { obj$1.x = this.x - v.x; obj$1.y = this.y - v.y; - return Vec2$1.prototype.magnitudeSquared.call(obj$1) + return Vector2$1.prototype.magnitudeSquared.call(obj$1) } /** * Adds a given vector into this * - * @param { Vec2} v + * @param { Vector2} v * @returns {this} */ add(v) { @@ -957,7 +957,7 @@ class Vec2$1 { /** * Subtracts a given vector from this vector * - * @param { Vec2} v + * @param { Vector2} v * @returns {this} */ sub(v) { @@ -979,7 +979,7 @@ class Vec2$1 { /** * Calculates the dot product of two vectors. * - * @param { Vec2} v + * @param { Vector2} v * @returns {number} */ dot(v) { @@ -988,7 +988,7 @@ class Vec2$1 { /** * Calculates the cross product of two vectors. * - * @param { Vec2} v + * @param { Vector2} v * @returns {number} */ cross(v) { @@ -1032,7 +1032,7 @@ class Vec2$1 { * Checks to see if this vector is equal to * another vector. * - * @param { Vec2} v + * @param { Vector2} v * @returns {boolean} */ equals(v) { @@ -1050,21 +1050,21 @@ class Vec2$1 { * Returns a scaled vector normal to this vector,when scaled to 1,it returns a unit vector. * * @param {number} l the length of the vector returned. - * @param { Vec2} [target = Vec2] Vec2 in which results are stored. - * @returns { Vec2} + * @param { Vector2} [target = Vector2] Vector2 in which results are stored. + * @returns { Vector2} */ normal(l = 1, target) { - target = target || new Vec2$1(); + target = target || new Vector2$1(); target.copy(this).normalize(); return target.set(-target.y * l, target.x * l); }; /** * Returns the normal to a vector, the normal has the same length as the vector. * - * @param { Vec2} [target = Vec2] Vec2 in which results are stored. - * @returns { Vec2} + * @param { Vector2} [target = Vector2] Vector2 in which results are stored. + * @returns { Vector2} */ - normalFast(target = new Vec2$1()) { + normalFast(target = new Vector2$1()) { return target.set(-this.y, this.x) } /** @@ -1101,16 +1101,16 @@ class Vec2$1 { * Copies x and y values of this vector to * a new vector and returns the new vector. * - * @return Vec2 + * @return Vector2 */ clone() { - return new Vec2$1(this.x, this.y) + return new Vector2$1(this.x, this.y) } /** * Copies x and y values of another vector * to this vector. * - * @@param { Vec2} v + * @@param { Vector2} v * @return this */ copy(v) { @@ -1166,10 +1166,10 @@ class Vec2$1 { * Returns a vector of this reflected on a sirface perpendicular to the normal. * * @param {number} normal the unit vector perpendicular to reflection surface - * @param { Vec2} [target] - * @return { Vec2} + * @param { Vector2} [target] + * @return { Vector2} */ - reflect(normal, target = new Vec2$1()) { + reflect(normal, target = new Vector2$1()) { return target.copy(normal).multiply(this.dot(normal) * 2).sub(this) } /** @@ -1207,33 +1207,33 @@ class Vec2$1 { * Gets the angle (in degrees) between two * vectors in the range 0° to 360° in the anticlockwise direction from v1 to v2 * - * @param { Vec2} v1 start of the angle - * @param { Vec2} v2 end of the angle + * @param { Vector2} v1 start of the angle + * @param { Vector2} v2 end of the angle * @returns {number} */ static getAbsDegBtwn(v1, v2) { let a = v1.cross(v2); - let deg = Vec2$1.getDegBtwn(v1, v2); + let deg = Vector2$1.getDegBtwn(v1, v2); return a < 0 ? deg : 360 - deg } /** - * Same as ` Vec2.getAbsDegBtwn` but returns in radians. + * Same as ` Vector2.getAbsDegBtwn` but returns in radians. * - * @param { Vec2 } v1 start of the angle - * @param { Vec2 } v2 end of the angle + * @param { Vector2 } v1 start of the angle + * @param { Vector2 } v2 end of the angle * @returns {number} **/ static getAbsRadBtwn(v1, v2) { let a = v1.cross(v2); - let deg = Vec2$1.getDegBtwn(v1, v2); + let deg = Vector2$1.getDegBtwn(v1, v2); return a < 0 ? deg : 360 - deg } /** * Gets the angle (in radians) between two * vectors in the shortest direction from v1 to v2 in the range of `0` to `Math.PI` * - * @param { Vec2} v1 start of the angle - * @param { Vec2} v2 end of the angle + * @param { Vector2} v1 start of the angle + * @param { Vector2} v2 end of the angle * @returns {number} */ static getRadBtwn(v1, v2) { @@ -1243,22 +1243,22 @@ class Vec2$1 { * Gets the angle (in degrees) between two * vectors in shortest direction from v1 to v2 in the range `0°` to `180°` * - * @param { Vec2} v1 start of the angle - * @param { Vec2} v2 end of the angle + * @param { Vector2} v1 start of the angle + * @param { Vector2} v2 end of the angle * @returns {number} */ static getDegBtwn(v1, v2) { - return Vec2$1.getRadBtwn(v1, v2) * 180 / Math.PI + return Vector2$1.getRadBtwn(v1, v2) * 180 / Math.PI } /** * Returns a unit vector pointing in the * given angle starting from the positive x axis. * * @param {number} radian angle in radians from 0 to `Math.PI * 2` - * @param { Vec2} [target] Vec2 to store results in. - * @returns { Vec2} + * @param { Vector2} [target] Vector2 to store results in. + * @returns { Vector2} */ - static fromRad(radian, target = new Vec2$1()) { + static fromRad(radian, target = new Vector2$1()) { return target.set(Math.cos(radian), Math.sin(radian)) } /** @@ -1266,32 +1266,32 @@ class Vec2$1 { * given angle from the positive x axis * * @param {number} degree angle in radians from `0°` to `360°` - * @param { Vec2} [target] Vec2 to store results in. - * @returns { Vec2} + * @param { Vector2} [target] Vector2 to store results in. + * @returns { Vector2} */ static fromDeg(degree, target) { - return Vec2$1.fromRad(degree * Math.PI / 180, target) + return Vector2$1.fromRad(degree * Math.PI / 180, target) } /** - * Generates a new unit Vec2 in a random direction + * Generates a new unit Vector2 in a random direction * - * @param { Vec2} [target] - * @returns { Vec2} + * @param { Vector2} [target] + * @returns { Vector2} */ static random(target) { - return Vec2$1.fromRad(Math.random() * TWO_PI, target) + return Vector2$1.fromRad(Math.random() * TWO_PI, target) } /** - * Returns a Vec2 that has been lerped between v1 and v2 - * @param { Vec2} v1 the vector to lerp from - * @param { Vec2} v2 the vector to lerp from - * @param {number} t a value from 0 to 1 to scale the new Vec2 between v1 and v2 - * @param { Vec2} [target] the vector to store results into + * Returns a Vector2 that has been lerped between v1 and v2 + * @param { Vector2} v1 the vector to lerp from + * @param { Vector2} v2 the vector to lerp from + * @param {number} t a value from 0 to 1 to scale the new Vector2 between v1 and v2 + * @param { Vector2} [target] the vector to store results into * - * @returns { Vec2} + * @returns { Vector2} */ - static lerp(v1, v2, t, target = new Vec2$1()) { - target = target || new Vec2$1(); + static lerp(v1, v2, t, target = new Vector2$1()) { + target = target || new Vector2$1(); return target.set( (v2.x - v1.x) * t + v1.x, (v2.y - v1.y) * t + v1.y @@ -1301,17 +1301,17 @@ class Vec2$1 { /** * Returns the angle in degrees between the positive x-axis and the vector. * - * @param { Vec2} v + * @param { Vector2} v * @returns {number} */ static toDeg(v) { - return Vec2$1.toRad(v) / Math.PI * 180 + return Vector2$1.toRad(v) / Math.PI * 180 } /** * Returns the angle in radians between the positive x-axis and the vector. * - * @param { Vec2} v + * @param { Vector2} v * @returns {number} */ static toRad(v) { @@ -1324,9 +1324,9 @@ class Vec2$1 { * * @static * @readonly - * @type { Vec2} + * @type { Vector2} */ - static ZERO = Object.freeze(new Vec2$1()) + static ZERO = Object.freeze(new Vector2$1()) } @@ -1558,7 +1558,7 @@ class Matrix2 { /** * Transforms the given vector. * - * @param { Vec2} v + * @param { Vector2} v */ transform(v) { let x = v.x; @@ -1890,19 +1890,19 @@ const Interpolation = { class Geometry { /** - * @type Vec2[] + * @type Vector2[] */ vertices = null /** - * @type Vec2[] + * @type Vector2[] */ normals = null /** - * @type Vec2[] + * @type Vector2[] */ _dynNormals = null /** - * @param { Vec2[]} vertices + * @param { Vector2[]} vertices */ constructor(vertices) { this.vertices = vertices; @@ -1923,7 +1923,7 @@ class Geometry { } /** * @param {number} rad - * @param { Vec2[]} target + * @param { Vector2[]} target */ getNormals(rad, target) { target = target || []; @@ -1934,7 +1934,7 @@ class Geometry { } /** * @private - * @returns Vec2[] + * @returns Vector2[] */ calcFaceNormals() { const axes = [], @@ -1956,8 +1956,8 @@ class Geometry { } /** * @param {number} n - * @param { Vec2[]} vertices - * @param { Vec2} pos + * @param { Vector2[]} vertices + * @param { Vector2} pos * @patam {number} rad */ transform(vertices, pos, rad, n) { @@ -1976,7 +1976,7 @@ class Geometry { return obj } fromJson(obj){ - this.vertices = obj.vertices.map(v=>new Vec2().fromJson(v)); + this.vertices = obj.vertices.map(v=>new Vector2().fromJson(v)); this.normals = this.calcFaceNormals(); this._dynNormals = this.normals.map(e => e.clone()); } @@ -2022,7 +2022,7 @@ const Settings = { type:BodyType.DYNAMIC }; -let tmp1$c = new Vec2$1(); +let tmp1$c = new Vector2$1(); /** * This class makes a body tangible @@ -2045,13 +2045,13 @@ class Shape { /** * The offset position of this shape from this body's position. * - * @type Vec2 + * @type Vector2 */ offPosition = null /** * The vertices describing the shape. * - * @type Vec2[] + * @type Vector2[] */ vertices = null /** @@ -2062,11 +2062,11 @@ class Shape { geometry = null /** - * @param { Vec2[]} vertices The vertices of the shape in local space coordinates. - * @param { Vec2} [offset=vector] offset position relative to parent body + * @param { Vector2[]} vertices The vertices of the shape in local space coordinates. + * @param { Vector2} [offset=vector] offset position relative to parent body * @param {number} [offsetAngle=0] offset angle relative to parent body. */ - constructor(vertices, offset = new Vec2$1(), offsetAngle = 0) { + constructor(vertices, offset = new Vector2$1(), offsetAngle = 0) { this.offPosition = offset; this.offAngle = offsetAngle * Math.PI / 180; this.vertices = vertices.map(v => v.clone()); @@ -2095,8 +2095,8 @@ class Shape { * Returns the normals of the faces when rotated. * * @param {Shape} shape - * @param { Vec2[]} [target=[]] An array where results are stored. - * @returns { Vec2[]} + * @param { Vector2[]} [target=[]] An array where results are stored. + * @returns { Vector2[]} */ getNormals(shape, target) { return this.geometry.getNormals(this.angle, target) @@ -2104,7 +2104,7 @@ class Shape { /** * Transforms the local coordinates of the vertices to world coordinates. * - * @param { Vec2} position the world position of the body + * @param { Vector2} position the world position of the body * @param {number} angle the orientation of body * @param {number} scale the scale of the body */ @@ -2116,9 +2116,9 @@ class Shape { /** * Returns the world coordinates of the vertices. * - * @param { Vec2} axis - * @param { Vec2[]} target - * @returns { Vec2[]} + * @param { Vector2} axis + * @param { Vector2[]} target + * @returns { Vector2[]} */ getVertices(axis, target) { return this.vertices @@ -2160,19 +2160,19 @@ class Line extends Shape { length = 0 /** * @param {number} length - * @param { Vec2} offset + * @param { Vector2} offset * @param {number} pffsetAngle */ constructor(length,offset,offsetAngle) { - let start = new Vec2$1(1).multiply(length / 2), - end = new Vec2$1(1).multiply(-length / 2); + let start = new Vector2$1(1).multiply(length / 2), + end = new Vector2$1(1).multiply(-length / 2); super([start, end],offset,offsetAngle); this.length = length; } } -let _vec1 = new Vec2$1(); -let _vec2 = new Vec2$1(); +let _vec1 = new Vector2$1(); +let _vec2 = new Vector2$1(); /** * A circular shape. @@ -2185,14 +2185,14 @@ class Circle extends Shape { radius = 0 /** * @param {number} radius - * @param { Vec2} offset Positional offset from the body center. + * @param { Vector2} offset Positional offset from the body center. * @param {number} offsetAngle Angular offset from the body center. */ constructor(radius, offset, offsetAngle) { //the first vertex is position super([], offset, offsetAngle); - this.vertices = [new Vec2$1(), new Vec2$1(), new Vec2$1()]; + this.vertices = [new Vector2$1(), new Vector2$1(), new Vector2$1()]; this.radius = radius; this.type = Shape.CIRCLE; } @@ -2210,9 +2210,9 @@ class Circle extends Shape { /** * @inheritdoc * - * @param { Vec2} axis - * @param { Vec2[]} out - * @returns { Vec2[]} + * @param { Vector2} axis + * @param { Vector2[]} out + * @returns { Vector2[]} */ getVertices(axis, out) { let target = out || []; @@ -2225,8 +2225,8 @@ class Circle extends Shape { /** * * @param {Shape} shape - * @param { Vec2[]} [target=[]] target - * @returns Array< Vec2> + * @param { Vector2[]} [target=[]] target + * @returns Array< Vector2> */ getNormals(shape, target = []) { let min = null, @@ -2245,7 +2245,7 @@ class Circle extends Shape { /** * @inheritdoc * - * @param { Vec2} position + * @param { Vector2} position * @param {number} angle * @param {number} scale */ @@ -2269,7 +2269,7 @@ class Circle extends Shape { fromJson(obj) { return new Circle( obj.radius, - new Vec2$1().fromJson(obj.offset), + new Vector2$1().fromJson(obj.offset), obj.offAngle ) } @@ -2287,14 +2287,14 @@ class Rectangle extends Shape { /** * @param {number} width * @param {number} height - * @param { Vec2} offset Positional offset from the body center. + * @param { Vector2} offset Positional offset from the body center. * @param {number} offsetAngle Angular offset from the body center. */ constructor(width, height, offset, offsetAngle) { - let v1 = new Vec2$1(-width / 2, -height / 2); - let v2 = new Vec2$1(-width / 2, height / 2); - let v3 = new Vec2$1(width / 2, height / 2); - let v4 = new Vec2$1(width / 2, -height / 2); + let v1 = new Vector2$1(-width / 2, -height / 2); + let v2 = new Vector2$1(-width / 2, height / 2); + let v3 = new Vector2$1(width / 2, height / 2); + let v4 = new Vector2$1(width / 2, -height / 2); super([v1, v2, v3, v4], offset, offsetAngle); this.height = height; this.width = width; @@ -2315,7 +2315,7 @@ class Rectangle extends Shape { } -let tmp1$b = new Vec2$1(); +let tmp1$b = new Vector2$1(); /** * A triangular shape. @@ -2327,16 +2327,16 @@ class Triangle extends Shape { * @param {number} base Length of one side. * @param {number} height Length of a second side. * @param {number} angle The angle between the two sides. - * @param { Vec2} offset Positional offset from the body center. + * @param { Vector2} offset Positional offset from the body center. * @param {number} offsetAngle Angular offset from the body center. * */ constructor(base, height, angle, offset, offsetAngle) { - let l1 = new Vec2$1().set(1, 0).multiply(base); - let l2 = Vec2$1.fromRad(angle).multiply(height/Math.sin(angle)); + let l1 = new Vector2$1().set(1, 0).multiply(base); + let l2 = Vector2$1.fromRad(angle).multiply(height/Math.sin(angle)); let center = tmp1$b.set((l1.x + l2.x) / 3, l2.y / 3); super([ - new Vec2$1().sub(center), + new Vector2$1().sub(center), l1.sub(center), l2.sub(center) ], offset, offsetAngle); @@ -2362,23 +2362,23 @@ class Body { * World space coordinates of a body * * @private - * @type Vec2 + * @type Vector2 */ - _position = new Vec2$1() + _position = new Vector2$1() /** * velocity of a body.Speed in pixels per second. * * @private - * @type Vec2 + * @type Vector2 */ - _velocity = new Vec2$1() + _velocity = new Vector2$1() /** * acceleration of a body in pixels per second squared. * * @private - * @type Vec2 + * @type Vector2 */ - _acceleration = new Vec2$1() + _acceleration = new Vector2$1() /** * World space orientation of a body * @@ -2426,22 +2426,22 @@ class Body { * Anchors of the body in local space. * * @private - * @type Vec2[] + * @type Vector2[] */ _localanchors = [] /** * The original anchors of the body in local space. * * @private - * @type Vec2[] + * @type Vector2[] */ anchors = [] /** * Position of a body in the last frame.. * - * @type Vec2 + * @type Vector2 */ - lastPosition = new Vec2$1() + lastPosition = new Vector2$1() /** * Inverse mass of the body. * @@ -2612,7 +2612,7 @@ class Body { /** * Acceleration of a body * - * @type Vec2 + * @type Vector2 */ get acceleration() { return this._acceleration @@ -2623,7 +2623,7 @@ class Body { /** * Velocity of a body * - * @type Vec2 + * @type Vector2 */ get velocity() { return this._velocity @@ -2700,7 +2700,7 @@ class Body { /** * World space position of a body * - * @type Vec2 + * @type Vector2 */ get position() { return this._position @@ -2755,11 +2755,11 @@ class Body { /** * Sets an anchor that is relative to the center of the body into it.The anchor's world coordinates will be updated when the body too is updated. * - * @param { Vec2} v The anchor arm + * @param { Vector2} v The anchor arm * @returns {number} */ setAnchor(v) { - this.anchors.push(new Vec2$1(v.x, v.y).rotate(this.orientation.radian).add(this.position)); + this.anchors.push(new Vector2$1(v.x, v.y).rotate(this.orientation.radian).add(this.position)); return this._localanchors.push(v) - 1 } /** @@ -2767,7 +2767,7 @@ class Body { * Treat the returned value as read-only. * * @param {number} index the position of the - * @returns { Vec2} + * @returns { Vector2} */ getAnchor(index) { return this.anchors[index] @@ -2776,20 +2776,20 @@ class Body { * Returns a rotated anchor relative to the body. * * @param {number} index The position of the anchor. - * @param { Vec2} [target= Vec2] Vec2 to store results in. - * @returns { Vec2} + * @param { Vector2} [target= Vector2] Vector2 to store results in. + * @returns { Vector2} */ - getLocalAnchor(index, target = new Vec2$1()) { + getLocalAnchor(index, target = new Vector2$1()) { return target.copy(this._localanchors[index]).rotate(this.orientation.radian) } /** * Applies a force to a body affecting its direction of travel and rotation. * * - * @param { Vec2} force The force to be applied. - * @param { Vec2} [arm= Vec2] The collision arm. + * @param { Vector2} force The force to be applied. + * @param { Vector2} [arm= Vector2] The collision arm. */ - applyForce(force, arm = Vec2$1.ZERO) { + applyForce(force, arm = Vector2$1.ZERO) { this.acceleration.add(force.multiply(this.inv_mass)); this.rotation.degree += arm.cross(force) * this.inv_inertia; } @@ -2889,7 +2889,7 @@ class Body { body.id = obj.id; body.mask = obj.mask; obj.anchors.forEach((v) => { - body.setAnchor(new Vec2$1().fromJson(v)); + body.setAnchor(new Vector2$1().fromJson(v)); }); } /** @@ -3033,10 +3033,10 @@ class Composite { /** * Acceleration of a body * - * @type Vec2 + * @type Vector2 */ get acceleration() { - let acceleration = new Vec2$1(); + let acceleration = new Vector2$1(); for (var i = 0; i < this.bodies.length; i++) { acceleration.copy(this.bodies[i].acceleration); } @@ -3050,10 +3050,10 @@ class Composite { /** * Velocity of a body * - * @type Vec2 + * @type Vector2 */ get velocity() { - let velocity = new Vec2$1(); + let velocity = new Vector2$1(); for (var i = 0; i < this.bodies.length; i++) { velocity.add(this.bodies[i].velocity); @@ -3127,10 +3127,10 @@ class Composite { /** * Position of a body * - * @type Vec2 + * @type Vector2 */ get position() { - let position = new Vec2$1(); + let position = new Vector2$1(); for (var i = 0; i < this.shapes.length; i++) { position.add(this.bodies[i].position); } @@ -3218,14 +3218,14 @@ class Constraint { /** * @param {Body} body1 * @param {Body} body2 - * @param { Vec2} localA - * @param { Vec2} localB + * @param { Vector2} localA + * @param { Vector2} localB */ constructor(body1, body2, localA, localB) { this.body1 = body1; this.body2 = body2; - this.localA = localA || new Vec2$1(); - this.localB = localB || new Vec2$1(); + this.localA = localA || new Vector2$1(); + this.localB = localB || new Vector2$1(); this.stiffness = 50; this.dampening = 0.03; } @@ -3287,8 +3287,8 @@ class Constraint { let constraint = new Constraint( bod1, bod2, - new Vec2$1().fromJson(obj.localA), - new Vec2$1().fromJson(obj.localB) + new Vector2$1().fromJson(obj.localA), + new Vector2$1().fromJson(obj.localB) ); constraint.stiffness = obj.stiffness; constraint.dampening = obj.dampening; @@ -3296,11 +3296,11 @@ class Constraint { } } -let tmp1$a = new Vec2$1(), - tmp2$8 = new Vec2$1(), - tmp3$4 = new Vec2$1(), - tmp4$4 = new Vec2$1(), - tmp5$3 = new Vec2$1(); +let tmp1$a = new Vector2$1(), + tmp2$8 = new Vector2$1(), + tmp3$4 = new Vector2$1(), + tmp4$4 = new Vector2$1(), + tmp5$3 = new Vector2$1(); /** * This constraint is stronger than a spring in the sense that it will not oscilate as such as a spring constraint. @@ -3309,8 +3309,8 @@ class DistanceConstraint extends Constraint { /** * @param {Body} body1 * @param {Body} body2 - * @param { Vec2} localA - * @param { Vec2} localB + * @param { Vector2} localA + * @param { Vector2} localB */ constructor(body1, body2, localA, localB) { super(body1, body2,localA,localB); @@ -3355,12 +3355,12 @@ class DistanceConstraint extends Constraint { } } -let tmp1$9 = new Vec2$1(), - tmp2$7 = new Vec2$1(), - tmp3$3 = new Vec2$1(), - tmp4$3 = new Vec2$1(), - tmp5$2 = new Vec2$1(), - zero = new Vec2$1(); +let tmp1$9 = new Vector2$1(), + tmp2$7 = new Vector2$1(), + tmp3$3 = new Vector2$1(), + tmp4$3 = new Vector2$1(), + tmp5$2 = new Vector2$1(), + zero = new Vector2$1(); /** * A constraint that acts like a spring between two bodies */ @@ -3368,13 +3368,13 @@ class SpringConstraint extends Constraint { /** * @param {Body} body1 * @param {Body} body2 - * @param { Vec2} localA - * @param { Vec2} localB + * @param { Vector2} localA + * @param { Vector2} localB */ constructor(body1, body2, localA, localB) { super(body1, body2); - this.localA = new Vec2$1().copy(localA || zero); - this.localB = new Vec2$1().copy(localB || zero); + this.localA = new Vector2$1().copy(localA || zero); + this.localB = new Vector2$1().copy(localB || zero); this.fixed = !body1.mass || !body2.mass; this.dampening = 1; this.maxDistance = 100; @@ -3411,11 +3411,11 @@ class SpringConstraint extends Constraint { } } -new Vec2$1(); +new Vector2$1(); -let position = new Vec2$1(); -let acceleration = new Vec2$1(); -let velocity = new Vec2$1(); +let position = new Vector2$1(); +let acceleration = new Vector2$1(); +let velocity = new Vector2$1(); /** * Verlet intergration. @@ -3441,11 +3441,11 @@ class VerletSolver { } } -let tmp1$8 = new Vec2$1(), - tmp2$6 = new Vec2$1(), - tmp3$2 = new Vec2$1(), - tmp4$2 = new Vec2$1(), - tmp5$1 = new Vec2$1(); +let tmp1$8 = new Vector2$1(), + tmp2$6 = new Vector2$1(), + tmp3$2 = new Vector2$1(), + tmp4$2 = new Vector2$1(), + tmp5$1 = new Vector2$1(); /** * Solves for impulse along collision tangent for a given body pair. @@ -3521,8 +3521,8 @@ const ContactSolver = { } }; -const tmp1$7 = new Vec2$1(), - tmp2$5 = new Vec2$1(); +const tmp1$7 = new Vector2$1(), + tmp2$5 = new Vector2$1(); let dampen = Settings.posDampen; /** @@ -3544,10 +3544,10 @@ const PenetrationSolver = { } }; -let tmp1$6 = new Vec2$1(), - tmp2$4 = new Vec2$1(), - tmp3$1 = new Vec2$1(), - tmp4$1 = new Vec2$1(); +let tmp1$6 = new Vector2$1(), + tmp2$4 = new Vector2$1(), + tmp3$1 = new Vector2$1(), + tmp4$1 = new Vector2$1(); /** * Solves for the collision normal impulse of a given body pair. @@ -4196,7 +4196,7 @@ const _arr = [], overlap: 0, verticesA: null, verticesB: null, - axis: new Vec2$1(), + axis: new Vector2$1(), vertex: null, shape: null }, @@ -4210,9 +4210,9 @@ const _arr = [], max: 0, indexN: 0 }, - tmp4 = new Vec2$1(), - tmp5 = new Vec2$1(), - tmp6 = new Vec2$1(); + tmp4 = new Vector2$1(), + tmp5 = new Vector2$1(), + tmp6 = new Vector2$1(); /** * Used for narrowphase collision detection and contact info generation. @@ -4299,7 +4299,7 @@ const SAT = { /** * @param {Shape} shapeA * @param {Shape} shapeB - * @param { Vec2[]} axes + * @param { Vector2[]} axes * @param {Manifold} shapeA * @param {number} iu */ @@ -4359,8 +4359,8 @@ const SAT = { return manifold }, /** - * @param { Vec2[]} vertices - * @param { Vec2} axis + * @param { Vector2[]} vertices + * @param { Vector2} axis * @param {Object} target */ projectVerticesToAxis(vertices, axis, target) { @@ -4385,9 +4385,9 @@ const SAT = { return target }, /** - * @param { Vec2[]} vertices - * @param { Vec2} axis - * @param { Vec2[]} target + * @param { Vector2[]} vertices + * @param { Vector2} axis + * @param { Vector2[]} target * @param {number} nearVertexIndex */ findNearSupports(vertices, axis, target = [], nearVertexIndex) { @@ -4415,7 +4415,7 @@ const SAT = { }, /** * @param {Shape} shape - * @param { Vec2} point + * @param { Vector2} point */ shapeContains(shape, point) { if (shape.type == "circle") @@ -4423,9 +4423,9 @@ const SAT = { return SAT.verticesContain(shape.vertices, point) }, /** - * @param { Vec2} position + * @param { Vector2} position * @param {number} radius - * @param { Vec2} point + * @param { Vector2} point */ circleContains(position, radius, point) { let dx = point.x - position.x, @@ -4435,7 +4435,7 @@ const SAT = { return true }, /** - * @param { Vec2[]} vertices + * @param { Vector2[]} vertices * @param {number} point */ verticesContain(vertices, point) { @@ -4487,7 +4487,7 @@ class SATNarrowPhase extends NarrowPhase { lastOverlap: 0, overlap: -Infinity, done: false, - axis: new Vec2$1(), + axis: new Vector2$1(), verticesA: [], verticesB: [], vertShapeA: null, @@ -4500,13 +4500,13 @@ class SATNarrowPhase extends NarrowPhase { stmp: -1, impulse: 0, persistent: false, - ca1: new Vec2$1(), - ca2: new Vec2$1(), + ca1: new Vector2$1(), + ca2: new Vector2$1(), restitution: 0, staticFriction: 0, kineticFriction: 0, - velA: new Vec2$1(), - velB: new Vec2$1(), + velA: new Vector2$1(), + velB: new Vector2$1(), rotA: 0, rotB: 0 }); @@ -4517,13 +4517,13 @@ class SATNarrowPhase extends NarrowPhase { SAT.shapesInBodyCollided(a, b, collisionData); if (collisionData.overlap < 0 || !collisionData.done) continue if (collisionData.contactNo == 2) { - Vec2$1.lerp( + Vector2$1.lerp( collisionData.verticesA[0], collisionData.verticesA[1], 0.5, manifold.ca1 ).sub(a.position); - Vec2$1.lerp( + Vector2$1.lerp( collisionData.verticesB[0], collisionData.verticesB[1], 0.5, @@ -4617,9 +4617,9 @@ class World { /** * The gravitational pull of the world. * - * @type Vec2 + * @type Vector2 */ - gravitationalAcceleration = new Vec2$1(0, 0) + gravitationalAcceleration = new Vector2$1(0, 0) /** * Time in seconds that a single frame takes.This has more precedence than the first parameter of World.update(),set to this to zero if you want to use the latter as the delta time. * @@ -4666,7 +4666,7 @@ class World { /** * Gravitational pull of the world,will affect all bodies except static bodies. * - * @type { Vec2 } + * @type { Vector2 } */ get gravity() { return this.gravitationalAcceleration @@ -4955,7 +4955,7 @@ class Transform { * @returns */ constructor(x,y,a){ - this.position = new Vec2$1(x,y); + this.position = new Vector2$1(x,y); this.orientation = new Angle(a); } init(){} @@ -4980,7 +4980,7 @@ class Camera { constructor() { } /** - * @type Vec2 + * @type Vector2 */ get position() { return this.transform.position @@ -5316,7 +5316,7 @@ class Sprite { /** * World space position. * - * @type Vec2 + * @type Vector2 */ get position() { return this._position @@ -5350,9 +5350,9 @@ class Sprite { */ init(entity) { if(!entity){ - this._position = new Vec2$1(); + this._position = new Vector2$1(); this._orientation = new Angle(); - this._scale = new Vec2$1(1,1); + this._scale = new Vector2$1(1,1); return } this.entity = entity; @@ -5361,7 +5361,7 @@ class Sprite { this._position = transform.position; this._orientation = transform.orientation; //TODO - Correct this later - this._scale = new Vec2$1(1,1); + this._scale = new Vector2$1(1,1); return this } toJson(){ @@ -5511,7 +5511,7 @@ function circle(ctx, x, y, r) { } /** * @param {CanvasRenderingContext2D} ctx - * @param { Vec2[]} vertices + * @param { Vector2[]} vertices * @param {boolean} [close=true] */ function vertices(ctx, vertices, close = true) { @@ -5728,7 +5728,7 @@ class SpriteMaterial { } } -let r = new Vec2$1(); +let r = new Vector2$1(); let material$1 = new BasicMaterial(); material$1.wireframe = true; /** @@ -5856,7 +5856,7 @@ class BodySprite extends Sprite { shape.position.x, shape.position.y, shape.radius); - Vec2$1.fromRad(shape.angle, r).multiply(shape.radius); + Vector2$1.fromRad(shape.angle, r).multiply(shape.radius); line(ctx, ...shape.position, shape.position.x + r.x, shape.position.y + r.y); @@ -5880,7 +5880,7 @@ class BodySprite extends Sprite { class BufferGeometry { /** * @readonly - * @type Vec2[] + * @type Vector2[] */ vertices = null /** @@ -5889,7 +5889,7 @@ class BufferGeometry { */ drawable = null /** - * @param { Vec2[]} vertices + * @param { Vector2[]} vertices */ constructor(vertices) { this.vertices = vertices || []; @@ -5927,9 +5927,9 @@ class CircleGeometry { } let geometry = new BufferGeometry([ - new Vec2$1(-10, -10), - new Vec2$1(-10, 10), - new Vec2$1(20, 0) + new Vector2$1(-10, -10), + new Vector2$1(-10, 10), + new Vector2$1(20, 0) ]); let material = new BasicMaterial(); material.fill = "purple"; @@ -5972,12 +5972,12 @@ class AgentSprite extends Sprite { class Particle { /** * @readonly - * @type Vec2 + * @type Vector2 */ position = null /** * @readonly - * @type Vec2 + * @type Vector2 */ velocity = null /** @@ -6003,13 +6003,13 @@ class Particle { */ lifespan = 0 /** - * @param { Vec2} pos + * @param { Vector2} pos * @param {number} radius * @param {number} [lifespan=5] In seconds */ constructor(pos, radius, lifespan = 5) { this.position = pos; - this.velocity = new Vec2$1(); + this.velocity = new Vector2$1(); this.radius = radius; this.color = { r: 100, @@ -6097,7 +6097,7 @@ class ParticleSystemSprite extends Sprite { */ create() { return new Particle( - new Vec2$1(...this.position), + new Vector2$1(...this.position), rand(1, 10), rand(1, 6) ) @@ -6225,20 +6225,20 @@ class Group extends Sprite { class CamController { /** * @readonly - * @type Vec2 + * @type Vector2 */ - offset = new Vec2$1() + offset = new Vector2$1() /** * @param {Camera} camera */ constructor(camera) { this.transform = camera.transform; - this.offset = new Vec2$1(); + this.offset = new Vector2$1(); this.targetPosition = null; this.targetOrientation = null; } /** - * @param { Vec2} position + * @param { Vector2} position * @param {Angle} orientation */ follow(position, orientation = null) { @@ -7510,9 +7510,9 @@ class Movable extends Component { */ constructor(x, y, a) { super(); - this.velocity = new Vec2$1(x, y); + this.velocity = new Vector2$1(x, y); this.rotation = new Angle(a); - this.acceleration = new Vec2$1(); + this.acceleration = new Vector2$1(); } toJson() { return { @@ -8185,7 +8185,7 @@ class BehaviourManager { /** * Accumulated force from behaviours to apply to agent */ - _accumulated = new Vec2$1() + _accumulated = new Vector2$1() /** * Adds a behavior to the manager * @@ -8220,14 +8220,14 @@ class BehaviourManager { * @param {number} inv_dt */ update(inv_dt) { - let result = new Vec2$1(); + let result = new Vector2$1(); this._accumulated.set(0, 0); for (let i = 0; i < this._behaviours.length; i++) { this._behaviours[i].calc(result, inv_dt); this._accumulated.add(result); } this._agent.acceleration.add(this._accumulated); - this._agent.orientation.radian = Vec2$1.toRad(this._agent.velocity); + this._agent.orientation.radian = Vector2$1.toRad(this._agent.velocity); } /** * Removes all behaviours from a manager. @@ -8253,19 +8253,19 @@ class Agent { /** * The position of the entity. * - * @type Vec2 + * @type Vector2 */ position = null /** * The velocity of the entity. * - * @type Vec2 + * @type Vector2 */ velocity = null /** * The acceleration of the entity. * - * @type Vec2 + * @type Vector2 */ acceleration = null /** @@ -8355,13 +8355,13 @@ class Behaviour { /** * The position of the agent. * - * @type Vec2 + * @type Vector2 */ position = null /** * The velocity of the agent. * - * @type Vec2 + * @type Vector2 */ velocity = null /** @@ -8391,9 +8391,9 @@ class Behaviour { /** * Calculates the amount of force required to satisfy a behavior. * - * @param { Vec2} target + * @param { Vector2} target * @param {number} inv_dt - * @returns Vec2 the first parameter + * @returns Vector2 the first parameter */ calc(target, inv_dt) {} /** @@ -8404,7 +8404,7 @@ class Behaviour { draw(renderer) {} } -let tmp1$4 = new Vec2$1(); +let tmp1$4 = new Vector2$1(); /** * Creates a behaviour to evade a certain position. * @@ -8418,7 +8418,7 @@ class EvadeBehaviour extends Behaviour { */ radius = 200 /** - * @param { Vec2} pursuer + * @param { Vector2} pursuer */ constructor(pursuer) { super(); @@ -8435,9 +8435,9 @@ class EvadeBehaviour extends Behaviour { } /** * @inheritdoc - * @param { Vec2} target + * @param { Vector2} target * @param {number} inv_dt - * @returns Vec2 the first parameter + * @returns Vector2 the first parameter */ calc(target,inv_dt) { let difference = tmp1$4.copy(this.position).sub(this.pursuer); @@ -8451,8 +8451,8 @@ class EvadeBehaviour extends Behaviour { } } -let tmp1$3 = new Vec2$1(), - tmp2$2 = new Vec2$1(); +let tmp1$3 = new Vector2$1(), + tmp2$2 = new Vector2$1(); /** * Creates a behaviour that is used to make an agent wander in an organic manner. @@ -8489,21 +8489,21 @@ class WanderBehaviour extends Behaviour { } /** * @inheritdoc - * @param { Vec2} target + * @param { Vector2} target * @param {number} inv_dt - * @returns Vec2 the first parameter + * @returns Vector2 the first parameter */ calc(target, inv_dt) { this._theta += rand(-this.dtheta, +this.dtheta); let forward = tmp1$3.copy(this.velocity); if (forward.equalsZero()) - Vec2$1.random(forward); + Vector2$1.random(forward); let radius = this._radius * 0.8; forward.setMagnitude(this._radius); //ctx.arc(...tmp2.copy(this.position).add(forward), radius, 0, Math.PI * 2) //ctx.stroke() - Vec2$1.fromDeg(this._theta + Vec2$1.toDeg(this.velocity), tmp2$2).multiply(radius); + Vector2$1.fromDeg(this._theta + Vector2$1.toDeg(this.velocity), tmp2$2).multiply(radius); forward.add(tmp2$2); //forward.draw(ctx,...this.position) forward.setMagnitude(this.maxSpeed); @@ -8531,9 +8531,9 @@ class Pursuit extends Behaviour { } /** * @inheritdoc - * @param { Vec2} target + * @param { Vector2} target * @param {number} inv_dt - * @returns Vec2 the first parameter + * @returns Vector2 the first parameter */ calc(target){ @@ -8563,16 +8563,16 @@ class Flock extends Behaviour{ } /** * @inheritdoc - * @param { Vec2} target + * @param { Vector2} target * @param {number} inv_dt - * @returns Vec2 the first parameter + * @returns Vector2 the first parameter */ calc(target,inv_dt) { } } -let tmp1$2 = new Vec2$1(); +let tmp1$2 = new Vector2$1(); /** * Creates a behaviour to seek out a target and move towards it. @@ -8588,11 +8588,11 @@ class SeekBehaviour extends Behaviour { */ radius = 100 /** - * @type Vec2 + * @type Vector2 */ target = null /** - * @param { Vec2} target + * @param { Vector2} target */ constructor(target) { super(); @@ -8608,9 +8608,9 @@ class SeekBehaviour extends Behaviour { } /** * @inheritdoc - * @param { Vec2} target + * @param { Vector2} target * @param {number} inv_dt - * @returns Vec2 the first parameter + * @returns Vector2 the first parameter */ calc(target,inv_dt) { let difference = tmp1$2.copy(this.target).sub(this.position); @@ -8622,8 +8622,8 @@ class SeekBehaviour extends Behaviour { } } -let tmp1$1 = new Vec2$1(), - tmp2$1 = new Vec2$1(); +let tmp1$1 = new Vector2$1(), + tmp2$1 = new Vector2$1(); /** * This provides a seek behaviour which slows down when the agent approaches a target. @@ -8638,7 +8638,7 @@ class ArriveBehaviour extends Behaviour { */ radius = 1000 /** - * @param { Vec2} target + * @param { Vector2} target */ constructor(target) { super(); @@ -8655,9 +8655,9 @@ class ArriveBehaviour extends Behaviour { } /** * @inheritdoc - * @param { Vec2} target + * @param { Vector2} target * @param {number} inv_dt - * @returns Vec2 the first parameter + * @returns Vector2 the first parameter */ calc(target, inv_dt) { let difference = tmp1$1.copy(this.target).sub(this.position); @@ -8678,8 +8678,8 @@ class ArriveBehaviour extends Behaviour { } } -const tmp1 = new Vec2$1(); -const tmp2 = new Vec2$1(); +const tmp1 = new Vector2$1(); +const tmp2 = new Vector2$1(); /** * Creates a behaviour that follows a certain path. * @@ -8702,9 +8702,9 @@ class PathFollowing extends Behaviour { } /** * @inheritdoc - * @param { Vec2} target + * @param { Vector2} target * @param {number} inv_dt - * @returns Vec2 the first parameter + * @returns Vector2 the first parameter */ calc(target, inv_dt) { tmp1.copy(this.position); @@ -8742,7 +8742,7 @@ class PathFollowing extends Behaviour { /** * Adds a point into the path. * - * @param { Vec2} point + * @param { Vector2} point */ add(point) { this.path.add(point); @@ -8779,11 +8779,11 @@ class PathFollowing extends Behaviour { } } -let tmp = new Vec2$1(); +let tmp = new Vector2$1(); class Path { /** * @private - * type Vec2[] + * type Vector2[] */ _points = [] /** @@ -8821,15 +8821,15 @@ class Path { _finished = false /** * @private - * type Vec2 + * type Vector2 */ - _lerpedPoint = new Vec2$1() + _lerpedPoint = new Vector2$1() /** * type boolean */ loop = false /** - * @param { Vec2} point + * @param { Vector2} point */ add(point) { this._points.push(point); @@ -8878,7 +8878,7 @@ class Path { if (!this.advance()) this._finished = true; } this._lerp_t = clamp(this._lerp_t, 0, 1); - Vec2$1.lerp( + Vector2$1.lerp( this._points[this._way[0]], this._points[this._way[1]], this._lerp_t, @@ -9214,7 +9214,7 @@ const Storage = { } }; -export { Agent, AgentManager, AgentSprite, Angle, ArriveBehaviour, AudioHandler, Ball, BasicMaterial, Behaviour, Body, BodySprite, Bound, BoundingBox, BoundingCircle, Box, BufferGeometry, CamController, Camera, Circle, CircleGeometry, Clock, Component, Composite, Constraint, Cookies, DEVICE, DOMEventHandler, DistanceConstraint, Easing, Entity, Err$1 as Err, EvadeBehaviour, EventDispatcher, Events, Flock, Geometry, Group, Input, Interpolation, Keyboard, Line, Loader, Manager, Material, Matrix2 as Matrix, Matrix2, Mouse, Movable, NaiveBroadphase, NarrowPhase, Overlaps, Particle, ParticleSystemSprite, Path, PathFollowing, Pursuit, Tree as QuadTreeBroadphase, Rectangle, Renderer, Renderer2D, SATNarrowPhase, SeekBehaviour, Session, Sfx, Shape, SpringConstraint, Sprite, SpriteMaterial, StaticImageMaterial, Storage, System, Touch, Transform, Triangle, Trigon, Utils$1 as Utils, Vec2$1 as Vec2, WanderBehaviour, WebGLRenderer, WebGPURenderer, World, arc, circle, clamp, defaultCollisionHandler, defaultPrecollisionHandler, degToRad, drawImage, exp, fill, fillText, lerp, line, map, naturalizePair, radToDeg, rand, rect, round, sq, sqrt, stroke, vertices, wrapAngle }; +export { Agent, AgentManager, AgentSprite, Angle, ArriveBehaviour, AudioHandler, Ball, BasicMaterial, Behaviour, Body, BodySprite, Bound, BoundingBox, BoundingCircle, Box, BufferGeometry, CamController, Camera, Circle, CircleGeometry, Clock, Component, Composite, Constraint, Cookies, DEVICE, DOMEventHandler, DistanceConstraint, Easing, Entity, Err$1 as Err, EvadeBehaviour, EventDispatcher, Events, Flock, Geometry, Group, Input, Interpolation, Keyboard, Line, Loader, Manager, Material, Matrix2 as Matrix, Matrix2, Mouse, Movable, NaiveBroadphase, NarrowPhase, Overlaps, Particle, ParticleSystemSprite, Path, PathFollowing, Pursuit, Tree as QuadTreeBroadphase, Rectangle, Renderer, Renderer2D, SATNarrowPhase, SeekBehaviour, Session, Sfx, Shape, SpringConstraint, Sprite, SpriteMaterial, StaticImageMaterial, Storage, System, Touch, Transform, Triangle, Trigon, Utils$1 as Utils, Vector2$1 as Vector2, WanderBehaviour, WebGLRenderer, WebGPURenderer, World, arc, circle, clamp, defaultCollisionHandler, defaultPrecollisionHandler, degToRad, drawImage, exp, fill, fillText, lerp, line, map, naturalizePair, radToDeg, rand, rect, round, sq, sqrt, stroke, vertices, wrapAngle }; /** * @typedef Bounds * @property {Vector_like} max @@ -9233,13 +9233,13 @@ export { Agent, AgentManager, AgentSprite, Angle, ArriveBehaviour, AudioHandler, * @property {number} stmp * @property {number} impulse * @property {boolean} persistent - * @property { Vec2} ca1 - * @property { Vec2} ca2 + * @property { Vector2} ca1 + * @property { Vector2} ca2 * @property {number} restitution * @property {number} staticFriction * @property {number} kineticFriction - * @property { Vec2} velA - * @property { Vec2} velB + * @property { Vector2} velA + * @property { Vector2} velB * @property {number} rotA * @property {number} rotB */ @@ -9249,9 +9249,9 @@ export { Agent, AgentManager, AgentSprite, Angle, ArriveBehaviour, AudioHandler, * @property {number} lastOverlap * @property {number} overlap=-Infinity * @property {boolean} done=false - * @property { Vec2} axis - * @property { Vec2[]} verticesA - * @property { Vec2[]} verticesB + * @property { Vector2} axis + * @property { Vector2[]} verticesA + * @property { Vector2[]} verticesB * @property {Shape} vertShapeA * @property {Shape} vertShapeB * @property {number} contactNo diff --git a/dist/chaos.umd.js b/dist/chaos.umd.js index 5355a79c..1534a38f 100644 --- a/dist/chaos.umd.js +++ b/dist/chaos.umd.js @@ -576,7 +576,7 @@ SOFTWARE. /** * Translates this bound to the given position. * - * @param { Vec2} pos + * @param { Vector2} pos */ update(pos) { let dx = pos.x - this.pos.x; @@ -873,7 +873,7 @@ SOFTWARE. * @author Wayne Mwashuma * @license MIT */ - class Vec2$1 { + class Vector2$1 { /** * @param {number} x the x coordinate of the vector * @param {number} y the y coordinate of the vector @@ -919,28 +919,28 @@ SOFTWARE. } /** *Calculates length of this vector to another vector - * @param { Vec2} v the other vector + * @param { Vector2} v the other vector */ distanceTo(v) { obj$1.x = this.x - v.x; obj$1.y = this.y - v.y; - return Math.sqrt( Vec2$1.prototype.magnitudeSquared.call(obj$1)) + return Math.sqrt( Vector2$1.prototype.magnitudeSquared.call(obj$1)) } /** *Calculates length squared of this vector to another vector * - * @param { Vec2} v the other vector + * @param { Vector2} v the other vector * @returns {number} */ distanceToSquared(v) { obj$1.x = this.x - v.x; obj$1.y = this.y - v.y; - return Vec2$1.prototype.magnitudeSquared.call(obj$1) + return Vector2$1.prototype.magnitudeSquared.call(obj$1) } /** * Adds a given vector into this * - * @param { Vec2} v + * @param { Vector2} v * @returns {this} */ add(v) { @@ -963,7 +963,7 @@ SOFTWARE. /** * Subtracts a given vector from this vector * - * @param { Vec2} v + * @param { Vector2} v * @returns {this} */ sub(v) { @@ -985,7 +985,7 @@ SOFTWARE. /** * Calculates the dot product of two vectors. * - * @param { Vec2} v + * @param { Vector2} v * @returns {number} */ dot(v) { @@ -994,7 +994,7 @@ SOFTWARE. /** * Calculates the cross product of two vectors. * - * @param { Vec2} v + * @param { Vector2} v * @returns {number} */ cross(v) { @@ -1038,7 +1038,7 @@ SOFTWARE. * Checks to see if this vector is equal to * another vector. * - * @param { Vec2} v + * @param { Vector2} v * @returns {boolean} */ equals(v) { @@ -1056,21 +1056,21 @@ SOFTWARE. * Returns a scaled vector normal to this vector,when scaled to 1,it returns a unit vector. * * @param {number} l the length of the vector returned. - * @param { Vec2} [target = Vec2] Vec2 in which results are stored. - * @returns { Vec2} + * @param { Vector2} [target = Vector2] Vector2 in which results are stored. + * @returns { Vector2} */ normal(l = 1, target) { - target = target || new Vec2$1(); + target = target || new Vector2$1(); target.copy(this).normalize(); return target.set(-target.y * l, target.x * l); }; /** * Returns the normal to a vector, the normal has the same length as the vector. * - * @param { Vec2} [target = Vec2] Vec2 in which results are stored. - * @returns { Vec2} + * @param { Vector2} [target = Vector2] Vector2 in which results are stored. + * @returns { Vector2} */ - normalFast(target = new Vec2$1()) { + normalFast(target = new Vector2$1()) { return target.set(-this.y, this.x) } /** @@ -1107,16 +1107,16 @@ SOFTWARE. * Copies x and y values of this vector to * a new vector and returns the new vector. * - * @return Vec2 + * @return Vector2 */ clone() { - return new Vec2$1(this.x, this.y) + return new Vector2$1(this.x, this.y) } /** * Copies x and y values of another vector * to this vector. * - * @@param { Vec2} v + * @@param { Vector2} v * @return this */ copy(v) { @@ -1172,10 +1172,10 @@ SOFTWARE. * Returns a vector of this reflected on a sirface perpendicular to the normal. * * @param {number} normal the unit vector perpendicular to reflection surface - * @param { Vec2} [target] - * @return { Vec2} + * @param { Vector2} [target] + * @return { Vector2} */ - reflect(normal, target = new Vec2$1()) { + reflect(normal, target = new Vector2$1()) { return target.copy(normal).multiply(this.dot(normal) * 2).sub(this) } /** @@ -1213,33 +1213,33 @@ SOFTWARE. * Gets the angle (in degrees) between two * vectors in the range 0° to 360° in the anticlockwise direction from v1 to v2 * - * @param { Vec2} v1 start of the angle - * @param { Vec2} v2 end of the angle + * @param { Vector2} v1 start of the angle + * @param { Vector2} v2 end of the angle * @returns {number} */ static getAbsDegBtwn(v1, v2) { let a = v1.cross(v2); - let deg = Vec2$1.getDegBtwn(v1, v2); + let deg = Vector2$1.getDegBtwn(v1, v2); return a < 0 ? deg : 360 - deg } /** - * Same as ` Vec2.getAbsDegBtwn` but returns in radians. + * Same as ` Vector2.getAbsDegBtwn` but returns in radians. * - * @param { Vec2 } v1 start of the angle - * @param { Vec2 } v2 end of the angle + * @param { Vector2 } v1 start of the angle + * @param { Vector2 } v2 end of the angle * @returns {number} **/ static getAbsRadBtwn(v1, v2) { let a = v1.cross(v2); - let deg = Vec2$1.getDegBtwn(v1, v2); + let deg = Vector2$1.getDegBtwn(v1, v2); return a < 0 ? deg : 360 - deg } /** * Gets the angle (in radians) between two * vectors in the shortest direction from v1 to v2 in the range of `0` to `Math.PI` * - * @param { Vec2} v1 start of the angle - * @param { Vec2} v2 end of the angle + * @param { Vector2} v1 start of the angle + * @param { Vector2} v2 end of the angle * @returns {number} */ static getRadBtwn(v1, v2) { @@ -1249,22 +1249,22 @@ SOFTWARE. * Gets the angle (in degrees) between two * vectors in shortest direction from v1 to v2 in the range `0°` to `180°` * - * @param { Vec2} v1 start of the angle - * @param { Vec2} v2 end of the angle + * @param { Vector2} v1 start of the angle + * @param { Vector2} v2 end of the angle * @returns {number} */ static getDegBtwn(v1, v2) { - return Vec2$1.getRadBtwn(v1, v2) * 180 / Math.PI + return Vector2$1.getRadBtwn(v1, v2) * 180 / Math.PI } /** * Returns a unit vector pointing in the * given angle starting from the positive x axis. * * @param {number} radian angle in radians from 0 to `Math.PI * 2` - * @param { Vec2} [target] Vec2 to store results in. - * @returns { Vec2} + * @param { Vector2} [target] Vector2 to store results in. + * @returns { Vector2} */ - static fromRad(radian, target = new Vec2$1()) { + static fromRad(radian, target = new Vector2$1()) { return target.set(Math.cos(radian), Math.sin(radian)) } /** @@ -1272,32 +1272,32 @@ SOFTWARE. * given angle from the positive x axis * * @param {number} degree angle in radians from `0°` to `360°` - * @param { Vec2} [target] Vec2 to store results in. - * @returns { Vec2} + * @param { Vector2} [target] Vector2 to store results in. + * @returns { Vector2} */ static fromDeg(degree, target) { - return Vec2$1.fromRad(degree * Math.PI / 180, target) + return Vector2$1.fromRad(degree * Math.PI / 180, target) } /** - * Generates a new unit Vec2 in a random direction + * Generates a new unit Vector2 in a random direction * - * @param { Vec2} [target] - * @returns { Vec2} + * @param { Vector2} [target] + * @returns { Vector2} */ static random(target) { - return Vec2$1.fromRad(Math.random() * TWO_PI, target) + return Vector2$1.fromRad(Math.random() * TWO_PI, target) } /** - * Returns a Vec2 that has been lerped between v1 and v2 - * @param { Vec2} v1 the vector to lerp from - * @param { Vec2} v2 the vector to lerp from - * @param {number} t a value from 0 to 1 to scale the new Vec2 between v1 and v2 - * @param { Vec2} [target] the vector to store results into + * Returns a Vector2 that has been lerped between v1 and v2 + * @param { Vector2} v1 the vector to lerp from + * @param { Vector2} v2 the vector to lerp from + * @param {number} t a value from 0 to 1 to scale the new Vector2 between v1 and v2 + * @param { Vector2} [target] the vector to store results into * - * @returns { Vec2} + * @returns { Vector2} */ - static lerp(v1, v2, t, target = new Vec2$1()) { - target = target || new Vec2$1(); + static lerp(v1, v2, t, target = new Vector2$1()) { + target = target || new Vector2$1(); return target.set( (v2.x - v1.x) * t + v1.x, (v2.y - v1.y) * t + v1.y @@ -1307,17 +1307,17 @@ SOFTWARE. /** * Returns the angle in degrees between the positive x-axis and the vector. * - * @param { Vec2} v + * @param { Vector2} v * @returns {number} */ static toDeg(v) { - return Vec2$1.toRad(v) / Math.PI * 180 + return Vector2$1.toRad(v) / Math.PI * 180 } /** * Returns the angle in radians between the positive x-axis and the vector. * - * @param { Vec2} v + * @param { Vector2} v * @returns {number} */ static toRad(v) { @@ -1330,9 +1330,9 @@ SOFTWARE. * * @static * @readonly - * @type { Vec2} + * @type { Vector2} */ - static ZERO = Object.freeze(new Vec2$1()) + static ZERO = Object.freeze(new Vector2$1()) } @@ -1564,7 +1564,7 @@ SOFTWARE. /** * Transforms the given vector. * - * @param { Vec2} v + * @param { Vector2} v */ transform(v) { let x = v.x; @@ -1896,19 +1896,19 @@ SOFTWARE. class Geometry { /** - * @type Vec2[] + * @type Vector2[] */ vertices = null /** - * @type Vec2[] + * @type Vector2[] */ normals = null /** - * @type Vec2[] + * @type Vector2[] */ _dynNormals = null /** - * @param { Vec2[]} vertices + * @param { Vector2[]} vertices */ constructor(vertices) { this.vertices = vertices; @@ -1929,7 +1929,7 @@ SOFTWARE. } /** * @param {number} rad - * @param { Vec2[]} target + * @param { Vector2[]} target */ getNormals(rad, target) { target = target || []; @@ -1940,7 +1940,7 @@ SOFTWARE. } /** * @private - * @returns Vec2[] + * @returns Vector2[] */ calcFaceNormals() { const axes = [], @@ -1962,8 +1962,8 @@ SOFTWARE. } /** * @param {number} n - * @param { Vec2[]} vertices - * @param { Vec2} pos + * @param { Vector2[]} vertices + * @param { Vector2} pos * @patam {number} rad */ transform(vertices, pos, rad, n) { @@ -1982,7 +1982,7 @@ SOFTWARE. return obj } fromJson(obj){ - this.vertices = obj.vertices.map(v=>new Vec2().fromJson(v)); + this.vertices = obj.vertices.map(v=>new Vector2().fromJson(v)); this.normals = this.calcFaceNormals(); this._dynNormals = this.normals.map(e => e.clone()); } @@ -2028,7 +2028,7 @@ SOFTWARE. type:BodyType.DYNAMIC }; - let tmp1$c = new Vec2$1(); + let tmp1$c = new Vector2$1(); /** * This class makes a body tangible @@ -2051,13 +2051,13 @@ SOFTWARE. /** * The offset position of this shape from this body's position. * - * @type Vec2 + * @type Vector2 */ offPosition = null /** * The vertices describing the shape. * - * @type Vec2[] + * @type Vector2[] */ vertices = null /** @@ -2068,11 +2068,11 @@ SOFTWARE. geometry = null /** - * @param { Vec2[]} vertices The vertices of the shape in local space coordinates. - * @param { Vec2} [offset=vector] offset position relative to parent body + * @param { Vector2[]} vertices The vertices of the shape in local space coordinates. + * @param { Vector2} [offset=vector] offset position relative to parent body * @param {number} [offsetAngle=0] offset angle relative to parent body. */ - constructor(vertices, offset = new Vec2$1(), offsetAngle = 0) { + constructor(vertices, offset = new Vector2$1(), offsetAngle = 0) { this.offPosition = offset; this.offAngle = offsetAngle * Math.PI / 180; this.vertices = vertices.map(v => v.clone()); @@ -2101,8 +2101,8 @@ SOFTWARE. * Returns the normals of the faces when rotated. * * @param {Shape} shape - * @param { Vec2[]} [target=[]] An array where results are stored. - * @returns { Vec2[]} + * @param { Vector2[]} [target=[]] An array where results are stored. + * @returns { Vector2[]} */ getNormals(shape, target) { return this.geometry.getNormals(this.angle, target) @@ -2110,7 +2110,7 @@ SOFTWARE. /** * Transforms the local coordinates of the vertices to world coordinates. * - * @param { Vec2} position the world position of the body + * @param { Vector2} position the world position of the body * @param {number} angle the orientation of body * @param {number} scale the scale of the body */ @@ -2122,9 +2122,9 @@ SOFTWARE. /** * Returns the world coordinates of the vertices. * - * @param { Vec2} axis - * @param { Vec2[]} target - * @returns { Vec2[]} + * @param { Vector2} axis + * @param { Vector2[]} target + * @returns { Vector2[]} */ getVertices(axis, target) { return this.vertices @@ -2166,19 +2166,19 @@ SOFTWARE. length = 0 /** * @param {number} length - * @param { Vec2} offset + * @param { Vector2} offset * @param {number} pffsetAngle */ constructor(length,offset,offsetAngle) { - let start = new Vec2$1(1).multiply(length / 2), - end = new Vec2$1(1).multiply(-length / 2); + let start = new Vector2$1(1).multiply(length / 2), + end = new Vector2$1(1).multiply(-length / 2); super([start, end],offset,offsetAngle); this.length = length; } } - let _vec1 = new Vec2$1(); - let _vec2 = new Vec2$1(); + let _vec1 = new Vector2$1(); + let _vec2 = new Vector2$1(); /** * A circular shape. @@ -2191,14 +2191,14 @@ SOFTWARE. radius = 0 /** * @param {number} radius - * @param { Vec2} offset Positional offset from the body center. + * @param { Vector2} offset Positional offset from the body center. * @param {number} offsetAngle Angular offset from the body center. */ constructor(radius, offset, offsetAngle) { //the first vertex is position super([], offset, offsetAngle); - this.vertices = [new Vec2$1(), new Vec2$1(), new Vec2$1()]; + this.vertices = [new Vector2$1(), new Vector2$1(), new Vector2$1()]; this.radius = radius; this.type = Shape.CIRCLE; } @@ -2216,9 +2216,9 @@ SOFTWARE. /** * @inheritdoc * - * @param { Vec2} axis - * @param { Vec2[]} out - * @returns { Vec2[]} + * @param { Vector2} axis + * @param { Vector2[]} out + * @returns { Vector2[]} */ getVertices(axis, out) { let target = out || []; @@ -2231,8 +2231,8 @@ SOFTWARE. /** * * @param {Shape} shape - * @param { Vec2[]} [target=[]] target - * @returns Array< Vec2> + * @param { Vector2[]} [target=[]] target + * @returns Array< Vector2> */ getNormals(shape, target = []) { let min = null, @@ -2251,7 +2251,7 @@ SOFTWARE. /** * @inheritdoc * - * @param { Vec2} position + * @param { Vector2} position * @param {number} angle * @param {number} scale */ @@ -2275,7 +2275,7 @@ SOFTWARE. fromJson(obj) { return new Circle( obj.radius, - new Vec2$1().fromJson(obj.offset), + new Vector2$1().fromJson(obj.offset), obj.offAngle ) } @@ -2293,14 +2293,14 @@ SOFTWARE. /** * @param {number} width * @param {number} height - * @param { Vec2} offset Positional offset from the body center. + * @param { Vector2} offset Positional offset from the body center. * @param {number} offsetAngle Angular offset from the body center. */ constructor(width, height, offset, offsetAngle) { - let v1 = new Vec2$1(-width / 2, -height / 2); - let v2 = new Vec2$1(-width / 2, height / 2); - let v3 = new Vec2$1(width / 2, height / 2); - let v4 = new Vec2$1(width / 2, -height / 2); + let v1 = new Vector2$1(-width / 2, -height / 2); + let v2 = new Vector2$1(-width / 2, height / 2); + let v3 = new Vector2$1(width / 2, height / 2); + let v4 = new Vector2$1(width / 2, -height / 2); super([v1, v2, v3, v4], offset, offsetAngle); this.height = height; this.width = width; @@ -2321,7 +2321,7 @@ SOFTWARE. } - let tmp1$b = new Vec2$1(); + let tmp1$b = new Vector2$1(); /** * A triangular shape. @@ -2333,16 +2333,16 @@ SOFTWARE. * @param {number} base Length of one side. * @param {number} height Length of a second side. * @param {number} angle The angle between the two sides. - * @param { Vec2} offset Positional offset from the body center. + * @param { Vector2} offset Positional offset from the body center. * @param {number} offsetAngle Angular offset from the body center. * */ constructor(base, height, angle, offset, offsetAngle) { - let l1 = new Vec2$1().set(1, 0).multiply(base); - let l2 = Vec2$1.fromRad(angle).multiply(height/Math.sin(angle)); + let l1 = new Vector2$1().set(1, 0).multiply(base); + let l2 = Vector2$1.fromRad(angle).multiply(height/Math.sin(angle)); let center = tmp1$b.set((l1.x + l2.x) / 3, l2.y / 3); super([ - new Vec2$1().sub(center), + new Vector2$1().sub(center), l1.sub(center), l2.sub(center) ], offset, offsetAngle); @@ -2368,23 +2368,23 @@ SOFTWARE. * World space coordinates of a body * * @private - * @type Vec2 + * @type Vector2 */ - _position = new Vec2$1() + _position = new Vector2$1() /** * velocity of a body.Speed in pixels per second. * * @private - * @type Vec2 + * @type Vector2 */ - _velocity = new Vec2$1() + _velocity = new Vector2$1() /** * acceleration of a body in pixels per second squared. * * @private - * @type Vec2 + * @type Vector2 */ - _acceleration = new Vec2$1() + _acceleration = new Vector2$1() /** * World space orientation of a body * @@ -2432,22 +2432,22 @@ SOFTWARE. * Anchors of the body in local space. * * @private - * @type Vec2[] + * @type Vector2[] */ _localanchors = [] /** * The original anchors of the body in local space. * * @private - * @type Vec2[] + * @type Vector2[] */ anchors = [] /** * Position of a body in the last frame.. * - * @type Vec2 + * @type Vector2 */ - lastPosition = new Vec2$1() + lastPosition = new Vector2$1() /** * Inverse mass of the body. * @@ -2618,7 +2618,7 @@ SOFTWARE. /** * Acceleration of a body * - * @type Vec2 + * @type Vector2 */ get acceleration() { return this._acceleration @@ -2629,7 +2629,7 @@ SOFTWARE. /** * Velocity of a body * - * @type Vec2 + * @type Vector2 */ get velocity() { return this._velocity @@ -2706,7 +2706,7 @@ SOFTWARE. /** * World space position of a body * - * @type Vec2 + * @type Vector2 */ get position() { return this._position @@ -2761,11 +2761,11 @@ SOFTWARE. /** * Sets an anchor that is relative to the center of the body into it.The anchor's world coordinates will be updated when the body too is updated. * - * @param { Vec2} v The anchor arm + * @param { Vector2} v The anchor arm * @returns {number} */ setAnchor(v) { - this.anchors.push(new Vec2$1(v.x, v.y).rotate(this.orientation.radian).add(this.position)); + this.anchors.push(new Vector2$1(v.x, v.y).rotate(this.orientation.radian).add(this.position)); return this._localanchors.push(v) - 1 } /** @@ -2773,7 +2773,7 @@ SOFTWARE. * Treat the returned value as read-only. * * @param {number} index the position of the - * @returns { Vec2} + * @returns { Vector2} */ getAnchor(index) { return this.anchors[index] @@ -2782,20 +2782,20 @@ SOFTWARE. * Returns a rotated anchor relative to the body. * * @param {number} index The position of the anchor. - * @param { Vec2} [target= Vec2] Vec2 to store results in. - * @returns { Vec2} + * @param { Vector2} [target= Vector2] Vector2 to store results in. + * @returns { Vector2} */ - getLocalAnchor(index, target = new Vec2$1()) { + getLocalAnchor(index, target = new Vector2$1()) { return target.copy(this._localanchors[index]).rotate(this.orientation.radian) } /** * Applies a force to a body affecting its direction of travel and rotation. * * - * @param { Vec2} force The force to be applied. - * @param { Vec2} [arm= Vec2] The collision arm. + * @param { Vector2} force The force to be applied. + * @param { Vector2} [arm= Vector2] The collision arm. */ - applyForce(force, arm = Vec2$1.ZERO) { + applyForce(force, arm = Vector2$1.ZERO) { this.acceleration.add(force.multiply(this.inv_mass)); this.rotation.degree += arm.cross(force) * this.inv_inertia; } @@ -2895,7 +2895,7 @@ SOFTWARE. body.id = obj.id; body.mask = obj.mask; obj.anchors.forEach((v) => { - body.setAnchor(new Vec2$1().fromJson(v)); + body.setAnchor(new Vector2$1().fromJson(v)); }); } /** @@ -3039,10 +3039,10 @@ SOFTWARE. /** * Acceleration of a body * - * @type Vec2 + * @type Vector2 */ get acceleration() { - let acceleration = new Vec2$1(); + let acceleration = new Vector2$1(); for (var i = 0; i < this.bodies.length; i++) { acceleration.copy(this.bodies[i].acceleration); } @@ -3056,10 +3056,10 @@ SOFTWARE. /** * Velocity of a body * - * @type Vec2 + * @type Vector2 */ get velocity() { - let velocity = new Vec2$1(); + let velocity = new Vector2$1(); for (var i = 0; i < this.bodies.length; i++) { velocity.add(this.bodies[i].velocity); @@ -3133,10 +3133,10 @@ SOFTWARE. /** * Position of a body * - * @type Vec2 + * @type Vector2 */ get position() { - let position = new Vec2$1(); + let position = new Vector2$1(); for (var i = 0; i < this.shapes.length; i++) { position.add(this.bodies[i].position); } @@ -3224,14 +3224,14 @@ SOFTWARE. /** * @param {Body} body1 * @param {Body} body2 - * @param { Vec2} localA - * @param { Vec2} localB + * @param { Vector2} localA + * @param { Vector2} localB */ constructor(body1, body2, localA, localB) { this.body1 = body1; this.body2 = body2; - this.localA = localA || new Vec2$1(); - this.localB = localB || new Vec2$1(); + this.localA = localA || new Vector2$1(); + this.localB = localB || new Vector2$1(); this.stiffness = 50; this.dampening = 0.03; } @@ -3293,8 +3293,8 @@ SOFTWARE. let constraint = new Constraint( bod1, bod2, - new Vec2$1().fromJson(obj.localA), - new Vec2$1().fromJson(obj.localB) + new Vector2$1().fromJson(obj.localA), + new Vector2$1().fromJson(obj.localB) ); constraint.stiffness = obj.stiffness; constraint.dampening = obj.dampening; @@ -3302,11 +3302,11 @@ SOFTWARE. } } - let tmp1$a = new Vec2$1(), - tmp2$8 = new Vec2$1(), - tmp3$4 = new Vec2$1(), - tmp4$4 = new Vec2$1(), - tmp5$3 = new Vec2$1(); + let tmp1$a = new Vector2$1(), + tmp2$8 = new Vector2$1(), + tmp3$4 = new Vector2$1(), + tmp4$4 = new Vector2$1(), + tmp5$3 = new Vector2$1(); /** * This constraint is stronger than a spring in the sense that it will not oscilate as such as a spring constraint. @@ -3315,8 +3315,8 @@ SOFTWARE. /** * @param {Body} body1 * @param {Body} body2 - * @param { Vec2} localA - * @param { Vec2} localB + * @param { Vector2} localA + * @param { Vector2} localB */ constructor(body1, body2, localA, localB) { super(body1, body2,localA,localB); @@ -3361,12 +3361,12 @@ SOFTWARE. } } - let tmp1$9 = new Vec2$1(), - tmp2$7 = new Vec2$1(), - tmp3$3 = new Vec2$1(), - tmp4$3 = new Vec2$1(), - tmp5$2 = new Vec2$1(), - zero = new Vec2$1(); + let tmp1$9 = new Vector2$1(), + tmp2$7 = new Vector2$1(), + tmp3$3 = new Vector2$1(), + tmp4$3 = new Vector2$1(), + tmp5$2 = new Vector2$1(), + zero = new Vector2$1(); /** * A constraint that acts like a spring between two bodies */ @@ -3374,13 +3374,13 @@ SOFTWARE. /** * @param {Body} body1 * @param {Body} body2 - * @param { Vec2} localA - * @param { Vec2} localB + * @param { Vector2} localA + * @param { Vector2} localB */ constructor(body1, body2, localA, localB) { super(body1, body2); - this.localA = new Vec2$1().copy(localA || zero); - this.localB = new Vec2$1().copy(localB || zero); + this.localA = new Vector2$1().copy(localA || zero); + this.localB = new Vector2$1().copy(localB || zero); this.fixed = !body1.mass || !body2.mass; this.dampening = 1; this.maxDistance = 100; @@ -3417,11 +3417,11 @@ SOFTWARE. } } - new Vec2$1(); + new Vector2$1(); - let position = new Vec2$1(); - let acceleration = new Vec2$1(); - let velocity = new Vec2$1(); + let position = new Vector2$1(); + let acceleration = new Vector2$1(); + let velocity = new Vector2$1(); /** * Verlet intergration. @@ -3447,11 +3447,11 @@ SOFTWARE. } } - let tmp1$8 = new Vec2$1(), - tmp2$6 = new Vec2$1(), - tmp3$2 = new Vec2$1(), - tmp4$2 = new Vec2$1(), - tmp5$1 = new Vec2$1(); + let tmp1$8 = new Vector2$1(), + tmp2$6 = new Vector2$1(), + tmp3$2 = new Vector2$1(), + tmp4$2 = new Vector2$1(), + tmp5$1 = new Vector2$1(); /** * Solves for impulse along collision tangent for a given body pair. @@ -3527,8 +3527,8 @@ SOFTWARE. } }; - const tmp1$7 = new Vec2$1(), - tmp2$5 = new Vec2$1(); + const tmp1$7 = new Vector2$1(), + tmp2$5 = new Vector2$1(); let dampen = Settings.posDampen; /** @@ -3550,10 +3550,10 @@ SOFTWARE. } }; - let tmp1$6 = new Vec2$1(), - tmp2$4 = new Vec2$1(), - tmp3$1 = new Vec2$1(), - tmp4$1 = new Vec2$1(); + let tmp1$6 = new Vector2$1(), + tmp2$4 = new Vector2$1(), + tmp3$1 = new Vector2$1(), + tmp4$1 = new Vector2$1(); /** * Solves for the collision normal impulse of a given body pair. @@ -4202,7 +4202,7 @@ SOFTWARE. overlap: 0, verticesA: null, verticesB: null, - axis: new Vec2$1(), + axis: new Vector2$1(), vertex: null, shape: null }, @@ -4216,9 +4216,9 @@ SOFTWARE. max: 0, indexN: 0 }, - tmp4 = new Vec2$1(), - tmp5 = new Vec2$1(), - tmp6 = new Vec2$1(); + tmp4 = new Vector2$1(), + tmp5 = new Vector2$1(), + tmp6 = new Vector2$1(); /** * Used for narrowphase collision detection and contact info generation. @@ -4305,7 +4305,7 @@ SOFTWARE. /** * @param {Shape} shapeA * @param {Shape} shapeB - * @param { Vec2[]} axes + * @param { Vector2[]} axes * @param {Manifold} shapeA * @param {number} iu */ @@ -4365,8 +4365,8 @@ SOFTWARE. return manifold }, /** - * @param { Vec2[]} vertices - * @param { Vec2} axis + * @param { Vector2[]} vertices + * @param { Vector2} axis * @param {Object} target */ projectVerticesToAxis(vertices, axis, target) { @@ -4391,9 +4391,9 @@ SOFTWARE. return target }, /** - * @param { Vec2[]} vertices - * @param { Vec2} axis - * @param { Vec2[]} target + * @param { Vector2[]} vertices + * @param { Vector2} axis + * @param { Vector2[]} target * @param {number} nearVertexIndex */ findNearSupports(vertices, axis, target = [], nearVertexIndex) { @@ -4421,7 +4421,7 @@ SOFTWARE. }, /** * @param {Shape} shape - * @param { Vec2} point + * @param { Vector2} point */ shapeContains(shape, point) { if (shape.type == "circle") @@ -4429,9 +4429,9 @@ SOFTWARE. return SAT.verticesContain(shape.vertices, point) }, /** - * @param { Vec2} position + * @param { Vector2} position * @param {number} radius - * @param { Vec2} point + * @param { Vector2} point */ circleContains(position, radius, point) { let dx = point.x - position.x, @@ -4441,7 +4441,7 @@ SOFTWARE. return true }, /** - * @param { Vec2[]} vertices + * @param { Vector2[]} vertices * @param {number} point */ verticesContain(vertices, point) { @@ -4493,7 +4493,7 @@ SOFTWARE. lastOverlap: 0, overlap: -Infinity, done: false, - axis: new Vec2$1(), + axis: new Vector2$1(), verticesA: [], verticesB: [], vertShapeA: null, @@ -4506,13 +4506,13 @@ SOFTWARE. stmp: -1, impulse: 0, persistent: false, - ca1: new Vec2$1(), - ca2: new Vec2$1(), + ca1: new Vector2$1(), + ca2: new Vector2$1(), restitution: 0, staticFriction: 0, kineticFriction: 0, - velA: new Vec2$1(), - velB: new Vec2$1(), + velA: new Vector2$1(), + velB: new Vector2$1(), rotA: 0, rotB: 0 }); @@ -4523,13 +4523,13 @@ SOFTWARE. SAT.shapesInBodyCollided(a, b, collisionData); if (collisionData.overlap < 0 || !collisionData.done) continue if (collisionData.contactNo == 2) { - Vec2$1.lerp( + Vector2$1.lerp( collisionData.verticesA[0], collisionData.verticesA[1], 0.5, manifold.ca1 ).sub(a.position); - Vec2$1.lerp( + Vector2$1.lerp( collisionData.verticesB[0], collisionData.verticesB[1], 0.5, @@ -4623,9 +4623,9 @@ SOFTWARE. /** * The gravitational pull of the world. * - * @type Vec2 + * @type Vector2 */ - gravitationalAcceleration = new Vec2$1(0, 0) + gravitationalAcceleration = new Vector2$1(0, 0) /** * Time in seconds that a single frame takes.This has more precedence than the first parameter of World.update(),set to this to zero if you want to use the latter as the delta time. * @@ -4672,7 +4672,7 @@ SOFTWARE. /** * Gravitational pull of the world,will affect all bodies except static bodies. * - * @type { Vec2 } + * @type { Vector2 } */ get gravity() { return this.gravitationalAcceleration @@ -4961,7 +4961,7 @@ SOFTWARE. * @returns */ constructor(x,y,a){ - this.position = new Vec2$1(x,y); + this.position = new Vector2$1(x,y); this.orientation = new Angle(a); } init(){} @@ -4986,7 +4986,7 @@ SOFTWARE. constructor() { } /** - * @type Vec2 + * @type Vector2 */ get position() { return this.transform.position @@ -5322,7 +5322,7 @@ SOFTWARE. /** * World space position. * - * @type Vec2 + * @type Vector2 */ get position() { return this._position @@ -5356,9 +5356,9 @@ SOFTWARE. */ init(entity) { if(!entity){ - this._position = new Vec2$1(); + this._position = new Vector2$1(); this._orientation = new Angle(); - this._scale = new Vec2$1(1,1); + this._scale = new Vector2$1(1,1); return } this.entity = entity; @@ -5367,7 +5367,7 @@ SOFTWARE. this._position = transform.position; this._orientation = transform.orientation; //TODO - Correct this later - this._scale = new Vec2$1(1,1); + this._scale = new Vector2$1(1,1); return this } toJson(){ @@ -5517,7 +5517,7 @@ SOFTWARE. } /** * @param {CanvasRenderingContext2D} ctx - * @param { Vec2[]} vertices + * @param { Vector2[]} vertices * @param {boolean} [close=true] */ function vertices(ctx, vertices, close = true) { @@ -5734,7 +5734,7 @@ SOFTWARE. } } - let r = new Vec2$1(); + let r = new Vector2$1(); let material$1 = new BasicMaterial(); material$1.wireframe = true; /** @@ -5862,7 +5862,7 @@ SOFTWARE. shape.position.x, shape.position.y, shape.radius); - Vec2$1.fromRad(shape.angle, r).multiply(shape.radius); + Vector2$1.fromRad(shape.angle, r).multiply(shape.radius); line(ctx, ...shape.position, shape.position.x + r.x, shape.position.y + r.y); @@ -5886,7 +5886,7 @@ SOFTWARE. class BufferGeometry { /** * @readonly - * @type Vec2[] + * @type Vector2[] */ vertices = null /** @@ -5895,7 +5895,7 @@ SOFTWARE. */ drawable = null /** - * @param { Vec2[]} vertices + * @param { Vector2[]} vertices */ constructor(vertices) { this.vertices = vertices || []; @@ -5933,9 +5933,9 @@ SOFTWARE. } let geometry = new BufferGeometry([ - new Vec2$1(-10, -10), - new Vec2$1(-10, 10), - new Vec2$1(20, 0) + new Vector2$1(-10, -10), + new Vector2$1(-10, 10), + new Vector2$1(20, 0) ]); let material = new BasicMaterial(); material.fill = "purple"; @@ -5978,12 +5978,12 @@ SOFTWARE. class Particle { /** * @readonly - * @type Vec2 + * @type Vector2 */ position = null /** * @readonly - * @type Vec2 + * @type Vector2 */ velocity = null /** @@ -6009,13 +6009,13 @@ SOFTWARE. */ lifespan = 0 /** - * @param { Vec2} pos + * @param { Vector2} pos * @param {number} radius * @param {number} [lifespan=5] In seconds */ constructor(pos, radius, lifespan = 5) { this.position = pos; - this.velocity = new Vec2$1(); + this.velocity = new Vector2$1(); this.radius = radius; this.color = { r: 100, @@ -6103,7 +6103,7 @@ SOFTWARE. */ create() { return new Particle( - new Vec2$1(...this.position), + new Vector2$1(...this.position), rand(1, 10), rand(1, 6) ) @@ -6231,20 +6231,20 @@ SOFTWARE. class CamController { /** * @readonly - * @type Vec2 + * @type Vector2 */ - offset = new Vec2$1() + offset = new Vector2$1() /** * @param {Camera} camera */ constructor(camera) { this.transform = camera.transform; - this.offset = new Vec2$1(); + this.offset = new Vector2$1(); this.targetPosition = null; this.targetOrientation = null; } /** - * @param { Vec2} position + * @param { Vector2} position * @param {Angle} orientation */ follow(position, orientation = null) { @@ -7516,9 +7516,9 @@ SOFTWARE. */ constructor(x, y, a) { super(); - this.velocity = new Vec2$1(x, y); + this.velocity = new Vector2$1(x, y); this.rotation = new Angle(a); - this.acceleration = new Vec2$1(); + this.acceleration = new Vector2$1(); } toJson() { return { @@ -8191,7 +8191,7 @@ SOFTWARE. /** * Accumulated force from behaviours to apply to agent */ - _accumulated = new Vec2$1() + _accumulated = new Vector2$1() /** * Adds a behavior to the manager * @@ -8226,14 +8226,14 @@ SOFTWARE. * @param {number} inv_dt */ update(inv_dt) { - let result = new Vec2$1(); + let result = new Vector2$1(); this._accumulated.set(0, 0); for (let i = 0; i < this._behaviours.length; i++) { this._behaviours[i].calc(result, inv_dt); this._accumulated.add(result); } this._agent.acceleration.add(this._accumulated); - this._agent.orientation.radian = Vec2$1.toRad(this._agent.velocity); + this._agent.orientation.radian = Vector2$1.toRad(this._agent.velocity); } /** * Removes all behaviours from a manager. @@ -8259,19 +8259,19 @@ SOFTWARE. /** * The position of the entity. * - * @type Vec2 + * @type Vector2 */ position = null /** * The velocity of the entity. * - * @type Vec2 + * @type Vector2 */ velocity = null /** * The acceleration of the entity. * - * @type Vec2 + * @type Vector2 */ acceleration = null /** @@ -8361,13 +8361,13 @@ SOFTWARE. /** * The position of the agent. * - * @type Vec2 + * @type Vector2 */ position = null /** * The velocity of the agent. * - * @type Vec2 + * @type Vector2 */ velocity = null /** @@ -8397,9 +8397,9 @@ SOFTWARE. /** * Calculates the amount of force required to satisfy a behavior. * - * @param { Vec2} target + * @param { Vector2} target * @param {number} inv_dt - * @returns Vec2 the first parameter + * @returns Vector2 the first parameter */ calc(target, inv_dt) {} /** @@ -8410,7 +8410,7 @@ SOFTWARE. draw(renderer) {} } - let tmp1$4 = new Vec2$1(); + let tmp1$4 = new Vector2$1(); /** * Creates a behaviour to evade a certain position. * @@ -8424,7 +8424,7 @@ SOFTWARE. */ radius = 200 /** - * @param { Vec2} pursuer + * @param { Vector2} pursuer */ constructor(pursuer) { super(); @@ -8441,9 +8441,9 @@ SOFTWARE. } /** * @inheritdoc - * @param { Vec2} target + * @param { Vector2} target * @param {number} inv_dt - * @returns Vec2 the first parameter + * @returns Vector2 the first parameter */ calc(target,inv_dt) { let difference = tmp1$4.copy(this.position).sub(this.pursuer); @@ -8457,8 +8457,8 @@ SOFTWARE. } } - let tmp1$3 = new Vec2$1(), - tmp2$2 = new Vec2$1(); + let tmp1$3 = new Vector2$1(), + tmp2$2 = new Vector2$1(); /** * Creates a behaviour that is used to make an agent wander in an organic manner. @@ -8495,21 +8495,21 @@ SOFTWARE. } /** * @inheritdoc - * @param { Vec2} target + * @param { Vector2} target * @param {number} inv_dt - * @returns Vec2 the first parameter + * @returns Vector2 the first parameter */ calc(target, inv_dt) { this._theta += rand(-this.dtheta, +this.dtheta); let forward = tmp1$3.copy(this.velocity); if (forward.equalsZero()) - Vec2$1.random(forward); + Vector2$1.random(forward); let radius = this._radius * 0.8; forward.setMagnitude(this._radius); //ctx.arc(...tmp2.copy(this.position).add(forward), radius, 0, Math.PI * 2) //ctx.stroke() - Vec2$1.fromDeg(this._theta + Vec2$1.toDeg(this.velocity), tmp2$2).multiply(radius); + Vector2$1.fromDeg(this._theta + Vector2$1.toDeg(this.velocity), tmp2$2).multiply(radius); forward.add(tmp2$2); //forward.draw(ctx,...this.position) forward.setMagnitude(this.maxSpeed); @@ -8537,9 +8537,9 @@ SOFTWARE. } /** * @inheritdoc - * @param { Vec2} target + * @param { Vector2} target * @param {number} inv_dt - * @returns Vec2 the first parameter + * @returns Vector2 the first parameter */ calc(target){ @@ -8569,16 +8569,16 @@ SOFTWARE. } /** * @inheritdoc - * @param { Vec2} target + * @param { Vector2} target * @param {number} inv_dt - * @returns Vec2 the first parameter + * @returns Vector2 the first parameter */ calc(target,inv_dt) { } } - let tmp1$2 = new Vec2$1(); + let tmp1$2 = new Vector2$1(); /** * Creates a behaviour to seek out a target and move towards it. @@ -8594,11 +8594,11 @@ SOFTWARE. */ radius = 100 /** - * @type Vec2 + * @type Vector2 */ target = null /** - * @param { Vec2} target + * @param { Vector2} target */ constructor(target) { super(); @@ -8614,9 +8614,9 @@ SOFTWARE. } /** * @inheritdoc - * @param { Vec2} target + * @param { Vector2} target * @param {number} inv_dt - * @returns Vec2 the first parameter + * @returns Vector2 the first parameter */ calc(target,inv_dt) { let difference = tmp1$2.copy(this.target).sub(this.position); @@ -8628,8 +8628,8 @@ SOFTWARE. } } - let tmp1$1 = new Vec2$1(), - tmp2$1 = new Vec2$1(); + let tmp1$1 = new Vector2$1(), + tmp2$1 = new Vector2$1(); /** * This provides a seek behaviour which slows down when the agent approaches a target. @@ -8644,7 +8644,7 @@ SOFTWARE. */ radius = 1000 /** - * @param { Vec2} target + * @param { Vector2} target */ constructor(target) { super(); @@ -8661,9 +8661,9 @@ SOFTWARE. } /** * @inheritdoc - * @param { Vec2} target + * @param { Vector2} target * @param {number} inv_dt - * @returns Vec2 the first parameter + * @returns Vector2 the first parameter */ calc(target, inv_dt) { let difference = tmp1$1.copy(this.target).sub(this.position); @@ -8684,8 +8684,8 @@ SOFTWARE. } } - const tmp1 = new Vec2$1(); - const tmp2 = new Vec2$1(); + const tmp1 = new Vector2$1(); + const tmp2 = new Vector2$1(); /** * Creates a behaviour that follows a certain path. * @@ -8708,9 +8708,9 @@ SOFTWARE. } /** * @inheritdoc - * @param { Vec2} target + * @param { Vector2} target * @param {number} inv_dt - * @returns Vec2 the first parameter + * @returns Vector2 the first parameter */ calc(target, inv_dt) { tmp1.copy(this.position); @@ -8748,7 +8748,7 @@ SOFTWARE. /** * Adds a point into the path. * - * @param { Vec2} point + * @param { Vector2} point */ add(point) { this.path.add(point); @@ -8785,11 +8785,11 @@ SOFTWARE. } } - let tmp = new Vec2$1(); + let tmp = new Vector2$1(); class Path { /** * @private - * type Vec2[] + * type Vector2[] */ _points = [] /** @@ -8827,15 +8827,15 @@ SOFTWARE. _finished = false /** * @private - * type Vec2 + * type Vector2 */ - _lerpedPoint = new Vec2$1() + _lerpedPoint = new Vector2$1() /** * type boolean */ loop = false /** - * @param { Vec2} point + * @param { Vector2} point */ add(point) { this._points.push(point); @@ -8884,7 +8884,7 @@ SOFTWARE. if (!this.advance()) this._finished = true; } this._lerp_t = clamp(this._lerp_t, 0, 1); - Vec2$1.lerp( + Vector2$1.lerp( this._points[this._way[0]], this._points[this._way[1]], this._lerp_t, @@ -9296,7 +9296,7 @@ SOFTWARE. exports.Triangle = Triangle; exports.Trigon = Trigon; exports.Utils = Utils$1; - exports. Vec2 = Vec2$1; + exports. Vector2 = Vector2$1; exports.WanderBehaviour = WanderBehaviour; exports.WebGLRenderer = WebGLRenderer; exports.WebGPURenderer = WebGPURenderer; @@ -9344,13 +9344,13 @@ SOFTWARE. * @property {number} stmp * @property {number} impulse * @property {boolean} persistent - * @property { Vec2} ca1 - * @property { Vec2} ca2 + * @property { Vector2} ca1 + * @property { Vector2} ca2 * @property {number} restitution * @property {number} staticFriction * @property {number} kineticFriction - * @property { Vec2} velA - * @property { Vec2} velB + * @property { Vector2} velA + * @property { Vector2} velB * @property {number} rotA * @property {number} rotB */ @@ -9360,9 +9360,9 @@ SOFTWARE. * @property {number} lastOverlap * @property {number} overlap=-Infinity * @property {boolean} done=false - * @property { Vec2} axis - * @property { Vec2[]} verticesA - * @property { Vec2[]} verticesB + * @property { Vector2} axis + * @property { Vector2[]} verticesA + * @property { Vector2[]} verticesB * @property {Shape} vertShapeA * @property {Shape} vertShapeB * @property {number} contactNo diff --git a/docs/AI_agent.js.html b/docs/AI_agent.js.html index 1e99b80d..cc385cc5 100644 --- a/docs/AI_agent.js.html +++ b/docs/AI_agent.js.html @@ -35,19 +35,19 @@

Source: AI/agent.js

/** * The position of the entity. * - * @type Vec2 + * @type Vector2 */ position = null /** * The velocity of the entity. * - * @type Vec2 + * @type Vector2 */ velocity = null /** * The acceleration of the entity. * - * @type Vec2 + * @type Vector2 */ acceleration = null /** @@ -138,7 +138,7 @@

Source: AI/agent.js


diff --git a/docs/AI_behaviourManager.js.html b/docs/AI_behaviourManager.js.html index 149a4c45..a0f1decb 100644 --- a/docs/AI_behaviourManager.js.html +++ b/docs/AI_behaviourManager.js.html @@ -24,7 +24,7 @@

Source: AI/behaviourManager.js

import { Utils } from "../utils/index.js"
-import { Vec2 } from "../math/index.js"
+import { Vector2 } from "../math/index.js"
 
 /**
  * Manages the behaviours for an agent.
@@ -41,7 +41,7 @@ 

Source: AI/behaviourManager.js

/** * Accumulated force from behaviours to apply to agent */ - _accumulated = new Vec2() + _accumulated = new Vector2() /** * Adds a behavior to the manager * @@ -76,14 +76,14 @@

Source: AI/behaviourManager.js

* @param {number} inv_dt */ update(inv_dt) { - let result = new Vec2() + let result = new Vector2() this._accumulated.set(0, 0) for (let i = 0; i < this._behaviours.length; i++) { this._behaviours[i].calc(result, inv_dt) this._accumulated.add(result) } this._agent.acceleration.add(this._accumulated) - this._agent.orientation.radian = Vec2.toRad(this._agent.velocity) + this._agent.orientation.radian = Vector2.toRad(this._agent.velocity) } /** * Removes all behaviours from a manager. @@ -111,7 +111,7 @@

Source: AI/behaviourManager.js


diff --git a/docs/AI_behaviours_arrive.js.html b/docs/AI_behaviours_arrive.js.html index dc4cbe68..6f5ce19f 100644 --- a/docs/AI_behaviours_arrive.js.html +++ b/docs/AI_behaviours_arrive.js.html @@ -24,10 +24,10 @@

Source: AI/behaviours/arrive.js

import { Behaviour } from "./behaviour.js"
-import { Vec2, map } from "../../math/index.js"
+import { Vector2, map } from "../../math/index.js"
 
-let tmp1 = new Vec2(),
-  tmp2 = new Vec2()
+let tmp1 = new Vector2(),
+  tmp2 = new Vector2()
 
 /**
  * This provides a seek behaviour which slows down when the agent approaches a target.
@@ -42,7 +42,7 @@ 

Source: AI/behaviours/arrive.js

*/ radius = 1000 /** - * @param { Vec2} target + * @param { Vector2} target */ constructor(target) { super() @@ -59,9 +59,9 @@

Source: AI/behaviours/arrive.js

} /** * @inheritdoc - * @param { Vec2} target + * @param { Vector2} target * @param {number} inv_dt - * @returns Vec2 the first parameter + * @returns Vector2 the first parameter */ calc(target, inv_dt) { let difference = tmp1.copy(this.target).sub(this.position) @@ -94,7 +94,7 @@

Source: AI/behaviours/arrive.js


diff --git a/docs/AI_behaviours_behaviour.js.html b/docs/AI_behaviours_behaviour.js.html index 59708b2e..b44c9d57 100644 --- a/docs/AI_behaviours_behaviour.js.html +++ b/docs/AI_behaviours_behaviour.js.html @@ -33,13 +33,13 @@

Source: AI/behaviours/behaviour.js

/** * The position of the agent. * - * @type Vec2 + * @type Vector2 */ position = null /** * The velocity of the agent. * - * @type Vec2 + * @type Vector2 */ velocity = null /** @@ -69,9 +69,9 @@

Source: AI/behaviours/behaviour.js

/** * Calculates the amount of force required to satisfy a behavior. * - * @param { Vec2} target + * @param { Vector2} target * @param {number} inv_dt - * @returns Vec2 the first parameter + * @returns Vector2 the first parameter */ calc(target, inv_dt) {} /** @@ -93,7 +93,7 @@

Source: AI/behaviours/behaviour.js


diff --git a/docs/AI_behaviours_evade.js.html b/docs/AI_behaviours_evade.js.html index 85af1913..8a6445eb 100644 --- a/docs/AI_behaviours_evade.js.html +++ b/docs/AI_behaviours_evade.js.html @@ -24,9 +24,9 @@

Source: AI/behaviours/evade.js

import { Behaviour } from "./behaviour.js"
-import { Vec2,map } from "../../math/index.js"
+import { Vector2,map } from "../../math/index.js"
 
-let tmp1 = new Vec2()
+let tmp1 = new Vector2()
 /**
  * Creates a behaviour to evade a certain position.
  * 
@@ -40,7 +40,7 @@ 

Source: AI/behaviours/evade.js

*/ radius = 200 /** - * @param { Vec2} pursuer + * @param { Vector2} pursuer */ constructor(pursuer) { super() @@ -57,9 +57,9 @@

Source: AI/behaviours/evade.js

} /** * @inheritdoc - * @param { Vec2} target + * @param { Vector2} target * @param {number} inv_dt - * @returns Vec2 the first parameter + * @returns Vector2 the first parameter */ calc(target,inv_dt) { let difference = tmp1.copy(this.position).sub(this.pursuer) @@ -85,7 +85,7 @@

Source: AI/behaviours/evade.js


diff --git a/docs/AI_behaviours_flocking.js.html b/docs/AI_behaviours_flocking.js.html index bf9530d2..62fbce04 100644 --- a/docs/AI_behaviours_flocking.js.html +++ b/docs/AI_behaviours_flocking.js.html @@ -24,7 +24,7 @@

Source: AI/behaviours/flocking.js

import { Behaviour } from "./behaviour.js"
-import { Vec2 } from "../../math/index.js"
+import { Vector2 } from "../../math/index.js"
 
 
 /**
@@ -50,9 +50,9 @@ 

Source: AI/behaviours/flocking.js

} /** * @inheritdoc - * @param { Vec2} target + * @param { Vector2} target * @param {number} inv_dt - * @returns Vec2 the first parameter + * @returns Vector2 the first parameter */ calc(target,inv_dt) { @@ -71,7 +71,7 @@

Source: AI/behaviours/flocking.js


diff --git a/docs/AI_behaviours_path.js.html b/docs/AI_behaviours_path.js.html index 84302f58..fd02a0e6 100644 --- a/docs/AI_behaviours_path.js.html +++ b/docs/AI_behaviours_path.js.html @@ -24,10 +24,10 @@

Source: AI/behaviours/path.js

import { Behaviour } from "./behaviour.js"
-import { Vec2, map } from "../../math/index.js"
+import { Vector2, map } from "../../math/index.js"
 import { circle, fill, stroke } from "../../render/index.js"
-const tmp1 = new Vec2()
-const tmp2 = new Vec2()
+const tmp1 = new Vector2()
+const tmp2 = new Vector2()
 /**
  * Creates a behaviour that follows a certain path.
  * 
@@ -50,9 +50,9 @@ 

Source: AI/behaviours/path.js

} /** * @inheritdoc - * @param { Vec2} target + * @param { Vector2} target * @param {number} inv_dt - * @returns Vec2 the first parameter + * @returns Vector2 the first parameter */ calc(target, inv_dt) { tmp1.copy(this.position) @@ -90,7 +90,7 @@

Source: AI/behaviours/path.js

/** * Adds a point into the path. * - * @param { Vec2} point + * @param { Vector2} point */ add(point) { this.path.add(point) @@ -135,7 +135,7 @@

Source: AI/behaviours/path.js


diff --git a/docs/AI_behaviours_pursuit.js.html b/docs/AI_behaviours_pursuit.js.html index 00e9e4d1..e4af7ec2 100644 --- a/docs/AI_behaviours_pursuit.js.html +++ b/docs/AI_behaviours_pursuit.js.html @@ -24,7 +24,7 @@

Source: AI/behaviours/pursuit.js

import { Behaviour } from "./behaviour.js"
-import { Vec2 } from "../../math/index.js"
+import { Vector2 } from "../../math/index.js"
 
 
 /**
@@ -45,9 +45,9 @@ 

Source: AI/behaviours/pursuit.js

} /** * @inheritdoc - * @param { Vec2} target + * @param { Vector2} target * @param {number} inv_dt - * @returns Vec2 the first parameter + * @returns Vector2 the first parameter */ calc(target){ @@ -66,7 +66,7 @@

Source: AI/behaviours/pursuit.js


diff --git a/docs/AI_behaviours_seek.js.html b/docs/AI_behaviours_seek.js.html index fa2174e3..b59b4674 100644 --- a/docs/AI_behaviours_seek.js.html +++ b/docs/AI_behaviours_seek.js.html @@ -24,9 +24,9 @@

Source: AI/behaviours/seek.js

import { Behaviour } from "./behaviour.js"
-import { Vec2 } from "../../math/index.js"
+import { Vector2 } from "../../math/index.js"
 
-let tmp1 = new Vec2()
+let tmp1 = new Vector2()
   
 /**
  * Creates a behaviour to seek out a target and move towards it.
@@ -42,11 +42,11 @@ 

Source: AI/behaviours/seek.js

*/ radius = 100 /** - * @type Vec2 + * @type Vector2 */ target = null /** - * @param { Vec2} target + * @param { Vector2} target */ constructor(target) { super() @@ -62,9 +62,9 @@

Source: AI/behaviours/seek.js

} /** * @inheritdoc - * @param { Vec2} target + * @param { Vector2} target * @param {number} inv_dt - * @returns Vec2 the first parameter + * @returns Vector2 the first parameter */ calc(target,inv_dt) { let difference = tmp1.copy(this.target).sub(this.position) @@ -88,7 +88,7 @@

Source: AI/behaviours/seek.js


diff --git a/docs/AI_behaviours_wandering.js.html b/docs/AI_behaviours_wandering.js.html index 4e791ead..d09bd848 100644 --- a/docs/AI_behaviours_wandering.js.html +++ b/docs/AI_behaviours_wandering.js.html @@ -24,10 +24,10 @@

Source: AI/behaviours/wandering.js

import { Behaviour } from "./behaviour.js"
-import { Vec2, rand } from "../../math/index.js"
+import { Vector2, rand } from "../../math/index.js"
 
-let tmp1 = new Vec2(),
-  tmp2 = new Vec2()
+let tmp1 = new Vector2(),
+  tmp2 = new Vector2()
   
 /**
  * Creates a behaviour that is used to make an agent wander in an organic manner.
@@ -64,21 +64,21 @@ 

Source: AI/behaviours/wandering.js

} /** * @inheritdoc - * @param { Vec2} target + * @param { Vector2} target * @param {number} inv_dt - * @returns Vec2 the first parameter + * @returns Vector2 the first parameter */ calc(target, inv_dt) { this._theta += rand(-this.dtheta, +this.dtheta) let forward = tmp1.copy(this.velocity) if (forward.equalsZero()) - Vec2.random(forward) + Vector2.random(forward) let radius = this._radius * 0.8 forward.setMagnitude(this._radius) //ctx.arc(...tmp2.copy(this.position).add(forward), radius, 0, Math.PI * 2) //ctx.stroke() - Vec2.fromDeg(this._theta + Vec2.toDeg(this.velocity), tmp2).multiply(radius) + Vector2.fromDeg(this._theta + Vector2.toDeg(this.velocity), tmp2).multiply(radius) forward.add(tmp2) //forward.draw(ctx,...this.position) forward.setMagnitude(this.maxSpeed) @@ -100,7 +100,7 @@

Source: AI/behaviours/wandering.js


diff --git a/docs/AI_manager.js.html b/docs/AI_manager.js.html index 3676cd8b..3b3c0769 100644 --- a/docs/AI_manager.js.html +++ b/docs/AI_manager.js.html @@ -62,7 +62,7 @@

Source: AI/manager.js


diff --git a/docs/AI_paths_path.js.html b/docs/AI_paths_path.js.html index 93c8372c..d68592dc 100644 --- a/docs/AI_paths_path.js.html +++ b/docs/AI_paths_path.js.html @@ -23,14 +23,14 @@

Source: AI/paths/path.js

-
import { Vec2, clamp } from "../../math/index.js"
+            
import { Vector2, clamp } from "../../math/index.js"
 import { vertices, stroke } from "../../render/index.js"
 
-let tmp = new Vec2()
+let tmp = new Vector2()
 export class Path {
   /**
    * @private
-   * type Vec2[]
+   * type Vector2[]
    */
   _points = []
   /**
@@ -68,15 +68,15 @@ 

Source: AI/paths/path.js

_finished = false /** * @private - * type Vec2 + * type Vector2 */ - _lerpedPoint = new Vec2() + _lerpedPoint = new Vector2() /** * type boolean */ loop = false /** - * @param { Vec2} point + * @param { Vector2} point */ add(point) { this._points.push(point) @@ -125,7 +125,7 @@

Source: AI/paths/path.js

if (!this.advance()) this._finished = true } this._lerp_t = clamp(this._lerp_t, 0, 1) - Vec2.lerp( + Vector2.lerp( this._points[this._way[0]], this._points[this._way[1]], this._lerp_t, @@ -164,7 +164,7 @@

Source: AI/paths/path.js


diff --git a/docs/Agent.html b/docs/Agent.html index 4cccc7c1..263bea27 100644 --- a/docs/Agent.html +++ b/docs/Agent.html @@ -147,7 +147,7 @@

Members

-

acceleration : Vec2

+

acceleration : Vector2

@@ -162,7 +162,7 @@
Type: