2 Copyright (C) 1996-1997 Id Software, Inc.
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 See the GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 // chase.c -- chase camera code
23 qboolean
SV_RecursiveHullCheck (hull_t
*hull
, int num
, float p1f
, float p2f
, vec3_t p1
, vec3_t p2
, trace_t
*trace
);
25 cvar_t chase_back
= {"chase_back", "100"};
26 cvar_t chase_up
= {"chase_up", "16"};
27 cvar_t chase_right
= {"chase_right", "0"};
28 cvar_t chase_active
= {"chase_active", "0"};
34 vec3_t chase_dest_angles
;
37 void Chase_Init (void)
39 Cvar_RegisterVariable (&chase_back
);
40 Cvar_RegisterVariable (&chase_up
);
41 Cvar_RegisterVariable (&chase_right
);
42 Cvar_RegisterVariable (&chase_active
);
45 void Chase_Reset (void)
47 // for respawning and teleporting
48 // start position 12 units behind head
51 void TraceLine (vec3_t start
, vec3_t end
, vec3_t impact
)
55 memset (&trace
, 0, sizeof(trace
));
56 SV_RecursiveHullCheck (cl
.worldmodel
->hulls
, 0, 0, 1, start
, end
, &trace
);
58 VectorCopy (trace
.endpos
, impact
);
61 void Chase_Update (void)
65 vec3_t forward
, up
, right
;
69 // if can't see player, reset
70 AngleVectors (cl
.viewangles
, forward
, right
, up
);
72 // calc exact destination
74 chase_dest
[i
] = r_refdef
.vieworg
[i
]
75 - forward
[i
]*chase_back
.value
76 - right
[i
]*chase_right
.value
;
77 chase_dest
[2] = r_refdef
.vieworg
[2] + chase_up
.value
;
79 // find the spot the player is looking at
80 VectorMA (r_refdef
.vieworg
, 4096, forward
, dest
);
81 TraceLine (r_refdef
.vieworg
, dest
, stop
);
83 // calculate pitch to look at the same spot from camera
84 VectorSubtract (stop
, r_refdef
.vieworg
, stop
);
85 dist
= DotProduct (stop
, forward
);
88 r_refdef
.viewangles
[PITCH
] = -atan(stop
[2] / dist
) / M_PI
* 180;
90 // move towards destination
91 VectorCopy (chase_dest
, r_refdef
.vieworg
);