made some changes kinda forgor what they were tbh
parent
60eba9cd4e
commit
a3eb4017cf
66
src/main.rs
66
src/main.rs
|
@ -13,6 +13,10 @@ enum gameState {
|
|||
Playing
|
||||
}
|
||||
|
||||
enum SceneEnum {
|
||||
Exit,
|
||||
Resume
|
||||
}
|
||||
|
||||
use imgui_glow_renderer::AutoRenderer;
|
||||
use imgui_sdl2_support::SdlPlatform;
|
||||
|
@ -40,6 +44,7 @@ use scene::Scene;
|
|||
|
||||
fn main() {
|
||||
|
||||
// initialize SDL and gl
|
||||
let (gl, shader_version, window, mut events_loop, _context) = {
|
||||
let sdl = match sdl2::init()
|
||||
{
|
||||
|
@ -82,37 +87,10 @@ fn main() {
|
|||
|
||||
|
||||
// NOTE intiialize Camera
|
||||
let mut camera = camera::Camera {
|
||||
Position: Point3::new(0.0, 0.40, 1.0),
|
||||
Pitch: -20.0,
|
||||
..camera::Camera::default()
|
||||
};
|
||||
// timing
|
||||
let mut deltaTime: f32; // time between current frame and last frame
|
||||
let mut lastFrame: f32 = 0.0;
|
||||
|
||||
//gl::load_with(|ptr| window.get_proc_address(ptr) as *const _);
|
||||
let (ourshader, ourModel) = unsafe {
|
||||
gl.enable(glow::DEPTH_TEST);
|
||||
|
||||
let ourShader = shader::shader::new("model", Arc::clone(&gl));
|
||||
|
||||
let ourModel = model::Model::new("resources/models/TestCarModel/CarW4.obj", Arc::clone(&gl));
|
||||
|
||||
(ourShader, ourModel)
|
||||
};
|
||||
|
||||
|
||||
|
||||
let mut State = gameState::Playing;
|
||||
|
||||
let mut scene = Scene::new(gl.clone());
|
||||
|
||||
|
||||
let projection: Matrix4<f32> = perspective(Deg(45.0), SCR_WIDTH as f32/ SCR_HEIGHT as f32, 0.1, 100.0);
|
||||
|
||||
|
||||
|
||||
let mut scene = Scene::new(gl);
|
||||
|
||||
println!("entering main loop");
|
||||
|
||||
|
@ -126,35 +104,19 @@ fn main() {
|
|||
match &State {
|
||||
gameState::Playing => {
|
||||
|
||||
scene.update(&mut events_loop, &window);
|
||||
match scene.update(&mut events_loop, &window)
|
||||
{
|
||||
scene::SceneEnum::Exit => {
|
||||
break 'main;
|
||||
},
|
||||
_ => (),
|
||||
|
||||
}
|
||||
|
||||
window.gl_swap_window();
|
||||
for event in events_loop.poll_iter() {
|
||||
|
||||
match event {
|
||||
Event::Quit {..} |
|
||||
Event::KeyDown { keycode: Some(Keycode::Escape), .. } => {
|
||||
break 'main
|
||||
},
|
||||
Event::KeyDown {keycode: Some(Keycode::P), ..} => {
|
||||
State = gameState::Paused;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
gameState::Paused => {
|
||||
|
||||
for event in events_loop.poll_iter() {
|
||||
|
||||
match event {
|
||||
Event::KeyDown {keycode: Some(Keycode::P), ..} => {
|
||||
State = gameState::Playing;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
33
src/scene.rs
33
src/scene.rs
|
@ -31,8 +31,14 @@ pub struct tempData {
|
|||
pub currentFrame: f32,
|
||||
pub deltaTime: f32,
|
||||
pub lastFrame: f32,
|
||||
DebugMode: bool,
|
||||
}
|
||||
|
||||
pub enum SceneEnum {
|
||||
Exit,
|
||||
Pause,
|
||||
Resume,
|
||||
}
|
||||
|
||||
|
||||
pub struct Scene {
|
||||
|
@ -68,7 +74,8 @@ impl Scene{
|
|||
current_rad: 1.0,
|
||||
currentFrame: 0.0,
|
||||
deltaTime: 0.0,
|
||||
lastFrame: 0.0
|
||||
lastFrame: 0.0,
|
||||
DebugMode: false,
|
||||
|
||||
};
|
||||
|
||||
|
@ -98,7 +105,7 @@ impl Scene{
|
|||
}
|
||||
}
|
||||
|
||||
pub fn update(&mut self ,events_loop: &mut sdl2::EventPump, window: &sdl2::video::Window)
|
||||
pub fn update(&mut self ,events_loop: &mut sdl2::EventPump, window: &sdl2::video::Window) -> SceneEnum
|
||||
{
|
||||
self.tempData.currentFrame = self.time.elapsed().as_secs_f32();
|
||||
self.tempData.deltaTime = self.tempData.currentFrame - self.tempData.lastFrame;
|
||||
|
@ -123,13 +130,31 @@ impl Scene{
|
|||
}
|
||||
self.Car.Draw(&self.shaders[0]);
|
||||
|
||||
self.drawImgui(&events_loop, &window);
|
||||
if self.tempData.DebugMode{
|
||||
self.drawImgui(&events_loop, &window);
|
||||
}
|
||||
|
||||
let quit = false;
|
||||
let mut ret = SceneEnum::Resume;
|
||||
for event in events_loop.poll_iter() {
|
||||
if self.tempData.DebugMode {
|
||||
self.imgui_plat.handle_event(&mut self.imgui, &event);
|
||||
}
|
||||
match event {
|
||||
Event::Quit {..} |
|
||||
Event::KeyDown { keycode: Some(Keycode::Escape), .. } => {
|
||||
ret = SceneEnum::Exit;
|
||||
},
|
||||
Event::KeyDown {keycode: Some(Keycode::P), ..} => {
|
||||
},
|
||||
Event::KeyDown {keycode: Some(Keycode::D), ..} => {
|
||||
self.tempData.DebugMode = !self.tempData.DebugMode
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ret
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue