Skip to content

Instantly share code, notes, and snippets.

@isXander
Created February 13, 2024 13:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isXander/929db41de73f40494cedb6b7a8d7fb60 to your computer and use it in GitHub Desktop.
Save isXander/929db41de73f40494cedb6b7a8d7fb60 to your computer and use it in GitHub Desktop.
fn create_face(
x: f32, y: f32, z: f32,
face: Face,
) -> Vec<engine::model::ModelVertex> {
let mut vertices = Vec::new();
println!("Creating face: {:?}", face);
let (x_axis, y_axis, z_axis, x_off, y_off, z_off, norm_x, norm_y, norm_z) = match face {
Face::Top => (1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0),
Face::Bottom => (1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0),
Face::North => (1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, -1.0),
Face::South => (1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0),
Face::East => (0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0),
Face::West => (0.0, 0.0, 1.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0),
};
let top_left = (x + x_off, y + y_off, z + z_off, 0.0, 0.0);
let top_right = (x + x_off + x_axis, y + y_off, z + z_off, 0.0, 1.0);
let bottom_left = (x + x_off, y + y_off + y_axis, z + z_off + z_axis, 1.0, 0.0);
let bottom_right = (x + x_off + x_axis, y + y_off + y_axis, z + z_off + z_axis, 1.0, 1.0);
let vertices_data = [
top_left, bottom_left, bottom_right,
top_left, bottom_right, top_right,
];
for (x, y, z, u, v) in vertices_data.iter() {
vertices.push(engine::model::ModelVertex {
position: [*x, *y, *z],
normal: [norm_x, norm_y, norm_z],
tex_coords: [*u, *v],
bitangent: [0.0, 0.0, 0.0],
tangent: [0.0, 0.0, 0.0],
});
}
vertices
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment