diff --git a/src/example_client.rs b/src/example_client.rs index 3f5d9ad..a1efed0 100644 --- a/src/example_client.rs +++ b/src/example_client.rs @@ -162,20 +162,26 @@ impl Client for ExampleClient { menu_bar.end(ui); } if self.show_camera_info { - let text = format!("{:?}", self.camera) - .replace("{", "{\n") - .replace("}", "\n}") - .replace("],", "],\n"); Window::new(im_str!("CameraInfo")) - .size([300.0, 300.0], Condition::Always) - .position([50.0, 50.0], Condition::Always) + .size([260.0, 430.0], Condition::Always) + .position([40.0, 40.0], Condition::Always) .title_bar(false) .scroll_bar(false) + .no_inputs() + .bg_alpha(0.8) .collapsible(false) .build(&ui, || { ui.text(im_str!("Camera info")); ui.separator(); - ui.text(text); + >::render( + &[&self.camera], + &"CameraInfo", + ui, + &imgui_inspect::InspectArgsDefault { + header: Some(false), + ..imgui_inspect::InspectArgsDefault::default() + }, + ); }); } if self.show_object_info { diff --git a/src/gaia/camera.rs b/src/gaia/camera.rs index 9cf6034..9c95bc2 100644 --- a/src/gaia/camera.rs +++ b/src/gaia/camera.rs @@ -1,8 +1,11 @@ #![allow(dead_code)] +use crate::gaia::imgui_helper::*; use cgmath; use cgmath::prelude::*; use cgmath::vec3; +use imgui_glfw_rs::imgui; +use imgui_inspect_derive::Inspect; type Point3 = cgmath::Point3; type Vector3 = cgmath::Vector3; @@ -25,13 +28,18 @@ const SPEED: f32 = 2.5; const SENSITIVTY: f32 = 0.1; const ZOOM: f32 = 45.0; -#[derive(Debug, Clone, Copy)] +#[derive(Inspect, Debug, Clone, Copy)] pub struct Camera { // Camera Attributes + #[inspect(proxy_type = "CgmathPoint3f32")] pub position: Point3, + #[inspect(proxy_type = "CgmathVec3f32")] pub front: Vector3, + #[inspect(proxy_type = "CgmathVec3f32")] pub up: Vector3, + #[inspect(proxy_type = "CgmathVec3f32")] pub right: Vector3, + #[inspect(proxy_type = "CgmathVec3f32")] pub worldup: Vector3, // Euler Angles pub yaw: f32, diff --git a/src/gaia/engine.rs b/src/gaia/engine.rs index 3e3c65e..ce1659d 100644 --- a/src/gaia/engine.rs +++ b/src/gaia/engine.rs @@ -82,6 +82,7 @@ impl Engine { ) .no_decoration() .no_inputs() + .bg_alpha(0.8) .save_settings(false) .build(&ui, || { ui.text("Welcome in doppler world!"); diff --git a/src/gaia/framebuffer.rs b/src/gaia/framebuffer.rs index 78afd75..eb148bf 100644 --- a/src/gaia/framebuffer.rs +++ b/src/gaia/framebuffer.rs @@ -15,7 +15,6 @@ pub struct FramebufferSystem { impl Drop for FramebufferSystem { fn drop(&mut self) { - println!("Drop framebuffer!"); unsafe { gl::DeleteVertexArrays(1, &self.vao); gl::DeleteBuffers(1, &self.vbo); diff --git a/src/gaia/imgui_helper.rs b/src/gaia/imgui_helper.rs index fd6c923..0261520 100644 --- a/src/gaia/imgui_helper.rs +++ b/src/gaia/imgui_helper.rs @@ -1,8 +1,9 @@ -use cgmath::Vector3; +use cgmath::{Point3, Vector3}; use imgui_glfw_rs::imgui; use imgui_inspect::InspectArgsDefault; use imgui_inspect::InspectRenderDefault; +pub struct CgmathPoint3f32; pub struct CgmathVec3f32; impl InspectRenderDefault> for CgmathVec3f32 { fn render( @@ -12,7 +13,10 @@ impl InspectRenderDefault> for CgmathVec3f32 { _args: &InspectArgsDefault, ) { ui.text(label); - ui.text(format!("{:?}", data)); + for el in data.iter() { + let text = format!("X: {:.3}, Y: {:.3}, Z: {:.3}", el.x, el.y, el.z); + ui.text(&text); + } } fn render_mut( @@ -35,3 +39,38 @@ impl InspectRenderDefault> for CgmathVec3f32 { change } } + +impl InspectRenderDefault> for CgmathPoint3f32 { + fn render( + data: &[&Point3], + label: &'static str, + ui: &imgui::Ui, + _args: &InspectArgsDefault, + ) { + ui.text(label); + for el in data.iter() { + let text = format!("X: {:.3}, Y: {:.3}, Z: {:.3}", el.x, el.y, el.z); + ui.text(&text); + } + } + + fn render_mut( + data: &mut [&mut Point3], + label: &'static str, + ui: &imgui::Ui, + _args: &InspectArgsDefault, + ) -> bool { + use imgui::*; + let label_im = im_str!("##x,y,z{}", label); + ui.text(label); + let mut change = false; + for el in data.iter_mut() { + let mut array: [f32; 3] = [el.x, el.y, el.z]; + change |= ui.drag_float3(&label_im, &mut array).build(); + el.x = array[0]; + el.y = array[1]; + el.z = array[2]; + } + change + } +} diff --git a/src/gaia/mesh.rs b/src/gaia/mesh.rs index 02e4fd3..be5968c 100644 --- a/src/gaia/mesh.rs +++ b/src/gaia/mesh.rs @@ -51,7 +51,9 @@ pub struct Texture { impl Drop for Texture { fn drop(&mut self) { - unsafe { gl::DeleteTextures(1, &self.id); } + unsafe { + gl::DeleteTextures(1, &self.id); + } } } diff --git a/src/gaia/shader.rs b/src/gaia/shader.rs index 65bcd25..6ae3d39 100644 --- a/src/gaia/shader.rs +++ b/src/gaia/shader.rs @@ -10,7 +10,7 @@ use gl::types::*; use crate::gaia::consts; use cgmath::prelude::*; -use cgmath::{Matrix, Matrix4, Vector3, Vector2}; +use cgmath::{Matrix, Matrix4, Vector2, Vector3}; #[derive(Debug)] pub struct Shader { @@ -19,7 +19,9 @@ pub struct Shader { impl Drop for Shader { fn drop(&mut self) { - unsafe{gl::DeleteShader(self.ID);} + unsafe { + gl::DeleteShader(self.ID); + } } }