| 2866 | |
| 2867 | #[no_mangle] |
| 2868 | pub extern "C" fn bloom_project_to_screen(wx: f64, wy: f64, wz: f64) -> f64 { |
| 2869 | let eng = engine(); |
| 2870 | let vp = eng.renderer.vp_matrix(); |
| 2871 | let w = eng.renderer.width() as f32; |
| 2872 | let h = eng.renderer.height() as f32; |
| 2873 | |
| 2874 | // Multiply by VP matrix |
| 2875 | let x = wx as f32; |
| 2876 | let y = wy as f32; |
| 2877 | let z = wz as f32; |
| 2878 | let clip_x = vp[0][0]*x + vp[1][0]*y + vp[2][0]*z + vp[3][0]; |
| 2879 | let clip_y = vp[0][1]*x + vp[1][1]*y + vp[2][1]*z + vp[3][1]; |
| 2880 | let clip_w = vp[0][3]*x + vp[1][3]*y + vp[2][3]*z + vp[3][3]; |
| 2881 | |
| 2882 | if clip_w <= 0.0 { |
| 2883 | unsafe { LAST_PROJECT = (-9999.0, -9999.0); } |
| 2884 | return -9999.0; |
| 2885 | } |
| 2886 | |
| 2887 | // NDC to screen |
| 2888 | let ndc_x = clip_x / clip_w; |
| 2889 | let ndc_y = clip_y / clip_w; |
| 2890 | let screen_x = ((ndc_x + 1.0) * 0.5 * w) as f64; |
| 2891 | let screen_y = ((1.0 - ndc_y) * 0.5 * h) as f64; |
| 2892 | |
| 2893 | unsafe { LAST_PROJECT = (screen_x, screen_y); } |
| 2894 | screen_x |
| 2895 | } |
| 2896 | |
| 2897 | #[no_mangle] |
| 2898 | pub extern "C" fn bloom_project_screen_y() -> f64 { |