add centered cube

This commit is contained in:
griffi-gh 2023-05-20 02:48:17 +02:00
parent 78689bbe1c
commit 8e2bc5d35d
2 changed files with 42 additions and 14 deletions

View file

@ -4,18 +4,17 @@ use kubi_shared::{entity::Entity, transform::Transform};
use crate::{ use crate::{
prefabs::ColoredShaderPrefab, prefabs::ColoredShaderPrefab,
camera::Camera, camera::Camera,
settings::GameSettings, settings::GameSettings
player::MainPlayer
}; };
use super::{ use super::{
RenderTarget, RenderTarget,
primitives::cube::CubePrimitive primitives::cube::CenteredCubePrimitive
}; };
// TODO: entity models // TODO: entity models
pub fn render_entities( pub fn render_entities(
mut target: NonSendSync<UniqueViewMut<RenderTarget>>, mut target: NonSendSync<UniqueViewMut<RenderTarget>>,
buffers: NonSendSync<UniqueView<CubePrimitive>>, buffers: NonSendSync<UniqueView<CenteredCubePrimitive>>,
program: NonSendSync<UniqueView<ColoredShaderPrefab>>, program: NonSendSync<UniqueView<ColoredShaderPrefab>>,
camera: View<Camera>, camera: View<Camera>,
settings: UniqueView<GameSettings>, settings: UniqueView<GameSettings>,

View file

@ -6,6 +6,21 @@ use super::PositionOnlyVertex;
#[derive(Unique)] #[derive(Unique)]
pub struct CubePrimitive(pub VertexBuffer<PositionOnlyVertex>, pub IndexBuffer<u16>); pub struct CubePrimitive(pub VertexBuffer<PositionOnlyVertex>, pub IndexBuffer<u16>);
#[derive(Unique)]
pub struct CenteredCubePrimitive(pub VertexBuffer<PositionOnlyVertex>, pub IndexBuffer<u16>);
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] = &[ const CUBE_VERTICES: &[PositionOnlyVertex] = &[
// front // front
PositionOnlyVertex { position: [0.0, 0.0, 1.0] }, PositionOnlyVertex { position: [0.0, 0.0, 1.0] },
@ -43,6 +58,7 @@ pub(super) fn init_cube_primitive(
storages: AllStoragesView, storages: AllStoragesView,
display: NonSendSync<UniqueView<Renderer>> display: NonSendSync<UniqueView<Renderer>>
) { ) {
{
let vert = VertexBuffer::new( let vert = VertexBuffer::new(
&display.display, &display.display,
CUBE_VERTICES CUBE_VERTICES
@ -54,3 +70,16 @@ pub(super) fn init_cube_primitive(
).unwrap(); ).unwrap();
storages.add_unique_non_send_sync(CubePrimitive(vert, index)); 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));
}
}