Commit graph

320 commits

Author SHA1 Message Date
Julian Adamse
7e5034958e
Fix the volume calculation for cylinders
(cherry picked from commit 03903fdeec)
2021-11-15 16:09:59 +01:00
lawnjelly
062406b555 [3.x] Add Basis helper functions for transforming normals
Correct transformation of normals that works with a Basis containing non-uniform scale is difficult to get correct for those not familiar with the maths, it is also rather verbose and hard to read in calling code. This PR adds helper functions which both standardize the approach and make it clearer in calling code what is being done and why.
2021-11-15 08:43:46 +00:00
PouleyKetchoupp
b93aeec4a2 Fix errors in KinematicBody when floor is destroyed or removed
In all physics servers, body_get_direct_state() now silently returns
nullptr when the body has been already freed or is removed from space,
so the client code can detect this state and invalidate the body rid.

In 2D, there is no change in behavior (just no more errors).

In 3D, the Bullet server returned a valid direct body state when the
body was removed from the physics space, but in this case it didn't
make sense to use the information from the body state.
2021-11-09 15:15:40 -07:00
Rémi Verschelde
6b7c841e1b
Merge pull request #54111 from nekomatata/fix-rigid-body-update-collision-layer-3.x 2021-11-08 23:58:47 +01:00
Rémi Verschelde
1b65550ec7
clang-format: Various fixes to comments alignment from clang-format 13
All reviewed manually and occasionally rewritten to avoid bad auto formatting.
2021-10-28 14:50:32 +02:00
Rémi Verschelde
42d385b312
clang-format: Disable alignment of operands, too unreliable
Sets `AlignOperands` to `DontAlign`.

`clang-format` developers seem to mostly care about space-based indentation and
every other version of clang-format breaks the bad mismatch of tabs and spaces
that it seems to use for operand alignment. So it's better without, so that it
respects our two-tabs `ContinuationIndentWidth`.
2021-10-28 13:23:38 +02:00
PouleyKetchoupp
562d9cef1b Fix RigidBody collision update after changing collision layer/mask
Changing the collision layer of a sleeping body was not triggering area
updates correctly.

Bodies need to be active for collision to be checked against already
overlapping bodies and areas.

Neighbors need to be activated too in order to handle the case where a
static body is modified (it can't be activated directly but paired
bodies need to check their collision again).

In 3D, moved the call to wakeup() from the physics server to
BodySW::_shapes_changed to make it consistent with 2D and also handle
the case where shapes are modified (_shapes_changed is called in both
this case and collision layer changes).
2021-10-21 17:22:47 -07:00
PouleyKetchoupp
48144ed40e Fix physics BVH broadphase update when changing collision layer/mask
The BVH implementation is not checking collision layers on existing
pairs on move like other physics broadphases do.

This is solved by adding a new call to trigger pair callbacks again so
the physics engine can check layers again (specific to the BVH version,
other broadphase implementations just trigger a move like before).
2021-10-21 16:53:41 -07:00
Rémi Verschelde
abb1413e0f
Merge pull request #53453 from nekomatata/fix-rayshape-snap-3.x 2021-10-06 08:37:57 +02:00
PouleyKetchoupp
255febefb2 Fix Rayshape recovery in test_body_ray_separation
These changes improve Rayshape behavior for Godot Physics 2D and 3D
when using move_and_slide with and without snapping.

Kinematic margin is now applied to ray shapes when handling snapping
collision tests and separation raycasts to help getting consistent
results in slopes and flat surfaces.

Recovery is calculated without the margin and a depth of 0 is still
considered a collision to stabilize results when on flat surface.

Recovery depth takes into account the current recovery vector (just like
test_body_motion) to fix jittering issues with multiple ray shapes due
to applying too much recovery.
2021-10-05 18:24:30 -07:00
PouleyKetchoupp
9bc1b4b90e Improved logic for KinematicBody collision recovery depth
Allows more flexible collision detection with different safe margin values.

Kinematic body motion changes in 2D and 3D:
-Recovery only for depth > min contact depth to help with collision
detection consistency (rest info could be lost if recovery was too much)
-Adaptive min contact depth (based on margin) instead of space parameter
2021-10-05 17:00:55 -07:00
Daniel
57b3b5108a Added wakeup() call to velocity, force and impulse functions. 2021-09-28 19:00:10 +13:00
PouleyKetchoupp
bb6760a09f Optimize raycast with large Heightmap shape data
Port raycast accelerator from Bullet's btHeightfieldTerrainShape.
2021-09-06 15:59:47 -07:00
Camille Mohr-Daurat
095dea7b71
Merge pull request #48551 from nekomatata/concave-shape-optimization-3.x
[3.x] Optimize area detection and intersect_shape queries with concave shapes
2021-09-06 09:36:27 -07:00
LoipesMas
32965aa0ab Epsilon check for angular velocity in BodySW 2021-08-16 20:11:46 +02:00
PouleyKetchoupp
da159cd258 Fix 3D moving platform logic
Same thing that was already done in 2D, applies moving platform motion
by using a call to move_and_collide that excludes the platform itself,
instead of making it part of the body motion.

Helps with handling walls and slopes correctly when the character walks
on the moving platform.

Also made some minor adjustments to the 2D version and documentation.

Co-authored-by: fabriceci <fabricecipolla@gmail.com>
2021-08-09 18:55:49 -07:00
Rémi Verschelde
0403cb8ad5
Merge pull request #51447 from nekomatata/fix-moving-platform-rotation-3.x
[3.x] Fix applied rotation from moving platforms in move_and_slide
2021-08-09 23:20:35 +02:00
PouleyKetchoupp
f101349225 Fix applied rotation from moving platforms in move_and_slide
When synchronizing KinematicBody motion with moving the platform using
direct body state, only the linear velocity was taken into account.

This change exposes velocity at local point in direct body state and
uses it in move_and_slide to get the proper velocity that includes
rotations.
2021-08-09 12:04:57 -07:00
lawnjelly
37f20e1d78 Fix Transform::xform(Plane) functions, add Transform unit tests
The Transform::xform and xform_inv are made safe for Planes when using non-uniform scaling.

Basic unit tests for Transform.

Optimization of calling sites to prevent loss of performance from the changes to xform(Plane).
2021-08-07 08:05:39 +01:00
PouleyKetchoupp
6fdffacb4e Fix GodotPhysics solver with kinematic body set to report contacts
In 3D, collision is disabled between kinematic/static bodies when
contacts are generated only to report them.

In 2D, this case was already fixed but the code is cleaned to make
it easier to follow.
2021-08-04 10:41:58 -07:00
Rémi Verschelde
801205b2c1
Merge pull request #48892 from lawnjelly/bvh_robust
BVH - thread safety option
2021-07-22 12:41:42 +02:00
PouleyKetchoupp
beeebb4c2f More accurate unsafe motion calculation
* Safe and unsafe motion are calculated by dichotomy with a limited
number of steps. It's good for performance, but on long motions that
either collide near the beginning or near the end, the result can be
very imprecise.
* Now a factor 0.25 or 0.75 is used to converge faster when this case
happens, which allows longer motions to get more accurate collision
detection.
* Makes snap collision more precise, and helps with cases where diagonal collision on the border of a platform can lead to the character being stuck.

Additional improvements to move_and_slide:
* Handle slide canceling in move_and_collide with 0 velocity instead of
not applying it.
* Better handling of snap with custom logic to cancel sliding.
* Remove small jittering when using stop on slope, by canceling the
motion completely when the resulting motion is less than margin instead
of always projecting to the up direction (in both body motion and snap).

Co-authored-by: fabriceci <fabricecipolla@gmail.com>
2021-07-19 08:09:17 -07:00
PouleyKetchoupp
2fbb6fff4e Fix move_and_collide causing sliding on slopes
Make sure the direction of the motion is preserved, unless the depth is
higher than the margin, which means the body needs depenetration in any
direction.

Also changed move_and_slide to avoid sliding on the first motion, in
order to avoid issues with unstable position on ground when jumping.

Co-authored-by: fabriceci <fabricecipolla@gmail.com>
2021-07-19 08:09:16 -07:00
Hugo Locurcio
9259b4adc4
Add a method to set the number of physics solver iterations in 3D
This is only for GodotPhysics, and adds a 3D counterpart to the 2D
method that was recently added.
2021-07-10 16:29:41 +02:00
PouleyKetchoupp
10fdd196b7 Fix and clean disabled shapes handling in godot physics servers
In 3D, disabled shapes are now not added to the broadphase anymore.
Since they are removed right away when disabled, no need to check for
disabled shapes for any query that comes from the broadphase.
Also Fixes raycast queries returning disabled shapes.

In 2D, disabled shapes where already not added to the broadphase.
Remove the same unnecessary checks as in 3D.

Overall harmonized API for disabled shapes in the physics servers and
removed duplicate method.
2021-06-22 16:48:24 -07:00
PouleyKetchoupp
c3107349a4 Ignore disabled shapes for mass property calculations 2021-06-17 17:17:05 -07:00
Marcel Admiraal
01dd6b0593 Apply infinite inertia checks to Godot physics 3D 2021-06-11 09:24:58 +01:00
Rémi Verschelde
80e1585a6e
Style: Cleanup uses of double spaces between words
Or after punctuation. Tried to leave third-party stuff alone, unless it has
been heavily modified for Godot.

(cherry picked from commit c1c76850cb)
2021-06-07 12:06:59 +02:00
Arkadiusz Marcin Kołek
7f14210a4c
Avoid division by zero when calculating inertias for bodies with colliders without areas.
(cherry picked from commit e347baddf3)
2021-06-01 12:53:31 +02:00
lawnjelly
14ce176f10 BVH - thread safety option
Added optional thread safe version through template argument and runtime switch, that wraps access with a mutex.
2021-05-25 10:47:32 +01:00
Morris Tabor
ba396caefc Replace QuickHull with Bullet's convex hull computer.
The code is based on the current version of thirdparty/vhacd and modified to use Godot's types and code style.

Additional changes:
- backported and extended PagedAllocator to allow leaked objects
- applied patch from https://github.com/bulletphysics/bullet3/pull/3037
2021-05-22 08:16:43 +02:00
Rémi Verschelde
eb78f80f03
Fix typos with codespell
Using codespell 2.0.0.

Method:
```
$ cat > ../godot-word-whitelist.txt << EOF
ang
curvelinear
dof
doubleclick
fave
findn
GIRD
leapyear
lod
merchantibility
nd
numer
ois
ony
que
seeked
synching
te
uint
unselect
webp
EOF

$ codespell -w -q 3 -I ../godot-word-whitelist.txt --skip="./thirdparty,*.po"
$ git diff // undo unwanted changes
```
2021-05-20 12:56:56 +02:00
PouleyKetchoupp
ea0015a8a6 Optimize area detection and intersect_shape queries with concave shapes
Whenever contact points are not needed, collision checks with concave
shapes (triangle mesh and heightmap) stop at the first colliding
triangle.
2021-05-07 19:19:41 -07:00
Rémi Verschelde
140350d767
Style: Enforce braces around if blocks and loops
Using clang-tidy's `readability-braces-around-statements`.
https://clang.llvm.org/extra/clang-tidy/checks/readability-braces-around-statements.html
2021-05-05 15:02:01 +02:00
PouleyKetchoupp
0dacc681b6 Fixed unnecessary bvh tree updates when calling set_pairable
Dynamic BVH doesn't update the tree anymore when calling set_pairable
with no parameter change.

Also modified Godot Physics broadphase to create objects directly with
pairable (static) set correctly to make use of this optimization for the
BVH broadphase.

Note: Octree broadphase doesn't use this optimization because it forces
an update on move, so passing the proper AABB and static parameters on
creation would cause the tree to update twice.
2021-05-04 12:24:31 -07:00
Rémi Verschelde
0c8b5b5c4d
Style: Remove redundant void argument lists
Using clang-tidy's `modernize-redundant-void-arg`.
https://clang.llvm.org/extra/clang-tidy/checks/modernize-redundant-void-arg.html
2021-05-04 16:40:33 +02:00
Rémi Verschelde
b4af1eba0a
Style: Enforce use of bool literals instead of integers
Using clang-tidy's `modernize-use-bool-literals`.
https://clang.llvm.org/extra/clang-tidy/checks/modernize-use-bool-literals.html
2021-05-04 16:39:13 +02:00
Rémi Verschelde
a828398655
Style: Replaces uses of 0/NULL by nullptr (C++11)
Using clang-tidy's `modernize-use-nullptr`.
https://clang.llvm.org/extra/clang-tidy/checks/modernize-use-nullptr.html
2021-05-04 16:30:23 +02:00
Rémi Verschelde
b5e1e05ef2
Style: clang-format: Disable KeepEmptyLinesAtTheStartOfBlocks 2021-05-04 14:45:16 +02:00
Rémi Verschelde
64a63e0861
Style: clang-format: Disable AllowShortCaseLabelsOnASingleLine 2021-05-04 14:45:15 +02:00
Rémi Verschelde
3d15f04668
Style: clang-format: Disable AllowShortIfStatementsOnASingleLine 2021-05-04 14:45:15 +02:00
Rémi Verschelde
a706fb11e5
Merge pull request #47943 from nekomatata/joint-check-body-types-3.x
[3.x] Fix errors related to joints setup with two non-dynamic bodies
2021-04-28 16:58:23 +02:00
Rémi Verschelde
f85d59c97f
Merge pull request #47349 from nekomatata/heightmap-support-3.x
[3.x] Heightmap collision shape support in Godot Physics
2021-04-28 16:57:29 +02:00
PouleyKetchoupp
64b11b6126 Fix errors related to joints setup with two non-dynamic bodies 2021-04-15 17:53:15 -07:00
Marcel Admiraal
28c7b3a17d Ensure ConvexPolygonShape support count variable is initialised 2021-04-06 16:46:04 +01:00
Rémi Verschelde
ab4c73604d
Merge pull request #44696 from madmiraal/fix-44632-3.2
[3.x] Remove all elements from monitored_bodies and monitored_areas when processed
2021-03-26 16:34:27 +01:00
PouleyKetchoupp
3ea72b273d Heightmap collision shape support in Godot Physics 2021-03-25 16:52:20 -07:00
Josh Jones
9327052bed [Godot Physics]: Correct typo in moment of inertia calculations.
The moment of inertia calculation for BoxShape is:

```
Vector3(
    (p_mass / 3.0) * (ly * ly + lz * lz), 
    (p_mass / 3.0) * (lx * lx + lz * lz), 
    (p_mass / 3.0) * (lx * lx + ly * ly));
```

where the final line includes both the x and y extents.

However, for CapsuleShape3D, CylinderShape3D, ConvexPolygonShape3D, ConcavePolygonShape3D, and HeightMapShape3D, the final line read `(p_mass / 3.0) * (extents.y * extents.y + extents.y * extents.y)`.  I believe this is a mistake, considering the comment in each case mentions using an AABB approximation, which should follow the same approach as BoxShape.

This change corrects the final line to include both the x and y components of the shape's extent.
2021-03-22 20:23:39 -07:00
e344fde6bf
9671f8ff4b [3.3] Fix some angular velocity calculations
The angular velocity estimate for kinematic bodies was calculated
incorrectly. Also, fixes its use in some kinematic/rigid collision
calculations.

3.3 version of #47130
2021-03-20 16:58:04 +10:00
Rémi Verschelde
dae319355f
Merge pull request #47068 from nekomatata/cylinder-fix-margins-3.2
[3.3] Fix Cylinder shape collision with margins when using GJK-EPA
2021-03-17 11:05:46 +01:00