mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-11-21 22:38:41 -06:00
add centered cube
This commit is contained in:
parent
75c6d127b7
commit
14c66ee2eb
|
@ -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>,
|
||||
|
|
|
@ -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
|
||||
|
@ -53,4 +69,17 @@ pub(super) fn init_cube_primitive(
|
|||
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));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue