/* gph-cmath - C graphics math library
- * Copyright (C) 2018 John Tsiombikas <nuclear@member.fsf.org>
+ * Copyright (C) 2018-2023 John Tsiombikas <nuclear@member.fsf.org>
*
* This program is free software. Feel free to use, modify, and/or redistribute
* it under the terms of the MIT/X11 license. See LICENSE for details.
cgm_vec3 npos, res;
float inv_pv[16];
- cgm_mcopy(inv_pv, proj);
- cgm_mmul(inv_pv, view);
+ cgm_mcopy(inv_pv, view);
+ cgm_mmul(inv_pv, proj);
+ cgm_minverse(inv_pv);
npos.x = (winx - vp[0]) / vp[2];
npos.y = (winy - vp[1]) / vp[4];
cgm_vec3 npos, farpt;
float inv_pv[16];
- cgm_mcopy(inv_pv, projmat);
- cgm_mmul(inv_pv, viewmat);
+ cgm_mcopy(inv_pv, viewmat);
+ cgm_mmul(inv_pv, projmat);
+ cgm_minverse(inv_pv);
cgm_vcons(&npos, nx, ny, 0.0f);
cgm_unproject(&ray->origin, &npos, inv_pv);