Debian Codegraph @

scene/2d/physics/joints/groove_joint_2d.cpp

raw symbols SCIP
1 /**************************************************************************/
2 /* groove_joint_2d.cpp */
3 /**************************************************************************/
4 /* This file is part of: */
5 /* GODOT ENGINE */
6 /* https://godotengine.org */
7 /**************************************************************************/
8 /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9 /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10 /* */
11 /* Permission is hereby granted, free of charge, to any person obtaining */
12 /* a copy of this software and associated documentation files (the */
13 /* "Software"), to deal in the Software without restriction, including */
14 /* without limitation the rights to use, copy, modify, merge, publish, */
15 /* distribute, sublicense, and/or sell copies of the Software, and to */
16 /* permit persons to whom the Software is furnished to do so, subject to */
17 /* the following conditions: */
18 /* */
19 /* The above copyright notice and this permission notice shall be */
20 /* included in all copies or substantial portions of the Software. */
21 /* */
22 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29 /**************************************************************************/
30
31 #include "groove_joint_2d.h"
32
33 #include "scene/2d/physics/physics_body_2d.h"
34
35 void GrooveJoint2D::_notification(int p_what) {
36 switch (p_what) {
37 case NOTIFICATION_DRAW: {
38 if (!is_inside_tree()) {
39 break;
40 }
41
42 if (!Engine::get_singleton()->is_editor_hint() && !get_tree()->is_debugging_collisions_hint()) {
43 break;
44 }
45
46 draw_line(Point2(-10, 0), Point2(+10, 0), Color(0.7, 0.6, 0.0, 0.5), 3);
47 draw_line(Point2(-10, length), Point2(+10, length), Color(0.7, 0.6, 0.0, 0.5), 3);
48 draw_line(Point2(0, 0), Point2(0, length), Color(0.7, 0.6, 0.0, 0.5), 3);
49 draw_line(Point2(-10, initial_offset), Point2(+10, initial_offset), Color(0.8, 0.8, 0.9, 0.5), 5);
50 } break;
51 }
52 }
53
54 void GrooveJoint2D::_configure_joint(RID p_joint, PhysicsBody2D *body_a, PhysicsBody2D *body_b) {
55 Transform2D gt = get_global_transform();
56 Vector2 groove_A1 = gt.get_origin();
57 Vector2 groove_A2 = gt.xform(Vector2(0, length));
58 Vector2 anchor_B = gt.xform(Vector2(0, initial_offset));
59
60 PhysicsServer2D::get_singleton()->joint_make_groove(p_joint, groove_A1, groove_A2, anchor_B, body_a->get_rid(), body_b->get_rid());
61 }
62
63 void GrooveJoint2D::set_length(real_t p_length) {
64 length = p_length;
65 queue_redraw();
66 }
67
68 real_t GrooveJoint2D::get_length() const {
69 return length;
70 }
71
72 void GrooveJoint2D::set_initial_offset(real_t p_initial_offset) {
73 initial_offset = p_initial_offset;
74 queue_redraw();
75 }
76
77 real_t GrooveJoint2D::get_initial_offset() const {
78 return initial_offset;
79 }
80
81 void GrooveJoint2D::_bind_methods() {
82 ClassDB::bind_method(D_METHOD("set_length", "length"), &GrooveJoint2D::set_length);
83 ClassDB::bind_method(D_METHOD("get_length"), &GrooveJoint2D::get_length);
84 ClassDB::bind_method(D_METHOD("set_initial_offset", "offset"), &GrooveJoint2D::set_initial_offset);
85 ClassDB::bind_method(D_METHOD("get_initial_offset"), &GrooveJoint2D::get_initial_offset);
86
87 ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "length", PROPERTY_HINT_RANGE, "1,65535,1,exp,suffix:px"), "set_length", "get_length");
88 ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "initial_offset", PROPERTY_HINT_RANGE, "1,65535,1,exp,suffix:px"), "set_initial_offset", "get_initial_offset");
89 }
90
91 GrooveJoint2D::GrooveJoint2D() {
92 }