Add from_xyz
to Transform
(#1212)
* Add the from_xyz helper method to Transform * Use `from_xyz` where possible
This commit is contained in:
parent
12d4184d7c
commit
9f2410a4ac
@ -8,7 +8,6 @@ use crate::{
|
|||||||
use base::MainPass;
|
use base::MainPass;
|
||||||
use bevy_asset::Handle;
|
use bevy_asset::Handle;
|
||||||
use bevy_ecs::Bundle;
|
use bevy_ecs::Bundle;
|
||||||
use bevy_math::Vec3;
|
|
||||||
use bevy_transform::components::{GlobalTransform, Transform};
|
use bevy_transform::components::{GlobalTransform, Transform};
|
||||||
|
|
||||||
/// A component bundle for "mesh" entities
|
/// A component bundle for "mesh" entities
|
||||||
@ -73,7 +72,7 @@ impl Default for Camera2dBundle {
|
|||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
visible_entities: Default::default(),
|
visible_entities: Default::default(),
|
||||||
transform: Transform::from_translation(Vec3::new(0.0, 0.0, far - 0.1)),
|
transform: Transform::from_xyz(0.0, 0.0, far - 0.1),
|
||||||
global_transform: Default::default(),
|
global_transform: Default::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,12 @@ pub struct GlobalTransform {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl GlobalTransform {
|
impl GlobalTransform {
|
||||||
|
/// Create a new [`GlobalTransform`] at the position `(x, y, z)`
|
||||||
|
#[inline]
|
||||||
|
pub fn from_xyz(x: f32, y: f32, z: f32) -> Self {
|
||||||
|
Self::from_translation(Vec3::new(x, y, z))
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn identity() -> Self {
|
pub fn identity() -> Self {
|
||||||
GlobalTransform {
|
GlobalTransform {
|
||||||
|
@ -12,6 +12,12 @@ pub struct Transform {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Transform {
|
impl Transform {
|
||||||
|
/// Create a new [`Transform`] at the position `(x, y, z)`
|
||||||
|
#[inline]
|
||||||
|
pub fn from_xyz(x: f32, y: f32, z: f32) -> Self {
|
||||||
|
Self::from_translation(Vec3::new(x, y, z))
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn identity() -> Self {
|
pub fn identity() -> Self {
|
||||||
Transform {
|
Transform {
|
||||||
|
@ -72,7 +72,6 @@ mod test {
|
|||||||
use super::*;
|
use super::*;
|
||||||
use crate::{hierarchy::BuildChildren, transform_propagate_system::transform_propagate_system};
|
use crate::{hierarchy::BuildChildren, transform_propagate_system::transform_propagate_system};
|
||||||
use bevy_ecs::{IntoSystem, Resources, Schedule, SystemStage, World};
|
use bevy_ecs::{IntoSystem, Resources, Schedule, SystemStage, World};
|
||||||
use bevy_math::Vec3;
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn correct_children() {
|
fn correct_children() {
|
||||||
@ -92,13 +91,13 @@ mod test {
|
|||||||
let mut parent = None;
|
let mut parent = None;
|
||||||
let mut children = Vec::new();
|
let mut children = Vec::new();
|
||||||
commands
|
commands
|
||||||
.spawn((Transform::from_translation(Vec3::new(1.0, 0.0, 0.0)),))
|
.spawn((Transform::from_xyz(1.0, 0.0, 0.0),))
|
||||||
.for_current_entity(|entity| parent = Some(entity))
|
.for_current_entity(|entity| parent = Some(entity))
|
||||||
.with_children(|parent| {
|
.with_children(|parent| {
|
||||||
parent
|
parent
|
||||||
.spawn((Transform::from_translation(Vec3::new(0.0, 2.0, 0.0)),))
|
.spawn((Transform::from_xyz(0.0, 2.0, 0.0),))
|
||||||
.for_current_entity(|entity| children.push(entity))
|
.for_current_entity(|entity| children.push(entity))
|
||||||
.spawn((Transform::from_translation(Vec3::new(0.0, 0.0, 3.0)),))
|
.spawn((Transform::from_xyz(0.0, 0.0, 3.0),))
|
||||||
.for_current_entity(|entity| children.push(entity));
|
.for_current_entity(|entity| children.push(entity));
|
||||||
});
|
});
|
||||||
let parent = parent.unwrap();
|
let parent = parent.unwrap();
|
||||||
|
@ -72,7 +72,6 @@ mod test {
|
|||||||
use super::*;
|
use super::*;
|
||||||
use crate::hierarchy::{parent_update_system, BuildChildren, BuildWorldChildren};
|
use crate::hierarchy::{parent_update_system, BuildChildren, BuildWorldChildren};
|
||||||
use bevy_ecs::{Resources, Schedule, SystemStage, World};
|
use bevy_ecs::{Resources, Schedule, SystemStage, World};
|
||||||
use bevy_math::Vec3;
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn did_propagate() {
|
fn did_propagate() {
|
||||||
@ -88,7 +87,7 @@ mod test {
|
|||||||
|
|
||||||
// Root entity
|
// Root entity
|
||||||
world.spawn((
|
world.spawn((
|
||||||
Transform::from_translation(Vec3::new(1.0, 0.0, 0.0)),
|
Transform::from_xyz(1.0, 0.0, 0.0),
|
||||||
GlobalTransform::identity(),
|
GlobalTransform::identity(),
|
||||||
));
|
));
|
||||||
|
|
||||||
@ -96,18 +95,18 @@ mod test {
|
|||||||
world
|
world
|
||||||
.build()
|
.build()
|
||||||
.spawn((
|
.spawn((
|
||||||
Transform::from_translation(Vec3::new(1.0, 0.0, 0.0)),
|
Transform::from_xyz(1.0, 0.0, 0.0),
|
||||||
GlobalTransform::identity(),
|
GlobalTransform::identity(),
|
||||||
))
|
))
|
||||||
.with_children(|parent| {
|
.with_children(|parent| {
|
||||||
parent
|
parent
|
||||||
.spawn((
|
.spawn((
|
||||||
Transform::from_translation(Vec3::new(0.0, 2.0, 0.)),
|
Transform::from_xyz(0.0, 2.0, 0.),
|
||||||
GlobalTransform::identity(),
|
GlobalTransform::identity(),
|
||||||
))
|
))
|
||||||
.for_current_entity(|entity| children.push(entity))
|
.for_current_entity(|entity| children.push(entity))
|
||||||
.spawn((
|
.spawn((
|
||||||
Transform::from_translation(Vec3::new(0.0, 0.0, 3.)),
|
Transform::from_xyz(0.0, 0.0, 3.),
|
||||||
GlobalTransform::identity(),
|
GlobalTransform::identity(),
|
||||||
))
|
))
|
||||||
.for_current_entity(|entity| children.push(entity));
|
.for_current_entity(|entity| children.push(entity));
|
||||||
@ -116,14 +115,12 @@ mod test {
|
|||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*world.get::<GlobalTransform>(children[0]).unwrap(),
|
*world.get::<GlobalTransform>(children[0]).unwrap(),
|
||||||
GlobalTransform::from_translation(Vec3::new(1.0, 0.0, 0.0))
|
GlobalTransform::from_xyz(1.0, 0.0, 0.0) * Transform::from_xyz(0.0, 2.0, 0.0)
|
||||||
* Transform::from_translation(Vec3::new(0.0, 2.0, 0.0))
|
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*world.get::<GlobalTransform>(children[1]).unwrap(),
|
*world.get::<GlobalTransform>(children[1]).unwrap(),
|
||||||
GlobalTransform::from_translation(Vec3::new(1.0, 0.0, 0.0))
|
GlobalTransform::from_xyz(1.0, 0.0, 0.0) * Transform::from_xyz(0.0, 0.0, 3.0)
|
||||||
* Transform::from_translation(Vec3::new(0.0, 0.0, 3.0))
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,18 +142,18 @@ mod test {
|
|||||||
let mut children = Vec::new();
|
let mut children = Vec::new();
|
||||||
commands
|
commands
|
||||||
.spawn((
|
.spawn((
|
||||||
Transform::from_translation(Vec3::new(1.0, 0.0, 0.0)),
|
Transform::from_xyz(1.0, 0.0, 0.0),
|
||||||
GlobalTransform::identity(),
|
GlobalTransform::identity(),
|
||||||
))
|
))
|
||||||
.with_children(|parent| {
|
.with_children(|parent| {
|
||||||
parent
|
parent
|
||||||
.spawn((
|
.spawn((
|
||||||
Transform::from_translation(Vec3::new(0.0, 2.0, 0.0)),
|
Transform::from_xyz(0.0, 2.0, 0.0),
|
||||||
GlobalTransform::identity(),
|
GlobalTransform::identity(),
|
||||||
))
|
))
|
||||||
.for_current_entity(|entity| children.push(entity))
|
.for_current_entity(|entity| children.push(entity))
|
||||||
.spawn((
|
.spawn((
|
||||||
Transform::from_translation(Vec3::new(0.0, 0.0, 3.0)),
|
Transform::from_xyz(0.0, 0.0, 3.0),
|
||||||
GlobalTransform::identity(),
|
GlobalTransform::identity(),
|
||||||
))
|
))
|
||||||
.for_current_entity(|entity| children.push(entity));
|
.for_current_entity(|entity| children.push(entity));
|
||||||
@ -166,14 +163,12 @@ mod test {
|
|||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*world.get::<GlobalTransform>(children[0]).unwrap(),
|
*world.get::<GlobalTransform>(children[0]).unwrap(),
|
||||||
GlobalTransform::from_translation(Vec3::new(1.0, 0.0, 0.0))
|
GlobalTransform::from_xyz(1.0, 0.0, 0.0) * Transform::from_xyz(0.0, 2.0, 0.0)
|
||||||
* Transform::from_translation(Vec3::new(0.0, 2.0, 0.0))
|
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*world.get::<GlobalTransform>(children[1]).unwrap(),
|
*world.get::<GlobalTransform>(children[1]).unwrap(),
|
||||||
GlobalTransform::from_translation(Vec3::new(1.0, 0.0, 0.0))
|
GlobalTransform::from_xyz(1.0, 0.0, 0.0) * Transform::from_xyz(0.0, 0.0, 3.0)
|
||||||
* Transform::from_translation(Vec3::new(0.0, 0.0, 3.0))
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,6 @@ use crate::{
|
|||||||
};
|
};
|
||||||
use bevy_asset::Handle;
|
use bevy_asset::Handle;
|
||||||
use bevy_ecs::Bundle;
|
use bevy_ecs::Bundle;
|
||||||
use bevy_math::Vec3;
|
|
||||||
use bevy_render::{
|
use bevy_render::{
|
||||||
camera::{Camera, OrthographicProjection, VisibleEntities, WindowOrigin},
|
camera::{Camera, OrthographicProjection, VisibleEntities, WindowOrigin},
|
||||||
draw::Draw,
|
draw::Draw,
|
||||||
@ -189,7 +188,7 @@ impl Default for CameraUiBundle {
|
|||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
visible_entities: Default::default(),
|
visible_entities: Default::default(),
|
||||||
transform: Transform::from_translation(Vec3::new(0.0, 0.0, far - 0.1)),
|
transform: Transform::from_xyz(0.0, 0.0, far - 0.1),
|
||||||
global_transform: Default::default(),
|
global_transform: Default::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -74,7 +74,7 @@ fn setup(
|
|||||||
// some sprites should be flipped
|
// some sprites should be flipped
|
||||||
let flipped = rnd.gen_bool(0.5);
|
let flipped = rnd.gen_bool(0.5);
|
||||||
|
|
||||||
let mut transform = Transform::from_translation(Vec3::new(pos.0, pos.1, 0.0));
|
let mut transform = Transform::from_xyz(pos.0, pos.1, 0.0);
|
||||||
transform.scale.x *= if flipped { -1.0 } else { 1.0 };
|
transform.scale.x *= if flipped { -1.0 } else { 1.0 };
|
||||||
|
|
||||||
commands
|
commands
|
||||||
|
@ -79,7 +79,7 @@ fn setup(
|
|||||||
// draw the atlas itself
|
// draw the atlas itself
|
||||||
.spawn(SpriteBundle {
|
.spawn(SpriteBundle {
|
||||||
material: materials.add(texture_atlas_texture.into()),
|
material: materials.add(texture_atlas_texture.into()),
|
||||||
transform: Transform::from_translation(Vec3::new(-300.0, 0.0, 0.0)),
|
transform: Transform::from_xyz(-300.0, 0.0, 0.0),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -26,17 +26,17 @@ fn setup(
|
|||||||
.spawn(PbrBundle {
|
.spawn(PbrBundle {
|
||||||
mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })),
|
mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })),
|
||||||
material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()),
|
material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()),
|
||||||
transform: Transform::from_translation(Vec3::new(0.0, 0.5, 0.0)),
|
transform: Transform::from_xyz(0.0, 0.5, 0.0),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
// light
|
// light
|
||||||
.spawn(LightBundle {
|
.spawn(LightBundle {
|
||||||
transform: Transform::from_translation(Vec3::new(4.0, 8.0, 4.0)),
|
transform: Transform::from_xyz(4.0, 8.0, 4.0),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
// camera
|
// camera
|
||||||
.spawn(Camera3dBundle {
|
.spawn(Camera3dBundle {
|
||||||
transform: Transform::from_translation(Vec3::new(-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()
|
||||||
});
|
});
|
||||||
|
@ -12,11 +12,11 @@ fn setup(commands: &mut Commands, asset_server: Res<AssetServer>) {
|
|||||||
commands
|
commands
|
||||||
.spawn_scene(asset_server.load("models/FlightHelmet/FlightHelmet.gltf#Scene0"))
|
.spawn_scene(asset_server.load("models/FlightHelmet/FlightHelmet.gltf#Scene0"))
|
||||||
.spawn(LightBundle {
|
.spawn(LightBundle {
|
||||||
transform: Transform::from_translation(Vec3::new(4.0, 5.0, 4.0)),
|
transform: Transform::from_xyz(4.0, 5.0, 4.0),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
.spawn(Camera3dBundle {
|
.spawn(Camera3dBundle {
|
||||||
transform: Transform::from_translation(Vec3::new(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()
|
||||||
});
|
});
|
||||||
|
@ -27,12 +27,12 @@ fn setup(
|
|||||||
})
|
})
|
||||||
// light
|
// light
|
||||||
.spawn(LightBundle {
|
.spawn(LightBundle {
|
||||||
transform: Transform::from_translation(Vec3::new(4.0, 8.0, 4.0)),
|
transform: Transform::from_xyz(4.0, 8.0, 4.0),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
// camera
|
// camera
|
||||||
.spawn(Camera3dBundle {
|
.spawn(Camera3dBundle {
|
||||||
transform: Transform::from_translation(Vec3::new(-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()
|
||||||
});
|
});
|
||||||
|
@ -38,7 +38,7 @@ fn setup(
|
|||||||
.spawn(PbrBundle {
|
.spawn(PbrBundle {
|
||||||
mesh: cube_handle.clone(),
|
mesh: cube_handle.clone(),
|
||||||
material: cube_material_handle.clone(),
|
material: cube_material_handle.clone(),
|
||||||
transform: Transform::from_translation(Vec3::new(0.0, 0.0, 1.0)),
|
transform: Transform::from_xyz(0.0, 0.0, 1.0),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
.with(Rotator)
|
.with(Rotator)
|
||||||
@ -47,18 +47,18 @@ fn setup(
|
|||||||
parent.spawn(PbrBundle {
|
parent.spawn(PbrBundle {
|
||||||
mesh: cube_handle,
|
mesh: cube_handle,
|
||||||
material: cube_material_handle,
|
material: cube_material_handle,
|
||||||
transform: Transform::from_translation(Vec3::new(0.0, 0.0, 3.0)),
|
transform: Transform::from_xyz(0.0, 0.0, 3.0),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
// light
|
// light
|
||||||
.spawn(LightBundle {
|
.spawn(LightBundle {
|
||||||
transform: Transform::from_translation(Vec3::new(4.0, 5.0, -4.0)),
|
transform: Transform::from_xyz(4.0, 5.0, -4.0),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
// camera
|
// camera
|
||||||
.spawn(Camera3dBundle {
|
.spawn(Camera3dBundle {
|
||||||
transform: Transform::from_translation(Vec3::new(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()
|
||||||
});
|
});
|
||||||
|
@ -39,12 +39,12 @@ fn setup(
|
|||||||
commands
|
commands
|
||||||
// light
|
// light
|
||||||
.spawn(LightBundle {
|
.spawn(LightBundle {
|
||||||
transform: Transform::from_translation(Vec3::new(4.0, -4.0, 5.0)),
|
transform: Transform::from_xyz(4.0, -4.0, 5.0),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
// camera
|
// camera
|
||||||
.spawn(Camera3dBundle {
|
.spawn(Camera3dBundle {
|
||||||
transform: Transform::from_translation(Vec3::new(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()
|
||||||
});
|
});
|
||||||
@ -62,11 +62,11 @@ fn setup(
|
|||||||
),
|
),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
transform: Transform::from_translation(Vec3::new(
|
transform: Transform::from_xyz(
|
||||||
rng.gen_range(-50.0, 50.0),
|
rng.gen_range(-50.0, 50.0),
|
||||||
rng.gen_range(-50.0, 50.0),
|
rng.gen_range(-50.0, 50.0),
|
||||||
0.0,
|
0.0,
|
||||||
)),
|
),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -96,7 +96,7 @@ fn setup(
|
|||||||
})
|
})
|
||||||
// camera
|
// camera
|
||||||
.spawn(Camera3dBundle {
|
.spawn(Camera3dBundle {
|
||||||
transform: Transform::from_translation(Vec3::new(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()
|
||||||
});
|
});
|
||||||
|
@ -26,11 +26,11 @@ fn setup(
|
|||||||
) {
|
) {
|
||||||
commands
|
commands
|
||||||
.spawn(LightBundle {
|
.spawn(LightBundle {
|
||||||
transform: Transform::from_translation(Vec3::new(4.0, 5.0, 4.0)),
|
transform: Transform::from_xyz(4.0, 5.0, 4.0),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
.spawn(Camera3dBundle {
|
.spawn(Camera3dBundle {
|
||||||
transform: Transform::from_translation(Vec3::new(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()
|
||||||
});
|
});
|
||||||
@ -39,7 +39,7 @@ fn setup(
|
|||||||
// with its parent
|
// with its parent
|
||||||
commands
|
commands
|
||||||
.spawn((
|
.spawn((
|
||||||
Transform::from_translation(Vec3::new(0.0, 0.0, -1.0)),
|
Transform::from_xyz(0.0, 0.0, -1.0),
|
||||||
GlobalTransform::default(),
|
GlobalTransform::default(),
|
||||||
))
|
))
|
||||||
.with_children(|parent| {
|
.with_children(|parent| {
|
||||||
|
@ -55,7 +55,7 @@ fn setup(
|
|||||||
shaded: false,
|
shaded: false,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
transform: Transform::from_translation(Vec3::new(0.0, 0.0, 1.0)),
|
transform: Transform::from_xyz(0.0, 0.0, 1.0),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
.with(Rotator)
|
.with(Rotator)
|
||||||
@ -68,7 +68,7 @@ fn setup(
|
|||||||
shaded: false,
|
shaded: false,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
transform: Transform::from_translation(Vec3::new(0.0, 3.0, 0.0)),
|
transform: Transform::from_xyz(0.0, 3.0, 0.0),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
.spawn(PbrBundle {
|
.spawn(PbrBundle {
|
||||||
@ -77,13 +77,13 @@ fn setup(
|
|||||||
shaded: false,
|
shaded: false,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
transform: Transform::from_translation(Vec3::new(0.0, -3.0, 0.0)),
|
transform: Transform::from_xyz(0.0, -3.0, 0.0),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
// camera
|
// camera
|
||||||
.spawn(Camera3dBundle {
|
.spawn(Camera3dBundle {
|
||||||
transform: Transform::from_translation(Vec3::new(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()
|
||||||
});
|
});
|
||||||
|
@ -28,17 +28,17 @@ fn setup(
|
|||||||
.spawn(PbrBundle {
|
.spawn(PbrBundle {
|
||||||
mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })),
|
mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })),
|
||||||
material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()),
|
material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()),
|
||||||
transform: Transform::from_translation(Vec3::new(0.0, 0.5, 0.0)),
|
transform: Transform::from_xyz(0.0, 0.5, 0.0),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
// light
|
// light
|
||||||
.spawn(LightBundle {
|
.spawn(LightBundle {
|
||||||
transform: Transform::from_translation(Vec3::new(4.0, 8.0, 4.0)),
|
transform: Transform::from_xyz(4.0, 8.0, 4.0),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
// camera
|
// camera
|
||||||
.spawn(Camera3dBundle {
|
.spawn(Camera3dBundle {
|
||||||
transform: Transform::from_translation(Vec3::new(-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()
|
||||||
});
|
});
|
||||||
|
@ -47,31 +47,31 @@ fn setup(
|
|||||||
.spawn(PbrBundle {
|
.spawn(PbrBundle {
|
||||||
mesh: monkey_handle,
|
mesh: monkey_handle,
|
||||||
material: material_handle.clone(),
|
material: material_handle.clone(),
|
||||||
transform: Transform::from_translation(Vec3::new(-3.0, 0.0, 0.0)),
|
transform: Transform::from_xyz(-3.0, 0.0, 0.0),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
// cube
|
// cube
|
||||||
.spawn(PbrBundle {
|
.spawn(PbrBundle {
|
||||||
mesh: cube_handle,
|
mesh: cube_handle,
|
||||||
material: material_handle.clone(),
|
material: material_handle.clone(),
|
||||||
transform: Transform::from_translation(Vec3::new(0.0, 0.0, 0.0)),
|
transform: Transform::from_xyz(0.0, 0.0, 0.0),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
// sphere
|
// sphere
|
||||||
.spawn(PbrBundle {
|
.spawn(PbrBundle {
|
||||||
mesh: sphere_handle,
|
mesh: sphere_handle,
|
||||||
material: material_handle,
|
material: material_handle,
|
||||||
transform: Transform::from_translation(Vec3::new(3.0, 0.0, 0.0)),
|
transform: Transform::from_xyz(3.0, 0.0, 0.0),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
// light
|
// light
|
||||||
.spawn(LightBundle {
|
.spawn(LightBundle {
|
||||||
transform: Transform::from_translation(Vec3::new(4.0, 5.0, 4.0)),
|
transform: Transform::from_xyz(4.0, 5.0, 4.0),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
// camera
|
// camera
|
||||||
.spawn(Camera3dBundle {
|
.spawn(Camera3dBundle {
|
||||||
transform: Transform::from_translation(Vec3::new(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()
|
||||||
});
|
});
|
||||||
|
@ -26,12 +26,12 @@ fn setup(commands: &mut Commands, asset_server: Res<AssetServer>) {
|
|||||||
.spawn_scene(scene_handle)
|
.spawn_scene(scene_handle)
|
||||||
// light
|
// light
|
||||||
.spawn(LightBundle {
|
.spawn(LightBundle {
|
||||||
transform: Transform::from_translation(Vec3::new(4.0, 5.0, 4.0)),
|
transform: Transform::from_xyz(4.0, 5.0, 4.0),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
// camera
|
// camera
|
||||||
.spawn(Camera3dBundle {
|
.spawn(Camera3dBundle {
|
||||||
transform: Transform::from_translation(Vec3::new(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()
|
||||||
});
|
});
|
||||||
|
@ -49,7 +49,7 @@ fn setup(
|
|||||||
// 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()),
|
||||||
transform: Transform::from_translation(Vec3::new(0.0, -215.0, 0.0)),
|
transform: Transform::from_xyz(0.0, -215.0, 0.0),
|
||||||
sprite: Sprite::new(Vec2::new(120.0, 30.0)),
|
sprite: Sprite::new(Vec2::new(120.0, 30.0)),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
@ -58,7 +58,7 @@ fn setup(
|
|||||||
// ball
|
// ball
|
||||||
.spawn(SpriteBundle {
|
.spawn(SpriteBundle {
|
||||||
material: materials.add(Color::rgb(1.0, 0.5, 0.5).into()),
|
material: materials.add(Color::rgb(1.0, 0.5, 0.5).into()),
|
||||||
transform: Transform::from_translation(Vec3::new(0.0, -50.0, 1.0)),
|
transform: Transform::from_xyz(0.0, -50.0, 1.0),
|
||||||
sprite: Sprite::new(Vec2::new(30.0, 30.0)),
|
sprite: Sprite::new(Vec2::new(30.0, 30.0)),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
@ -97,7 +97,7 @@ fn setup(
|
|||||||
// left
|
// left
|
||||||
.spawn(SpriteBundle {
|
.spawn(SpriteBundle {
|
||||||
material: wall_material.clone(),
|
material: wall_material.clone(),
|
||||||
transform: Transform::from_translation(Vec3::new(-bounds.x / 2.0, 0.0, 0.0)),
|
transform: Transform::from_xyz(-bounds.x / 2.0, 0.0, 0.0),
|
||||||
sprite: Sprite::new(Vec2::new(wall_thickness, bounds.y + wall_thickness)),
|
sprite: Sprite::new(Vec2::new(wall_thickness, bounds.y + wall_thickness)),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
@ -105,7 +105,7 @@ fn setup(
|
|||||||
// right
|
// right
|
||||||
.spawn(SpriteBundle {
|
.spawn(SpriteBundle {
|
||||||
material: wall_material.clone(),
|
material: wall_material.clone(),
|
||||||
transform: Transform::from_translation(Vec3::new(bounds.x / 2.0, 0.0, 0.0)),
|
transform: Transform::from_xyz(bounds.x / 2.0, 0.0, 0.0),
|
||||||
sprite: Sprite::new(Vec2::new(wall_thickness, bounds.y + wall_thickness)),
|
sprite: Sprite::new(Vec2::new(wall_thickness, bounds.y + wall_thickness)),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
@ -113,7 +113,7 @@ fn setup(
|
|||||||
// bottom
|
// bottom
|
||||||
.spawn(SpriteBundle {
|
.spawn(SpriteBundle {
|
||||||
material: wall_material.clone(),
|
material: wall_material.clone(),
|
||||||
transform: Transform::from_translation(Vec3::new(0.0, -bounds.y / 2.0, 0.0)),
|
transform: Transform::from_xyz(0.0, -bounds.y / 2.0, 0.0),
|
||||||
sprite: Sprite::new(Vec2::new(bounds.x + wall_thickness, wall_thickness)),
|
sprite: Sprite::new(Vec2::new(bounds.x + wall_thickness, wall_thickness)),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
@ -121,7 +121,7 @@ fn setup(
|
|||||||
// top
|
// top
|
||||||
.spawn(SpriteBundle {
|
.spawn(SpriteBundle {
|
||||||
material: wall_material,
|
material: wall_material,
|
||||||
transform: Transform::from_translation(Vec3::new(0.0, bounds.y / 2.0, 0.0)),
|
transform: Transform::from_xyz(0.0, bounds.y / 2.0, 0.0),
|
||||||
sprite: Sprite::new(Vec2::new(bounds.x + wall_thickness, wall_thickness)),
|
sprite: Sprite::new(Vec2::new(bounds.x + wall_thickness, wall_thickness)),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
|
@ -33,7 +33,7 @@ fn setup(
|
|||||||
.spawn(PbrBundle {
|
.spawn(PbrBundle {
|
||||||
mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })),
|
mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })),
|
||||||
material: materials.add(Color::rgb(0.5, 0.4, 0.3).into()),
|
material: materials.add(Color::rgb(0.5, 0.4, 0.3).into()),
|
||||||
transform: Transform::from_translation(Vec3::new(0.0, 0.5, 0.0)),
|
transform: Transform::from_xyz(0.0, 0.5, 0.0),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
// sphere
|
// sphere
|
||||||
@ -43,17 +43,17 @@ fn setup(
|
|||||||
radius: 0.5,
|
radius: 0.5,
|
||||||
})),
|
})),
|
||||||
material: materials.add(Color::rgb(0.1, 0.4, 0.8).into()),
|
material: materials.add(Color::rgb(0.1, 0.4, 0.8).into()),
|
||||||
transform: Transform::from_translation(Vec3::new(1.5, 1.5, 1.5)),
|
transform: Transform::from_xyz(1.5, 1.5, 1.5),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
// light
|
// light
|
||||||
.spawn(LightBundle {
|
.spawn(LightBundle {
|
||||||
transform: Transform::from_translation(Vec3::new(4.0, 8.0, 4.0)),
|
transform: Transform::from_xyz(4.0, 8.0, 4.0),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
// camera
|
// camera
|
||||||
.spawn(Camera3dBundle {
|
.spawn(Camera3dBundle {
|
||||||
transform: Transform::from_translation(Vec3::new(-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()
|
||||||
});
|
});
|
||||||
|
@ -110,8 +110,7 @@ fn setup(
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
commands.spawn(Camera3dBundle {
|
commands.spawn(Camera3dBundle {
|
||||||
transform: Transform::from_translation(Vec3::new(2.0, 2.0, 2.0))
|
transform: Transform::from_xyz(2.0, 2.0, 2.0).looking_at(Vec3::default(), Vec3::unit_y()),
|
||||||
.looking_at(Vec3::default(), Vec3::unit_y()),
|
|
||||||
..Default::default()
|
..Default::default()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -67,13 +67,13 @@ fn setup(
|
|||||||
render_pipelines: RenderPipelines::from_pipelines(vec![RenderPipeline::new(
|
render_pipelines: RenderPipelines::from_pipelines(vec![RenderPipeline::new(
|
||||||
pipeline_handle,
|
pipeline_handle,
|
||||||
)]),
|
)]),
|
||||||
transform: Transform::from_translation(Vec3::new(0.0, 0.0, 0.0)),
|
transform: Transform::from_xyz(0.0, 0.0, 0.0),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
.with(material)
|
.with(material)
|
||||||
// camera
|
// camera
|
||||||
.spawn(Camera3dBundle {
|
.spawn(Camera3dBundle {
|
||||||
transform: Transform::from_translation(Vec3::new(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()
|
||||||
});
|
});
|
||||||
|
@ -132,13 +132,13 @@ fn setup(
|
|||||||
render_pipelines: RenderPipelines::from_pipelines(vec![RenderPipeline::new(
|
render_pipelines: RenderPipelines::from_pipelines(vec![RenderPipeline::new(
|
||||||
pipeline_handle,
|
pipeline_handle,
|
||||||
)]),
|
)]),
|
||||||
transform: Transform::from_translation(Vec3::new(0.0, 0.0, 0.0)),
|
transform: Transform::from_xyz(0.0, 0.0, 0.0),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
.with(material)
|
.with(material)
|
||||||
// camera
|
// camera
|
||||||
.spawn(Camera3dBundle {
|
.spawn(Camera3dBundle {
|
||||||
transform: Transform::from_translation(Vec3::new(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()
|
||||||
});
|
});
|
||||||
|
@ -88,13 +88,13 @@ fn setup(
|
|||||||
render_pipelines: RenderPipelines::from_pipelines(vec![RenderPipeline::new(
|
render_pipelines: RenderPipelines::from_pipelines(vec![RenderPipeline::new(
|
||||||
pipeline_handle,
|
pipeline_handle,
|
||||||
)]),
|
)]),
|
||||||
transform: Transform::from_translation(Vec3::new(0.0, 0.0, 0.0)),
|
transform: Transform::from_xyz(0.0, 0.0, 0.0),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
.with(material)
|
.with(material)
|
||||||
// camera
|
// camera
|
||||||
.spawn(Camera3dBundle {
|
.spawn(Camera3dBundle {
|
||||||
transform: Transform::from_translation(Vec3::new(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()
|
||||||
});
|
});
|
||||||
|
@ -109,7 +109,7 @@ fn setup(
|
|||||||
render_pipelines: RenderPipelines::from_pipelines(vec![RenderPipeline::new(
|
render_pipelines: RenderPipelines::from_pipelines(vec![RenderPipeline::new(
|
||||||
pipeline_handle.clone(),
|
pipeline_handle.clone(),
|
||||||
)]),
|
)]),
|
||||||
transform: Transform::from_translation(Vec3::new(-2.0, 0.0, 0.0)),
|
transform: Transform::from_xyz(-2.0, 0.0, 0.0),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
.with(green_material)
|
.with(green_material)
|
||||||
@ -119,13 +119,13 @@ fn setup(
|
|||||||
render_pipelines: RenderPipelines::from_pipelines(vec![RenderPipeline::new(
|
render_pipelines: RenderPipelines::from_pipelines(vec![RenderPipeline::new(
|
||||||
pipeline_handle,
|
pipeline_handle,
|
||||||
)]),
|
)]),
|
||||||
transform: Transform::from_translation(Vec3::new(2.0, 0.0, 0.0)),
|
transform: Transform::from_xyz(2.0, 0.0, 0.0),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
.with(blue_material)
|
.with(blue_material)
|
||||||
// camera
|
// camera
|
||||||
.spawn(Camera3dBundle {
|
.spawn(Camera3dBundle {
|
||||||
transform: Transform::from_translation(Vec3::new(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()
|
||||||
});
|
});
|
||||||
|
@ -188,12 +188,12 @@ fn setup_pipeline(
|
|||||||
.spawn_scene(asset_server.load("models/monkey/Monkey.gltf#Scene0"))
|
.spawn_scene(asset_server.load("models/monkey/Monkey.gltf#Scene0"))
|
||||||
// light
|
// light
|
||||||
.spawn(LightBundle {
|
.spawn(LightBundle {
|
||||||
transform: Transform::from_translation(Vec3::new(4.0, 5.0, 4.0)),
|
transform: Transform::from_xyz(4.0, 5.0, 4.0),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
// main camera
|
// main camera
|
||||||
.spawn(Camera3dBundle {
|
.spawn(Camera3dBundle {
|
||||||
transform: Transform::from_translation(Vec3::new(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()
|
||||||
})
|
})
|
||||||
@ -204,7 +204,7 @@ fn setup_pipeline(
|
|||||||
window: window_id,
|
window: window_id,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
transform: Transform::from_translation(Vec3::new(6.0, 0.0, 0.0))
|
transform: Transform::from_xyz(6.0, 0.0, 0.0)
|
||||||
.looking_at(Vec3::default(), Vec3::unit_y()),
|
.looking_at(Vec3::default(), Vec3::unit_y()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user