Skip to content

Commit

Permalink
Fix camera up verctor and scroll events
Browse files Browse the repository at this point in the history
  • Loading branch information
voxelias committed Nov 25, 2024
1 parent 2b00f1d commit 0090b0f
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 36 deletions.
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub use world::{Camera, Entity, World};

/// Window API and input events
pub mod window;
pub use window::event::{Button as ButtonEvent, Event};
pub use window::event::{Button as ButtonEvent, Event, Modifiers, MouseScroll};
pub use window::{Input, ReadInput, Window};

//pub use utils::{ Id };
Expand Down
44 changes: 22 additions & 22 deletions src/tasks/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ pub fn spawn<T: context::Context>(
}

if restart_queue {
log::debug!("restart queue(queue_executed: {}", queue_executed);
// log::debug!("restart queue(queue_executed: {}", queue_executed);
if queue_executed {
let mut ctx = context_manager.lock().expect("Mutex to be locked");
ctx.reset_data(tasks_graph_changed);
Expand All @@ -155,24 +155,24 @@ pub fn spawn<T: context::Context>(

let default_state = TypeId::of::<()>();
let current_state = ctx.current_state();
log::debug!("current state: {:?}", current_state);
// log::debug!("current state: {:?}", current_state);
if current_state != default_state {
if let Some(tasks) = pool.select_for_state(&default_state) {
for task in tasks.iter() {
log::debug!(
"tasks for default state: {:?}",
pool.get(*task).and_then(|t| t.name())
);
// log::debug!(
// "tasks for default state: {:?}",
// pool.get(*task).and_then(|t| t.name())
// );
}
queue.extend_from_slice(tasks);
}
}
if let Some(tasks) = pool.select_for_state(&current_state) {
for task in tasks.iter() {
log::debug!(
"tasks for current state: {:?}",
pool.get(*task).and_then(|t| t.name())
);
// log::debug!(
// "tasks for current state: {:?}",
// pool.get(*task).and_then(|t| t.name())
// );
}
queue.extend_from_slice(tasks);
}
Expand All @@ -198,28 +198,28 @@ pub fn spawn<T: context::Context>(
while index < stop_index {
let task_id = queue[index];
if let Some(mut task) = pool.take(&task_id) {
log::debug!("task({}): begin control", task.name());
// log::debug!("task({}): begin control", task.name());
if !task.is_scheduled() {
log::debug!("task({}): not scheduled yet", task.name());
// log::debug!("task({}): not scheduled yet", task.name());
if task.name() == "dotrix::window::input::ReadInput" {
log::debug!(
"task({}): not scheduled yet: {:?}",
task.name(),
task.dependencies()
);
// log::debug!(
// "task({}): not scheduled yet: {:?}",
// task.name(),
// task.dependencies()
// );
}
if let Some(dependencies_state) = context_manager
.lock()
.unwrap()
.match_dependencies(task.dependencies())
{
log::debug!("task({}): to be scheduled", task.name());
// log::debug!("task({}): to be scheduled", task.name());
task.schedule_with(dependencies_state);
} else {
log::debug!(
"task({}): dependencies are not sattisfied",
task.name()
);
// log::debug!(
// "task({}): dependencies are not sattisfied",
// task.name()
// );
}
}

Expand Down
28 changes: 16 additions & 12 deletions src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,17 +224,21 @@ impl<T: Application> winit::application::ApplicationHandler for EventLoop<T> {
self.task_manager.provide(input_event);
}
winit::event::WindowEvent::MouseWheel { delta, .. } => {
let input_event = match delta {
winit::event::MouseScrollDelta::LineDelta(x, y) => event::MouseScroll::Lines {
horizontal: x,
vertical: y,
},
winit::event::MouseScrollDelta::PixelDelta(position) => {
event::MouseScroll::Pixels {
horizontal: position.x,
vertical: position.y,
let input_event = event::Event::MouseScroll {
delta: match delta {
winit::event::MouseScrollDelta::LineDelta(x, y) => {
event::MouseScroll::Lines {
horizontal: x,
vertical: y,
}
}
}
winit::event::MouseScrollDelta::PixelDelta(position) => {
event::MouseScroll::Pixels {
horizontal: position.x,
vertical: position.y,
}
}
},
};
self.task_manager.provide(input_event);
}
Expand All @@ -255,11 +259,11 @@ impl<T: Application> winit::application::ApplicationHandler for EventLoop<T> {
if let Some(instance) = self.window_instance.as_ref() {
instance.winit_window.pre_present_notify();
}
log::debug!("Wait for presenter...");
// log::debug!("Wait for presenter...");
self.task_manager
.wait_for::<graphics::FramePresenter>()
.present();
log::debug!("...presented");
// log::debug!("...presented");
self.task_manager.run();
// Note: can be used for debug
// fill::fill_window(window);
Expand Down
2 changes: 1 addition & 1 deletion src/world/camera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl View {

/// Return view matrix made from target
pub fn target(&self, target: Vec3) -> Mat4 {
self.target_up(target, Vec3::Z)
self.target_up(target, -Vec3::Y)
}

/// Return view matrix made from target and up vector
Expand Down

0 comments on commit 0090b0f

Please sign in to comment.