mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-12-26 21:58:20 -06:00
add centered cube
This commit is contained in:
parent
78689bbe1c
commit
8e2bc5d35d
|
@ -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>,
|
||||||
|
|
|
@ -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
|
||||||
|
@ -53,4 +69,17 @@ pub(super) fn init_cube_primitive(
|
||||||
CUBE_INDICES
|
CUBE_INDICES
|
||||||
).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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue