Skip to content

Commit

Permalink
Add draw_grid_ex, and have draw_grid use that with vec3(0,0,0)
Browse files Browse the repository at this point in the history
  • Loading branch information
computermouth committed Nov 29, 2023
1 parent 6d9685d commit 3639f4e
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,45 @@ pub fn draw_line_3d(start: Vec3, end: Vec3, color: Color) {

/// Draw a grid centered at (0, 0, 0)
pub fn draw_grid(slices: u32, spacing: f32, axes_color: Color, other_color: Color) {
draw_grid_ex(slices, spacing, axes_color, other_color, vec3(0., 0., 0.));
}

/// Draw a grid centered at an offset
pub fn draw_grid_ex(
slices: u32,
spacing: f32,
axes_color: Color,
other_color: Color,
offset: Vec3,
) {
let half_slices = (slices as i32) / 2;
for i in -half_slices..half_slices + 1 {
let color = if i == 0 { axes_color } else { other_color };

draw_line_3d(
vec3(i as f32 * spacing, 0., -half_slices as f32 * spacing),
vec3(i as f32 * spacing, 0., half_slices as f32 * spacing),
vec3(
i as f32 * spacing + offset.x,
0. + offset.y,
-half_slices as f32 * spacing + offset.z,
),
vec3(
i as f32 * spacing + offset.x,
0. + offset.y,
half_slices as f32 * spacing + offset.z,
),
color,
);
draw_line_3d(
vec3(-half_slices as f32 * spacing, 0., i as f32 * spacing),
vec3(half_slices as f32 * spacing, 0., i as f32 * spacing),
vec3(
-half_slices as f32 * spacing + offset.x,
0. + offset.y,
i as f32 * spacing + offset.z,
),
vec3(
half_slices as f32 * spacing + offset.x,
0. + offset.y,
i as f32 * spacing + offset.z,
),
color,
);
}
Expand Down

0 comments on commit 3639f4e

Please sign in to comment.