debug toggle

This commit is contained in:
Robin Appelman 2022-03-20 16:00:18 +01:00
commit 0bc20c0d65
2 changed files with 13 additions and 4 deletions

View file

@ -4,6 +4,7 @@ pub struct FirstPerson {
control: CameraControl,
speed: f32,
keys: [bool; 4],
pub debug: bool,
}
impl FirstPerson {
@ -20,6 +21,7 @@ impl FirstPerson {
},
speed,
keys: [false; 4],
debug: true,
}
}
@ -31,6 +33,11 @@ impl FirstPerson {
let change = self.control.handle_events(camera, events)?;
for event in events.iter_mut() {
match event {
Event::Text(text) => {
if text == "`" {
self.debug = !self.debug;
}
}
Event::KeyPress { kind, .. } => {
self.key_press(kind);
}

View file

@ -52,7 +52,7 @@ impl Renderer {
}
pub fn render(&mut self, mut frame_input: FrameInput) -> ThreeDResult<FrameOutput> {
let (ui_change, panel_width) = self.gui.update(&mut frame_input, &self.camera)?;
let (ui_change, _panel_width) = self.gui.update(&mut frame_input, &self.camera)?;
let change = frame_input.first_frame || ui_change;
if change {
if self.gui.shadows_enabled {
@ -79,9 +79,9 @@ impl Renderer {
}
let viewport = Viewport {
x: panel_width as i32,
x: 0,
y: 0,
width: frame_input.viewport.width - panel_width,
width: frame_input.viewport.width,
height: frame_input.viewport.height,
};
self.camera.set_viewport(viewport).unwrap();
@ -149,7 +149,9 @@ impl Renderer {
.render_pass(&self.camera, &self.models, &self.lights)?
}
};
if self.control.debug {
self.gui.render()?;
}
Ok(())
})?;
Ok(FrameOutput::default())