Skip to content

Commit

Permalink
extend OrbitCamera::new with init_pos
Browse files Browse the repository at this point in the history
  • Loading branch information
mkovaxx committed Nov 27, 2023
1 parent 60d4344 commit b5e53d2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
14 changes: 9 additions & 5 deletions crates/viewer/src/camera.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use glam::{vec3, Mat3, Mat4, Quat, Vec2, Vec3};
use glam::{Mat3, Mat4, Quat, Vec2, Vec3, Vec3Swizzles};

const MIN_ZOOM_FACTOR: f32 = 0.05;

Expand All @@ -24,14 +24,18 @@ pub struct OrbitCamera {
}

impl OrbitCamera {
pub fn new(width: u32, height: u32) -> Self {
pub fn new(width: u32, height: u32, init_pos: Vec3) -> Self {
let target = Vec3::ZERO;
let radius = init_pos.length();
let look_at_matrix = Mat4::look_at_rh(init_pos, target, Vec3::Z);
let orientation = Quat::from_mat4(&look_at_matrix).inverse();
Self {
projection: Projection::Orthographic,
aspect_ratio: width as f32 / height as f32,
zoom_factor: 1.0,
target: vec3(0.0, 0.0, 0.0),
radius: 100.0,
orientation: Quat::IDENTITY,
target,
radius,
orientation,
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/viewer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ impl GameApp for ViewerApp {

Self {
client_rect: vec2(width as f32, height as f32),
camera: OrbitCamera::new(width, height),
camera: OrbitCamera::new(width, height, Vec3::new(40.0, -40.0, 20.0)),
depth_texture,
text_system: TextSystem::new(device, surface_texture_format, width, height),
fps_counter: FPSCounter::new(),
Expand Down

0 comments on commit b5e53d2

Please sign in to comment.