Skip to content

Commit

Permalink
added Mouse motion support
Browse files Browse the repository at this point in the history
  • Loading branch information
Snowiiii committed Jul 11, 2024
1 parent 60eadf6 commit 688bb3c
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 21 deletions.
26 changes: 26 additions & 0 deletions crates/vent-math/src/scalar/mat4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,32 @@ impl Mat4 {
)
}

#[inline]
#[must_use]
pub fn orthographic_rh(
left: f32,
right: f32,
bottom: f32,
top: f32,
near: f32,
far: f32,
) -> Self {
let rcp_width = 1.0 / (right - left);
let rcp_height = 1.0 / (top - bottom);
let r = 1.0 / (near - far);
Self::from_cols(
Vec4::new(rcp_width + rcp_width, 0.0, 0.0, 0.0),
Vec4::new(0.0, rcp_height + rcp_height, 0.0, 0.0),
Vec4::new(0.0, 0.0, r, 0.0),
Vec4::new(
-(left + right) * rcp_width,
-(top + bottom) * rcp_height,
r * near,
1.0,
),
)
}

#[inline]
#[must_use]
pub fn mul_mat4(&self, rhs: &Self) -> Self {
Expand Down
12 changes: 6 additions & 6 deletions crates/vent-rendering/src/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,19 @@ impl VulkanPipeline {
front_face: vk::FrontFace::COUNTER_CLOCKWISE,
line_width: 1.0,
polygon_mode: vk::PolygonMode::FILL,
cull_mode: vk::CullModeFlags::BACK,
cull_mode: vk::CullModeFlags::NONE, // TODO
..Default::default()
};
let multisample_state_info = vk::PipelineMultisampleStateCreateInfo {
rasterization_samples: vk::SampleCountFlags::TYPE_1,
..Default::default()
};

let depth_state_info = vk::PipelineDepthStencilStateCreateInfo::default()
.depth_test_enable(true)
.depth_write_enable(true)
.depth_compare_op(vk::CompareOp::LESS)
.max_depth_bounds(1.0);
let depth_state_info = vk::PipelineDepthStencilStateCreateInfo::default();
// .depth_test_enable(true)
// .depth_write_enable(true)
// .depth_compare_op(vk::CompareOp::LESS)
// .max_depth_bounds(1.0);
let color_blend_attachment_states = [vk::PipelineColorBlendAttachmentState {
color_write_mask: vk::ColorComponentFlags::RGBA,
..Default::default()
Expand Down
7 changes: 4 additions & 3 deletions crates/vent-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl VentApplication {
// TODO
let mut renderer = DefaultRuntimeRenderer::new(&project, &app_window);

let mut controller = CameraController3D::new(20.0, 10.0);
let mut controller = CameraController3D::new(20.0, 1.0);
let mut delta_time = 0.0;

// TODO, Handle scale factor change
Expand All @@ -60,7 +60,7 @@ impl VentApplication {
delta_time,
);
}
WindowEvent::Mouse { button, state } => {
WindowEvent::MouseButton { button, state } => {
controller.process_mouse_input(&button, &state);
}
WindowEvent::Resize {
Expand All @@ -69,7 +69,8 @@ impl VentApplication {
} => {
renderer.resize((new_width, new_height));
}
WindowEvent::Draw => delta_time = renderer.render(), // Default,
WindowEvent::Draw => delta_time = renderer.render(),
WindowEvent::MouseMotion { x, y } => controller.process_mouse_movement(renderer.camera.downcast_mut().expect("TODO"), x, y, delta_time), // Default,
}
});
}
Expand Down
14 changes: 10 additions & 4 deletions crates/vent-runtime/src/render/camera/camera_controller3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ pub struct CameraController3D {
sensitivity_x: f32,
sensitivity_y: f32,

old_x: f64,
old_y: f64,
mouse_left_down: bool,
}

Expand All @@ -20,6 +22,8 @@ impl CameraController3D {
sensitivity_x: sensitivity,
sensitivity_y: sensitivity,
mouse_left_down: false,
old_x: 0.0,
old_y: 0.0,
}
}

Expand Down Expand Up @@ -80,14 +84,16 @@ impl CameraController3D {
}

pub fn process_mouse_movement(
&self,
&mut self,
camera: &mut Camera3D,
mouse_dx: f64,
mouse_dy: f64,
mouse_x: f64,
mouse_y: f64,
delta_time: f32,
) {
if self.mouse_left_down {
let deltaposition = Vec2::new(mouse_dx as f32, mouse_dy as f32);
let deltaposition = Vec2::new((mouse_x - self.old_x) as f32, (mouse_y - self.old_y) as f32);
self.old_x = mouse_x;
self.old_y = mouse_y;

let moveposition =
deltaposition * Vec2::new(self.sensitivity_x, self.sensitivity_y) * delta_time;
Expand Down
6 changes: 5 additions & 1 deletion crates/vent-window/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@ pub enum WindowEvent {
key: keyboard::Key,
state: keyboard::KeyState,
},
Mouse {
MouseButton {
button: mouse::Button,
state: mouse::ButtonState,
},
MouseMotion {
x: f64,
y: f64,
},
Resize {
new_width: u32,
new_height: u32,
Expand Down
15 changes: 8 additions & 7 deletions crates/vent-window/src/platform/wayland/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ impl PointerHandler for WaylandWindow {
self.set_cursor = true;
self.decorations_cursor = Some(new_cursor);
}
self.event_sender.send(WindowEvent::MouseMotion { x, y, }).unwrap();
}
PointerEventKind::Press {
button,
Expand Down Expand Up @@ -439,49 +440,49 @@ fn press_mouse(button: u32, state: &WaylandWindow, mouse_state: mouse::ButtonSta
match button {
BTN_LEFT => state
.event_sender
.send(WindowEvent::Mouse {
.send(WindowEvent::MouseButton {
button: crate::mouse::Button::LEFT,
state: mouse_state,
})
.unwrap(),
BTN_RIGHT => state
.event_sender
.send(WindowEvent::Mouse {
.send(WindowEvent::MouseButton {
button: crate::mouse::Button::RIGHT,
state: mouse_state,
})
.unwrap(),
BTN_MIDDLE => state
.event_sender
.send(WindowEvent::Mouse {
.send(WindowEvent::MouseButton {
button: crate::mouse::Button::MIDDLE,
state: mouse_state,
})
.unwrap(),
BTN_SIDE => state
.event_sender
.send(WindowEvent::Mouse {
.send(WindowEvent::MouseButton {
button: crate::mouse::Button::SIDE,
state: mouse_state,
})
.unwrap(),
BTN_EXTRA => state
.event_sender
.send(WindowEvent::Mouse {
.send(WindowEvent::MouseButton {
button: crate::mouse::Button::EXTRA,
state: mouse_state,
})
.unwrap(),
BTN_FORWARD => state
.event_sender
.send(WindowEvent::Mouse {
.send(WindowEvent::MouseButton {
button: crate::mouse::Button::FORWARD,
state: mouse_state,
})
.unwrap(),
BTN_BACK => state
.event_sender
.send(WindowEvent::Mouse {
.send(WindowEvent::MouseButton {
button: crate::mouse::Button::BACK,
state: mouse_state,
})
Expand Down
Binary file removed docs/icon.png
Binary file not shown.
Binary file added docs/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 688bb3c

Please sign in to comment.