Camera display imgui, imgui design fixes

This commit is contained in:
Piotr 2020-09-27 01:09:36 +02:00
parent d78ba01130
commit a48a8ab252
7 changed files with 71 additions and 14 deletions

View File

@ -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);
<Camera as imgui_inspect::InspectRenderDefault<Camera>>::render(
&[&self.camera],
&"CameraInfo",
ui,
&imgui_inspect::InspectArgsDefault {
header: Some(false),
..imgui_inspect::InspectArgsDefault::default()
},
);
});
}
if self.show_object_info {

View File

@ -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<f32>;
type Vector3 = cgmath::Vector3<f32>;
@ -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,

View File

@ -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!");

View File

@ -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);

View File

@ -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<Vector3<f32>> for CgmathVec3f32 {
fn render(
@ -12,7 +13,10 @@ impl InspectRenderDefault<Vector3<f32>> 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<Vector3<f32>> for CgmathVec3f32 {
change
}
}
impl InspectRenderDefault<Point3<f32>> for CgmathPoint3f32 {
fn render(
data: &[&Point3<f32>],
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<f32>],
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
}
}

View File

@ -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);
}
}
}

View File

@ -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);
}
}
}