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::{
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<UniqueViewMut<RenderTarget>>,
buffers: NonSendSync<UniqueView<CubePrimitive>>,
buffers: NonSendSync<UniqueView<CenteredCubePrimitive>>,
program: NonSendSync<UniqueView<ColoredShaderPrefab>>,
camera: View<Camera>,
settings: UniqueView<GameSettings>,

View file

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