Skip to content

Commit

Permalink
win settings camera in cfg
Browse files Browse the repository at this point in the history
  • Loading branch information
GregoireHENRY committed Dec 14, 2023
1 parent dab9033 commit 17cfe0f
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 6 deletions.
24 changes: 22 additions & 2 deletions src/cfg/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand Down Expand Up @@ -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(),
Expand All @@ -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)]
Expand Down
4 changes: 2 additions & 2 deletions src/simu/routines/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
}
Expand Down Expand Up @@ -186,7 +186,7 @@ pub trait Routines: DowncastSync {
"none",
&origin,
);
Vec3::from_row_slice(&position)
Vec3::from_row_slice(&position) * 1e3
} else {
Vec3::zeros()
}
Expand Down
3 changes: 3 additions & 0 deletions src/simu/scenario.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 9 additions & 2 deletions src/win/scene.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{util::*, Camera, Light, Surface, WindowSettings, VAO};
use crate::{util::*, Camera, Light, ProjectionMode, Surface, WindowSettings, VAO};

use itertools::izip;

Expand All @@ -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(
Expand Down

0 comments on commit 17cfe0f

Please sign in to comment.