diff --git a/src/gameobject.rs b/src/gameobject.rs new file mode 100644 index 0000000..5f64487 --- /dev/null +++ b/src/gameobject.rs @@ -0,0 +1,21 @@ +use nalgebra_glm as glm; + +pub struct Transform { + pub position: glm::Vec3, + pub rotation: glm::Vec3, + pub scale: glm::Vec3, +} + +impl Default for Transform { + fn default() -> Self { + Transform { + position: glm::zero(), + rotation: glm::zero(), + scale: glm::vec3(1.0, 1.0, 1.0), + } + } +} + +pub trait Spatial { + fn get_transform() -> Transform; +} diff --git a/src/main.rs b/src/main.rs index f10b025..9486ecd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,7 @@ mod device; mod model; mod scripting; +mod gameobject; #[macro_use] extern crate glium; @@ -27,9 +28,12 @@ fn main() { let mut device_manager = crate::device::DeviceManager::new(); - let mut offset = 0.0; - let mut rotate = 0.0; + struct Cube { + t: gameobject::Transform, + } + let mut cube = Cube { t: Default::default() }; + let model = Model::new(&display, "Box.glb"); let mut script_lang = Lua::new(); @@ -56,21 +60,22 @@ fn main() { last_draw = now; if device_manager.is_pressed(&device::Key::W) { - offset += 1.0 * delta; + cube.t.position.z += 1.0 * delta; } else if device_manager.is_pressed(&device::Key::S) { - offset -= 1.0 * delta; + cube.t.position.z -= 1.0 * delta; } if device_manager.is_pressed(&device::Key::A) { - rotate += 1.0 * delta; + cube.t.rotation.x += 1.0 * delta; } else if device_manager.is_pressed(&device::Key::D) { - rotate -= 1.0 * delta; + cube.t.rotation.x -= 1.0 * delta; } script_lang.update(delta); let mvp = glm::perspective::(4.0/3.0, 45.0_f32.to_radians(), 0.2, 100.0); - let mvp = glm::translate::(&mvp, &glm::vec3(0.0, 0.0, -10.0 + offset)); - let mvp = glm::rotate::(&mvp, 15.0_f32.to_radians() + rotate, &glm::vec3(1.0, 0.0, 0.0)); + let mvp = glm::translate::(&mvp, &(glm::vec3(0.0, 0.0, -10.0) + cube.t.position)); + let mvp = glm::rotate::(&mvp, 15.0_f32.to_radians(), &glm::vec3(1.0, 0.0, 0.0)); + let mvp = glm::rotate_x(&mvp, cube.t.rotation.x); let uniforms = uniform! { MVP: *mvp.as_ref(), };