Skip to content

Commit

Permalink
Use GlobalTransform, closes #172
Browse files Browse the repository at this point in the history
  • Loading branch information
Shatur committed May 27, 2022
1 parent 563bec4 commit 80dd8fb
Show file tree
Hide file tree
Showing 26 changed files with 436 additions and 283 deletions.
24 changes: 13 additions & 11 deletions bevy_rapier2d/examples/boxes2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@ fn main() {
}

fn setup_graphics(mut commands: Commands) {
let mut camera = OrthographicCameraBundle::new_2d();
camera.transform = Transform {
translation: Vec3::new(0.0, 20.0, 0.0),
..Transform::identity()
};
commands.spawn_bundle(camera);
commands.spawn_bundle(OrthographicCameraBundle {
transform: Transform::from_xyz(0.0, 20.0, 0.0),
..OrthographicCameraBundle::new_2d()
});
}

pub fn setup_physics(mut commands: Commands) {
Expand All @@ -34,9 +32,11 @@ pub fn setup_physics(mut commands: Commands) {
let ground_height = 10.0;

commands
.spawn()
.insert(Collider::cuboid(ground_size, ground_height))
.insert(Transform::from_xyz(0.0, 0.0 * -ground_height, 0.0));
.spawn_bundle(TransformBundle {
local: Transform::from_xyz(0.0, 0.0 * -ground_height, 0.0),
..Default::default()
})
.insert(Collider::cuboid(ground_size, ground_height));

/*
* Create the cubes
Expand All @@ -56,9 +56,11 @@ pub fn setup_physics(mut commands: Commands) {
let y = j as f32 * shift + centery + 30.0;

commands
.spawn()
.spawn_bundle(TransformBundle {
local: Transform::from_xyz(x, y, 0.0),
..Default::default()
})
.insert(RigidBody::Dynamic)
.insert(Transform::from_xyz(x, y, 0.0))
.insert(Collider::cuboid(rad, rad));
}

Expand Down
28 changes: 16 additions & 12 deletions bevy_rapier2d/examples/contact_filter2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,10 @@ fn main() {
}

fn setup_graphics(mut commands: Commands) {
let mut camera = OrthographicCameraBundle::new_2d();
camera.transform = Transform {
translation: Vec3::new(0.0, 20.0, 0.0),
..Transform::identity()
};
commands.spawn_bundle(camera);
commands.spawn_bundle(OrthographicCameraBundle {
transform: Transform::from_xyz(0.0, 20.0, 0.0),
..OrthographicCameraBundle::new_2d()
});
}

pub fn setup_physics(mut commands: Commands) {
Expand All @@ -66,15 +64,19 @@ pub fn setup_physics(mut commands: Commands) {
let ground_size = 100.0;

commands
.spawn()
.spawn_bundle(TransformBundle {
local: Transform::from_xyz(0.0, -100.0, 0.0),
..Default::default()
})
.insert(Collider::cuboid(ground_size, 12.0))
.insert(Transform::from_xyz(0.0, -100.0, 0.0))
.insert(CustomFilterTag::GroupA);

commands
.spawn()
.spawn_bundle(TransformBundle {
local: Transform::from_xyz(0.0, 0.0, 0.0),
..Default::default()
})
.insert(Collider::cuboid(ground_size, 12.0))
.insert(Transform::from_xyz(0.0, 0.0, 0.0))
.insert(CustomFilterTag::GroupB);

/*
Expand All @@ -97,10 +99,12 @@ pub fn setup_physics(mut commands: Commands) {
group_id += 1;

commands
.spawn()
.spawn_bundle(TransformBundle {
local: Transform::from_xyz(x, y, 0.0),
..Default::default()
})
.insert(RigidBody::Dynamic)
.insert(Collider::cuboid(rad, rad))
.insert(Transform::from_xyz(x, y, 0.0))
.insert(ActiveHooks::FILTER_CONTACT_PAIRS)
.insert(tags[group_id % 2])
.insert(ColliderDebugColor(colors[group_id % 2]));
Expand Down
26 changes: 14 additions & 12 deletions bevy_rapier2d/examples/custom_system_setup2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ impl SpecialStagingPlugin {

impl SpecialStagingPlugin {
fn build(self, app: &mut App) {
app.add_stage_before(
app.add_stage_after(
CoreStage::Update,
"special_staging_plugin_stage",
SpecialStage::new(self.schedule),
Expand Down Expand Up @@ -123,12 +123,10 @@ fn despawn_one_box(
}

fn setup_graphics(mut commands: Commands) {
let mut camera = OrthographicCameraBundle::new_2d();
camera.transform = Transform {
translation: Vec3::new(0.0, 20.0, 0.0),
..Transform::identity()
};
commands.spawn_bundle(camera);
commands.spawn_bundle(OrthographicCameraBundle {
transform: Transform::from_xyz(0.0, 20.0, 0.0),
..OrthographicCameraBundle::new_2d()
});
}

pub fn setup_physics(mut commands: Commands) {
Expand All @@ -139,9 +137,11 @@ pub fn setup_physics(mut commands: Commands) {
let ground_height = 10.0;

commands
.spawn()
.insert(Collider::cuboid(ground_size, ground_height))
.insert(Transform::from_xyz(0.0, 0.0 * -ground_height, 0.0));
.spawn_bundle(TransformBundle {
local: Transform::from_xyz(0.0, 0.0 * -ground_height, 0.0),
..Default::default()
})
.insert(Collider::cuboid(ground_size, ground_height));

/*
* Create the cubes
Expand All @@ -161,9 +161,11 @@ pub fn setup_physics(mut commands: Commands) {
let y = j as f32 * shift + centery + 30.0;

commands
.spawn()
.spawn_bundle(TransformBundle {
local: Transform::from_xyz(x, y, 0.0),
..Default::default()
})
.insert(RigidBody::Dynamic)
.insert(Transform::from_xyz(x, y, 0.0))
.insert(Collider::cuboid(rad, rad));
}

Expand Down
14 changes: 6 additions & 8 deletions bevy_rapier2d/examples/debug_despawn2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,17 +129,16 @@ fn setup_board(commands: &mut Commands, game: &Game) {

// Add floor
commands
.spawn()
.insert_bundle(SpriteBundle {
.spawn_bundle(SpriteBundle {
sprite: Sprite {
color: Color::rgb(0.5, 0.5, 0.5),
custom_size: Some(Vec2::new(game.n_lanes as f32 * 30.0, 60.0)),
..Default::default()
},
transform: Transform::from_xyz(0.0, floor_y - 30.0 * 0.5, 0.0),
..Default::default()
})
.insert(RigidBody::Fixed)
.insert(Transform::from_xyz(0.0, floor_y - 30.0 * 0.5, 0.0))
.insert(Collider::cuboid(
game.n_lanes as f32 * 30.0 / 2.0,
60.0 / 2.0,
Expand Down Expand Up @@ -202,17 +201,16 @@ fn spawn_block(
let linear_damping = 3.0;

commands
.spawn()
.insert_bundle(SpriteBundle {
.spawn_bundle(SpriteBundle {
sprite: Sprite {
color: game.cube_colors[kind as usize],
custom_size: Some(Vec2::new(30.0, 30.0)),
..Default::default()
},
transform: Transform::from_xyz(x, y, 0.0),
..Default::default()
})
.insert(RigidBody::Dynamic)
.insert(Transform::from_xyz(x, y, 0.0))
.insert(Damping {
linear_damping,
angular_damping: 0.0,
Expand All @@ -225,7 +223,7 @@ fn spawn_block(
fn cube_sleep_detection(
mut commands: Commands,
mut game: ResMut<Game>,
block_query: Query<(Entity, &Transform)>,
block_query: Query<(Entity, &GlobalTransform)>,
) {
let all_blocks_sleeping = true;

Expand All @@ -245,7 +243,7 @@ fn cube_sleep_detection(
fn clear_filled_rows(
commands: &mut Commands,
game: &mut Game,
block_query: Query<(Entity, &Transform)>,
block_query: Query<(Entity, &GlobalTransform)>,
) {
let mut blocks_per_row: Vec<Vec<Entity>> = (0..game.n_rows).map(|_| vec![]).collect();

Expand Down
32 changes: 18 additions & 14 deletions bevy_rapier2d/examples/despawn2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,10 @@ fn main() {
}

fn setup_graphics(mut commands: Commands) {
let mut camera = OrthographicCameraBundle::new_2d();
camera.transform = Transform {
translation: Vec3::new(0.0, 20.0, 0.0),
..Transform::identity()
};
commands.spawn_bundle(camera);
commands.spawn_bundle(OrthographicCameraBundle {
transform: Transform::from_xyz(0.0, 20.0, 0.0),
..OrthographicCameraBundle::new_2d()
});
}

pub fn setup_physics(
Expand All @@ -57,14 +55,18 @@ pub fn setup_physics(
despawn.entities.push(entity);

commands
.spawn()
.insert(Collider::cuboid(12.0, ground_size * 2.0))
.insert(Transform::from_xyz(ground_size, ground_size * 2.0, 0.0));
.spawn_bundle(TransformBundle {
local: Transform::from_xyz(ground_size, ground_size * 2.0, 0.0),
..Default::default()
})
.insert(Collider::cuboid(12.0, ground_size * 2.0));

commands
.spawn()
.insert(Collider::cuboid(12.0, ground_size * 2.0))
.insert(Transform::from_xyz(-ground_size, ground_size * 2.0, 0.0));
.spawn_bundle(TransformBundle {
local: Transform::from_xyz(-ground_size, ground_size * 2.0, 0.0),
..Default::default()
})
.insert(Collider::cuboid(12.0, ground_size * 2.0));

/*
* Create the cubes
Expand All @@ -82,10 +84,12 @@ pub fn setup_physics(
let y = j as f32 * shift + centery + 2.0;

let entity = commands
.spawn()
.spawn_bundle(TransformBundle {
local: Transform::from_xyz(x, y, 0.0),
..Default::default()
})
.insert(RigidBody::Dynamic)
.insert(Collider::cuboid(rad, rad))
.insert(Transform::from_xyz(x, y, 0.0))
.id();

if (i + j * num) % 100 == 0 {
Expand Down
22 changes: 14 additions & 8 deletions bevy_rapier2d/examples/events2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,26 @@ pub fn setup_physics(mut commands: Commands) {
* Ground
*/
commands
.spawn()
.insert(Collider::cuboid(80.0, 20.0))
.insert(Transform::from_xyz(0.0, -24.0, 0.0));
.spawn_bundle(TransformBundle {
local: Transform::from_xyz(0.0, -24.0, 0.0),
..Default::default()
})
.insert(Collider::cuboid(80.0, 20.0));

commands
.spawn()
.spawn_bundle(TransformBundle {
local: Transform::from_xyz(0.0, 100.0, 0.0),
..Default::default()
})
.insert(Collider::cuboid(80.0, 30.0))
.insert(Sensor(true))
.insert(Transform::from_xyz(0.0, 100.0, 0.0));
.insert(Sensor(true));

commands
.spawn()
.spawn_bundle(TransformBundle {
local: Transform::from_xyz(0.0, 260.0, 0.0),
..Default::default()
})
.insert(RigidBody::Dynamic)
.insert(Collider::cuboid(10.0, 10.0))
.insert(Transform::from_xyz(0.0, 260.0, 0.0))
.insert(ActiveEvents::COLLISION_EVENTS);
}
16 changes: 8 additions & 8 deletions bevy_rapier2d/examples/joints2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@ fn main() {
}

fn setup_graphics(mut commands: Commands) {
let mut camera = OrthographicCameraBundle::new_2d();
camera.transform = Transform {
translation: Vec3::new(0.0, -200.0, 0.0),
..Transform::identity()
};
commands.spawn_bundle(camera);
commands.spawn_bundle(OrthographicCameraBundle {
transform: Transform::from_xyz(0.0, -200.0, 0.0),
..OrthographicCameraBundle::new_2d()
});
}

pub fn setup_physics(mut commands: Commands) {
Expand All @@ -47,9 +45,11 @@ pub fn setup_physics(mut commands: Commands) {
};

let child_entity = commands
.spawn()
.spawn_bundle(TransformBundle {
local: Transform::from_xyz(fk * shift, -fi * shift, 0.0),
..Default::default()
})
.insert(rigid_body)
.insert(Transform::from_xyz(fk * shift, -fi * shift, 0.0))
.insert(Collider::cuboid(rad, rad))
.id();

Expand Down
16 changes: 8 additions & 8 deletions bevy_rapier2d/examples/joints_despawn2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,10 @@ fn main() {
}

fn setup_graphics(mut commands: Commands) {
let mut camera = OrthographicCameraBundle::new_2d();
camera.transform = Transform {
translation: Vec3::new(0.0, -200.0, 0.0),
..Transform::identity()
};
commands.spawn_bundle(camera);
commands.spawn_bundle(OrthographicCameraBundle {
transform: Transform::from_xyz(0.0, -200.0, 0.0),
..OrthographicCameraBundle::new_2d()
});
}

pub fn setup_physics(mut commands: Commands, mut despawn: ResMut<DespawnResource>) {
Expand All @@ -54,9 +52,11 @@ pub fn setup_physics(mut commands: Commands, mut despawn: ResMut<DespawnResource
};

let child_entity = commands
.spawn()
.spawn_bundle(TransformBundle {
local: Transform::from_xyz(fk * shift, -fi * shift, 0.0),
..Default::default()
})
.insert(rigid_body)
.insert(Transform::from_xyz(fk * shift, -fi * shift, 0.0))
.insert(Collider::cuboid(rad, rad))
.id();

Expand Down
Loading

0 comments on commit 80dd8fb

Please sign in to comment.