Path: blob/master/modules/jolt_physics/shapes/jolt_separation_ray_shape_3d.cpp
10278 views
/**************************************************************************/1/* jolt_separation_ray_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_separation_ray_shape_3d.h"3132#include "../misc/jolt_type_conversions.h"33#include "jolt_custom_ray_shape.h"3435JPH::ShapeRefC JoltSeparationRayShape3D::_build() const {36ERR_FAIL_COND_V_MSG(length <= 0.0f, nullptr, vformat("Failed to build Jolt Physics separation ray shape with %s. Its length must be greater than 0. This shape belongs to %s.", to_string(), _owners_to_string()));3738const JoltCustomRayShapeSettings shape_settings(length, slide_on_slope);39const JPH::ShapeSettings::ShapeResult shape_result = shape_settings.Create();40ERR_FAIL_COND_V_MSG(shape_result.HasError(), nullptr, vformat("Failed to build Jolt Physics separation ray shape with %s. It returned the following error: '%s'. This shape belongs to %s.", to_string(), to_godot(shape_result.GetError()), _owners_to_string()));4142return shape_result.Get();43}4445Variant JoltSeparationRayShape3D::get_data() const {46Dictionary data;47data["length"] = length;48data["slide_on_slope"] = slide_on_slope;49return data;50}5152void JoltSeparationRayShape3D::set_data(const Variant &p_data) {53ERR_FAIL_COND(p_data.get_type() != Variant::DICTIONARY);5455const Dictionary data = p_data;5657const Variant maybe_length = data.get("length", Variant());58ERR_FAIL_COND(maybe_length.get_type() != Variant::FLOAT);5960const Variant maybe_slide_on_slope = data.get("slide_on_slope", Variant());61ERR_FAIL_COND(maybe_slide_on_slope.get_type() != Variant::BOOL);6263const float new_length = maybe_length;64const bool new_slide_on_slope = maybe_slide_on_slope;6566if (unlikely(new_length == length && new_slide_on_slope == slide_on_slope)) {67return;68}6970length = new_length;71slide_on_slope = new_slide_on_slope;7273destroy();74}7576AABB JoltSeparationRayShape3D::get_aabb() const {77constexpr float size_xy = 0.1f;78constexpr float half_size_xy = size_xy / 2.0f;79return AABB(Vector3(-half_size_xy, -half_size_xy, 0.0f), Vector3(size_xy, size_xy, length));80}8182String JoltSeparationRayShape3D::to_string() const {83return vformat("{length=%f slide_on_slope=%s}", length, slide_on_slope);84}858687