Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/modules/jolt_physics/shapes/jolt_sphere_shape_3d.cpp
10278 views
1
/**************************************************************************/
2
/* jolt_sphere_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_sphere_shape_3d.h"
32
33
#include "../misc/jolt_type_conversions.h"
34
35
#include "Jolt/Physics/Collision/Shape/SphereShape.h"
36
37
JPH::ShapeRefC JoltSphereShape3D::_build() const {
38
ERR_FAIL_COND_V_MSG(radius <= 0.0f, nullptr, vformat("Failed to build Jolt Physics sphere shape with %s. Its radius must be greater than 0. This shape belongs to %s.", to_string(), _owners_to_string()));
39
40
const JPH::SphereShapeSettings shape_settings(radius);
41
const JPH::ShapeSettings::ShapeResult shape_result = shape_settings.Create();
42
ERR_FAIL_COND_V_MSG(shape_result.HasError(), nullptr, vformat("Failed to build Jolt Physics sphere shape with %s. It returned the following error: '%s'. This shape belongs to %s.", to_string(), to_godot(shape_result.GetError()), _owners_to_string()));
43
44
return shape_result.Get();
45
}
46
47
Variant JoltSphereShape3D::get_data() const {
48
return radius;
49
}
50
51
void JoltSphereShape3D::set_data(const Variant &p_data) {
52
ERR_FAIL_COND(p_data.get_type() != Variant::FLOAT);
53
54
const float new_radius = p_data;
55
if (unlikely(new_radius == radius)) {
56
return;
57
}
58
59
radius = new_radius;
60
61
destroy();
62
}
63
64
AABB JoltSphereShape3D::get_aabb() const {
65
const Vector3 half_extents(radius, radius, radius);
66
return AABB(-half_extents, half_extents * 2.0f);
67
}
68
69
String JoltSphereShape3D::to_string() const {
70
return vformat("{radius=%f}", radius);
71
}
72
73