Path: blob/master/modules/jolt_physics/objects/jolt_shaped_object_3d.h
10278 views
/**************************************************************************/1/* jolt_shaped_object_3d.h */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#pragma once3132#include "jolt_object_3d.h"3334#include "core/templates/self_list.h"3536#include "Jolt/Jolt.h"3738#include "Jolt/Physics/Body/Body.h"39#include "Jolt/Physics/Body/BodyCreationSettings.h"4041class JoltShapedObject3D : public JoltObject3D {42friend class JoltShape3D;4344protected:45SelfList<JoltShapedObject3D> shapes_changed_element;46SelfList<JoltShapedObject3D> needs_optimization_element;4748Vector3 scale = Vector3(1, 1, 1);4950JPH::ShapeRefC jolt_shape;51JPH::ShapeRefC previous_jolt_shape;5253JPH::BodyCreationSettings *jolt_settings = new JPH::BodyCreationSettings();5455virtual JPH::EMotionType _get_motion_type() const = 0;5657bool _is_big() const;5859JPH::ShapeRefC _try_build_shape(bool p_optimize_compound);60JPH::ShapeRefC _try_build_single_shape();61JPH::ShapeRefC _try_build_compound_shape(bool p_optimize);6263void _enqueue_shapes_changed();64void _dequeue_shapes_changed();6566void _enqueue_needs_optimization();67void _dequeue_needs_optimization();6869virtual void _shapes_changed();70virtual void _shapes_committed();71virtual void _space_changing() override;7273public:74explicit JoltShapedObject3D(ObjectType p_object_type);75virtual ~JoltShapedObject3D() override;7677Transform3D get_transform_unscaled() const;78Transform3D get_transform_scaled() const;7980Vector3 get_scale() const { return scale; }81Basis get_basis() const;82Vector3 get_position() const;8384Vector3 get_center_of_mass() const;85Vector3 get_center_of_mass_relative() const;86Vector3 get_center_of_mass_local() const;8788Vector3 get_linear_velocity() const;89Vector3 get_angular_velocity() const;9091AABB get_aabb() const;9293virtual bool has_custom_center_of_mass() const = 0;94virtual Vector3 get_center_of_mass_custom() const = 0;9596JPH::ShapeRefC build_shapes(bool p_optimize_compound);9798void commit_shapes(bool p_optimize_compound);99100const JPH::Shape *get_jolt_shape() const { return jolt_shape; }101const JPH::Shape *get_previous_jolt_shape() const { return previous_jolt_shape; }102103void add_shape(JoltShape3D *p_shape, Transform3D p_transform, bool p_disabled);104void remove_shape(const JoltShape3D *p_shape);105void remove_shape(int p_index);106107JoltShape3D *get_shape(int p_index) const;108void set_shape(int p_index, JoltShape3D *p_shape);109110void clear_shapes();111void clear_previous_shape();112113int get_shape_count() const { return shapes.size(); }114115int find_shape_index(uint32_t p_shape_instance_id) const;116int find_shape_index(const JPH::SubShapeID &p_sub_shape_id) const;117118JoltShape3D *find_shape(uint32_t p_shape_instance_id) const;119JoltShape3D *find_shape(const JPH::SubShapeID &p_sub_shape_id) const;120121Transform3D get_shape_transform_unscaled(int p_index) const;122Transform3D get_shape_transform_scaled(int p_index) const;123void set_shape_transform(int p_index, Transform3D p_transform);124125Vector3 get_shape_scale(int p_index) const;126127bool is_shape_disabled(int p_index) const;128void set_shape_disabled(int p_index, bool p_disabled);129};130131132