OrthographicProjection scaling mode + camera bundle refactoring (#400)
* add normalized orthographic projection * custom scale for ScaledOrthographicProjection * allow choosing base axis for ScaledOrthographicProjection * cargo fmt * add general (scaled) orthographic camera bundle FIXME: does the same "far" trick from Camera2DBundle make any sense here? * fixes * camera bundles: rename and new ortho constructors * unify orthographic projections * give PerspectiveCameraBundle constructors like those of OrthographicCameraBundle * update examples with new camera bundle syntax * rename CameraUiBundle to UiCameraBundle * update examples * ScalingMode::None * remove extra blank lines * sane default bounds for orthographic projection * fix alien_cake_addict example * reorder ScalingMode enum variants * ios example fix
This commit is contained in:
parent
af67231567
commit
57f9ac18d7
@ -51,6 +51,20 @@ pub enum WindowOrigin {
|
|||||||
BottomLeft,
|
BottomLeft,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Reflect, Serialize, Deserialize)]
|
||||||
|
#[reflect_value(Serialize, Deserialize)]
|
||||||
|
pub enum ScalingMode {
|
||||||
|
/// Manually specify left/right/top/bottom values.
|
||||||
|
/// Ignore window resizing; the image will stretch.
|
||||||
|
None,
|
||||||
|
/// Match the window size. 1 world unit = 1 pixel.
|
||||||
|
WindowSize,
|
||||||
|
/// Keep vertical axis constant; resize horizontal with aspect ratio.
|
||||||
|
FixedVertical,
|
||||||
|
/// Keep horizontal axis constant; resize vertical with aspect ratio.
|
||||||
|
FixedHorizontal,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Reflect)]
|
#[derive(Debug, Clone, Reflect)]
|
||||||
#[reflect(Component)]
|
#[reflect(Component)]
|
||||||
pub struct OrthographicProjection {
|
pub struct OrthographicProjection {
|
||||||
@ -61,23 +75,25 @@ pub struct OrthographicProjection {
|
|||||||
pub near: f32,
|
pub near: f32,
|
||||||
pub far: f32,
|
pub far: f32,
|
||||||
pub window_origin: WindowOrigin,
|
pub window_origin: WindowOrigin,
|
||||||
|
pub scaling_mode: ScalingMode,
|
||||||
|
pub scale: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CameraProjection for OrthographicProjection {
|
impl CameraProjection for OrthographicProjection {
|
||||||
fn get_projection_matrix(&self) -> Mat4 {
|
fn get_projection_matrix(&self) -> Mat4 {
|
||||||
Mat4::orthographic_rh(
|
Mat4::orthographic_rh(
|
||||||
self.left,
|
self.left * self.scale,
|
||||||
self.right,
|
self.right * self.scale,
|
||||||
self.bottom,
|
self.bottom * self.scale,
|
||||||
self.top,
|
self.top * self.scale,
|
||||||
self.near,
|
self.near,
|
||||||
self.far,
|
self.far,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update(&mut self, width: f32, height: f32) {
|
fn update(&mut self, width: f32, height: f32) {
|
||||||
match self.window_origin {
|
match (&self.scaling_mode, &self.window_origin) {
|
||||||
WindowOrigin::Center => {
|
(ScalingMode::WindowSize, WindowOrigin::Center) => {
|
||||||
let half_width = width / 2.0;
|
let half_width = width / 2.0;
|
||||||
let half_height = height / 2.0;
|
let half_height = height / 2.0;
|
||||||
self.left = -half_width;
|
self.left = -half_width;
|
||||||
@ -85,12 +101,41 @@ impl CameraProjection for OrthographicProjection {
|
|||||||
self.top = half_height;
|
self.top = half_height;
|
||||||
self.bottom = -half_height;
|
self.bottom = -half_height;
|
||||||
}
|
}
|
||||||
WindowOrigin::BottomLeft => {
|
(ScalingMode::WindowSize, WindowOrigin::BottomLeft) => {
|
||||||
self.left = 0.0;
|
self.left = 0.0;
|
||||||
self.right = width;
|
self.right = width;
|
||||||
self.top = height;
|
self.top = height;
|
||||||
self.bottom = 0.0;
|
self.bottom = 0.0;
|
||||||
}
|
}
|
||||||
|
(ScalingMode::FixedVertical, WindowOrigin::Center) => {
|
||||||
|
let aspect_ratio = width / height;
|
||||||
|
self.left = -aspect_ratio;
|
||||||
|
self.right = aspect_ratio;
|
||||||
|
self.top = 1.0;
|
||||||
|
self.bottom = -1.0;
|
||||||
|
}
|
||||||
|
(ScalingMode::FixedVertical, WindowOrigin::BottomLeft) => {
|
||||||
|
let aspect_ratio = width / height;
|
||||||
|
self.left = 0.0;
|
||||||
|
self.right = aspect_ratio;
|
||||||
|
self.top = 1.0;
|
||||||
|
self.bottom = 0.0;
|
||||||
|
}
|
||||||
|
(ScalingMode::FixedHorizontal, WindowOrigin::Center) => {
|
||||||
|
let aspect_ratio = height / width;
|
||||||
|
self.left = -1.0;
|
||||||
|
self.right = 1.0;
|
||||||
|
self.top = aspect_ratio;
|
||||||
|
self.bottom = -aspect_ratio;
|
||||||
|
}
|
||||||
|
(ScalingMode::FixedHorizontal, WindowOrigin::BottomLeft) => {
|
||||||
|
let aspect_ratio = height / width;
|
||||||
|
self.left = 0.0;
|
||||||
|
self.right = 1.0;
|
||||||
|
self.top = aspect_ratio;
|
||||||
|
self.bottom = 0.0;
|
||||||
|
}
|
||||||
|
(ScalingMode::None, _) => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,13 +147,15 @@ impl CameraProjection for OrthographicProjection {
|
|||||||
impl Default for OrthographicProjection {
|
impl Default for OrthographicProjection {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
OrthographicProjection {
|
OrthographicProjection {
|
||||||
left: 0.0,
|
left: -1.0,
|
||||||
right: 0.0,
|
right: 1.0,
|
||||||
bottom: 0.0,
|
bottom: -1.0,
|
||||||
top: 0.0,
|
top: 1.0,
|
||||||
near: 0.0,
|
near: 0.0,
|
||||||
far: 1000.0,
|
far: 1000.0,
|
||||||
window_origin: WindowOrigin::Center,
|
window_origin: WindowOrigin::Center,
|
||||||
|
scaling_mode: ScalingMode::WindowSize,
|
||||||
|
scale: 1.0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,9 +22,11 @@ pub struct MeshBundle {
|
|||||||
pub global_transform: GlobalTransform,
|
pub global_transform: GlobalTransform,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A component bundle for "3d camera" entities
|
/// Component bundle for camera entities with perspective projection
|
||||||
|
///
|
||||||
|
/// Use this for 3D rendering.
|
||||||
#[derive(Bundle)]
|
#[derive(Bundle)]
|
||||||
pub struct Camera3dBundle {
|
pub struct PerspectiveCameraBundle {
|
||||||
pub camera: Camera,
|
pub camera: Camera,
|
||||||
pub perspective_projection: PerspectiveProjection,
|
pub perspective_projection: PerspectiveProjection,
|
||||||
pub visible_entities: VisibleEntities,
|
pub visible_entities: VisibleEntities,
|
||||||
@ -32,9 +34,28 @@ pub struct Camera3dBundle {
|
|||||||
pub global_transform: GlobalTransform,
|
pub global_transform: GlobalTransform,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Camera3dBundle {
|
impl PerspectiveCameraBundle {
|
||||||
|
pub fn new_3d() -> Self {
|
||||||
|
Default::default()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn with_name(name: &str) -> Self {
|
||||||
|
PerspectiveCameraBundle {
|
||||||
|
camera: Camera {
|
||||||
|
name: Some(name.to_string()),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
perspective_projection: Default::default(),
|
||||||
|
visible_entities: Default::default(),
|
||||||
|
transform: Default::default(),
|
||||||
|
global_transform: Default::default(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for PerspectiveCameraBundle {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Camera3dBundle {
|
PerspectiveCameraBundle {
|
||||||
camera: Camera {
|
camera: Camera {
|
||||||
name: Some(base::camera::CAMERA_3D.to_string()),
|
name: Some(base::camera::CAMERA_3D.to_string()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
@ -47,9 +68,11 @@ impl Default for Camera3dBundle {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A component bundle for "2d camera" entities
|
/// Component bundle for camera entities with orthographic projection
|
||||||
|
///
|
||||||
|
/// Use this for 2D games, isometric games, CAD-like 3D views.
|
||||||
#[derive(Bundle)]
|
#[derive(Bundle)]
|
||||||
pub struct Camera2dBundle {
|
pub struct OrthographicCameraBundle {
|
||||||
pub camera: Camera,
|
pub camera: Camera,
|
||||||
pub orthographic_projection: OrthographicProjection,
|
pub orthographic_projection: OrthographicProjection,
|
||||||
pub visible_entities: VisibleEntities,
|
pub visible_entities: VisibleEntities,
|
||||||
@ -57,12 +80,12 @@ pub struct Camera2dBundle {
|
|||||||
pub global_transform: GlobalTransform,
|
pub global_transform: GlobalTransform,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Camera2dBundle {
|
impl OrthographicCameraBundle {
|
||||||
fn default() -> Self {
|
pub fn new_2d() -> Self {
|
||||||
// we want 0 to be "closest" and +far to be "farthest" in 2d, so we offset
|
// we want 0 to be "closest" and +far to be "farthest" in 2d, so we offset
|
||||||
// the camera's translation by far and use a right handed coordinate system
|
// the camera's translation by far and use a right handed coordinate system
|
||||||
let far = 1000.0;
|
let far = 1000.0;
|
||||||
Camera2dBundle {
|
OrthographicCameraBundle {
|
||||||
camera: Camera {
|
camera: Camera {
|
||||||
name: Some(base::camera::CAMERA_2D.to_string()),
|
name: Some(base::camera::CAMERA_2D.to_string()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
@ -76,4 +99,30 @@ impl Default for Camera2dBundle {
|
|||||||
global_transform: Default::default(),
|
global_transform: Default::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn new_3d() -> Self {
|
||||||
|
OrthographicCameraBundle {
|
||||||
|
camera: Camera {
|
||||||
|
name: Some(base::camera::CAMERA_3D.to_string()),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
orthographic_projection: Default::default(),
|
||||||
|
visible_entities: Default::default(),
|
||||||
|
transform: Default::default(),
|
||||||
|
global_transform: Default::default(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn with_name(name: &str) -> Self {
|
||||||
|
OrthographicCameraBundle {
|
||||||
|
camera: Camera {
|
||||||
|
name: Some(name.to_string()),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
orthographic_projection: Default::default(),
|
||||||
|
visible_entities: Default::default(),
|
||||||
|
transform: Default::default(),
|
||||||
|
global_transform: Default::default(),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -164,7 +164,7 @@ impl Default for ButtonBundle {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Bundle, Debug)]
|
#[derive(Bundle, Debug)]
|
||||||
pub struct CameraUiBundle {
|
pub struct UiCameraBundle {
|
||||||
pub camera: Camera,
|
pub camera: Camera,
|
||||||
pub orthographic_projection: OrthographicProjection,
|
pub orthographic_projection: OrthographicProjection,
|
||||||
pub visible_entities: VisibleEntities,
|
pub visible_entities: VisibleEntities,
|
||||||
@ -172,12 +172,12 @@ pub struct CameraUiBundle {
|
|||||||
pub global_transform: GlobalTransform,
|
pub global_transform: GlobalTransform,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for CameraUiBundle {
|
impl Default for UiCameraBundle {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
// we want 0 to be "closest" and +far to be "farthest" in 2d, so we offset
|
// we want 0 to be "closest" and +far to be "farthest" in 2d, so we offset
|
||||||
// the camera's translation by far and use a right handed coordinate system
|
// the camera's translation by far and use a right handed coordinate system
|
||||||
let far = 1000.0;
|
let far = 1000.0;
|
||||||
CameraUiBundle {
|
UiCameraBundle {
|
||||||
camera: Camera {
|
camera: Camera {
|
||||||
name: Some(crate::camera::CAMERA_UI.to_string()),
|
name: Some(crate::camera::CAMERA_UI.to_string()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
@ -55,8 +55,8 @@ fn setup(
|
|||||||
let texture_handle = asset_server.load("branding/icon.png");
|
let texture_handle = asset_server.load("branding/icon.png");
|
||||||
|
|
||||||
commands
|
commands
|
||||||
.spawn(Camera2dBundle::default())
|
.spawn(OrthographicCameraBundle::new_2d())
|
||||||
.spawn(CameraUiBundle::default());
|
.spawn(UiCameraBundle::default());
|
||||||
|
|
||||||
let mut sel = ContributorSelection {
|
let mut sel = ContributorSelection {
|
||||||
order: vec![],
|
order: vec![],
|
||||||
|
@ -14,7 +14,7 @@ fn setup(
|
|||||||
) {
|
) {
|
||||||
let texture_handle = asset_server.load("branding/icon.png");
|
let texture_handle = asset_server.load("branding/icon.png");
|
||||||
commands
|
commands
|
||||||
.spawn(Camera2dBundle::default())
|
.spawn(OrthographicCameraBundle::new_2d())
|
||||||
.spawn(SpriteBundle {
|
.spawn(SpriteBundle {
|
||||||
material: materials.add(texture_handle.into()),
|
material: materials.add(texture_handle.into()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
@ -31,7 +31,7 @@ fn setup(
|
|||||||
let texture_atlas = TextureAtlas::from_grid(texture_handle, Vec2::new(24.0, 24.0), 7, 1);
|
let texture_atlas = TextureAtlas::from_grid(texture_handle, Vec2::new(24.0, 24.0), 7, 1);
|
||||||
let texture_atlas_handle = texture_atlases.add(texture_atlas);
|
let texture_atlas_handle = texture_atlases.add(texture_atlas);
|
||||||
commands
|
commands
|
||||||
.spawn(Camera2dBundle::default())
|
.spawn(OrthographicCameraBundle::new_2d())
|
||||||
.spawn(SpriteSheetBundle {
|
.spawn(SpriteSheetBundle {
|
||||||
texture_atlas: texture_atlas_handle,
|
texture_atlas: texture_atlas_handle,
|
||||||
transform: Transform::from_scale(Vec3::splat(6.0)),
|
transform: Transform::from_scale(Vec3::splat(6.0)),
|
||||||
|
@ -11,7 +11,7 @@ fn main() {
|
|||||||
fn setup(commands: &mut Commands, asset_server: Res<AssetServer>) {
|
fn setup(commands: &mut Commands, asset_server: Res<AssetServer>) {
|
||||||
commands
|
commands
|
||||||
// 2d camera
|
// 2d camera
|
||||||
.spawn(Camera2dBundle::default())
|
.spawn(OrthographicCameraBundle::new_2d())
|
||||||
.spawn(Text2dBundle {
|
.spawn(Text2dBundle {
|
||||||
text: Text::with_section(
|
text: Text::with_section(
|
||||||
"This text is in the 2D scene.",
|
"This text is in the 2D scene.",
|
||||||
|
@ -64,7 +64,7 @@ fn setup(
|
|||||||
|
|
||||||
// set up a scene to display our texture atlas
|
// set up a scene to display our texture atlas
|
||||||
commands
|
commands
|
||||||
.spawn(Camera2dBundle::default())
|
.spawn(OrthographicCameraBundle::new_2d())
|
||||||
// draw a sprite from the atlas
|
// draw a sprite from the atlas
|
||||||
.spawn(SpriteSheetBundle {
|
.spawn(SpriteSheetBundle {
|
||||||
transform: Transform {
|
transform: Transform {
|
||||||
|
@ -35,7 +35,7 @@ fn setup(
|
|||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
// camera
|
// camera
|
||||||
.spawn(Camera3dBundle {
|
.spawn(PerspectiveCameraBundle {
|
||||||
transform: Transform::from_xyz(-2.0, 2.5, 5.0)
|
transform: Transform::from_xyz(-2.0, 2.5, 5.0)
|
||||||
.looking_at(Vec3::default(), Vec3::unit_y()),
|
.looking_at(Vec3::default(), Vec3::unit_y()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
@ -15,7 +15,7 @@ fn setup(commands: &mut Commands, asset_server: Res<AssetServer>) {
|
|||||||
transform: Transform::from_xyz(4.0, 5.0, 4.0),
|
transform: Transform::from_xyz(4.0, 5.0, 4.0),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
.spawn(Camera3dBundle {
|
.spawn(PerspectiveCameraBundle {
|
||||||
transform: Transform::from_xyz(0.7, 0.7, 1.0)
|
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::unit_y()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
@ -31,7 +31,7 @@ fn setup(
|
|||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
// camera
|
// camera
|
||||||
.spawn(Camera3dBundle {
|
.spawn(PerspectiveCameraBundle {
|
||||||
transform: Transform::from_xyz(-3.0, 3.0, 5.0)
|
transform: Transform::from_xyz(-3.0, 3.0, 5.0)
|
||||||
.looking_at(Vec3::default(), Vec3::unit_y()),
|
.looking_at(Vec3::default(), Vec3::unit_y()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
@ -57,7 +57,7 @@ fn setup(
|
|||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
// camera
|
// camera
|
||||||
.spawn(Camera3dBundle {
|
.spawn(PerspectiveCameraBundle {
|
||||||
transform: Transform::from_xyz(5.0, 10.0, 10.0)
|
transform: Transform::from_xyz(5.0, 10.0, 10.0)
|
||||||
.looking_at(Vec3::default(), Vec3::unit_y()),
|
.looking_at(Vec3::default(), Vec3::unit_y()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
@ -43,7 +43,7 @@ fn setup(
|
|||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
// camera
|
// camera
|
||||||
.spawn(Camera3dBundle {
|
.spawn(PerspectiveCameraBundle {
|
||||||
transform: Transform::from_xyz(0.0, 15.0, 150.0)
|
transform: Transform::from_xyz(0.0, 15.0, 150.0)
|
||||||
.looking_at(Vec3::default(), Vec3::unit_y()),
|
.looking_at(Vec3::default(), Vec3::unit_y()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
@ -95,7 +95,7 @@ fn setup(
|
|||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
// camera
|
// camera
|
||||||
.spawn(Camera3dBundle {
|
.spawn(PerspectiveCameraBundle {
|
||||||
transform: Transform::from_xyz(3.0, 5.0, 8.0)
|
transform: Transform::from_xyz(3.0, 5.0, 8.0)
|
||||||
.looking_at(Vec3::default(), Vec3::unit_y()),
|
.looking_at(Vec3::default(), Vec3::unit_y()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
@ -29,7 +29,7 @@ fn setup(
|
|||||||
transform: Transform::from_xyz(4.0, 5.0, 4.0),
|
transform: Transform::from_xyz(4.0, 5.0, 4.0),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
.spawn(Camera3dBundle {
|
.spawn(PerspectiveCameraBundle {
|
||||||
transform: Transform::from_xyz(1.05, 0.9, 1.5)
|
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::unit_y()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
@ -82,7 +82,7 @@ fn setup(
|
|||||||
});
|
});
|
||||||
})
|
})
|
||||||
// camera
|
// camera
|
||||||
.spawn(Camera3dBundle {
|
.spawn(PerspectiveCameraBundle {
|
||||||
transform: Transform::from_xyz(5.0, 10.0, 10.0)
|
transform: Transform::from_xyz(5.0, 10.0, 10.0)
|
||||||
.looking_at(Vec3::default(), Vec3::unit_y()),
|
.looking_at(Vec3::default(), Vec3::unit_y()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
@ -37,7 +37,7 @@ fn setup(
|
|||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
// camera
|
// camera
|
||||||
.spawn(Camera3dBundle {
|
.spawn(PerspectiveCameraBundle {
|
||||||
transform: Transform::from_xyz(-2.0, 2.5, 5.0)
|
transform: Transform::from_xyz(-2.0, 2.5, 5.0)
|
||||||
.looking_at(Vec3::default(), Vec3::unit_y()),
|
.looking_at(Vec3::default(), Vec3::unit_y()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
@ -70,7 +70,7 @@ fn setup(
|
|||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
// camera
|
// camera
|
||||||
.spawn(Camera3dBundle {
|
.spawn(PerspectiveCameraBundle {
|
||||||
transform: Transform::from_xyz(0.0, 3.0, 10.0)
|
transform: Transform::from_xyz(0.0, 3.0, 10.0)
|
||||||
.looking_at(Vec3::default(), Vec3::unit_y()),
|
.looking_at(Vec3::default(), Vec3::unit_y()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
@ -96,7 +96,7 @@ fn setup(
|
|||||||
) {
|
) {
|
||||||
let texture_handle = asset_server.load("branding/icon.png");
|
let texture_handle = asset_server.load("branding/icon.png");
|
||||||
commands
|
commands
|
||||||
.spawn(Camera2dBundle::default())
|
.spawn(OrthographicCameraBundle::new_2d())
|
||||||
.spawn(SpriteBundle {
|
.spawn(SpriteBundle {
|
||||||
material: materials.add(texture_handle.into()),
|
material: materials.add(texture_handle.into()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
@ -30,7 +30,7 @@ fn setup(commands: &mut Commands, asset_server: Res<AssetServer>) {
|
|||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
// camera
|
// camera
|
||||||
.spawn(Camera3dBundle {
|
.spawn(PerspectiveCameraBundle {
|
||||||
transform: Transform::from_xyz(2.0, 2.0, 6.0)
|
transform: Transform::from_xyz(2.0, 2.0, 6.0)
|
||||||
.looking_at(Vec3::default(), Vec3::unit_y()),
|
.looking_at(Vec3::default(), Vec3::unit_y()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
@ -13,7 +13,7 @@ fn setup(
|
|||||||
asset_server: Res<AssetServer>,
|
asset_server: Res<AssetServer>,
|
||||||
mut materials: ResMut<Assets<ColorMaterial>>,
|
mut materials: ResMut<Assets<ColorMaterial>>,
|
||||||
) {
|
) {
|
||||||
commands.spawn(Camera2dBundle::default());
|
commands.spawn(OrthographicCameraBundle::new_2d());
|
||||||
let texture = asset_server.load("branding/icon.png");
|
let texture = asset_server.load("branding/icon.png");
|
||||||
|
|
||||||
// Spawn a root entity with no parent
|
// Spawn a root entity with no parent
|
||||||
|
@ -8,7 +8,7 @@ fn spawn_system(
|
|||||||
asset_server: Res<AssetServer>,
|
asset_server: Res<AssetServer>,
|
||||||
mut materials: ResMut<Assets<ColorMaterial>>,
|
mut materials: ResMut<Assets<ColorMaterial>>,
|
||||||
) {
|
) {
|
||||||
commands.spawn(Camera2dBundle::default());
|
commands.spawn(OrthographicCameraBundle::new_2d());
|
||||||
let texture_handle = asset_server.load("branding/icon.png");
|
let texture_handle = asset_server.load("branding/icon.png");
|
||||||
let material = materials.add(texture_handle.into());
|
let material = materials.add(texture_handle.into());
|
||||||
for _ in 0..128 {
|
for _ in 0..128 {
|
||||||
|
@ -33,7 +33,7 @@ fn setup(
|
|||||||
let texture = asset_server.load("branding/icon.png");
|
let texture = asset_server.load("branding/icon.png");
|
||||||
|
|
||||||
commands
|
commands
|
||||||
.spawn(Camera2dBundle::default())
|
.spawn(OrthographicCameraBundle::new_2d())
|
||||||
.spawn(SpriteBundle {
|
.spawn(SpriteBundle {
|
||||||
material: materials.add(texture.into()),
|
material: materials.add(texture.into()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
@ -35,7 +35,7 @@ fn setup_menu(
|
|||||||
) {
|
) {
|
||||||
commands
|
commands
|
||||||
// ui camera
|
// ui camera
|
||||||
.spawn(CameraUiBundle::default())
|
.spawn(UiCameraBundle::default())
|
||||||
.spawn(ButtonBundle {
|
.spawn(ButtonBundle {
|
||||||
style: Style {
|
style: Style {
|
||||||
size: Size::new(Val::Px(150.0), Val::Px(65.0)),
|
size: Size::new(Val::Px(150.0), Val::Px(65.0)),
|
||||||
@ -104,7 +104,7 @@ fn setup_game(
|
|||||||
) {
|
) {
|
||||||
let texture_handle = asset_server.load("branding/icon.png");
|
let texture_handle = asset_server.load("branding/icon.png");
|
||||||
commands
|
commands
|
||||||
.spawn(Camera2dBundle::default())
|
.spawn(OrthographicCameraBundle::new_2d())
|
||||||
.spawn(SpriteBundle {
|
.spawn(SpriteBundle {
|
||||||
material: materials.add(texture_handle.into()),
|
material: materials.add(texture_handle.into()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
@ -83,7 +83,7 @@ fn setup_cameras(commands: &mut Commands, mut game: ResMut<Game>) {
|
|||||||
game.camera_should_focus = Vec3::from(RESET_FOCUS);
|
game.camera_should_focus = Vec3::from(RESET_FOCUS);
|
||||||
game.camera_is_focus = game.camera_should_focus;
|
game.camera_is_focus = game.camera_should_focus;
|
||||||
commands
|
commands
|
||||||
.spawn(Camera3dBundle {
|
.spawn(PerspectiveCameraBundle {
|
||||||
transform: Transform::from_xyz(
|
transform: Transform::from_xyz(
|
||||||
-(BOARD_SIZE_I as f32 / 2.0),
|
-(BOARD_SIZE_I as f32 / 2.0),
|
||||||
2.0 * BOARD_SIZE_J as f32 / 3.0,
|
2.0 * BOARD_SIZE_J as f32 / 3.0,
|
||||||
@ -92,7 +92,7 @@ fn setup_cameras(commands: &mut Commands, mut game: ResMut<Game>) {
|
|||||||
.looking_at(game.camera_is_focus, Vec3::unit_y()),
|
.looking_at(game.camera_is_focus, Vec3::unit_y()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
.spawn(CameraUiBundle::default());
|
.spawn(UiCameraBundle::default());
|
||||||
}
|
}
|
||||||
|
|
||||||
fn setup(commands: &mut Commands, asset_server: Res<AssetServer>, mut game: ResMut<Game>) {
|
fn setup(commands: &mut Commands, asset_server: Res<AssetServer>, mut game: ResMut<Game>) {
|
||||||
|
@ -44,8 +44,8 @@ fn setup(
|
|||||||
// Add the game's entities to our world
|
// Add the game's entities to our world
|
||||||
commands
|
commands
|
||||||
// cameras
|
// cameras
|
||||||
.spawn(Camera2dBundle::default())
|
.spawn(OrthographicCameraBundle::new_2d())
|
||||||
.spawn(CameraUiBundle::default())
|
.spawn(UiCameraBundle::default())
|
||||||
// paddle
|
// paddle
|
||||||
.spawn(SpriteBundle {
|
.spawn(SpriteBundle {
|
||||||
material: materials.add(Color::rgb(0.5, 0.5, 1.0).into()),
|
material: materials.add(Color::rgb(0.5, 0.5, 1.0).into()),
|
||||||
|
@ -52,7 +52,7 @@ fn setup(
|
|||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
// camera
|
// camera
|
||||||
.spawn(Camera3dBundle {
|
.spawn(PerspectiveCameraBundle {
|
||||||
transform: Transform::from_xyz(-2.0, 2.5, 5.0)
|
transform: Transform::from_xyz(-2.0, 2.5, 5.0)
|
||||||
.looking_at(Vec3::default(), Vec3::unit_y()),
|
.looking_at(Vec3::default(), Vec3::unit_y()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
@ -97,7 +97,7 @@ fn save_scene_system(_world: &mut World, resources: &mut Resources) {
|
|||||||
|
|
||||||
// This is only necessary for the info message in the UI. See examples/ui/text.rs for a standalone text example.
|
// This is only necessary for the info message in the UI. See examples/ui/text.rs for a standalone text example.
|
||||||
fn infotext_system(commands: &mut Commands, asset_server: Res<AssetServer>) {
|
fn infotext_system(commands: &mut Commands, asset_server: Res<AssetServer>) {
|
||||||
commands.spawn(CameraUiBundle::default()).spawn(TextBundle {
|
commands.spawn(UiCameraBundle::default()).spawn(TextBundle {
|
||||||
style: Style {
|
style: Style {
|
||||||
align_self: AlignSelf::FlexEnd,
|
align_self: AlignSelf::FlexEnd,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
@ -109,7 +109,7 @@ fn setup(
|
|||||||
.add_node_edge("my_array_texture", base::node::MAIN_PASS)
|
.add_node_edge("my_array_texture", base::node::MAIN_PASS)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
commands.spawn(Camera3dBundle {
|
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::unit_y()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
});
|
});
|
||||||
|
@ -72,7 +72,7 @@ fn setup(
|
|||||||
})
|
})
|
||||||
.with(material)
|
.with(material)
|
||||||
// camera
|
// camera
|
||||||
.spawn(Camera3dBundle {
|
.spawn(PerspectiveCameraBundle {
|
||||||
transform: Transform::from_xyz(3.0, 5.0, -8.0)
|
transform: Transform::from_xyz(3.0, 5.0, -8.0)
|
||||||
.looking_at(Vec3::default(), Vec3::unit_y()),
|
.looking_at(Vec3::default(), Vec3::unit_y()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
@ -137,7 +137,7 @@ fn setup(
|
|||||||
})
|
})
|
||||||
.with(material)
|
.with(material)
|
||||||
// camera
|
// camera
|
||||||
.spawn(Camera3dBundle {
|
.spawn(PerspectiveCameraBundle {
|
||||||
transform: Transform::from_xyz(3.0, 5.0, -8.0)
|
transform: Transform::from_xyz(3.0, 5.0, -8.0)
|
||||||
.looking_at(Vec3::default(), Vec3::unit_y()),
|
.looking_at(Vec3::default(), Vec3::unit_y()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
@ -93,7 +93,7 @@ fn setup(
|
|||||||
})
|
})
|
||||||
.with(material)
|
.with(material)
|
||||||
// camera
|
// camera
|
||||||
.spawn(Camera3dBundle {
|
.spawn(PerspectiveCameraBundle {
|
||||||
transform: Transform::from_xyz(3.0, 5.0, -8.0)
|
transform: Transform::from_xyz(3.0, 5.0, -8.0)
|
||||||
.looking_at(Vec3::default(), Vec3::unit_y()),
|
.looking_at(Vec3::default(), Vec3::unit_y()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
@ -124,7 +124,7 @@ fn setup(
|
|||||||
})
|
})
|
||||||
.with(blue_material)
|
.with(blue_material)
|
||||||
// camera
|
// camera
|
||||||
.spawn(Camera3dBundle {
|
.spawn(PerspectiveCameraBundle {
|
||||||
transform: Transform::from_xyz(3.0, 5.0, -8.0)
|
transform: Transform::from_xyz(3.0, 5.0, -8.0)
|
||||||
.looking_at(Vec3::default(), Vec3::unit_y()),
|
.looking_at(Vec3::default(), Vec3::unit_y()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
@ -50,8 +50,8 @@ fn main() {
|
|||||||
|
|
||||||
fn setup(commands: &mut Commands, asset_server: Res<AssetServer>) {
|
fn setup(commands: &mut Commands, asset_server: Res<AssetServer>) {
|
||||||
commands
|
commands
|
||||||
.spawn(Camera2dBundle::default())
|
.spawn(OrthographicCameraBundle::new_2d())
|
||||||
.spawn(CameraUiBundle::default())
|
.spawn(UiCameraBundle::default())
|
||||||
.spawn(TextBundle {
|
.spawn(TextBundle {
|
||||||
text: Text {
|
text: Text {
|
||||||
sections: vec![
|
sections: vec![
|
||||||
|
@ -61,7 +61,7 @@ fn setup(
|
|||||||
) {
|
) {
|
||||||
commands
|
commands
|
||||||
// ui camera
|
// ui camera
|
||||||
.spawn(CameraUiBundle::default())
|
.spawn(UiCameraBundle::default())
|
||||||
.spawn(ButtonBundle {
|
.spawn(ButtonBundle {
|
||||||
style: Style {
|
style: Style {
|
||||||
size: Size::new(Val::Px(150.0), Val::Px(65.0)),
|
size: Size::new(Val::Px(150.0), Val::Px(65.0)),
|
||||||
|
@ -79,7 +79,7 @@ fn text_update_system(mut state: ResMut<State>, time: Res<Time>, mut query: Quer
|
|||||||
fn setup(commands: &mut Commands, asset_server: Res<AssetServer>, mut state: ResMut<State>) {
|
fn setup(commands: &mut Commands, asset_server: Res<AssetServer>, mut state: ResMut<State>) {
|
||||||
let font_handle = asset_server.load("fonts/FiraSans-Bold.ttf");
|
let font_handle = asset_server.load("fonts/FiraSans-Bold.ttf");
|
||||||
state.handle = font_handle.clone();
|
state.handle = font_handle.clone();
|
||||||
commands.spawn(CameraUiBundle::default()).spawn(TextBundle {
|
commands.spawn(UiCameraBundle::default()).spawn(TextBundle {
|
||||||
text: Text::with_section(
|
text: Text::with_section(
|
||||||
"a",
|
"a",
|
||||||
TextStyle {
|
TextStyle {
|
||||||
|
@ -25,7 +25,7 @@ struct ColorText;
|
|||||||
fn setup(commands: &mut Commands, asset_server: Res<AssetServer>) {
|
fn setup(commands: &mut Commands, asset_server: Res<AssetServer>) {
|
||||||
commands
|
commands
|
||||||
// UI camera
|
// UI camera
|
||||||
.spawn(CameraUiBundle::default())
|
.spawn(UiCameraBundle::default())
|
||||||
// Text with one section
|
// Text with one section
|
||||||
.spawn(TextBundle {
|
.spawn(TextBundle {
|
||||||
style: Style {
|
style: Style {
|
||||||
|
@ -21,7 +21,7 @@ struct TextChanges;
|
|||||||
|
|
||||||
fn infotext_system(commands: &mut Commands, asset_server: Res<AssetServer>) {
|
fn infotext_system(commands: &mut Commands, asset_server: Res<AssetServer>) {
|
||||||
let font = asset_server.load("fonts/FiraSans-Bold.ttf");
|
let font = asset_server.load("fonts/FiraSans-Bold.ttf");
|
||||||
commands.spawn(CameraUiBundle::default());
|
commands.spawn(UiCameraBundle::default());
|
||||||
commands.spawn(TextBundle {
|
commands.spawn(TextBundle {
|
||||||
style: Style {
|
style: Style {
|
||||||
align_self: AlignSelf::FlexEnd,
|
align_self: AlignSelf::FlexEnd,
|
||||||
|
@ -15,7 +15,7 @@ fn setup(
|
|||||||
) {
|
) {
|
||||||
commands
|
commands
|
||||||
// ui camera
|
// ui camera
|
||||||
.spawn(CameraUiBundle::default())
|
.spawn(UiCameraBundle::default())
|
||||||
// root node
|
// root node
|
||||||
.spawn(NodeBundle {
|
.spawn(NodeBundle {
|
||||||
style: Style {
|
style: Style {
|
||||||
|
@ -192,13 +192,13 @@ fn setup_pipeline(
|
|||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
// main camera
|
// main camera
|
||||||
.spawn(Camera3dBundle {
|
.spawn(PerspectiveCameraBundle {
|
||||||
transform: Transform::from_xyz(0.0, 0.0, 6.0)
|
transform: Transform::from_xyz(0.0, 0.0, 6.0)
|
||||||
.looking_at(Vec3::default(), Vec3::unit_y()),
|
.looking_at(Vec3::default(), Vec3::unit_y()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
// second window camera
|
// second window camera
|
||||||
.spawn(Camera3dBundle {
|
.spawn(PerspectiveCameraBundle {
|
||||||
camera: Camera {
|
camera: Camera {
|
||||||
name: Some("Secondary".to_string()),
|
name: Some("Secondary".to_string()),
|
||||||
window: window_id,
|
window: window_id,
|
||||||
|
@ -22,7 +22,7 @@ fn setup(
|
|||||||
) {
|
) {
|
||||||
commands
|
commands
|
||||||
// ui camera
|
// ui camera
|
||||||
.spawn(CameraUiBundle::default())
|
.spawn(UiCameraBundle::default())
|
||||||
// root node
|
// root node
|
||||||
.spawn(NodeBundle {
|
.spawn(NodeBundle {
|
||||||
style: Style {
|
style: Style {
|
||||||
|
Loading…
Reference in New Issue
Block a user