Path: blob/master/scene/resources/3d/separation_ray_shape_3d.cpp
9898 views
/**************************************************************************/1/* 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 "separation_ray_shape_3d.h"3132#include "scene/resources/mesh.h"33#include "servers/physics_server_3d.h"3435Vector<Vector3> SeparationRayShape3D::get_debug_mesh_lines() const {36Vector<Vector3> points = {37Vector3(),38Vector3(0, 0, get_length())39};4041return points;42}4344Ref<ArrayMesh> SeparationRayShape3D::get_debug_arraymesh_faces(const Color &p_modulate) const {45return memnew(ArrayMesh);46}4748real_t SeparationRayShape3D::get_enclosing_radius() const {49return length;50}5152void SeparationRayShape3D::_update_shape() {53Dictionary d;54d["length"] = length;55d["slide_on_slope"] = slide_on_slope;56PhysicsServer3D::get_singleton()->shape_set_data(get_shape(), d);57Shape3D::_update_shape();58}5960void SeparationRayShape3D::set_length(float p_length) {61length = p_length;62_update_shape();63emit_changed();64}6566float SeparationRayShape3D::get_length() const {67return length;68}6970void SeparationRayShape3D::set_slide_on_slope(bool p_active) {71slide_on_slope = p_active;72_update_shape();73emit_changed();74}7576bool SeparationRayShape3D::get_slide_on_slope() const {77return slide_on_slope;78}7980void SeparationRayShape3D::_bind_methods() {81ClassDB::bind_method(D_METHOD("set_length", "length"), &SeparationRayShape3D::set_length);82ClassDB::bind_method(D_METHOD("get_length"), &SeparationRayShape3D::get_length);8384ClassDB::bind_method(D_METHOD("set_slide_on_slope", "active"), &SeparationRayShape3D::set_slide_on_slope);85ClassDB::bind_method(D_METHOD("get_slide_on_slope"), &SeparationRayShape3D::get_slide_on_slope);8687ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "length", PROPERTY_HINT_RANGE, "0.001,100,0.001,or_greater,suffix:m"), "set_length", "get_length");88ADD_PROPERTY(PropertyInfo(Variant::BOOL, "slide_on_slope"), "set_slide_on_slope", "get_slide_on_slope");89}9091SeparationRayShape3D::SeparationRayShape3D() :92Shape3D(PhysicsServer3D::get_singleton()->shape_create(PhysicsServer3D::SHAPE_SEPARATION_RAY)) {93/* Code copied from setters to prevent the use of uninitialized variables */94_update_shape();95emit_changed();96}979899