removed some code and made it move properly
parent
37b38694c5
commit
9161af2b83
54
src/scene.rs
54
src/scene.rs
|
@ -40,6 +40,7 @@ pub struct Scene {
|
||||||
shaders: Vec<Rc<shader>>,
|
shaders: Vec<Rc<shader>>,
|
||||||
time: std::time::Instant,
|
time: std::time::Instant,
|
||||||
DebugMode: bool,
|
DebugMode: bool,
|
||||||
|
input: objects::Input
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Scene{
|
impl Scene{
|
||||||
|
@ -65,7 +66,8 @@ impl Scene{
|
||||||
debug,
|
debug,
|
||||||
shaders: vec![shader],
|
shaders: vec![shader],
|
||||||
time,
|
time,
|
||||||
DebugMode: false
|
DebugMode: false,
|
||||||
|
input: objects::Input::default()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,24 +79,6 @@ impl Scene{
|
||||||
self.gl.enable(glow::DEPTH_TEST);
|
self.gl.enable(glow::DEPTH_TEST);
|
||||||
self.gl.clear(glow::COLOR_BUFFER_BIT | glow::DEPTH_BUFFER_BIT);
|
self.gl.clear(glow::COLOR_BUFFER_BIT | glow::DEPTH_BUFFER_BIT);
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
unsafe {
|
|
||||||
|
|
||||||
self.shaders[0].Use();
|
|
||||||
self.tempData.projection = perspective(Deg(self.camera.Zoom), SCR_WIDTH as f32 /SCR_HEIGHT as f32, 0.1, 100.0);
|
|
||||||
let view = self.camera.GetViewMatrix();
|
|
||||||
self.shaders[0].setMat4("projection", &self.tempData.projection);
|
|
||||||
self.shaders[0].setMat4("view", &view);
|
|
||||||
|
|
||||||
let mut model: Matrix4<f32> = Matrix4::from_axis_angle(vec3(0.0, -1.0, 0.0).normalize(),
|
|
||||||
cgmath::Rad(1.0));
|
|
||||||
|
|
||||||
model = model * Matrix4::from_scale(0.2);
|
|
||||||
self.shaders[0].setMat4("model", &model);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
self.Car.update();
|
|
||||||
self.Car.Draw(&self.shaders[0], &self.camera);
|
|
||||||
|
|
||||||
|
|
||||||
if self.DebugMode{
|
if self.DebugMode{
|
||||||
|
@ -105,6 +89,7 @@ impl Scene{
|
||||||
if self.DebugMode {
|
if self.DebugMode {
|
||||||
self.debug.handle(&event);
|
self.debug.handle(&event);
|
||||||
}
|
}
|
||||||
|
|
||||||
match event {
|
match event {
|
||||||
Event::Quit {..} |
|
Event::Quit {..} |
|
||||||
Event::KeyDown { keycode: Some(Keycode::Escape), .. } => {
|
Event::KeyDown { keycode: Some(Keycode::Escape), .. } => {
|
||||||
|
@ -115,12 +100,31 @@ impl Scene{
|
||||||
Event::KeyDown {keycode: Some(Keycode::Q), ..} => {
|
Event::KeyDown {keycode: Some(Keycode::Q), ..} => {
|
||||||
self.DebugMode = !self.DebugMode
|
self.DebugMode = !self.DebugMode
|
||||||
},
|
},
|
||||||
Event::KeyDown {keycode: Some(Keycode::W), ..} => {
|
Event::KeyDown {keycode: Some(Keycode::W), repeat: false, ..} => {
|
||||||
self.Car.forward();
|
self.input.Accel = true;
|
||||||
|
},
|
||||||
|
Event::KeyUp {keycode: Some(Keycode::W), ..} => {
|
||||||
|
self.input.Accel = false;
|
||||||
|
},
|
||||||
|
Event::KeyDown {keycode: Some(Keycode::S), repeat: false, ..} => {
|
||||||
|
self.input.Decel = true;
|
||||||
|
},
|
||||||
|
Event::KeyUp {keycode: Some(Keycode::S), ..} => {
|
||||||
|
self.input.Decel = false;
|
||||||
|
},
|
||||||
|
Event::KeyDown {keycode: Some(Keycode::D), repeat: false, ..} => {
|
||||||
|
self.input.Right = true;
|
||||||
|
},
|
||||||
|
Event::KeyUp {keycode: Some(Keycode::D), ..} => {
|
||||||
|
self.input.Right = false;
|
||||||
|
},
|
||||||
|
|
||||||
|
Event::KeyDown {keycode: Some(Keycode::A), repeat: false, ..} => {
|
||||||
|
self.input.Left = true;
|
||||||
|
},
|
||||||
|
Event::KeyUp {keycode: Some(Keycode::A), ..} => {
|
||||||
|
self.input.Left = false;
|
||||||
},
|
},
|
||||||
Event::KeyDown {keycode: Some(Keycode::A), .. }=> {
|
|
||||||
self.Car.turn(2.5);
|
|
||||||
}
|
|
||||||
Event::KeyDown {keycode: Some(Keycode::M), ..} => {
|
Event::KeyDown {keycode: Some(Keycode::M), ..} => {
|
||||||
self.debug.addWindow(debug::OpenWindows::ModelInfo)
|
self.debug.addWindow(debug::OpenWindows::ModelInfo)
|
||||||
},
|
},
|
||||||
|
@ -129,6 +133,8 @@ impl Scene{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.Car.update(&self.input);
|
||||||
|
self.Car.Draw(&self.shaders[0], &self.camera);
|
||||||
ret
|
ret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,23 @@ use cgmath::prelude::*;
|
||||||
use crate::model::Model;
|
use crate::model::Model;
|
||||||
use crate::camera::Camera;
|
use crate::camera::Camera;
|
||||||
|
|
||||||
|
pub struct Input {
|
||||||
|
pub Accel: bool,
|
||||||
|
pub Decel: bool,
|
||||||
|
pub Left: bool,
|
||||||
|
pub Right: bool
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for Input {
|
||||||
|
fn default() -> Input {
|
||||||
|
Input {
|
||||||
|
Accel: false,
|
||||||
|
Decel: false,
|
||||||
|
Left: false,
|
||||||
|
Right: false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
pub struct Transform {
|
pub struct Transform {
|
||||||
pub Position: Vector3<f32>,
|
pub Position: Vector3<f32>,
|
||||||
pub Rotation: Quaternion<f32>,
|
pub Rotation: Quaternion<f32>,
|
||||||
|
@ -27,6 +44,7 @@ impl Default for Transform {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Transform {
|
impl Transform {
|
||||||
pub fn setPos(&mut self, input: Vector3<f32>)
|
pub fn setPos(&mut self, input: Vector3<f32>)
|
||||||
{
|
{
|
||||||
|
@ -47,15 +65,29 @@ impl Player {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update(&mut self)
|
pub fn update(&mut self, input: &Input)
|
||||||
{
|
{
|
||||||
|
if input.Accel {
|
||||||
|
self.forward(0.01);
|
||||||
|
}
|
||||||
|
if input.Decel {
|
||||||
|
self.forward(-0.01)
|
||||||
|
}
|
||||||
|
|
||||||
|
if input.Left {
|
||||||
|
self.turn(1.5)
|
||||||
|
}
|
||||||
|
if input.Right {
|
||||||
|
self.turn(-1.5)
|
||||||
|
}
|
||||||
|
|
||||||
self.Transform.Position += self.Transform.Velocity;
|
self.Transform.Position += self.Transform.Velocity;
|
||||||
self.Transform.Rotation = self.Transform.Rotation.normalize();
|
self.Transform.Rotation = self.Transform.Rotation.normalize();
|
||||||
}
|
}
|
||||||
pub fn forward(&mut self)
|
pub fn forward(&mut self, amount: f32)
|
||||||
{
|
{
|
||||||
let forward = self.Transform.Rotation.rotate_vector(cgmath::Vector3::unit_z());
|
let forward = self.Transform.Rotation.rotate_vector(cgmath::Vector3::unit_z());
|
||||||
let distance = forward * 0.01;
|
let distance = forward * amount;
|
||||||
self.Transform.Position += distance;
|
self.Transform.Position += distance;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue