| 1985 | |
| 1986 | #[no_mangle] |
| 1987 | pub extern "C" fn bloom_project_to_screen(wx: f64, wy: f64, wz: f64) -> f64 { |
| 1988 | let eng = engine(); |
| 1989 | let vp = eng.renderer.vp_matrix(); |
| 1990 | let w = eng.renderer.width() as f32; |
| 1991 | let h = eng.renderer.height() as f32; |
| 1992 | |
| 1993 | let x = wx as f32; |
| 1994 | let y = wy as f32; |
| 1995 | let z = wz as f32; |
| 1996 | let clip_x = vp[0][0]*x + vp[1][0]*y + vp[2][0]*z + vp[3][0]; |
| 1997 | let clip_y = vp[0][1]*x + vp[1][1]*y + vp[2][1]*z + vp[3][1]; |
| 1998 | let clip_w = vp[0][3]*x + vp[1][3]*y + vp[2][3]*z + vp[3][3]; |
| 1999 | |
| 2000 | if clip_w <= 0.0 { |
| 2001 | unsafe { LAST_PROJECT = (-9999.0, -9999.0); } |
| 2002 | return -9999.0; |
| 2003 | } |
| 2004 | |
| 2005 | let ndc_x = clip_x / clip_w; |
| 2006 | let ndc_y = clip_y / clip_w; |
| 2007 | let screen_x = ((ndc_x + 1.0) * 0.5 * w) as f64; |
| 2008 | let screen_y = ((1.0 - ndc_y) * 0.5 * h) as f64; |
| 2009 | |
| 2010 | unsafe { LAST_PROJECT = (screen_x, screen_y); } |
| 2011 | screen_x |
| 2012 | } |
| 2013 | |
| 2014 | #[no_mangle] |
| 2015 | pub extern "C" fn bloom_register_frame_callback(priority: f64, callback: extern "C" fn(f64)) -> f64 { |