mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-11-10 01:28:41 -06:00
camera
This commit is contained in:
parent
f076172fb8
commit
3fb2194ca6
|
@ -41,14 +41,13 @@ pub fn run() {
|
||||||
let assets = Assets::load_all_sync(&display);
|
let assets = Assets::load_all_sync(&display);
|
||||||
log::info!("init game state");
|
log::info!("init game state");
|
||||||
let mut state = State::init();
|
let mut state = State::init();
|
||||||
state.camera.position = [0., 0., 1.];
|
state.camera.position = [0., 0., -1.];
|
||||||
state.camera.direction = [0., 0., -1.];
|
|
||||||
log::info!("game loaded");
|
log::info!("game loaded");
|
||||||
|
|
||||||
//=======================
|
//=======================
|
||||||
let vertex1 = ChunkVertex { position: [-0.5, -0.5, 0.], uv: [0., 0.], normal: [0., 1., 0.] };
|
let vertex1 = ChunkVertex { position: [-0.5, -0.5, 0.], uv: [0., 0.], normal: [0., 1., 0.] };
|
||||||
let vertex2 = ChunkVertex { position: [ 0.0, 0.5, 0.], uv: [0., 1.], normal: [0., 1., 0.] };
|
let vertex2 = ChunkVertex { position: [ 0.0, 0.5, 0.], uv: [0., 1.], normal: [0., 1., 0.] };
|
||||||
let vertex3 = ChunkVertex { position: [ 0.5, -0.25, 0.], uv: [1., 1.], normal: [0., 1., 0.] };
|
let vertex3 = ChunkVertex { position: [ 0.5, -0.5, 0.], uv: [1., 1.], normal: [0., 1., 0.] };
|
||||||
let shape = vec![vertex1, vertex2, vertex3];
|
let shape = vec![vertex1, vertex2, vertex3];
|
||||||
let vertex_buffer = glium::VertexBuffer::new(&display, &shape).unwrap();
|
let vertex_buffer = glium::VertexBuffer::new(&display, &shape).unwrap();
|
||||||
//=======================
|
//=======================
|
||||||
|
@ -89,9 +88,7 @@ pub fn run() {
|
||||||
let dt = (now - last_render).as_secs_f32();
|
let dt = (now - last_render).as_secs_f32();
|
||||||
last_render = now;
|
last_render = now;
|
||||||
|
|
||||||
let actions = state.controls.calculate(dt);
|
state.controls.calculate(dt).apply_to_camera(&mut state.camera);
|
||||||
log::trace!("{}", actions.rotation[0]);
|
|
||||||
actions.apply_to_camera(&mut state.camera);
|
|
||||||
|
|
||||||
let mut target = display.draw();
|
let mut target = display.draw();
|
||||||
let target_dimensions = target.get_dimensions();
|
let target_dimensions = target.get_dimensions();
|
||||||
|
|
|
@ -17,9 +17,9 @@ pub struct Actions {
|
||||||
impl Actions {
|
impl Actions {
|
||||||
pub fn apply_to_camera(&self, camera: &mut Camera) {
|
pub fn apply_to_camera(&self, camera: &mut Camera) {
|
||||||
//Apply movement
|
//Apply movement
|
||||||
for v in camera.position.iter_mut().zip(self.movement) {
|
camera.position[0] += self.movement[0];
|
||||||
*v.0 -= v.1;
|
camera.position[1] += self.movement[1];
|
||||||
}
|
camera.position[2] += self.movement[2];
|
||||||
//Apply rotation
|
//Apply rotation
|
||||||
camera.yaw -= self.rotation[0];
|
camera.yaw -= self.rotation[0];
|
||||||
camera.pitch -= self.rotation[1];
|
camera.pitch -= self.rotation[1];
|
||||||
|
@ -33,6 +33,12 @@ pub struct Controls {
|
||||||
pub sensitivity: f32,
|
pub sensitivity: f32,
|
||||||
}
|
}
|
||||||
impl Controls {
|
impl Controls {
|
||||||
|
pub fn lock(&mut self) {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
pub fn unlock(&mut self) {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
pub fn process_mouse_input(&mut self, dx: f64, dy: f64) {
|
pub fn process_mouse_input(&mut self, dx: f64, dy: f64) {
|
||||||
self.inputs.look_h += dx as f32;
|
self.inputs.look_h += dx as f32;
|
||||||
self.inputs.look_v += dy as f32;
|
self.inputs.look_v += dy as f32;
|
||||||
|
|
Loading…
Reference in a new issue