xform macros
This commit is contained in:
parent
650c5cd762
commit
2a7146c8c9
19
src/math.h
19
src/math.h
@ -459,6 +459,12 @@ INLINE struct mat4x4 mat4x4_mul(struct mat4x4 m1, struct mat4x4 m2)
|
|||||||
* Xform
|
* 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_translate(struct xform xf, struct v2 v);
|
||||||
INLINE struct xform xform_rotate(struct xform xf, f32 angle);
|
INLINE struct xform xform_rotate(struct xform xf, f32 angle);
|
||||||
INLINE struct xform xform_scale(struct xform xf, struct v2 v);
|
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_from_xform(struct xform m);
|
||||||
INLINE struct trs trs_lerp(struct trs a, struct trs b, f32 t);
|
INLINE struct trs trs_lerp(struct trs a, struct trs b, f32 t);
|
||||||
|
|
||||||
INLINE struct xform xform_ident(void)
|
INLINE struct xform xform_from_pos(struct v2 v)
|
||||||
{
|
|
||||||
return (struct xform) {
|
|
||||||
.bx = { 1, 0 },
|
|
||||||
.by = { 0, 1 },
|
|
||||||
.tl = { 0, 0 }
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
INLINE struct xform xform_from_translate(struct v2 v)
|
|
||||||
{
|
{
|
||||||
return (struct xform) {
|
return (struct xform) {
|
||||||
.bx = {1, 0},
|
.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)
|
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_rotate(m, trs.r);
|
||||||
m = xform_scale(m, trs.s);
|
m = xform_scale(m, trs.s);
|
||||||
return m;
|
return m;
|
||||||
|
|||||||
@ -220,7 +220,7 @@ INTERNAL struct xform view_get_xform(struct view view)
|
|||||||
);
|
);
|
||||||
|
|
||||||
struct v2 pivot = view.center;
|
struct v2 pivot = view.center;
|
||||||
struct xform res = xform_ident();
|
struct xform res = XFORM_IDENT;
|
||||||
res = xform_translate(res, pivot);
|
res = xform_translate(res, pivot);
|
||||||
res = xform_trs_pivot_rs(res, trs, pivot);
|
res = xform_trs_pivot_rs(res, trs, pivot);
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user