Fix cube faces
This commit is contained in:
parent
fe9099aac9
commit
45c0a31cb3
1 changed files with 45 additions and 12 deletions
|
@ -1,22 +1,49 @@
|
|||
use engine::prelude::{cgmath::*, *};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct CubeCorners(pub [PositionOnly; 8]);
|
||||
|
||||
impl CubeCorners {
|
||||
#[rustfmt::skip]
|
||||
pub fn new(offset: Vector3<f32>, extent: Vector3<f32>) -> Self {
|
||||
Self([
|
||||
// 0 - left bottom front
|
||||
PositionOnly::new(vec3(offset.x, offset.y, offset.z)),
|
||||
PositionOnly::new(vec3(
|
||||
offset.x,
|
||||
offset.y,
|
||||
offset.z
|
||||
)),
|
||||
// 1 - right bottom front
|
||||
PositionOnly::new(vec3(offset.x + extent.x, offset.y, offset.z)),
|
||||
PositionOnly::new(vec3(
|
||||
offset.x + extent.x,
|
||||
offset.y,
|
||||
offset.z
|
||||
)),
|
||||
// 2 - right top front
|
||||
PositionOnly::new(vec3(offset.x + extent.x, offset.y + extent.y, offset.z)),
|
||||
PositionOnly::new(vec3(
|
||||
offset.x + extent.x,
|
||||
offset.y + extent.y,
|
||||
offset.z
|
||||
)),
|
||||
// 3 - left top front
|
||||
PositionOnly::new(vec3(offset.x, offset.y + extent.y, offset.z)),
|
||||
PositionOnly::new(vec3(
|
||||
offset.x,
|
||||
offset.y + extent.y,
|
||||
offset.z
|
||||
)),
|
||||
|
||||
// 4 - left bottom back
|
||||
PositionOnly::new(vec3(offset.x, offset.y, offset.z + extent.z)),
|
||||
PositionOnly::new(vec3(
|
||||
offset.x,
|
||||
offset.y,
|
||||
offset.z + extent.z
|
||||
)),
|
||||
// 5 - right bottom back
|
||||
PositionOnly::new(vec3(offset.x + extent.x, offset.y, offset.z + extent.z)),
|
||||
PositionOnly::new(vec3(
|
||||
offset.x + extent.x,
|
||||
offset.y,
|
||||
offset.z + extent.z
|
||||
)),
|
||||
// 6 - right top back
|
||||
PositionOnly::new(vec3(
|
||||
offset.x + extent.x,
|
||||
|
@ -24,11 +51,16 @@ impl CubeCorners {
|
|||
offset.z + extent.z,
|
||||
)),
|
||||
// 7 - left top back
|
||||
PositionOnly::new(vec3(offset.x, offset.y + extent.y, offset.z + extent.z)),
|
||||
PositionOnly::new(vec3(
|
||||
offset.x,
|
||||
offset.y + extent.y,
|
||||
offset.z + extent.z
|
||||
)),
|
||||
])
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Plane([PositionOnly; 4]);
|
||||
|
||||
impl Plane {
|
||||
|
@ -45,9 +77,10 @@ impl<'a> From<(&'a CubeCorners, usize, usize, usize, usize)> for Plane {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Cube {
|
||||
pub left: Plane,
|
||||
pub right: Plane,
|
||||
pub left: Plane,
|
||||
pub front: Plane,
|
||||
pub back: Plane,
|
||||
pub top: Plane,
|
||||
|
@ -57,9 +90,9 @@ pub struct Cube {
|
|||
impl Cube {
|
||||
pub fn triangulate(self) -> [PositionOnly; 36] {
|
||||
[
|
||||
self.front.triangulate(),
|
||||
self.left.triangulate(),
|
||||
self.right.triangulate(),
|
||||
self.left.triangulate(),
|
||||
self.front.triangulate(),
|
||||
self.back.triangulate(),
|
||||
self.top.triangulate(),
|
||||
self.bottom.triangulate(),
|
||||
|
@ -73,8 +106,8 @@ impl Cube {
|
|||
impl From<CubeCorners> for Cube {
|
||||
fn from(corners: CubeCorners) -> Self {
|
||||
Self {
|
||||
left: Plane::from((&corners, 0, 3, 4, 7)),
|
||||
right: Plane::from((&corners, 2, 1, 6, 5)),
|
||||
right: Plane::from((&corners, 1, 2, 6, 5)),
|
||||
left: Plane::from((&corners, 3, 0, 4, 7)),
|
||||
front: Plane::from((&corners, 0, 1, 2, 3)),
|
||||
back: Plane::from((&corners, 5, 4, 7, 6)),
|
||||
top: Plane::from((&corners, 3, 2, 6, 7)),
|
||||
|
|
Loading…
Reference in a new issue