From d2be8795987c599bcfe6091c9374aa0c67e26520 Mon Sep 17 00:00:00 2001 From: MirceaKitsune Date: Sun, 1 May 2011 22:56:45 +0300 Subject: [PATCH] Event chasecam from Xonotic (original code by me). Causes camera to do into third person mode when the player is dead. --- data/defaultVT.cfg | 4 ++++ data/qcsrc/client/Main.qc | 4 ++++ data/qcsrc/client/View.qc | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+) diff --git a/data/defaultVT.cfg b/data/defaultVT.cfg index ff1d5e67..3707e475 100644 --- a/data/defaultVT.cfg +++ b/data/defaultVT.cfg @@ -644,6 +644,10 @@ seta cl_notify_carried_items "3" "notify you of carried items when you obtain th seta cl_hitsound 1 "play a hit notifier sound when you have hit an enemy" seta cl_announcer default "name of the announcer you wish to use from data/sound/announcer" +seta cl_eventchase_death 1 "camera goes into 3rd person mode when the player is dead" +seta cl_eventchase_distance 140 "final camera distance" +seta cl_eventchase_speed 1.3 "how fast the camera slides back, 0 is instant" + seta cl_itembobheight 10 seta cl_itembobspeed 0.5 diff --git a/data/qcsrc/client/Main.qc b/data/qcsrc/client/Main.qc index e01f560f..3f9c7292 100644 --- a/data/qcsrc/client/Main.qc +++ b/data/qcsrc/client/Main.qc @@ -208,6 +208,10 @@ void CSQC_Shutdown(void) if(camera_active) cvar_set("chase_active",ftos(chase_active_backup)); + // unset the event chasecam's chase_active + if(cvar("chase_active") < 0) + cvar_set("chase_active", "0"); + if not(isdemo()) { if not(calledhooks & HOOK_START) diff --git a/data/qcsrc/client/View.qc b/data/qcsrc/client/View.qc index a0a337b0..1a758a79 100644 --- a/data/qcsrc/client/View.qc +++ b/data/qcsrc/client/View.qc @@ -260,6 +260,7 @@ float old_blurradius, old_bluralpha, old_sharpen_intensity; float stomachsplash_alpha, stomachsplash_remove_at_respawn; float volume_modify_1, volume_modify_2, volume_modify_default_1, volume_modify_default_2; float volume_modify_changed_1, volume_modify_changed_2; +float eventchase_current_distance; vector myhealth_gentlergb; vector liquidcolor_prev; vector damage_blurpostprocess, content_blurpostprocess; @@ -294,6 +295,41 @@ void CSQC_UpdateView(float w, float h) pmove_org = warpzone_fixview_origin - vo; input_angles = warpzone_fixview_angles; + // event chase camera + if(cvar("chase_active") <= 0) // greater than 0 means it's enabled manually, and this code is skipped + { + if(spectatee_status >= 0 && (cvar("cl_eventchase_death") && getstati(STAT_HEALTH) <= 0 && !intermission)) + { + // We must enable chase_active to get a third person view (weapon viewmodel hidden and own player model showing). + // Ideally, there should be another way to enable third person cameras, such as through R_SetView() + if(!cvar("chase_active")) + cvar_set("chase_active", "-1"); // -1 enables chase_active while marking it as set by this code, and not by the user (which would be 1) + + // make the camera smooth back + if(cvar("cl_eventchase_speed") && eventchase_current_distance < cvar("cl_eventchase_distance")) + eventchase_current_distance += cvar("cl_eventchase_speed") * (cvar("cl_eventchase_distance") - eventchase_current_distance) * frametime; // slow down the further we get + else if(eventchase_current_distance != cvar("cl_eventchase_distance")) + eventchase_current_distance = cvar("cl_eventchase_distance"); + + vector eventchase_target_origin; + makevectors(view_angles); + // pass 1, used to check where the camera would go and obtain the trace_fraction + eventchase_target_origin = pmove_org - v_forward * eventchase_current_distance; + + traceline(pmove_org, eventchase_target_origin, MOVE_WORLDONLY, self); + // pass 2, also multiplying view_forward with trace_fraction, to prevent the camera from going through walls + // The 0.1 subtraction is to not limit the camera precisely at the wall surface, as that allows the view to poke through + eventchase_target_origin = pmove_org - v_forward * eventchase_current_distance * (trace_fraction - 0.1); + + R_SetView(VF_ORIGIN, eventchase_target_origin); + } + else if(cvar("chase_active") < 0) // time to disable chase_active if it was set by this code + { + cvar_set("chase_active", "0"); + eventchase_current_distance = 0; // start from 0 next time + } + } + // Render the Scene if(!intermission || !view_set) { -- 2.39.2