diff --git a/src/cfg/window.rs b/src/cfg/window.rs index bcf513a..b8c4457 100644 --- a/src/cfg/window.rs +++ b/src/cfg/window.rs @@ -28,9 +28,15 @@ pub struct CfgWindow { #[serde(default)] pub orthographic: bool, - #[serde(default)] + #[serde(default = "default_fovy")] pub fovy: Float, + #[serde(default = "default_camera_up")] + pub camera_up: Vec3, + + #[serde(default = "default_camera_direction")] + pub camera_direction: Vec3, + #[serde(default)] pub ambient: Vec3, @@ -63,7 +69,9 @@ impl Default for CfgWindow { shadow_dpi: default_dpi(), shadows: false, orthographic: false, - fovy: 30.0, + fovy: default_fovy(), + camera_up: default_camera_up(), + camera_direction: default_camera_direction(), ambient: Vec3::zeros(), wireframe: false, colormap: CfgColormap::default(), @@ -90,6 +98,18 @@ fn default_normals_length() -> Float { 0.02 } +pub fn default_fovy() -> Float { + 30.0 +} + +fn default_camera_up() -> Vec3 { + Vec3::z() +} + +fn default_camera_direction() -> Vec3 { + -Vec3::x() +} + #[derive(Clone, Debug, Serialize, Deserialize)] pub struct CfgColormap { #[serde(default)] diff --git a/src/simu/routines/core.rs b/src/simu/routines/core.rs index c346e83..9395d68 100644 --- a/src/simu/routines/core.rs +++ b/src/simu/routines/core.rs @@ -41,7 +41,7 @@ pub trait Routines: DowncastSync { "none", &body.id, ); - Vec3::from_row_slice(&position) + Vec3::from_row_slice(&position) * 1e3 } else { panic!("A body must be loaded to compute the position of the Sun.") } @@ -186,7 +186,7 @@ pub trait Routines: DowncastSync { "none", &origin, ); - Vec3::from_row_slice(&position) + Vec3::from_row_slice(&position) * 1e3 } else { Vec3::zeros() } diff --git a/src/simu/scenario.rs b/src/simu/scenario.rs index 24aafe2..9156e27 100644 --- a/src/simu/scenario.rs +++ b/src/simu/scenario.rs @@ -79,6 +79,9 @@ impl Scenario { s.colormap = cfg.window.colormap.name; s.shadows = cfg.window.shadows; s.ortho = cfg.window.orthographic; + s.fovy = cfg.window.fovy; + s.camera_up = cfg.window.camera_up; + s.camera_direction = cfg.window.camera_direction; s.ambient_light_color = cfg.window.ambient; s.wireframe = cfg.window.wireframe; s.draw_normals = cfg.window.normals; diff --git a/src/win/scene.rs b/src/win/scene.rs index d4a6b8b..da39faf 100644 --- a/src/win/scene.rs +++ b/src/win/scene.rs @@ -1,4 +1,4 @@ -use crate::{util::*, Camera, Light, Surface, WindowSettings, VAO}; +use crate::{util::*, Camera, Light, ProjectionMode, Surface, WindowSettings, VAO}; use itertools::izip; @@ -13,11 +13,18 @@ pub struct WindowScene { impl WindowScene { pub fn new(settings: &WindowSettings) -> Self { - let camera = Camera::new( + let mut camera = Camera::new( settings.camera_up, settings.camera_direction, settings.camera_position, ); + + if settings.ortho { + camera.projection.mode = ProjectionMode::Orthographic(settings.fovy); + } else { + camera.projection.mode = ProjectionMode::Perspective(camera.position.magnitude()); + } + let light = Light::new(settings.light_position); let light_vao = settings.show_light.then_some(VAO::smooth_element_buffers(