From 8e2bc5d35d038ce6a1d114111bf52c14674efe02 Mon Sep 17 00:00:00 2001 From: griffi-gh Date: Sat, 20 May 2023 02:48:17 +0200 Subject: [PATCH] add centered cube --- kubi/src/rendering/entities.rs | 7 ++-- kubi/src/rendering/primitives/cube.rs | 49 +++++++++++++++++++++------ 2 files changed, 42 insertions(+), 14 deletions(-) diff --git a/kubi/src/rendering/entities.rs b/kubi/src/rendering/entities.rs index 94075a6..0135edf 100644 --- a/kubi/src/rendering/entities.rs +++ b/kubi/src/rendering/entities.rs @@ -4,18 +4,17 @@ use kubi_shared::{entity::Entity, transform::Transform}; use crate::{ prefabs::ColoredShaderPrefab, camera::Camera, - settings::GameSettings, - player::MainPlayer + settings::GameSettings }; use super::{ RenderTarget, - primitives::cube::CubePrimitive + primitives::cube::CenteredCubePrimitive }; // TODO: entity models pub fn render_entities( mut target: NonSendSync>, - buffers: NonSendSync>, + buffers: NonSendSync>, program: NonSendSync>, camera: View, settings: UniqueView, diff --git a/kubi/src/rendering/primitives/cube.rs b/kubi/src/rendering/primitives/cube.rs index cee8f02..297dcb1 100644 --- a/kubi/src/rendering/primitives/cube.rs +++ b/kubi/src/rendering/primitives/cube.rs @@ -6,6 +6,21 @@ use super::PositionOnlyVertex; #[derive(Unique)] pub struct CubePrimitive(pub VertexBuffer, pub IndexBuffer); +#[derive(Unique)] +pub struct CenteredCubePrimitive(pub VertexBuffer, pub IndexBuffer); + +const CENTERED_CUBE_VERTICES: &[PositionOnlyVertex] = &[ + // front + PositionOnlyVertex { position: [-0.5, -0.5, 0.5] }, + PositionOnlyVertex { position: [ 0.5, -0.5, 0.5] }, + PositionOnlyVertex { position: [ 0.5, 0.5, 0.5] }, + PositionOnlyVertex { position: [-0.5, 0.5, 0.5] }, + // back + PositionOnlyVertex { position: [-0.5, -0.5, -0.5] }, + PositionOnlyVertex { position: [ 0.5, -0.5, -0.5] }, + PositionOnlyVertex { position: [ 0.5, 0.5, -0.5] }, + PositionOnlyVertex { position: [-0.5, 0.5, -0.5] }, +]; const CUBE_VERTICES: &[PositionOnlyVertex] = &[ // front PositionOnlyVertex { position: [0.0, 0.0, 1.0] }, @@ -43,14 +58,28 @@ pub(super) fn init_cube_primitive( storages: AllStoragesView, display: NonSendSync> ) { - let vert = VertexBuffer::new( - &display.display, - CUBE_VERTICES - ).unwrap(); - let index = IndexBuffer::new( - &display.display, - PrimitiveType::TrianglesList, - CUBE_INDICES - ).unwrap(); - storages.add_unique_non_send_sync(CubePrimitive(vert, index)); + { + let vert = VertexBuffer::new( + &display.display, + CUBE_VERTICES + ).unwrap(); + let index = IndexBuffer::new( + &display.display, + PrimitiveType::TrianglesList, + CUBE_INDICES + ).unwrap(); + storages.add_unique_non_send_sync(CubePrimitive(vert, index)); + } + { + let vert = VertexBuffer::new( + &display.display, + CENTERED_CUBE_VERTICES + ).unwrap(); + let index = IndexBuffer::new( + &display.display, + PrimitiveType::TrianglesList, + CUBE_INDICES + ).unwrap(); + storages.add_unique_non_send_sync(CenteredCubePrimitive(vert, index)); + } }