Skip to content

Commit

Permalink
renamed sun to space.rs and put axis/equator to it
Browse files Browse the repository at this point in the history
  • Loading branch information
-karlos- committed Dec 23, 2023
1 parent aa427c5 commit 5229b68
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 66 deletions.
65 changes: 5 additions & 60 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//! Loads and renders a glTF file as a scene.
use std::f32::consts::FRAC_PI_2;

use bevy::{
diagnostic::{DiagnosticsStore, FrameTimeDiagnosticsPlugin},
pbr::NotShadowCaster,
Expand Down Expand Up @@ -31,7 +29,7 @@ mod flycam;
mod geocoord;
mod geoview;
mod http_assets;
mod sun;
mod space;
mod tilemap;
#[cfg(all(feature = "xr", not(any(target_os = "macos", target_arch = "wasm32"))))]
mod xr;
Expand Down Expand Up @@ -106,7 +104,7 @@ pub fn main() {
xr,
});

let _start_view = GeoView {
let start_view = GeoView {
geo_coord,
elevation,
direction,
Expand All @@ -115,7 +113,7 @@ pub fn main() {
camera_fov: 7.,
};

let start_view = GeoView {
let _start_view = GeoView {
// test only
geo_coord: GeoCoord { lat: 33., lon: 0. }, // up,dir
elevation: 5000000.,
Expand Down Expand Up @@ -149,7 +147,7 @@ pub fn main() {
})
.add_plugins(ScreenFrameDiagnosticsPlugin)
.add_plugins(ScreenEntityDiagnosticsPlugin)
.add_plugins(sun::Plugin)
.add_plugins(space::Plugin)
.add_plugins(flycam::Plugin)
.add_plugins(geoview::Plugin { start_view })
.insert_resource(TileMap::default())
Expand Down Expand Up @@ -178,61 +176,8 @@ pub fn main() {
.run();
}

fn setup(
mut diags: ResMut<ScreenDiagnostics>,
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
) {
fn setup(mut diags: ResMut<ScreenDiagnostics>) {
diags.modify("fps").aggregate(Aggregate::Average);
let rot = Quat::from_axis_angle(Vec3::X, FRAC_PI_2);
let transform =
Transform::from_translation(Vec3::NEG_Z * EARTH_RADIUS * 1.5).with_rotation(rot);

let material = materials.add(StandardMaterial {
fog_enabled: false,
..default()
});

// Rotational axis
let mesh = meshes.add(
shape::Cylinder {
radius: 1000.0,
height: EARTH_RADIUS * 6.0,
resolution: 16,
segments: 1,
}
.into(),
);
commands.spawn((
PbrBundle {
mesh,
transform,
material: material.clone(),
..default()
},
GalacticGrid::ZERO,
));

// Equator
let mesh = meshes.add(
shape::Cylinder {
radius: EARTH_RADIUS + 1000.0,
height: 1.0,
resolution: 64,
segments: 1,
}
.into(),
);
commands.spawn((
PbrBundle {
mesh,
transform: Transform::from_rotation(rot),
material,
..default()
},
GalacticGrid::ZERO,
));
}

#[cfg(not(all(feature = "xr", not(any(target_os = "macos", target_arch = "wasm32")))))]
Expand Down
63 changes: 57 additions & 6 deletions src/sun.rs → src/space.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ fn setup(
..default()
});

let mesh = meshes.add(
let sphere = meshes.add(
shape::UVSphere {
radius: 1.0,
sectors: 128,
Expand All @@ -92,7 +92,7 @@ fn setup(
let image = server.load("embedded://8k_stars.jpg");
commands.spawn((
PbrBundle {
mesh: mesh.clone(),
mesh: sphere.clone(),
material: materials.add(StandardMaterial {
base_color: Color::WHITE,
unlit: true,
Expand All @@ -110,11 +110,62 @@ fn setup(
GalacticGrid::ZERO,
));

// Earth

let rot = Quat::from_axis_angle(Vec3::X, FRAC_PI_2);
let transform =
Transform::from_translation(Vec3::NEG_Z * EARTH_RADIUS * 1.5).with_rotation(rot);

let material = materials.add(StandardMaterial {
fog_enabled: false,
..default()
});

// Rotational axis
let mesh = meshes.add(
shape::Cylinder {
radius: 1000.0,
height: EARTH_RADIUS * 6.0,
resolution: 16,
segments: 1,
}
.into(),
);
commands.spawn((
PbrBundle {
mesh,
transform,
material: material.clone(),
..default()
},
GalacticGrid::ZERO,
));

// Equator
let mesh = meshes.add(
shape::Cylinder {
radius: EARTH_RADIUS + 1000.0,
height: 1.0,
resolution: 64,
segments: 1,
}
.into(),
);
commands.spawn((
PbrBundle {
mesh,
transform: Transform::from_rotation(rot),
material,
..default()
},
GalacticGrid::ZERO,
));

// Clouds visible from earth and space
let image = server.load("embedded://8k_earth_clouds.jpg");
commands.spawn((
PbrBundle {
mesh: mesh.clone(),
mesh: sphere.clone(),
material: materials.add(StandardMaterial {
base_color: Color::WHITE,
unlit: true,
Expand All @@ -135,7 +186,7 @@ fn setup(
// Sky
commands.spawn((
PbrBundle {
mesh: mesh.clone(),
mesh: sphere.clone(),
material: materials.add(StandardMaterial {
base_color: Color::hex("000088").unwrap(),
unlit: true,
Expand All @@ -154,7 +205,7 @@ fn setup(
// ground
commands.spawn((
PbrBundle {
mesh: mesh.clone(),
mesh: sphere.clone(),
material: materials.add(StandardMaterial {
base_color: Color::WHITE,
unlit: true,
Expand All @@ -177,7 +228,7 @@ fn setup(
// moon
commands.spawn((
PbrBundle {
mesh,
mesh: sphere,
material: materials.add(StandardMaterial {
base_color: Color::WHITE,
unlit: true,
Expand Down

0 comments on commit 5229b68

Please sign in to comment.