MCPcopy Create free account
hub / github.com/Bloom-Engine/engine / draw_cylinder

Method draw_cylinder

native/shared/src/renderer/mod.rs:12629–12664  ·  view source on GitHub ↗
(&mut self, x: f64, y: f64, z: f64, radius_top: f64, radius_bottom: f64, height: f64, r: f64, g: f64, b: f64, a: f64)

Source from the content-addressed store, hash-verified

12627 }
12628
12629 pub fn draw_cylinder(&mut self, x: f64, y: f64, z: f64, radius_top: f64, radius_bottom: f64, height: f64, r: f64, g: f64, b: f64, a: f64) {
12630 self.ensure_draw_state_3d(self.current_texture_3d);
12631 let color = Self::color_to_f32(r, g, b, a);
12632 let (x, y, z) = (x as f32, y as f32, z as f32);
12633 let (rt, rb, h) = (radius_top as f32, radius_bottom as f32, height as f32);
12634 let slices = 16u32;
12635
12636 for i in 0..slices {
12637 let a1 = (i as f32) / (slices as f32) * std::f32::consts::TAU;
12638 let a2 = ((i + 1) as f32) / (slices as f32) * std::f32::consts::TAU;
12639 let (c1, s1) = (a1.cos(), a1.sin());
12640 let (c2, s2) = (a2.cos(), a2.sin());
12641
12642 // Side face
12643 let base = self.vertices_3d.len() as u32;
12644 self.vertices_3d.push(Vertex3D { position: [x + rb*c1, y, z + rb*s1], normal: [c1, 0.0, s1], color, uv: [0.0, 0.0], joints: [0.0; 4], weights: [0.0; 4], tangent: [0.0; 4] });
12645 self.vertices_3d.push(Vertex3D { position: [x + rb*c2, y, z + rb*s2], normal: [c2, 0.0, s2], color, uv: [0.0, 0.0], joints: [0.0; 4], weights: [0.0; 4], tangent: [0.0; 4] });
12646 self.vertices_3d.push(Vertex3D { position: [x + rt*c2, y+h, z + rt*s2], normal: [c2, 0.0, s2], color, uv: [0.0, 0.0], joints: [0.0; 4], weights: [0.0; 4], tangent: [0.0; 4] });
12647 self.vertices_3d.push(Vertex3D { position: [x + rt*c1, y+h, z + rt*s1], normal: [c1, 0.0, s1], color, uv: [0.0, 0.0], joints: [0.0; 4], weights: [0.0; 4], tangent: [0.0; 4] });
12648 self.indices_3d.extend_from_slice(&[base, base+1, base+2, base, base+2, base+3]);
12649
12650 // Top cap
12651 let base = self.vertices_3d.len() as u32;
12652 self.vertices_3d.push(Vertex3D { position: [x, y+h, z], normal: [0.0, 1.0, 0.0], color, uv: [0.0, 0.0], joints: [0.0; 4], weights: [0.0; 4], tangent: [0.0; 4] });
12653 self.vertices_3d.push(Vertex3D { position: [x+rt*c1, y+h, z+rt*s1], normal: [0.0, 1.0, 0.0], color, uv: [0.0, 0.0], joints: [0.0; 4], weights: [0.0; 4], tangent: [0.0; 4] });
12654 self.vertices_3d.push(Vertex3D { position: [x+rt*c2, y+h, z+rt*s2], normal: [0.0, 1.0, 0.0], color, uv: [0.0, 0.0], joints: [0.0; 4], weights: [0.0; 4], tangent: [0.0; 4] });
12655 self.indices_3d.extend_from_slice(&[base, base+1, base+2]);
12656
12657 // Bottom cap
12658 let base = self.vertices_3d.len() as u32;
12659 self.vertices_3d.push(Vertex3D { position: [x, y, z], normal: [0.0, -1.0, 0.0], color, uv: [0.0, 0.0], joints: [0.0; 4], weights: [0.0; 4], tangent: [0.0; 4] });
12660 self.vertices_3d.push(Vertex3D { position: [x+rb*c2, y, z+rb*s2], normal: [0.0, -1.0, 0.0], color, uv: [0.0, 0.0], joints: [0.0; 4], weights: [0.0; 4], tangent: [0.0; 4] });
12661 self.vertices_3d.push(Vertex3D { position: [x+rb*c1, y, z+rb*s1], normal: [0.0, -1.0, 0.0], color, uv: [0.0, 0.0], joints: [0.0; 4], weights: [0.0; 4], tangent: [0.0; 4] });
12662 self.indices_3d.extend_from_slice(&[base, base+1, base+2]);
12663 }
12664 }
12665
12666 pub fn draw_plane(&mut self, cx: f64, cy: f64, cz: f64, w: f64, d: f64, r: f64, g: f64, b: f64, a: f64) {
12667 self.ensure_draw_state_3d(self.current_texture_3d);

Callers 7

bloom_draw_cylinderFunction · 0.80
bloom_draw_cylinderFunction · 0.80
bloom_draw_cylinderFunction · 0.80
bloom_draw_cylinderFunction · 0.80
bloom_draw_cylinderFunction · 0.80
bloom_draw_cylinderFunction · 0.80
bloom_draw_cylinderFunction · 0.80

Calls 2

ensure_draw_state_3dMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected