Adding transforms and spatials
This commit is contained in:
parent
99f100c812
commit
6a33b25d81
21
src/gameobject.rs
Normal file
21
src/gameobject.rs
Normal file
@ -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;
|
||||
}
|
21
src/main.rs
21
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::<f32>(4.0/3.0, 45.0_f32.to_radians(), 0.2, 100.0);
|
||||
let mvp = glm::translate::<f32>(&mvp, &glm::vec3(0.0, 0.0, -10.0 + offset));
|
||||
let mvp = glm::rotate::<f32>(&mvp, 15.0_f32.to_radians() + rotate, &glm::vec3(1.0, 0.0, 0.0));
|
||||
let mvp = glm::translate::<f32>(&mvp, &(glm::vec3(0.0, 0.0, -10.0) + cube.t.position));
|
||||
let mvp = glm::rotate::<f32>(&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(),
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user