]> de.git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
fix cs_project and cs_unproject builtins, they were completely ignoring
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Thu, 2 Oct 2008 09:14:53 +0000 (09:14 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Thu, 2 Oct 2008 09:14:53 +0000 (09:14 +0000)
the view rectangle and not centered

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@8517 d7cf8633-e32d-0410-b094-e92efae38249

clvm_cmds.c

index 289e531eed039e9391c2aed589f1c2581128603d..cc48e814e23475df20e16aab81a7ef565fa53f05 100644 (file)
@@ -916,7 +916,7 @@ static void VM_CL_unproject (void)
 
        VM_SAFEPARMCOUNT(1, VM_CL_unproject);
        f = PRVM_G_VECTOR(OFS_PARM0);
-       VectorSet(temp, f[2], f[0] * f[2] * -r_refdef.view.frustum_x * 2.0 / r_refdef.view.width, f[1] * f[2] * -r_refdef.view.frustum_y * 2.0 / r_refdef.view.height);
+       VectorSet(temp, f[2], (-1.0 + 2.0 * (f[0] - r_refdef.view.x)) / r_refdef.view.width * f[2] * -r_refdef.view.frustum_x, (-1.0 + 2.0 * (f[1] - r_refdef.view.y))  / r_refdef.view.height * f[2] * -r_refdef.view.frustum_y);
        Matrix4x4_Transform(&r_refdef.view.matrix, temp, PRVM_G_VECTOR(OFS_RETURN));
 }
 
@@ -931,7 +931,7 @@ static void VM_CL_project (void)
        f = PRVM_G_VECTOR(OFS_PARM0);
        Matrix4x4_Invert_Simple(&m, &r_refdef.view.matrix);
        Matrix4x4_Transform(&m, f, v);
-       VectorSet(PRVM_G_VECTOR(OFS_RETURN), v[1]/v[0]/-r_refdef.view.frustum_x*0.5*r_refdef.view.width, v[2]/v[0]/-r_refdef.view.frustum_y*r_refdef.view.height*0.5, v[0]);
+       VectorSet(PRVM_G_VECTOR(OFS_RETURN), r_refdef.view.x + r_refdef.view.width*0.5*(1.0+v[1]/v[0]/-r_refdef.view.frustum_x), r_refdef.view.y + r_refdef.view.height*0.5*(1.0+v[2]/v[0]/-r_refdef.view.frustum_y), v[0]);
 }
 
 //#330 float(float stnum) getstatf (EXT_CSQC)