diff --git a/Cargo.toml b/Cargo.toml index 99d0ff9..ee671f7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,3 +15,4 @@ sdl2 = "0.34.5" imgui = "0.10.0" imgui-glow-renderer = {path = "./imgui_glow_renderer"} imgui-sdl2-support = {path = "./imgui_sdl2_support"} +mint = "0.5.9" diff --git a/src/debug.rs b/src/debug.rs index f7a4f53..eefa13f 100644 --- a/src/debug.rs +++ b/src/debug.rs @@ -8,13 +8,14 @@ const MODELS: [&str; 3]= ["resources/models/TestCarModel/CarW4.obj", "resources/ mod info; - pub enum dEvent { loadModel(i32), setTest(f32, i32), + getObj(i32), addWindow(OpenWindows), removeWindow(OpenWindows), + setObj(cgmath::Vector3, cgmath::Vector3), exit, } @@ -23,6 +24,7 @@ pub enum Callback { ModelInfo(info::ModelI), TestWind(info::testI), + ObjectInfo(info::ObjectI), MainMenu, } @@ -31,6 +33,7 @@ pub enum OpenWindows { ModelInfo, TestWind, MainMenu, + Object(i32), } pub struct Debug { @@ -43,6 +46,25 @@ pub struct Debug { } +fn makeMint(input: cgmath::Vector3) -> mint::Vector3 +{ + mint::Vector3{ + x: input.x, + y: input.y, + z: input.z + } + +} + +fn makeCG(input: mint::Vector3) -> cgmath::Vector3 + { + cgmath::Vector3 + { + x: input.x, + y: input.y, + z: input.z + } + } impl Debug { pub fn new(gl: std::sync::Arc) -> Debug @@ -92,6 +114,8 @@ impl Debug { ret.append(&mut Debug::displayTest(ui, &mut a)), Callback::MainMenu => ret.append(&mut Debug::displayMain(ui)), + Callback::ObjectInfo(mut a) => + ret.append(&mut Debug::displayObject(ui, &mut a)) } } @@ -165,8 +189,7 @@ impl Debug { ret.push(dEvent::loadModel(selectedModel)); } }); - ret.push(dEvent::setTest(spinSpeed, selectedModel - )); + ret.push(dEvent::setTest(spinSpeed, selectedModel)); ret } @@ -207,6 +230,9 @@ impl Debug { if ui.button("Open the Test Modifier"){ ret.push(dEvent::addWindow(OpenWindows::TestWind)) } + if ui.button("Open Object Modifier") { + ret.push(dEvent::addWindow(OpenWindows::Object(0))) + } if ui.button("Quit") { ret.push(dEvent::exit) } @@ -214,10 +240,24 @@ impl Debug { }); ret } + fn displayObject(ui: &mut imgui::Ui , object: &mut info::ObjectI ) -> Vec + { + let mut ret = Vec::new(); + let mut position = makeMint(object.Position); + let mut rotation = makeMint(object.Rotation.v); + ui.window("ObjectInfo") + .build(|| { + ui.text("Position"); + ui.input_float3("Position", &mut position).build(); + ui.input_float3("Rotation", &mut rotation).build(); + ui.text("WIP"); + ret.push(dEvent::setObj(makeCG(position), makeCG(rotation))); + }); + ret - } - + } +} use crate::model; @@ -241,3 +281,19 @@ pub fn TestWind(spinSpeed: f32, selectedModel: i32) -> Callback selectedModel, }) } + +use crate::scene::objects::Player; + +pub fn ObjectInfo(object: &Player) -> Callback + { + let Position = object.Transform.Position; + let Rotation = object.Transform.Rotation; + let Velocity = object.Transform.Velocity; + let Scale = object.Transform.Scale; + Callback::ObjectInfo(info::ObjectI { + Position, + Rotation, + Velocity, + Scale + }) + } diff --git a/src/debug/info.rs b/src/debug/info.rs index b4386b1..a0e966e 100644 --- a/src/debug/info.rs +++ b/src/debug/info.rs @@ -1,3 +1,4 @@ +use cgmath::{Vector3, Quaternion}; pub struct ModelI { @@ -10,3 +11,11 @@ pub struct testI pub spinSpeed: f32, pub selectedModel: i32, } + +pub struct ObjectI + { + pub Position: Vector3, + pub Rotation: Quaternion, + pub Velocity: Vector3, + pub Scale: f32 + } diff --git a/src/scene.rs b/src/scene.rs index bc6a20f..1734202 100644 --- a/src/scene.rs +++ b/src/scene.rs @@ -10,7 +10,7 @@ use glow::*; use imgui_glow_renderer::AutoRenderer; use imgui_sdl2_support::SdlPlatform; use crate::debug; -mod objects; +pub mod objects; use cgmath::{Matrix4, vec3, Point3, Deg, perspective}; use cgmath::prelude::*; @@ -119,7 +119,6 @@ impl Scene{ } */ self.Car.update(); - self.Car.turn(self.tempData.spinSpeed); self.Car.Draw(&self.shaders[0], &self.camera); @@ -165,6 +164,7 @@ impl Scene{ debug::OpenWindows::ModelInfo => Callbacks.push(debug::ModelInfo(&self.Car.Model)), debug::OpenWindows::TestWind => Callbacks.push(debug::TestWind(self.tempData.spinSpeed, self.tempData.selectedModel)), debug::OpenWindows::MainMenu => Callbacks.push(debug::Callback::MainMenu), + debug::OpenWindows::Object(a) => Callbacks.push(debug::ObjectInfo(&self.Car)), } } @@ -183,6 +183,14 @@ impl Scene{ }, dEvent::addWindow(a) => self.debug.addWindow(a), dEvent::removeWindow(a) => self.debug.removeWindow(a), + dEvent::setObj(p, r) => + { + self.Car.Transform.Position = p; + self.Car.Transform.Rotation.v = r; + self.Car.Transform.Rotation.normalize(); + } + // TODO + dEvent::getObj(_a) => () } } diff --git a/src/scene/objects.rs b/src/scene/objects.rs index 52620d7..6ab090c 100644 --- a/src/scene/objects.rs +++ b/src/scene/objects.rs @@ -8,10 +8,10 @@ use crate::model::Model; use crate::camera::Camera; pub struct Transform { - Position: Vector3, - Rotation: Quaternion, - Velocity: Vector3, - Scale: f32, + pub Position: Vector3, + pub Rotation: Quaternion, + pub Velocity: Vector3, + pub Scale: f32, } impl Default for Transform { @@ -27,6 +27,12 @@ impl Default for Transform { } } +impl Transform { + pub fn setPos(&mut self, input: Vector3) + { + self.Position = input; + } +} pub struct Player { pub Transform: Transform,