Path: blob/master/modules/jolt_physics/shapes/jolt_shape_instance_3d.cpp
10278 views
/**************************************************************************/1/* jolt_shape_instance_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_shape_instance_3d.h"3132#include "jolt_shape_3d.h"3334#include "Jolt/Physics/Collision/Shape/DecoratedShape.h"3536JoltShapeInstance3D::ShapeReference::ShapeReference(JoltShapedObject3D *p_parent, JoltShape3D *p_shape) :37parent(p_parent),38shape(p_shape) {39if (shape != nullptr) {40shape->add_owner(parent);41}42}4344JoltShapeInstance3D::ShapeReference::ShapeReference(ShapeReference &&p_other) :45parent(p_other.parent),46shape(p_other.shape) {47p_other.parent = nullptr;48p_other.shape = nullptr;49}5051JoltShapeInstance3D::ShapeReference::~ShapeReference() {52if (shape != nullptr) {53shape->remove_owner(parent);54}55}5657JoltShapeInstance3D::ShapeReference &JoltShapeInstance3D::ShapeReference::operator=(ShapeReference &&p_other) {58if (this != &p_other) {59SWAP(parent, p_other.parent);60SWAP(shape, p_other.shape);61}6263return *this;64}6566JoltShapeInstance3D::JoltShapeInstance3D(JoltShapedObject3D *p_parent, JoltShape3D *p_shape, const Transform3D &p_transform, const Vector3 &p_scale, bool p_disabled) :67transform(p_transform),68scale(p_scale),69shape(p_parent, p_shape),70disabled(p_disabled) {71}7273AABB JoltShapeInstance3D::get_aabb() const {74return get_transform_scaled().xform(shape->get_aabb());75}7677bool JoltShapeInstance3D::try_build() {78ERR_FAIL_COND_V(is_disabled(), false);7980const JPH::ShapeRefC maybe_new_shape = shape->try_build();8182if (maybe_new_shape == nullptr) {83jolt_ref = nullptr;84return false;85}8687if (jolt_ref != nullptr) {88const JPH::DecoratedShape *outer_shape = static_cast<const JPH::DecoratedShape *>(jolt_ref.GetPtr());8990if (outer_shape->GetInnerShape() == maybe_new_shape) {91return true;92}93}9495jolt_ref = JoltShape3D::with_user_data(maybe_new_shape, (uint64_t)id);9697return true;98}99100101