diff --git a/src/math.h b/src/math.h index 649bfa34..252ec2a3 100644 --- a/src/math.h +++ b/src/math.h @@ -459,6 +459,12 @@ INLINE struct mat4x4 mat4x4_mul(struct mat4x4 m1, struct mat4x4 m2) * Xform * ========================== */ +/* Construct identity xform */ +#define XFORM_IDENT ((struct xform) { .bx.x = 1, .by.y = 1 }) + +/* Takes a translation, rotation, and scale as optional parameters for constructing an xform */ +#define XFORM_TRS(...) xform_from_trs((struct trs) { .t = V2(0,0), .s = V2(1, 1), .r = 0, __VA_ARGS__ }) + INLINE struct xform xform_translate(struct xform xf, struct v2 v); INLINE struct xform xform_rotate(struct xform xf, f32 angle); INLINE struct xform xform_scale(struct xform xf, struct v2 v); @@ -468,16 +474,7 @@ INLINE f32 xform_get_determinant(struct xform xf); INLINE struct trs trs_from_xform(struct xform m); INLINE struct trs trs_lerp(struct trs a, struct trs b, f32 t); -INLINE struct xform xform_ident(void) -{ - return (struct xform) { - .bx = { 1, 0 }, - .by = { 0, 1 }, - .tl = { 0, 0 } - }; -} - -INLINE struct xform xform_from_translate(struct v2 v) +INLINE struct xform xform_from_pos(struct v2 v) { return (struct xform) { .bx = {1, 0}, @@ -488,7 +485,7 @@ INLINE struct xform xform_from_translate(struct v2 v) INLINE struct xform xform_from_trs(struct trs trs) { - struct xform m = xform_from_translate(trs.t); + struct xform m = xform_from_pos(trs.t); m = xform_rotate(m, trs.r); m = xform_scale(m, trs.s); return m; diff --git a/src/user.c b/src/user.c index de7dafbf..bc5ce29c 100644 --- a/src/user.c +++ b/src/user.c @@ -220,7 +220,7 @@ INTERNAL struct xform view_get_xform(struct view view) ); struct v2 pivot = view.center; - struct xform res = xform_ident(); + struct xform res = XFORM_IDENT; res = xform_translate(res, pivot); res = xform_trs_pivot_rs(res, trs, pivot);