Debian Codegraph @

modules/jolt_physics/shapes/jolt_world_boundary_shape_3d.cpp

raw symbols SCIP
1 /**************************************************************************/
2 /* jolt_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 "jolt_world_boundary_shape_3d.h"
32
33 #include "../jolt_project_settings.h"
34 #include "../misc/jolt_type_conversions.h"
35
36 #include "Jolt/Physics/Collision/Shape/PlaneShape.h"
37
38 JPH::ShapeRefC JoltWorldBoundaryShape3D::_build() const {
39 const Plane normalized_plane = plane.normalized();
40 ERR_FAIL_COND_V_MSG(normalized_plane == Plane(), nullptr, vformat("Failed to build Jolt Physics world boundary shape with %s. The plane's normal must not be zero. This shape belongs to %s.", to_string(), _owners_to_string()));
41
42 const float half_size = JoltProjectSettings::world_boundary_shape_size / 2.0f;
43 const JPH::PlaneShapeSettings shape_settings(to_jolt(normalized_plane), nullptr, half_size);
44 const JPH::ShapeSettings::ShapeResult shape_result = shape_settings.Create();
45 ERR_FAIL_COND_V_MSG(shape_result.HasError(), nullptr, vformat("Failed to build Jolt Physics world boundary shape with %s. It returned the following error: '%s'. This shape belongs to %s.", to_string(), to_godot(shape_result.GetError()), _owners_to_string()));
46
47 return shape_result.Get();
48 }
49
50 Variant JoltWorldBoundaryShape3D::get_data() const {
51 return plane;
52 }
53
54 void JoltWorldBoundaryShape3D::set_data(const Variant &p_data) {
55 ERR_FAIL_COND(p_data.get_type() != Variant::PLANE);
56
57 const Plane new_plane = p_data;
58 if (unlikely(new_plane == plane)) {
59 return;
60 }
61
62 plane = p_data;
63
64 destroy();
65 }
66
67 AABB JoltWorldBoundaryShape3D::get_aabb() const {
68 const float size = JoltProjectSettings::world_boundary_shape_size;
69 const float half_size = size / 2.0f;
70 return AABB(Vector3(-half_size, -half_size, -half_size), Vector3(size, half_size, size));
71 }
72
73 String JoltWorldBoundaryShape3D::to_string() const {
74 return vformat("{plane=%s}", plane);
75 }