Path: blob/master/modules/jolt_physics/shapes/jolt_sphere_shape_3d.cpp
10278 views
/**************************************************************************/1/* jolt_sphere_shape_3d.cpp */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#include "jolt_sphere_shape_3d.h"3132#include "../misc/jolt_type_conversions.h"3334#include "Jolt/Physics/Collision/Shape/SphereShape.h"3536JPH::ShapeRefC JoltSphereShape3D::_build() const {37ERR_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()));3839const JPH::SphereShapeSettings shape_settings(radius);40const JPH::ShapeSettings::ShapeResult shape_result = shape_settings.Create();41ERR_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()));4243return shape_result.Get();44}4546Variant JoltSphereShape3D::get_data() const {47return radius;48}4950void JoltSphereShape3D::set_data(const Variant &p_data) {51ERR_FAIL_COND(p_data.get_type() != Variant::FLOAT);5253const float new_radius = p_data;54if (unlikely(new_radius == radius)) {55return;56}5758radius = new_radius;5960destroy();61}6263AABB JoltSphereShape3D::get_aabb() const {64const Vector3 half_extents(radius, radius, radius);65return AABB(-half_extents, half_extents * 2.0f);66}6768String JoltSphereShape3D::to_string() const {69return vformat("{radius=%f}", radius);70}717273