# transform

A hierarchical transform storing 3D or 2D position, rotation (as a quaternion),
and scale. Can have a parent transform. Freed automatically on GC.


### pos <sub>accessor</sub>

Get or set the transform's position as a 3D vector [x, y, z].



**value**: (when setting) [x, y, z].


**Returns**: The current position vector (when getting), or None (when setting).


### scale <sub>accessor</sub>

Get or set the transform's scale as a 3D vector [x, y, z].
For 2D usage, z is often 1.



**value**: (when setting) [sx, sy, sz].


**Returns**: The current scale (when getting), or None (when setting).


### rotation <sub>accessor</sub>

Get or set the transform's rotation as a quaternion [x, y, z, w].
Angles in degrees or radians must first be converted prior to making a quaternion.



**value**: (when setting) [qx, qy, qz, qw].


**Returns**: The current quaternion (when getting), or None (when setting).


### parent <sub>accessor</sub>

Get or set the transform's parent. If set, this transform becomes a child of
the parent (re-parenting). Must be another transform object or undefined.



**value**: (when setting) Another transform or undefined.


**Returns**: The current parent transform (when getting), or None (when setting).


### change_hook <sub>accessor</sub>

A user-supplied function that's called whenever the transform's local matrix changes.
If undefined, no hook is called.



**value**: (when setting) A function.


**Returns**: The current function or undefined.


### trs(pos, quat, scale) <sub>function</sub>

Set the transform's position, rotation, and scale in one call.



**pos**: [x,y,z] for position, or undefined to keep existing.

**quat**: [qx,qy,qz,qw] for rotation, or undefined.

**scale**: [sx,sy,sz] for scale, or undefined.


**Returns**: None


### phys2d(velocity, angularVel, dt) <sub>function</sub>

Apply simple 2D velocity and angular velocity to this transform.



**velocity**: [vx, vy] added to 'pos' each frame.

**angularVel**: A scalar for rotation in (radians/second).

**dt**: The time delta in seconds.


**Returns**: None


### move(delta) <sub>function</sub>

Translate this transform by the specified vector.



**delta**: [dx, dy, dz] to add to .pos


**Returns**: None


### rotate(axis, angle) <sub>function</sub>

Rotate this transform by an axis+angle.



**axis**: [ax, ay, az] the axis of rotation.

**angle**: The angle in turns or radians (depending on usage).


**Returns**: None


### angle(axis) <sub>function</sub>

Return the transform's rotation about a specified axis (x, y, or z).
For example, angle([1,0,0]) returns the roll about the X-axis.



**axis**: Which axis [1,0,0] or [0,1,0] or [0,0,1].


**Returns**: The numeric angle in 'turns' or radians, depending on usage.


### lookat(target) <sub>function</sub>

Rotate this transform so it looks toward the given world position.



**target**: [x, y, z] position in world coords.


**Returns**: None


### direction(localDir) <sub>function</sub>

Rotate a vector by this transform's rotation, effectively "transforming"
a direction from local space to world space.



**localDir**: [dx, dy, dz] in local transform coordinates.


**Returns**: [dx', dy', dz'] direction in world space.


### unit() <sub>function</sub>

Reset position, rotation, and scale to [0,0,0], identity rotation, and [1,1,1].



**Returns**: None


### rect(rect) <sub>function</sub>

Set this transform's pos and scale from a 2D rect object {x, y, w, h}.



**rect**: Object with .x, .y, .w, .h


**Returns**: None


### array() <sub>function</sub>

Return this transform's matrix as a 16-element float array in column-major order.



**Returns**: An array of 16 floats.


### torect() <sub>function</sub>

Convert transform's 2D position/scale to a rect {x, y, w, h}.
Rotation is currently ignored.



**Returns**: A rect object {x, y, w, h}.


### children() <sub>function</sub>

Return an array of child transforms belonging to this transform.



**Returns**: An array of transform objects.

