place sun separately of the other stars, for better placement in map

This commit is contained in:
yuni 2024-04-18 23:39:34 +02:00
parent 0c2c295f6b
commit fca8251f27
4 changed files with 51 additions and 8 deletions

View file

@ -44,6 +44,8 @@ def render(ra, dec, mag, ci, dist, name):
dec = float(dec) dec = float(dec)
mag = float(mag) mag = float(mag)
name = re.sub(r'\s+', ' ', name) name = re.sub(r'\s+', ' ', name)
if name == 'Sol':
return
distance = 1.0 distance = 1.0
ra_radians = math.radians(ra * 15) # ra is in [0, 24], multiplying by 15 gives degrees in [0, 360] ra_radians = math.radians(ra * 15) # ra is in [0, 24], multiplying by 15 gives degrees in [0, 360]

View file

@ -39,7 +39,7 @@ struct ParserState {
// Actor fields // Actor fields
id: String, id: String,
pos: DVec3, pos: DVec3,
model: String, model: Option<String>,
model_scale: f32, model_scale: f32,
rotation: Quat, rotation: Quat,
velocity: DVec3, velocity: DVec3,
@ -53,6 +53,7 @@ struct ParserState {
is_vehicle: bool, is_vehicle: bool,
is_clickable: bool, is_clickable: bool,
is_targeted_on_startup: bool, is_targeted_on_startup: bool,
is_sun: bool,
has_physics: bool, has_physics: bool,
wants_maxrotation: Option<f64>, wants_maxrotation: Option<f64>,
wants_maxvelocity: Option<f64>, wants_maxvelocity: Option<f64>,
@ -84,7 +85,7 @@ impl Default for ParserState {
id: "".to_string(), id: "".to_string(),
pos: DVec3::new(0.0, 0.0, 0.0), pos: DVec3::new(0.0, 0.0, 0.0),
model: "".to_string(), model: None,
model_scale: 1.0, model_scale: 1.0,
rotation: Quat::IDENTITY, rotation: Quat::IDENTITY,
velocity: DVec3::splat(0.0), velocity: DVec3::splat(0.0),
@ -98,6 +99,7 @@ impl Default for ParserState {
is_vehicle: false, is_vehicle: false,
is_clickable: true, is_clickable: true,
is_targeted_on_startup: false, is_targeted_on_startup: false,
is_sun: false,
has_physics: true, has_physics: true,
wants_maxrotation: None, wants_maxrotation: None,
wants_maxvelocity: None, wants_maxvelocity: None,
@ -177,7 +179,21 @@ pub fn load_defs(
ew_spawn.send(SpawnEvent(state)); ew_spawn.send(SpawnEvent(state));
state = ParserState::default(); state = ParserState::default();
state.class = DefClass::Actor; state.class = DefClass::Actor;
state.model = model.to_string(); state.model = Some(model.to_string());
if let (Ok(x_float), Ok(y_float), Ok(z_float)) =
(x.parse::<f64>(), y.parse::<f64>(), z.parse::<f64>()) {
state.pos = DVec3::new(x_float, y_float, z_float);
}
else {
error!("Can't parse coordinates as floats in def: {line}");
state = ParserState::default();
continue;
}
}
["actor", x, y, z] => {
ew_spawn.send(SpawnEvent(state));
state = ParserState::default();
state.class = DefClass::Actor;
if let (Ok(x_float), Ok(y_float), Ok(z_float)) = if let (Ok(x_float), Ok(y_float), Ok(z_float)) =
(x.parse::<f64>(), y.parse::<f64>(), z.parse::<f64>()) { (x.parse::<f64>(), y.parse::<f64>(), z.parse::<f64>()) {
state.pos = DVec3::new(x_float, y_float, z_float); state.pos = DVec3::new(x_float, y_float, z_float);
@ -237,6 +253,10 @@ pub fn load_defs(
["moon", "yes"] => { ["moon", "yes"] => {
state.model_scale *= 3.0; state.model_scale *= 3.0;
} }
["sun", "yes"] => {
state.is_sun = true;
state.model_scale *= 5.0;
}
["oxygen", amount] => { ["oxygen", amount] => {
if let Ok(amount) = amount.parse::<f32>() { if let Ok(amount) = amount.parse::<f32>() {
state.is_lifeform = true; state.is_lifeform = true;
@ -461,10 +481,14 @@ fn spawn_entities(
actor.insert(Position::from(state.pos)); actor.insert(Position::from(state.pos));
actor.insert(Rotation::from(state.rotation)); actor.insert(Rotation::from(state.rotation));
if state.is_sphere { if state.is_sphere {
let sphere_texture_handle: Handle<Image> = asset_server.load(format!("textures/{}.jpg", state.model)); let sphere_texture_handle = if let Some(model) = &state.model {
Some(asset_server.load(format!("textures/{}.jpg", model)))
} else {
None
};
let sphere_handle = meshes.add(Sphere::new(1.0).mesh().uv(128, 128)); let sphere_handle = meshes.add(Sphere::new(1.0).mesh().uv(128, 128));
let sphere_material_handle = materials.add(StandardMaterial { let sphere_material_handle = materials.add(StandardMaterial {
base_color_texture: Some(sphere_texture_handle.clone()), base_color_texture: sphere_texture_handle,
perceptual_roughness: 1.0, perceptual_roughness: 1.0,
metallic: 0.0, metallic: 0.0,
..default() ..default()
@ -478,13 +502,13 @@ fn spawn_entities(
}, },
..default() ..default()
}); });
} else { } else if let Some(model) = &state.model {
actor.insert(SceneBundle { actor.insert(SceneBundle {
transform: Transform { transform: Transform {
scale: Vec3::splat(state.model_scale), scale: Vec3::splat(state.model_scale),
..default() ..default()
}, },
scene: asset_server.load(world::asset_name_to_path(state.model.as_str())), scene: asset_server.load(world::asset_name_to_path(model.as_str())),
..default() ..default()
}); });
} }
@ -524,6 +548,14 @@ fn spawn_entities(
actor.insert(actor::Player); actor.insert(actor::Player);
actor.insert(actor::PlayerCamera); actor.insert(actor::PlayerCamera);
} }
if state.is_sun {
let (r, g, b) = nature::star_color_index_to_rgb(0.656);
actor.insert(materials.add(StandardMaterial {
base_color: Color::rgb(r, g, b) * 13.0,
unlit: true,
..default()
}));
}
if state.is_targeted_on_startup { if state.is_targeted_on_startup {
actor.insert(hud::IsTargeted); actor.insert(hud::IsTargeted);
} }

View file

@ -3,7 +3,6 @@
// License: CC BY-SA 4.0: https://creativecommons.org/licenses/by-sa/4.0/ // License: CC BY-SA 4.0: https://creativecommons.org/licenses/by-sa/4.0/
// Each star's values: (x, y, z, magnitude, color index, distance, name) // Each star's values: (x, y, z, magnitude, color index, distance, name)
[ [
(1.0,0.0,-0.0,-26.7,0.656,0.0,"Sol"),
(-0.1875,-0.2876,-0.9392,-1.44,0.009,2.6371,"Sirius"), (-0.1875,-0.2876,-0.9392,-1.44,0.009,2.6371,"Sirius"),
(-0.06322,-0.7954,-0.6027,-0.62,0.164,94.7867,"Canopus"), (-0.06322,-0.7954,-0.6027,-0.62,0.164,94.7867,"Canopus"),
(-0.7838,0.3286,0.527,-0.05,1.239,11.2575,"Arcturus"), (-0.7838,0.3286,0.527,-0.05,1.239,11.2575,"Arcturus"),

View file

@ -1,4 +1,14 @@
actor 0 0 0
id sol
name Sol
scale 696300e3
sphere yes
sun yes
physics off
actor 0 0 0 jupiter actor 0 0 0 jupiter
relativeto sol
orbit 778479000e3 0.5
id jupiter id jupiter
name Jupiter name Jupiter
scale 71492e3 scale 71492e3