feat: added physics world queries
This commit is contained in:
parent
92907b1b82
commit
e0a05e546e
|
@ -30,17 +30,6 @@ void physics_world_remove_entity(PhysicsEntity entity) {
|
||||||
ASSERT_RETURN(0,, "Physics entity with data at %p is not registered in physics world", entity.data);
|
ASSERT_RETURN(0,, "Physics entity with data at %p is not registered in physics world", entity.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
Collider* physics_world_query(PhysicsQuery query) {
|
|
||||||
list_foreach(RigidBody**, body, &_world_bodies) {
|
|
||||||
list_foreach(Collider**, collider, rigidbody_get_colliders(*body)) {
|
|
||||||
if(overlap_check(query, *collider))
|
|
||||||
return *collider;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline
|
static inline
|
||||||
void _internal_physics_check_entities(PhysicsEntity left, PhysicsEntity right) {
|
void _internal_physics_check_entities(PhysicsEntity left, PhysicsEntity right) {
|
||||||
RigidBody* rbleft = left.tc->get_rigidbody(left.data);
|
RigidBody* rbleft = left.tc->get_rigidbody(left.data);
|
||||||
|
@ -99,3 +88,37 @@ void physics_world_tick() {
|
||||||
_internal_physics_narrow_collision();
|
_internal_physics_narrow_collision();
|
||||||
_internal_physics_apply();
|
_internal_physics_apply();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Collider* physics_world_query(PhysicsQuery query, RigidBody* ignore) {
|
||||||
|
list_foreach(PhysicsEntity*, entity, &_world_bodies) {
|
||||||
|
RigidBody* body = entity->tc->get_rigidbody(entity->data);
|
||||||
|
if(body == ignore) continue;
|
||||||
|
|
||||||
|
list_foreach(Collider**, collider, rigidbody_get_colliders(body)) {
|
||||||
|
if(overlap_check(query, *collider))
|
||||||
|
return *collider;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
Collider* physics_world_box_query(Vector centre, Vector extents, PhysicsMask mask, RigidBody* ignore) {
|
||||||
|
Transform transform = {
|
||||||
|
.position = centre,
|
||||||
|
.scale = OneVector,
|
||||||
|
.rotation = 0.f
|
||||||
|
};
|
||||||
|
Shape* shape = shape_new((Vector[]){
|
||||||
|
MakeVector(-extents.x, -extents.y),
|
||||||
|
MakeVector(extents.x, -extents.y),
|
||||||
|
MakeVector(extents.x, extents.y),
|
||||||
|
MakeVector(-extents.x, extents.y)
|
||||||
|
}, 4);
|
||||||
|
PhysicsQuery query = {
|
||||||
|
.shape = shape,
|
||||||
|
.transform = &transform,
|
||||||
|
.mask = mask
|
||||||
|
};
|
||||||
|
return physics_world_query(query, ignore);
|
||||||
|
}
|
||||||
|
|
|
@ -10,8 +10,9 @@ extern void physics_world_clean();
|
||||||
extern void physics_world_add_entity(PhysicsEntity entity);
|
extern void physics_world_add_entity(PhysicsEntity entity);
|
||||||
extern void physics_world_remove_entity(PhysicsEntity entity);
|
extern void physics_world_remove_entity(PhysicsEntity entity);
|
||||||
|
|
||||||
extern Collider* physics_world_query(PhysicsQuery query);
|
|
||||||
|
|
||||||
extern void physics_world_tick();
|
extern void physics_world_tick();
|
||||||
|
|
||||||
|
extern Collider* physics_world_query(PhysicsQuery query, RigidBody* ignore);
|
||||||
|
extern Collider* physics_world_box_query(Vector centre, Vector extents, PhysicsMask mask, RigidBody* ignore);
|
||||||
|
|
||||||
#endif // !_fencer_physics_world_h
|
#endif // !_fencer_physics_world_h
|
||||||
|
|
Loading…
Reference in a new issue