diff --git a/src/transform.h b/src/transform.h new file mode 100644 index 0000000..1fd8b6b --- /dev/null +++ b/src/transform.h @@ -0,0 +1,43 @@ +#ifndef _fencer_transform_h +#define _fencer_transform_h + +#include "vmath.h" + +typedef struct Transform Transform; +struct Transform { + Vector position; + Vector scale; + float rotation; +}; + +#define IdentityTransform (Transform){ZeroVector, OneVector, 0.0f} + +static inline +Transform transform_apply(Transform a, Transform b) { + return (Transform) { + .position = vaddf(a.position, b.position), + .scale = vmulf(a.scale, b.scale), + .rotation = a.rotation + b.rotation + }; +} + +static inline +Transform transform_invert(Transform a) { + return (Transform) { + .position = vinvf(a.position), + .scale = vreciprocalf(a.scale), + .rotation = -a.rotation + }; +} + +static inline +Vector transform_direction(Transform* self, Vector direction) { + return vmulf(vrotatef(direction, self->rotation), self->scale); +} + +static inline +Vector transform_point(Transform* self, Vector position) { + return vaddf(transform_direction(self, position), self->position); +} + +#endif // !_fencer_transform_h