Skip to content

Commit

Permalink
Update glam to 0.13.0. (#1550)
Browse files Browse the repository at this point in the history
See https://github.com/bitshifter/glam-rs/blob/master/CHANGELOG.md for details on changes.

Co-authored-by: Cameron Hart <[email protected]>
  • Loading branch information
bitshifter and Cameron Hart committed Mar 6, 2021
1 parent 0eba5f3 commit f61e44d
Show file tree
Hide file tree
Showing 29 changed files with 43 additions and 60 deletions.
2 changes: 1 addition & 1 deletion crates/bevy_core/src/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,6 @@ mod tests {

#[test]
fn test_mat4_round_trip() {
test_round_trip(Mat4::identity());
test_round_trip(Mat4::IDENTITY);
}
}
2 changes: 1 addition & 1 deletion crates/bevy_math/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ license = "MIT"
keywords = ["bevy"]

[dependencies]
glam = { version = "0.12.0", features = ["serde"] }
glam = { version = "0.13.0", features = ["serde"] }
bevy_reflect = { path = "../bevy_reflect", version = "0.4.0", features = ["bevy"] }
2 changes: 1 addition & 1 deletion crates/bevy_reflect/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ parking_lot = "0.11.0"
thiserror = "1.0"
serde = "1"
smallvec = { version = "1.4", features = ["serde"], optional = true }
glam = { version = "0.12.0", features = ["serde"], optional = true }
glam = { version = "0.13.0", features = ["serde"], optional = true }

[dev-dependencies]
ron = "0.6.2"
4 changes: 2 additions & 2 deletions crates/bevy_render/src/camera/camera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ impl Camera {
// Build a transform to convert from world to NDC using camera data
let world_to_ndc: Mat4 =
self.projection_matrix * camera_transform.compute_matrix().inverse();
let ndc_space_coords: Vec3 = world_to_ndc.transform_point3(world_position);
let ndc_space_coords: Vec3 = world_to_ndc.project_point3(world_position);
// NDC z-values outside of 0 < z < 1 are behind the camera and are thus not in screen space
if ndc_space_coords.z < 0.0 || ndc_space_coords.z > 1.0 {
return None;
}
// Once in NDC space, we can discard the z element and rescale x/y to fit the screen
let screen_space_coords = (ndc_space_coords.truncate() + Vec2::one()) / 2.0 * window_size;
let screen_space_coords = (ndc_space_coords.truncate() + Vec2::ONE) / 2.0 * window_size;
Some(screen_space_coords)
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_render/src/mesh/shape/torus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl From<Torus> for Mesh {
let z = theta.sin() * (torus.radius + torus.ring_radius * phi.cos());
let y = torus.ring_radius * phi.sin();

let normal = segment_pos.cross(Vec3::unit_y()).normalize();
let normal = segment_pos.cross(Vec3::Y).normalize();

positions.push([x, y, z]);
normals.push(normal.into());
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_text/src/text2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,14 @@ pub fn draw_text2d_system(
if let Some(text_glyphs) = text_pipeline.get_glyphs(&entity) {
let position = global_transform.translation
+ match text.alignment.vertical {
VerticalAlign::Top => Vec3::zero(),
VerticalAlign::Top => Vec3::ZERO,
VerticalAlign::Center => Vec3::new(0.0, -height * 0.5, 0.0),
VerticalAlign::Bottom => Vec3::new(0.0, -height, 0.0),
}
+ match text.alignment.horizontal {
HorizontalAlign::Left => Vec3::new(-width, 0.0, 0.0),
HorizontalAlign::Center => Vec3::new(-width * 0.5, 0.0, 0.0),
HorizontalAlign::Right => Vec3::zero(),
HorizontalAlign::Right => Vec3::ZERO,
};

let mut drawable_text = DrawableText {
Expand Down
12 changes: 6 additions & 6 deletions crates/bevy_transform/src/components/global_transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ impl GlobalTransform {
#[inline]
pub fn identity() -> Self {
GlobalTransform {
translation: Vec3::zero(),
rotation: Quat::identity(),
scale: Vec3::one(),
translation: Vec3::ZERO,
rotation: Quat::IDENTITY,
scale: Vec3::ONE,
}
}

Expand Down Expand Up @@ -78,19 +78,19 @@ impl GlobalTransform {
#[inline]
/// Get the unit vector in the local x direction
pub fn local_x(&self) -> Vec3 {
self.rotation * Vec3::unit_x()
self.rotation * Vec3::X
}

#[inline]
/// Get the unit vector in the local y direction
pub fn local_y(&self) -> Vec3 {
self.rotation * Vec3::unit_y()
self.rotation * Vec3::Y
}

#[inline]
/// Get the unit vector in the local z direction
pub fn local_z(&self) -> Vec3 {
self.rotation * Vec3::unit_z()
self.rotation * Vec3::Z
}

#[inline]
Expand Down
12 changes: 6 additions & 6 deletions crates/bevy_transform/src/components/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ impl Transform {
#[inline]
pub fn identity() -> Self {
Transform {
translation: Vec3::zero(),
rotation: Quat::identity(),
scale: Vec3::one(),
translation: Vec3::ZERO,
rotation: Quat::IDENTITY,
scale: Vec3::ONE,
}
}

Expand Down Expand Up @@ -78,19 +78,19 @@ impl Transform {
#[inline]
/// Get the unit vector in the local x direction
pub fn local_x(&self) -> Vec3 {
self.rotation * Vec3::unit_x()
self.rotation * Vec3::X
}

#[inline]
/// Get the unit vector in the local y direction
pub fn local_y(&self) -> Vec3 {
self.rotation * Vec3::unit_y()
self.rotation * Vec3::Y
}

#[inline]
/// Get the unit vector in the local z direction
pub fn local_z(&self) -> Vec3 {
self.rotation * Vec3::unit_z()
self.rotation * Vec3::Z
}

#[inline]
Expand Down
3 changes: 1 addition & 2 deletions examples/3d/3d_scene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ fn setup(
})
// camera
.spawn(PerspectiveCameraBundle {
transform: Transform::from_xyz(-2.0, 2.5, 5.0)
.looking_at(Vec3::default(), Vec3::unit_y()),
transform: Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::default(), Vec3::Y),
..Default::default()
});
}
2 changes: 1 addition & 1 deletion examples/3d/load_gltf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
})
.spawn(PerspectiveCameraBundle {
transform: Transform::from_xyz(0.7, 0.7, 1.0)
.looking_at(Vec3::new(0.0, 0.3, 0.0), Vec3::unit_y()),
.looking_at(Vec3::new(0.0, 0.3, 0.0), Vec3::Y),
..Default::default()
});
}
3 changes: 1 addition & 2 deletions examples/3d/msaa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ fn setup(
})
// camera
.spawn(PerspectiveCameraBundle {
transform: Transform::from_xyz(-3.0, 3.0, 5.0)
.looking_at(Vec3::default(), Vec3::unit_y()),
transform: Transform::from_xyz(-3.0, 3.0, 5.0).looking_at(Vec3::default(), Vec3::Y),
..Default::default()
});
}
2 changes: 1 addition & 1 deletion examples/3d/orthographic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ fn setup(
// set up the camera
let mut camera = OrthographicCameraBundle::new_3d();
camera.orthographic_projection.scale = 3.0;
camera.transform = Transform::from_xyz(5.0, 5.0, 5.0).looking_at(Vec3::zero(), Vec3::unit_y());
camera.transform = Transform::from_xyz(5.0, 5.0, 5.0).looking_at(Vec3::ZERO, Vec3::Y);

// add entities to the world
commands
Expand Down
3 changes: 1 addition & 2 deletions examples/3d/parenting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ fn setup(
})
// camera
.spawn(PerspectiveCameraBundle {
transform: Transform::from_xyz(5.0, 10.0, 10.0)
.looking_at(Vec3::default(), Vec3::unit_y()),
transform: Transform::from_xyz(5.0, 10.0, 10.0).looking_at(Vec3::default(), Vec3::Y),
..Default::default()
});
}
3 changes: 1 addition & 2 deletions examples/3d/spawner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ fn setup(
})
// camera
.spawn(PerspectiveCameraBundle {
transform: Transform::from_xyz(0.0, 15.0, 150.0)
.looking_at(Vec3::default(), Vec3::unit_y()),
transform: Transform::from_xyz(0.0, 15.0, 150.0).looking_at(Vec3::default(), Vec3::Y),
..Default::default()
});

Expand Down
3 changes: 1 addition & 2 deletions examples/3d/texture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@ fn setup(
})
// camera
.spawn(PerspectiveCameraBundle {
transform: Transform::from_xyz(3.0, 5.0, 8.0)
.looking_at(Vec3::default(), Vec3::unit_y()),
transform: Transform::from_xyz(3.0, 5.0, 8.0).looking_at(Vec3::default(), Vec3::Y),
..Default::default()
});
}
2 changes: 1 addition & 1 deletion examples/3d/update_gltf_scene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ fn setup(
})
.spawn(PerspectiveCameraBundle {
transform: Transform::from_xyz(1.05, 0.9, 1.5)
.looking_at(Vec3::new(0.0, 0.3, 0.0), Vec3::unit_y()),
.looking_at(Vec3::new(0.0, 0.3, 0.0), Vec3::Y),
..Default::default()
});

Expand Down
3 changes: 1 addition & 2 deletions examples/3d/wireframe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ fn setup(
})
// camera
.spawn(PerspectiveCameraBundle {
transform: Transform::from_xyz(-2.0, 2.5, 5.0)
.looking_at(Vec3::default(), Vec3::unit_y()),
transform: Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::default(), Vec3::Y),
..Default::default()
});
}
3 changes: 1 addition & 2 deletions examples/3d/z_sort_debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ fn setup(
})
// camera
.spawn(PerspectiveCameraBundle {
transform: Transform::from_xyz(5.0, 10.0, 10.0)
.looking_at(Vec3::default(), Vec3::unit_y()),
transform: Transform::from_xyz(5.0, 10.0, 10.0).looking_at(Vec3::default(), Vec3::Y),
..Default::default()
});
}
3 changes: 1 addition & 2 deletions examples/android/android.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ fn setup(
})
// camera
.spawn(PerspectiveCameraBundle {
transform: Transform::from_xyz(-2.0, 2.5, 5.0)
.looking_at(Vec3::default(), Vec3::unit_y()),
transform: Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::default(), Vec3::Y),
..Default::default()
});
}
3 changes: 1 addition & 2 deletions examples/asset/asset_loading.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ fn setup(
})
// camera
.spawn(PerspectiveCameraBundle {
transform: Transform::from_xyz(0.0, 3.0, 10.0)
.looking_at(Vec3::default(), Vec3::unit_y()),
transform: Transform::from_xyz(0.0, 3.0, 10.0).looking_at(Vec3::default(), Vec3::Y),
..Default::default()
});
}
3 changes: 1 addition & 2 deletions examples/asset/hot_asset_reloading.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
})
// camera
.spawn(PerspectiveCameraBundle {
transform: Transform::from_xyz(2.0, 2.0, 6.0)
.looking_at(Vec3::default(), Vec3::unit_y()),
transform: Transform::from_xyz(2.0, 2.0, 6.0).looking_at(Vec3::default(), Vec3::Y),
..Default::default()
});
}
4 changes: 2 additions & 2 deletions examples/game/alien_cake_addict.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ fn setup_cameras(mut commands: Commands, mut game: ResMut<Game>) {
2.0 * BOARD_SIZE_J as f32 / 3.0,
BOARD_SIZE_J as f32 / 2.0 - 0.5,
)
.looking_at(game.camera_is_focus, Vec3::unit_y()),
.looking_at(game.camera_is_focus, Vec3::Y),
..Default::default()
})
.spawn(UiCameraBundle::default());
Expand Down Expand Up @@ -301,7 +301,7 @@ fn focus_camera(
// look at that new camera's actual focus
for (mut transform, camera) in transforms.q0_mut().iter_mut() {
if camera.name == Some(CAMERA_3D.to_string()) {
*transform = transform.looking_at(game.camera_is_focus, Vec3::unit_y());
*transform = transform.looking_at(game.camera_is_focus, Vec3::Y);
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions examples/ios/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ fn setup(
})
// camera
.spawn(PerspectiveCameraBundle {
transform: Transform::from_xyz(-2.0, 2.5, 5.0)
.looking_at(Vec3::default(), Vec3::unit_y()),
transform: Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::default(), Vec3::Y),
..Default::default()
});
}
2 changes: 1 addition & 1 deletion examples/shader/array_texture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ fn setup(
.unwrap();

commands.spawn(PerspectiveCameraBundle {
transform: Transform::from_xyz(2.0, 2.0, 2.0).looking_at(Vec3::default(), Vec3::unit_y()),
transform: Transform::from_xyz(2.0, 2.0, 2.0).looking_at(Vec3::default(), Vec3::Y),
..Default::default()
});
}
Expand Down
3 changes: 1 addition & 2 deletions examples/shader/hot_shader_reloading.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ fn setup(
.with(material)
// camera
.spawn(PerspectiveCameraBundle {
transform: Transform::from_xyz(3.0, 5.0, -8.0)
.looking_at(Vec3::default(), Vec3::unit_y()),
transform: Transform::from_xyz(3.0, 5.0, -8.0).looking_at(Vec3::default(), Vec3::Y),
..Default::default()
});
}
3 changes: 1 addition & 2 deletions examples/shader/mesh_custom_attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,7 @@ fn setup(
.with(material)
// camera
.spawn(PerspectiveCameraBundle {
transform: Transform::from_xyz(3.0, 5.0, -8.0)
.looking_at(Vec3::default(), Vec3::unit_y()),
transform: Transform::from_xyz(3.0, 5.0, -8.0).looking_at(Vec3::default(), Vec3::Y),
..Default::default()
});
}
3 changes: 1 addition & 2 deletions examples/shader/shader_custom_material.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ fn setup(
.with(material)
// camera
.spawn(PerspectiveCameraBundle {
transform: Transform::from_xyz(3.0, 5.0, -8.0)
.looking_at(Vec3::default(), Vec3::unit_y()),
transform: Transform::from_xyz(3.0, 5.0, -8.0).looking_at(Vec3::default(), Vec3::Y),
..Default::default()
});
}
3 changes: 1 addition & 2 deletions examples/shader/shader_defs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,7 @@ fn setup(
.with(blue_material)
// camera
.spawn(PerspectiveCameraBundle {
transform: Transform::from_xyz(3.0, 5.0, -8.0)
.looking_at(Vec3::default(), Vec3::unit_y()),
transform: Transform::from_xyz(3.0, 5.0, -8.0).looking_at(Vec3::default(), Vec3::Y),
..Default::default()
});
}
6 changes: 2 additions & 4 deletions examples/window/multiple_windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,7 @@ fn setup_pipeline(
})
// main camera
.spawn(PerspectiveCameraBundle {
transform: Transform::from_xyz(0.0, 0.0, 6.0)
.looking_at(Vec3::default(), Vec3::unit_y()),
transform: Transform::from_xyz(0.0, 0.0, 6.0).looking_at(Vec3::default(), Vec3::Y),
..Default::default()
})
// second window camera
Expand All @@ -201,8 +200,7 @@ fn setup_pipeline(
window: window_id,
..Default::default()
},
transform: Transform::from_xyz(6.0, 0.0, 0.0)
.looking_at(Vec3::default(), Vec3::unit_y()),
transform: Transform::from_xyz(6.0, 0.0, 0.0).looking_at(Vec3::default(), Vec3::Y),
..Default::default()
});
}

0 comments on commit f61e44d

Please sign in to comment.