summaryrefslogtreecommitdiff
path: root/scene/2d
diff options
context:
space:
mode:
authorPouleyKetchoupp <pouleyketchoup@gmail.com>2021-11-01 18:00:58 -0700
committerPouleyKetchoupp <pouleyketchoup@gmail.com>2021-11-04 11:44:39 -0700
commitacbd24ea842cb90ab49cd66d5dc7220e57c73f29 (patch)
tree9ae32f04a7f744f7c58a19a1b9679f49589053cb /scene/2d
parent25bea735449d4e762e3c5f6b960d5f5b9cf79ac1 (diff)
Use parameter classes instead of arguments for all physics queries
Same as what is already done for shape queries, applied to point and ray queries. Easier to document and more flexible to add more parameters. Also expose intersect_point method to script in 3D. Remove intersect_point_on_canvas in 2D, replaced with a parameter.
Diffstat (limited to 'scene/2d')
-rw-r--r--scene/2d/audio_stream_player_2d.cpp8
-rw-r--r--scene/2d/ray_cast_2d.cpp11
2 files changed, 17 insertions, 2 deletions
diff --git a/scene/2d/audio_stream_player_2d.cpp b/scene/2d/audio_stream_player_2d.cpp
index f73d52152e..24da2ce9ce 100644
--- a/scene/2d/audio_stream_player_2d.cpp
+++ b/scene/2d/audio_stream_player_2d.cpp
@@ -112,7 +112,13 @@ StringName AudioStreamPlayer2D::_get_actual_bus() {
PhysicsDirectSpaceState2D *space_state = PhysicsServer2D::get_singleton()->space_get_direct_state(world_2d->get_space());
PhysicsDirectSpaceState2D::ShapeResult sr[MAX_INTERSECT_AREAS];
- int areas = space_state->intersect_point(global_pos, sr, MAX_INTERSECT_AREAS, Set<RID>(), area_mask, false, true);
+ PhysicsDirectSpaceState2D::PointParameters point_params;
+ point_params.position = global_pos;
+ point_params.collision_mask = area_mask;
+ point_params.collide_with_bodies = false;
+ point_params.collide_with_areas = true;
+
+ int areas = space_state->intersect_point(point_params, sr, MAX_INTERSECT_AREAS);
for (int i = 0; i < areas; i++) {
Area2D *area2d = Object::cast_to<Area2D>(sr[i].collider);
diff --git a/scene/2d/ray_cast_2d.cpp b/scene/2d/ray_cast_2d.cpp
index 0a8e9e2a58..7af91f3a8d 100644
--- a/scene/2d/ray_cast_2d.cpp
+++ b/scene/2d/ray_cast_2d.cpp
@@ -192,7 +192,16 @@ void RayCast2D::_update_raycast_state() {
PhysicsDirectSpaceState2D::RayResult rr;
bool prev_collision_state = collided;
- if (dss->intersect_ray(gt.get_origin(), gt.xform(to), rr, exclude, collision_mask, collide_with_bodies, collide_with_areas)) {
+
+ PhysicsDirectSpaceState2D::RayParameters ray_params;
+ ray_params.from = gt.get_origin();
+ ray_params.to = gt.xform(to);
+ ray_params.exclude = exclude;
+ ray_params.collision_mask = collision_mask;
+ ray_params.collide_with_bodies = collide_with_bodies;
+ ray_params.collide_with_areas = collide_with_areas;
+
+ if (dss->intersect_ray(ray_params, rr)) {
collided = true;
against = rr.collider_id;
collision_point = rr.position;