excalibur 0.28.3 → 0.28.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gitattributes +63 -63
- package/CHANGELOG.md +2003 -1955
- package/LICENSE.md +25 -25
- package/README.md +134 -134
- package/STYLEGUIDE.md +136 -136
- package/build/dist/Actions/Action/ActionSequence.js +31 -0
- package/build/dist/Actions/Action/ActionSequence.js.map +1 -0
- package/build/dist/Actions/Action/Blink.js +54 -0
- package/build/dist/Actions/Action/Blink.js.map +1 -0
- package/build/dist/Actions/Action/CallMethod.js +21 -0
- package/build/dist/Actions/Action/CallMethod.js.map +1 -0
- package/build/dist/Actions/Action/Delay.js +26 -0
- package/build/dist/Actions/Action/Delay.js.map +1 -0
- package/build/dist/Actions/Action/Die.js +22 -0
- package/build/dist/Actions/Action/Die.js.map +1 -0
- package/build/dist/Actions/Action/EaseBy.js +70 -0
- package/build/dist/Actions/Action/EaseBy.js.map +1 -0
- package/build/dist/Actions/Action/EaseTo.js +69 -0
- package/build/dist/Actions/Action/EaseTo.js.map +1 -0
- package/build/dist/Actions/Action/Fade.js +48 -0
- package/build/dist/Actions/Action/Fade.js.map +1 -0
- package/build/dist/Actions/Action/Follow.js +56 -0
- package/build/dist/Actions/Action/Follow.js.map +1 -0
- package/build/dist/Actions/Action/Meet.js +54 -0
- package/build/dist/Actions/Action/Meet.js.map +1 -0
- package/build/dist/Actions/Action/MoveBy.js +48 -0
- package/build/dist/Actions/Action/MoveBy.js.map +1 -0
- package/build/dist/Actions/Action/MoveTo.js +41 -0
- package/build/dist/Actions/Action/MoveTo.js.map +1 -0
- package/build/dist/Actions/Action/ParallelActions.js +23 -0
- package/build/dist/Actions/Action/ParallelActions.js.map +1 -0
- package/build/dist/Actions/Action/Repeat.js +31 -0
- package/build/dist/Actions/Action/Repeat.js.map +1 -0
- package/build/dist/Actions/Action/RepeatForever.js +37 -0
- package/build/dist/Actions/Action/RepeatForever.js.map +1 -0
- package/build/dist/Actions/Action/RotateBy.js +95 -0
- package/build/dist/Actions/Action/RotateBy.js.map +1 -0
- package/build/dist/Actions/Action/RotateTo.js +91 -0
- package/build/dist/Actions/Action/RotateTo.js.map +1 -0
- package/build/dist/Actions/Action/ScaleBy.js +46 -0
- package/build/dist/Actions/Action/ScaleBy.js.map +1 -0
- package/build/dist/Actions/Action/ScaleTo.js +58 -0
- package/build/dist/Actions/Action/ScaleTo.js.map +1 -0
- package/build/dist/Actions/Action.js +2 -0
- package/build/dist/Actions/Action.js.map +1 -0
- package/build/dist/Actions/ActionContext.js +322 -0
- package/build/dist/Actions/ActionContext.js.map +1 -0
- package/build/dist/Actions/ActionQueue.js +87 -0
- package/build/dist/Actions/ActionQueue.js.map +1 -0
- package/build/dist/Actions/Actionable.js +2 -0
- package/build/dist/Actions/Actionable.js.map +1 -0
- package/build/dist/Actions/ActionsComponent.js +195 -0
- package/build/dist/Actions/ActionsComponent.js.map +1 -0
- package/build/dist/Actions/ActionsSystem.js +30 -0
- package/build/dist/Actions/ActionsSystem.js.map +1 -0
- package/build/dist/Actions/Index.js +26 -0
- package/build/dist/Actions/Index.js.map +1 -0
- package/build/dist/Actions/RotationType.js +27 -0
- package/build/dist/Actions/RotationType.js.map +1 -0
- package/build/dist/Actor.js +629 -0
- package/build/dist/Actor.js.map +1 -0
- package/build/dist/Camera.js +660 -0
- package/build/dist/Camera.js.map +1 -0
- package/build/dist/Collision/BoundingBox.js +415 -0
- package/build/dist/Collision/BoundingBox.js.map +1 -0
- package/build/dist/Collision/ColliderComponent.js +202 -0
- package/build/dist/Collision/ColliderComponent.js.map +1 -0
- package/build/dist/Collision/Colliders/CircleCollider.js +226 -0
- package/build/dist/Collision/Colliders/CircleCollider.js.map +1 -0
- package/build/dist/Collision/Colliders/ClosestLineJumpTable.js +211 -0
- package/build/dist/Collision/Colliders/ClosestLineJumpTable.js.map +1 -0
- package/build/dist/Collision/Colliders/Collider.js +32 -0
- package/build/dist/Collision/Colliders/Collider.js.map +1 -0
- package/build/dist/Collision/Colliders/CollisionJumpTable.js +300 -0
- package/build/dist/Collision/Colliders/CollisionJumpTable.js.map +1 -0
- package/build/dist/Collision/Colliders/EdgeCollider.js +229 -0
- package/build/dist/Collision/Colliders/EdgeCollider.js.map +1 -0
- package/build/dist/Collision/Colliders/PolygonCollider.js +556 -0
- package/build/dist/Collision/Colliders/PolygonCollider.js.map +1 -0
- package/build/dist/Collision/Colliders/SeparatingAxis.js +67 -0
- package/build/dist/Collision/Colliders/SeparatingAxis.js.map +1 -0
- package/build/dist/Collision/Colliders/Shape.js +99 -0
- package/build/dist/Collision/Colliders/Shape.js.map +1 -0
- package/build/dist/Collision/CollisionType.js +33 -0
- package/build/dist/Collision/CollisionType.js.map +1 -0
- package/build/dist/Collision/Detection/CollisionContact.js +51 -0
- package/build/dist/Collision/Detection/CollisionContact.js.map +1 -0
- package/build/dist/Collision/Detection/CollisionProcessor.js +2 -0
- package/build/dist/Collision/Detection/CollisionProcessor.js.map +1 -0
- package/build/dist/Collision/Detection/DynamicTree.js +442 -0
- package/build/dist/Collision/Detection/DynamicTree.js.map +1 -0
- package/build/dist/Collision/Detection/Pair.js +92 -0
- package/build/dist/Collision/Detection/Pair.js.map +1 -0
- package/build/dist/Collision/Detection/QuadTree.js +193 -0
- package/build/dist/Collision/Detection/QuadTree.js.map +1 -0
- package/build/dist/Collision/Group/CollisionGroup.js +3 -3
- package/build/dist/Collision/Integrator.js +25 -0
- package/build/dist/Collision/Integrator.js.map +1 -0
- package/build/dist/Collision/MotionSystem.js +35 -0
- package/build/dist/Collision/MotionSystem.js.map +1 -0
- package/build/dist/Collision/Physics.js +163 -0
- package/build/dist/Collision/Physics.js.map +1 -0
- package/build/dist/Collision/PhysicsWorld.js +10 -0
- package/build/dist/Collision/PhysicsWorld.js.map +1 -0
- package/build/dist/Collision/Side.js +51 -0
- package/build/dist/Collision/Side.js.map +1 -0
- package/build/dist/Collision/Solver/ArcadeSolver.js +154 -0
- package/build/dist/Collision/Solver/ArcadeSolver.js.map +1 -0
- package/build/dist/Collision/Solver/ContactConstraintPoint.js +87 -0
- package/build/dist/Collision/Solver/ContactConstraintPoint.js.map +1 -0
- package/build/dist/Collision/Solver/RealisticSolver.js +293 -0
- package/build/dist/Collision/Solver/RealisticSolver.js.map +1 -0
- package/build/dist/Collision/Solver/Solver.js +2 -0
- package/build/dist/Collision/Solver/Solver.js.map +1 -0
- package/build/dist/Color.js +417 -0
- package/build/dist/Color.js.map +1 -0
- package/build/dist/Configurable.js +32 -0
- package/build/dist/Configurable.js.map +1 -0
- package/build/dist/Debug/Debug.d.ts +11 -0
- package/build/dist/Debug/Debug.js +385 -0
- package/build/dist/Debug/Debug.js.map +1 -0
- package/build/dist/Debug/DebugFlags.js +40 -0
- package/build/dist/Debug/DebugFlags.js.map +1 -0
- package/build/dist/Debug/DebugSystem.js +263 -0
- package/build/dist/Debug/DebugSystem.js.map +1 -0
- package/build/dist/Debug/index.js +4 -0
- package/build/dist/Debug/index.js.map +1 -0
- package/build/dist/Deprecated.js +2 -0
- package/build/dist/Deprecated.js.map +1 -0
- package/build/dist/Engine.js +986 -0
- package/build/dist/Engine.js.map +1 -0
- package/build/dist/EntityComponentSystem/Component.js +65 -0
- package/build/dist/EntityComponentSystem/Component.js.map +1 -0
- package/build/dist/EntityComponentSystem/Components/MotionComponent.js +33 -0
- package/build/dist/EntityComponentSystem/Components/MotionComponent.js.map +1 -0
- package/build/dist/EntityComponentSystem/Components/TransformComponent.js +107 -0
- package/build/dist/EntityComponentSystem/Components/TransformComponent.js.map +1 -0
- package/build/dist/EntityComponentSystem/Entity.js +487 -0
- package/build/dist/EntityComponentSystem/Entity.js.map +1 -0
- package/build/dist/EntityComponentSystem/EntityManager.js +137 -0
- package/build/dist/EntityComponentSystem/EntityManager.js.map +1 -0
- package/build/dist/EntityComponentSystem/Query.js +90 -0
- package/build/dist/EntityComponentSystem/Query.js.map +1 -0
- package/build/dist/EntityComponentSystem/QueryManager.js +90 -0
- package/build/dist/EntityComponentSystem/QueryManager.js.map +1 -0
- package/build/dist/EntityComponentSystem/System.js +76 -0
- package/build/dist/EntityComponentSystem/System.js.map +1 -0
- package/build/dist/EntityComponentSystem/SystemManager.js +104 -0
- package/build/dist/EntityComponentSystem/SystemManager.js.map +1 -0
- package/build/dist/EntityComponentSystem/Util.js +5 -0
- package/build/dist/EntityComponentSystem/Util.js.map +1 -0
- package/build/dist/EntityComponentSystem/World.js +55 -0
- package/build/dist/EntityComponentSystem/World.js.map +1 -0
- package/build/dist/EntityComponentSystem/index.js +11 -0
- package/build/dist/EntityComponentSystem/index.js.map +1 -0
- package/build/dist/EventDispatcher.js +122 -0
- package/build/dist/EventDispatcher.js.map +1 -0
- package/build/dist/EventEmitter.js +86 -0
- package/build/dist/EventEmitter.js.map +1 -0
- package/build/dist/Events/ExEvent.js +12 -0
- package/build/dist/Events/ExEvent.js.map +1 -0
- package/build/dist/Events/MediaEvents.js +75 -0
- package/build/dist/Events/MediaEvents.js.map +1 -0
- package/build/dist/Events/PointerEvents.js +52 -0
- package/build/dist/Events/PointerEvents.js.map +1 -0
- package/build/dist/Events.js +473 -0
- package/build/dist/Events.js.map +1 -0
- package/build/dist/Flags.js +67 -0
- package/build/dist/Flags.js.map +1 -0
- package/build/dist/Graphics/Animation.js +344 -0
- package/build/dist/Graphics/Animation.js.map +1 -0
- package/build/dist/Graphics/Canvas.js +38 -0
- package/build/dist/Graphics/Canvas.js.map +1 -0
- package/build/dist/Graphics/Circle.js +48 -0
- package/build/dist/Graphics/Circle.js.map +1 -0
- package/build/dist/Graphics/Context/ExcaliburGraphicsContext.js +2 -0
- package/build/dist/Graphics/Context/ExcaliburGraphicsContext.js.map +1 -0
- package/build/dist/Graphics/Context/ExcaliburGraphicsContext2DCanvas.js +237 -0
- package/build/dist/Graphics/Context/ExcaliburGraphicsContext2DCanvas.js.map +1 -0
- package/build/dist/Graphics/Context/ExcaliburGraphicsContextWebGL.d.ts +1 -0
- package/build/dist/Graphics/Context/ExcaliburGraphicsContextWebGL.js +481 -0
- package/build/dist/Graphics/Context/ExcaliburGraphicsContextWebGL.js.map +1 -0
- package/build/dist/Graphics/Context/circle-renderer/circle-renderer.frag.glsl +52 -52
- package/build/dist/Graphics/Context/circle-renderer/circle-renderer.js +174 -0
- package/build/dist/Graphics/Context/circle-renderer/circle-renderer.js.map +1 -0
- package/build/dist/Graphics/Context/circle-renderer/circle-renderer.vert.glsl +37 -37
- package/build/dist/Graphics/Context/debug-text.js +47 -0
- package/build/dist/Graphics/Context/debug-text.js.map +1 -0
- package/build/dist/Graphics/Context/draw-call.js +16 -0
- package/build/dist/Graphics/Context/draw-call.js.map +1 -0
- package/build/dist/Graphics/Context/image-renderer/image-renderer.frag.glsl +32 -32
- package/build/dist/Graphics/Context/image-renderer/image-renderer.js +246 -0
- package/build/dist/Graphics/Context/image-renderer/image-renderer.js.map +1 -0
- package/build/dist/Graphics/Context/image-renderer/image-renderer.vert.glsl +32 -32
- package/build/dist/Graphics/Context/line-renderer/line-fragment.glsl +10 -10
- package/build/dist/Graphics/Context/line-renderer/line-renderer.js +90 -0
- package/build/dist/Graphics/Context/line-renderer/line-renderer.js.map +1 -0
- package/build/dist/Graphics/Context/line-renderer/line-vertex.glsl +14 -14
- package/build/dist/Graphics/Context/material-renderer/material-renderer.js +23 -2
- package/build/dist/Graphics/Context/material-renderer/material-renderer.js.map +1 -1
- package/build/dist/Graphics/Context/material.d.ts +2 -0
- package/build/dist/Graphics/Context/material.js +72 -0
- package/build/dist/Graphics/Context/material.js.map +1 -0
- package/build/dist/Graphics/Context/point-renderer/point-fragment.glsl +19 -19
- package/build/dist/Graphics/Context/point-renderer/point-renderer.js +91 -0
- package/build/dist/Graphics/Context/point-renderer/point-renderer.js.map +1 -0
- package/build/dist/Graphics/Context/point-renderer/point-vertex.glsl +11 -11
- package/build/dist/Graphics/Context/quad-index-buffer.js +67 -0
- package/build/dist/Graphics/Context/quad-index-buffer.js.map +1 -0
- package/build/dist/Graphics/Context/rectangle-renderer/rectangle-renderer.frag.glsl +85 -85
- package/build/dist/Graphics/Context/rectangle-renderer/rectangle-renderer.js +305 -0
- package/build/dist/Graphics/Context/rectangle-renderer/rectangle-renderer.js.map +1 -0
- package/build/dist/Graphics/Context/rectangle-renderer/rectangle-renderer.vert.glsl +42 -42
- package/build/dist/Graphics/Context/render-source.js +16 -0
- package/build/dist/Graphics/Context/render-source.js.map +1 -0
- package/build/dist/Graphics/Context/render-target.js +65 -0
- package/build/dist/Graphics/Context/render-target.js.map +1 -0
- package/build/dist/Graphics/Context/renderer.js +2 -0
- package/build/dist/Graphics/Context/renderer.js.map +1 -0
- package/build/dist/Graphics/Context/screen-pass-painter/screen-fragment.glsl +13 -13
- package/build/dist/Graphics/Context/screen-pass-painter/screen-pass-painter.js +56 -0
- package/build/dist/Graphics/Context/screen-pass-painter/screen-pass-painter.js.map +1 -0
- package/build/dist/Graphics/Context/screen-pass-painter/screen-vertex.glsl +11 -11
- package/build/dist/Graphics/Context/state-stack.js +37 -0
- package/build/dist/Graphics/Context/state-stack.js.map +1 -0
- package/build/dist/Graphics/Context/texture-loader.js +109 -0
- package/build/dist/Graphics/Context/texture-loader.js.map +1 -0
- package/build/dist/Graphics/Context/transform-stack.js +30 -0
- package/build/dist/Graphics/Context/transform-stack.js.map +1 -0
- package/build/dist/Graphics/Context/vertex-buffer.js +53 -0
- package/build/dist/Graphics/Context/vertex-buffer.js.map +1 -0
- package/build/dist/Graphics/Context/webgl-util.js +79 -0
- package/build/dist/Graphics/Context/webgl-util.js.map +1 -0
- package/build/dist/Graphics/DebugGraphicsComponent.d.ts +3 -2
- package/build/dist/Graphics/DebugGraphicsComponent.js +16 -0
- package/build/dist/Graphics/DebugGraphicsComponent.js.map +1 -0
- package/build/dist/Graphics/Filtering.js +17 -0
- package/build/dist/Graphics/Filtering.js.map +1 -0
- package/build/dist/Graphics/Font.js +148 -0
- package/build/dist/Graphics/Font.js.map +1 -0
- package/build/dist/Graphics/FontCache.d.ts +1 -0
- package/build/dist/Graphics/FontCache.js +80 -0
- package/build/dist/Graphics/FontCache.js.map +1 -0
- package/build/dist/Graphics/FontCommon.js +109 -0
- package/build/dist/Graphics/FontCommon.js.map +1 -0
- package/build/dist/Graphics/FontTextInstance.js +230 -0
- package/build/dist/Graphics/FontTextInstance.js.map +1 -0
- package/build/dist/Graphics/Graphic.js +208 -0
- package/build/dist/Graphics/Graphic.js.map +1 -0
- package/build/dist/Graphics/GraphicsComponent.js +336 -0
- package/build/dist/Graphics/GraphicsComponent.js.map +1 -0
- package/build/dist/Graphics/GraphicsDiagnostics.js +9 -0
- package/build/dist/Graphics/GraphicsDiagnostics.js.map +1 -0
- package/build/dist/Graphics/GraphicsGroup.js +69 -0
- package/build/dist/Graphics/GraphicsGroup.js.map +1 -0
- package/build/dist/Graphics/GraphicsSystem.js +210 -0
- package/build/dist/Graphics/GraphicsSystem.js.map +1 -0
- package/build/dist/Graphics/ImageSource.js +124 -0
- package/build/dist/Graphics/ImageSource.js.map +1 -0
- package/build/dist/Graphics/Line.js +45 -0
- package/build/dist/Graphics/Line.js.map +1 -0
- package/build/dist/Graphics/OffscreenSystem.js +64 -0
- package/build/dist/Graphics/OffscreenSystem.js.map +1 -0
- package/build/dist/Graphics/ParallaxComponent.js +11 -0
- package/build/dist/Graphics/ParallaxComponent.js.map +1 -0
- package/build/dist/Graphics/Polygon.js +59 -0
- package/build/dist/Graphics/Polygon.js.map +1 -0
- package/build/dist/Graphics/PostProcessor/ColorBlindnessMode.js +7 -0
- package/build/dist/Graphics/PostProcessor/ColorBlindnessMode.js.map +1 -0
- package/build/dist/Graphics/PostProcessor/ColorBlindnessPostProcessor.js +52 -0
- package/build/dist/Graphics/PostProcessor/ColorBlindnessPostProcessor.js.map +1 -0
- package/build/dist/Graphics/PostProcessor/PostProcessor.js +2 -0
- package/build/dist/Graphics/PostProcessor/PostProcessor.js.map +1 -0
- package/build/dist/Graphics/PostProcessor/ScreenShader.js +59 -0
- package/build/dist/Graphics/PostProcessor/ScreenShader.js.map +1 -0
- package/build/dist/Graphics/PostProcessor/color-blind-fragment.glsl +64 -64
- package/build/dist/Graphics/Raster.js +215 -0
- package/build/dist/Graphics/Raster.js.map +1 -0
- package/build/dist/Graphics/Rectangle.js +29 -0
- package/build/dist/Graphics/Rectangle.js.map +1 -0
- package/build/dist/Graphics/Sprite.js +82 -0
- package/build/dist/Graphics/Sprite.js.map +1 -0
- package/build/dist/Graphics/SpriteFont.js +139 -0
- package/build/dist/Graphics/SpriteFont.js.map +1 -0
- package/build/dist/Graphics/SpriteSheet.js +116 -0
- package/build/dist/Graphics/SpriteSheet.js.map +1 -0
- package/build/dist/Graphics/Text.js +103 -0
- package/build/dist/Graphics/Text.js.map +1 -0
- package/build/dist/Graphics/index.js +46 -0
- package/build/dist/Graphics/index.js.map +1 -0
- package/build/dist/Id.js +8 -0
- package/build/dist/Id.js.map +1 -0
- package/build/dist/Input/CapturePointerConfig.js +5 -0
- package/build/dist/Input/CapturePointerConfig.js.map +1 -0
- package/build/dist/Input/EngineInput.js +2 -0
- package/build/dist/Input/EngineInput.js.map +1 -0
- package/build/dist/Input/Gamepad.js +422 -0
- package/build/dist/Input/Gamepad.js.map +1 -0
- package/build/dist/Input/Index.js +88 -0
- package/build/dist/Input/Index.js.map +1 -0
- package/build/dist/Input/InputMapper.js +45 -0
- package/build/dist/Input/InputMapper.js.map +1 -0
- package/build/dist/Input/Keyboard.js +348 -0
- package/build/dist/Input/Keyboard.js.map +1 -0
- package/build/dist/Input/NativePointerButton.js +12 -0
- package/build/dist/Input/NativePointerButton.js.map +1 -0
- package/build/dist/Input/PointerAbstraction.js +44 -0
- package/build/dist/Input/PointerAbstraction.js.map +1 -0
- package/build/dist/Input/PointerButton.js +12 -0
- package/build/dist/Input/PointerButton.js.map +1 -0
- package/build/dist/Input/PointerComponent.js +28 -0
- package/build/dist/Input/PointerComponent.js.map +1 -0
- package/build/dist/Input/PointerEvent.js +25 -0
- package/build/dist/Input/PointerEvent.js.map +1 -0
- package/build/dist/Input/PointerEventReceiver.js +456 -0
- package/build/dist/Input/PointerEventReceiver.js.map +1 -0
- package/build/dist/Input/PointerScope.js +16 -0
- package/build/dist/Input/PointerScope.js.map +1 -0
- package/build/dist/Input/PointerSystem.js +249 -0
- package/build/dist/Input/PointerSystem.js.map +1 -0
- package/build/dist/Input/PointerType.js +11 -0
- package/build/dist/Input/PointerType.js.map +1 -0
- package/build/dist/Input/WheelDeltaMode.js +7 -0
- package/build/dist/Input/WheelDeltaMode.js.map +1 -0
- package/build/dist/Input/WheelEvent.js +21 -0
- package/build/dist/Input/WheelEvent.js.map +1 -0
- package/build/dist/Interfaces/Audio.js +2 -0
- package/build/dist/Interfaces/Audio.js.map +1 -0
- package/build/dist/Interfaces/AudioImplementation.js +11 -0
- package/build/dist/Interfaces/AudioImplementation.js.map +1 -0
- package/build/dist/Interfaces/Clonable.js +2 -0
- package/build/dist/Interfaces/Clonable.js.map +1 -0
- package/build/dist/Interfaces/Evented.js +2 -0
- package/build/dist/Interfaces/Evented.js.map +1 -0
- package/build/dist/Interfaces/Index.js +8 -0
- package/build/dist/Interfaces/Index.js.map +1 -0
- package/build/dist/Interfaces/LifecycleEvents.js +51 -0
- package/build/dist/Interfaces/LifecycleEvents.js.map +1 -0
- package/build/dist/Interfaces/Loadable.js +2 -0
- package/build/dist/Interfaces/Loadable.js.map +1 -0
- package/build/dist/Interfaces/PointerEventHandlers.js +2 -0
- package/build/dist/Interfaces/PointerEventHandlers.js.map +1 -0
- package/build/dist/Label.js +81 -0
- package/build/dist/Label.js.map +1 -0
- package/build/dist/Loader.js +416 -0
- package/build/dist/Loader.js.map +1 -0
- package/build/dist/Math/Index.js +13 -0
- package/build/dist/Math/Index.js.map +1 -0
- package/build/dist/Math/Random.js +239 -0
- package/build/dist/Math/Random.js.map +1 -0
- package/build/dist/Math/affine-matrix.js +331 -0
- package/build/dist/Math/affine-matrix.js.map +1 -0
- package/build/dist/Math/coord-plane.js +17 -0
- package/build/dist/Math/coord-plane.js.map +1 -0
- package/build/dist/Math/global-coordinates.js +30 -0
- package/build/dist/Math/global-coordinates.js.map +1 -0
- package/build/dist/Math/line-segment.js +205 -0
- package/build/dist/Math/line-segment.js.map +1 -0
- package/build/dist/Math/matrix.js +457 -0
- package/build/dist/Math/matrix.js.map +1 -0
- package/build/dist/Math/projection.js +24 -0
- package/build/dist/Math/projection.js.map +1 -0
- package/build/dist/Math/ray.js +52 -0
- package/build/dist/Math/ray.js.map +1 -0
- package/build/dist/Math/transform.js +219 -0
- package/build/dist/Math/transform.js.map +1 -0
- package/build/dist/Math/util.js +82 -0
- package/build/dist/Math/util.js.map +1 -0
- package/build/dist/Math/vector-view.js +25 -0
- package/build/dist/Math/vector-view.js.map +1 -0
- package/build/dist/Math/vector.js +340 -0
- package/build/dist/Math/vector.js.map +1 -0
- package/build/dist/Math/watch-vector.js +26 -0
- package/build/dist/Math/watch-vector.js.map +1 -0
- package/build/dist/Particles.js +430 -0
- package/build/dist/Particles.js.map +1 -0
- package/build/dist/Polyfill.js +56 -0
- package/build/dist/Polyfill.js.map +1 -0
- package/build/dist/Resources/Gif.js +464 -0
- package/build/dist/Resources/Gif.js.map +1 -0
- package/build/dist/Resources/Index.js +4 -0
- package/build/dist/Resources/Index.js.map +1 -0
- package/build/dist/Resources/Resource.js +81 -0
- package/build/dist/Resources/Resource.js.map +1 -0
- package/build/dist/Resources/Sound/AudioContext.js +16 -0
- package/build/dist/Resources/Sound/AudioContext.js.map +1 -0
- package/build/dist/Resources/Sound/Index.js +4 -0
- package/build/dist/Resources/Sound/Index.js.map +1 -0
- package/build/dist/Resources/Sound/Sound.js +326 -0
- package/build/dist/Resources/Sound/Sound.js.map +1 -0
- package/build/dist/Resources/Sound/WebAudioInstance.js +190 -0
- package/build/dist/Resources/Sound/WebAudioInstance.js.map +1 -0
- package/build/dist/Scene.js +444 -0
- package/build/dist/Scene.js.map +1 -0
- package/build/dist/Screen.js +782 -0
- package/build/dist/Screen.js.map +1 -0
- package/build/dist/ScreenElement.js +43 -0
- package/build/dist/ScreenElement.js.map +1 -0
- package/build/dist/TileMap/IsometricEntityComponent.js +17 -0
- package/build/dist/TileMap/IsometricEntityComponent.js.map +1 -0
- package/build/dist/TileMap/IsometricEntitySystem.js +23 -0
- package/build/dist/TileMap/IsometricEntitySystem.js.map +1 -0
- package/build/dist/TileMap/IsometricMap.js +311 -0
- package/build/dist/TileMap/IsometricMap.js.map +1 -0
- package/build/dist/TileMap/TileMap.d.ts +2 -1
- package/build/dist/TileMap/TileMap.js +630 -0
- package/build/dist/TileMap/TileMap.js.map +1 -0
- package/build/dist/TileMap/index.js +5 -0
- package/build/dist/TileMap/index.js.map +1 -0
- package/build/dist/Timer.js +202 -0
- package/build/dist/Timer.js.map +1 -0
- package/build/dist/Trigger.js +94 -0
- package/build/dist/Trigger.js.map +1 -0
- package/build/dist/Util/Browser.js +66 -0
- package/build/dist/Util/Browser.js.map +1 -0
- package/build/dist/Util/Clock.js +219 -0
- package/build/dist/Util/Clock.js.map +1 -0
- package/build/dist/Util/Decorators.js +78 -0
- package/build/dist/Util/Decorators.js.map +1 -0
- package/build/dist/Util/Detector.js +167 -0
- package/build/dist/Util/Detector.js.map +1 -0
- package/build/dist/Util/DrawUtil.js +115 -0
- package/build/dist/Util/DrawUtil.js.map +1 -0
- package/build/dist/Util/EasingFunctions.js +102 -0
- package/build/dist/Util/EasingFunctions.js.map +1 -0
- package/build/dist/Util/Fps.js +47 -0
- package/build/dist/Util/Fps.js.map +1 -0
- package/build/dist/Util/Future.js +30 -0
- package/build/dist/Util/Future.js.map +1 -0
- package/build/dist/Util/IFrame.js +23 -0
- package/build/dist/Util/IFrame.js.map +1 -0
- package/build/dist/Util/Index.js +7 -0
- package/build/dist/Util/Index.js.map +1 -0
- package/build/dist/Util/Log.js +195 -0
- package/build/dist/Util/Log.js.map +1 -0
- package/build/dist/Util/Observable.js +66 -0
- package/build/dist/Util/Observable.js.map +1 -0
- package/build/dist/Util/Pool.js +74 -0
- package/build/dist/Util/Pool.js.map +1 -0
- package/build/dist/Util/Semaphore.js +55 -0
- package/build/dist/Util/Semaphore.js.map +1 -0
- package/build/dist/Util/Sound.js +22 -0
- package/build/dist/Util/Sound.js.map +1 -0
- package/build/dist/Util/StateMachine.js +79 -0
- package/build/dist/Util/StateMachine.js.map +1 -0
- package/build/dist/Util/Toaster.css +28 -28
- package/build/dist/Util/Toaster.js +84 -0
- package/build/dist/Util/Toaster.js.map +1 -0
- package/build/dist/Util/Util.d.ts +6 -0
- package/build/dist/Util/Util.js +95 -0
- package/build/dist/Util/Util.js.map +1 -0
- package/build/dist/Util/Watch.js +67 -0
- package/build/dist/Util/Watch.js.map +1 -0
- package/build/dist/Util/WebAudio.js +62 -0
- package/build/dist/Util/WebAudio.js.map +1 -0
- package/build/dist/excalibur.d.ts +2 -2
- package/build/dist/excalibur.js +389 -258
- package/build/dist/excalibur.js.map +1 -1
- package/build/dist/excalibur.min.js +1 -1
- package/build/dist/excalibur.min.js.LICENSE.txt +1 -1
- package/build/dist/excalibur.min.js.map +1 -1
- package/build/dist/index.js +81 -0
- package/build/dist/index.js.map +1 -0
- package/build/esm/Debug/Debug.d.ts +11 -0
- package/build/esm/Graphics/Context/ExcaliburGraphicsContextWebGL.d.ts +1 -0
- package/build/esm/Graphics/Context/material.d.ts +2 -0
- package/build/esm/Graphics/DebugGraphicsComponent.d.ts +3 -2
- package/build/esm/Graphics/FontCache.d.ts +1 -0
- package/build/esm/TileMap/TileMap.d.ts +2 -1
- package/build/esm/Util/Util.d.ts +6 -0
- package/build/esm/excalibur.d.ts +2 -2
- package/build/esm/excalibur.js +389 -258
- package/build/esm/excalibur.js.map +1 -1
- package/build/esm/excalibur.min.js +1 -1
- package/build/esm/excalibur.min.js.LICENSE.txt +1 -1
- package/build/esm/excalibur.min.js.map +1 -1
- package/docker-compose.yml +11 -11
- package/package.json +131 -131
- package/build/dist/Loader.css +0 -122
- package/build/nuget/Excalibur.0.28.3.nupkg +0 -0
- package/build/v0.28.3.zip +0 -0
- package/excalibur-0.28.3.tgz +0 -0
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import { Vector } from './vector';
|
|
2
|
+
/**
|
|
3
|
+
* A 2D line segment
|
|
4
|
+
*/
|
|
5
|
+
export class LineSegment {
|
|
6
|
+
/**
|
|
7
|
+
* @param begin The starting point of the line segment
|
|
8
|
+
* @param end The ending point of the line segment
|
|
9
|
+
*/
|
|
10
|
+
constructor(begin, end) {
|
|
11
|
+
this.begin = begin;
|
|
12
|
+
this.end = end;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Gets the raw slope (m) of the line. Will return (+/-)Infinity for vertical lines.
|
|
16
|
+
*/
|
|
17
|
+
get slope() {
|
|
18
|
+
return (this.end.y - this.begin.y) / (this.end.x - this.begin.x);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Gets the Y-intercept (b) of the line. Will return (+/-)Infinity if there is no intercept.
|
|
22
|
+
*/
|
|
23
|
+
get intercept() {
|
|
24
|
+
return this.begin.y - this.slope * this.begin.x;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Gets the normal of the line
|
|
28
|
+
*/
|
|
29
|
+
normal() {
|
|
30
|
+
if (this._normal) {
|
|
31
|
+
return this._normal;
|
|
32
|
+
}
|
|
33
|
+
return this._normal = this.end.sub(this.begin).normal();
|
|
34
|
+
}
|
|
35
|
+
dir() {
|
|
36
|
+
if (this._dir) {
|
|
37
|
+
return this._dir;
|
|
38
|
+
}
|
|
39
|
+
return this._dir = this.end.sub(this.begin);
|
|
40
|
+
}
|
|
41
|
+
getPoints() {
|
|
42
|
+
return [this.begin, this.end];
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Returns the slope of the line in the form of a vector of length 1
|
|
46
|
+
*/
|
|
47
|
+
getSlope() {
|
|
48
|
+
if (this._slope) {
|
|
49
|
+
return this._slope;
|
|
50
|
+
}
|
|
51
|
+
const begin = this.begin;
|
|
52
|
+
const end = this.end;
|
|
53
|
+
const distance = begin.distance(end);
|
|
54
|
+
return this._slope = end.sub(begin).scale(1 / distance);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Returns the edge of the line as vector, the length of the vector is the length of the edge
|
|
58
|
+
*/
|
|
59
|
+
getEdge() {
|
|
60
|
+
const begin = this.begin;
|
|
61
|
+
const end = this.end;
|
|
62
|
+
return end.sub(begin);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Returns the length of the line segment in pixels
|
|
66
|
+
*/
|
|
67
|
+
getLength() {
|
|
68
|
+
if (this._length) {
|
|
69
|
+
return this._length;
|
|
70
|
+
}
|
|
71
|
+
const begin = this.begin;
|
|
72
|
+
const end = this.end;
|
|
73
|
+
const distance = begin.distance(end);
|
|
74
|
+
return this._length = distance;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Returns the midpoint of the edge
|
|
78
|
+
*/
|
|
79
|
+
get midpoint() {
|
|
80
|
+
return this.begin.add(this.end).scale(0.5);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Flips the direction of the line segment
|
|
84
|
+
*/
|
|
85
|
+
flip() {
|
|
86
|
+
return new LineSegment(this.end, this.begin);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Tests if a given point is below the line, points in the normal direction above the line are considered above.
|
|
90
|
+
* @param point
|
|
91
|
+
*/
|
|
92
|
+
below(point) {
|
|
93
|
+
const above2 = (this.end.x - this.begin.x) * (point.y - this.begin.y) - (this.end.y - this.begin.y) * (point.x - this.begin.x);
|
|
94
|
+
return above2 >= 0;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Returns the clip point
|
|
98
|
+
* @param sideVector Vector that traces the line
|
|
99
|
+
* @param length Length to clip along side
|
|
100
|
+
*/
|
|
101
|
+
clip(sideVector, length) {
|
|
102
|
+
let dir = sideVector;
|
|
103
|
+
dir = dir.normalize();
|
|
104
|
+
const near = dir.dot(this.begin) - length;
|
|
105
|
+
const far = dir.dot(this.end) - length;
|
|
106
|
+
const results = [];
|
|
107
|
+
if (near <= 0) {
|
|
108
|
+
results.push(this.begin);
|
|
109
|
+
}
|
|
110
|
+
if (far <= 0) {
|
|
111
|
+
results.push(this.end);
|
|
112
|
+
}
|
|
113
|
+
if (near * far < 0) {
|
|
114
|
+
const clipTime = near / (near - far);
|
|
115
|
+
results.push(this.begin.add(this.end.sub(this.begin).scale(clipTime)));
|
|
116
|
+
}
|
|
117
|
+
if (results.length !== 2) {
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
120
|
+
return new LineSegment(results[0], results[1]);
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Find the perpendicular distance from the line to a point
|
|
124
|
+
* https://en.wikipedia.org/wiki/Distance_from_a_point_to_a_line
|
|
125
|
+
* @param point
|
|
126
|
+
*/
|
|
127
|
+
distanceToPoint(point, signed = false) {
|
|
128
|
+
const x0 = point.x;
|
|
129
|
+
const y0 = point.y;
|
|
130
|
+
const l = this.getLength();
|
|
131
|
+
const dy = this.end.y - this.begin.y;
|
|
132
|
+
const dx = this.end.x - this.begin.x;
|
|
133
|
+
const distance = (dy * x0 - dx * y0 + this.end.x * this.begin.y - this.end.y * this.begin.x) / l;
|
|
134
|
+
return signed ? distance : Math.abs(distance);
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Find the perpendicular line from the line to a point
|
|
138
|
+
* https://en.wikipedia.org/wiki/Distance_from_a_point_to_a_line
|
|
139
|
+
* (a - p) - ((a - p) * n)n
|
|
140
|
+
* a is a point on the line
|
|
141
|
+
* p is the arbitrary point above the line
|
|
142
|
+
* n is a unit vector in direction of the line
|
|
143
|
+
* @param point
|
|
144
|
+
*/
|
|
145
|
+
findVectorToPoint(point) {
|
|
146
|
+
const aMinusP = this.begin.sub(point);
|
|
147
|
+
const n = this.getSlope();
|
|
148
|
+
return aMinusP.sub(n.scale(aMinusP.dot(n)));
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Finds a point on the line given only an X or a Y value. Given an X value, the function returns
|
|
152
|
+
* a new point with the calculated Y value and vice-versa.
|
|
153
|
+
* @param x The known X value of the target point
|
|
154
|
+
* @param y The known Y value of the target point
|
|
155
|
+
* @returns A new point with the other calculated axis value
|
|
156
|
+
*/
|
|
157
|
+
findPoint(x = null, y = null) {
|
|
158
|
+
const m = this.slope;
|
|
159
|
+
const b = this.intercept;
|
|
160
|
+
if (x !== null) {
|
|
161
|
+
return new Vector(x, m * x + b);
|
|
162
|
+
}
|
|
163
|
+
else if (y !== null) {
|
|
164
|
+
return new Vector((y - b) / m, y);
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
throw new Error('You must provide an X or a Y value');
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* @see http://stackoverflow.com/a/11908158/109458
|
|
172
|
+
*/
|
|
173
|
+
hasPoint() {
|
|
174
|
+
let currPoint;
|
|
175
|
+
let threshold = 0;
|
|
176
|
+
if (typeof arguments[0] === 'number' && typeof arguments[1] === 'number') {
|
|
177
|
+
currPoint = new Vector(arguments[0], arguments[1]);
|
|
178
|
+
threshold = arguments[2] || 0;
|
|
179
|
+
}
|
|
180
|
+
else if (arguments[0] instanceof Vector) {
|
|
181
|
+
currPoint = arguments[0];
|
|
182
|
+
threshold = arguments[1] || 0;
|
|
183
|
+
}
|
|
184
|
+
else {
|
|
185
|
+
throw 'Could not determine the arguments for Vector.hasPoint';
|
|
186
|
+
}
|
|
187
|
+
const dxc = currPoint.x - this.begin.x;
|
|
188
|
+
const dyc = currPoint.y - this.begin.y;
|
|
189
|
+
const dx1 = this.end.x - this.begin.x;
|
|
190
|
+
const dy1 = this.end.y - this.begin.y;
|
|
191
|
+
const cross = dxc * dy1 - dyc * dx1;
|
|
192
|
+
// check whether point lines on the line
|
|
193
|
+
if (Math.abs(cross) > threshold) {
|
|
194
|
+
return false;
|
|
195
|
+
}
|
|
196
|
+
// check whether point lies in-between start and end
|
|
197
|
+
if (Math.abs(dx1) >= Math.abs(dy1)) {
|
|
198
|
+
return dx1 > 0 ? this.begin.x <= currPoint.x && currPoint.x <= this.end.x : this.end.x <= currPoint.x && currPoint.x <= this.begin.x;
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
return dy1 > 0 ? this.begin.y <= currPoint.y && currPoint.y <= this.end.y : this.end.y <= currPoint.y && currPoint.y <= this.begin.y;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
//# sourceMappingURL=line-segment.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"line-segment.js","sourceRoot":"","sources":["../../../src/engine/Math/line-segment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC;;GAEG;AAEH,MAAM,OAAO,WAAW;IAEtB;;;OAGG;IACH,YAA4B,KAAa,EAAkB,GAAW;QAA1C,UAAK,GAAL,KAAK,CAAQ;QAAkB,QAAG,GAAH,GAAG,CAAQ;IAAG,CAAC;IAE1E;;OAEG;IACH,IAAW,KAAK;QACd,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACnE,CAAC;IAED;;OAEG;IACH,IAAW,SAAS;QAClB,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IAClD,CAAC;IAGD;;OAEG;IACI,MAAM;QACX,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACjB,OAAO,IAAI,CAAC,OAAO,CAAC;QACtB,CAAC;QACD,OAAO,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CA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AC,IAAI,SAAS,CAAC,CAAC,IAAI,SAAS,CAAC,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;QACvI,CAAC;aAAM,CAAC;YACN,OAAO,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,SAAS,CAAC,CAAC,IAAI,SAAS,CAAC,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,SAAS,CAAC,CAAC,IAAI,SAAS,CAAC,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;QACvI,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,457 @@
|
|
|
1
|
+
import { sign } from './util';
|
|
2
|
+
import { Vector, vec } from './vector';
|
|
3
|
+
import { canonicalizeAngle } from './util';
|
|
4
|
+
export var MatrixLocations;
|
|
5
|
+
(function (MatrixLocations) {
|
|
6
|
+
MatrixLocations[MatrixLocations["X"] = 12] = "X";
|
|
7
|
+
MatrixLocations[MatrixLocations["Y"] = 13] = "Y";
|
|
8
|
+
})(MatrixLocations || (MatrixLocations = {}));
|
|
9
|
+
/**
|
|
10
|
+
* Excalibur Matrix helper for 4x4 matrices
|
|
11
|
+
*
|
|
12
|
+
* Useful for webgl 4x4 matrices
|
|
13
|
+
*/
|
|
14
|
+
export class Matrix {
|
|
15
|
+
constructor() {
|
|
16
|
+
/**
|
|
17
|
+
* 4x4 matrix in column major order
|
|
18
|
+
*
|
|
19
|
+
* | | | | |
|
|
20
|
+
* | ------- | ------- | -------- | -------- |
|
|
21
|
+
* | data[0] | data[4] | data[8] | data[12] |
|
|
22
|
+
* | data[1] | data[5] | data[9] | data[13] |
|
|
23
|
+
* | data[2] | data[6] | data[10] | data[14] |
|
|
24
|
+
* | data[3] | data[7] | data[11] | data[15] |
|
|
25
|
+
*
|
|
26
|
+
*/
|
|
27
|
+
this.data = new Float32Array(16);
|
|
28
|
+
this._scaleX = 1;
|
|
29
|
+
this._scaleSignX = 1;
|
|
30
|
+
this._scaleY = 1;
|
|
31
|
+
this._scaleSignY = 1;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Creates an orthographic (flat non-perspective) projection
|
|
35
|
+
* https://en.wikipedia.org/wiki/Orthographic_projection
|
|
36
|
+
* @param left
|
|
37
|
+
* @param right
|
|
38
|
+
* @param bottom
|
|
39
|
+
* @param top
|
|
40
|
+
* @param near
|
|
41
|
+
* @param far
|
|
42
|
+
*/
|
|
43
|
+
static ortho(left, right, bottom, top, near, far) {
|
|
44
|
+
const mat = new Matrix();
|
|
45
|
+
mat.data[0] = 2 / (right - left);
|
|
46
|
+
mat.data[1] = 0;
|
|
47
|
+
mat.data[2] = 0;
|
|
48
|
+
mat.data[3] = 0;
|
|
49
|
+
mat.data[4] = 0;
|
|
50
|
+
mat.data[5] = 2 / (top - bottom);
|
|
51
|
+
mat.data[6] = 0;
|
|
52
|
+
mat.data[7] = 0;
|
|
53
|
+
mat.data[8] = 0;
|
|
54
|
+
mat.data[9] = 0;
|
|
55
|
+
mat.data[10] = -2 / (far - near);
|
|
56
|
+
mat.data[11] = 0;
|
|
57
|
+
mat.data[12] = -(right + left) / (right - left);
|
|
58
|
+
mat.data[13] = -(top + bottom) / (top - bottom);
|
|
59
|
+
mat.data[14] = -(far + near) / (far - near);
|
|
60
|
+
mat.data[15] = 1;
|
|
61
|
+
return mat;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Creates a new Matrix with the same data as the current 4x4
|
|
65
|
+
*/
|
|
66
|
+
clone(dest) {
|
|
67
|
+
const mat = dest || new Matrix();
|
|
68
|
+
mat.data[0] = this.data[0];
|
|
69
|
+
mat.data[1] = this.data[1];
|
|
70
|
+
mat.data[2] = this.data[2];
|
|
71
|
+
mat.data[3] = this.data[3];
|
|
72
|
+
mat.data[4] = this.data[4];
|
|
73
|
+
mat.data[5] = this.data[5];
|
|
74
|
+
mat.data[6] = this.data[6];
|
|
75
|
+
mat.data[7] = this.data[7];
|
|
76
|
+
mat.data[8] = this.data[8];
|
|
77
|
+
mat.data[9] = this.data[9];
|
|
78
|
+
mat.data[10] = this.data[10];
|
|
79
|
+
mat.data[11] = this.data[11];
|
|
80
|
+
mat.data[12] = this.data[12];
|
|
81
|
+
mat.data[13] = this.data[13];
|
|
82
|
+
mat.data[14] = this.data[14];
|
|
83
|
+
mat.data[15] = this.data[15];
|
|
84
|
+
return mat;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Converts the current matrix into a DOMMatrix
|
|
88
|
+
*
|
|
89
|
+
* This is useful when working with the browser Canvas context
|
|
90
|
+
* @returns {DOMMatrix} DOMMatrix
|
|
91
|
+
*/
|
|
92
|
+
toDOMMatrix() {
|
|
93
|
+
return new DOMMatrix([...this.data]);
|
|
94
|
+
}
|
|
95
|
+
static fromFloat32Array(data) {
|
|
96
|
+
const matrix = new Matrix();
|
|
97
|
+
matrix.data = data;
|
|
98
|
+
return matrix;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Creates a new identity matrix (a matrix that when applied does nothing)
|
|
102
|
+
*/
|
|
103
|
+
static identity() {
|
|
104
|
+
const mat = new Matrix();
|
|
105
|
+
mat.data[0] = 1;
|
|
106
|
+
mat.data[1] = 0;
|
|
107
|
+
mat.data[2] = 0;
|
|
108
|
+
mat.data[3] = 0;
|
|
109
|
+
mat.data[4] = 0;
|
|
110
|
+
mat.data[5] = 1;
|
|
111
|
+
mat.data[6] = 0;
|
|
112
|
+
mat.data[7] = 0;
|
|
113
|
+
mat.data[8] = 0;
|
|
114
|
+
mat.data[9] = 0;
|
|
115
|
+
mat.data[10] = 1;
|
|
116
|
+
mat.data[11] = 0;
|
|
117
|
+
mat.data[12] = 0;
|
|
118
|
+
mat.data[13] = 0;
|
|
119
|
+
mat.data[14] = 0;
|
|
120
|
+
mat.data[15] = 1;
|
|
121
|
+
return mat;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Resets the current matrix to the identity matrix, mutating it
|
|
125
|
+
* @returns {Matrix} Current matrix as identity
|
|
126
|
+
*/
|
|
127
|
+
reset() {
|
|
128
|
+
const mat = this;
|
|
129
|
+
mat.data[0] = 1;
|
|
130
|
+
mat.data[1] = 0;
|
|
131
|
+
mat.data[2] = 0;
|
|
132
|
+
mat.data[3] = 0;
|
|
133
|
+
mat.data[4] = 0;
|
|
134
|
+
mat.data[5] = 1;
|
|
135
|
+
mat.data[6] = 0;
|
|
136
|
+
mat.data[7] = 0;
|
|
137
|
+
mat.data[8] = 0;
|
|
138
|
+
mat.data[9] = 0;
|
|
139
|
+
mat.data[10] = 1;
|
|
140
|
+
mat.data[11] = 0;
|
|
141
|
+
mat.data[12] = 0;
|
|
142
|
+
mat.data[13] = 0;
|
|
143
|
+
mat.data[14] = 0;
|
|
144
|
+
mat.data[15] = 1;
|
|
145
|
+
return mat;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Creates a brand new translation matrix at the specified 3d point
|
|
149
|
+
* @param x
|
|
150
|
+
* @param y
|
|
151
|
+
*/
|
|
152
|
+
static translation(x, y) {
|
|
153
|
+
const mat = Matrix.identity();
|
|
154
|
+
mat.data[12] = x;
|
|
155
|
+
mat.data[13] = y;
|
|
156
|
+
return mat;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Creates a brand new scaling matrix with the specified scaling factor
|
|
160
|
+
* @param sx
|
|
161
|
+
* @param sy
|
|
162
|
+
*/
|
|
163
|
+
static scale(sx, sy) {
|
|
164
|
+
const mat = Matrix.identity();
|
|
165
|
+
mat.data[0] = sx;
|
|
166
|
+
mat.data[5] = sy;
|
|
167
|
+
mat.data[10] = 1;
|
|
168
|
+
mat.data[15] = 1;
|
|
169
|
+
return mat;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Creates a brand new rotation matrix with the specified angle
|
|
173
|
+
* @param angleRadians
|
|
174
|
+
*/
|
|
175
|
+
static rotation(angleRadians) {
|
|
176
|
+
const mat = Matrix.identity();
|
|
177
|
+
mat.data[0] = Math.cos(angleRadians);
|
|
178
|
+
mat.data[4] = -Math.sin(angleRadians);
|
|
179
|
+
mat.data[1] = Math.sin(angleRadians);
|
|
180
|
+
mat.data[5] = Math.cos(angleRadians);
|
|
181
|
+
return mat;
|
|
182
|
+
}
|
|
183
|
+
multiply(vectorOrMatrix, dest) {
|
|
184
|
+
if (vectorOrMatrix instanceof Vector) {
|
|
185
|
+
const result = dest || new Vector(0, 0);
|
|
186
|
+
const vector = vectorOrMatrix;
|
|
187
|
+
// these shenanigans are to allow dest and vector to be the same instance
|
|
188
|
+
const resultX = vector.x * this.data[0] + vector.y * this.data[4] + this.data[12];
|
|
189
|
+
const resultY = vector.x * this.data[1] + vector.y * this.data[5] + this.data[13];
|
|
190
|
+
result.x = resultX;
|
|
191
|
+
result.y = resultY;
|
|
192
|
+
return result;
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
const result = dest || new Matrix();
|
|
196
|
+
const other = vectorOrMatrix;
|
|
197
|
+
const a11 = this.data[0];
|
|
198
|
+
const a21 = this.data[1];
|
|
199
|
+
const a31 = this.data[2];
|
|
200
|
+
const a41 = this.data[3];
|
|
201
|
+
const a12 = this.data[4];
|
|
202
|
+
const a22 = this.data[5];
|
|
203
|
+
const a32 = this.data[6];
|
|
204
|
+
const a42 = this.data[7];
|
|
205
|
+
const a13 = this.data[8];
|
|
206
|
+
const a23 = this.data[9];
|
|
207
|
+
const a33 = this.data[10];
|
|
208
|
+
const a43 = this.data[11];
|
|
209
|
+
const a14 = this.data[12];
|
|
210
|
+
const a24 = this.data[13];
|
|
211
|
+
const a34 = this.data[14];
|
|
212
|
+
const a44 = this.data[15];
|
|
213
|
+
const b11 = other.data[0];
|
|
214
|
+
const b21 = other.data[1];
|
|
215
|
+
const b31 = other.data[2];
|
|
216
|
+
const b41 = other.data[3];
|
|
217
|
+
const b12 = other.data[4];
|
|
218
|
+
const b22 = other.data[5];
|
|
219
|
+
const b32 = other.data[6];
|
|
220
|
+
const b42 = other.data[7];
|
|
221
|
+
const b13 = other.data[8];
|
|
222
|
+
const b23 = other.data[9];
|
|
223
|
+
const b33 = other.data[10];
|
|
224
|
+
const b43 = other.data[11];
|
|
225
|
+
const b14 = other.data[12];
|
|
226
|
+
const b24 = other.data[13];
|
|
227
|
+
const b34 = other.data[14];
|
|
228
|
+
const b44 = other.data[15];
|
|
229
|
+
result.data[0] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
|
|
230
|
+
result.data[1] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
|
|
231
|
+
result.data[2] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
|
|
232
|
+
result.data[3] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
|
|
233
|
+
result.data[4] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
|
|
234
|
+
result.data[5] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
|
|
235
|
+
result.data[6] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
|
|
236
|
+
result.data[7] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
|
|
237
|
+
result.data[8] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
|
|
238
|
+
result.data[9] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
|
|
239
|
+
result.data[10] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
|
|
240
|
+
result.data[11] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
|
|
241
|
+
result.data[12] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
|
|
242
|
+
result.data[13] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
|
|
243
|
+
result.data[14] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
|
|
244
|
+
result.data[15] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
|
|
245
|
+
const s = this.getScale();
|
|
246
|
+
result._scaleSignX = sign(s.x) * sign(result._scaleSignX);
|
|
247
|
+
result._scaleSignY = sign(s.y) * sign(result._scaleSignY);
|
|
248
|
+
return result;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Applies translation to the current matrix mutating it
|
|
253
|
+
* @param x
|
|
254
|
+
* @param y
|
|
255
|
+
*/
|
|
256
|
+
translate(x, y) {
|
|
257
|
+
const a11 = this.data[0];
|
|
258
|
+
const a21 = this.data[1];
|
|
259
|
+
const a31 = this.data[2];
|
|
260
|
+
const a41 = this.data[3];
|
|
261
|
+
const a12 = this.data[4];
|
|
262
|
+
const a22 = this.data[5];
|
|
263
|
+
const a32 = this.data[6];
|
|
264
|
+
const a42 = this.data[7];
|
|
265
|
+
const a13 = this.data[8];
|
|
266
|
+
const a23 = this.data[9];
|
|
267
|
+
const a33 = this.data[10];
|
|
268
|
+
const a43 = this.data[11];
|
|
269
|
+
const a14 = this.data[12];
|
|
270
|
+
const a24 = this.data[13];
|
|
271
|
+
const a34 = this.data[14];
|
|
272
|
+
const a44 = this.data[15];
|
|
273
|
+
// Doesn't change z
|
|
274
|
+
const z = 0;
|
|
275
|
+
const w = 1;
|
|
276
|
+
this.data[12] = a11 * x + a12 * y + a13 * z + a14 * w;
|
|
277
|
+
this.data[13] = a21 * x + a22 * y + a23 * z + a24 * w;
|
|
278
|
+
this.data[14] = a31 * x + a32 * y + a33 * z + a34 * w;
|
|
279
|
+
this.data[15] = a41 * x + a42 * y + a43 * z + a44 * w;
|
|
280
|
+
return this;
|
|
281
|
+
}
|
|
282
|
+
setPosition(x, y) {
|
|
283
|
+
this.data[12] = x;
|
|
284
|
+
this.data[13] = y;
|
|
285
|
+
}
|
|
286
|
+
getPosition() {
|
|
287
|
+
return vec(this.data[12], this.data[13]);
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Applies rotation to the current matrix mutating it
|
|
291
|
+
* @param angle in Radians
|
|
292
|
+
*/
|
|
293
|
+
rotate(angle) {
|
|
294
|
+
const a11 = this.data[0];
|
|
295
|
+
const a21 = this.data[1];
|
|
296
|
+
const a31 = this.data[2];
|
|
297
|
+
const a41 = this.data[3];
|
|
298
|
+
const a12 = this.data[4];
|
|
299
|
+
const a22 = this.data[5];
|
|
300
|
+
const a32 = this.data[6];
|
|
301
|
+
const a42 = this.data[7];
|
|
302
|
+
const sine = Math.sin(angle);
|
|
303
|
+
const cosine = Math.cos(angle);
|
|
304
|
+
this.data[0] = cosine * a11 + sine * a12;
|
|
305
|
+
this.data[1] = cosine * a21 + sine * a22;
|
|
306
|
+
this.data[2] = cosine * a31 + sine * a32;
|
|
307
|
+
this.data[3] = cosine * a41 + sine * a42;
|
|
308
|
+
this.data[4] = cosine * a12 - sine * a11;
|
|
309
|
+
this.data[5] = cosine * a22 - sine * a21;
|
|
310
|
+
this.data[6] = cosine * a32 - sine * a31;
|
|
311
|
+
this.data[7] = cosine * a42 - sine * a41;
|
|
312
|
+
return this;
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* Applies scaling to the current matrix mutating it
|
|
316
|
+
* @param x
|
|
317
|
+
* @param y
|
|
318
|
+
*/
|
|
319
|
+
scale(x, y) {
|
|
320
|
+
const a11 = this.data[0];
|
|
321
|
+
const a21 = this.data[1];
|
|
322
|
+
const a31 = this.data[2];
|
|
323
|
+
const a41 = this.data[3];
|
|
324
|
+
const a12 = this.data[4];
|
|
325
|
+
const a22 = this.data[5];
|
|
326
|
+
const a32 = this.data[6];
|
|
327
|
+
const a42 = this.data[7];
|
|
328
|
+
this.data[0] = a11 * x;
|
|
329
|
+
this.data[1] = a21 * x;
|
|
330
|
+
this.data[2] = a31 * x;
|
|
331
|
+
this.data[3] = a41 * x;
|
|
332
|
+
this.data[4] = a12 * y;
|
|
333
|
+
this.data[5] = a22 * y;
|
|
334
|
+
this.data[6] = a32 * y;
|
|
335
|
+
this.data[7] = a42 * y;
|
|
336
|
+
return this;
|
|
337
|
+
}
|
|
338
|
+
setRotation(angle) {
|
|
339
|
+
const currentScale = this.getScale();
|
|
340
|
+
const sine = Math.sin(angle);
|
|
341
|
+
const cosine = Math.cos(angle);
|
|
342
|
+
this.data[0] = cosine * currentScale.x;
|
|
343
|
+
this.data[1] = sine * currentScale.y;
|
|
344
|
+
this.data[4] = -sine * currentScale.x;
|
|
345
|
+
this.data[5] = cosine * currentScale.y;
|
|
346
|
+
}
|
|
347
|
+
getRotation() {
|
|
348
|
+
const angle = Math.atan2(this.data[1] / this.getScaleY(), this.data[0] / this.getScaleX());
|
|
349
|
+
return canonicalizeAngle(angle);
|
|
350
|
+
}
|
|
351
|
+
getScaleX() {
|
|
352
|
+
// absolute scale of the matrix (we lose sign so need to add it back)
|
|
353
|
+
const xscale = vec(this.data[0], this.data[4]).size;
|
|
354
|
+
return this._scaleSignX * xscale;
|
|
355
|
+
}
|
|
356
|
+
getScaleY() {
|
|
357
|
+
// absolute scale of the matrix (we lose sign so need to add it back)
|
|
358
|
+
const yscale = vec(this.data[1], this.data[5]).size;
|
|
359
|
+
return this._scaleSignY * yscale;
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* Get the scale of the matrix
|
|
363
|
+
*/
|
|
364
|
+
getScale() {
|
|
365
|
+
return vec(this.getScaleX(), this.getScaleY());
|
|
366
|
+
}
|
|
367
|
+
setScaleX(val) {
|
|
368
|
+
if (this._scaleX === val) {
|
|
369
|
+
return;
|
|
370
|
+
}
|
|
371
|
+
this._scaleSignX = sign(val);
|
|
372
|
+
// negative scale acts like a 180 rotation, so flip
|
|
373
|
+
const xscale = vec(this.data[0] * this._scaleSignX, this.data[4] * this._scaleSignX).normalize();
|
|
374
|
+
this.data[0] = xscale.x * val;
|
|
375
|
+
this.data[4] = xscale.y * val;
|
|
376
|
+
this._scaleX = val;
|
|
377
|
+
}
|
|
378
|
+
setScaleY(val) {
|
|
379
|
+
if (this._scaleY === val) {
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
382
|
+
this._scaleSignY = sign(val);
|
|
383
|
+
// negative scale acts like a 180 rotation, so flip
|
|
384
|
+
const yscale = vec(this.data[1] * this._scaleSignY, this.data[5] * this._scaleSignY).normalize();
|
|
385
|
+
this.data[1] = yscale.x * val;
|
|
386
|
+
this.data[5] = yscale.y * val;
|
|
387
|
+
this._scaleY = val;
|
|
388
|
+
}
|
|
389
|
+
setScale(scale) {
|
|
390
|
+
this.setScaleX(scale.x);
|
|
391
|
+
this.setScaleY(scale.y);
|
|
392
|
+
}
|
|
393
|
+
/**
|
|
394
|
+
* Determinant of the upper left 2x2 matrix
|
|
395
|
+
*/
|
|
396
|
+
getBasisDeterminant() {
|
|
397
|
+
return this.data[0] * this.data[5] - this.data[1] * this.data[4];
|
|
398
|
+
}
|
|
399
|
+
/**
|
|
400
|
+
* Return the affine inverse, optionally store it in a target matrix.
|
|
401
|
+
*
|
|
402
|
+
* It's recommended you call .reset() the target unless you know what you're doing
|
|
403
|
+
* @param target
|
|
404
|
+
*/
|
|
405
|
+
getAffineInverse(target) {
|
|
406
|
+
// See http://negativeprobability.blogspot.com/2011/11/affine-transformations-and-their.html
|
|
407
|
+
// See https://www.mathsisfun.com/algebra/matrix-inverse.html
|
|
408
|
+
// Since we are actually only doing 2D transformations we can use this hack
|
|
409
|
+
// We don't actually use the 3rd or 4th dimension
|
|
410
|
+
const det = this.getBasisDeterminant();
|
|
411
|
+
const inverseDet = 1 / det; // todo zero check
|
|
412
|
+
const a = this.data[0];
|
|
413
|
+
const b = this.data[4];
|
|
414
|
+
const c = this.data[1];
|
|
415
|
+
const d = this.data[5];
|
|
416
|
+
const m = target || Matrix.identity();
|
|
417
|
+
// inverts rotation and scale
|
|
418
|
+
m.data[0] = d * inverseDet;
|
|
419
|
+
m.data[1] = -c * inverseDet;
|
|
420
|
+
m.data[4] = -b * inverseDet;
|
|
421
|
+
m.data[5] = a * inverseDet;
|
|
422
|
+
const tx = this.data[12];
|
|
423
|
+
const ty = this.data[13];
|
|
424
|
+
// invert translation
|
|
425
|
+
// transform translation into the matrix basis created by rot/scale
|
|
426
|
+
m.data[12] = -(tx * m.data[0] + ty * m.data[4]);
|
|
427
|
+
m.data[13] = -(tx * m.data[1] + ty * m.data[5]);
|
|
428
|
+
return m;
|
|
429
|
+
}
|
|
430
|
+
isIdentity() {
|
|
431
|
+
return (this.data[0] === 1 &&
|
|
432
|
+
this.data[1] === 0 &&
|
|
433
|
+
this.data[2] === 0 &&
|
|
434
|
+
this.data[3] === 0 &&
|
|
435
|
+
this.data[4] === 0 &&
|
|
436
|
+
this.data[5] === 1 &&
|
|
437
|
+
this.data[6] === 0 &&
|
|
438
|
+
this.data[7] === 0 &&
|
|
439
|
+
this.data[8] === 0 &&
|
|
440
|
+
this.data[9] === 0 &&
|
|
441
|
+
this.data[10] === 1 &&
|
|
442
|
+
this.data[11] === 0 &&
|
|
443
|
+
this.data[12] === 0 &&
|
|
444
|
+
this.data[13] === 0 &&
|
|
445
|
+
this.data[14] === 0 &&
|
|
446
|
+
this.data[15] === 1);
|
|
447
|
+
}
|
|
448
|
+
toString() {
|
|
449
|
+
return `
|
|
450
|
+
[${this.data[0]} ${this.data[4]} ${this.data[8]} ${this.data[12]}]
|
|
451
|
+
[${this.data[1]} ${this.data[5]} ${this.data[9]} ${this.data[13]}]
|
|
452
|
+
[${this.data[2]} ${this.data[6]} ${this.data[10]} ${this.data[14]}]
|
|
453
|
+
[${this.data[3]} ${this.data[7]} ${this.data[11]} ${this.data[15]}]
|
|
454
|
+
`;
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
//# sourceMappingURL=matrix.js.map
|