1/**************************************************************************/
2/* world_boundary_shape_3d.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 "world_boundary_shape_3d.h"
32
33#include "servers/physics_server_3d.h"
34
35Vector<Vector3> WorldBoundaryShape3D::get_debug_mesh_lines() const {
36 Plane p = get_plane();
37
38 Vector3 n1 = p.get_any_perpendicular_normal();
39 Vector3 n2 = p.normal.cross(n1).normalized();
40
41 Vector3 pface[4] = {
42 p.normal * p.d + n1 * 10.0 + n2 * 10.0,
43 p.normal * p.d + n1 * 10.0 + n2 * -10.0,
44 p.normal * p.d + n1 * -10.0 + n2 * -10.0,
45 p.normal * p.d + n1 * -10.0 + n2 * 10.0,
46 };
47
48 Vector<Vector3> points = {
49 pface[0],
50 pface[1],
51 pface[1],
52 pface[2],
53 pface[2],
54 pface[3],
55 pface[3],
56 pface[0],
57 p.normal * p.d,
58 p.normal * p.d + p.normal * 3
59 };
60
61 return points;
62}
63
64void WorldBoundaryShape3D::_update_shape() {
65 PhysicsServer3D::get_singleton()->shape_set_data(get_shape(), plane);
66 Shape3D::_update_shape();
67}
68
69void WorldBoundaryShape3D::set_plane(const Plane &p_plane) {
70 plane = p_plane;
71 _update_shape();
72 emit_changed();
73}
74
75const Plane &WorldBoundaryShape3D::get_plane() const {
76 return plane;
77}
78
79void WorldBoundaryShape3D::_bind_methods() {
80 ClassDB::bind_method(D_METHOD("set_plane", "plane"), &WorldBoundaryShape3D::set_plane);
81 ClassDB::bind_method(D_METHOD("get_plane"), &WorldBoundaryShape3D::get_plane);
82
83 ADD_PROPERTY(PropertyInfo(Variant::PLANE, "plane", PROPERTY_HINT_NONE, "suffix:m"), "set_plane", "get_plane");
84}
85
86WorldBoundaryShape3D::WorldBoundaryShape3D() :
87 Shape3D(PhysicsServer3D::get_singleton()->shape_create(PhysicsServer3D::SHAPE_WORLD_BOUNDARY)) {
88 set_plane(Plane(0, 1, 0, 0));
89}
90