fencer/core/src/transformable.h
2023-11-20 12:04:55 +01:00

38 lines
1.2 KiB
C

#ifndef _fencer_transformable_h
#define _fencer_transformable_h
#include "vmath.h"
#include "typeclass_helpers.h"
typedef struct {
struct Transform* (*const get_transform)(void* self);
} ITransformable;
typedef struct {
void* data;
ITransformable const* tc;
} Transformable;
extern Vector transformable_get_position(Transformable self);
extern void transformable_set_position(Transformable self, Vector position);
extern void transformable_move(Transformable self, Vector delta);
extern Vector transformable_get_scale(Transformable self);
extern void transformable_set_scale(Transformable self, Vector scale);
extern void transformable_scale(Transformable self, Vector factor);
extern float transformable_get_rotation(Transformable self);
extern void transformable_set_rotation(Transformable self, float rotation);
extern void transformable_rotate(Transformable self, float delta);
#define impl_Transformable_for(T, get_transform_f)\
static inline Transformable T##_as_Transformable(T* x) {\
TC_FN_TYPECHECK(Transform*, get_transform_f, T*);\
static ITransformable const tc = {\
.get_transform = (Transform*(*const)(void*)) get_transform_f\
};\
return (Transformable){.tc = &tc, .data = x};\
}
#endif // !_fencer_transformable_h