Debian Codegraph @

modules/jolt_physics/shapes/jolt_custom_motion_shape.cpp

raw symbols SCIP
1 /**************************************************************************/
2 /* jolt_custom_motion_shape.cpp */
3 /**************************************************************************/
4 /* This file is part of: */
5 /* GODOT ENGINE */
6 /* https://godotengine.org */
7 /**************************************************************************/
8 /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9 /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10 /* */
11 /* Permission is hereby granted, free of charge, to any person obtaining */
12 /* a copy of this software and associated documentation files (the */
13 /* "Software"), to deal in the Software without restriction, including */
14 /* without limitation the rights to use, copy, modify, merge, publish, */
15 /* distribute, sublicense, and/or sell copies of the Software, and to */
16 /* permit persons to whom the Software is furnished to do so, subject to */
17 /* the following conditions: */
18 /* */
19 /* The above copyright notice and this permission notice shall be */
20 /* included in all copies or substantial portions of the Software. */
21 /* */
22 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29 /**************************************************************************/
30
31 #include "jolt_custom_motion_shape.h"
32
33 namespace {
34
35 class JoltMotionConvexSupport final : public JPH::ConvexShape::Support {
36 public:
37 JoltMotionConvexSupport(JPH::Vec3Arg p_motion, const JPH::ConvexShape::Support *p_inner_support) :
38 motion(p_motion),
39 inner_support(p_inner_support) {}
40
41 virtual JPH::Vec3 GetSupport(JPH::Vec3Arg p_direction) const override {
42 JPH::Vec3 support = inner_support->GetSupport(p_direction);
43
44 if (p_direction.Dot(motion) > 0) {
45 support += motion;
46 }
47
48 return support;
49 }
50
51 virtual float GetConvexRadius() const override { return inner_support->GetConvexRadius(); }
52
53 private:
54 JPH::Vec3 motion = JPH::Vec3::sZero();
55
56 const JPH::ConvexShape::Support *inner_support = nullptr;
57 };
58
59 } // namespace
60
61 JPH::AABox JoltCustomMotionShape::GetLocalBounds() const {
62 JPH::AABox aabb = inner_shape.GetLocalBounds();
63 JPH::AABox aabb_translated = aabb;
64 aabb_translated.Translate(motion);
65 aabb.Encapsulate(aabb_translated);
66
67 return aabb;
68 }
69
70 void JoltCustomMotionShape::GetSupportingFace(const JPH::SubShapeID &p_sub_shape_id, JPH::Vec3Arg p_direction, JPH::Vec3Arg p_scale, JPH::Mat44Arg p_center_of_mass_transform, JPH::Shape::SupportingFace &p_vertices) const {
71 // This is technically called when using the enhanced internal edge removal, but `JPH::InternalEdgeRemovingCollector` will
72 // only ever use the faces of the second shape in the collision pair, and this shape will always be the first in the pair, so
73 // we can safely skip this.
74 }
75
76 const JPH::ConvexShape::Support *JoltCustomMotionShape::GetSupportFunction(JPH::ConvexShape::ESupportMode p_mode, JPH::ConvexShape::SupportBuffer &p_buffer, JPH::Vec3Arg p_scale) const {
77 return new (&p_buffer) JoltMotionConvexSupport(motion, inner_shape.GetSupportFunction(p_mode, inner_support_buffer, p_scale));
78 }