UNPKG

@woosh/meep-engine

Version:

Pure JavaScript game engine. Fully featured and production ready.

210 lines 5.63 kB
/** * A Transform represents the position, rotation, and scale of an object in 3D space. * Think of it like the object's location, orientation, and size. * It has properties for position (like coordinates), rotation (how it's turned), and scale (how big it is). * * It also uses a "matrix" (a table of numbers) internally to efficiently store and calculate transformations, but you usually interact with the position, rotation, and scale directly. * @class */ export class Transform { /** * * @param json * @returns {Transform} */ static fromJSON(json: any): Transform; /** * * @param {number[]|Float32Array} mat * @returns {Transform} */ static fromMatrix(mat: number[] | Float32Array): Transform; /** * @deprecated use {@link Quaternion.rotateTowards} instead * @param {Quaternion} sourceQuaternion * @param {Vector3} targetVector * @param {Number} limit */ static adjustRotation(sourceQuaternion: Quaternion, targetVector: Vector3, limit?: number): void; /** * @type {Vector3} * @readonly */ readonly position: Vector3; /** * Orientation represented as a quaternion. * If Euler (XYZ) angles are required - consult {@link Quaternion} for relevant method * @type {Quaternion} * @readonly */ readonly rotation: Quaternion; /** * @type {Vector3} * @readonly */ readonly scale: Vector3; /** * transform matrix, position, rotation and scale must match, but shear can be different * @readonly * @type {Float32Array} */ readonly matrix: Float32Array; /** * Various bit flags, see {@link TransformFlags} * This should generally be accessed through {@link getFlag}/{@link setFlag} instead of modifying the value directly * @type {number} */ flags: number; /** * Current "forward" direction * NOTE that this vector is not live, meaning that if you modify transform, previously-obtained result will no longer be valid * @returns {Vector3} */ get forward(): Vector3; /** * Current "up" direction * @return {Vector3} */ get up(): Vector3; /** * Current "right" direction * @return {Vector3} */ get right(): Vector3; /** * Attach change listener * @param {function} handler * @param {*} [thisArg] */ subscribe(handler: Function, thisArg?: any): void; /** * Disconnect change listener * @param {function} handler * @param {*} [thisArg] */ unsubscribe(handler: Function, thisArg?: any): void; /** * * @param {number|TransformFlags} flag * @returns {void} */ setFlag(flag: number | TransformFlags): void; /** * * @param {number|TransformFlags} flag * @returns {void} */ clearFlag(flag: number | TransformFlags): void; /** * * @param {number|TransformFlags} flag * @param {boolean} value */ writeFlag(flag: number | TransformFlags, value: boolean): void; /** * * @param {number|TransformFlags} flag * @returns {boolean} */ getFlag(flag: number | TransformFlags): boolean; /** * Update {@link matrix} attribute from current position/rotation/scale */ updateMatrix(): void; /** * * @param {Vector3} target * @param {Vector3} [up] */ lookAt(target: Vector3, up?: Vector3): void; fromJSON(json: any): void; toJSON(): { position: { x: number; y: number; z: number; }; rotation: { x: number; y: number; z: number; w: number; }; scale: { x: number; y: number; z: number; }; }; /** * * @param {Transform} other */ copy(other: Transform): void; /** * * @returns {Transform} */ clone(): Transform; /** * * @param {Transform} other * @returns {boolean} */ equals(other: Transform): boolean; /** * * @returns {number} */ hash(): number; /** * * @param {Transform} other * @returns {this} */ multiply(other: Transform): this; /** * Multiply two transforms, result it written into this one * @param {Transform} a * @param {Transform} b * @returns {this} */ multiplyTransforms(a: Transform, b: Transform): this; /** * * @param {mat4|number[]|Float32Array} matrix * @returns {this} */ fromMatrix4(matrix: mat4 | number[] | Float32Array): this; /** * Write out the current transform to a supplied container * @param {number[]|Float32Array} result */ toMatrix4(result: number[] | Float32Array): void; /** * reset transform, resulting transform is an identity matrix * - position: [0,0,0] * - rotation: [0,0,0,1] * - scale: [1,1,1] */ makeIdentity(): void; /** * Identity Transform is where position is 0, rotation is 0 (un-rotated) and scale is 1 * @returns {boolean} */ isIdentity(): boolean; toString(): string; /** * @readonly * @type {boolean} */ readonly isTransform: boolean; #private; } export namespace Transform { let typeName: string; } import Vector3 from "../../../core/geom/Vector3.js"; import Quaternion from "../../../core/geom/Quaternion.js"; import { TransformFlags } from "./TransformFlags.js"; //# sourceMappingURL=Transform.d.ts.map