diff --git a/src/example_client.rs b/src/example_client.rs index b5de798..f2bad07 100644 --- a/src/example_client.rs +++ b/src/example_client.rs @@ -1,6 +1,6 @@ use crate::gaia::camera::*; -use crate::gaia::{consts,macros}; +use crate::gaia::{consts}; use crate::gaia::*; use imgui_glfw_rs::glfw; use crate::gaia::components::{Transform,ModelComponent}; @@ -81,6 +81,23 @@ impl Client for ExampleClient { .enable_mouse_movement(window.get_key(Key::LeftControl) != Action::Press); } + fn debug_draw(&mut self, ui: &imgui_glfw_rs::imgui::Ui) { + use imgui_glfw_rs::imgui; + use imgui::*; + use imgui_inspect::InspectArgsStruct; + Window::new(im_str!("Object info")) + .size([250.0, 250.0], Condition::FirstUseEver) + .build(&ui, || { + let mut selected_mut = vec![&mut self.model.transform]; + >::render_mut( + &mut selected_mut, + "Example Struct - Writable", + &ui, + &InspectArgsStruct::default(), + ); + }); + } + fn on_mouse_scroll(&mut self, yoffset: f32){ self.camera.process_mouse_scroll(yoffset as f32); } diff --git a/src/gaia/client.rs b/src/gaia/client.rs index bfe07c1..b0febe8 100644 --- a/src/gaia/client.rs +++ b/src/gaia/client.rs @@ -8,4 +8,5 @@ pub trait Client { fn on_mouse_move(&mut self, x: f32, y: f32); // fn draw(&mut self, engine: &mut Engine) where T: Client; unsafe fn draw(&mut self); + fn debug_draw(&mut self, ui: &imgui_glfw_rs::imgui::Ui); } \ No newline at end of file diff --git a/src/gaia/components.rs b/src/gaia/components.rs index dc1968a..37f8c0d 100644 --- a/src/gaia/components.rs +++ b/src/gaia/components.rs @@ -1,12 +1,49 @@ -use crate::gaia::*; -use crate::gaia::macros; +use imgui_inspect::InspectArgsDefault; +use imgui_inspect::InspectRenderDefault; use cgmath::{perspective, vec3, Deg, Matrix4, Point3, Rad, Vector3}; use crate::gaia::model::Model; use crate::gaia::shader::Shader; +use imgui_glfw_rs::imgui; +use imgui_inspect::*; +use imgui_inspect_derive::Inspect; +use imgui_inspect::InspectArgsStruct; +struct cgmathVec3f32; +impl InspectRenderDefault> for cgmathVec3f32 { + fn render(data: &[&Vector3], label: &'static str, ui: &imgui::Ui, args: &InspectArgsDefault) { + ui.text(label); + ui.text(format!("{:?}", data)); + } + + fn render_mut(data: &mut [&mut Vector3], label: &'static str, ui: &imgui::Ui, args: &InspectArgsDefault) -> bool { + use imgui::*; + ui.text(label); + let mut change = false; + for el in data.iter_mut() { + change |= ui.input_float(im_str!("x"), &mut el.x) + .step(0.01) + .step_fast(1.0) + .build(); + change |= ui.input_float(im_str!("y"), &mut el.y) + .step(0.01) + .step_fast(1.0) + .build(); + change |= ui.input_float(im_str!("z"), &mut el.z) + .step(0.01) + .step_fast(1.0) + .build(); + } + change + } +} + +#[derive(Inspect, Clone)] pub struct Transform { + #[inspect(proxy_type = "cgmathVec3f32")] pub position: Vector3, + #[inspect(proxy_type = "cgmathVec3f32")] pub scale: Vector3, + #[inspect(proxy_type = "cgmathVec3f32")] pub rotation: Vector3, } diff --git a/src/gaia/engine.rs b/src/gaia/engine.rs index 0a9a1e5..654022a 100644 --- a/src/gaia/engine.rs +++ b/src/gaia/engine.rs @@ -64,6 +64,7 @@ impl Engine { let ui = self.imgui_glfw.frame(&mut self.window, &mut self.imgui); { + self.client.debug_draw(&ui); use imgui::*; let fps = 1.0 / delta_time; let mut info = self.bg_info; diff --git a/src/gaia/utils.rs b/src/gaia/utils.rs index 4c718b3..35bfaaf 100644 --- a/src/gaia/utils.rs +++ b/src/gaia/utils.rs @@ -1,9 +1,6 @@ use std::os::raw::c_void; use std::path::Path; -use std::sync::mpsc::Receiver; - use gl; - use image; use image::DynamicImage::*; use image::GenericImage;