Select stuff (hit detection is still off)

This commit is contained in:
2021-03-19 02:43:28 +01:00
parent 02f39453ac
commit ff80f7b9aa
8 changed files with 43 additions and 14 deletions

View File

@@ -6,6 +6,8 @@ use crate::input::InputState;
use crate::vulkan::{RendererDescriptorSets, TextureHandle};
use crate::vulkan::{MeshHandle, VulkanRenderer};
use super::pipelines::vs;
#[derive(Clone)]
pub struct GameObject {
pub mesh_index: usize,
@@ -15,14 +17,15 @@ pub struct GameObject {
pub rotation: Quaternion<f32>,
pub scale: Vector3<f32>,
pub children: Vec<GameObject>,
pub descriptor_sets: Vec<Arc<RendererDescriptorSets>>
pub descriptor_sets: Vec<Arc<RendererDescriptorSets>>,
pub is_selected: bool
}
impl GameObject {
pub fn new(mesh: MeshHandle) -> GameObject {
GameObject { mesh_index: mesh.index, texture_index: mesh.diffuse_handle, normal_map_index: mesh.normal_handle, position: Vector3::new(0.0, 0.0, 0.0),
rotation: Quaternion::new(1.0, 0.0, 0.0, 0.0), scale: Vector3::new(1.0, 1.0, 1.0), children: vec![],
descriptor_sets: vec![] }
descriptor_sets: vec![], is_selected: false }
}
pub fn _set_position(&mut self, x: f32, y: f32, z: f32) {
@@ -51,6 +54,13 @@ impl GameObject {
self.rotation = self.rotation * Quaternion::from(Euler::new(Deg(x), Deg(y), Deg(z)));
}
pub fn get_push_constants(&self) -> vs::ty::PushConstants {
vs::ty::PushConstants {
model: self.get_model_matrix().into(),
is_selected: if self.is_selected { 0 } else { 1 },
}
}
pub fn get_model_matrix(&self) -> Matrix4<f32> {
let translation = Matrix4::from_translation(self.position);
let rotation: Matrix4<f32> = self.rotation.into();