(&mut self, start: [f32; 3], end: [f32; 3], color: [f32; 4], thickness: f32)
| 12489 | // ============================================================ |
| 12490 | |
| 12491 | fn add_line_3d(&mut self, start: [f32; 3], end: [f32; 3], color: [f32; 4], thickness: f32) { |
| 12492 | let dx = end[0] - start[0]; |
| 12493 | let dy = end[1] - start[1]; |
| 12494 | let dz = end[2] - start[2]; |
| 12495 | let len = (dx*dx + dy*dy + dz*dz).sqrt(); |
| 12496 | if len < 0.0001 { return; } |
| 12497 | let (dx, dy, dz) = (dx/len, dy/len, dz/len); |
| 12498 | |
| 12499 | // Find perpendicular using cross product with best reference axis |
| 12500 | let (px, py, pz) = if dy.abs() > 0.9 { |
| 12501 | // Cross with X axis: (0, dz, -dy) |
| 12502 | (0.0, dz, -dy) |
| 12503 | } else { |
| 12504 | // Cross with Y axis: (-dz, 0, dx) |
| 12505 | (-dz, 0.0, dx) |
| 12506 | }; |
| 12507 | let plen = (px*px + py*py + pz*pz).sqrt(); |
| 12508 | let ht = thickness * 0.5; |
| 12509 | let (px, py, pz) = (px/plen * ht, py/plen * ht, pz/plen * ht); |
| 12510 | let normal = [px/ht, py/ht, pz/ht]; |
| 12511 | |
| 12512 | let base = self.vertices_3d.len() as u32; |
| 12513 | self.vertices_3d.push(Vertex3D { position: [start[0]+px, start[1]+py, start[2]+pz], normal, color, uv: [0.0, 0.0], joints: [0.0; 4], weights: [0.0; 4], tangent: [0.0; 4] }); |
| 12514 | self.vertices_3d.push(Vertex3D { position: [start[0]-px, start[1]-py, start[2]-pz], normal, color, uv: [0.0, 0.0], joints: [0.0; 4], weights: [0.0; 4], tangent: [0.0; 4] }); |
| 12515 | self.vertices_3d.push(Vertex3D { position: [end[0]-px, end[1]-py, end[2]-pz], normal, color, uv: [0.0, 0.0], joints: [0.0; 4], weights: [0.0; 4], tangent: [0.0; 4] }); |
| 12516 | self.vertices_3d.push(Vertex3D { position: [end[0]+px, end[1]+py, end[2]+pz], normal, color, uv: [0.0, 0.0], joints: [0.0; 4], weights: [0.0; 4], tangent: [0.0; 4] }); |
| 12517 | self.indices_3d.extend_from_slice(&[base, base+1, base+2, base, base+2, base+3]); |
| 12518 | } |
| 12519 | |
| 12520 | pub fn draw_cube(&mut self, x: f64, y: f64, z: f64, w: f64, h: f64, d: f64, r: f64, g: f64, b: f64, a: f64) { |
| 12521 | self.ensure_draw_state_3d(self.current_texture_3d); |
no test coverage detected