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

Method draw_sphere

native/shared/src/renderer/mod.rs:12564–12598  ·  view source on GitHub ↗
(&mut self, cx: f64, cy: f64, cz: f64, radius: f64, r: f64, g: f64, b: f64, a: f64)

Source from the content-addressed store, hash-verified

12562 }
12563
12564 pub fn draw_sphere(&mut self, cx: f64, cy: f64, cz: f64, radius: f64, r: f64, g: f64, b: f64, a: f64) {
12565 self.ensure_draw_state_3d(self.current_texture_3d);
12566 let color = Self::color_to_f32(r, g, b, a);
12567 let (cx, cy, cz, radius) = (cx as f32, cy as f32, cz as f32, radius as f32);
12568 let rings = 8u32;
12569 let slices = 8u32;
12570
12571 for i in 0..rings {
12572 let theta1 = (i as f32) / (rings as f32) * std::f32::consts::PI;
12573 let theta2 = ((i + 1) as f32) / (rings as f32) * std::f32::consts::PI;
12574 for j in 0..slices {
12575 let phi1 = (j as f32) / (slices as f32) * std::f32::consts::TAU;
12576 let phi2 = ((j + 1) as f32) / (slices as f32) * std::f32::consts::TAU;
12577
12578 let p = |theta: f32, phi: f32| -> ([f32; 3], [f32; 3]) {
12579 let nx = theta.sin() * phi.cos();
12580 let ny = theta.cos();
12581 let nz = theta.sin() * phi.sin();
12582 ([cx + radius * nx, cy + radius * ny, cz + radius * nz], [nx, ny, nz])
12583 };
12584
12585 let (p00, n00) = p(theta1, phi1);
12586 let (p10, n10) = p(theta2, phi1);
12587 let (p11, n11) = p(theta2, phi2);
12588 let (p01, n01) = p(theta1, phi2);
12589
12590 let base = self.vertices_3d.len() as u32;
12591 self.vertices_3d.push(Vertex3D { position: p00, normal: n00, color, uv: [0.0, 0.0], joints: [0.0; 4], weights: [0.0; 4], tangent: [0.0; 4] });
12592 self.vertices_3d.push(Vertex3D { position: p10, normal: n10, color, uv: [0.0, 0.0], joints: [0.0; 4], weights: [0.0; 4], tangent: [0.0; 4] });
12593 self.vertices_3d.push(Vertex3D { position: p11, normal: n11, color, uv: [0.0, 0.0], joints: [0.0; 4], weights: [0.0; 4], tangent: [0.0; 4] });
12594 self.vertices_3d.push(Vertex3D { position: p01, normal: n01, color, uv: [0.0, 0.0], joints: [0.0; 4], weights: [0.0; 4], tangent: [0.0; 4] });
12595 self.indices_3d.extend_from_slice(&[base, base+1, base+2, base, base+2, base+3]);
12596 }
12597 }
12598 }
12599
12600 pub fn draw_sphere_wires(&mut self, cx: f64, cy: f64, cz: f64, radius: f64, r: f64, g: f64, b: f64, a: f64) {
12601 let color = Self::color_to_f32(r, g, b, a);

Callers 7

bloom_draw_sphereFunction · 0.80
bloom_draw_sphereFunction · 0.80
bloom_draw_sphereFunction · 0.80
bloom_draw_sphereFunction · 0.80
bloom_draw_sphereFunction · 0.80
bloom_draw_sphereFunction · 0.80
bloom_draw_sphereFunction · 0.80

Calls 2

ensure_draw_state_3dMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected