Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix shape not casting #48

Merged
merged 9 commits into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions .vscode/settings.json

This file was deleted.

54 changes: 29 additions & 25 deletions DOCUMENTATION.md → CONTRIBUTE.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,6 @@
# Documentation
# Build godot-cpp

## Build the Rapier 2D Extension

### Build godot-cpp

Official C++ bindings for Godot API (https://github.com/godotengine/godot-cpp)

Steps to build godot-cpp:
- Open a command line prompt in `godot-cpp/` folder
- Run `scons target=[TARGET] platform=[PLATFORM] debug_symbols=[DEBUG] dev_build=[DEBUG] -j[CORES]` with:
`[TARGET]`: `template_debug` for godot debug export and `template_release` for godot release export
`[PLATFORM]`: (optional) target platform if different from the current patform
`[DEBUG]`: (optional) `yes` to generate symbols and disable optimization for a debug build (useful only for debugging the extension)
`[CORES]`: (optional) number of cores to use in order to accelerate the build

Example:
Official C++ bindings for Godot API (https://github.com/godotengine/godot-cpp). In order to build the extension you need to build godot-cpp first.

```
cd godot-cpp
Expand All @@ -23,11 +9,13 @@ scons target=template_debug generate_bindings=yes

See [Building the C++ bindings](https://docs.godotengine.org/en/stable/tutorials/scripting/gdextension/gdextension_cpp_example.html#building-the-c-bindings) from the official documentation for more details about building the bindings.

### Build the Rapier 2D wrapper
# Build the Rapier 2D wrapper

Prerequisites:
- Install `cargo` for Rust support
Generate the C bindings header file (in `src/rapier2d-wrapper/includes/`)


1. Generate the C bindings header file (in `src/rapier2d-wrapper/includes/`)

Go to `src/rapier2d-wrapper` folder and run `cbindgen`

Expand All @@ -37,13 +25,13 @@ cargo install --force cbindgen
cbindgen --config cbindgen.toml --crate rapier2d-wrapper --output includes/rapier2d_wrapper.h
```

Compile the rust release Rapier2D library:
2. Compile the rust release Rapier2D library:

```
cargo build --release
```

### Compile the Rapier 2D extension
# Compile the Rapier 2D extension

This step will build the final Godot Rapier extension library.

Expand All @@ -61,11 +49,27 @@ scons target=template_debug generate_bindings=no

The library files will be found in `bin/addons/` folder.

## Function Documentation
# How to debug using VSCode

## Clone Godot repo

Take a look at `godot.code-workspace`. It's a workspace in VSCode. It loads both this folder, and another folder `../godot`. For this to work you have to clone the [godot](https://github.com/godotengine/godot) repo there.

## Build Godot

Then, you have to build the godot. Take a look at the tasks in `godot.code-workspace` for help. You can also try just running `scons` command without any arguments, and it will automatically select the platform and architecture based on what you are currently using.

## Run Godot from debugger inside VSCode

Click `Run and Debug` in VSCode on the left. With the workspace opened, select `Debug Scene Rapier`. This will start godot binary `godot.macos.editor.dev.arm64` and run scene from `godot-rapier-2d/Godot-Physics-Tests/test.tscn`. If you use a different binary(eg. windows), change the binary path. Same for the scene path.

Now you should be able to place breakpoints in the extension code. If you also want to place breakpoints in the rust code, you need to build that with debug. Take a look at `scripts/build-dev.sh` for help on how to do that.

# test_body_motion

## test_body_motion
This explains roughly the functionality of test_body_motion and how it's implemented.

### Step 1
## Step 1

We check if the body + margin collide something:
- if true:
Expand All @@ -75,12 +79,12 @@ We check if the body + margin collide something:
we depenetrate the body but not of the full penetration, 0,4
- if false: go to step 2

### Step 2
## Step 2

We apply the motion to the body and build a aabb from the body start to the body end.
We try the colliding distance (lower one). And we need two value: safe (when it does not collide), unsafe (where it collide)

### Step 3
## Step 3

- If collided:

Expand Down
61 changes: 14 additions & 47 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<div align="center">
<h1>Godot Rapier2D</h1>
</div>

<p align="center">
<img src="https://github.com/appsinacup/godot-rapier2d/blob/main/logo.jpg?raw=true" width="256px"/>
</p>
<p align="center">
<a href="https://github.com/appsinacup/godot-rapier-2d/actions/workflows/runner.yml">
<img src="https://github.com/appsinacup/godot-rapier-2d/actions/workflows/runner.yml/badge.svg?branch=main"
Expand All @@ -11,36 +10,29 @@
<a href="https://github.com/godotengine/godot-cpp" alt="Godot Version">
<img src="https://img.shields.io/badge/Godot-v4.2-%23478cbf?logo=godot-engine&logoColor=white" /></a>
<a href="https://github.com/appsinacup/godot-rapier-2d/graphs/contributors" alt="Contributors">
<img src="https://img.shields.io/github/contributors/appsinacup/godot-rapier-2d" /></a>
<a href="https://github.com/appsinacup/godot-rapier-2d/pulse" alt="Activity">
<img src="https://img.shields.io/github/commit-activity/m/appsinacup/godot-rapier-2d" /></a>
<a href="https://discord.gg/56dMud8HYn">
<img src="https://img.shields.io/discord/1138836561102897172?logo=discord"
alt="Chat on Discord"></a>
</p>

<img src="https://github.com/appsinacup/godot-rapier2d/blob/main/logo.jpg?raw=true"/>
A 2d [rapier](https://github.com/dimforge/rapier) physics server for [Godot Engine v4.2](https://github.com/godotengine/godot), implemented as a GDExtension.

# Features

- Parallel support (for non enhnanced determinism builds)
- Single and Double float precision build.
- SIMD (Single instruction, multiple data) build.
- Cross-platform determinism build.

<p align="center">
<img src="rapier-vid.gif"/>
</p>

A 2d [rapier](https://github.com/dimforge/rapier) physics server for [Godot Engine](https://github.com/godotengine/godot), implemented as a GDExtension.

## Table of Contents

1. [Limitations](#limitations)
2. [Supported Platforms](#supported-platforms)
3. [Installation](#installation)
4. [Features](#features)
5. [Comparison](#comparison)
6. [License](#license)

# Limitations

- SeparationRay2D missing [issues/5](https://github.com/appsinacup/godot-rapier-2d/issues/5)
- Web exports not working [issues/23](https://github.com/appsinacup/godot-rapier-2d/issues/23)
- Cross platform determinism isn't working [issues/47](https://github.com/appsinacup/godot-rapier-2d/issues/47)

# Supported Platforms

Expand All @@ -49,7 +41,7 @@ A 2d [rapier](https://github.com/dimforge/rapier) physics server for [Godot Engi
- Linux (x86_64)
- Android (x86_64, arm64)
- iOS (arm64)
- Web (wasm32)
- Web (wasm32)

# Installation

Expand All @@ -61,35 +53,10 @@ A 2d [rapier](https://github.com/dimforge/rapier) physics server for [Godot Engi

After installing, go to `Advanced Settings` -> `Physics` -> `2D`. Change `Physics Engine` to `Rapier2D`.

Video Tutorial:

[![Tutorial](https://img.youtube.com/vi/KgKWAZ49T9E/0.jpg)](https://www.youtube.com/watch?v=KgKWAZ49T9E)

# Features

- Parallel support (for non enhnanced determinism builds)
- Single and Double float precision build.
- SIMD (Single instruction, multiple data) build.
- Cross-platform determinism build.

# Comparison
# Contribute

Watch a comparison to Godot Physics 2D and [Box2D](https://github.com/appsinacup/godot-box-2d) physics plugin:

[![Comparison](https://img.youtube.com/vi/wgUiZ7E19eM/0.jpg)](https://www.youtube.com/watch?v=wgUiZ7E19eM)

Or read about it on [appsinacup.com/godot-physics-vs-box2d-vs-rapier2d](https://appsinacup.com/godot-physics-vs-box2d-vs-rapier2d/)


# Roadmap

- Fix all other issues from Limitations.
If you want to contribute, view [CONTRIBUTE.md](CONTRIBUTE.md) for more info.

# [Discord](https://discord.gg/56dMud8HYn)

A vibrant community for discussion, user support and showcases.

# License

All code in this repository is provided under the MIT license. See `LICENSE` for more details and `THIRDPARTY.txt` for third-party licenses.
This repo is a continuation of https://github.com/fabriceci/godot-rapier2d .
110 changes: 110 additions & 0 deletions godot-rapier.code-workspace
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
{
"folders": [
{
"name": "godot",
"path": "../godot"
},
{
"name": "godot-rapier-2d",
"path": "."
}
],
"settings": {
"rust-analyzer.linkedProjects": [
"${workspaceFolder:godot-rapier-2d}/src/rapier2d-wrapper/Cargo.toml"
],
"rust-analyzer.showUnlinkedFileNotification": false,
"lldb.launch.sourceMap": {
"src/": "${workspaceFolder:godot-rapier-2d}/src"
},
"files.associations": {
"vector": "cpp",
"chrono": "cpp",
"*.inc": "cpp",
"__bit_reference": "cpp",
"bitset": "cpp",
"map": "cpp",
"set": "cpp",
"unordered_map": "cpp",
"unordered_set": "cpp",
"algorithm": "cpp",
"__locale": "cpp",
"string": "cpp",
"string_view": "cpp",
"__config": "cpp"
}
},
"launch": {
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"program": "${workspaceFolder:godot}/bin/godot.macos.editor.arm64",
"type": "cppdbg",
"request": "launch",
"cwd": "${workspaceFolder:godot-rapier-2d}",
"osx": {
"MIMode": "lldb"
},
"args": [
"--path",
"${workspaceFolder:godot-rapier-2d}/Godot-Physics-Tests",
"--debug-collisions",
"test.tscn"
]
}
]
},
"tasks": {
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "godot build dev mac",
"command": "scons",
"args": [
"platform=macos",
"arch=arm64",
"tools=yes",
"target=editor",
"dev_build=true",
"debug_symbols=true",
"precision=single",
"--jobs=8"
],
"options": {
"cwd": "${workspaceFolder:godot}"
},
"problemMatcher": ["$gcc"],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "godot build dev"
},
{
"type": "shell",
"label": "godot build mac",
"command": "scons",
"args": [
"platform=macos",
"arch=arm64",
"tools=yes",
"target=editor",
"debug_symbols=false",
"precision=single",
"--jobs=8"
],
"options": {
"cwd": "${workspaceFolder:godot}"
},
"problemMatcher": ["$gcc"],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "build godot"
}
]
}
}
5 changes: 4 additions & 1 deletion src/rapier2d-wrapper/includes/rapier2d_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ struct WorldSettings {
Real sleep_angular_threshold;
Real sleep_time_until_sleep;
Real solver_prediction_distance;
size_t max_ccd_substeps;
};

struct PointHitInfo {
Expand Down Expand Up @@ -218,6 +219,7 @@ struct SimulationSettings {
/// Number of internal Project Gauss Seidel (PGS) iterations run at each solver iteration (default: `1`).
size_t num_internal_pgs_iterations;
Vector pixel_gravity;
size_t max_ccd_substeps;
};

extern "C" {
Expand Down Expand Up @@ -440,7 +442,8 @@ ShapeCastResult shape_casting(Handle world_handle,
bool collide_with_body,
bool collide_with_area,
QueryHandleExcludedCallback handle_excluded_callback,
const QueryExcludedInfo *handle_excluded_info);
const QueryExcludedInfo *handle_excluded_info,
bool ignore_intersecting);

ShapeCastResult shape_collide(const Vector *pixel_motion1,
ShapeInfo shape_info1,
Expand Down
1 change: 0 additions & 1 deletion src/rapier2d-wrapper/src/collider.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use rapier2d::na::ComplexField;
use rapier2d::na::Point2;
use rapier2d::na::Vector2;
use rapier2d::prelude::*;
Expand Down
5 changes: 3 additions & 2 deletions src/rapier2d-wrapper/src/physics_world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,10 @@ impl PhysicsWorld {

pub fn step(&mut self, settings : &SimulationSettings) {
let mut integration_parameters = IntegrationParameters::default();

integration_parameters.dt = settings.dt;
integration_parameters.erp = settings.erp;
integration_parameters.max_ccd_substeps = settings.max_ccd_substeps;
integration_parameters.damping_ratio = settings.damping_ratio;
integration_parameters.joint_erp = settings.joint_erp;
integration_parameters.joint_damping_ratio = settings.joint_damping_ratio;
Expand Down Expand Up @@ -243,7 +244,7 @@ impl PhysicsWorld {

if self.collision_event_callback.is_some() {
let callback = self.collision_event_callback.unwrap();
while let Ok((collision_event, contact_pair)) = collision_recv.try_recv() {
while let Ok((collision_event, _contact_pair)) = collision_recv.try_recv() {
let handle1 = collision_event.collider1();
let handle2 = collision_event.collider2();

Expand Down
Loading
Loading