Skip to content

Commit

Permalink
Add rectangle as a primitive shape
Browse files Browse the repository at this point in the history
  • Loading branch information
Gipson62 committed Aug 25, 2023
1 parent 51e1681 commit d24a865
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/primitive_shapes/two_dimensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,37 @@ pub fn square(

Ok(())
}

/// Create a 2D rectangle based on a width and height
pub fn rectangle(width: f32, height: f32, name: impl StringBuffer, settings: ObjectSettings, renderer: &mut Renderer, objects: &mut ObjectStorage) -> anyhow::Result<()> {
objects.new_object(
name.clone(),
vec![
Vertex {
position: [width/2.0, height/2.0, 0.0],
uv: [1.0, 0.0],
normal: [0f32, 0f32, 0f32],
},
Vertex {
position: [width/2.0, -height/2.0, 0.0],
uv: [1.0, 1.0],
normal: [0f32, 0f32, 0f32],
},
Vertex {
position: [-width/2.0, -height/2.0, 0.0],
uv: [0.0, 1.0],
normal: [0f32, 0f32, 0f32],
},
Vertex {
position: [-width/2.0, height/2.0, 0.0],
uv: [0.0, 0.0],
normal: [0f32, 0f32, 0f32],
},
],
vec![2, 1, 0, 2, 0, 3],
settings,
renderer
)?;

Ok(())
}

0 comments on commit d24a865

Please sign in to comment.