From 253ef7b81768bd6cca0d0003547e17f01259ba48 Mon Sep 17 00:00:00 2001 From: Spoike Date: Mon, 3 Jan 2011 03:52:37 +0000 Subject: [PATCH] Made Matrix4_UnProject a bit more intuitive/reliable. git-svn-id: https://svn.code.sf.net/p/fteqw/code/branches/wip@3713 fc73d0e0-1445-4013-8a0c-d673dee63da5 --- engine/client/cl_input.c | 8 ++------ engine/common/mathlib.c | 12 ++++++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/engine/client/cl_input.c b/engine/client/cl_input.c index 87cf4f72e..99188b461 100644 --- a/engine/client/cl_input.c +++ b/engine/client/cl_input.c @@ -756,17 +756,13 @@ void CL_UpdatePrydonCursor(usercmd_t *from, float cursor_screen[2], vec3_t curso VectorCopy(r_origin, cursor_start); Matrix4_UnProject(temp, cursor_end, cl.viewangles[0], cursor_start, r_refdef.fov_x, r_refdef.fov_y); - VectorScale(cursor_end, 100000, cursor_end); CL_SetSolidEntities(); //don't bother with players, they don't exist in NQ... TraceLineN(cursor_start, cursor_end, cursor_impact, cursor_impact_normal); -// CL_SelectTraceLine(cursor_start, cursor_end, cursor_impact, entnum); - // makes sparks where cursor is - //CL_SparkShower(cl.cmd.cursor_impact, cl.cmd.cursor_normal, 5, 0); -// P_RunParticleEffectType(cursor_impact, vec3_origin, 1, pt_gunshot); -//P_ParticleTrail(cursor_start, cursor_impact, 0, NULL); + +// P_RunParticleEffect(cursor_impact, vec3_origin, 15, 16); } #ifdef NQPROT diff --git a/engine/common/mathlib.c b/engine/common/mathlib.c index 0ba9b76f2..67e748132 100644 --- a/engine/common/mathlib.c +++ b/engine/common/mathlib.c @@ -1583,14 +1583,18 @@ void Matrix4_UnProject(const vec3_t in, vec3_t out, const vec3_t viewangles, con float v[4], tempv[4]; v[0] = in[0]*2-1; v[1] = in[1]*2-1; - v[2] = in[2]*2-1; + v[2] = in[2]; v[3] = 1; + //don't use 1, because the far clip plane really is an infinite distance away + if (v[2] >= 1) + v[2] = 0.999999; + Matrix4_Transform4(proj, v, tempv); - out[0] = tempv[0]; - out[1] = tempv[1]; - out[2] = tempv[2]; + out[0] = tempv[0]/tempv[3]; + out[1] = tempv[1]/tempv[3]; + out[2] = tempv[2]/tempv[3]; } }