Path: blob/master/modules/jolt_physics/objects/jolt_object_3d.h
10278 views
/**************************************************************************/1/* jolt_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 "../shapes/jolt_shape_instance_3d.h"3334#include "core/math/vector3.h"35#include "core/object/object.h"36#include "core/string/ustring.h"37#include "core/templates/local_vector.h"38#include "core/templates/rid.h"3940#include "Jolt/Jolt.h"4142#include "Jolt/Physics/Body/Body.h"43#include "Jolt/Physics/Collision/BroadPhase/BroadPhaseLayer.h"44#include "Jolt/Physics/Collision/ObjectLayer.h"4546class JoltArea3D;47class JoltBody3D;48class JoltShapedObject3D;49class JoltShape3D;50class JoltSoftBody3D;51class JoltSpace3D;5253class JoltObject3D {54public:55enum ObjectType : char {56OBJECT_TYPE_INVALID,57OBJECT_TYPE_BODY,58OBJECT_TYPE_SOFT_BODY,59OBJECT_TYPE_AREA,60};6162protected:63LocalVector<JoltShapeInstance3D> shapes;6465RID rid;66ObjectID instance_id;67JoltSpace3D *space = nullptr;68JPH::Body *jolt_body = nullptr;6970uint32_t collision_layer = 1;71uint32_t collision_mask = 1;7273ObjectType object_type = OBJECT_TYPE_INVALID;7475bool pickable = false;7677virtual JPH::BroadPhaseLayer _get_broad_phase_layer() const = 0;78virtual JPH::ObjectLayer _get_object_layer() const = 0;7980virtual void _add_to_space() = 0;81virtual void _remove_from_space();8283void _reset_space();8485void _update_object_layer();8687virtual void _collision_layer_changed();88virtual void _collision_mask_changed();8990virtual void _space_changing() {}91virtual void _space_changed() {}9293public:94explicit JoltObject3D(ObjectType p_object_type);95virtual ~JoltObject3D() = 0;9697ObjectType get_type() const { return object_type; }9899bool is_body() const { return object_type == OBJECT_TYPE_BODY; }100bool is_soft_body() const { return object_type == OBJECT_TYPE_SOFT_BODY; }101bool is_area() const { return object_type == OBJECT_TYPE_AREA; }102bool is_shaped() const { return object_type != OBJECT_TYPE_SOFT_BODY; }103104JoltShapedObject3D *as_shaped() { return is_shaped() ? reinterpret_cast<JoltShapedObject3D *>(this) : nullptr; }105const JoltShapedObject3D *as_shaped() const { return is_shaped() ? reinterpret_cast<const JoltShapedObject3D *>(this) : nullptr; }106107JoltBody3D *as_body() { return is_body() ? reinterpret_cast<JoltBody3D *>(this) : nullptr; }108const JoltBody3D *as_body() const { return is_body() ? reinterpret_cast<const JoltBody3D *>(this) : nullptr; }109110JoltSoftBody3D *as_soft_body() { return is_soft_body() ? reinterpret_cast<JoltSoftBody3D *>(this) : nullptr; }111const JoltSoftBody3D *as_soft_body() const { return is_soft_body() ? reinterpret_cast<const JoltSoftBody3D *>(this) : nullptr; }112113JoltArea3D *as_area() { return is_area() ? reinterpret_cast<JoltArea3D *>(this) : nullptr; }114const JoltArea3D *as_area() const { return is_area() ? reinterpret_cast<const JoltArea3D *>(this) : nullptr; }115116RID get_rid() const { return rid; }117void set_rid(const RID &p_rid) { rid = p_rid; }118119ObjectID get_instance_id() const { return instance_id; }120void set_instance_id(ObjectID p_id) { instance_id = p_id; }121Object *get_instance() const;122123JPH::Body *get_jolt_body() const { return jolt_body; }124JPH::BodyID get_jolt_id() const { return jolt_body->GetID(); }125126JoltSpace3D *get_space() const { return space; }127void set_space(JoltSpace3D *p_space);128bool in_space() const { return space != nullptr && jolt_body != nullptr; }129130uint32_t get_collision_layer() const { return collision_layer; }131void set_collision_layer(uint32_t p_layer);132133uint32_t get_collision_mask() const { return collision_mask; }134void set_collision_mask(uint32_t p_mask);135136virtual Vector3 get_velocity_at_position(const Vector3 &p_position) const = 0;137138bool is_pickable() const { return pickable; }139void set_pickable(bool p_enabled) { pickable = p_enabled; }140141bool can_collide_with(const JoltObject3D &p_other) const;142bool can_interact_with(const JoltObject3D &p_other) const;143144virtual bool can_interact_with(const JoltBody3D &p_other) const = 0;145virtual bool can_interact_with(const JoltSoftBody3D &p_other) const = 0;146virtual bool can_interact_with(const JoltArea3D &p_other) const = 0;147148virtual bool reports_contacts() const = 0;149150virtual void pre_step(float p_step, JPH::Body &p_jolt_body) {}151152String to_string() const;153};154155156