use cgmath::{Matrix4, SquareMatrix, Vector3, vec3}; use crate::vulkan::{MeshHandle, VulkanRenderer}; use crate::input::InputState; pub struct GameObject { pub mesh_index: usize, pub texture_index: usize, pub model_matrix: Matrix4, } impl GameObject { pub fn new(mesh: MeshHandle, texture_index: usize) -> GameObject { GameObject { mesh_index: mesh, texture_index, model_matrix: Matrix4::identity() } } pub fn set_position(&mut self, pos: (f32, f32, f32)) { self.model_matrix.w.x = pos.0; self.model_matrix.w.y = pos.1; self.model_matrix.w.z = pos.2; } pub fn get_position(&self) -> Vector3 { vec3(self.model_matrix.w.x, self.model_matrix.w.y, self.model_matrix.w.z) } pub fn translate(&mut self, x: f32, y: f32, z: f32) { self.model_matrix.w.x += x; self.model_matrix.w.y += y; self.model_matrix.w.z += z; } pub fn update(&mut self, delta_time: f32, input: &InputState) { if input.button_down("test") { self.translate(delta_time as f32, 0.0, 0.0); } } } pub struct GameObjectHandle { pub object_index: usize } impl GameObjectHandle { pub fn get_game_object<'a>(&mut self, renderer: &'a mut VulkanRenderer) -> Option<&'a mut GameObject> { renderer.game_data.game_objects.get_mut(self.object_index) } }