add centered cube

This commit is contained in:
griffi-gh 2023-05-20 02:48:17 +02:00
parent 75c6d127b7
commit 14c66ee2eb
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,14 +58,28 @@ pub(super) fn init_cube_primitive(
storages: AllStoragesView, storages: AllStoragesView,
display: NonSendSync<UniqueView<Renderer>> display: NonSendSync<UniqueView<Renderer>>
) { ) {
let vert = VertexBuffer::new( {
&display.display, let vert = VertexBuffer::new(
CUBE_VERTICES &display.display,
).unwrap(); CUBE_VERTICES
let index = IndexBuffer::new( ).unwrap();
&display.display, let index = IndexBuffer::new(
PrimitiveType::TrianglesList, &display.display,
CUBE_INDICES PrimitiveType::TrianglesList,
).unwrap(); CUBE_INDICES
storages.add_unique_non_send_sync(CubePrimitive(vert, index)); ).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));
}
} }