bevy/src/vertex.rs

45 lines
1.3 KiB
Rust
Raw Normal View History

2019-12-01 01:42:27 +00:00
use zerocopy::{AsBytes, FromBytes};
2019-12-10 07:12:50 +00:00
use std::convert::From;
2019-12-01 01:42:27 +00:00
#[repr(C)]
#[derive(Clone, Copy, AsBytes, FromBytes)]
pub struct Vertex {
2019-12-10 07:12:50 +00:00
pub position: [f32; 4],
pub normal: [f32; 4],
}
impl From<([f32; 4], [f32; 4])> for Vertex {
fn from((position, normal): ([f32; 4], [f32; 4])) -> Self {
Vertex {
position: position,
normal: normal,
}
}
}
impl From<([f32; 3], [f32; 3])> for Vertex {
fn from((position, normal): ([f32; 3], [f32; 3])) -> Self {
Vertex {
position: [position[0] as f32, position[1] as f32, position[2] as f32, 1.0],
normal: [normal[0] as f32, normal[1] as f32, normal[2] as f32, 0.0],
}
}
}
impl From<([i8; 4], [i8; 4])> for Vertex {
fn from((position, normal): ([i8; 4], [i8; 4])) -> Self {
Vertex {
position: [position[0] as f32, position[1] as f32, position[2] as f32, position[3] as f32],
normal: [normal[0] as f32, normal[1] as f32, normal[2] as f32, normal[3] as f32],
}
}
}
impl From<([i8; 3], [i8; 3])> for Vertex {
fn from((position, normal): ([i8; 3], [i8; 3])) -> Self {
Vertex {
position: [position[0] as f32, position[1] as f32, position[2] as f32, 1.0],
normal: [normal[0] as f32, normal[1] as f32, normal[2] as f32, 0.0],
}
}
2019-12-01 01:42:27 +00:00
}