feat: added query_all functions for physics world
This commit is contained in:
parent
1fb0aedac2
commit
2f9cd32f6c
|
@ -113,6 +113,40 @@ void physics_world_tick() {
|
|||
_internal_physics_apply();
|
||||
}
|
||||
|
||||
List physics_world_query_all(PhysicsQuery query, RigidBody* ignore) {
|
||||
List result = list_init(sizeof(Collider*));
|
||||
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))
|
||||
list_add(&result, *collider);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
List physics_world_box_query_all(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_all(query, ignore);
|
||||
}
|
||||
|
||||
Collider* physics_world_query(PhysicsQuery query, RigidBody* ignore) {
|
||||
list_foreach(PhysicsEntity*, entity, &_world_bodies) {
|
||||
RigidBody* body = entity->tc->get_rigidbody(entity->data);
|
||||
|
@ -123,7 +157,6 @@ Collider* physics_world_query(PhysicsQuery query, RigidBody* ignore) {
|
|||
return *collider;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
|
@ -12,6 +12,8 @@ extern void physics_world_remove_entity(PhysicsEntity entity);
|
|||
|
||||
extern void physics_world_tick();
|
||||
|
||||
extern List physics_world_query_all(PhysicsQuery query, RigidBody* ignore);
|
||||
extern List physics_world_box_query_all(Vector centre, Vector extents, PhysicsMask mask, RigidBody* ignore);
|
||||
extern Collider* physics_world_query(PhysicsQuery query, RigidBody* ignore);
|
||||
extern Collider* physics_world_box_query(Vector centre, Vector extents, PhysicsMask mask, RigidBody* ignore);
|
||||
|
||||
|
|
Loading…
Reference in a new issue