added transforms
This commit is contained in:
parent
ee69c8de8c
commit
85a1798a3e
43
src/transform.h
Normal file
43
src/transform.h
Normal file
|
@ -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
|
Loading…
Reference in a new issue