70 lines · 1.6 KB · C
RawDownload
// chase.c -- chase camera code #include <math.h>#include "quakedef.h" static cvar_t chase_back = {"chase_back", "100"};static cvar_t chase_up = {"chase_up", "16"};static cvar_t chase_right = {"chase_right", "0"};cvar_t chase_active = {"chase_active", "0"}; static vec3_t chase_dest; voidChase_Init(void){	Cvar_RegisterVariable(&chase_back);	Cvar_RegisterVariable(&chase_up);	Cvar_RegisterVariable(&chase_right);	Cvar_RegisterVariable(&chase_active);} voidChase_Reset(void){	// for respawning and teleporting	// start position 12 units behind head} voidTraceLine(vec3_t start, vec3_t end, vec3_t impact){	trace_t trace; 	memset(&trace, 0, sizeof(trace));	SV_RecursiveHullCheck(cl.worldmodel->hulls, 0, 0, 1, start, end, &trace); 	VectorCopy(trace.endpos, impact);} voidChase_Update(void){	vec3_t forward, up, right;	vec3_t dest, stop;	float dist;	int i; 	// if can't see player, reset	AngleVectors(cl.viewangles, forward, right, up); 	// calc exact destination	for (i = 0; i < 3 ;i++)		chase_dest[i] = r_refdef.vieworg[i] - forward[i]*chase_back.value - right[i]*chase_right.value;	chase_dest[2] = r_refdef.vieworg[2] + chase_up.value; 	// find the spot the player is looking at	VectorMA(r_refdef.vieworg, 4096, forward, dest);	TraceLine(r_refdef.vieworg, dest, stop); 	// calculate pitch to look at the same spot from camera	VectorSubtract(stop, r_refdef.vieworg, stop);	dist = DotProduct(stop, forward);	if (dist < 1)		dist = 1;	r_refdef.viewangles[PITCH] = -atan(stop[2] / dist) / M_PI * 180; 	// move towards destination	VectorCopy(chase_dest, r_refdef.vieworg);} 

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t