some bugs, but basic menu
parent
0a712b4c72
commit
83d940b25b
|
@ -15,3 +15,4 @@ sdl2 = "0.34.5"
|
||||||
imgui = "0.10.0"
|
imgui = "0.10.0"
|
||||||
imgui-glow-renderer = {path = "./imgui_glow_renderer"}
|
imgui-glow-renderer = {path = "./imgui_glow_renderer"}
|
||||||
imgui-sdl2-support = {path = "./imgui_sdl2_support"}
|
imgui-sdl2-support = {path = "./imgui_sdl2_support"}
|
||||||
|
mint = "0.5.9"
|
||||||
|
|
64
src/debug.rs
64
src/debug.rs
|
@ -8,13 +8,14 @@ const MODELS: [&str; 3]= ["resources/models/TestCarModel/CarW4.obj", "resources/
|
||||||
|
|
||||||
mod info;
|
mod info;
|
||||||
|
|
||||||
|
|
||||||
pub enum dEvent
|
pub enum dEvent
|
||||||
{
|
{
|
||||||
loadModel(i32),
|
loadModel(i32),
|
||||||
setTest(f32, i32),
|
setTest(f32, i32),
|
||||||
|
getObj(i32),
|
||||||
addWindow(OpenWindows),
|
addWindow(OpenWindows),
|
||||||
removeWindow(OpenWindows),
|
removeWindow(OpenWindows),
|
||||||
|
setObj(cgmath::Vector3<f32>, cgmath::Vector3<f32>),
|
||||||
exit,
|
exit,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,6 +24,7 @@ pub enum Callback
|
||||||
{
|
{
|
||||||
ModelInfo(info::ModelI),
|
ModelInfo(info::ModelI),
|
||||||
TestWind(info::testI),
|
TestWind(info::testI),
|
||||||
|
ObjectInfo(info::ObjectI),
|
||||||
MainMenu,
|
MainMenu,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,6 +33,7 @@ pub enum OpenWindows {
|
||||||
ModelInfo,
|
ModelInfo,
|
||||||
TestWind,
|
TestWind,
|
||||||
MainMenu,
|
MainMenu,
|
||||||
|
Object(i32),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Debug {
|
pub struct Debug {
|
||||||
|
@ -43,6 +46,25 @@ pub struct Debug {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fn makeMint<T>(input: cgmath::Vector3<T>) -> mint::Vector3<T>
|
||||||
|
{
|
||||||
|
mint::Vector3{
|
||||||
|
x: input.x,
|
||||||
|
y: input.y,
|
||||||
|
z: input.z
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
fn makeCG<T>(input: mint::Vector3<T>) -> cgmath::Vector3<T>
|
||||||
|
{
|
||||||
|
cgmath::Vector3
|
||||||
|
{
|
||||||
|
x: input.x,
|
||||||
|
y: input.y,
|
||||||
|
z: input.z
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Debug {
|
impl Debug {
|
||||||
pub fn new(gl: std::sync::Arc<glow::Context>) -> Debug
|
pub fn new(gl: std::sync::Arc<glow::Context>) -> Debug
|
||||||
|
@ -92,6 +114,8 @@ impl Debug {
|
||||||
ret.append(&mut Debug::displayTest(ui, &mut a)),
|
ret.append(&mut Debug::displayTest(ui, &mut a)),
|
||||||
Callback::MainMenu =>
|
Callback::MainMenu =>
|
||||||
ret.append(&mut Debug::displayMain(ui)),
|
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::loadModel(selectedModel));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
ret.push(dEvent::setTest(spinSpeed, selectedModel
|
ret.push(dEvent::setTest(spinSpeed, selectedModel));
|
||||||
));
|
|
||||||
ret
|
ret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -207,6 +230,9 @@ impl Debug {
|
||||||
if ui.button("Open the Test Modifier"){
|
if ui.button("Open the Test Modifier"){
|
||||||
ret.push(dEvent::addWindow(OpenWindows::TestWind))
|
ret.push(dEvent::addWindow(OpenWindows::TestWind))
|
||||||
}
|
}
|
||||||
|
if ui.button("Open Object Modifier") {
|
||||||
|
ret.push(dEvent::addWindow(OpenWindows::Object(0)))
|
||||||
|
}
|
||||||
if ui.button("Quit") {
|
if ui.button("Quit") {
|
||||||
ret.push(dEvent::exit)
|
ret.push(dEvent::exit)
|
||||||
}
|
}
|
||||||
|
@ -214,10 +240,24 @@ impl Debug {
|
||||||
});
|
});
|
||||||
ret
|
ret
|
||||||
}
|
}
|
||||||
|
fn displayObject(ui: &mut imgui::Ui , object: &mut info::ObjectI ) -> Vec<dEvent>
|
||||||
|
{
|
||||||
|
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;
|
use crate::model;
|
||||||
|
@ -241,3 +281,19 @@ pub fn TestWind(spinSpeed: f32, selectedModel: i32) -> Callback
|
||||||
selectedModel,
|
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
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use cgmath::{Vector3, Quaternion};
|
||||||
|
|
||||||
pub struct ModelI
|
pub struct ModelI
|
||||||
{
|
{
|
||||||
|
@ -10,3 +11,11 @@ pub struct testI
|
||||||
pub spinSpeed: f32,
|
pub spinSpeed: f32,
|
||||||
pub selectedModel: i32,
|
pub selectedModel: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct ObjectI
|
||||||
|
{
|
||||||
|
pub Position: Vector3<f32>,
|
||||||
|
pub Rotation: Quaternion<f32>,
|
||||||
|
pub Velocity: Vector3<f32>,
|
||||||
|
pub Scale: f32
|
||||||
|
}
|
||||||
|
|
12
src/scene.rs
12
src/scene.rs
|
@ -10,7 +10,7 @@ use glow::*;
|
||||||
use imgui_glow_renderer::AutoRenderer;
|
use imgui_glow_renderer::AutoRenderer;
|
||||||
use imgui_sdl2_support::SdlPlatform;
|
use imgui_sdl2_support::SdlPlatform;
|
||||||
use crate::debug;
|
use crate::debug;
|
||||||
mod objects;
|
pub mod objects;
|
||||||
use cgmath::{Matrix4, vec3, Point3, Deg, perspective};
|
use cgmath::{Matrix4, vec3, Point3, Deg, perspective};
|
||||||
use cgmath::prelude::*;
|
use cgmath::prelude::*;
|
||||||
|
|
||||||
|
@ -119,7 +119,6 @@ impl Scene{
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
self.Car.update();
|
self.Car.update();
|
||||||
self.Car.turn(self.tempData.spinSpeed);
|
|
||||||
self.Car.Draw(&self.shaders[0], &self.camera);
|
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::ModelInfo => Callbacks.push(debug::ModelInfo(&self.Car.Model)),
|
||||||
debug::OpenWindows::TestWind => Callbacks.push(debug::TestWind(self.tempData.spinSpeed, self.tempData.selectedModel)),
|
debug::OpenWindows::TestWind => Callbacks.push(debug::TestWind(self.tempData.spinSpeed, self.tempData.selectedModel)),
|
||||||
debug::OpenWindows::MainMenu => Callbacks.push(debug::Callback::MainMenu),
|
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::addWindow(a) => self.debug.addWindow(a),
|
||||||
dEvent::removeWindow(a) => self.debug.removeWindow(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) => ()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,10 +8,10 @@ use crate::model::Model;
|
||||||
use crate::camera::Camera;
|
use crate::camera::Camera;
|
||||||
|
|
||||||
pub struct Transform {
|
pub struct Transform {
|
||||||
Position: Vector3<f32>,
|
pub Position: Vector3<f32>,
|
||||||
Rotation: Quaternion<f32>,
|
pub Rotation: Quaternion<f32>,
|
||||||
Velocity: Vector3<f32>,
|
pub Velocity: Vector3<f32>,
|
||||||
Scale: f32,
|
pub Scale: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Transform {
|
impl Default for Transform {
|
||||||
|
@ -27,6 +27,12 @@ impl Default for Transform {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
impl Transform {
|
||||||
|
pub fn setPos(&mut self, input: Vector3<f32>)
|
||||||
|
{
|
||||||
|
self.Position = input;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct Player {
|
pub struct Player {
|
||||||
pub Transform: Transform,
|
pub Transform: Transform,
|
||||||
|
|
Loading…
Reference in New Issue