From: havoc Date: Thu, 14 Jun 2007 05:27:56 +0000 (+0000) Subject: implemented csqc VF_PERSPECTIVE, still needs more work but it's a start X-Git-Tag: xonotic-v0.1.0preview~3042 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=15c38bb14f3a48f6d202b61f90885a29375e8d8b;p=xonotic%2Fdarkplaces.git implemented csqc VF_PERSPECTIVE, still needs more work but it's a start git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@7419 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/client.h b/client.h index 52a9ce06..d00873f3 100644 --- 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; diff --git a/clvm_cmds.c b/clvm_cmds.c index 37deefa8..b8544075 100644 --- a/clvm_cmds.c +++ b/clvm_cmds.c @@ -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; diff --git a/csprogs.h b/csprogs.h index 451fc3d5..964f1214 100644 --- 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. diff --git a/gl_rmain.c b/gl_rmain.c index 8aa50492..f1dd2be5 100644 --- a/gl_rmain.c +++ b/gl_rmain.c @@ -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);