]> de.git.xonotic.org Git - voretournament/voretournament.git/commitdiff
Event chasecam from Xonotic (original code by me). Causes camera to do into third...
authorMirceaKitsune <sonichedgehog_hyperblast00@yahoo.com>
Sun, 1 May 2011 19:56:45 +0000 (22:56 +0300)
committerMirceaKitsune <sonichedgehog_hyperblast00@yahoo.com>
Sun, 1 May 2011 19:56:45 +0000 (22:56 +0300)
data/defaultVT.cfg
data/qcsrc/client/Main.qc
data/qcsrc/client/View.qc

index ff1d5e67b77fec1d9b31b11fad91ea1bb9e07da6..3707e475e7923a8a303ac57b6cc392716fe96993 100644 (file)
@@ -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"\r
 seta cl_announcer default "name of the announcer you wish to use from data/sound/announcer"\r
 \r
+seta cl_eventchase_death 1 "camera goes into 3rd person mode when the player is dead"\r
+seta cl_eventchase_distance 140 "final camera distance"\r
+seta cl_eventchase_speed 1.3 "how fast the camera slides back, 0 is instant"\r
+\r
 seta cl_itembobheight 10\r
 seta cl_itembobspeed 0.5\r
 \r
index e01f560fe805dc7b32badaa04a320f30d8f3c63d..3f9c72927e22bb6636cf010b59f025ffca3a8510 100644 (file)
@@ -208,6 +208,10 @@ void CSQC_Shutdown(void)
        if(camera_active)\r
                cvar_set("chase_active",ftos(chase_active_backup));\r
 \r
+       // unset the event chasecam's chase_active\r
+       if(cvar("chase_active") < 0)\r
+               cvar_set("chase_active", "0");\r
+\r
        if not(isdemo())\r
        {\r
                if not(calledhooks & HOOK_START)\r
index a0a337b0ce31dfaafb5d5f131f309e1fedcb5947..1a758a7925ead45b8d6ae4747da12a5b943a5db2 100644 (file)
@@ -260,6 +260,7 @@ float old_blurradius, old_bluralpha, old_sharpen_intensity;
 float stomachsplash_alpha, stomachsplash_remove_at_respawn;\r
 float volume_modify_1, volume_modify_2, volume_modify_default_1, volume_modify_default_2;\r
 float volume_modify_changed_1, volume_modify_changed_2;\r
+float eventchase_current_distance;\r
 vector myhealth_gentlergb;\r
 vector liquidcolor_prev;\r
 vector damage_blurpostprocess, content_blurpostprocess;\r
@@ -294,6 +295,41 @@ void CSQC_UpdateView(float w, float h)
        pmove_org = warpzone_fixview_origin - vo;\r
        input_angles = warpzone_fixview_angles;\r
 \r
+       // event chase camera\r
+       if(cvar("chase_active") <= 0) // greater than 0 means it's enabled manually, and this code is skipped\r
+       {\r
+               if(spectatee_status >= 0 && (cvar("cl_eventchase_death") && getstati(STAT_HEALTH) <= 0 && !intermission))\r
+               {\r
+                       // We must enable chase_active to get a third person view (weapon viewmodel hidden and own player model showing).\r
+                       // Ideally, there should be another way to enable third person cameras, such as through R_SetView()\r
+                       if(!cvar("chase_active"))\r
+                               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)\r
+\r
+                       // make the camera smooth back\r
+                       if(cvar("cl_eventchase_speed") && eventchase_current_distance < cvar("cl_eventchase_distance"))\r
+                               eventchase_current_distance += cvar("cl_eventchase_speed") * (cvar("cl_eventchase_distance") - eventchase_current_distance) * frametime; // slow down the further we get\r
+                       else if(eventchase_current_distance != cvar("cl_eventchase_distance"))\r
+                               eventchase_current_distance = cvar("cl_eventchase_distance");\r
+\r
+                       vector eventchase_target_origin;\r
+                       makevectors(view_angles);\r
+                       // pass 1, used to check where the camera would go and obtain the trace_fraction\r
+                       eventchase_target_origin = pmove_org - v_forward * eventchase_current_distance;\r
+\r
+                       traceline(pmove_org, eventchase_target_origin, MOVE_WORLDONLY, self);\r
+                       // pass 2, also multiplying view_forward with trace_fraction, to prevent the camera from going through walls\r
+                       // The 0.1 subtraction is to not limit the camera precisely at the wall surface, as that allows the view to poke through\r
+                       eventchase_target_origin = pmove_org - v_forward * eventchase_current_distance * (trace_fraction - 0.1);\r
+\r
+                       R_SetView(VF_ORIGIN, eventchase_target_origin);\r
+               }\r
+               else if(cvar("chase_active") < 0) // time to disable chase_active if it was set by this code\r
+               {\r
+                       cvar_set("chase_active", "0");\r
+                       eventchase_current_distance = 0; // start from 0 next time\r
+               }\r
+       }\r
+\r
        // Render the Scene\r
        if(!intermission || !view_set)\r
        {\r