Path: blob/master/modules/jolt_physics/shapes/jolt_shape_instance_3d.h
10278 views
/**************************************************************************/1/* jolt_shape_instance_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 "core/math/transform_3d.h"3334#include "Jolt/Jolt.h"3536#include "Jolt/Physics/Collision/Shape/Shape.h"3738class JoltShapedObject3D;39class JoltShape3D;4041class JoltShapeInstance3D {42// This RAII helper exists solely to avoid needing to maintain move construction/assignment in `JoltShapeInstance3D`.43struct ShapeReference {44JoltShapedObject3D *parent = nullptr;45JoltShape3D *shape = nullptr;4647ShapeReference() = default;48ShapeReference(JoltShapedObject3D *p_parent, JoltShape3D *p_shape);49ShapeReference(const ShapeReference &p_other) = delete;50ShapeReference(ShapeReference &&p_other);51~ShapeReference();5253ShapeReference &operator=(const ShapeReference &p_other) = delete;54ShapeReference &operator=(ShapeReference &&p_other);5556JoltShape3D *operator*() const { return shape; }57JoltShape3D *operator->() const { return shape; }58operator JoltShape3D *() const { return shape; }59};6061inline static uint32_t next_id = 1;6263Transform3D transform;64Vector3 scale;65ShapeReference shape;66JPH::ShapeRefC jolt_ref;67uint32_t id = next_id++;68bool disabled = false;6970public:71JoltShapeInstance3D() = default;72JoltShapeInstance3D(JoltShapedObject3D *p_parent, JoltShape3D *p_shape, const Transform3D &p_transform = Transform3D(), const Vector3 &p_scale = Vector3(1.0f, 1.0f, 1.0f), bool p_disabled = false);7374uint32_t get_id() const { return id; }7576JoltShape3D *get_shape() const { return shape; }7778const JPH::Shape *get_jolt_ref() const { return jolt_ref; }7980const Transform3D &get_transform_unscaled() const { return transform; }81Transform3D get_transform_scaled() const { return transform.scaled_local(scale); }82void set_transform(const Transform3D &p_transform) { transform = p_transform; }8384const Vector3 &get_scale() const { return scale; }85void set_scale(const Vector3 &p_scale) { scale = p_scale; }8687AABB get_aabb() const;8889bool is_built() const { return jolt_ref != nullptr; }9091bool is_enabled() const { return !disabled; }92bool is_disabled() const { return disabled; }9394void enable() { disabled = false; }95void disable() { disabled = true; }9697bool try_build();98};99100101