fencer/src/transformable.h

34 lines
1.1 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);
Vector* (*const get_position)(void* self);
Vector* (*const get_scale)(void* self);
float* (*const get_rotation)(void* self);
} ITransformable;
typedef struct {
void* self;
ITransformable const* tc;
} Transformable;
#define impl_Transformable_for(T, get_transform_f, get_position_f, get_scale_f, get_rotation_f)\
static inline Transformable T##_as_Transformable(T* x) {\
TC_FN_TYPECHECK(Transform*, get_transform_f, T* e);\
TC_FN_TYPECHECK(Vector*, get_position_f, T* e);\
TC_FN_TYPECHECK(float*, get_rotation_f, T* e);\
static ITransformable const tc = {\
.get_transform = (Transform*(*const)(void*)) get_transform_f,\
.get_position = (Vector*(*const)(void*)) get_position_f,\
.get_scale = (Vector*(*const)(void*)) get_scale_f,\
.get_rotation = (float*(*const)(void*)) get_rotation_f\
};\
return (Transformable){.tc = &tc, .self = x };\
}
#endif // !_fencer_transformable_h