Rename LineShape2D to WorldMarginShape2D
The new name makes it more obvious that it acts as an infinite plane, and is consistent with its 3D counterpart (WorldMarginShape3D).
This commit is contained in:
parent
3a48474c49
commit
8e3f71d750
19 changed files with 82 additions and 81 deletions
|
@ -716,11 +716,6 @@
|
||||||
Sets a joint parameter. See [enum JointParam] for a list of available parameters.
|
Sets a joint parameter. See [enum JointParam] for a list of available parameters.
|
||||||
</description>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
<method name="line_shape_create">
|
|
||||||
<return type="RID" />
|
|
||||||
<description>
|
|
||||||
</description>
|
|
||||||
</method>
|
|
||||||
<method name="rectangle_shape_create">
|
<method name="rectangle_shape_create">
|
||||||
<return type="RID" />
|
<return type="RID" />
|
||||||
<description>
|
<description>
|
||||||
|
@ -812,6 +807,11 @@
|
||||||
Sets the value for a space parameter. See [enum SpaceParameter] for a list of available parameters.
|
Sets the value for a space parameter. See [enum SpaceParameter] for a list of available parameters.
|
||||||
</description>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
|
<method name="world_margin_shape_create">
|
||||||
|
<return type="RID" />
|
||||||
|
<description>
|
||||||
|
</description>
|
||||||
|
</method>
|
||||||
</methods>
|
</methods>
|
||||||
<constants>
|
<constants>
|
||||||
<constant name="SPACE_PARAM_CONTACT_RECYCLE_RADIUS" value="0" enum="SpaceParameter">
|
<constant name="SPACE_PARAM_CONTACT_RECYCLE_RADIUS" value="0" enum="SpaceParameter">
|
||||||
|
@ -837,11 +837,11 @@
|
||||||
</constant>
|
</constant>
|
||||||
<constant name="SPACE_PARAM_TEST_MOTION_MIN_CONTACT_DEPTH" value="7" enum="SpaceParameter">
|
<constant name="SPACE_PARAM_TEST_MOTION_MIN_CONTACT_DEPTH" value="7" enum="SpaceParameter">
|
||||||
</constant>
|
</constant>
|
||||||
<constant name="SHAPE_LINE" value="0" enum="ShapeType">
|
<constant name="SHAPE_WORLD_MARGIN" value="0" enum="ShapeType">
|
||||||
This is the constant for creating line shapes. A line shape is an infinite line with an origin point, and a normal. Thus, it can be used for front/behind checks.
|
This is the constant for creating world margin shapes. A world margin shape is an [i]infinite[/i] line with an origin point, and a normal. Thus, it can be used for front/behind checks.
|
||||||
</constant>
|
</constant>
|
||||||
<constant name="SHAPE_SEGMENT" value="1" enum="ShapeType">
|
<constant name="SHAPE_SEGMENT" value="1" enum="ShapeType">
|
||||||
This is the constant for creating segment shapes. A segment shape is a line from a point A to a point B. It can be checked for intersections.
|
This is the constant for creating segment shapes. A segment shape is a [i]finite[/i] line from a point A to a point B. It can be checked for intersections.
|
||||||
</constant>
|
</constant>
|
||||||
<constant name="SHAPE_CIRCLE" value="2" enum="ShapeType">
|
<constant name="SHAPE_CIRCLE" value="2" enum="ShapeType">
|
||||||
This is the constant for creating circle shapes. A circle shape only has a radius. It can be used for intersections and inside/outside checks.
|
This is the constant for creating circle shapes. A circle shape only has a radius. It can be used for intersections and inside/outside checks.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
<class name="LineShape2D" inherits="Shape2D" version="4.0">
|
<class name="WorldMarginShape2D" inherits="Shape2D" version="4.0">
|
||||||
<brief_description>
|
<brief_description>
|
||||||
Line shape for 2D collisions.
|
Line shape for 2D collisions.
|
||||||
</brief_description>
|
</brief_description>
|
Before Width: | Height: | Size: 392 B After Width: | Height: | Size: 392 B |
|
@ -36,9 +36,9 @@
|
||||||
#include "scene/resources/circle_shape_2d.h"
|
#include "scene/resources/circle_shape_2d.h"
|
||||||
#include "scene/resources/concave_polygon_shape_2d.h"
|
#include "scene/resources/concave_polygon_shape_2d.h"
|
||||||
#include "scene/resources/convex_polygon_shape_2d.h"
|
#include "scene/resources/convex_polygon_shape_2d.h"
|
||||||
#include "scene/resources/line_shape_2d.h"
|
|
||||||
#include "scene/resources/rectangle_shape_2d.h"
|
#include "scene/resources/rectangle_shape_2d.h"
|
||||||
#include "scene/resources/segment_shape_2d.h"
|
#include "scene/resources/segment_shape_2d.h"
|
||||||
|
#include "scene/resources/world_margin_shape_2d.h"
|
||||||
|
|
||||||
void CollisionShape2DEditor::_node_removed(Node *p_node) {
|
void CollisionShape2DEditor::_node_removed(Node *p_node) {
|
||||||
if (p_node == node) {
|
if (p_node == node) {
|
||||||
|
@ -74,8 +74,8 @@ Variant CollisionShape2DEditor::get_handle_value(int idx) const {
|
||||||
case CONVEX_POLYGON_SHAPE: {
|
case CONVEX_POLYGON_SHAPE: {
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case LINE_SHAPE: {
|
case WORLD_MARGIN_SHAPE: {
|
||||||
Ref<LineShape2D> line = node->get_shape();
|
Ref<WorldMarginShape2D> line = node->get_shape();
|
||||||
|
|
||||||
if (idx == 0) {
|
if (idx == 0) {
|
||||||
return line->get_distance();
|
return line->get_distance();
|
||||||
|
@ -142,9 +142,9 @@ void CollisionShape2DEditor::set_handle(int idx, Point2 &p_point) {
|
||||||
case CONVEX_POLYGON_SHAPE: {
|
case CONVEX_POLYGON_SHAPE: {
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case LINE_SHAPE: {
|
case WORLD_MARGIN_SHAPE: {
|
||||||
if (idx < 2) {
|
if (idx < 2) {
|
||||||
Ref<LineShape2D> line = node->get_shape();
|
Ref<WorldMarginShape2D> line = node->get_shape();
|
||||||
|
|
||||||
if (idx == 0) {
|
if (idx == 0) {
|
||||||
line->set_distance(p_point.length());
|
line->set_distance(p_point.length());
|
||||||
|
@ -241,8 +241,8 @@ void CollisionShape2DEditor::commit_handle(int idx, Variant &p_org) {
|
||||||
// Cannot be edited directly, use CollisionPolygon2D instead.
|
// Cannot be edited directly, use CollisionPolygon2D instead.
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case LINE_SHAPE: {
|
case WORLD_MARGIN_SHAPE: {
|
||||||
Ref<LineShape2D> line = node->get_shape();
|
Ref<WorldMarginShape2D> line = node->get_shape();
|
||||||
|
|
||||||
if (idx == 0) {
|
if (idx == 0) {
|
||||||
undo_redo->add_do_method(line.ptr(), "set_distance", line->get_distance());
|
undo_redo->add_do_method(line.ptr(), "set_distance", line->get_distance());
|
||||||
|
@ -397,8 +397,8 @@ void CollisionShape2DEditor::_get_current_shape_type() {
|
||||||
shape_type = CONCAVE_POLYGON_SHAPE;
|
shape_type = CONCAVE_POLYGON_SHAPE;
|
||||||
} else if (Object::cast_to<ConvexPolygonShape2D>(*s)) {
|
} else if (Object::cast_to<ConvexPolygonShape2D>(*s)) {
|
||||||
shape_type = CONVEX_POLYGON_SHAPE;
|
shape_type = CONVEX_POLYGON_SHAPE;
|
||||||
} else if (Object::cast_to<LineShape2D>(*s)) {
|
} else if (Object::cast_to<WorldMarginShape2D>(*s)) {
|
||||||
shape_type = LINE_SHAPE;
|
shape_type = WORLD_MARGIN_SHAPE;
|
||||||
} else if (Object::cast_to<RectangleShape2D>(*s)) {
|
} else if (Object::cast_to<RectangleShape2D>(*s)) {
|
||||||
shape_type = RECTANGLE_SHAPE;
|
shape_type = RECTANGLE_SHAPE;
|
||||||
} else if (Object::cast_to<SegmentShape2D>(*s)) {
|
} else if (Object::cast_to<SegmentShape2D>(*s)) {
|
||||||
|
@ -464,8 +464,8 @@ void CollisionShape2DEditor::forward_canvas_draw_over_viewport(Control *p_overla
|
||||||
case CONVEX_POLYGON_SHAPE: {
|
case CONVEX_POLYGON_SHAPE: {
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case LINE_SHAPE: {
|
case WORLD_MARGIN_SHAPE: {
|
||||||
Ref<LineShape2D> shape = node->get_shape();
|
Ref<WorldMarginShape2D> shape = node->get_shape();
|
||||||
|
|
||||||
handles.resize(2);
|
handles.resize(2);
|
||||||
handles.write[0] = shape->get_normal() * shape->get_distance();
|
handles.write[0] = shape->get_normal() * shape->get_distance();
|
||||||
|
|
|
@ -46,7 +46,7 @@ class CollisionShape2DEditor : public Control {
|
||||||
CIRCLE_SHAPE,
|
CIRCLE_SHAPE,
|
||||||
CONCAVE_POLYGON_SHAPE,
|
CONCAVE_POLYGON_SHAPE,
|
||||||
CONVEX_POLYGON_SHAPE,
|
CONVEX_POLYGON_SHAPE,
|
||||||
LINE_SHAPE,
|
WORLD_MARGIN_SHAPE,
|
||||||
RECTANGLE_SHAPE,
|
RECTANGLE_SHAPE,
|
||||||
SEGMENT_SHAPE
|
SEGMENT_SHAPE
|
||||||
};
|
};
|
||||||
|
|
|
@ -148,7 +148,6 @@
|
||||||
#include "scene/resources/gradient.h"
|
#include "scene/resources/gradient.h"
|
||||||
#include "scene/resources/height_map_shape_3d.h"
|
#include "scene/resources/height_map_shape_3d.h"
|
||||||
#include "scene/resources/immediate_mesh.h"
|
#include "scene/resources/immediate_mesh.h"
|
||||||
#include "scene/resources/line_shape_2d.h"
|
|
||||||
#include "scene/resources/material.h"
|
#include "scene/resources/material.h"
|
||||||
#include "scene/resources/mesh.h"
|
#include "scene/resources/mesh.h"
|
||||||
#include "scene/resources/mesh_data_tool.h"
|
#include "scene/resources/mesh_data_tool.h"
|
||||||
|
@ -187,6 +186,7 @@
|
||||||
#include "scene/resources/visual_shader_sdf_nodes.h"
|
#include "scene/resources/visual_shader_sdf_nodes.h"
|
||||||
#include "scene/resources/world_2d.h"
|
#include "scene/resources/world_2d.h"
|
||||||
#include "scene/resources/world_3d.h"
|
#include "scene/resources/world_3d.h"
|
||||||
|
#include "scene/resources/world_margin_shape_2d.h"
|
||||||
#include "scene/resources/world_margin_shape_3d.h"
|
#include "scene/resources/world_margin_shape_3d.h"
|
||||||
#include "scene/scene_string_names.h"
|
#include "scene/scene_string_names.h"
|
||||||
|
|
||||||
|
@ -823,7 +823,7 @@ void register_scene_types() {
|
||||||
OS::get_singleton()->yield(); //may take time to init
|
OS::get_singleton()->yield(); //may take time to init
|
||||||
|
|
||||||
GDREGISTER_VIRTUAL_CLASS(Shape2D);
|
GDREGISTER_VIRTUAL_CLASS(Shape2D);
|
||||||
GDREGISTER_CLASS(LineShape2D);
|
GDREGISTER_CLASS(WorldMarginShape2D);
|
||||||
GDREGISTER_CLASS(SegmentShape2D);
|
GDREGISTER_CLASS(SegmentShape2D);
|
||||||
GDREGISTER_CLASS(CircleShape2D);
|
GDREGISTER_CLASS(CircleShape2D);
|
||||||
GDREGISTER_CLASS(RectangleShape2D);
|
GDREGISTER_CLASS(RectangleShape2D);
|
||||||
|
@ -910,6 +910,7 @@ void register_scene_types() {
|
||||||
ClassDB::add_compatibility_class("KinematicBody2D", "CharacterBody2D");
|
ClassDB::add_compatibility_class("KinematicBody2D", "CharacterBody2D");
|
||||||
ClassDB::add_compatibility_class("KinematicCollision", "KinematicCollision3D");
|
ClassDB::add_compatibility_class("KinematicCollision", "KinematicCollision3D");
|
||||||
ClassDB::add_compatibility_class("Light", "Light3D");
|
ClassDB::add_compatibility_class("Light", "Light3D");
|
||||||
|
ClassDB::add_compatibility_class("LineShape2D", "WorldMarginShape2D");
|
||||||
ClassDB::add_compatibility_class("Listener", "Listener3D");
|
ClassDB::add_compatibility_class("Listener", "Listener3D");
|
||||||
ClassDB::add_compatibility_class("MeshInstance", "MeshInstance3D");
|
ClassDB::add_compatibility_class("MeshInstance", "MeshInstance3D");
|
||||||
ClassDB::add_compatibility_class("MultiMeshInstance", "MultiMeshInstance3D");
|
ClassDB::add_compatibility_class("MultiMeshInstance", "MultiMeshInstance3D");
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*************************************************************************/
|
/*************************************************************************/
|
||||||
/* line_shape_2d.cpp */
|
/* world_margin_shape_2d.cpp */
|
||||||
/*************************************************************************/
|
/*************************************************************************/
|
||||||
/* This file is part of: */
|
/* This file is part of: */
|
||||||
/* GODOT ENGINE */
|
/* GODOT ENGINE */
|
||||||
|
@ -28,13 +28,13 @@
|
||||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||||
/*************************************************************************/
|
/*************************************************************************/
|
||||||
|
|
||||||
#include "line_shape_2d.h"
|
#include "world_margin_shape_2d.h"
|
||||||
|
|
||||||
#include "core/math/geometry_2d.h"
|
#include "core/math/geometry_2d.h"
|
||||||
#include "servers/physics_server_2d.h"
|
#include "servers/physics_server_2d.h"
|
||||||
#include "servers/rendering_server.h"
|
#include "servers/rendering_server.h"
|
||||||
|
|
||||||
bool LineShape2D::_edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const {
|
bool WorldMarginShape2D::_edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const {
|
||||||
Vector2 point = get_distance() * get_normal();
|
Vector2 point = get_distance() * get_normal();
|
||||||
Vector2 l[2][2] = { { point - get_normal().orthogonal() * 100, point + get_normal().orthogonal() * 100 }, { point, point + get_normal() * 30 } };
|
Vector2 l[2][2] = { { point - get_normal().orthogonal() * 100, point + get_normal().orthogonal() * 100 }, { point, point + get_normal() * 30 } };
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@ bool LineShape2D::_edit_is_selected_on_click(const Point2 &p_point, double p_tol
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LineShape2D::_update_shape() {
|
void WorldMarginShape2D::_update_shape() {
|
||||||
Array arr;
|
Array arr;
|
||||||
arr.push_back(normal);
|
arr.push_back(normal);
|
||||||
arr.push_back(distance);
|
arr.push_back(distance);
|
||||||
|
@ -56,25 +56,25 @@ void LineShape2D::_update_shape() {
|
||||||
emit_changed();
|
emit_changed();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LineShape2D::set_normal(const Vector2 &p_normal) {
|
void WorldMarginShape2D::set_normal(const Vector2 &p_normal) {
|
||||||
normal = p_normal;
|
normal = p_normal;
|
||||||
_update_shape();
|
_update_shape();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LineShape2D::set_distance(real_t p_distance) {
|
void WorldMarginShape2D::set_distance(real_t p_distance) {
|
||||||
distance = p_distance;
|
distance = p_distance;
|
||||||
_update_shape();
|
_update_shape();
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2 LineShape2D::get_normal() const {
|
Vector2 WorldMarginShape2D::get_normal() const {
|
||||||
return normal;
|
return normal;
|
||||||
}
|
}
|
||||||
|
|
||||||
real_t LineShape2D::get_distance() const {
|
real_t WorldMarginShape2D::get_distance() const {
|
||||||
return distance;
|
return distance;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LineShape2D::draw(const RID &p_to_rid, const Color &p_color) {
|
void WorldMarginShape2D::draw(const RID &p_to_rid, const Color &p_color) {
|
||||||
Vector2 point = get_distance() * get_normal();
|
Vector2 point = get_distance() * get_normal();
|
||||||
|
|
||||||
Vector2 l1[2] = { point - get_normal().orthogonal() * 100, point + get_normal().orthogonal() * 100 };
|
Vector2 l1[2] = { point - get_normal().orthogonal() * 100, point + get_normal().orthogonal() * 100 };
|
||||||
|
@ -83,7 +83,7 @@ void LineShape2D::draw(const RID &p_to_rid, const Color &p_color) {
|
||||||
RS::get_singleton()->canvas_item_add_line(p_to_rid, l2[0], l2[1], p_color, 3);
|
RS::get_singleton()->canvas_item_add_line(p_to_rid, l2[0], l2[1], p_color, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
Rect2 LineShape2D::get_rect() const {
|
Rect2 WorldMarginShape2D::get_rect() const {
|
||||||
Vector2 point = get_distance() * get_normal();
|
Vector2 point = get_distance() * get_normal();
|
||||||
|
|
||||||
Vector2 l1[2] = { point - get_normal().orthogonal() * 100, point + get_normal().orthogonal() * 100 };
|
Vector2 l1[2] = { point - get_normal().orthogonal() * 100, point + get_normal().orthogonal() * 100 };
|
||||||
|
@ -96,22 +96,22 @@ Rect2 LineShape2D::get_rect() const {
|
||||||
return rect;
|
return rect;
|
||||||
}
|
}
|
||||||
|
|
||||||
real_t LineShape2D::get_enclosing_radius() const {
|
real_t WorldMarginShape2D::get_enclosing_radius() const {
|
||||||
return distance;
|
return distance;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LineShape2D::_bind_methods() {
|
void WorldMarginShape2D::_bind_methods() {
|
||||||
ClassDB::bind_method(D_METHOD("set_normal", "normal"), &LineShape2D::set_normal);
|
ClassDB::bind_method(D_METHOD("set_normal", "normal"), &WorldMarginShape2D::set_normal);
|
||||||
ClassDB::bind_method(D_METHOD("get_normal"), &LineShape2D::get_normal);
|
ClassDB::bind_method(D_METHOD("get_normal"), &WorldMarginShape2D::get_normal);
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("set_distance", "distance"), &LineShape2D::set_distance);
|
ClassDB::bind_method(D_METHOD("set_distance", "distance"), &WorldMarginShape2D::set_distance);
|
||||||
ClassDB::bind_method(D_METHOD("get_distance"), &LineShape2D::get_distance);
|
ClassDB::bind_method(D_METHOD("get_distance"), &WorldMarginShape2D::get_distance);
|
||||||
|
|
||||||
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "normal"), "set_normal", "get_normal");
|
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "normal"), "set_normal", "get_normal");
|
||||||
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "distance"), "set_distance", "get_distance");
|
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "distance"), "set_distance", "get_distance");
|
||||||
}
|
}
|
||||||
|
|
||||||
LineShape2D::LineShape2D() :
|
WorldMarginShape2D::WorldMarginShape2D() :
|
||||||
Shape2D(PhysicsServer2D::get_singleton()->line_shape_create()) {
|
Shape2D(PhysicsServer2D::get_singleton()->world_margin_shape_create()) {
|
||||||
_update_shape();
|
_update_shape();
|
||||||
}
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
/*************************************************************************/
|
/*************************************************************************/
|
||||||
/* line_shape_2d.h */
|
/* world_margin_shape_2d.h */
|
||||||
/*************************************************************************/
|
/*************************************************************************/
|
||||||
/* This file is part of: */
|
/* This file is part of: */
|
||||||
/* GODOT ENGINE */
|
/* GODOT ENGINE */
|
||||||
|
@ -28,15 +28,15 @@
|
||||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||||
/*************************************************************************/
|
/*************************************************************************/
|
||||||
|
|
||||||
#ifndef LINE_SHAPE_2D_H
|
#ifndef WORLD_MARGIN_SHAPE_2D_H
|
||||||
#define LINE_SHAPE_2D_H
|
#define WORLD_MARGIN_SHAPE_2D_H
|
||||||
|
|
||||||
#include "scene/resources/shape_2d.h"
|
#include "scene/resources/shape_2d.h"
|
||||||
|
|
||||||
class LineShape2D : public Shape2D {
|
class WorldMarginShape2D : public Shape2D {
|
||||||
GDCLASS(LineShape2D, Shape2D);
|
GDCLASS(WorldMarginShape2D, Shape2D);
|
||||||
|
|
||||||
// LineShape2D is often used for one-way platforms, where the normal pointing up makes sense.
|
// WorldMarginShape2D is often used for one-way platforms, where the normal pointing up makes sense.
|
||||||
Vector2 normal = Vector2(0, -1);
|
Vector2 normal = Vector2(0, -1);
|
||||||
real_t distance = 0.0;
|
real_t distance = 0.0;
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@ public:
|
||||||
virtual Rect2 get_rect() const override;
|
virtual Rect2 get_rect() const override;
|
||||||
virtual real_t get_enclosing_radius() const override;
|
virtual real_t get_enclosing_radius() const override;
|
||||||
|
|
||||||
LineShape2D();
|
WorldMarginShape2D();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // LINE_SHAPE_2D_H
|
#endif // WORLD_MARGIN_SHAPE_2D_H
|
|
@ -1114,12 +1114,12 @@ static void _collision_convex_polygon_convex_polygon(const Shape2DSW *p_a, const
|
||||||
bool sat_2d_calculate_penetration(const Shape2DSW *p_shape_A, const Transform2D &p_transform_A, const Vector2 &p_motion_A, const Shape2DSW *p_shape_B, const Transform2D &p_transform_B, const Vector2 &p_motion_B, CollisionSolver2DSW::CallbackResult p_result_callback, void *p_userdata, bool p_swap, Vector2 *sep_axis, real_t p_margin_A, real_t p_margin_B) {
|
bool sat_2d_calculate_penetration(const Shape2DSW *p_shape_A, const Transform2D &p_transform_A, const Vector2 &p_motion_A, const Shape2DSW *p_shape_B, const Transform2D &p_transform_B, const Vector2 &p_motion_B, CollisionSolver2DSW::CallbackResult p_result_callback, void *p_userdata, bool p_swap, Vector2 *sep_axis, real_t p_margin_A, real_t p_margin_B) {
|
||||||
PhysicsServer2D::ShapeType type_A = p_shape_A->get_type();
|
PhysicsServer2D::ShapeType type_A = p_shape_A->get_type();
|
||||||
|
|
||||||
ERR_FAIL_COND_V(type_A == PhysicsServer2D::SHAPE_LINE, false);
|
ERR_FAIL_COND_V(type_A == PhysicsServer2D::SHAPE_WORLD_MARGIN, false);
|
||||||
ERR_FAIL_COND_V(p_shape_A->is_concave(), false);
|
ERR_FAIL_COND_V(p_shape_A->is_concave(), false);
|
||||||
|
|
||||||
PhysicsServer2D::ShapeType type_B = p_shape_B->get_type();
|
PhysicsServer2D::ShapeType type_B = p_shape_B->get_type();
|
||||||
|
|
||||||
ERR_FAIL_COND_V(type_B == PhysicsServer2D::SHAPE_LINE, false);
|
ERR_FAIL_COND_V(type_B == PhysicsServer2D::SHAPE_WORLD_MARGIN, false);
|
||||||
ERR_FAIL_COND_V(p_shape_B->is_concave(), false);
|
ERR_FAIL_COND_V(p_shape_B->is_concave(), false);
|
||||||
|
|
||||||
static const CollisionFunc collision_table[5][5] = {
|
static const CollisionFunc collision_table[5][5] = {
|
||||||
|
|
|
@ -34,14 +34,14 @@
|
||||||
#define collision_solver sat_2d_calculate_penetration
|
#define collision_solver sat_2d_calculate_penetration
|
||||||
//#define collision_solver gjk_epa_calculate_penetration
|
//#define collision_solver gjk_epa_calculate_penetration
|
||||||
|
|
||||||
bool CollisionSolver2DSW::solve_static_line(const Shape2DSW *p_shape_A, const Transform2D &p_transform_A, const Shape2DSW *p_shape_B, const Transform2D &p_transform_B, CallbackResult p_result_callback, void *p_userdata, bool p_swap_result) {
|
bool CollisionSolver2DSW::solve_static_world_margin(const Shape2DSW *p_shape_A, const Transform2D &p_transform_A, const Shape2DSW *p_shape_B, const Transform2D &p_transform_B, CallbackResult p_result_callback, void *p_userdata, bool p_swap_result) {
|
||||||
const LineShape2DSW *line = static_cast<const LineShape2DSW *>(p_shape_A);
|
const WorldMarginShape2DSW *world_margin = static_cast<const WorldMarginShape2DSW *>(p_shape_A);
|
||||||
if (p_shape_B->get_type() == PhysicsServer2D::SHAPE_LINE) {
|
if (p_shape_B->get_type() == PhysicsServer2D::SHAPE_WORLD_MARGIN) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2 n = p_transform_A.basis_xform(line->get_normal()).normalized();
|
Vector2 n = p_transform_A.basis_xform(world_margin->get_normal()).normalized();
|
||||||
Vector2 p = p_transform_A.xform(line->get_normal() * line->get_d());
|
Vector2 p = p_transform_A.xform(world_margin->get_normal() * world_margin->get_d());
|
||||||
real_t d = n.dot(p);
|
real_t d = n.dot(p);
|
||||||
|
|
||||||
Vector2 supports[2];
|
Vector2 supports[2];
|
||||||
|
@ -166,15 +166,15 @@ bool CollisionSolver2DSW::solve(const Shape2DSW *p_shape_A, const Transform2D &p
|
||||||
swap = true;
|
swap = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type_A == PhysicsServer2D::SHAPE_LINE) {
|
if (type_A == PhysicsServer2D::SHAPE_WORLD_MARGIN) {
|
||||||
if (type_B == PhysicsServer2D::SHAPE_LINE) {
|
if (type_B == PhysicsServer2D::SHAPE_WORLD_MARGIN) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (swap) {
|
if (swap) {
|
||||||
return solve_static_line(p_shape_B, p_transform_B, p_shape_A, p_transform_A, p_result_callback, p_userdata, true);
|
return solve_static_world_margin(p_shape_B, p_transform_B, p_shape_A, p_transform_A, p_result_callback, p_userdata, true);
|
||||||
} else {
|
} else {
|
||||||
return solve_static_line(p_shape_A, p_transform_A, p_shape_B, p_transform_B, p_result_callback, p_userdata, false);
|
return solve_static_world_margin(p_shape_A, p_transform_A, p_shape_B, p_transform_B, p_result_callback, p_userdata, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (concave_B) {
|
} else if (concave_B) {
|
||||||
|
|
|
@ -38,7 +38,7 @@ public:
|
||||||
typedef void (*CallbackResult)(const Vector2 &p_point_A, const Vector2 &p_point_B, void *p_userdata);
|
typedef void (*CallbackResult)(const Vector2 &p_point_A, const Vector2 &p_point_B, void *p_userdata);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static bool solve_static_line(const Shape2DSW *p_shape_A, const Transform2D &p_transform_A, const Shape2DSW *p_shape_B, const Transform2D &p_transform_B, CallbackResult p_result_callback, void *p_userdata, bool p_swap_result);
|
static bool solve_static_world_margin(const Shape2DSW *p_shape_A, const Transform2D &p_transform_A, const Shape2DSW *p_shape_B, const Transform2D &p_transform_B, CallbackResult p_result_callback, void *p_userdata, bool p_swap_result);
|
||||||
static void concave_callback(void *p_userdata, Shape2DSW *p_convex);
|
static void concave_callback(void *p_userdata, Shape2DSW *p_convex);
|
||||||
static bool solve_concave(const Shape2DSW *p_shape_A, const Transform2D &p_transform_A, const Vector2 &p_motion_A, const Shape2DSW *p_shape_B, const Transform2D &p_transform_B, const Vector2 &p_motion_B, CallbackResult p_result_callback, void *p_userdata, bool p_swap_result, Vector2 *sep_axis = nullptr, real_t p_margin_A = 0, real_t p_margin_B = 0);
|
static bool solve_concave(const Shape2DSW *p_shape_A, const Transform2D &p_transform_A, const Vector2 &p_motion_A, const Shape2DSW *p_shape_B, const Transform2D &p_transform_B, const Vector2 &p_motion_B, CallbackResult p_result_callback, void *p_userdata, bool p_swap_result, Vector2 *sep_axis = nullptr, real_t p_margin_A = 0, real_t p_margin_B = 0);
|
||||||
static bool solve_raycast(const Shape2DSW *p_shape_A, const Vector2 &p_motion_A, const Transform2D &p_transform_A, const Shape2DSW *p_shape_B, const Transform2D &p_transform_B, CallbackResult p_result_callback, void *p_userdata, bool p_swap_result, Vector2 *sep_axis = nullptr);
|
static bool solve_raycast(const Shape2DSW *p_shape_A, const Vector2 &p_motion_A, const Transform2D &p_transform_A, const Shape2DSW *p_shape_B, const Transform2D &p_transform_B, CallbackResult p_result_callback, void *p_userdata, bool p_swap_result, Vector2 *sep_axis = nullptr);
|
||||||
|
|
|
@ -42,8 +42,8 @@
|
||||||
RID PhysicsServer2DSW::_shape_create(ShapeType p_shape) {
|
RID PhysicsServer2DSW::_shape_create(ShapeType p_shape) {
|
||||||
Shape2DSW *shape = nullptr;
|
Shape2DSW *shape = nullptr;
|
||||||
switch (p_shape) {
|
switch (p_shape) {
|
||||||
case SHAPE_LINE: {
|
case SHAPE_WORLD_MARGIN: {
|
||||||
shape = memnew(LineShape2DSW);
|
shape = memnew(WorldMarginShape2DSW);
|
||||||
} break;
|
} break;
|
||||||
case SHAPE_SEGMENT: {
|
case SHAPE_SEGMENT: {
|
||||||
shape = memnew(SegmentShape2DSW);
|
shape = memnew(SegmentShape2DSW);
|
||||||
|
@ -75,8 +75,8 @@ RID PhysicsServer2DSW::_shape_create(ShapeType p_shape) {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
RID PhysicsServer2DSW::line_shape_create() {
|
RID PhysicsServer2DSW::world_margin_shape_create() {
|
||||||
return _shape_create(SHAPE_LINE);
|
return _shape_create(SHAPE_WORLD_MARGIN);
|
||||||
}
|
}
|
||||||
|
|
||||||
RID PhysicsServer2DSW::segment_shape_create() {
|
RID PhysicsServer2DSW::segment_shape_create() {
|
||||||
|
|
|
@ -87,7 +87,7 @@ public:
|
||||||
Vector2 *ptr;
|
Vector2 *ptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
virtual RID line_shape_create() override;
|
virtual RID world_margin_shape_create() override;
|
||||||
virtual RID segment_shape_create() override;
|
virtual RID segment_shape_create() override;
|
||||||
virtual RID circle_shape_create() override;
|
virtual RID circle_shape_create() override;
|
||||||
virtual RID rectangle_shape_create() override;
|
virtual RID rectangle_shape_create() override;
|
||||||
|
|
|
@ -79,7 +79,7 @@ public:
|
||||||
#include "servers/server_wrap_mt_common.h"
|
#include "servers/server_wrap_mt_common.h"
|
||||||
|
|
||||||
//FUNC1RID(shape,ShapeType); todo fix
|
//FUNC1RID(shape,ShapeType); todo fix
|
||||||
FUNCRID(line_shape)
|
FUNCRID(world_margin_shape)
|
||||||
FUNCRID(segment_shape)
|
FUNCRID(segment_shape)
|
||||||
FUNCRID(circle_shape)
|
FUNCRID(circle_shape)
|
||||||
FUNCRID(rectangle_shape)
|
FUNCRID(rectangle_shape)
|
||||||
|
|
|
@ -88,15 +88,15 @@ Shape2DSW::~Shape2DSW() {
|
||||||
/*********************************************************/
|
/*********************************************************/
|
||||||
/*********************************************************/
|
/*********************************************************/
|
||||||
|
|
||||||
void LineShape2DSW::get_supports(const Vector2 &p_normal, Vector2 *r_supports, int &r_amount) const {
|
void WorldMarginShape2DSW::get_supports(const Vector2 &p_normal, Vector2 *r_supports, int &r_amount) const {
|
||||||
r_amount = 0;
|
r_amount = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LineShape2DSW::contains_point(const Vector2 &p_point) const {
|
bool WorldMarginShape2DSW::contains_point(const Vector2 &p_point) const {
|
||||||
return normal.dot(p_point) < d;
|
return normal.dot(p_point) < d;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LineShape2DSW::intersect_segment(const Vector2 &p_begin, const Vector2 &p_end, Vector2 &r_point, Vector2 &r_normal) const {
|
bool WorldMarginShape2DSW::intersect_segment(const Vector2 &p_begin, const Vector2 &p_end, Vector2 &r_point, Vector2 &r_normal) const {
|
||||||
Vector2 segment = p_begin - p_end;
|
Vector2 segment = p_begin - p_end;
|
||||||
real_t den = normal.dot(segment);
|
real_t den = normal.dot(segment);
|
||||||
|
|
||||||
|
@ -118,11 +118,11 @@ bool LineShape2DSW::intersect_segment(const Vector2 &p_begin, const Vector2 &p_e
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
real_t LineShape2DSW::get_moment_of_inertia(real_t p_mass, const Size2 &p_scale) const {
|
real_t WorldMarginShape2DSW::get_moment_of_inertia(real_t p_mass, const Size2 &p_scale) const {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LineShape2DSW::set_data(const Variant &p_data) {
|
void WorldMarginShape2DSW::set_data(const Variant &p_data) {
|
||||||
ERR_FAIL_COND(p_data.get_type() != Variant::ARRAY);
|
ERR_FAIL_COND(p_data.get_type() != Variant::ARRAY);
|
||||||
Array arr = p_data;
|
Array arr = p_data;
|
||||||
ERR_FAIL_COND(arr.size() != 2);
|
ERR_FAIL_COND(arr.size() != 2);
|
||||||
|
@ -131,7 +131,7 @@ void LineShape2DSW::set_data(const Variant &p_data) {
|
||||||
configure(Rect2(Vector2(-1e4, -1e4), Vector2(1e4 * 2, 1e4 * 2)));
|
configure(Rect2(Vector2(-1e4, -1e4), Vector2(1e4 * 2, 1e4 * 2)));
|
||||||
}
|
}
|
||||||
|
|
||||||
Variant LineShape2DSW::get_data() const {
|
Variant WorldMarginShape2DSW::get_data() const {
|
||||||
Array arr;
|
Array arr;
|
||||||
arr.resize(2);
|
arr.resize(2);
|
||||||
arr[0] = normal;
|
arr[0] = normal;
|
||||||
|
|
|
@ -36,7 +36,7 @@
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
||||||
SHAPE_LINE, ///< plane:"plane"
|
SHAPE_WORLD_MARGIN, ///< plane:"plane"
|
||||||
SHAPE_SEGMENT, ///< real_t:"length"
|
SHAPE_SEGMENT, ///< real_t:"length"
|
||||||
SHAPE_CIRCLE, ///< real_t:"radius"
|
SHAPE_CIRCLE, ///< real_t:"radius"
|
||||||
SHAPE_RECTANGLE, ///< vec3:"extents"
|
SHAPE_RECTANGLE, ///< vec3:"extents"
|
||||||
|
@ -152,7 +152,7 @@ public:
|
||||||
r_max = MAX(maxa, maxb); \
|
r_max = MAX(maxa, maxb); \
|
||||||
}
|
}
|
||||||
|
|
||||||
class LineShape2DSW : public Shape2DSW {
|
class WorldMarginShape2DSW : public Shape2DSW {
|
||||||
Vector2 normal;
|
Vector2 normal;
|
||||||
real_t d;
|
real_t d;
|
||||||
|
|
||||||
|
@ -160,7 +160,7 @@ public:
|
||||||
_FORCE_INLINE_ Vector2 get_normal() const { return normal; }
|
_FORCE_INLINE_ Vector2 get_normal() const { return normal; }
|
||||||
_FORCE_INLINE_ real_t get_d() const { return d; }
|
_FORCE_INLINE_ real_t get_d() const { return d; }
|
||||||
|
|
||||||
virtual PhysicsServer2D::ShapeType get_type() const { return PhysicsServer2D::SHAPE_LINE; }
|
virtual PhysicsServer2D::ShapeType get_type() const { return PhysicsServer2D::SHAPE_WORLD_MARGIN; }
|
||||||
|
|
||||||
virtual void project_rangev(const Vector2 &p_normal, const Transform2D &p_transform, real_t &r_min, real_t &r_max) const { project_range(p_normal, p_transform, r_min, r_max); }
|
virtual void project_rangev(const Vector2 &p_normal, const Transform2D &p_transform, real_t &r_min, real_t &r_max) const { project_range(p_normal, p_transform, r_min, r_max); }
|
||||||
virtual void get_supports(const Vector2 &p_normal, Vector2 *r_supports, int &r_amount) const;
|
virtual void get_supports(const Vector2 &p_normal, Vector2 *r_supports, int &r_amount) const;
|
||||||
|
|
|
@ -513,7 +513,7 @@ bool PhysicsServer2D::_body_test_motion(RID p_body, const Transform2D &p_from, c
|
||||||
}
|
}
|
||||||
|
|
||||||
void PhysicsServer2D::_bind_methods() {
|
void PhysicsServer2D::_bind_methods() {
|
||||||
ClassDB::bind_method(D_METHOD("line_shape_create"), &PhysicsServer2D::line_shape_create);
|
ClassDB::bind_method(D_METHOD("world_margin_shape_create"), &PhysicsServer2D::world_margin_shape_create);
|
||||||
ClassDB::bind_method(D_METHOD("segment_shape_create"), &PhysicsServer2D::segment_shape_create);
|
ClassDB::bind_method(D_METHOD("segment_shape_create"), &PhysicsServer2D::segment_shape_create);
|
||||||
ClassDB::bind_method(D_METHOD("circle_shape_create"), &PhysicsServer2D::circle_shape_create);
|
ClassDB::bind_method(D_METHOD("circle_shape_create"), &PhysicsServer2D::circle_shape_create);
|
||||||
ClassDB::bind_method(D_METHOD("rectangle_shape_create"), &PhysicsServer2D::rectangle_shape_create);
|
ClassDB::bind_method(D_METHOD("rectangle_shape_create"), &PhysicsServer2D::rectangle_shape_create);
|
||||||
|
@ -674,7 +674,7 @@ void PhysicsServer2D::_bind_methods() {
|
||||||
BIND_ENUM_CONSTANT(SPACE_PARAM_CONSTRAINT_DEFAULT_BIAS);
|
BIND_ENUM_CONSTANT(SPACE_PARAM_CONSTRAINT_DEFAULT_BIAS);
|
||||||
BIND_ENUM_CONSTANT(SPACE_PARAM_TEST_MOTION_MIN_CONTACT_DEPTH);
|
BIND_ENUM_CONSTANT(SPACE_PARAM_TEST_MOTION_MIN_CONTACT_DEPTH);
|
||||||
|
|
||||||
BIND_ENUM_CONSTANT(SHAPE_LINE);
|
BIND_ENUM_CONSTANT(SHAPE_WORLD_MARGIN);
|
||||||
BIND_ENUM_CONSTANT(SHAPE_SEGMENT);
|
BIND_ENUM_CONSTANT(SHAPE_SEGMENT);
|
||||||
BIND_ENUM_CONSTANT(SHAPE_CIRCLE);
|
BIND_ENUM_CONSTANT(SHAPE_CIRCLE);
|
||||||
BIND_ENUM_CONSTANT(SHAPE_RECTANGLE);
|
BIND_ENUM_CONSTANT(SHAPE_RECTANGLE);
|
||||||
|
|
|
@ -219,7 +219,7 @@ public:
|
||||||
static PhysicsServer2D *get_singleton();
|
static PhysicsServer2D *get_singleton();
|
||||||
|
|
||||||
enum ShapeType {
|
enum ShapeType {
|
||||||
SHAPE_LINE, ///< plane:"plane"
|
SHAPE_WORLD_MARGIN, ///< plane:"plane"
|
||||||
SHAPE_SEGMENT, ///< float:"length"
|
SHAPE_SEGMENT, ///< float:"length"
|
||||||
SHAPE_CIRCLE, ///< float:"radius"
|
SHAPE_CIRCLE, ///< float:"radius"
|
||||||
SHAPE_RECTANGLE, ///< vec3:"extents"
|
SHAPE_RECTANGLE, ///< vec3:"extents"
|
||||||
|
@ -229,7 +229,7 @@ public:
|
||||||
SHAPE_CUSTOM, ///< Server-Implementation based custom shape, calling shape_create() with this value will result in an error
|
SHAPE_CUSTOM, ///< Server-Implementation based custom shape, calling shape_create() with this value will result in an error
|
||||||
};
|
};
|
||||||
|
|
||||||
virtual RID line_shape_create() = 0;
|
virtual RID world_margin_shape_create() = 0;
|
||||||
virtual RID segment_shape_create() = 0;
|
virtual RID segment_shape_create() = 0;
|
||||||
virtual RID circle_shape_create() = 0;
|
virtual RID circle_shape_create() = 0;
|
||||||
virtual RID rectangle_shape_create() = 0;
|
virtual RID rectangle_shape_create() = 0;
|
||||||
|
|
|
@ -255,7 +255,7 @@ protected:
|
||||||
arr.push_back(p_normal);
|
arr.push_back(p_normal);
|
||||||
arr.push_back(p_d);
|
arr.push_back(p_d);
|
||||||
|
|
||||||
RID plane = ps->line_shape_create();
|
RID plane = ps->world_margin_shape_create();
|
||||||
ps->shape_set_data(plane, arr);
|
ps->shape_set_data(plane, arr);
|
||||||
|
|
||||||
RID plane_body = ps->body_create();
|
RID plane_body = ps->body_create();
|
||||||
|
|
Loading…
Reference in a new issue