Skip to content

Commit

Permalink
adapt to changes from dimforge/bevy_rapier#585
Browse files Browse the repository at this point in the history
  • Loading branch information
Vrixyz committed Oct 15, 2024
1 parent 1e631b7 commit 2901672
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 128 deletions.
3 changes: 2 additions & 1 deletion docs-examples/2d/bevy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ edition = "2021"

[dependencies]
bevy = "0.14"
bevy_rapier2d = "0.27"
# bevy_rapier2d = "0.28"
bevy_rapier2d = { path = "../../../../bevy_rapier/bevy_rapier2d" }
12 changes: 8 additions & 4 deletions docs-examples/2d/bevy/examples/advanced_collision_detection2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,10 @@ fn display_events(
// DOCUSAURUS: Events stop

// DOCUSAURUS: ContactGraph1 start
fn display_contact_info(rapier_context: Res<RapierContext>, custom_info: Res<CustomInfo>) {
fn display_contact_info(rapier_context: ReadRapierContext, custom_info: Res<CustomInfo>) {
let entity1 = custom_info.entity1; // A first entity with a collider attached.
let entity2 = custom_info.entity2; // A second entity with a collider attached.
let rapier_context = rapier_context.single();

/* Find the contact pair, if it exists, between two colliders. */
if let Some(contact_pair) = rapier_context.contact_pair(entity1, entity2) {
Expand Down Expand Up @@ -121,10 +122,11 @@ fn display_contact_info(rapier_context: Res<RapierContext>, custom_info: Res<Cus

// DOCUSAURUS: ContactGraph2 start
fn display_contact_info_all_from_1_entity(
rapier_context: Res<RapierContext>,
rapier_context: ReadRapierContext,
custom_info: Res<CustomInfo>,
) {
let entity = custom_info.entity2; // An entity with a collider attached.
let rapier_context = rapier_context.single();

/* Iterate through all the contact pairs involving a specific collider. */
for contact_pair in rapier_context.contact_pairs_with(entity) {
Expand All @@ -141,9 +143,10 @@ fn display_contact_info_all_from_1_entity(
// DOCUSAURUS: ContactGraph2 stop

// DOCUSAURUS: IntersectionGraph1 start
fn display_intersection_info(rapier_context: Res<RapierContext>, custom_info: Res<CustomInfo>) {
fn display_intersection_info(rapier_context: ReadRapierContext, custom_info: Res<CustomInfo>) {
let entity1 = custom_info.entity1; // A first entity with a collider attached.
let entity2 = custom_info.entity2; // A second entity with a collider attached.
let rapier_context = rapier_context.single();

/* Find the intersection pair, if it exists, between two colliders. */
if rapier_context.intersection_pair(entity1, entity2) == Some(true) {
Expand All @@ -157,10 +160,11 @@ fn display_intersection_info(rapier_context: Res<RapierContext>, custom_info: Re

// DOCUSAURUS: IntersectionGraph2 start
fn display_intersection_info_all_from_1_entity(
rapier_context: Res<RapierContext>,
rapier_context: ReadRapierContext,
custom_info: Res<CustomInfo>,
) {
let entity = custom_info.entity2; // An entity with a collider attached.
let rapier_context = rapier_context.single();

/* Iterate through all the intersection pairs involving a specific collider. */
for (collider1, collider2, intersecting) in rapier_context.intersection_pairs_with(entity) {
Expand Down
19 changes: 13 additions & 6 deletions docs-examples/2d/bevy/examples/scene_queries2.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use bevy::{prelude::*, render::primitives::Aabb};
use bevy_rapier2d::{parry::query::intersection_test, prelude::*};
use bevy_rapier2d::prelude::*;

#[derive(PartialEq, Eq, Clone, Copy, Component)]
struct CustomData {
Expand Down Expand Up @@ -46,13 +46,15 @@ fn setup_physics(mut commands: Commands) {

// DOCUSAURUS: Raycast start
/* Cast a ray inside of a system. */
fn cast_ray(rapier_context: Res<RapierContext>) {
fn cast_ray(rapier_context: ReadRapierContext) {
let ray_pos = Vec2::new(1.0, 2.0);
let ray_dir = Vec2::new(0.0, 1.0);
let max_toi = 4.0;
let solid = true;
let filter = QueryFilter::default();

let rapier_context = rapier_context.single();

if let Some((entity, toi)) = rapier_context.cast_ray(ray_pos, ray_dir, max_toi, solid, filter) {
// The first collider hit has the entity `entity` and it hit after
// the ray travelled a distance equal to `ray_dir * toi`.
Expand Down Expand Up @@ -95,7 +97,7 @@ fn cast_ray(rapier_context: Res<RapierContext>) {

// DOCUSAURUS: Shapecast start
/* Cast a shape inside of a system. */
fn cast_shape(rapier_context: Res<RapierContext>) {
fn cast_shape(rapier_context: ReadRapierContext) {
let shape = Collider::cuboid(1.0, 2.0);
let shape_pos = Vec2::new(1.0, 2.0);
let shape_rot = 0.8;
Expand All @@ -107,6 +109,7 @@ fn cast_shape(rapier_context: Res<RapierContext>) {
stop_at_penetration: false,
compute_impact_geometry_on_penetration: false,
};
let rapier_context = rapier_context.single();

if let Some((entity, hit)) =
rapier_context.cast_shape(shape_pos, shape_rot, shape_vel, &shape, options, filter)
Expand All @@ -123,11 +126,12 @@ fn cast_shape(rapier_context: Res<RapierContext>) {

// DOCUSAURUS: PointProjection start
/* Project a point inside of a system. */
fn project_point(rapier_context: Res<RapierContext>) {
fn project_point(rapier_context: ReadRapierContext) {
let point = Vec2::new(1.0, 2.0);
let solid = true;
let filter = QueryFilter::default();

let rapier_context = rapier_context.single();
if let Some((entity, projection)) = rapier_context.project_point(point, solid, filter) {
// The collider closest to the point has this `handle`.
println!(
Expand All @@ -151,12 +155,13 @@ fn project_point(rapier_context: Res<RapierContext>) {

// DOCUSAURUS: IntersectionTest start
/* Test intersections inside of a system. */
fn test_intersections(rapier_context: Res<RapierContext>) {
fn test_intersections(rapier_context: ReadRapierContext) {
let shape = Collider::cuboid(1.0, 2.0);
let shape_pos = Vec2::new(0.0, 1.0);
let shape_rot = 0.8;
let filter = QueryFilter::default();

let rapier_context = rapier_context.single();
rapier_context.intersections_with_shape(shape_pos, shape_rot, &shape, filter, |entity| {
println!("The entity {:?} intersects our shape.", entity);
true // Return `false` instead if we want to stop searching for other colliders that contain this point.
Expand All @@ -176,11 +181,13 @@ fn test_intersections(rapier_context: Res<RapierContext>) {
// DOCUSAURUS: QueryFilter start
/* Cast a ray inside of a system. */
fn cast_ray_filtered(
rapier_context: Res<RapierContext>,
rapier_context: ReadRapierContext,
player_query: Query<Entity, With<Player>>,
custom_data_query: Query<&CustomData>,
) {
let player_handle = player_query.single();
let rapier_context = rapier_context.single();

let ray_pos = Vec2::new(1.0, 2.0);
let ray_dir = Vec2::new(0.0, 1.0);
let max_toi = 4.0;
Expand Down
3 changes: 2 additions & 1 deletion docs-examples/3d/bevy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ edition = "2021"

[dependencies]
bevy = "0.14"
bevy_rapier3d = "0.27"
# bevy_rapier3d = "0.27"
bevy_rapier3d = { path = "../../../../bevy_rapier/bevy_rapier3d" }
14 changes: 9 additions & 5 deletions docs-examples/3d/bevy/examples/scene_queries3.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use bevy::prelude::*;
use bevy::render::primitives::Aabb;
use bevy_rapier3d::prelude::*;
use bevy_rapier3d::rapier::geometry::InteractionGroups;

fn main() {
App::new()
Expand Down Expand Up @@ -41,7 +40,9 @@ fn setup_physics(mut commands: Commands) {

// DOCUSAURUS: Raycast start
/* Cast a ray inside of a system. */
fn cast_ray(rapier_context: Res<RapierContext>) {
fn cast_ray(rapier_context: ReadRapierContext) {
let rapier_context = rapier_context.single();

let ray_pos = Vec3::new(1.0, 2.0, 3.0);
let ray_dir = Vec3::new(0.0, 1.0, 0.0);
let max_toi = 4.0;
Expand Down Expand Up @@ -90,7 +91,8 @@ fn cast_ray(rapier_context: Res<RapierContext>) {

// DOCUSAURUS: Shapecast start
/* Cast a shape inside of a system. */
fn cast_shape(rapier_context: Res<RapierContext>) {
fn cast_shape(rapier_context: ReadRapierContext) {
let rapier_context = rapier_context.single();
let shape = Collider::cuboid(1.0, 2.0, 3.0);
let shape_pos = Vec3::new(1.0, 2.0, 3.0);
let shape_rot = Quat::from_rotation_z(0.8);
Expand Down Expand Up @@ -118,7 +120,8 @@ fn cast_shape(rapier_context: Res<RapierContext>) {

// DOCUSAURUS: PointProjection start
/* Project a point inside of a system. */
fn project_point(rapier_context: Res<RapierContext>) {
fn project_point(rapier_context: ReadRapierContext) {
let rapier_context = rapier_context.single();
let point = Vec3::new(1.0, 2.0, 3.0);
let solid = true;
let filter = QueryFilter::default();
Expand Down Expand Up @@ -146,7 +149,8 @@ fn project_point(rapier_context: Res<RapierContext>) {

// DOCUSAURUS: IntersectionTest start
/* Test intersections inside of a system. */
fn test_intersections(rapier_context: Res<RapierContext>) {
fn test_intersections(rapier_context: ReadRapierContext) {
let rapier_context = rapier_context.single();
let shape = Collider::cuboid(1.0, 2.0, 3.0);
let shape_pos = Vec3::new(0.0, 1.0, 2.0);
let shape_rot = Quat::from_rotation_z(0.8);
Expand Down
110 changes: 6 additions & 104 deletions docs-examples/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/user_guides/templates/rigid_body_gravity.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import TabItem from '@theme/TabItem';
Gravity is such a common force that it is implemented as a special case (even if it could easily be implemented
by the user using [force application](#forces-and-impulses)). <rapier>The gravity is given as an argument to the
`PhysicsPipeline::step` method and can be modified at will by simply modifying that argument.</rapier><bevy>The gravity
is given by the field `RapierConfiguration::gravity` of the resource `RapierConfiguration` and can be modified at
is given by the field `RapierConfiguration::gravity` of the component `RapierConfiguration` and can be modified at
will.</bevy><js>The gravity is given to the constructor of the physics `World`. It can be modified by modifying the
field `World.gravity`.</js> Note however that a change of gravity won't automatically wake-up the
[sleeping bodies](#sleeping) so keep in mind that you may want to wake them up manually before a gravity change.
Expand Down
Loading

0 comments on commit 2901672

Please sign in to comment.