restore previous night sky appearance, tho with real star distances

This commit is contained in:
yuni 2024-04-19 03:42:59 +02:00
parent 8c0af0e467
commit 7d85a93449
3 changed files with 39 additions and 25 deletions

View file

@ -32,10 +32,10 @@ impl Plugin for CameraPlugin {
#[derive(Resource)]
pub struct MapCam {
zoom_level: f32,
target_zoom_level: f32,
pitch: f32,
yaw: f32,
pub zoom_level: f32,
pub target_zoom_level: f32,
pub pitch: f32,
pub yaw: f32,
}
impl Default for MapCam {
fn default() -> Self {

View file

@ -11,6 +11,7 @@ pub const LIGHTYEAR2METER: f64 = 9_460_730_472_580_800.0;
pub const PARSEC2METER: f64 = 3.0857e16;
pub const DIST_JUPTER_SUN: f64 = 778479.0e6;
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)
pub const STARS: &[(f32, f32, f32, f32, f32, f32, &str)] = &include!("data/stars.in");

View file

@ -115,52 +115,65 @@ pub fn setup(
// Generate starmap
let sphere_handle = meshes.add(Sphere::new(1.0).mesh().uv(16, 16));
let mut starcount = 0;
for star in nature::STARS {
let (x, y, z, mag, absmag, color_index, name) = *star;
for (index, star) in nature::STARS.iter().enumerate() {
let (x, y, z, mag, absmag, color_index, radius, name) = *star;
if mag > STARS_MAX_MAGNITUDE {
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 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 {
base_color: Color::rgb(scale_color(r), scale_color(g), scale_color(b)),
unlit: true,
..default()
});
let name = if star.6.is_empty() {
"Uncharted Star".to_string()
let name = if name.is_empty() {
format!("Uncharted Star #{index}")
} 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((
Star,
hud::IsClickable {
name: Some(name),
distance: None,
distance,
},
PbrBundle {
mesh: sphere_handle.clone(),
material: star_color_handle,
transform: Transform {
translation,
scale: Vec3::splat(scale),
translation: pos_render.as_vec3(),
scale: Vec3::splat(scale as f32),
..default()
},
..default()
},
Position::new(translation.as_dvec3()),
));
starcount += 1;
}