Initial camera camera repositioning
This commit is contained in:
parent
e61964c513
commit
7c160731e7
7 changed files with 82 additions and 44 deletions
|
|
@ -1,19 +1,17 @@
|
|||
use egui::Widget;
|
||||
use egui::{ahash::HashMap, Widget};
|
||||
use egui_winit_vulkano::{Gui, GuiConfig};
|
||||
use ray_tracing_core::prelude::*;
|
||||
use ray_tracing_scene::examples::example_scenes;
|
||||
use render::{render_thread, RENDERER};
|
||||
use setup::{get_compute_pipeline, get_framebuffers};
|
||||
use std::sync::Arc;
|
||||
use setup::{get_compute_pipeline, get_framebuffers, SetupResult};
|
||||
use std::{collections::HashSet, sync::Arc};
|
||||
use vulkano::{
|
||||
buffer::{Buffer, BufferCreateInfo, BufferUsage},
|
||||
command_buffer::{allocator::StandardCommandBufferAllocator, AutoCommandBufferBuilder},
|
||||
descriptor_set::{
|
||||
allocator::StandardDescriptorSetAllocator, PersistentDescriptorSet, WriteDescriptorSet,
|
||||
},
|
||||
memory::allocator::{
|
||||
AllocationCreateInfo, MemoryAllocator, MemoryTypeFilter, StandardMemoryAllocator,
|
||||
},
|
||||
memory::allocator::{AllocationCreateInfo, MemoryTypeFilter, StandardMemoryAllocator},
|
||||
pipeline::Pipeline,
|
||||
swapchain::{self, SwapchainCreateInfo, SwapchainPresentInfo},
|
||||
sync::{self, future::FenceSignalFuture, GpuFuture},
|
||||
|
|
@ -60,9 +58,9 @@ mod cs {
|
|||
}
|
||||
|
||||
fn main() {
|
||||
let (event_loop, physical_device, device, queue, window, surface) = setup::setup();
|
||||
let SetupResult(event_loop, physical_device, device, queue, window, surface) = setup::setup();
|
||||
|
||||
let (mut swapchain, mut images) = setup::create_swapchain(
|
||||
let (mut swapchain, images) = setup::create_swapchain(
|
||||
physical_device.clone(),
|
||||
device.clone(),
|
||||
surface.clone(),
|
||||
|
|
@ -100,7 +98,7 @@ fn main() {
|
|||
scene: scene.0,
|
||||
renderer_id: 0,
|
||||
camera_pos: e.camera_pos,
|
||||
camera_dir: e.camera_dir,
|
||||
camera_look_at: e.camera_look_at,
|
||||
camera_up: e.camera_up,
|
||||
camera_horizontal_fov: e.horizontal_fov,
|
||||
}
|
||||
|
|
@ -124,6 +122,7 @@ fn main() {
|
|||
let mut buffer = None;
|
||||
|
||||
let cs = cs::load(device.clone()).unwrap();
|
||||
let mut keypressed = HashSet::new();
|
||||
|
||||
let cpu_buffers: Vec<_> = framebuffers
|
||||
.iter()
|
||||
|
|
@ -148,8 +147,20 @@ fn main() {
|
|||
let mut pipeline = get_compute_pipeline(device.clone(), cs.clone());
|
||||
|
||||
event_loop.run(move |event, _, control_flow| match event {
|
||||
Event::WindowEvent { window_id, event } => {
|
||||
gui.update(&event);
|
||||
Event::WindowEvent {
|
||||
window_id: _,
|
||||
event,
|
||||
} => {
|
||||
if !gui.update(&event) {
|
||||
if let WindowEvent::KeyboardInput { input, .. } = event {
|
||||
if let Some(virt) = input.virtual_keycode {
|
||||
match input.state {
|
||||
winit::event::ElementState::Pressed => keypressed.insert(virt),
|
||||
winit::event::ElementState::Released => keypressed.remove(&virt),
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
match event {
|
||||
WindowEvent::Resized(_) => {
|
||||
recreate_swapchain = true;
|
||||
|
|
@ -178,6 +189,27 @@ fn main() {
|
|||
}
|
||||
|
||||
let mut settings_changed = false;
|
||||
if keypressed.contains(&winit::event::VirtualKeyCode::Right) {
|
||||
let translation = Dir3::cross(
|
||||
settings.camera_look_at - settings.camera_pos,
|
||||
settings.camera_up,
|
||||
)
|
||||
.normalize();
|
||||
settings.camera_pos = settings.camera_pos + translation * 0.1;
|
||||
settings.camera_look_at = settings.camera_look_at + translation * 0.1;
|
||||
settings_changed = true;
|
||||
}
|
||||
if keypressed.contains(&winit::event::VirtualKeyCode::Left) {
|
||||
let translation = Dir3::cross(
|
||||
settings.camera_look_at - settings.camera_pos,
|
||||
settings.camera_up,
|
||||
)
|
||||
.normalize();
|
||||
settings.camera_pos = settings.camera_pos - translation * 0.1;
|
||||
settings.camera_look_at = settings.camera_look_at - translation * 0.1;
|
||||
settings_changed = true;
|
||||
}
|
||||
|
||||
gui.immediate_ui(|gui| {
|
||||
let ctx = gui.context();
|
||||
egui::Window::new("panel").show(&ctx, |ui| {
|
||||
|
|
@ -195,7 +227,7 @@ fn main() {
|
|||
settings_changed = true;
|
||||
let e = scenes[settings.scene]();
|
||||
settings.camera_pos = e.camera_pos;
|
||||
settings.camera_dir = e.camera_dir;
|
||||
settings.camera_look_at = e.camera_look_at;
|
||||
settings.camera_up = e.camera_up;
|
||||
settings.camera_horizontal_fov = e.horizontal_fov;
|
||||
}
|
||||
|
|
@ -340,6 +372,7 @@ fn main() {
|
|||
.then_signal_fence_and_flush();
|
||||
|
||||
fences[image_i as usize] = match future.map_err(Validated::unwrap) {
|
||||
#[allow(clippy::arc_with_non_send_sync)]
|
||||
Ok(value) => Some(Arc::new(value)),
|
||||
Err(VulkanError::OutOfDate) => {
|
||||
recreate_swapchain = true;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue