added PhysicsEntity trait describing an object containing a rigidbody, shape and transform
This commit is contained in:
parent
32c8b93d40
commit
39625789e2
33
src/physics_entity.h
Normal file
33
src/physics_entity.h
Normal file
|
@ -0,0 +1,33 @@
|
|||
#ifndef _fencer_collidable_h
|
||||
#define _fencer_collidable_h
|
||||
|
||||
#include "vmath.h"
|
||||
#include "typeclass_helpers.h"
|
||||
|
||||
#include "rigidbody.h"
|
||||
#include "shape.h"
|
||||
|
||||
typedef struct {
|
||||
RigidBody* (*const get_rigidbody)(void* self);
|
||||
Shape* (*const get_shape)(void* self);
|
||||
Transformable (*const as_transformable)(void* self);
|
||||
} IPhysicsEntity;
|
||||
|
||||
typedef struct {
|
||||
void* self;
|
||||
IPhysicsEntity const* tc;
|
||||
} PhysicsEntity;
|
||||
|
||||
#define impl_PhysicsEntity_for(T, get_rigidbody_f, get_shape_f)\
|
||||
static inline PhysicsEntity T##_as_PhysicsEntity(T* x) {\
|
||||
TC_FN_TYPECHECK(RigidBody*, get_rigidbody_f, T* e);\
|
||||
TC_FN_TYPECHECK(Shape*, get_shape_f, T* e);\
|
||||
static IPhysicsEntity const tc = {\
|
||||
.get_rigidbody = (RigidBody*(*const)(void*)) get_transform_f,\
|
||||
.get_shape = (Shape*(*const)(void*)) get_shape_f,\
|
||||
.as_transformable = T##_as_Transformable\
|
||||
};\
|
||||
return (PhysicsEntity){.tc = &interface, .self = x};\
|
||||
}
|
||||
|
||||
#endif // !_fencer_collidable_h
|
Loading…
Reference in a new issue