restore previous night sky appearance, tho with real star distances
This commit is contained in:
parent
8c0af0e467
commit
7d85a93449
|
@ -32,10 +32,10 @@ impl Plugin for CameraPlugin {
|
||||||
|
|
||||||
#[derive(Resource)]
|
#[derive(Resource)]
|
||||||
pub struct MapCam {
|
pub struct MapCam {
|
||||||
zoom_level: f32,
|
pub zoom_level: f32,
|
||||||
target_zoom_level: f32,
|
pub target_zoom_level: f32,
|
||||||
pitch: f32,
|
pub pitch: f32,
|
||||||
yaw: f32,
|
pub yaw: f32,
|
||||||
}
|
}
|
||||||
impl Default for MapCam {
|
impl Default for MapCam {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
|
|
|
@ -11,6 +11,7 @@ pub const LIGHTYEAR2METER: f64 = 9_460_730_472_580_800.0;
|
||||||
pub const PARSEC2METER: f64 = 3.0857e16;
|
pub const PARSEC2METER: f64 = 3.0857e16;
|
||||||
pub const DIST_JUPTER_SUN: f64 = 778479.0e6;
|
pub const DIST_JUPTER_SUN: f64 = 778479.0e6;
|
||||||
pub const EARTH_GRAVITY: f32 = 9.81;
|
pub const EARTH_GRAVITY: f32 = 9.81;
|
||||||
|
pub const SOL_RADIUS: f64 = 696.3e6;
|
||||||
|
|
||||||
// Each star's values: (x, y, z, magnitude, color index, distance, name)
|
// Each star's values: (x, y, z, magnitude, color index, distance, name)
|
||||||
pub const STARS: &[(f32, f32, f32, f32, f32, f32, &str)] = &include!("data/stars.in");
|
pub const STARS: &[(f32, f32, f32, f32, f32, f32, &str)] = &include!("data/stars.in");
|
||||||
|
|
55
src/world.rs
55
src/world.rs
|
@ -115,52 +115,65 @@ pub fn setup(
|
||||||
// Generate starmap
|
// Generate starmap
|
||||||
let sphere_handle = meshes.add(Sphere::new(1.0).mesh().uv(16, 16));
|
let sphere_handle = meshes.add(Sphere::new(1.0).mesh().uv(16, 16));
|
||||||
let mut starcount = 0;
|
let mut starcount = 0;
|
||||||
for star in nature::STARS {
|
for (index, star) in nature::STARS.iter().enumerate() {
|
||||||
let (x, y, z, mag, absmag, color_index, name) = *star;
|
let (x, y, z, mag, absmag, color_index, radius, name) = *star;
|
||||||
if mag > STARS_MAX_MAGNITUDE {
|
if mag > STARS_MAX_MAGNITUDE {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let mag = mag.min(6.0);
|
|
||||||
let scale_color = {|color: f32|
|
|
||||||
color * (0.0659663 * mag * mag - 1.09862 * mag + 4.3)
|
|
||||||
};
|
|
||||||
let (r, g, b) = nature::star_color_index_to_rgb(color_index);
|
let (r, g, b) = nature::star_color_index_to_rgb(color_index);
|
||||||
|
let mut pos = DVec3::new(x as f64, z as f64, -y as f64) * nature::PARSEC2METER;
|
||||||
|
if pos.length() > 1e21 {
|
||||||
|
pos *= 0.002;
|
||||||
|
}
|
||||||
|
let pos_render = pos * 1.0;
|
||||||
|
let scale_factor = 1e-4 * pos_render.length() as f32; // from experimentation
|
||||||
|
|
||||||
|
let mag = mag.min(6.0);
|
||||||
|
let scale_size = {|mag: f32|
|
||||||
|
scale_factor * (0.230299 * mag * mag - 3.09013 * mag + 15.1782)
|
||||||
|
};
|
||||||
|
let scale = scale_size(mag);
|
||||||
|
|
||||||
|
let scale_color = {|color: f32|
|
||||||
|
1.2 * color * (0.0659663 * mag * mag - 1.09862 * mag + 4.3)
|
||||||
|
};
|
||||||
|
//let scale = translation.length().powf(0.84);
|
||||||
|
//pos_render.length().powf(0.64)
|
||||||
|
//(radius as f64 * nature::SOL_RADIUS).powf(0.02) as f32 *
|
||||||
|
|
||||||
let star_color_handle = materials.add(StandardMaterial {
|
let star_color_handle = materials.add(StandardMaterial {
|
||||||
base_color: Color::rgb(scale_color(r), scale_color(g), scale_color(b)),
|
base_color: Color::rgb(scale_color(r), scale_color(g), scale_color(b)),
|
||||||
unlit: true,
|
unlit: true,
|
||||||
..default()
|
..default()
|
||||||
});
|
});
|
||||||
let name = if star.6.is_empty() {
|
let name = if name.is_empty() {
|
||||||
"Uncharted Star".to_string()
|
format!("Uncharted Star #{index}")
|
||||||
} else {
|
} else {
|
||||||
star.6.to_string()
|
name.to_string()
|
||||||
|
};
|
||||||
|
let distance = if pos.length() > 1e21 {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
Some(pos.length())
|
||||||
};
|
};
|
||||||
let translation = Vec3::new(
|
|
||||||
nature::PARSEC2METER as f32 * x,
|
|
||||||
nature::PARSEC2METER as f32 * z,
|
|
||||||
nature::PARSEC2METER as f32 * -y,
|
|
||||||
);
|
|
||||||
//let rotation = Quat::from_rotation_arc(Vec3::Z, (-translation).normalize());
|
|
||||||
|
|
||||||
let scale = translation.length().powf(0.85);
|
|
||||||
|
|
||||||
commands.spawn((
|
commands.spawn((
|
||||||
Star,
|
Star,
|
||||||
hud::IsClickable {
|
hud::IsClickable {
|
||||||
name: Some(name),
|
name: Some(name),
|
||||||
distance: None,
|
distance,
|
||||||
},
|
},
|
||||||
PbrBundle {
|
PbrBundle {
|
||||||
mesh: sphere_handle.clone(),
|
mesh: sphere_handle.clone(),
|
||||||
material: star_color_handle,
|
material: star_color_handle,
|
||||||
transform: Transform {
|
transform: Transform {
|
||||||
translation,
|
translation: pos_render.as_vec3(),
|
||||||
scale: Vec3::splat(scale),
|
scale: Vec3::splat(scale as f32),
|
||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
Position::new(translation.as_dvec3()),
|
|
||||||
));
|
));
|
||||||
starcount += 1;
|
starcount += 1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue