implemented csqc VF_PERSPECTIVE, still needs more work but it's a start
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Thu, 14 Jun 2007 05:27:56 +0000 (05:27 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Thu, 14 Jun 2007 05:27:56 +0000 (05:27 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@7419 d7cf8633-e32d-0410-b094-e92efae38249

client.h
clvm_cmds.c
csprogs.h
gl_rmain.c

index 52a9ce0..d00873f 100644 (file)
--- a/client.h
+++ b/client.h
@@ -1408,6 +1408,8 @@ typedef struct r_view_s
        mplane_t frustum[5];
        float frustum_x, frustum_y;
        vec3_t frustumcorner[4];
+       // if turned off it renders an ortho view
+       int useperspective;
 
        // screen area to render in
        int x;
index 37deefa..b854407 100644 (file)
@@ -685,35 +685,32 @@ static void VM_CL_R_SetView (void)
 
        switch(c)
        {
-       case VF_MIN:                    r_view.x = (int)f[0];
-                                                       r_view.y = (int)f[1];
+       case VF_MIN:                    r_view.x = (int)(f[0] * vid.width / vid_conwidth.value);
+                                                       r_view.y = (int)(f[1] * vid.height / vid_conheight.value);
                                                        break;
-       case VF_MIN_X:                  r_view.x = (int)k;
+       case VF_MIN_X:                  r_view.x = (int)(k * vid.width / vid_conwidth.value);
                                                        break;
-       case VF_MIN_Y:                  r_view.y = (int)k;
+       case VF_MIN_Y:                  r_view.y = (int)(k * vid.height / vid_conheight.value);
                                                        break;
-       case VF_SIZE:                   r_view.width = (int)f[0];
-                                                       r_view.height = (int)f[1];
+       case VF_SIZE:                   r_view.width = (int)(f[0] * vid.width / vid_conwidth.value);
+                                                       r_view.height = (int)(f[1] * vid.height / vid_conheight.value);
                                                        break;
-       case VF_SIZE_Y:                 r_view.width = (int)k;
+       case VF_SIZE_Y:                 r_view.width = (int)(k * vid.width / vid_conwidth.value);
                                                        break;
-       case VF_SIZE_X:                 r_view.height = (int)k;
+       case VF_SIZE_X:                 r_view.height = (int)(k * vid.height / vid_conheight.value);
                                                        break;
-       case VF_VIEWPORT:               r_view.x = (int)f[0];
-                                                       r_view.y = (int)f[1];
-                                                       r_view.z = 0;
-                                                       // TODO: make sure that view_z and view_depth are set properly even if csqc does not set them!
+       case VF_VIEWPORT:               r_view.x = (int)(f[0] * vid.width / vid_conwidth.value);
+                                                       r_view.y = (int)(f[1] * vid.height / vid_conheight.value);
                                                        f = PRVM_G_VECTOR(OFS_PARM2);
-                                                       r_view.width = (int)f[0];
-                                                       r_view.height = (int)f[1];
-                                                       r_view.depth = 1;
+                                                       r_view.width = (int)(f[0] * vid.width / vid_conwidth.value);
+                                                       r_view.height = (int)(f[1] * vid.height / vid_conheight.value);
                                                        break;
-       case VF_FOV:                    //r_refdef.fov_x = f[0]; // FIXME!
-                                                       //r_refdef.fov_y = f[1]; // FIXME!
+       case VF_FOV:                    r_view.frustum_x = tan(f[0] * M_PI / 360.0);
+                                                       r_view.frustum_y = tan(f[1] * M_PI / 360.0);
                                                        break;
-       case VF_FOVX:                   //r_refdef.fov_x = k; // FIXME!
+       case VF_FOVX:                   r_view.frustum_x = tan(k * M_PI / 360.0);
                                                        break;
-       case VF_FOVY:                   //r_refdef.fov_y = k; // FIXME!
+       case VF_FOVY:                   r_view.frustum_y = tan(k * M_PI / 360.0);
                                                        break;
        case VF_ORIGIN:                 VectorCopy(f, cl.csqc_origin);
                                                        CSQC_R_RecalcView();
@@ -755,6 +752,9 @@ static void VM_CL_R_SetView (void)
        case VF_CL_VIEWANGLES_Z:cl.viewangles[2] = k;
                                                        break;
 
+       case VF_PERSPECTIVE:    r_view.useperspective = k != 0;
+                                                       break;
+
        default:                                PRVM_G_FLOAT(OFS_RETURN) = 0;
                                                        VM_Warning("VM_CL_R_SetView : unknown parm %i\n", c);
                                                        return;
index 451fc3d..964f121 100644 (file)
--- a/csprogs.h
+++ b/csprogs.h
@@ -38,7 +38,7 @@
 #define VF_CL_VIEWANGLES_Y     35      //(float)
 #define VF_CL_VIEWANGLES_Z     36      //(float)
 
-//#define VF_PERSPECTIVE               200
+#define VF_PERSPECTIVE         200 //(float)
 
 #define RF_VIEWMODEL           1       // The entity is never drawn in mirrors. In engines with realtime lighting, it casts no shadows.
 #define RF_EXTERNALMODEL       2       // The entity is appears in mirrors but not in the normal view. It does still cast shadows in engines with realtime lighting.
index 8aa5049..f1dd2be 100644 (file)
@@ -1994,7 +1994,9 @@ void R_View_Update(void)
 
 void R_SetupView(const matrix4x4_t *matrix)
 {
-       if (r_refdef.rtworldshadows || r_refdef.rtdlightshadows)
+       if (!r_view.useperspective)
+               GL_SetupView_Mode_Ortho(r_view.x, r_view.y, r_view.x + r_view.width, r_view.y + r_view.height, -r_refdef.farclip, r_refdef.farclip);
+       else if (r_refdef.rtworldshadows || r_refdef.rtdlightshadows)
                GL_SetupView_Mode_PerspectiveInfiniteFarClip(r_view.frustum_x, r_view.frustum_y, r_refdef.nearclip);
        else
                GL_SetupView_Mode_Perspective(r_view.frustum_x, r_view.frustum_y, r_refdef.nearclip, r_refdef.farclip);