(
&mut self, bind_group_idx: u32,
src_x: f64, src_y: f64, src_w: f64, src_h: f64,
dst_x: f64, dst_y: f64, dst_w: f64, dst_h: f64,
origin_x: f64, origin_y: f64, rotation
| 12002 | } |
| 12003 | |
| 12004 | pub fn draw_texture_pro( |
| 12005 | &mut self, bind_group_idx: u32, |
| 12006 | src_x: f64, src_y: f64, src_w: f64, src_h: f64, |
| 12007 | dst_x: f64, dst_y: f64, dst_w: f64, dst_h: f64, |
| 12008 | origin_x: f64, origin_y: f64, rotation: f64, |
| 12009 | tint_r: f64, tint_g: f64, tint_b: f64, tint_a: f64, |
| 12010 | ) { |
| 12011 | let (tw, th) = self.texture_sizes.get(bind_group_idx as usize).copied().unwrap_or((0, 0)); |
| 12012 | if tw == 0 { return; } |
| 12013 | let color = Self::color_to_f32(tint_r, tint_g, tint_b, tint_a); |
| 12014 | let u0 = src_x as f32 / tw as f32; |
| 12015 | let v0 = src_y as f32 / th as f32; |
| 12016 | let u1 = (src_x + src_w) as f32 / tw as f32; |
| 12017 | let v1 = (src_y + src_h) as f32 / th as f32; |
| 12018 | |
| 12019 | let cos_r = (rotation as f32).to_radians().cos(); |
| 12020 | let sin_r = (rotation as f32).to_radians().sin(); |
| 12021 | let ox = origin_x as f32; |
| 12022 | let oy = origin_y as f32; |
| 12023 | let (dx, dy, dw, dh) = (dst_x as f32, dst_y as f32, dst_w as f32, dst_h as f32); |
| 12024 | |
| 12025 | let corners = [ |
| 12026 | [dx - ox, dy - oy], |
| 12027 | [dx + dw - ox, dy - oy], |
| 12028 | [dx + dw - ox, dy + dh - oy], |
| 12029 | [dx - ox, dy + dh - oy], |
| 12030 | ]; |
| 12031 | |
| 12032 | self.ensure_draw_state(bind_group_idx); |
| 12033 | let base = self.vertices_2d.len() as u32; |
| 12034 | let uvs = [[u0, v0], [u1, v0], [u1, v1], [u0, v1]]; |
| 12035 | for (c, uv) in corners.iter().zip(uvs.iter()) { |
| 12036 | let rx = c[0] * cos_r - c[1] * sin_r + ox; |
| 12037 | let ry = c[0] * sin_r + c[1] * cos_r + oy; |
| 12038 | self.vertices_2d.push(Vertex2D { position: [rx, ry], uv: *uv, color }); |
| 12039 | } |
| 12040 | self.indices_2d.extend_from_slice(&[base, base + 1, base + 2, base, base + 2, base + 3]); |
| 12041 | } |
| 12042 | |
| 12043 | // ============================================================ |
| 12044 | // Camera 2D |
no test coverage detected