astraea/src/main.rs

113 lines
3 KiB
Rust
Raw Normal View History

2024-10-05 09:37:47 +02:00
//! A simple 3D scene with light shining over a cube sitting on a plane.
2024-10-05 08:41:37 +02:00
use bevy::prelude::*;
2024-10-05 12:17:55 +02:00
//use bevy::render::*;
2024-10-05 09:37:47 +02:00
use bevy::math::*;
2024-10-05 12:17:55 +02:00
use std::fs::File;
use std::io::Read;
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug)]
struct StarData {
#[serde(rename = "Dec")]
dec: String,
#[serde(rename = "HR")]
hr: String,
#[serde(rename = "K")]
k: Option<String>,
#[serde(rename = "RA")]
ra: String,
#[serde(rename = "V")]
v: String,
#[serde(rename = "C")]
constellation: Option<String>, // Optional field
#[serde(rename = "F")]
f: Option<String>, // Optional field
#[serde(rename = "B")]
bayer_designation: Option<String>, // Optional field
#[serde(rename = "N")]
name: Option<String>, // Optional field
}
2024-10-05 08:41:37 +02:00
fn main() {
App::new()
2024-10-05 09:37:47 +02:00
.add_plugins(DefaultPlugins)
.add_systems(Startup, setup)
.run();
2024-10-05 08:41:37 +02:00
}
2024-10-05 09:46:57 +02:00
#[derive(Component)]
struct Star;
2024-10-05 08:41:37 +02:00
fn setup(
2024-10-05 09:37:47 +02:00
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
2024-10-05 08:41:37 +02:00
) {
2024-10-05 09:46:57 +02:00
// plane
2024-10-05 12:17:55 +02:00
let stars = get_stars().unwrap();
for star in stars {
info!("{:?}", star);
}
let star_size = 0.02;
2024-10-05 09:37:47 +02:00
commands.spawn((
2024-10-05 10:52:42 +02:00
PbrBundle {//Plane3d::default().mesh().size(1., 1.)
2024-10-05 12:17:55 +02:00
mesh: meshes.add(Cuboid::new(star_size, star_size, star_size)),
2024-10-05 10:52:42 +02:00
material: materials.add(Color::srgb(1.0, 1.0, 1.0)),
2024-10-05 12:17:55 +02:00
transform: Transform::from_xyz(1.0, 0.0, 0.0),
2024-10-05 09:37:47 +02:00
..default()
},
2024-10-05 09:46:57 +02:00
Star,
2024-10-05 09:37:47 +02:00
));
2024-10-05 09:46:57 +02:00
// light
commands.spawn(DirectionalLightBundle {
2024-10-05 10:52:42 +02:00
transform: Transform::from_xyz(0.0, 0.0, 0.0).with_rotation(Quat::from_rotation_y(-1.5)),
2024-10-05 09:46:57 +02:00
..default()
});
2024-10-05 09:37:47 +02:00
// camera
2024-10-05 09:46:57 +02:00
commands.spawn(Camera3dBundle {
2024-10-05 10:52:42 +02:00
transform: Transform::from_xyz(0.0, 0.0, 0.0).with_rotation(Quat::from_rotation_y(-1.5)),
2024-10-05 09:46:57 +02:00
..default()
});
2024-10-05 08:41:37 +02:00
}
2024-10-05 09:46:57 +02:00
2024-10-05 12:17:55 +02:00
fn get_stars() -> std::io::Result<Vec<StarData>> {
let mut file = File::open("data/stars.json")?;
let mut data = String::new();
file.read_to_string(&mut data)?;
info!("###");
2024-10-05 09:46:57 +02:00
2024-10-05 12:17:55 +02:00
let stars: Vec<StarData> = serde_json::from_str(&data).unwrap();
Ok(stars)
}
// fn star_position_to_spherical(ra_hours: f32, dec_deg: f32, dec_min: f32, dec_sec: f32) -> Vec3 {
// // Convert declination to decimal degrees
// let dec_decimal = declination_to_decimal(dec_deg, dec_min, dec_sec);
//
// // Convert Right Ascension from hours to degrees
// let ra_degrees = right_ascension_to_degrees(ra_hours);
2024-10-05 09:46:57 +02:00
//
2024-10-05 12:17:55 +02:00
// // Convert to spherical coordinates
// let theta = ra_degrees.to_radians(); // RA as theta (azimuthal angle)
// let phi = (90.0 - dec_decimal).to_radians(); // Declination to phi (polar angle)
2024-10-05 09:46:57 +02:00
//
2024-10-05 12:17:55 +02:00
// // Assuming a unit sphere, the radius (r) is 1. Calculate Cartesian coordinates.
// let x = phi.sin() * theta.cos();
// let y = phi.sin() * theta.sin();
// let z = phi.cos();
//
// Vec3::new(x, y, z)
2024-10-05 09:46:57 +02:00
// }
2024-10-05 12:17:55 +02:00