Skip to content

Commit

Permalink
Rename RayShape to SeparationRayShape
Browse files Browse the repository at this point in the history
Makes it clearer that it's used for special cases when picking a
collision shape.
  • Loading branch information
pouleyKetchoupp committed Aug 25, 2021
1 parent aa47917 commit 3d5dc80
Show file tree
Hide file tree
Showing 37 changed files with 192 additions and 190 deletions.
9 changes: 5 additions & 4 deletions doc/classes/PhysicsServer2D.xml
Original file line number Diff line number Diff line change
Expand Up @@ -717,17 +717,17 @@
Sets a joint parameter. See [enum JointParam] for a list of available parameters.
</description>
</method>
<method name="ray_shape_create">
<method name="rectangle_shape_create">
<return type="RID" />
<description>
</description>
</method>
<method name="rectangle_shape_create">
<method name="segment_shape_create">
<return type="RID" />
<description>
</description>
</method>
<method name="segment_shape_create">
<method name="separation_ray_shape_create">
<return type="RID" />
<description>
</description>
Expand Down Expand Up @@ -846,7 +846,8 @@
<constant name="SHAPE_WORLD_MARGIN" value="0" enum="ShapeType">
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 name="SHAPE_RAY" value="1" enum="ShapeType">
<constant name="SHAPE_SEPARATION_RAY" value="1" enum="ShapeType">
This is the constant for creating separation ray shapes. A separation ray is defined by a length and separates itself from what is touching its far endpoint. Useful for character controllers.
</constant>
<constant name="SHAPE_SEGMENT" value="2" enum="ShapeType">
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.
Expand Down
6 changes: 3 additions & 3 deletions doc/classes/PhysicsServer3D.xml
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,7 @@
<description>
</description>
</method>
<method name="ray_shape_create">
<method name="separation_ray_shape_create">
<return type="RID" />
<description>
</description>
Expand Down Expand Up @@ -1177,8 +1177,8 @@
<constant name="SHAPE_PLANE" value="0" enum="ShapeType">
The [Shape3D] is a [WorldMarginShape3D].
</constant>
<constant name="SHAPE_RAY" value="1" enum="ShapeType">
The [Shape3D] is a [RayShape3D].
<constant name="SHAPE_SEPARATION_RAY" value="1" enum="ShapeType">
The [Shape3D] is a [SeparationRayShape3D].
</constant>
<constant name="SHAPE_SPHERE" value="2" enum="ShapeType">
The [Shape3D] is a [SphereShape3D].
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="RayShape3D" inherits="Shape3D" version="4.0">
<class name="SeparationRayShape2D" inherits="Shape2D" version="4.0">
<brief_description>
Ray shape for 3D collisions.
Separation ray shape for 2D collisions.
</brief_description>
<description>
Ray shape for 3D collisions, which can be set into a [PhysicsBody3D] or [Area3D]. A ray is not really a collision body; instead, it tries to separate itself from whatever is touching its far endpoint. It's often useful for characters.
Separation ray shape for 2D collisions. A ray is not really a collision body; instead, it tries to separate itself from whatever is touching its far endpoint. It's often useful for characters.
</description>
<tutorials>
</tutorials>
<methods>
</methods>
<members>
<member name="length" type="float" setter="set_length" getter="get_length" default="1.0">
<member name="length" type="float" setter="set_length" getter="get_length" default="20.0">
The ray's length.
</member>
<member name="slide_on_slope" type="bool" setter="set_slide_on_slope" getter="get_slide_on_slope" default="false">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="RayShape2D" inherits="Shape2D" version="4.0">
<class name="SeparationRayShape3D" inherits="Shape3D" version="4.0">
<brief_description>
Ray shape for 2D collisions.
Separation ray shape for 3D collisions.
</brief_description>
<description>
Ray shape for 2D collisions. A ray is not really a collision body; instead, it tries to separate itself from whatever is touching its far endpoint. It's often useful for characters.
Separation ray shape for 3D collisions, which can be set into a [PhysicsBody3D] or [Area3D]. A ray is not really a collision body; instead, it tries to separate itself from whatever is touching its far endpoint. It's often useful for characters.
</description>
<tutorials>
</tutorials>
<methods>
</methods>
<members>
<member name="length" type="float" setter="set_length" getter="get_length" default="20.0">
<member name="length" type="float" setter="set_length" getter="get_length" default="1.0">
The ray's length.
</member>
<member name="slide_on_slope" type="bool" setter="set_slide_on_slope" getter="get_slide_on_slope" default="false">
Expand Down
File renamed without changes
File renamed without changes
4 changes: 2 additions & 2 deletions editor/import/resource_importer_scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
#include "scene/resources/animation.h"
#include "scene/resources/box_shape_3d.h"
#include "scene/resources/packed_scene.h"
#include "scene/resources/ray_shape_3d.h"
#include "scene/resources/resource_format_text.h"
#include "scene/resources/separation_ray_shape_3d.h"
#include "scene/resources/sphere_shape_3d.h"
#include "scene/resources/surface_tool.h"
#include "scene/resources/world_margin_shape_3d.h"
Expand Down Expand Up @@ -381,7 +381,7 @@ Node *ResourceImporterScene::_pre_fix_node(Node *p_node, Node *p_root, Map<Ref<E
boxShape->set_size(Vector3(2, 2, 2));
colshape->set_shape(boxShape);
} else if (empty_draw_type == "SINGLE_ARROW") {
RayShape3D *rayShape = memnew(RayShape3D);
SeparationRayShape3D *rayShape = memnew(SeparationRayShape3D);
rayShape->set_length(1);
colshape->set_shape(rayShape);
Object::cast_to<Node3D>(sb)->rotate_x(Math_PI / 2);
Expand Down
22 changes: 11 additions & 11 deletions editor/plugins/collision_shape_2d_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@
#include "scene/resources/circle_shape_2d.h"
#include "scene/resources/concave_polygon_shape_2d.h"
#include "scene/resources/convex_polygon_shape_2d.h"
#include "scene/resources/ray_shape_2d.h"
#include "scene/resources/rectangle_shape_2d.h"
#include "scene/resources/segment_shape_2d.h"
#include "scene/resources/separation_ray_shape_2d.h"
#include "scene/resources/world_margin_shape_2d.h"

void CollisionShape2DEditor::_node_removed(Node *p_node) {
Expand Down Expand Up @@ -81,8 +81,8 @@ Variant CollisionShape2DEditor::get_handle_value(int idx) const {

} break;

case RAY_SHAPE: {
Ref<RayShape2D> ray = node->get_shape();
case SEPARATION_RAY_SHAPE: {
Ref<SeparationRayShape2D> ray = node->get_shape();

if (idx == 0) {
return ray->get_length();
Expand Down Expand Up @@ -162,8 +162,8 @@ void CollisionShape2DEditor::set_handle(int idx, Point2 &p_point) {

} break;

case RAY_SHAPE: {
Ref<RayShape2D> ray = node->get_shape();
case SEPARATION_RAY_SHAPE: {
Ref<SeparationRayShape2D> ray = node->get_shape();

ray->set_length(Math::abs(p_point.y));

Expand Down Expand Up @@ -272,8 +272,8 @@ void CollisionShape2DEditor::commit_handle(int idx, Variant &p_org) {

} break;

case RAY_SHAPE: {
Ref<RayShape2D> ray = node->get_shape();
case SEPARATION_RAY_SHAPE: {
Ref<SeparationRayShape2D> ray = node->get_shape();

undo_redo->add_do_method(ray.ptr(), "set_length", ray->get_length());
undo_redo->add_do_method(canvas_item_editor, "update_viewport");
Expand Down Expand Up @@ -423,8 +423,8 @@ void CollisionShape2DEditor::_get_current_shape_type() {
shape_type = CONVEX_POLYGON_SHAPE;
} else if (Object::cast_to<WorldMarginShape2D>(*s)) {
shape_type = WORLD_MARGIN_SHAPE;
} else if (Object::cast_to<RayShape2D>(*s)) {
shape_type = RAY_SHAPE;
} else if (Object::cast_to<SeparationRayShape2D>(*s)) {
shape_type = SEPARATION_RAY_SHAPE;
} else if (Object::cast_to<RectangleShape2D>(*s)) {
shape_type = RECTANGLE_SHAPE;
} else if (Object::cast_to<SegmentShape2D>(*s)) {
Expand Down Expand Up @@ -502,8 +502,8 @@ void CollisionShape2DEditor::forward_canvas_draw_over_viewport(Control *p_overla

} break;

case RAY_SHAPE: {
Ref<RayShape2D> shape = node->get_shape();
case SEPARATION_RAY_SHAPE: {
Ref<SeparationRayShape2D> shape = node->get_shape();

handles.resize(1);
handles.write[0] = Point2(0, shape->get_length());
Expand Down
2 changes: 1 addition & 1 deletion editor/plugins/collision_shape_2d_editor_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class CollisionShape2DEditor : public Control {
CONCAVE_POLYGON_SHAPE,
CONVEX_POLYGON_SHAPE,
WORLD_MARGIN_SHAPE,
RAY_SHAPE,
SEPARATION_RAY_SHAPE,
RECTANGLE_SHAPE,
SEGMENT_SHAPE
};
Expand Down
22 changes: 11 additions & 11 deletions editor/plugins/node_3d_editor_gizmos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
#include "scene/resources/cylinder_shape_3d.h"
#include "scene/resources/height_map_shape_3d.h"
#include "scene/resources/primitive_meshes.h"
#include "scene/resources/ray_shape_3d.h"
#include "scene/resources/separation_ray_shape_3d.h"
#include "scene/resources/sphere_shape_3d.h"
#include "scene/resources/surface_tool.h"
#include "scene/resources/world_margin_shape_3d.h"
Expand Down Expand Up @@ -4068,7 +4068,7 @@ String CollisionShape3DGizmoPlugin::get_handle_name(const EditorNode3DGizmo *p_g
return p_id == 0 ? "Radius" : "Height";
}

if (Object::cast_to<RayShape3D>(*s)) {
if (Object::cast_to<SeparationRayShape3D>(*s)) {
return "Length";
}

Expand Down Expand Up @@ -4103,8 +4103,8 @@ Variant CollisionShape3DGizmoPlugin::get_handle_value(const EditorNode3DGizmo *p
return p_id == 0 ? cs2->get_radius() : cs2->get_height();
}

if (Object::cast_to<RayShape3D>(*s)) {
Ref<RayShape3D> cs2 = s;
if (Object::cast_to<SeparationRayShape3D>(*s)) {
Ref<SeparationRayShape3D> cs2 = s;
return cs2->get_length();
}

Expand Down Expand Up @@ -4143,8 +4143,8 @@ void CollisionShape3DGizmoPlugin::set_handle(const EditorNode3DGizmo *p_gizmo, i
ss->set_radius(d);
}

if (Object::cast_to<RayShape3D>(*s)) {
Ref<RayShape3D> rs = s;
if (Object::cast_to<SeparationRayShape3D>(*s)) {
Ref<SeparationRayShape3D> rs = s;
Vector3 ra, rb;
Geometry3D::get_closest_points_between_segments(Vector3(), Vector3(0, 0, 4096), sg[0], sg[1], ra, rb);
float d = ra.z;
Expand Down Expand Up @@ -4314,15 +4314,15 @@ void CollisionShape3DGizmoPlugin::commit_handle(const EditorNode3DGizmo *p_gizmo
ur->commit_action();
}

if (Object::cast_to<RayShape3D>(*s)) {
Ref<RayShape3D> ss = s;
if (Object::cast_to<SeparationRayShape3D>(*s)) {
Ref<SeparationRayShape3D> ss = s;
if (p_cancel) {
ss->set_length(p_restore);
return;
}

UndoRedo *ur = Node3DEditor::get_singleton()->get_undo_redo();
ur->create_action(TTR("Change Ray Shape Length"));
ur->create_action(TTR("Change Separation Ray Shape Length"));
ur->add_do_method(ss.ptr(), "set_length", ss->get_length());
ur->add_undo_method(ss.ptr(), "set_length", p_restore);
ur->commit_action();
Expand Down Expand Up @@ -4597,8 +4597,8 @@ void CollisionShape3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
p_gizmo->add_collision_segments(cs2->get_debug_mesh_lines());
}

if (Object::cast_to<RayShape3D>(*s)) {
Ref<RayShape3D> rs = s;
if (Object::cast_to<SeparationRayShape3D>(*s)) {
Ref<SeparationRayShape3D> rs = s;

Vector<Vector3> points;
points.push_back(Vector3());
Expand Down
11 changes: 6 additions & 5 deletions scene/register_scene_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,11 @@
#include "scene/resources/physics_material.h"
#include "scene/resources/polygon_path_finder.h"
#include "scene/resources/primitive_meshes.h"
#include "scene/resources/ray_shape_2d.h"
#include "scene/resources/ray_shape_3d.h"
#include "scene/resources/rectangle_shape_2d.h"
#include "scene/resources/resource_format_text.h"
#include "scene/resources/segment_shape_2d.h"
#include "scene/resources/separation_ray_shape_2d.h"
#include "scene/resources/separation_ray_shape_3d.h"
#include "scene/resources/skeleton_modification_2d.h"
#include "scene/resources/skeleton_modification_2d_ccdik.h"
#include "scene/resources/skeleton_modification_2d_fabrik.h"
Expand Down Expand Up @@ -754,7 +754,7 @@ void register_scene_types() {
OS::get_singleton()->yield(); //may take time to init

GDREGISTER_VIRTUAL_CLASS(Shape3D);
GDREGISTER_CLASS(RayShape3D);
GDREGISTER_CLASS(SeparationRayShape3D);
GDREGISTER_CLASS(SphereShape3D);
GDREGISTER_CLASS(BoxShape3D);
GDREGISTER_CLASS(CapsuleShape3D);
Expand Down Expand Up @@ -843,7 +843,7 @@ void register_scene_types() {
GDREGISTER_VIRTUAL_CLASS(Shape2D);
GDREGISTER_CLASS(WorldMarginShape2D);
GDREGISTER_CLASS(SegmentShape2D);
GDREGISTER_CLASS(RayShape2D);
GDREGISTER_CLASS(SeparationRayShape2D);
GDREGISTER_CLASS(CircleShape2D);
GDREGISTER_CLASS(RectangleShape2D);
GDREGISTER_CLASS(CapsuleShape2D);
Expand Down Expand Up @@ -964,7 +964,8 @@ void register_scene_types() {
ClassDB::add_compatibility_class("ProceduralSky", "Sky");
ClassDB::add_compatibility_class("ProximityGroup", "ProximityGroup3D");
ClassDB::add_compatibility_class("RayCast", "RayCast3D");
ClassDB::add_compatibility_class("RayShape", "RayShape3D");
ClassDB::add_compatibility_class("RayShape", "SeparationRayShape3D");
ClassDB::add_compatibility_class("RayShape2D", "SeparationRayShape2D");
ClassDB::add_compatibility_class("RemoteTransform", "RemoteTransform3D");
ClassDB::add_compatibility_class("RigidBody", "RigidBody3D");
ClassDB::add_compatibility_class("Shape", "Shape3D");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*************************************************************************/
/* ray_shape_2d.cpp */
/* separation_ray_shape_2d.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
Expand Down Expand Up @@ -28,20 +28,20 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/

#include "ray_shape_2d.h"
#include "separation_ray_shape_2d.h"

#include "servers/physics_server_2d.h"
#include "servers/rendering_server.h"

void RayShape2D::_update_shape() {
void SeparationRayShape2D::_update_shape() {
Dictionary d;
d["length"] = length;
d["slide_on_slope"] = slide_on_slope;
PhysicsServer2D::get_singleton()->shape_set_data(get_rid(), d);
emit_changed();
}

void RayShape2D::draw(const RID &p_to_rid, const Color &p_color) {
void SeparationRayShape2D::draw(const RID &p_to_rid, const Color &p_color) {
const Vector2 target_position = Vector2(0, get_length());

const float max_arrow_size = 6;
Expand Down Expand Up @@ -72,48 +72,48 @@ void RayShape2D::draw(const RID &p_to_rid, const Color &p_color) {
RS::get_singleton()->canvas_item_add_primitive(p_to_rid, pts, cols, Vector<Point2>(), RID());
}

Rect2 RayShape2D::get_rect() const {
Rect2 SeparationRayShape2D::get_rect() const {
Rect2 rect;
rect.position = Vector2();
rect.expand_to(Vector2(0, length));
rect = rect.grow(Math_SQRT12 * 4);
return rect;
}

real_t RayShape2D::get_enclosing_radius() const {
real_t SeparationRayShape2D::get_enclosing_radius() const {
return length;
}

void RayShape2D::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_length", "length"), &RayShape2D::set_length);
ClassDB::bind_method(D_METHOD("get_length"), &RayShape2D::get_length);
void SeparationRayShape2D::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_length", "length"), &SeparationRayShape2D::set_length);
ClassDB::bind_method(D_METHOD("get_length"), &SeparationRayShape2D::get_length);

ClassDB::bind_method(D_METHOD("set_slide_on_slope", "active"), &RayShape2D::set_slide_on_slope);
ClassDB::bind_method(D_METHOD("get_slide_on_slope"), &RayShape2D::get_slide_on_slope);
ClassDB::bind_method(D_METHOD("set_slide_on_slope", "active"), &SeparationRayShape2D::set_slide_on_slope);
ClassDB::bind_method(D_METHOD("get_slide_on_slope"), &SeparationRayShape2D::get_slide_on_slope);

ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "length"), "set_length", "get_length");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "slide_on_slope"), "set_slide_on_slope", "get_slide_on_slope");
}

void RayShape2D::set_length(real_t p_length) {
void SeparationRayShape2D::set_length(real_t p_length) {
length = p_length;
_update_shape();
}

real_t RayShape2D::get_length() const {
real_t SeparationRayShape2D::get_length() const {
return length;
}

void RayShape2D::set_slide_on_slope(bool p_active) {
void SeparationRayShape2D::set_slide_on_slope(bool p_active) {
slide_on_slope = p_active;
_update_shape();
}

bool RayShape2D::get_slide_on_slope() const {
bool SeparationRayShape2D::get_slide_on_slope() const {
return slide_on_slope;
}

RayShape2D::RayShape2D() :
Shape2D(PhysicsServer2D::get_singleton()->ray_shape_create()) {
SeparationRayShape2D::SeparationRayShape2D() :
Shape2D(PhysicsServer2D::get_singleton()->separation_ray_shape_create()) {
_update_shape();
}
Loading

0 comments on commit 3d5dc80

Please sign in to comment.