Path: blob/master/servers/extensions/physics_server_2d_extension.cpp
10277 views
/**************************************************************************/1/* physics_server_2d_extension.cpp */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#include "physics_server_2d_extension.h"3132bool PhysicsDirectSpaceState2DExtension::is_body_excluded_from_query(const RID &p_body) const {33return exclude && exclude->has(p_body);34}3536thread_local const HashSet<RID> *PhysicsDirectSpaceState2DExtension::exclude = nullptr;3738void PhysicsDirectSpaceState2DExtension::_bind_methods() {39ClassDB::bind_method(D_METHOD("is_body_excluded_from_query", "body"), &PhysicsDirectSpaceState2DExtension::is_body_excluded_from_query);4041GDVIRTUAL_BIND(_intersect_ray, "from", "to", "collision_mask", "collide_with_bodies", "collide_with_areas", "hit_from_inside", "result");42GDVIRTUAL_BIND(_intersect_point, "position", "canvas_instance_id", "collision_mask", "collide_with_bodies", "collide_with_areas", "results", "max_results");43GDVIRTUAL_BIND(_intersect_shape, "shape_rid", "transform", "motion", "margin", "collision_mask", "collide_with_bodies", "collide_with_areas", "result", "max_results");44GDVIRTUAL_BIND(_cast_motion, "shape_rid", "transform", "motion", "margin", "collision_mask", "collide_with_bodies", "collide_with_areas", "closest_safe", "closest_unsafe");45GDVIRTUAL_BIND(_collide_shape, "shape_rid", "transform", "motion", "margin", "collision_mask", "collide_with_bodies", "collide_with_areas", "results", "max_results", "result_count");46GDVIRTUAL_BIND(_rest_info, "shape_rid", "transform", "motion", "margin", "collision_mask", "collide_with_bodies", "collide_with_areas", "rest_info");47}4849PhysicsDirectSpaceState2DExtension::PhysicsDirectSpaceState2DExtension() {50}5152void PhysicsDirectBodyState2DExtension::_bind_methods() {53GDVIRTUAL_BIND(_get_total_gravity);54GDVIRTUAL_BIND(_get_total_linear_damp);55GDVIRTUAL_BIND(_get_total_angular_damp);5657GDVIRTUAL_BIND(_get_center_of_mass);58GDVIRTUAL_BIND(_get_center_of_mass_local);59GDVIRTUAL_BIND(_get_inverse_mass);60GDVIRTUAL_BIND(_get_inverse_inertia);6162GDVIRTUAL_BIND(_set_linear_velocity, "velocity");63GDVIRTUAL_BIND(_get_linear_velocity);6465GDVIRTUAL_BIND(_set_angular_velocity, "velocity");66GDVIRTUAL_BIND(_get_angular_velocity);6768GDVIRTUAL_BIND(_set_transform, "transform");69GDVIRTUAL_BIND(_get_transform);7071GDVIRTUAL_BIND(_get_velocity_at_local_position, "local_position");7273GDVIRTUAL_BIND(_apply_central_impulse, "impulse");74GDVIRTUAL_BIND(_apply_impulse, "impulse", "position");75GDVIRTUAL_BIND(_apply_torque_impulse, "impulse");7677GDVIRTUAL_BIND(_apply_central_force, "force");78GDVIRTUAL_BIND(_apply_force, "force", "position");79GDVIRTUAL_BIND(_apply_torque, "torque");8081GDVIRTUAL_BIND(_add_constant_central_force, "force");82GDVIRTUAL_BIND(_add_constant_force, "force", "position");83GDVIRTUAL_BIND(_add_constant_torque, "torque");8485GDVIRTUAL_BIND(_set_constant_force, "force");86GDVIRTUAL_BIND(_get_constant_force);8788GDVIRTUAL_BIND(_set_constant_torque, "torque");89GDVIRTUAL_BIND(_get_constant_torque);9091GDVIRTUAL_BIND(_set_sleep_state, "enabled");92GDVIRTUAL_BIND(_is_sleeping);9394GDVIRTUAL_BIND(_set_collision_layer, "layer");95GDVIRTUAL_BIND(_get_collision_layer);9697GDVIRTUAL_BIND(_set_collision_mask, "mask");98GDVIRTUAL_BIND(_get_collision_mask);99100GDVIRTUAL_BIND(_get_contact_count);101102GDVIRTUAL_BIND(_get_contact_local_position, "contact_idx");103GDVIRTUAL_BIND(_get_contact_local_normal, "contact_idx");104GDVIRTUAL_BIND(_get_contact_local_shape, "contact_idx");105GDVIRTUAL_BIND(_get_contact_local_velocity_at_position, "contact_idx");106GDVIRTUAL_BIND(_get_contact_collider, "contact_idx");107GDVIRTUAL_BIND(_get_contact_collider_position, "contact_idx");108GDVIRTUAL_BIND(_get_contact_collider_id, "contact_idx");109GDVIRTUAL_BIND(_get_contact_collider_object, "contact_idx");110GDVIRTUAL_BIND(_get_contact_collider_shape, "contact_idx");111GDVIRTUAL_BIND(_get_contact_collider_velocity_at_position, "contact_idx");112GDVIRTUAL_BIND(_get_contact_impulse, "contact_idx");113114GDVIRTUAL_BIND(_get_step);115GDVIRTUAL_BIND(_integrate_forces);116117GDVIRTUAL_BIND(_get_space_state);118}119120PhysicsDirectBodyState2DExtension::PhysicsDirectBodyState2DExtension() {121}122123thread_local const HashSet<RID> *PhysicsServer2DExtension::exclude_bodies = nullptr;124thread_local const HashSet<ObjectID> *PhysicsServer2DExtension::exclude_objects = nullptr;125126bool PhysicsServer2DExtension::body_test_motion_is_excluding_body(RID p_body) const {127return exclude_bodies && exclude_bodies->has(p_body);128}129130bool PhysicsServer2DExtension::body_test_motion_is_excluding_object(ObjectID p_object) const {131return exclude_objects && exclude_objects->has(p_object);132}133134void PhysicsServer2DExtension::_bind_methods() {135/* SHAPE API */136137GDVIRTUAL_BIND(_world_boundary_shape_create);138GDVIRTUAL_BIND(_separation_ray_shape_create);139GDVIRTUAL_BIND(_segment_shape_create);140GDVIRTUAL_BIND(_circle_shape_create);141GDVIRTUAL_BIND(_rectangle_shape_create);142GDVIRTUAL_BIND(_capsule_shape_create);143GDVIRTUAL_BIND(_convex_polygon_shape_create);144GDVIRTUAL_BIND(_concave_polygon_shape_create);145146GDVIRTUAL_BIND(_shape_set_data, "shape", "data");147GDVIRTUAL_BIND(_shape_set_custom_solver_bias, "shape", "bias");148149GDVIRTUAL_BIND(_shape_get_type, "shape");150GDVIRTUAL_BIND(_shape_get_data, "shape");151GDVIRTUAL_BIND(_shape_get_custom_solver_bias, "shape");152GDVIRTUAL_BIND(_shape_collide, "shape_A", "xform_A", "motion_A", "shape_B", "xform_B", "motion_B", "results", "result_max", "result_count");153154/* SPACE API */155156GDVIRTUAL_BIND(_space_create);157GDVIRTUAL_BIND(_space_set_active, "space", "active");158GDVIRTUAL_BIND(_space_is_active, "space");159160GDVIRTUAL_BIND(_space_set_param, "space", "param", "value");161GDVIRTUAL_BIND(_space_get_param, "space", "param");162163GDVIRTUAL_BIND(_space_get_direct_state, "space");164165GDVIRTUAL_BIND(_space_set_debug_contacts, "space", "max_contacts");166GDVIRTUAL_BIND(_space_get_contacts, "space");167GDVIRTUAL_BIND(_space_get_contact_count, "space");168169/* AREA API */170171GDVIRTUAL_BIND(_area_create);172173GDVIRTUAL_BIND(_area_set_space, "area", "space");174GDVIRTUAL_BIND(_area_get_space, "area");175176GDVIRTUAL_BIND(_area_add_shape, "area", "shape", "transform", "disabled");177GDVIRTUAL_BIND(_area_set_shape, "area", "shape_idx", "shape");178GDVIRTUAL_BIND(_area_set_shape_transform, "area", "shape_idx", "transform");179GDVIRTUAL_BIND(_area_set_shape_disabled, "area", "shape_idx", "disabled");180181GDVIRTUAL_BIND(_area_get_shape_count, "area");182GDVIRTUAL_BIND(_area_get_shape, "area", "shape_idx");183GDVIRTUAL_BIND(_area_get_shape_transform, "area", "shape_idx");184185GDVIRTUAL_BIND(_area_remove_shape, "area", "shape_idx");186GDVIRTUAL_BIND(_area_clear_shapes, "area");187188GDVIRTUAL_BIND(_area_attach_object_instance_id, "area", "id");189GDVIRTUAL_BIND(_area_get_object_instance_id, "area");190191GDVIRTUAL_BIND(_area_attach_canvas_instance_id, "area", "id");192GDVIRTUAL_BIND(_area_get_canvas_instance_id, "area");193194GDVIRTUAL_BIND(_area_set_param, "area", "param", "value");195GDVIRTUAL_BIND(_area_set_transform, "area", "transform");196197GDVIRTUAL_BIND(_area_get_param, "area", "param");198GDVIRTUAL_BIND(_area_get_transform, "area");199200GDVIRTUAL_BIND(_area_set_collision_layer, "area", "layer");201GDVIRTUAL_BIND(_area_get_collision_layer, "area");202203GDVIRTUAL_BIND(_area_set_collision_mask, "area", "mask");204GDVIRTUAL_BIND(_area_get_collision_mask, "area");205206GDVIRTUAL_BIND(_area_set_monitorable, "area", "monitorable");207GDVIRTUAL_BIND(_area_set_pickable, "area", "pickable");208209GDVIRTUAL_BIND(_area_set_monitor_callback, "area", "callback");210GDVIRTUAL_BIND(_area_set_area_monitor_callback, "area", "callback");211212/* BODY API */213214ClassDB::bind_method(D_METHOD("body_test_motion_is_excluding_body", "body"), &PhysicsServer2DExtension::body_test_motion_is_excluding_body);215ClassDB::bind_method(D_METHOD("body_test_motion_is_excluding_object", "object"), &PhysicsServer2DExtension::body_test_motion_is_excluding_object);216217GDVIRTUAL_BIND(_body_create);218219GDVIRTUAL_BIND(_body_set_space, "body", "space");220GDVIRTUAL_BIND(_body_get_space, "body");221222GDVIRTUAL_BIND(_body_set_mode, "body", "mode");223GDVIRTUAL_BIND(_body_get_mode, "body");224225GDVIRTUAL_BIND(_body_add_shape, "body", "shape", "transform", "disabled");226GDVIRTUAL_BIND(_body_set_shape, "body", "shape_idx", "shape");227GDVIRTUAL_BIND(_body_set_shape_transform, "body", "shape_idx", "transform");228229GDVIRTUAL_BIND(_body_get_shape_count, "body");230GDVIRTUAL_BIND(_body_get_shape, "body", "shape_idx");231GDVIRTUAL_BIND(_body_get_shape_transform, "body", "shape_idx");232233GDVIRTUAL_BIND(_body_set_shape_disabled, "body", "shape_idx", "disabled");234GDVIRTUAL_BIND(_body_set_shape_as_one_way_collision, "body", "shape_idx", "enable", "margin");235236GDVIRTUAL_BIND(_body_remove_shape, "body", "shape_idx");237GDVIRTUAL_BIND(_body_clear_shapes, "body");238239GDVIRTUAL_BIND(_body_attach_object_instance_id, "body", "id");240GDVIRTUAL_BIND(_body_get_object_instance_id, "body");241242GDVIRTUAL_BIND(_body_attach_canvas_instance_id, "body", "id");243GDVIRTUAL_BIND(_body_get_canvas_instance_id, "body");244245GDVIRTUAL_BIND(_body_set_continuous_collision_detection_mode, "body", "mode");246GDVIRTUAL_BIND(_body_get_continuous_collision_detection_mode, "body");247248GDVIRTUAL_BIND(_body_set_collision_layer, "body", "layer");249GDVIRTUAL_BIND(_body_get_collision_layer, "body");250251GDVIRTUAL_BIND(_body_set_collision_mask, "body", "mask");252GDVIRTUAL_BIND(_body_get_collision_mask, "body");253254GDVIRTUAL_BIND(_body_set_collision_priority, "body", "priority");255GDVIRTUAL_BIND(_body_get_collision_priority, "body");256257GDVIRTUAL_BIND(_body_set_param, "body", "param", "value");258GDVIRTUAL_BIND(_body_get_param, "body", "param");259260GDVIRTUAL_BIND(_body_reset_mass_properties, "body");261262GDVIRTUAL_BIND(_body_set_state, "body", "state", "value");263GDVIRTUAL_BIND(_body_get_state, "body", "state");264265GDVIRTUAL_BIND(_body_apply_central_impulse, "body", "impulse");266GDVIRTUAL_BIND(_body_apply_torque_impulse, "body", "impulse");267GDVIRTUAL_BIND(_body_apply_impulse, "body", "impulse", "position");268269GDVIRTUAL_BIND(_body_apply_central_force, "body", "force");270GDVIRTUAL_BIND(_body_apply_force, "body", "force", "position");271GDVIRTUAL_BIND(_body_apply_torque, "body", "torque");272273GDVIRTUAL_BIND(_body_add_constant_central_force, "body", "force");274GDVIRTUAL_BIND(_body_add_constant_force, "body", "force", "position");275GDVIRTUAL_BIND(_body_add_constant_torque, "body", "torque");276277GDVIRTUAL_BIND(_body_set_constant_force, "body", "force");278GDVIRTUAL_BIND(_body_get_constant_force, "body");279280GDVIRTUAL_BIND(_body_set_constant_torque, "body", "torque");281GDVIRTUAL_BIND(_body_get_constant_torque, "body");282283GDVIRTUAL_BIND(_body_set_axis_velocity, "body", "axis_velocity");284285GDVIRTUAL_BIND(_body_add_collision_exception, "body", "excepted_body");286GDVIRTUAL_BIND(_body_remove_collision_exception, "body", "excepted_body");287GDVIRTUAL_BIND(_body_get_collision_exceptions, "body");288289GDVIRTUAL_BIND(_body_set_max_contacts_reported, "body", "amount");290GDVIRTUAL_BIND(_body_get_max_contacts_reported, "body");291292GDVIRTUAL_BIND(_body_set_contacts_reported_depth_threshold, "body", "threshold");293GDVIRTUAL_BIND(_body_get_contacts_reported_depth_threshold, "body");294295GDVIRTUAL_BIND(_body_set_omit_force_integration, "body", "enable");296GDVIRTUAL_BIND(_body_is_omitting_force_integration, "body");297298GDVIRTUAL_BIND(_body_set_state_sync_callback, "body", "callable");299GDVIRTUAL_BIND(_body_set_force_integration_callback, "body", "callable", "userdata");300301GDVIRTUAL_BIND(_body_collide_shape, "body", "body_shape", "shape", "shape_xform", "motion", "results", "result_max", "result_count");302303GDVIRTUAL_BIND(_body_set_pickable, "body", "pickable");304305GDVIRTUAL_BIND(_body_get_direct_state, "body");306307GDVIRTUAL_BIND(_body_test_motion, "body", "from", "motion", "margin", "collide_separation_ray", "recovery_as_collision", "result");308309/* JOINT API */310311GDVIRTUAL_BIND(_joint_create);312GDVIRTUAL_BIND(_joint_clear, "joint");313314GDVIRTUAL_BIND(_joint_set_param, "joint", "param", "value");315GDVIRTUAL_BIND(_joint_get_param, "joint", "param");316317GDVIRTUAL_BIND(_joint_disable_collisions_between_bodies, "joint", "disable");318GDVIRTUAL_BIND(_joint_is_disabled_collisions_between_bodies, "joint");319320GDVIRTUAL_BIND(_joint_make_pin, "joint", "anchor", "body_a", "body_b");321GDVIRTUAL_BIND(_joint_make_groove, "joint", "a_groove1", "a_groove2", "b_anchor", "body_a", "body_b");322GDVIRTUAL_BIND(_joint_make_damped_spring, "joint", "anchor_a", "anchor_b", "body_a", "body_b");323324GDVIRTUAL_BIND(_pin_joint_set_flag, "joint", "flag", "enabled");325GDVIRTUAL_BIND(_pin_joint_get_flag, "joint", "flag");326327GDVIRTUAL_BIND(_pin_joint_set_param, "joint", "param", "value");328GDVIRTUAL_BIND(_pin_joint_get_param, "joint", "param");329330GDVIRTUAL_BIND(_damped_spring_joint_set_param, "joint", "param", "value");331GDVIRTUAL_BIND(_damped_spring_joint_get_param, "joint", "param");332333GDVIRTUAL_BIND(_joint_get_type, "joint");334335/* MISC */336337GDVIRTUAL_BIND(_free_rid, "rid");338339GDVIRTUAL_BIND(_set_active, "active");340341GDVIRTUAL_BIND(_init);342GDVIRTUAL_BIND(_step, "step");343GDVIRTUAL_BIND(_sync);344GDVIRTUAL_BIND(_flush_queries);345GDVIRTUAL_BIND(_end_sync);346GDVIRTUAL_BIND(_finish);347348GDVIRTUAL_BIND(_is_flushing_queries);349GDVIRTUAL_BIND(_get_process_info, "process_info");350}351352PhysicsServer2DExtension::PhysicsServer2DExtension() {353}354355PhysicsServer2DExtension::~PhysicsServer2DExtension() {356}357358359