diff --git a/src/app/app.ts b/src/app/app.ts index 4c14a9e4b..e60e0fc88 100644 --- a/src/app/app.ts +++ b/src/app/app.ts @@ -21,7 +21,7 @@ import type { import { type KEventController, KEventHandler } from "../events/events"; import { canvasToViewport } from "../gfx/viewport"; import { map, vec2 } from "../math/math"; -import { Vec2 } from "../math/Vec2"; +import { Vec2 } from "../math/vec2"; import { _k } from "../shared"; import { deprecateMsg } from "../utils/log"; import { overload2 } from "../utils/overload"; diff --git a/src/assets/shader.ts b/src/assets/shader.ts index bdc1467bd..f18e10055 100644 --- a/src/assets/shader.ts +++ b/src/assets/shader.ts @@ -7,9 +7,9 @@ import { } from "../constants/general"; import { type GfxCtx, Texture } from "../gfx/gfx"; import { Color } from "../math/color"; -import { Mat4 } from "../math/Mat4"; +import { Mat4 } from "../math/mat4"; import { Mat23 } from "../math/math"; -import { Vec2 } from "../math/Vec2"; +import { Vec2 } from "../math/vec2"; import { _k } from "../shared"; import type { RenderProps } from "../types"; import { arrayIsColor, arrayIsNumber, arrayIsVec2 } from "../utils/asserts"; diff --git a/src/constants/math.ts b/src/constants/math.ts index a05c148dc..04de4d6b1 100644 --- a/src/constants/math.ts +++ b/src/constants/math.ts @@ -1,5 +1,5 @@ -import { Mat4 } from "../math/Mat4"; -import { Vec2 } from "../math/Vec2"; +import { Mat4 } from "../math/mat4"; +import { Vec2 } from "../math/vec2"; export const IDENTITY_MATRIX = new Mat4(); export const TOP_LEFT = new Vec2(-1, -1); diff --git a/src/core/context.ts b/src/core/context.ts index 9dea1fe5d..3044e0f8c 100644 --- a/src/core/context.ts +++ b/src/core/context.ts @@ -165,7 +165,7 @@ import { easings } from "../math/easings"; import { gjkShapeIntersection, gjkShapeIntersects } from "../math/gjk"; import { lerp } from "../math/lerp"; import { lerpAngle } from "../math/lerpAngle"; -import { Mat4 } from "../math/Mat4"; +import { Mat4 } from "../math/mat4"; import { bezier, cardinal, @@ -221,6 +221,7 @@ import { testRectRect, triangulate, vec2, + vec3, wave, } from "../math/math"; import { buildConnectivityMap, floodFill } from "../math/navigation"; @@ -234,7 +235,8 @@ import { import { chance, rand, randi, randSeed, RNG, setRNG } from "../math/random"; import { insertionSort } from "../math/sort"; import { makeQuadtree, Quadtree } from "../math/spatial/quadtree"; -import { Vec2 } from "../math/Vec2"; +import { Vec2 } from "../math/vec2"; +import { Vec3 } from "../math/vec3"; import { BlendMode, type KAPLAYPlugin } from "../types"; import { download, @@ -512,6 +514,7 @@ export const createContext = ( Polygon, Collision, Vec2, + Vec3, Color, Mat2, Mat4, diff --git a/src/core/contextType.ts b/src/core/contextType.ts index 51c6c9f14..2e40c6c1b 100644 --- a/src/core/contextType.ts +++ b/src/core/contextType.ts @@ -147,7 +147,7 @@ import type { Color, CSSColorKeywords } from "../math/color"; import type { EaseFunc, EaseFuncs } from "../math/easings"; import type { GjkCollisionResult } from "../math/gjk"; import type { LerpValue } from "../math/lerp"; -import type { Mat4 } from "../math/Mat4"; +import type { Mat4 } from "../math/mat4"; import type { Circle, Ellipse, @@ -166,7 +166,8 @@ import type { NavGrid } from "../math/navigationgrid"; import type { NavMesh } from "../math/navigationmesh"; import type { RandomGenerator, RNG, RNGConfig, RNGSeed } from "../math/random"; import type { Quadtree, ResizingQuadtree } from "../math/spatial/quadtree"; -import type { Vec2 } from "../math/Vec2"; +import type { Vec2 } from "../math/vec2"; +import type { Vec3 } from "../math/vec3"; import { type Anchor, type BlendMode, @@ -6528,6 +6529,14 @@ export interface KAPLAYCtx { Vec2: typeof Vec2; /** * A color. + * + * @since v2000.0 + * @group Math + * @subgroup Vectors + */ + Vec3: typeof Vec3; + /** + * A 3D vector. * * @since v2000.0 * @group Math diff --git a/src/core/frameRendering.ts b/src/core/frameRendering.ts index b0b2c4dfb..57223df28 100644 --- a/src/core/frameRendering.ts +++ b/src/core/frameRendering.ts @@ -7,7 +7,7 @@ import { drawUVQuad } from "../gfx/draw/drawUVQuad"; import type { AppGfxCtx } from "../gfx/gfxApp"; import { flush, height, width } from "../gfx/stack"; import { Quad } from "../math/math"; -import { Vec2 } from "../math/Vec2"; +import { Vec2 } from "../math/vec2"; /** * A frame renderer. diff --git a/src/ecs/components/draw/circle.ts b/src/ecs/components/draw/circle.ts index cd5d40c44..5bf9576b2 100644 --- a/src/ecs/components/draw/circle.ts +++ b/src/ecs/components/draw/circle.ts @@ -1,7 +1,7 @@ import { getRenderProps } from "../../../game/utils"; import { drawCircle } from "../../../gfx/draw/drawCircle"; import { Circle, Rect } from "../../../math/math"; -import { Vec2 } from "../../../math/Vec2"; +import { Vec2 } from "../../../math/vec2"; import type { Comp, GameObj } from "../../../types"; import { nextRenderAreaVersion } from "../physics/area"; import type { AnchorComp } from "../transform/anchor"; diff --git a/src/ecs/components/draw/ellipse.ts b/src/ecs/components/draw/ellipse.ts index 94b081216..82ceae854 100644 --- a/src/ecs/components/draw/ellipse.ts +++ b/src/ecs/components/draw/ellipse.ts @@ -1,7 +1,7 @@ import { getRenderProps } from "../../../game/utils"; import { drawEllipse } from "../../../gfx/draw/drawEllipse"; import { Ellipse } from "../../../math/math"; -import { Vec2 } from "../../../math/Vec2"; +import { Vec2 } from "../../../math/vec2"; import type { Comp, GameObj } from "../../../types"; import { nextRenderAreaVersion } from "../physics/area"; import type { AnchorComp } from "../transform/anchor"; diff --git a/src/ecs/components/draw/particles.ts b/src/ecs/components/draw/particles.ts index eb54f200d..de439af1f 100644 --- a/src/ecs/components/draw/particles.ts +++ b/src/ecs/components/draw/particles.ts @@ -5,7 +5,7 @@ import { Color } from "../../../math/color"; import { lerp } from "../../../math/lerp"; import { deg2rad, map, Quad, type ShapeType, vec2 } from "../../../math/math"; import { rand } from "../../../math/random"; -import { Vec2 } from "../../../math/Vec2"; +import { Vec2 } from "../../../math/vec2"; import { _k } from "../../../shared"; import type { Comp } from "../../../types"; diff --git a/src/ecs/components/draw/polygon.ts b/src/ecs/components/draw/polygon.ts index 72ec0cc81..974c36db9 100644 --- a/src/ecs/components/draw/polygon.ts +++ b/src/ecs/components/draw/polygon.ts @@ -6,7 +6,7 @@ import { import type { Texture } from "../../../gfx/gfx"; import type { Color } from "../../../math/color"; import { Polygon } from "../../../math/math"; -import { type Vec2 } from "../../../math/Vec2"; +import { type Vec2 } from "../../../math/vec2"; import type { Comp, GameObj } from "../../../types"; import { nextRenderAreaVersion } from "../physics/area"; import type { FillComp } from "./fill"; diff --git a/src/ecs/components/draw/raycast.ts b/src/ecs/components/draw/raycast.ts index c4ced63f5..fbc2e0cc0 100644 --- a/src/ecs/components/draw/raycast.ts +++ b/src/ecs/components/draw/raycast.ts @@ -1,5 +1,5 @@ import type { RaycastResult } from "../../../math/math"; -import type { Vec2 } from "../../../math/Vec2"; +import type { Vec2 } from "../../../math/vec2"; import { _k } from "../../../shared"; // this is not a component lol diff --git a/src/ecs/components/draw/sprite.ts b/src/ecs/components/draw/sprite.ts index a305cc605..6d503995e 100644 --- a/src/ecs/components/draw/sprite.ts +++ b/src/ecs/components/draw/sprite.ts @@ -13,7 +13,7 @@ import { anchorPt } from "../../../gfx/anchor"; import { drawTexture } from "../../../gfx/draw/drawTexture"; import type { Texture } from "../../../gfx/gfx"; import { Quad, quad, Rect, vec2 } from "../../../math/math"; -import { type Vec2 } from "../../../math/Vec2"; +import { type Vec2 } from "../../../math/vec2"; import { _k } from "../../../shared"; import type { Comp, GameObj, SpriteAnimPlayOpt } from "../../../types"; import { warn } from "../../../utils/log"; diff --git a/src/ecs/components/level/agent.ts b/src/ecs/components/level/agent.ts index 28ab253a2..a5254bdcc 100644 --- a/src/ecs/components/level/agent.ts +++ b/src/ecs/components/level/agent.ts @@ -1,5 +1,5 @@ import type { KEventController } from "../../../events/events"; -import type { Vec2 } from "../../../math/Vec2"; +import type { Vec2 } from "../../../math/vec2"; import type { Comp, GameObj } from "../../../types"; import type { PosComp } from "../transform/pos"; import type { TileComp } from "./tile"; diff --git a/src/ecs/components/level/level.ts b/src/ecs/components/level/level.ts index a239a5260..4b81ddb75 100644 --- a/src/ecs/components/level/level.ts +++ b/src/ecs/components/level/level.ts @@ -6,7 +6,7 @@ import { type Vec2Args, } from "../../../math/math"; import { calcTransform } from "../../../math/various"; -import { type Vec2 } from "../../../math/Vec2"; +import { type Vec2 } from "../../../math/vec2"; import { type Comp, type CompList, diff --git a/src/ecs/components/level/pathfinder.ts b/src/ecs/components/level/pathfinder.ts index 675962023..04e7091c1 100644 --- a/src/ecs/components/level/pathfinder.ts +++ b/src/ecs/components/level/pathfinder.ts @@ -1,5 +1,5 @@ import { type Graph } from "../../../math/navigation"; -import { Vec2 } from "../../../math/Vec2"; +import { Vec2 } from "../../../math/vec2"; import type { Comp, GameObj } from "../../../types"; import type { PosComp } from "../transform/pos"; diff --git a/src/ecs/components/level/patrol.ts b/src/ecs/components/level/patrol.ts index 5e61a5c9c..51d1e8f55 100644 --- a/src/ecs/components/level/patrol.ts +++ b/src/ecs/components/level/patrol.ts @@ -1,5 +1,5 @@ import type { KEventController } from "../../../events/events"; -import type { Vec2 } from "../../../math/Vec2"; +import type { Vec2 } from "../../../math/vec2"; import type { Comp, GameObj } from "../../../types"; import type { PosComp } from "../transform/pos"; diff --git a/src/ecs/components/level/sentry.ts b/src/ecs/components/level/sentry.ts index 0c32aaeb5..59aa2f514 100644 --- a/src/ecs/components/level/sentry.ts +++ b/src/ecs/components/level/sentry.ts @@ -1,5 +1,5 @@ import type { KEventController } from "../../../events/events"; -import { Vec2 } from "../../../math/Vec2"; +import { Vec2 } from "../../../math/vec2"; import { _k } from "../../../shared"; import type { Comp, GameObj, QueryOpt } from "../../../types"; import { raycast } from "../draw/raycast"; diff --git a/src/ecs/components/level/tile.ts b/src/ecs/components/level/tile.ts index 7bfa007cf..b90f0c1bf 100644 --- a/src/ecs/components/level/tile.ts +++ b/src/ecs/components/level/tile.ts @@ -1,5 +1,5 @@ import { vec2 } from "../../../math/math"; -import { Vec2 } from "../../../math/Vec2"; +import { Vec2 } from "../../../math/vec2"; import { type Comp, type Edge, EdgeMask, type GameObj } from "../../../types"; import type { LevelComp } from "./level"; diff --git a/src/ecs/components/misc/animate.ts b/src/ecs/components/misc/animate.ts index be24b60f5..c65c9489d 100644 --- a/src/ecs/components/misc/animate.ts +++ b/src/ecs/components/misc/animate.ts @@ -4,7 +4,7 @@ import { Color } from "../../../math/color"; import { type EaseFunc, easings } from "../../../math/easings"; import { lerp, type LerpValue } from "../../../math/lerp"; import { catmullRom, hermiteFirstDerivative, vec2 } from "../../../math/math"; -import { Vec2 } from "../../../math/Vec2"; +import { Vec2 } from "../../../math/vec2"; import { _k } from "../../../shared"; import type { Comp, GameObj } from "../../../types"; import type { NamedComp } from "./named"; diff --git a/src/ecs/components/misc/fakeMouse.ts b/src/ecs/components/misc/fakeMouse.ts index 4f64d2e58..5f94e6503 100644 --- a/src/ecs/components/misc/fakeMouse.ts +++ b/src/ecs/components/misc/fakeMouse.ts @@ -1,4 +1,4 @@ -import type { Vec2 } from "../../../math/Vec2"; +import type { Vec2 } from "../../../math/vec2"; import { _k } from "../../../shared"; import type { Comp, GameObj } from "../../../types"; import type { PosComp } from "../transform/pos"; diff --git a/src/ecs/components/misc/timer.ts b/src/ecs/components/misc/timer.ts index 4c8acd1e5..37c8becec 100644 --- a/src/ecs/components/misc/timer.ts +++ b/src/ecs/components/misc/timer.ts @@ -1,7 +1,7 @@ import { KEvent } from "../../../events/events"; import { easings } from "../../../math/easings"; import { lerp, type LerpValue } from "../../../math/lerp"; -import { Vec2 } from "../../../math/Vec2"; +import { Vec2 } from "../../../math/vec2"; import { _k } from "../../../shared"; import type { Comp, GameObj } from "../../../types"; diff --git a/src/ecs/components/physics/area.ts b/src/ecs/components/physics/area.ts index c8abdbc1a..9c53a3be9 100644 --- a/src/ecs/components/physics/area.ts +++ b/src/ecs/components/physics/area.ts @@ -8,7 +8,7 @@ import { drawRect } from "../../../gfx/draw/drawRect"; import { multTranslate, popTransform, pushTransform } from "../../../gfx/stack"; import { rgb } from "../../../math/color"; import { Circle, Polygon, Rect, shapeFactory, vec2 } from "../../../math/math"; -import { Vec2 } from "../../../math/Vec2"; +import { Vec2 } from "../../../math/vec2"; import { _k } from "../../../shared"; import type { Comp, diff --git a/src/ecs/components/physics/body.ts b/src/ecs/components/physics/body.ts index ca1016cd5..2d7612314 100644 --- a/src/ecs/components/physics/body.ts +++ b/src/ecs/components/physics/body.ts @@ -4,7 +4,7 @@ import { getGravityDirection } from "../../../game/gravity"; import { lerp } from "../../../math/lerp"; import { vec2 } from "../../../math/math"; import { calcTransform } from "../../../math/various"; -import { type Vec2 } from "../../../math/Vec2"; +import { type Vec2 } from "../../../math/vec2"; import { _k } from "../../../shared"; import type { Comp, GameObj } from "../../../types"; import { exists } from "../../entity/utils"; diff --git a/src/ecs/components/physics/effectors.ts b/src/ecs/components/physics/effectors.ts index 73cff7171..f1feecef1 100644 --- a/src/ecs/components/physics/effectors.ts +++ b/src/ecs/components/physics/effectors.ts @@ -1,5 +1,5 @@ import { Polygon, vec2 } from "../../../math/math"; -import { Vec2 } from "../../../math/Vec2"; +import { Vec2 } from "../../../math/vec2"; import type { Comp, GameObj } from "../../../types"; import type { PosComp } from "../transform/pos"; import type { AreaComp } from "./area"; diff --git a/src/ecs/components/transform/anchor.ts b/src/ecs/components/transform/anchor.ts index 3c608ddd3..717f60522 100644 --- a/src/ecs/components/transform/anchor.ts +++ b/src/ecs/components/transform/anchor.ts @@ -1,6 +1,6 @@ import { anchorPt } from "../../../gfx/anchor"; import { vec2 } from "../../../math/math"; -import { type SerializedVec2, Vec2 } from "../../../math/Vec2"; +import { type SerializedVec2, Vec2 } from "../../../math/vec2"; import type { Anchor, Comp } from "../../../types"; /** diff --git a/src/ecs/components/transform/constraint.ts b/src/ecs/components/transform/constraint.ts index 30a4db170..655aa4df4 100644 --- a/src/ecs/components/transform/constraint.ts +++ b/src/ecs/components/transform/constraint.ts @@ -18,7 +18,7 @@ import { updateChildrenTransformRecursive, updateTransformRecursive, } from "../../../math/various"; -import { Vec2 } from "../../../math/Vec2"; +import { Vec2 } from "../../../math/vec2"; import { _k } from "../../../shared"; import type { Comp, GameObj } from "../../../types"; import { system, SystemPhase } from "../../systems/systems"; diff --git a/src/ecs/components/transform/follow.ts b/src/ecs/components/transform/follow.ts index dc1edc9cb..76faf835d 100644 --- a/src/ecs/components/transform/follow.ts +++ b/src/ecs/components/transform/follow.ts @@ -1,5 +1,5 @@ import { vec2 } from "../../../math/math"; -import { Vec2 } from "../../../math/Vec2"; +import { Vec2 } from "../../../math/vec2"; import type { Comp, GameObj } from "../../../types"; import { exists } from "../../entity/utils"; import type { PosComp } from "./pos"; diff --git a/src/ecs/components/transform/move.ts b/src/ecs/components/transform/move.ts index a6c7d1714..97b695f96 100644 --- a/src/ecs/components/transform/move.ts +++ b/src/ecs/components/transform/move.ts @@ -1,4 +1,4 @@ -import { type SerializedVec2, Vec2 } from "../../../math/Vec2"; +import { type SerializedVec2, Vec2 } from "../../../math/vec2"; import type { Comp, EmptyComp, GameObj } from "../../../types"; import type { PosComp } from "./pos"; diff --git a/src/ecs/components/transform/pos.ts b/src/ecs/components/transform/pos.ts index 6023adc03..474d456ae 100644 --- a/src/ecs/components/transform/pos.ts +++ b/src/ecs/components/transform/pos.ts @@ -2,7 +2,7 @@ import { toScreen, toWorld } from "../../../game/camera"; import { drawCircle } from "../../../gfx/draw/drawCircle"; import { rgb } from "../../../math/color"; import { vec2, type Vec2Args } from "../../../math/math"; -import { Vec2 } from "../../../math/Vec2"; +import { Vec2 } from "../../../math/vec2"; import { _k } from "../../../shared"; import type { Comp, GameObj } from "../../../types"; import { diff --git a/src/ecs/components/transform/scale.ts b/src/ecs/components/transform/scale.ts index f163a25b9..ef3274418 100644 --- a/src/ecs/components/transform/scale.ts +++ b/src/ecs/components/transform/scale.ts @@ -1,5 +1,5 @@ import { vec2, type Vec2Args } from "../../../math/math"; -import { type SerializedVec2, Vec2 } from "../../../math/Vec2"; +import { type SerializedVec2, Vec2 } from "../../../math/vec2"; import type { Comp } from "../../../types"; import { type InternalGameObjRaw, diff --git a/src/ecs/components/transform/skew.ts b/src/ecs/components/transform/skew.ts index 84068071a..eb841dd02 100644 --- a/src/ecs/components/transform/skew.ts +++ b/src/ecs/components/transform/skew.ts @@ -1,5 +1,5 @@ import { vec2, type Vec2Args } from "../../../math/math"; -import { type SerializedVec2, Vec2 } from "../../../math/Vec2"; +import { type SerializedVec2, Vec2 } from "../../../math/vec2"; import type { Comp } from "../../../types"; import { type InternalGameObjRaw, diff --git a/src/ecs/entity/premade/addKaboom.ts b/src/ecs/entity/premade/addKaboom.ts index d1605ea31..d82744729 100644 --- a/src/ecs/entity/premade/addKaboom.ts +++ b/src/ecs/entity/premade/addKaboom.ts @@ -1,4 +1,4 @@ -import type { Vec2 } from "../../../math/Vec2"; +import type { Vec2 } from "../../../math/vec2"; import { _k } from "../../../shared"; import type { CompList, GameObj } from "../../../types"; import { sprite } from "../../components/draw/sprite"; diff --git a/src/ecs/entity/premade/addLevel.ts b/src/ecs/entity/premade/addLevel.ts index 19ba2ff56..c9e51f4b1 100644 --- a/src/ecs/entity/premade/addLevel.ts +++ b/src/ecs/entity/premade/addLevel.ts @@ -1,5 +1,5 @@ import { vec2 } from "../../../math/math"; -import type { Vec2 } from "../../../math/Vec2"; +import type { Vec2 } from "../../../math/vec2"; import { _k } from "../../../shared"; import type { GameObj } from "../../../types"; import { diff --git a/src/ecs/systems/Collision.ts b/src/ecs/systems/Collision.ts index ad753abe9..90a3e5f86 100644 --- a/src/ecs/systems/Collision.ts +++ b/src/ecs/systems/Collision.ts @@ -1,5 +1,5 @@ import { vec2 } from "../../math/math"; -import type { Vec2 } from "../../math/Vec2"; +import type { Vec2 } from "../../math/vec2"; import { _k } from "../../shared"; import type { GameObj } from "../../types"; diff --git a/src/events/eventMap.ts b/src/events/eventMap.ts index f6a382da1..6ee293f0e 100644 --- a/src/events/eventMap.ts +++ b/src/events/eventMap.ts @@ -11,7 +11,7 @@ import { type doubleJump } from "../ecs/components/physics/doubleJump"; import { type offscreen } from "../ecs/components/transform/offscreen"; import { type addLevel } from "../ecs/entity/premade/addLevel"; import type { Collision } from "../ecs/systems/Collision"; -import type { Vec2 } from "../math/Vec2"; +import type { Vec2 } from "../math/vec2"; import type { GameObj, Key, diff --git a/src/game/camera.ts b/src/game/camera.ts index 4228853e5..6cf4ba792 100644 --- a/src/game/camera.ts +++ b/src/game/camera.ts @@ -6,7 +6,7 @@ import { destroy } from "../ecs/entity/utils"; import { center, height, width } from "../gfx/stack"; import { type Color, rgb } from "../math/color"; import { type Mat23, vec2, type Vec2Args } from "../math/math"; -import { Vec2 } from "../math/Vec2"; +import { Vec2 } from "../math/vec2"; import { _k } from "../shared"; import { deprecateMsg } from "../utils/log"; diff --git a/src/game/game.ts b/src/game/game.ts index 9a78e9c70..e7e43527a 100644 --- a/src/game/game.ts +++ b/src/game/game.ts @@ -17,7 +17,7 @@ import type { GameEventMap, GameObjEventMap } from "../events/eventMap"; import { type KEventController, KEventHandler } from "../events/events"; import { Mat23, Rect } from "../math/math"; import { RNG, type RNGConfig } from "../math/random"; -import { Vec2 } from "../math/Vec2"; +import { Vec2 } from "../math/vec2"; import type { GameObj } from "../types"; import type { SceneDef, SceneState } from "./scenes"; diff --git a/src/game/gravity.ts b/src/game/gravity.ts index 0f795b68c..73b2c54cf 100644 --- a/src/game/gravity.ts +++ b/src/game/gravity.ts @@ -1,7 +1,7 @@ // Gravity manipulation import { vec2 } from "../math/math"; -import { type Vec2 } from "../math/Vec2"; +import { type Vec2 } from "../math/vec2"; import { _k } from "../shared"; export function setGravity(g: number) { diff --git a/src/gfx/TexPacker.ts b/src/gfx/TexPacker.ts index 9f3656bce..71fab965c 100644 --- a/src/gfx/TexPacker.ts +++ b/src/gfx/TexPacker.ts @@ -1,6 +1,6 @@ import { drawImageSourceAt } from "../assets/utils"; import { Quad, Rect, testRectRect } from "../math/math"; -import { Vec2 } from "../math/Vec2"; +import { Vec2 } from "../math/vec2"; import type { ImageSource, TexFilter } from "../types"; import { type GfxCtx, Texture } from "./gfx"; diff --git a/src/gfx/anchor.ts b/src/gfx/anchor.ts index d789404a5..5509fc496 100644 --- a/src/gfx/anchor.ts +++ b/src/gfx/anchor.ts @@ -9,7 +9,7 @@ import { TOP_LEFT, TOP_RIGHT, } from "../constants/math"; -import { Vec2 } from "../math/Vec2"; +import { Vec2 } from "../math/vec2"; import { type Anchor } from "../types"; import type { TextAlign } from "./draw/drawText"; diff --git a/src/gfx/draw/drawBezier.ts b/src/gfx/draw/drawBezier.ts index e05980ad4..6fa92bd51 100644 --- a/src/gfx/draw/drawBezier.ts +++ b/src/gfx/draw/drawBezier.ts @@ -1,5 +1,5 @@ import { evaluateBezier } from "../../math/math"; -import { type Vec2 } from "../../math/Vec2"; +import { type Vec2 } from "../../math/vec2"; import { drawCurve, type DrawCurveOpt } from "./drawCurve"; /** diff --git a/src/gfx/draw/drawCircle.ts b/src/gfx/draw/drawCircle.ts index b8b3ac9ee..8ab45d99c 100644 --- a/src/gfx/draw/drawCircle.ts +++ b/src/gfx/draw/drawCircle.ts @@ -1,5 +1,5 @@ import type { Color } from "../../math/color"; -import type { Vec2 } from "../../math/Vec2"; +import type { Vec2 } from "../../math/vec2"; import type { Anchor, RenderProps } from "../../types"; import { drawEllipse } from "./drawEllipse"; diff --git a/src/gfx/draw/drawCurve.ts b/src/gfx/draw/drawCurve.ts index d4f7851b9..2bd3017bc 100644 --- a/src/gfx/draw/drawCurve.ts +++ b/src/gfx/draw/drawCurve.ts @@ -1,4 +1,4 @@ -import type { Vec2 } from "../../math/Vec2"; +import type { Vec2 } from "../../math/vec2"; import type { RenderProps } from "../../types"; import { drawLines } from "./drawLine"; diff --git a/src/gfx/draw/drawEllipse.ts b/src/gfx/draw/drawEllipse.ts index 722469a15..50703b42f 100644 --- a/src/gfx/draw/drawEllipse.ts +++ b/src/gfx/draw/drawEllipse.ts @@ -1,6 +1,6 @@ import type { Color } from "../../math/color"; import { getArcPts } from "../../math/various"; -import { Vec2 } from "../../math/Vec2"; +import { Vec2 } from "../../math/vec2"; import type { Anchor, RenderProps } from "../../types"; import { anchorPt } from "../anchor"; import { drawPolygon } from "./drawPolygon"; diff --git a/src/gfx/draw/drawFormattedText.ts b/src/gfx/draw/drawFormattedText.ts index 5d7f0a4d6..dbb1edae8 100644 --- a/src/gfx/draw/drawFormattedText.ts +++ b/src/gfx/draw/drawFormattedText.ts @@ -1,7 +1,7 @@ import type { FontData } from "../../assets/font"; import type { Uniform } from "../../assets/shader"; import { Color } from "../../math/color"; -import type { Vec2 } from "../../math/Vec2"; +import type { Vec2 } from "../../math/vec2"; import { anchorPt } from "../anchor"; import type { Texture } from "../gfx"; import { diff --git a/src/gfx/draw/drawFrame.ts b/src/gfx/draw/drawFrame.ts index 766073681..9909cd354 100644 --- a/src/gfx/draw/drawFrame.ts +++ b/src/gfx/draw/drawFrame.ts @@ -4,7 +4,7 @@ import { } from "../../ecs/entity/GameObjRaw"; import { lerp } from "../../math/lerp"; import { rand } from "../../math/random"; -import { Vec2 } from "../../math/Vec2"; +import { Vec2 } from "../../math/vec2"; import { _k } from "../../shared"; import { center, flush } from "../stack"; diff --git a/src/gfx/draw/drawInspectText.ts b/src/gfx/draw/drawInspectText.ts index 717d54554..04e880d17 100644 --- a/src/gfx/draw/drawInspectText.ts +++ b/src/gfx/draw/drawInspectText.ts @@ -1,7 +1,7 @@ import { DBG_FONT } from "../../constants/general"; import { rgb } from "../../math/color"; import { vec2 } from "../../math/math"; -import { type Vec2 } from "../../math/Vec2"; +import { type Vec2 } from "../../math/vec2"; import { formatText } from "../formatText"; import { height, diff --git a/src/gfx/draw/drawLine.ts b/src/gfx/draw/drawLine.ts index 4e0a385fa..95c616928 100644 --- a/src/gfx/draw/drawLine.ts +++ b/src/gfx/draw/drawLine.ts @@ -1,7 +1,7 @@ import { Color } from "../../math/color"; import { lerp } from "../../math/lerp"; import { deg2rad, vec2 } from "../../math/math"; -import { Vec2 } from "../../math/Vec2"; +import { Vec2 } from "../../math/vec2"; import { _k } from "../../shared"; import type { RenderProps } from "../../types"; import { drawRaw } from "./drawRaw"; diff --git a/src/gfx/draw/drawPolygon.ts b/src/gfx/draw/drawPolygon.ts index 09bdefa2f..1cb1ae084 100644 --- a/src/gfx/draw/drawPolygon.ts +++ b/src/gfx/draw/drawPolygon.ts @@ -1,6 +1,6 @@ import { Color } from "../../math/color"; import { triangulate } from "../../math/math"; -import { Vec2 } from "../../math/Vec2"; +import { Vec2 } from "../../math/vec2"; import { _k } from "../../shared"; import { BlendMode, type RenderProps } from "../../types"; import type { Texture } from "../gfx"; diff --git a/src/gfx/draw/drawRect.ts b/src/gfx/draw/drawRect.ts index 3f29e2f22..6b884eae7 100644 --- a/src/gfx/draw/drawRect.ts +++ b/src/gfx/draw/drawRect.ts @@ -2,7 +2,7 @@ import { DEF_ANCHOR } from "../../constants/general"; import type { Color } from "../../math/color"; import { vec2 } from "../../math/math"; import { getArcPts } from "../../math/various"; -import { Vec2 } from "../../math/Vec2"; +import { Vec2 } from "../../math/vec2"; import type { Anchor, RenderProps } from "../../types"; import { anchorPt } from "../anchor"; import { drawPolygon } from "./drawPolygon"; diff --git a/src/gfx/draw/drawSprite.ts b/src/gfx/draw/drawSprite.ts index 540aa5bad..bf0c5001f 100644 --- a/src/gfx/draw/drawSprite.ts +++ b/src/gfx/draw/drawSprite.ts @@ -1,7 +1,7 @@ import type { Asset } from "../../assets/asset"; import { resolveSprite, type SpriteData } from "../../assets/sprite"; import { Quad, vec2 } from "../../math/math"; -import { type Vec2 } from "../../math/Vec2"; +import { type Vec2 } from "../../math/vec2"; import type { Anchor, RenderProps } from "../../types"; import type { Texture } from "../gfx"; import { drawTexture } from "./drawTexture"; diff --git a/src/gfx/draw/drawText.ts b/src/gfx/draw/drawText.ts index 34f448142..8d0c7e904 100644 --- a/src/gfx/draw/drawText.ts +++ b/src/gfx/draw/drawText.ts @@ -3,7 +3,7 @@ import type { BitmapFontData } from "../../assets/bitmapFont"; import type { FontData } from "../../assets/font"; import type { Uniform } from "../../assets/shader"; import type { Color } from "../../math/color"; -import type { Vec2 } from "../../math/Vec2"; +import type { Vec2 } from "../../math/vec2"; import type { Anchor, RenderProps } from "../../types"; import { formatText } from "../formatText"; import { drawFormattedText } from "./drawFormattedText"; diff --git a/src/gfx/draw/drawTexture.ts b/src/gfx/draw/drawTexture.ts index b33e5cdcf..872c61cb4 100644 --- a/src/gfx/draw/drawTexture.ts +++ b/src/gfx/draw/drawTexture.ts @@ -1,7 +1,7 @@ import { DEF_ANCHOR } from "../../constants/general"; import { Color } from "../../math/color"; import { Quad } from "../../math/math"; -import { Vec2 } from "../../math/Vec2"; +import { Vec2 } from "../../math/vec2"; import { type Anchor, BlendMode, type RenderProps } from "../../types"; import { anchorPt } from "../anchor"; import type { Texture } from "../gfx"; diff --git a/src/gfx/draw/drawTriangle.ts b/src/gfx/draw/drawTriangle.ts index cb9f7816c..cfdc61e63 100644 --- a/src/gfx/draw/drawTriangle.ts +++ b/src/gfx/draw/drawTriangle.ts @@ -1,4 +1,4 @@ -import type { Vec2 } from "../../math/Vec2"; +import type { Vec2 } from "../../math/vec2"; import type { RenderProps } from "../../types"; import { drawPolygon } from "./drawPolygon"; diff --git a/src/gfx/draw/drawUVQuad.ts b/src/gfx/draw/drawUVQuad.ts index 943845630..df8b63b04 100644 --- a/src/gfx/draw/drawUVQuad.ts +++ b/src/gfx/draw/drawUVQuad.ts @@ -1,7 +1,7 @@ import { DEF_ANCHOR } from "../../constants/general"; import { Color } from "../../math/color"; import { Quad } from "../../math/math"; -import { Vec2 } from "../../math/Vec2"; +import { Vec2 } from "../../math/vec2"; import { type Anchor, BlendMode, type RenderProps } from "../../types"; import { anchorPt } from "../anchor"; import type { Texture } from "../gfx"; diff --git a/src/gfx/gfxApp.ts b/src/gfx/gfxApp.ts index 7b249e1fc..afca18cb1 100644 --- a/src/gfx/gfxApp.ts +++ b/src/gfx/gfxApp.ts @@ -8,7 +8,7 @@ import { } from "../constants/general"; import { type Color, rgb } from "../math/color"; import { Mat23 } from "../math/math"; -import { Vec2 } from "../math/Vec2"; +import { Vec2 } from "../math/vec2"; import type { MustKAPLAYOpt } from "../types"; import type { FontAtlas } from "./formatText"; import { FrameBuffer } from "./FrameBuffer"; diff --git a/src/gfx/stack.ts b/src/gfx/stack.ts index c0e9d343c..bfcad9149 100644 --- a/src/gfx/stack.ts +++ b/src/gfx/stack.ts @@ -1,6 +1,6 @@ import type { Uniform } from "../assets/shader"; import { type Mat23, vec2 } from "../math/math"; -import { Vec2 } from "../math/Vec2"; +import { Vec2 } from "../math/vec2"; import { _k } from "../shared"; export function pushTransform() { diff --git a/src/gfx/viewport.ts b/src/gfx/viewport.ts index 39e8ab6ab..0a18439b0 100644 --- a/src/gfx/viewport.ts +++ b/src/gfx/viewport.ts @@ -1,4 +1,4 @@ -import { Vec2 } from "../math/Vec2"; +import { Vec2 } from "../math/vec2"; import { _k } from "../shared"; /* diff --git a/src/math/convexhull.ts b/src/math/convexhull.ts index d76be8f7d..5739f50a5 100644 --- a/src/math/convexhull.ts +++ b/src/math/convexhull.ts @@ -1,4 +1,4 @@ -import type { Vec2 } from "./Vec2"; +import type { Vec2 } from "./vec2"; /** * > 0 if counter clockwise diff --git a/src/math/getImageOutline.ts b/src/math/getImageOutline.ts index 360bd7909..354f768b6 100644 --- a/src/math/getImageOutline.ts +++ b/src/math/getImageOutline.ts @@ -1,4 +1,4 @@ -import { Vec2 } from "./Vec2"; +import { Vec2 } from "./vec2"; export function traceRegion( width: number, diff --git a/src/math/gjk.ts b/src/math/gjk.ts index 08ff41430..d614477bf 100644 --- a/src/math/gjk.ts +++ b/src/math/gjk.ts @@ -1,7 +1,7 @@ import { MAX_TRIES } from "../constants/general"; import type { Shape } from "../types"; import { Circle, Ellipse, Polygon, Rect, vec2 } from "./math"; -import { Vec2 } from "./Vec2"; +import { Vec2 } from "./vec2"; function calculateSupport( shapeA: Shape, diff --git a/src/math/lerp.ts b/src/math/lerp.ts index f66ed565c..db5299ce0 100644 --- a/src/math/lerp.ts +++ b/src/math/lerp.ts @@ -1,5 +1,5 @@ import { Color } from "./color"; -import { Vec2 } from "./Vec2"; +import { Vec2 } from "./vec2"; /** * A valid value for lerp. diff --git a/src/math/lerpAngle.ts b/src/math/lerpAngle.ts index 87bb627aa..8bc73b81f 100644 --- a/src/math/lerpAngle.ts +++ b/src/math/lerpAngle.ts @@ -1,5 +1,5 @@ import { clampAngle } from "./various"; -import { Vec2 } from "./Vec2"; +import { Vec2 } from "./vec2"; export function lerpAngle(a: V, b: V, t: number): V { if ( diff --git a/src/math/Mat4.ts b/src/math/mat4.ts similarity index 90% rename from src/math/Mat4.ts rename to src/math/mat4.ts index c217d6f8c..5da724f6f 100644 --- a/src/math/Mat4.ts +++ b/src/math/mat4.ts @@ -1,7 +1,10 @@ import { deg2rad, rad2deg } from "./math"; -import { Vec2 } from "./Vec2"; +import { Vec2 } from "./vec2"; +import { Vec3 } from "./vec3"; /** + * A 4x4 matrix. + * * @group Math */ export class Mat4 { @@ -152,6 +155,14 @@ export class Mat4 { return this; } + translateVec3(p: Vec3) { + this.m[12] += this.m[0] * p.x + this.m[4] * p.y + this.m[8] * p.z; + this.m[13] += this.m[1] * p.x + this.m[5] * p.y + this.m[9] * p.z; + this.m[14] += this.m[2] * p.x + this.m[6] * p.y + this.m[10] * p.z; + this.m[15] += this.m[3] * p.x + this.m[7] * p.y + this.m[11] * p.z; + return this; + } + scale(p: Vec2) { this.m[0] *= p.x; this.m[4] *= p.y; @@ -247,7 +258,7 @@ export class Mat4 { const r = Math.sqrt(this.m[0] * this.m[0] + this.m[1] * this.m[1]); return new Vec2( Math.atan(this.m[0] * this.m[4] + this.m[1] * this.m[5]) - / (r * r), + / (r * r), 0, ); } @@ -256,7 +267,7 @@ export class Mat4 { return new Vec2( 0, Math.atan(this.m[0] * this.m[4] + this.m[1] * this.m[5]) - / (s * s), + / (s * s), ); } else { @@ -321,6 +332,19 @@ export class Mat4 { return new Mat4(out); } + static perspective(fov: number, aspect: number, near: number = 0.1, far: number = 100): Mat4 { + const fovRad = fov * Math.PI / 180.0; + const f = 1.0 / Math.tan(fovRad * 0.5); + const nf = 1.0 / (near - far); + + return new Mat4([ + f / aspect, 0, 0, 0, + 0, f, 0, 0, + 0, 0, (far + near) * nf, -1, + 0, 0, (2 * far * near) * nf, 0, + ]); + } + clone(): Mat4 { return new Mat4([...this.m]); } diff --git a/src/math/math.ts b/src/math/math.ts index 25c09bb53..7ec013090 100644 --- a/src/math/math.ts +++ b/src/math/math.ts @@ -7,7 +7,8 @@ import { clamp } from "./clamp"; import { traceRegion } from "./getImageOutline"; import { lerp, type LerpValue } from "./lerp"; import { rand, RNG } from "./random"; -import { Vec2 } from "./Vec2"; +import { Vec2 } from "./vec2"; +import { Vec3 } from "./vec3"; /** * Possible arguments for a Vec2. @@ -72,6 +73,10 @@ export function vec2(...args: Vec2Args): Vec2 { return new Vec2(...args); } +export function vec3(x: number, y: number, z: number): Vec3 { + return new Vec3(x, y, z); +} + /** * @group Math * @subgroup Advanced diff --git a/src/math/minkowski.ts b/src/math/minkowski.ts index e8e1949d3..cd0aaaf2b 100644 --- a/src/math/minkowski.ts +++ b/src/math/minkowski.ts @@ -1,6 +1,6 @@ import type { Shape } from "../types"; import { Rect, vec2 } from "./math"; -import { Vec2 } from "./Vec2"; +import { Vec2 } from "./vec2"; function minkowskiRectDifference(r1: Rect, r2: Rect): Rect { return new Rect( diff --git a/src/math/navigation.ts b/src/math/navigation.ts index f6548eb7f..1e25805a4 100644 --- a/src/math/navigation.ts +++ b/src/math/navigation.ts @@ -1,5 +1,5 @@ import { BinaryHeap } from "../utils/binaryheap"; -import { Vec2 } from "./Vec2"; +import { Vec2 } from "./vec2"; export interface Graph { /* Returns the reachable neighbors of this location */ diff --git a/src/math/navigationgrid.ts b/src/math/navigationgrid.ts index 2cc6ed244..e08e9b6e8 100644 --- a/src/math/navigationgrid.ts +++ b/src/math/navigationgrid.ts @@ -1,6 +1,6 @@ import { vec2 } from "./math"; import { aStarSearch, buildConnectivityMap, type Graph } from "./navigation"; -import { Vec2 } from "./Vec2"; +import { Vec2 } from "./vec2"; /** * A navigation grid is a graph consisting of connected grid cells diff --git a/src/math/navigationmesh.ts b/src/math/navigationmesh.ts index 4ec371727..824e0fb79 100644 --- a/src/math/navigationmesh.ts +++ b/src/math/navigationmesh.ts @@ -1,6 +1,6 @@ import { vec2 } from "./math"; import { aStarSearch, type Graph } from "./navigation"; -import { Vec2 } from "./Vec2"; +import { Vec2 } from "./vec2"; class NavEdge { a: Vec2; diff --git a/src/math/polygongeneration.ts b/src/math/polygongeneration.ts index 738b03243..b9e4b79b6 100644 --- a/src/math/polygongeneration.ts +++ b/src/math/polygongeneration.ts @@ -1,5 +1,5 @@ import { deg2rad, vec2 } from "./math"; -import type { Vec2 } from "./Vec2"; +import type { Vec2 } from "./vec2"; export function createRegularPolygon( radius: number, diff --git a/src/math/random.ts b/src/math/random.ts index f5d5469b0..516e7b630 100644 --- a/src/math/random.ts +++ b/src/math/random.ts @@ -5,7 +5,7 @@ import { vec2 } from "./math"; import { Alea } from "./rngAlea"; import { LinearCongruentialEngine } from "./rngLce"; import { XorShift32 } from "./rngXorShift32"; -import { Vec2 } from "./Vec2"; +import { Vec2 } from "./vec2"; export interface RandomGenerator { /** diff --git a/src/math/sat.ts b/src/math/sat.ts index 982acd1ea..97fb47a39 100644 --- a/src/math/sat.ts +++ b/src/math/sat.ts @@ -1,6 +1,6 @@ import type { Shape } from "../types"; import { Polygon, vec2 } from "./math"; -import { Vec2 } from "./Vec2"; +import { Vec2 } from "./vec2"; export type SatResult = { normal: Vec2; diff --git a/src/math/spatial/hashgrid.ts b/src/math/spatial/hashgrid.ts index b8ff80135..a1b4db4a8 100644 --- a/src/math/spatial/hashgrid.ts +++ b/src/math/spatial/hashgrid.ts @@ -14,7 +14,7 @@ import { loadIdentity, pushMatrix } from "../../gfx/stack"; import type { GameObj } from "../../types"; import { type Rect, vec2 } from "../math"; import { calcTransform } from "../various"; -import type { Vec2 } from "../Vec2"; +import type { Vec2 } from "../vec2"; export type HashGridOpt = { hashGridSize?: number; diff --git a/src/math/spatial/quadtree.ts b/src/math/spatial/quadtree.ts index c3728bc74..5b2762e5b 100644 --- a/src/math/spatial/quadtree.ts +++ b/src/math/spatial/quadtree.ts @@ -12,7 +12,7 @@ import { exists, isPaused } from "../../ecs/entity/utils"; import type { GameObj } from "../../types"; import { Rect, vec2 } from "../math"; import { calcTransform } from "../various"; -import type { Vec2 } from "../Vec2"; +import type { Vec2 } from "../vec2"; import type { BroadPhaseAlgorithm } from "."; /** diff --git a/src/math/various.ts b/src/math/various.ts index 79e0e940e..6036dc57d 100644 --- a/src/math/various.ts +++ b/src/math/various.ts @@ -1,6 +1,6 @@ import type { GameObj } from "../types"; import { deg2rad, Mat23, vec2 } from "./math"; -import { Vec2 } from "./Vec2"; +import { Vec2 } from "./vec2"; export function calcTransform(obj: GameObj, tr: Mat23): Mat23 { if (obj.parent) { diff --git a/src/math/Vec2.ts b/src/math/vec2.ts similarity index 99% rename from src/math/Vec2.ts rename to src/math/vec2.ts index 1545d607c..88e1f1b3c 100644 --- a/src/math/Vec2.ts +++ b/src/math/vec2.ts @@ -1,10 +1,10 @@ import { _k } from "../shared"; import { lerpNumber } from "./lerpNumber"; -import type { Mat4 } from "./Mat4"; +import type { Mat4 } from "./mat4"; import { deg2rad, rad2deg, Rect, vec2, type Vec2Args } from "./math"; /** - * A serialized 2d vector. + * A serialized 2D vector. * * @group Components * @subgroup Component Serialization diff --git a/src/types.ts b/src/types.ts index a60ec939d..2aba91fd8 100644 --- a/src/types.ts +++ b/src/types.ts @@ -15,7 +15,7 @@ import type { FrameBuffer } from "./gfx/FrameBuffer"; import type { Color, RGBAValue, RGBValue } from "./math/color"; import type { Circle, Ellipse, Line, Point, Polygon, Rect } from "./math/math"; import type { RNGConfig } from "./math/random"; -import type { Vec2 } from "./math/Vec2"; +import type { Vec2 } from "./math/vec2"; import type { Defined, MergeObj } from "./utils/types"; export type Tag = string; diff --git a/src/utils/asserts.ts b/src/utils/asserts.ts index f3d4dfd2c..85cb1cc86 100644 --- a/src/utils/asserts.ts +++ b/src/utils/asserts.ts @@ -1,5 +1,5 @@ import { Color } from "../math/color"; -import { Vec2 } from "../math/Vec2"; +import { Vec2 } from "../math/vec2"; export function arrayIsColor(arr: unknown[]): arr is Color[] { return arr[0] instanceof Color;