some bugs, but basic menu

Objects
Milk.H 2023-03-30 10:46:33 +02:00
parent 0a712b4c72
commit 83d940b25b
No known key found for this signature in database
GPG Key ID: 3D9DAE46AAC37BD8
5 changed files with 91 additions and 11 deletions

View File

@ -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"

View File

@ -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<f32>, cgmath::Vector3<f32>),
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<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 {
pub fn new(gl: std::sync::Arc<glow::Context>) -> 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<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;
@ -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
})
}

View File

@ -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<f32>,
pub Rotation: Quaternion<f32>,
pub Velocity: Vector3<f32>,
pub Scale: f32
}

View File

@ -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) => ()
}
}

View File

@ -8,10 +8,10 @@ use crate::model::Model;
use crate::camera::Camera;
pub struct Transform {
Position: Vector3<f32>,
Rotation: Quaternion<f32>,
Velocity: Vector3<f32>,
Scale: f32,
pub Position: Vector3<f32>,
pub Rotation: Quaternion<f32>,
pub Velocity: Vector3<f32>,
pub Scale: f32,
}
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 Transform: Transform,