mirror of
https://github.com/eliasstepanik/big_space_with_trim.git
synced 2026-01-11 18:38:28 +00:00
parent
be690d90d5
commit
6fa7d31a0e
35
Cargo.toml
35
Cargo.toml
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "big_space"
|
name = "big_space"
|
||||||
version = "0.7.0-rc.0"
|
version = "0.6.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
description = "A floating origin plugin for bevy"
|
description = "A floating origin plugin for bevy"
|
||||||
license = "MIT OR Apache-2.0"
|
license = "MIT OR Apache-2.0"
|
||||||
@ -9,23 +9,22 @@ repository = "https://github.com/aevyrie/big_space"
|
|||||||
documentation = "https://docs.rs/crate/big_space/latest"
|
documentation = "https://docs.rs/crate/big_space/latest"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bevy_app = { version = "0.14.0-rc.4", default_features = false }
|
bevy_app = { version = "0.13", default_features = false }
|
||||||
bevy_ecs = { version = "0.14.0-rc.4", default_features = false }
|
bevy_ecs = { version = "0.13", default_features = false }
|
||||||
bevy_hierarchy = { version = "0.14.0-rc.4", default_features = false }
|
bevy_hierarchy = { version = "0.13", default_features = false }
|
||||||
bevy_log = { version = "0.14.0-rc.4", default_features = false }
|
bevy_log = { version = "0.13", default_features = false }
|
||||||
bevy_math = { version = "0.14.0-rc.4", default_features = false }
|
bevy_math = { version = "0.13", default_features = false }
|
||||||
bevy_reflect = { version = "0.14.0-rc.4", default_features = false }
|
bevy_reflect = { version = "0.13", default_features = false }
|
||||||
bevy_transform = { version = "0.14.0-rc.4", default_features = false }
|
bevy_transform = { version = "0.13", default_features = false }
|
||||||
bevy_utils = { version = "0.14.0-rc.4", default_features = false }
|
bevy_utils = { version = "0.13", default_features = false }
|
||||||
# Optional
|
# Optional
|
||||||
bevy_color = { version = "0.14.0-rc.4", default_features = false, optional = true }
|
bevy_gizmos = { version = "0.13", default_features = false, optional = true }
|
||||||
bevy_gizmos = { version = "0.14.0-rc.4", default_features = false, optional = true }
|
bevy_render = { version = "0.13", default_features = false, optional = true }
|
||||||
bevy_render = { version = "0.14.0-rc.4", default_features = false, optional = true }
|
bevy_input = { version = "0.13", default_features = false, optional = true }
|
||||||
bevy_input = { version = "0.14.0-rc.4", default_features = false, optional = true }
|
bevy_time = { version = "0.13", default_features = false, optional = true }
|
||||||
bevy_time = { version = "0.14.0-rc.4", default_features = false, optional = true }
|
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
bevy = { version = "0.14.0-rc.4", default-features = false, features = [
|
bevy = { version = "0.13", default-features = false, features = [
|
||||||
"bevy_scene",
|
"bevy_scene",
|
||||||
"bevy_gltf",
|
"bevy_gltf",
|
||||||
"bevy_winit",
|
"bevy_winit",
|
||||||
@ -35,14 +34,14 @@ bevy = { version = "0.14.0-rc.4", default-features = false, features = [
|
|||||||
"bevy_gizmos",
|
"bevy_gizmos",
|
||||||
"x11",
|
"x11",
|
||||||
"tonemapping_luts",
|
"tonemapping_luts",
|
||||||
"multi_threaded",
|
"multi-threaded",
|
||||||
] }
|
] }
|
||||||
# bevy-inspector-egui = "0.24"
|
bevy-inspector-egui = "0.24"
|
||||||
rand = "0.8.5"
|
rand = "0.8.5"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["debug", "camera", "bevy_render"]
|
default = ["debug", "camera", "bevy_render"]
|
||||||
debug = ["bevy_gizmos", "bevy_color"]
|
debug = ["bevy_gizmos", "bevy_render"]
|
||||||
camera = ["bevy_render", "bevy_time", "bevy_input"]
|
camera = ["bevy_render", "bevy_time", "bevy_input"]
|
||||||
|
|
||||||
[[example]]
|
[[example]]
|
||||||
|
|||||||
@ -38,7 +38,6 @@ From the docs: https://docs.rs/big_space/latest/big_space/precision/trait.GridPr
|
|||||||
|
|
||||||
| bevy | big_space |
|
| bevy | big_space |
|
||||||
| ---- | --------- |
|
| ---- | --------- |
|
||||||
| 0.14 | 0.7 |
|
|
||||||
| 0.13 | 0.5, 0.6 |
|
| 0.13 | 0.5, 0.6 |
|
||||||
| 0.12 | 0.4 |
|
| 0.12 | 0.4 |
|
||||||
| 0.11 | 0.3 |
|
| 0.11 | 0.3 |
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
#![allow(clippy::type_complexity)]
|
#![allow(clippy::type_complexity)]
|
||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy_color::palettes;
|
|
||||||
use big_space::{commands::BigSpaceCommands, reference_frame::ReferenceFrame, FloatingOrigin};
|
use big_space::{commands::BigSpaceCommands, reference_frame::ReferenceFrame, FloatingOrigin};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
@ -14,7 +13,7 @@ fn main() {
|
|||||||
.insert_resource(ClearColor(Color::BLACK))
|
.insert_resource(ClearColor(Color::BLACK))
|
||||||
.add_systems(Startup, setup)
|
.add_systems(Startup, setup)
|
||||||
.add_systems(Update, (movement, rotation))
|
.add_systems(Update, (movement, rotation))
|
||||||
.run();
|
.run()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
@ -62,7 +61,7 @@ fn setup(
|
|||||||
) {
|
) {
|
||||||
let mesh_handle = meshes.add(Sphere::new(0.1).mesh().ico(16).unwrap());
|
let mesh_handle = meshes.add(Sphere::new(0.1).mesh().ico(16).unwrap());
|
||||||
let matl_handle = materials.add(StandardMaterial {
|
let matl_handle = materials.add(StandardMaterial {
|
||||||
base_color: Color::Srgba(palettes::basic::YELLOW),
|
base_color: Color::YELLOW,
|
||||||
..default()
|
..default()
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -3,7 +3,6 @@ use bevy::{
|
|||||||
transform::TransformSystem,
|
transform::TransformSystem,
|
||||||
window::{CursorGrabMode, PrimaryWindow},
|
window::{CursorGrabMode, PrimaryWindow},
|
||||||
};
|
};
|
||||||
use bevy_color::palettes;
|
|
||||||
use big_space::{
|
use big_space::{
|
||||||
camera::{CameraController, CameraInput},
|
camera::{CameraController, CameraInput},
|
||||||
commands::BigSpaceCommands,
|
commands::BigSpaceCommands,
|
||||||
@ -27,7 +26,7 @@ fn main() {
|
|||||||
PostUpdate,
|
PostUpdate,
|
||||||
highlight_nearest_sphere.after(TransformSystem::TransformPropagate),
|
highlight_nearest_sphere.after(TransformSystem::TransformPropagate),
|
||||||
)
|
)
|
||||||
.run();
|
.run()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn setup(
|
fn setup(
|
||||||
@ -55,7 +54,7 @@ fn setup(
|
|||||||
|
|
||||||
let mesh_handle = meshes.add(Sphere::new(0.5).mesh().ico(32).unwrap());
|
let mesh_handle = meshes.add(Sphere::new(0.5).mesh().ico(32).unwrap());
|
||||||
let matl_handle = materials.add(StandardMaterial {
|
let matl_handle = materials.add(StandardMaterial {
|
||||||
base_color: Color::Srgba(palettes::basic::BLUE),
|
base_color: Color::BLUE,
|
||||||
perceptual_roughness: 0.8,
|
perceptual_roughness: 0.8,
|
||||||
reflectance: 1.0,
|
reflectance: 1.0,
|
||||||
..default()
|
..default()
|
||||||
@ -79,7 +78,7 @@ fn setup(
|
|||||||
// light
|
// light
|
||||||
root.spawn_spatial(DirectionalLightBundle {
|
root.spawn_spatial(DirectionalLightBundle {
|
||||||
directional_light: DirectionalLight {
|
directional_light: DirectionalLight {
|
||||||
illuminance: 10_000.0,
|
illuminance: 100_000.0,
|
||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
..default()
|
..default()
|
||||||
@ -148,13 +147,8 @@ fn highlight_nearest_sphere(
|
|||||||
// Ignore rotation due to panicking in gizmos, as of bevy 0.13
|
// Ignore rotation due to panicking in gizmos, as of bevy 0.13
|
||||||
let (scale, rotation, translation) = transform.to_scale_rotation_translation();
|
let (scale, rotation, translation) = transform.to_scale_rotation_translation();
|
||||||
gizmos
|
gizmos
|
||||||
.sphere(
|
.sphere(translation, rotation, scale.x * 0.505, Color::RED)
|
||||||
translation,
|
.circle_segments(128);
|
||||||
rotation,
|
|
||||||
scale.x * 0.505,
|
|
||||||
Color::Srgba(palettes::basic::RED),
|
|
||||||
)
|
|
||||||
.resolution(128);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::type_complexity)]
|
#[allow(clippy::type_complexity)]
|
||||||
|
|||||||
@ -20,7 +20,7 @@ fn main() {
|
|||||||
))
|
))
|
||||||
.add_systems(Startup, (setup_scene, setup_ui))
|
.add_systems(Startup, (setup_scene, setup_ui))
|
||||||
.add_systems(Update, (rotator_system, toggle_plugin))
|
.add_systems(Update, (rotator_system, toggle_plugin))
|
||||||
.run();
|
.run()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// You can put things really, really far away from the origin. The distance we use here is actually
|
/// You can put things really, really far away from the origin. The distance we use here is actually
|
||||||
|
|||||||
@ -1,19 +1,18 @@
|
|||||||
//! This example demonstrates error accumulating from parent to children in nested reference frames.
|
//! This example demonstrates error accumulating from parent to children in nested reference frames.
|
||||||
use bevy::{math::DVec3, prelude::*};
|
use bevy::{math::DVec3, prelude::*};
|
||||||
use bevy_color::palettes;
|
|
||||||
use big_space::{commands::BigSpaceCommands, reference_frame::ReferenceFrame, FloatingOrigin};
|
use big_space::{commands::BigSpaceCommands, reference_frame::ReferenceFrame, FloatingOrigin};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
App::new()
|
App::new()
|
||||||
.add_plugins((
|
.add_plugins((
|
||||||
DefaultPlugins.build().disable::<TransformPlugin>(),
|
DefaultPlugins.build().disable::<TransformPlugin>(),
|
||||||
// bevy_inspector_egui::quick::WorldInspectorPlugin::new(),
|
bevy_inspector_egui::quick::WorldInspectorPlugin::new(),
|
||||||
big_space::BigSpacePlugin::<i64>::default(),
|
big_space::BigSpacePlugin::<i64>::default(),
|
||||||
big_space::camera::CameraControllerPlugin::<i64>::default(),
|
big_space::camera::CameraControllerPlugin::<i64>::default(),
|
||||||
big_space::debug::FloatingOriginDebugPlugin::<i64>::default(),
|
big_space::debug::FloatingOriginDebugPlugin::<i64>::default(),
|
||||||
))
|
))
|
||||||
.add_systems(Startup, setup_scene)
|
.add_systems(Startup, setup_scene)
|
||||||
.run();
|
.run()
|
||||||
}
|
}
|
||||||
|
|
||||||
// The nearby object is NEARBY meters away from us. The distance object is DISTANT meters away from
|
// The nearby object is NEARBY meters away from us. The distance object is DISTANT meters away from
|
||||||
@ -29,7 +28,7 @@ fn setup_scene(
|
|||||||
) {
|
) {
|
||||||
let mesh_handle = meshes.add(Sphere::new(SPHERE_RADIUS).mesh());
|
let mesh_handle = meshes.add(Sphere::new(SPHERE_RADIUS).mesh());
|
||||||
let matl_handle = materials.add(StandardMaterial {
|
let matl_handle = materials.add(StandardMaterial {
|
||||||
base_color: Color::srgb(0.8, 0.7, 0.6),
|
base_color: Color::rgb(0.8, 0.7, 0.6),
|
||||||
..default()
|
..default()
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -38,7 +37,7 @@ fn setup_scene(
|
|||||||
|root_frame| {
|
|root_frame| {
|
||||||
root_frame.spawn_spatial(PbrBundle {
|
root_frame.spawn_spatial(PbrBundle {
|
||||||
mesh: mesh_handle.clone(),
|
mesh: mesh_handle.clone(),
|
||||||
material: materials.add(Color::from(palettes::css::BLUE)),
|
material: materials.add(Color::BLUE),
|
||||||
transform: Transform::from_translation(NEARBY),
|
transform: Transform::from_translation(NEARBY),
|
||||||
..default()
|
..default()
|
||||||
});
|
});
|
||||||
@ -47,8 +46,8 @@ fn setup_scene(
|
|||||||
root_frame.with_frame(
|
root_frame.with_frame(
|
||||||
ReferenceFrame::new(SPHERE_RADIUS * 100.0, 0.0),
|
ReferenceFrame::new(SPHERE_RADIUS * 100.0, 0.0),
|
||||||
|parent_frame| {
|
|parent_frame| {
|
||||||
// This function introduces a small amount of error, because it can only work up
|
// This function introduces a small amount of error, because it can only work up to
|
||||||
// to double precision floats. (f64).
|
// double precision floats. (f64).
|
||||||
let child = parent_frame
|
let child = parent_frame
|
||||||
.frame()
|
.frame()
|
||||||
.translation_to_grid(-DISTANT + NEARBY.as_dvec3());
|
.translation_to_grid(-DISTANT + NEARBY.as_dvec3());
|
||||||
@ -61,16 +60,16 @@ fn setup_scene(
|
|||||||
parent_frame.insert(parent.0);
|
parent_frame.insert(parent.0);
|
||||||
|
|
||||||
parent_frame.with_children(|child_builder| {
|
parent_frame.with_children(|child_builder| {
|
||||||
// A green sphere that is a child of the sphere very far from the origin.
|
// A green sphere that is a child of the sphere very far from the origin. This
|
||||||
// This child is very far from its parent, and should be located exactly at
|
// child is very far from its parent, and should be located exactly at the
|
||||||
// the origin (if there was no floating point error). The distance from the
|
// origin (if there was no floating point error). The distance from the green
|
||||||
// green sphere to the red sphere is the error caused by float imprecision.
|
// sphere to the red sphere is the error caused by float imprecision. Note that
|
||||||
// Note that the sphere does not have any rendering artifacts, its position
|
// the sphere does not have any rendering artifacts, its position just has a
|
||||||
// just has a fixed error.
|
// fixed error.
|
||||||
child_builder.spawn((
|
child_builder.spawn((
|
||||||
PbrBundle {
|
PbrBundle {
|
||||||
mesh: mesh_handle,
|
mesh: mesh_handle,
|
||||||
material: materials.add(Color::from(palettes::css::GREEN)),
|
material: materials.add(Color::GREEN),
|
||||||
transform: Transform::from_translation(child.1),
|
transform: Transform::from_translation(child.1),
|
||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
|
|||||||
@ -11,7 +11,6 @@ use bevy::{
|
|||||||
render::camera::Exposure,
|
render::camera::Exposure,
|
||||||
transform::TransformSystem,
|
transform::TransformSystem,
|
||||||
};
|
};
|
||||||
use bevy_color::palettes;
|
|
||||||
use big_space::{
|
use big_space::{
|
||||||
camera::{CameraController, CameraInput},
|
camera::{CameraController, CameraInput},
|
||||||
commands::BigSpaceCommands,
|
commands::BigSpaceCommands,
|
||||||
@ -52,7 +51,7 @@ fn main() {
|
|||||||
)
|
)
|
||||||
.register_type::<Sun>()
|
.register_type::<Sun>()
|
||||||
.register_type::<Rotates>()
|
.register_type::<Rotates>()
|
||||||
.run();
|
.run()
|
||||||
}
|
}
|
||||||
|
|
||||||
const EARTH_ORBIT_RADIUS_M: f64 = 149.60e9;
|
const EARTH_ORBIT_RADIUS_M: f64 = 149.60e9;
|
||||||
@ -130,7 +129,7 @@ fn spawn_solar_system(
|
|||||||
let earth_mesh_handle = meshes.add(Sphere::new(1.0).mesh().ico(35).unwrap());
|
let earth_mesh_handle = meshes.add(Sphere::new(1.0).mesh().ico(35).unwrap());
|
||||||
let moon_mesh_handle = meshes.add(Sphere::new(MOON_RADIUS_M as f32).mesh().ico(15).unwrap());
|
let moon_mesh_handle = meshes.add(Sphere::new(MOON_RADIUS_M as f32).mesh().ico(15).unwrap());
|
||||||
let ball_mesh_handle = meshes.add(Sphere::new(5.0).mesh().ico(5).unwrap());
|
let ball_mesh_handle = meshes.add(Sphere::new(5.0).mesh().ico(5).unwrap());
|
||||||
let plane_mesh_handle = meshes.add(Plane3d::new(Vec3::X, Vec2::splat(0.5)));
|
let plane_mesh_handle = meshes.add(Plane3d::new(Vec3::X));
|
||||||
|
|
||||||
commands.spawn((
|
commands.spawn((
|
||||||
PrimaryLight,
|
PrimaryLight,
|
||||||
@ -161,7 +160,7 @@ fn spawn_solar_system(
|
|||||||
mesh: sun_mesh_handle,
|
mesh: sun_mesh_handle,
|
||||||
material: materials.add(StandardMaterial {
|
material: materials.add(StandardMaterial {
|
||||||
base_color: Color::WHITE,
|
base_color: Color::WHITE,
|
||||||
emissive: LinearRgba::rgb(100000., 100000., 100000.),
|
emissive: Color::rgb_linear(100000000., 100000000., 100000000.),
|
||||||
..default()
|
..default()
|
||||||
}),
|
}),
|
||||||
..default()
|
..default()
|
||||||
@ -178,7 +177,7 @@ fn spawn_solar_system(
|
|||||||
PbrBundle {
|
PbrBundle {
|
||||||
mesh: earth_mesh_handle,
|
mesh: earth_mesh_handle,
|
||||||
material: materials.add(StandardMaterial {
|
material: materials.add(StandardMaterial {
|
||||||
base_color: Color::Srgba(palettes::css::BLUE),
|
base_color: Color::BLUE,
|
||||||
perceptual_roughness: 0.8,
|
perceptual_roughness: 0.8,
|
||||||
reflectance: 1.0,
|
reflectance: 1.0,
|
||||||
..default()
|
..default()
|
||||||
@ -198,7 +197,7 @@ fn spawn_solar_system(
|
|||||||
PbrBundle {
|
PbrBundle {
|
||||||
mesh: moon_mesh_handle,
|
mesh: moon_mesh_handle,
|
||||||
material: materials.add(StandardMaterial {
|
material: materials.add(StandardMaterial {
|
||||||
base_color: Color::Srgba(palettes::css::GRAY),
|
base_color: Color::GRAY,
|
||||||
perceptual_roughness: 1.0,
|
perceptual_roughness: 1.0,
|
||||||
reflectance: 0.0,
|
reflectance: 0.0,
|
||||||
..default()
|
..default()
|
||||||
@ -227,7 +226,7 @@ fn spawn_solar_system(
|
|||||||
children.spawn((PbrBundle {
|
children.spawn((PbrBundle {
|
||||||
mesh: plane_mesh_handle,
|
mesh: plane_mesh_handle,
|
||||||
material: materials.add(StandardMaterial {
|
material: materials.add(StandardMaterial {
|
||||||
base_color: Color::Srgba(palettes::css::DARK_GREEN),
|
base_color: Color::DARK_GREEN,
|
||||||
perceptual_roughness: 1.0,
|
perceptual_roughness: 1.0,
|
||||||
reflectance: 0.0,
|
reflectance: 0.0,
|
||||||
..default()
|
..default()
|
||||||
@ -283,7 +282,7 @@ fn spawn_solar_system(
|
|||||||
|
|
||||||
let star_mat = materials.add(StandardMaterial {
|
let star_mat = materials.add(StandardMaterial {
|
||||||
base_color: Color::WHITE,
|
base_color: Color::WHITE,
|
||||||
emissive: LinearRgba::rgb(2., 2., 2.),
|
emissive: Color::rgb_linear(100000., 100000., 100000.),
|
||||||
..default()
|
..default()
|
||||||
});
|
});
|
||||||
let star_mesh_handle = meshes.add(Sphere::new(1e10).mesh().ico(5).unwrap());
|
let star_mesh_handle = meshes.add(Sphere::new(1e10).mesh().ico(5).unwrap());
|
||||||
|
|||||||
@ -9,7 +9,6 @@ use bevy::{
|
|||||||
render::{camera::Viewport, view::RenderLayers},
|
render::{camera::Viewport, view::RenderLayers},
|
||||||
transform::TransformSystem,
|
transform::TransformSystem,
|
||||||
};
|
};
|
||||||
use bevy_color::palettes;
|
|
||||||
use big_space::{
|
use big_space::{
|
||||||
camera::{CameraController, CameraControllerPlugin},
|
camera::{CameraController, CameraControllerPlugin},
|
||||||
commands::BigSpaceCommands,
|
commands::BigSpaceCommands,
|
||||||
@ -34,7 +33,7 @@ fn main() {
|
|||||||
.after(big_space::camera::camera_controller::<i32>)
|
.after(big_space::camera::camera_controller::<i32>)
|
||||||
.before(TransformSystem::TransformPropagate),
|
.before(TransformSystem::TransformPropagate),
|
||||||
)
|
)
|
||||||
.run();
|
.run()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
@ -59,7 +58,7 @@ fn setup(
|
|||||||
transform: Transform::default().looking_to(Vec3::NEG_ONE, Vec3::Y),
|
transform: Transform::default().looking_to(Vec3::NEG_ONE, Vec3::Y),
|
||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
RenderLayers::from_layers(&[1, 2]),
|
RenderLayers::all(),
|
||||||
));
|
));
|
||||||
|
|
||||||
// Big Space 1
|
// Big Space 1
|
||||||
@ -81,7 +80,7 @@ fn setup(
|
|||||||
PbrBundle {
|
PbrBundle {
|
||||||
mesh: meshes.add(Cuboid::new(1.0, 2.0, 1.0)),
|
mesh: meshes.add(Cuboid::new(1.0, 2.0, 1.0)),
|
||||||
material: materials.add(StandardMaterial {
|
material: materials.add(StandardMaterial {
|
||||||
base_color: Color::Srgba(palettes::css::YELLOW),
|
base_color: Color::YELLOW,
|
||||||
..default()
|
..default()
|
||||||
}),
|
}),
|
||||||
..default()
|
..default()
|
||||||
@ -95,7 +94,7 @@ fn setup(
|
|||||||
PbrBundle {
|
PbrBundle {
|
||||||
mesh: meshes.add(Cuboid::new(1.0, 2.0, 1.0)),
|
mesh: meshes.add(Cuboid::new(1.0, 2.0, 1.0)),
|
||||||
material: materials.add(StandardMaterial {
|
material: materials.add(StandardMaterial {
|
||||||
base_color: Color::Srgba(palettes::css::FUCHSIA),
|
base_color: Color::PINK,
|
||||||
..default()
|
..default()
|
||||||
}),
|
}),
|
||||||
..default()
|
..default()
|
||||||
@ -107,7 +106,7 @@ fn setup(
|
|||||||
PbrBundle {
|
PbrBundle {
|
||||||
mesh: meshes.add(Sphere::new(1.0).mesh().ico(35).unwrap()),
|
mesh: meshes.add(Sphere::new(1.0).mesh().ico(35).unwrap()),
|
||||||
material: materials.add(StandardMaterial {
|
material: materials.add(StandardMaterial {
|
||||||
base_color: Color::Srgba(palettes::css::BLUE),
|
base_color: Color::BLUE,
|
||||||
..default()
|
..default()
|
||||||
}),
|
}),
|
||||||
transform: Transform::from_xyz(1_000_000.0, 0.0, 0.0)
|
transform: Transform::from_xyz(1_000_000.0, 0.0, 0.0)
|
||||||
@ -121,7 +120,7 @@ fn setup(
|
|||||||
PbrBundle {
|
PbrBundle {
|
||||||
mesh: meshes.add(Sphere::new(1.0).mesh().ico(35).unwrap()),
|
mesh: meshes.add(Sphere::new(1.0).mesh().ico(35).unwrap()),
|
||||||
material: materials.add(StandardMaterial {
|
material: materials.add(StandardMaterial {
|
||||||
base_color: Color::Srgba(palettes::css::GREEN),
|
base_color: Color::GREEN,
|
||||||
..default()
|
..default()
|
||||||
}),
|
}),
|
||||||
transform: Transform::from_xyz(-1_000_000.0, 0.0, 0.0)
|
transform: Transform::from_xyz(-1_000_000.0, 0.0, 0.0)
|
||||||
@ -155,7 +154,7 @@ fn setup(
|
|||||||
PbrBundle {
|
PbrBundle {
|
||||||
mesh: meshes.add(Cuboid::new(1.0, 2.0, 1.0)),
|
mesh: meshes.add(Cuboid::new(1.0, 2.0, 1.0)),
|
||||||
material: materials.add(StandardMaterial {
|
material: materials.add(StandardMaterial {
|
||||||
base_color: Color::Srgba(palettes::css::PINK),
|
base_color: Color::PINK,
|
||||||
..default()
|
..default()
|
||||||
}),
|
}),
|
||||||
..default()
|
..default()
|
||||||
@ -169,7 +168,7 @@ fn setup(
|
|||||||
PbrBundle {
|
PbrBundle {
|
||||||
mesh: meshes.add(Cuboid::new(1.0, 2.0, 1.0)),
|
mesh: meshes.add(Cuboid::new(1.0, 2.0, 1.0)),
|
||||||
material: materials.add(StandardMaterial {
|
material: materials.add(StandardMaterial {
|
||||||
base_color: Color::Srgba(palettes::css::YELLOW),
|
base_color: Color::YELLOW,
|
||||||
..default()
|
..default()
|
||||||
}),
|
}),
|
||||||
..default()
|
..default()
|
||||||
@ -181,7 +180,7 @@ fn setup(
|
|||||||
PbrBundle {
|
PbrBundle {
|
||||||
mesh: meshes.add(Sphere::new(1.0).mesh().ico(35).unwrap()),
|
mesh: meshes.add(Sphere::new(1.0).mesh().ico(35).unwrap()),
|
||||||
material: materials.add(StandardMaterial {
|
material: materials.add(StandardMaterial {
|
||||||
base_color: Color::Srgba(palettes::css::BLUE),
|
base_color: Color::BLUE,
|
||||||
..default()
|
..default()
|
||||||
}),
|
}),
|
||||||
transform: Transform::from_xyz(1_000_000.0, 0.0, 0.0)
|
transform: Transform::from_xyz(1_000_000.0, 0.0, 0.0)
|
||||||
@ -195,7 +194,7 @@ fn setup(
|
|||||||
PbrBundle {
|
PbrBundle {
|
||||||
mesh: meshes.add(Sphere::new(1.0).mesh().ico(35).unwrap()),
|
mesh: meshes.add(Sphere::new(1.0).mesh().ico(35).unwrap()),
|
||||||
material: materials.add(StandardMaterial {
|
material: materials.add(StandardMaterial {
|
||||||
base_color: Color::Srgba(palettes::css::GREEN),
|
base_color: Color::GREEN,
|
||||||
..default()
|
..default()
|
||||||
}),
|
}),
|
||||||
transform: Transform::from_xyz(-1_000_000.0, 0.0, 0.0)
|
transform: Transform::from_xyz(-1_000_000.0, 0.0, 0.0)
|
||||||
|
|||||||
@ -45,12 +45,6 @@ pub struct CameraController {
|
|||||||
pub rotational_smoothness: f64,
|
pub rotational_smoothness: f64,
|
||||||
/// Base speed.
|
/// Base speed.
|
||||||
pub speed: f64,
|
pub speed: f64,
|
||||||
/// Rotational yaw speed multiplier.
|
|
||||||
pub speed_yaw: f64,
|
|
||||||
/// Rotational pitch speed multiplier.
|
|
||||||
pub speed_pitch: f64,
|
|
||||||
/// Rotational roll speed multiplier.
|
|
||||||
pub speed_roll: f64,
|
|
||||||
/// Minimum and maximum speed.
|
/// Minimum and maximum speed.
|
||||||
pub speed_bounds: [f64; 2],
|
pub speed_bounds: [f64; 2],
|
||||||
/// Whether the camera should slow down when approaching an entity's [`Aabb`].
|
/// Whether the camera should slow down when approaching an entity's [`Aabb`].
|
||||||
@ -79,25 +73,6 @@ impl CameraController {
|
|||||||
self.speed = speed;
|
self.speed = speed;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the yaw angular velocity of the controller, and returns the modified result.
|
|
||||||
pub fn with_speed_yaw(mut self, speed: f64) -> Self {
|
|
||||||
self.speed_yaw = speed;
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets the pitch angular velocity of the controller, and returns the modified result.
|
|
||||||
pub fn with_speed_pitch(mut self, speed: f64) -> Self {
|
|
||||||
self.speed_pitch = speed;
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets the pitch angular velocity of the controller, and returns the modified result.
|
|
||||||
pub fn with_speed_roll(mut self, speed: f64) -> Self {
|
|
||||||
self.speed_roll = speed;
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets the speed of the controller, and returns the modified result.
|
/// Sets the speed of the controller, and returns the modified result.
|
||||||
pub fn with_speed_bounds(mut self, speed_limits: [f64; 2]) -> Self {
|
pub fn with_speed_bounds(mut self, speed_limits: [f64; 2]) -> Self {
|
||||||
self.speed_bounds = speed_limits;
|
self.speed_bounds = speed_limits;
|
||||||
@ -121,9 +96,6 @@ impl Default for CameraController {
|
|||||||
smoothness: 0.8,
|
smoothness: 0.8,
|
||||||
rotational_smoothness: 0.5,
|
rotational_smoothness: 0.5,
|
||||||
speed: 1.0,
|
speed: 1.0,
|
||||||
speed_pitch: 1.0,
|
|
||||||
speed_yaw: 1.0,
|
|
||||||
speed_roll: 1.0,
|
|
||||||
speed_bounds: [1e-17, 1e30],
|
speed_bounds: [1e-17, 1e30],
|
||||||
slow_near_objects: true,
|
slow_near_objects: true,
|
||||||
nearest_object: None,
|
nearest_object: None,
|
||||||
@ -165,17 +137,12 @@ impl CameraInput {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the desired velocity transform.
|
/// Returns the desired velocity transform.
|
||||||
pub fn target_velocity(
|
pub fn target_velocity(&self, speed: f64, dt: f64) -> (DVec3, DQuat) {
|
||||||
&self,
|
|
||||||
controller: &CameraController,
|
|
||||||
speed: f64,
|
|
||||||
dt: f64,
|
|
||||||
) -> (DVec3, DQuat) {
|
|
||||||
let rotation = DQuat::from_euler(
|
let rotation = DQuat::from_euler(
|
||||||
EulerRot::XYZ,
|
EulerRot::XYZ,
|
||||||
self.pitch * dt * controller.speed_pitch,
|
self.pitch * dt,
|
||||||
self.yaw * dt * controller.speed_yaw,
|
self.yaw * dt,
|
||||||
self.roll * dt * controller.speed_roll,
|
self.roll * dt,
|
||||||
);
|
);
|
||||||
|
|
||||||
let translation = DVec3::new(self.right, self.up, self.forward) * speed * dt;
|
let translation = DVec3::new(self.right, self.up, self.forward) * speed * dt;
|
||||||
@ -229,15 +196,15 @@ pub fn nearest_objects_in_frame<P: GridPrecision>(
|
|||||||
let Ok((cam_entity, mut camera, cam_pos, cam_layer)) = camera.get_single_mut() else {
|
let Ok((cam_entity, mut camera, cam_pos, cam_layer)) = camera.get_single_mut() else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
let cam_layer = cam_layer.to_owned().unwrap_or_default();
|
let cam_layer = cam_layer.copied().unwrap_or(RenderLayers::all());
|
||||||
let cam_children: HashSet<Entity> = children.iter_descendants(cam_entity).collect();
|
let cam_children: HashSet<Entity> = children.iter_descendants(cam_entity).collect();
|
||||||
|
|
||||||
let nearest_object = objects
|
let nearest_object = objects
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|(entity, ..)| !cam_children.contains(entity))
|
.filter(|(entity, ..)| !cam_children.contains(entity))
|
||||||
.filter(|(.., obj_layer)| {
|
.filter(|(.., obj_layer)| {
|
||||||
let obj_layer = obj_layer.unwrap_or_default();
|
let obj_layer = obj_layer.copied().unwrap_or(RenderLayers::layer(0));
|
||||||
cam_layer.intersects(obj_layer)
|
cam_layer.intersects(&obj_layer)
|
||||||
})
|
})
|
||||||
.map(|(entity, object_local, obj_pos, aabb, _)| {
|
.map(|(entity, object_local, obj_pos, aabb, _)| {
|
||||||
let center_distance =
|
let center_distance =
|
||||||
@ -276,8 +243,7 @@ pub fn camera_controller<P: GridPrecision>(
|
|||||||
let lerp_rotation = 1.0 - controller.rotational_smoothness.clamp(0.0, 0.999);
|
let lerp_rotation = 1.0 - controller.rotational_smoothness.clamp(0.0, 0.999);
|
||||||
|
|
||||||
let (vel_t_current, vel_r_current) = (controller.vel_translation, controller.vel_rotation);
|
let (vel_t_current, vel_r_current) = (controller.vel_translation, controller.vel_rotation);
|
||||||
let (vel_t_target, vel_r_target) =
|
let (vel_t_target, vel_r_target) = input.target_velocity(speed, time.delta_seconds_f64());
|
||||||
input.target_velocity(&controller, speed, time.delta_seconds_f64());
|
|
||||||
|
|
||||||
let cam_rot = position.transform.rotation.as_dquat();
|
let cam_rot = position.transform.rotation.as_dquat();
|
||||||
let vel_t_next = cam_rot * vel_t_target; // Orients the translation to match the camera
|
let vel_t_next = cam_rot * vel_t_target; // Orients the translation to match the camera
|
||||||
|
|||||||
13
src/debug.rs
13
src/debug.rs
@ -3,13 +3,10 @@
|
|||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
|
|
||||||
use bevy_app::prelude::*;
|
use bevy_app::prelude::*;
|
||||||
use bevy_color::{
|
|
||||||
palettes::css::{BLUE, GREEN, RED},
|
|
||||||
prelude::*,
|
|
||||||
};
|
|
||||||
use bevy_ecs::prelude::*;
|
use bevy_ecs::prelude::*;
|
||||||
use bevy_gizmos::prelude::*;
|
use bevy_gizmos::prelude::*;
|
||||||
use bevy_math::prelude::*;
|
use bevy_math::prelude::*;
|
||||||
|
use bevy_render::prelude::*;
|
||||||
use bevy_transform::prelude::*;
|
use bevy_transform::prelude::*;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@ -47,7 +44,7 @@ pub fn update_debug_bounds<P: GridPrecision>(
|
|||||||
&Transform::from_scale(Vec3::splat(frame.cell_edge_length() * 0.999)),
|
&Transform::from_scale(Vec3::splat(frame.cell_edge_length() * 0.999)),
|
||||||
);
|
);
|
||||||
if origin.is_none() {
|
if origin.is_none() {
|
||||||
gizmos.cuboid(transform, Color::Srgba(GREEN))
|
gizmos.cuboid(transform, Color::GREEN)
|
||||||
} else {
|
} else {
|
||||||
// gizmos.cuboid(transform, Color::rgba(0.0, 0.0, 1.0, 0.5))
|
// gizmos.cuboid(transform, Color::rgba(0.0, 0.0, 1.0, 0.5))
|
||||||
}
|
}
|
||||||
@ -62,8 +59,8 @@ pub fn update_reference_frame_axes<P: GridPrecision>(
|
|||||||
for (transform, frame) in frames.iter() {
|
for (transform, frame) in frames.iter() {
|
||||||
let start = transform.translation();
|
let start = transform.translation();
|
||||||
let len = frame.cell_edge_length() * 2.0;
|
let len = frame.cell_edge_length() * 2.0;
|
||||||
gizmos.ray(start, transform.right() * len, Color::Srgba(RED));
|
gizmos.ray(start, transform.right() * len, Color::RED);
|
||||||
gizmos.ray(start, transform.up() * len, Color::Srgba(GREEN));
|
gizmos.ray(start, transform.up() * len, Color::GREEN);
|
||||||
gizmos.ray(start, transform.back() * len, Color::Srgba(BLUE));
|
gizmos.ray(start, transform.back() * len, Color::BLUE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
use bevy_app::prelude::*;
|
use bevy_app::prelude::*;
|
||||||
use bevy_ecs::prelude::*;
|
use bevy_ecs::prelude::*;
|
||||||
use bevy_reflect::{prelude::*, GetTypeRegistration};
|
use bevy_reflect::prelude::*;
|
||||||
use bevy_transform::{prelude::*, TransformSystem};
|
use bevy_transform::{prelude::*, TransformSystem};
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
|
|
||||||
@ -52,9 +52,7 @@ pub enum FloatingOriginSet {
|
|||||||
PropagateLowPrecision,
|
PropagateLowPrecision,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<P: GridPrecision + Reflect + FromReflect + TypePath + GetTypeRegistration> Plugin
|
impl<P: GridPrecision + Reflect + FromReflect + TypePath> Plugin for BigSpacePlugin<P> {
|
||||||
for BigSpacePlugin<P>
|
|
||||||
{
|
|
||||||
fn build(&self, app: &mut App) {
|
fn build(&self, app: &mut App) {
|
||||||
let system_set_config = || {
|
let system_set_config = || {
|
||||||
(
|
(
|
||||||
|
|||||||
@ -506,18 +506,18 @@ mod tests {
|
|||||||
ReferenceFrame::<i32>::default(),
|
ReferenceFrame::<i32>::default(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let child_1 = app.world_mut().spawn(frame_bundle.clone()).id();
|
let child_1 = app.world.spawn(frame_bundle.clone()).id();
|
||||||
let child_2 = app.world_mut().spawn(frame_bundle.clone()).id();
|
let child_2 = app.world.spawn(frame_bundle.clone()).id();
|
||||||
let parent = app.world_mut().spawn(frame_bundle.clone()).id();
|
let parent = app.world.spawn(frame_bundle.clone()).id();
|
||||||
let root = app.world_mut().spawn(frame_bundle.clone()).id();
|
let root = app.world.spawn(frame_bundle.clone()).id();
|
||||||
|
|
||||||
app.world_mut().entity_mut(root).push_children(&[parent]);
|
app.world.entity_mut(root).push_children(&[parent]);
|
||||||
app.world_mut()
|
app.world
|
||||||
.entity_mut(parent)
|
.entity_mut(parent)
|
||||||
.push_children(&[child_1, child_2]);
|
.push_children(&[child_1, child_2]);
|
||||||
|
|
||||||
let mut state = SystemState::<ReferenceFramesMut<i32>>::new(app.world_mut());
|
let mut state = SystemState::<ReferenceFramesMut<i32>>::new(&mut app.world);
|
||||||
let mut ref_frames = state.get_mut(app.world_mut());
|
let mut ref_frames = state.get_mut(&mut app.world);
|
||||||
|
|
||||||
// Children
|
// Children
|
||||||
let result = ref_frames.child_frames(root);
|
let result = ref_frames.child_frames(root);
|
||||||
@ -559,12 +559,12 @@ mod tests {
|
|||||||
..default()
|
..default()
|
||||||
};
|
};
|
||||||
let root = app
|
let root = app
|
||||||
.world_mut()
|
.world
|
||||||
.spawn((Transform::default(), GridCell::<i32>::default(), root_frame))
|
.spawn((Transform::default(), GridCell::<i32>::default(), root_frame))
|
||||||
.id();
|
.id();
|
||||||
|
|
||||||
let child = app
|
let child = app
|
||||||
.world_mut()
|
.world
|
||||||
.spawn((
|
.spawn((
|
||||||
Transform::from_rotation(Quat::from_rotation_z(std::f32::consts::FRAC_PI_2))
|
Transform::from_rotation(Quat::from_rotation_z(std::f32::consts::FRAC_PI_2))
|
||||||
.with_translation(Vec3::new(1.0, 1.0, 0.0)),
|
.with_translation(Vec3::new(1.0, 1.0, 0.0)),
|
||||||
@ -573,10 +573,10 @@ mod tests {
|
|||||||
))
|
))
|
||||||
.id();
|
.id();
|
||||||
|
|
||||||
app.world_mut().entity_mut(root).push_children(&[child]);
|
app.world.entity_mut(root).push_children(&[child]);
|
||||||
|
|
||||||
let mut state = SystemState::<ReferenceFramesMut<i32>>::new(app.world_mut());
|
let mut state = SystemState::<ReferenceFramesMut<i32>>::new(&mut app.world);
|
||||||
let mut reference_frames = state.get_mut(app.world_mut());
|
let mut reference_frames = state.get_mut(&mut app.world);
|
||||||
|
|
||||||
// The function we are testing
|
// The function we are testing
|
||||||
propagate_origin_to_child(root, &mut reference_frames, child);
|
propagate_origin_to_child(root, &mut reference_frames, child);
|
||||||
@ -615,10 +615,10 @@ mod tests {
|
|||||||
GridCell::<i64>::default(),
|
GridCell::<i64>::default(),
|
||||||
ReferenceFrame::<i64>::default(),
|
ReferenceFrame::<i64>::default(),
|
||||||
);
|
);
|
||||||
let root = app.world_mut().spawn(frame_bundle.clone()).id();
|
let root = app.world.spawn(frame_bundle.clone()).id();
|
||||||
|
|
||||||
let child = app
|
let child = app
|
||||||
.world_mut()
|
.world
|
||||||
.spawn((
|
.spawn((
|
||||||
Transform::from_rotation(Quat::from_rotation_z(std::f32::consts::FRAC_PI_2))
|
Transform::from_rotation(Quat::from_rotation_z(std::f32::consts::FRAC_PI_2))
|
||||||
.with_translation(Vec3::new(1.0, 1.0, 0.0)),
|
.with_translation(Vec3::new(1.0, 1.0, 0.0)),
|
||||||
@ -634,10 +634,10 @@ mod tests {
|
|||||||
))
|
))
|
||||||
.id();
|
.id();
|
||||||
|
|
||||||
app.world_mut().entity_mut(root).push_children(&[child]);
|
app.world.entity_mut(root).push_children(&[child]);
|
||||||
|
|
||||||
let mut state = SystemState::<ReferenceFramesMut<i64>>::new(app.world_mut());
|
let mut state = SystemState::<ReferenceFramesMut<i64>>::new(&mut app.world);
|
||||||
let mut reference_frames = state.get_mut(app.world_mut());
|
let mut reference_frames = state.get_mut(&mut app.world);
|
||||||
|
|
||||||
// The function we are testing
|
// The function we are testing
|
||||||
propagate_origin_to_parent(child, &mut reference_frames, root);
|
propagate_origin_to_parent(child, &mut reference_frames, root);
|
||||||
@ -672,7 +672,7 @@ mod tests {
|
|||||||
app.add_plugins(BigSpacePlugin::<i32>::default());
|
app.add_plugins(BigSpacePlugin::<i32>::default());
|
||||||
|
|
||||||
let root = app
|
let root = app
|
||||||
.world_mut()
|
.world
|
||||||
.spawn((
|
.spawn((
|
||||||
Transform::default(),
|
Transform::default(),
|
||||||
GridCell::<i32>::default(),
|
GridCell::<i32>::default(),
|
||||||
@ -688,7 +688,7 @@ mod tests {
|
|||||||
.id();
|
.id();
|
||||||
|
|
||||||
let child = app
|
let child = app
|
||||||
.world_mut()
|
.world
|
||||||
.spawn((
|
.spawn((
|
||||||
Transform::default()
|
Transform::default()
|
||||||
.with_rotation(Quat::from_rotation_z(-std::f32::consts::FRAC_PI_2))
|
.with_rotation(Quat::from_rotation_z(-std::f32::consts::FRAC_PI_2))
|
||||||
@ -698,10 +698,10 @@ mod tests {
|
|||||||
))
|
))
|
||||||
.id();
|
.id();
|
||||||
|
|
||||||
app.world_mut().entity_mut(root).push_children(&[child]);
|
app.world.entity_mut(root).push_children(&[child]);
|
||||||
|
|
||||||
let mut state = SystemState::<ReferenceFramesMut<i32>>::new(app.world_mut());
|
let mut state = SystemState::<ReferenceFramesMut<i32>>::new(&mut app.world);
|
||||||
let mut reference_frames = state.get_mut(app.world_mut());
|
let mut reference_frames = state.get_mut(&mut app.world);
|
||||||
|
|
||||||
propagate_origin_to_child(root, &mut reference_frames, child);
|
propagate_origin_to_child(root, &mut reference_frames, child);
|
||||||
|
|
||||||
|
|||||||
@ -34,7 +34,7 @@ pub mod propagation;
|
|||||||
/// the same rotating reference frame, instead of moving rapidly through space around a star, or
|
/// the same rotating reference frame, instead of moving rapidly through space around a star, or
|
||||||
/// worse, around the center of the galaxy.
|
/// worse, around the center of the galaxy.
|
||||||
#[derive(Debug, Clone, Reflect, Component)]
|
#[derive(Debug, Clone, Reflect, Component)]
|
||||||
pub struct ReferenceFrame<P: GridPrecision + Reflect> {
|
pub struct ReferenceFrame<P: GridPrecision> {
|
||||||
/// The high-precision position of the floating origin's current grid cell local to this
|
/// The high-precision position of the floating origin's current grid cell local to this
|
||||||
/// reference frame.
|
/// reference frame.
|
||||||
local_floating_origin: LocalFloatingOrigin<P>,
|
local_floating_origin: LocalFloatingOrigin<P>,
|
||||||
|
|||||||
26
src/tests.rs
26
src/tests.rs
@ -8,7 +8,7 @@ fn changing_floating_origin_updates_global_transform() {
|
|||||||
app.add_plugins(BigSpacePlugin::<i32>::default());
|
app.add_plugins(BigSpacePlugin::<i32>::default());
|
||||||
|
|
||||||
let first = app
|
let first = app
|
||||||
.world_mut()
|
.world
|
||||||
.spawn((
|
.spawn((
|
||||||
TransformBundle::from_transform(Transform::from_translation(Vec3::new(
|
TransformBundle::from_transform(Transform::from_translation(Vec3::new(
|
||||||
150.0, 0.0, 0.0,
|
150.0, 0.0, 0.0,
|
||||||
@ -19,7 +19,7 @@ fn changing_floating_origin_updates_global_transform() {
|
|||||||
.id();
|
.id();
|
||||||
|
|
||||||
let second = app
|
let second = app
|
||||||
.world_mut()
|
.world
|
||||||
.spawn((
|
.spawn((
|
||||||
TransformBundle::from_transform(Transform::from_translation(Vec3::new(
|
TransformBundle::from_transform(Transform::from_translation(Vec3::new(
|
||||||
0.0, 0.0, 300.0,
|
0.0, 0.0, 300.0,
|
||||||
@ -28,18 +28,18 @@ fn changing_floating_origin_updates_global_transform() {
|
|||||||
))
|
))
|
||||||
.id();
|
.id();
|
||||||
|
|
||||||
app.world_mut()
|
app.world
|
||||||
.spawn(BigSpaceRootBundle::<i32>::default())
|
.spawn(BigSpaceRootBundle::<i32>::default())
|
||||||
.push_children(&[first, second]);
|
.push_children(&[first, second]);
|
||||||
|
|
||||||
app.update();
|
app.update();
|
||||||
|
|
||||||
app.world_mut().entity_mut(first).remove::<FloatingOrigin>();
|
app.world.entity_mut(first).remove::<FloatingOrigin>();
|
||||||
app.world_mut().entity_mut(second).insert(FloatingOrigin);
|
app.world.entity_mut(second).insert(FloatingOrigin);
|
||||||
|
|
||||||
app.update();
|
app.update();
|
||||||
|
|
||||||
let second_global_transform = app.world_mut().get::<GlobalTransform>(second).unwrap();
|
let second_global_transform = app.world.get::<GlobalTransform>(second).unwrap();
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
second_global_transform.translation(),
|
second_global_transform.translation(),
|
||||||
@ -53,7 +53,7 @@ fn child_global_transforms_are_updated_when_floating_origin_changes() {
|
|||||||
app.add_plugins(BigSpacePlugin::<i32>::default());
|
app.add_plugins(BigSpacePlugin::<i32>::default());
|
||||||
|
|
||||||
let first = app
|
let first = app
|
||||||
.world_mut()
|
.world
|
||||||
.spawn((
|
.spawn((
|
||||||
TransformBundle::from_transform(Transform::from_translation(Vec3::new(
|
TransformBundle::from_transform(Transform::from_translation(Vec3::new(
|
||||||
150.0, 0.0, 0.0,
|
150.0, 0.0, 0.0,
|
||||||
@ -64,7 +64,7 @@ fn child_global_transforms_are_updated_when_floating_origin_changes() {
|
|||||||
.id();
|
.id();
|
||||||
|
|
||||||
let second = app
|
let second = app
|
||||||
.world_mut()
|
.world
|
||||||
.spawn((
|
.spawn((
|
||||||
TransformBundle::from_transform(Transform::from_translation(Vec3::new(
|
TransformBundle::from_transform(Transform::from_translation(Vec3::new(
|
||||||
0.0, 0.0, 300.0,
|
0.0, 0.0, 300.0,
|
||||||
@ -78,19 +78,19 @@ fn child_global_transforms_are_updated_when_floating_origin_changes() {
|
|||||||
})
|
})
|
||||||
.id();
|
.id();
|
||||||
|
|
||||||
app.world_mut()
|
app.world
|
||||||
.spawn(BigSpaceRootBundle::<i32>::default())
|
.spawn(BigSpaceRootBundle::<i32>::default())
|
||||||
.push_children(&[first, second]);
|
.push_children(&[first, second]);
|
||||||
|
|
||||||
app.update();
|
app.update();
|
||||||
|
|
||||||
app.world_mut().entity_mut(first).remove::<FloatingOrigin>();
|
app.world.entity_mut(first).remove::<FloatingOrigin>();
|
||||||
app.world_mut().entity_mut(second).insert(FloatingOrigin);
|
app.world.entity_mut(second).insert(FloatingOrigin);
|
||||||
|
|
||||||
app.update();
|
app.update();
|
||||||
|
|
||||||
let child = app.world_mut().get::<Children>(second).unwrap()[0];
|
let child = app.world.get::<Children>(second).unwrap()[0];
|
||||||
let child_transform = app.world_mut().get::<GlobalTransform>(child).unwrap();
|
let child_transform = app.world.get::<GlobalTransform>(child).unwrap();
|
||||||
|
|
||||||
assert_eq!(child_transform.translation(), Vec3::new(0.0, 0.0, 600.0));
|
assert_eq!(child_transform.translation(), Vec3::new(0.0, 0.0, 600.0));
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user