diff-camtrace.txt

Basic CamTrace Support - acqu, 14.01.2013 12:13

Download (5.61 KB)

 
1
Index: src/cgame/cg_info.c
2
===================================================================
3
--- src/cgame/cg_info.c	(revision 58)
4
+++ src/cgame/cg_info.c	(working copy)
5
@@ -288,6 +288,35 @@
6
 			if(down) cgs.aviDemoRate = demo_avifpsF5.integer;
7
 			else trap_Cvar_Set("cl_avidemo", demo_avifpsF5.string);
8
 			return;
9
+
10
+		// sta camtrace support
11
+		case K_KP_ENTER:
12
+			if(!down) {
13
+				CG_ToggleFreeCam();
14
+			}
15
+			return;
16
+
17
+		case 'w':
18
+			if(down) {
19
+				CG_FreeCamMoveForward();
20
+			}
21
+			return;
22
+		case 's':
23
+			if(down) {
24
+				CG_FreeCamMoveBackward();
25
+			}
26
+			return;
27
+		case 'a':
28
+			if(down) {
29
+				CG_FreeCamMoveLeft();
30
+			}
31
+			return;
32
+		case 'd':
33
+			if(down) {
34
+				CG_FreeCamMoveRight();
35
+			}
36
+			return;
37
+		// end camtrace support
38
 	}
39
 }
40
 
41
Index: src/cgame/cg_consolecmds.c
42
===================================================================
43
--- src/cgame/cg_consolecmds.c	(revision 58)
44
+++ src/cgame/cg_consolecmds.c	(working copy)
45
@@ -942,6 +942,95 @@
46
 	CG_AddPMItem( PM_MESSAGE, CG_Argv(1), cgs.media.voiceChatShader );
47
 }
48
 
49
+// sta camtrace support
50
+void CG_ToggleFreeCam( void ) {
51
+	cg.freeCam = cg.freeCam ? 0 : 1;
52
+
53
+	if(cg.freeCam) {
54
+		trap_Cvar_Set("cg_thirdperson", "1");
55
+	}
56
+	else {
57
+		trap_Cvar_Set("cg_thirdperson", "0");
58
+	}
59
+
60
+	VectorCopy(cg.refdef.vieworg, cg.freeCamPos);
61
+	VectorCopy(cg.refdefViewAngles, cg.freeCamAngles);
62
+}
63
+
64
+void CG_FreeCamMoveForward( void ) {
65
+	centity_t *cent = &cg_entities[cg.snap->ps.clientNum];
66
+	vec3_t vector;
67
+	vector[0] = 0.0f;
68
+	vector[1] = 127.0f;
69
+	vector[2] = 0.0f;
70
+	VectorAdd(cg.freeCamPos, vector, cg.freeCamPos);
71
+
72
+	CG_Printf("lerpOrigin[0] = %i\n", (int)cent->lerpOrigin[0]);
73
+	CG_Printf("lerpOrigin[1] = %i\n", (int)cent->lerpOrigin[1]);
74
+	CG_Printf("lerpOrigin[2] = %i\n", (int)cent->lerpOrigin[2]);
75
+
76
+	CG_Printf("CG_FreeCamMoveForward\n");
77
+}
78
+
79
+void CG_FreeCamMoveBackward( void ) {
80
+	vec3_t vector;
81
+	vector[0] = 0.0f;
82
+	vector[1] = -127.0f;
83
+	vector[2] = 0.0f;
84
+	VectorAdd(cg.freeCamPos, vector, cg.freeCamPos);
85
+
86
+	CG_Printf("CG_FreeCamMoveBackward\n");
87
+}
88
+
89
+void CG_FreeCamMoveLeft( void ) {
90
+	vec3_t vector;
91
+	vector[0] = -127.0f;
92
+	vector[1] = 0.0f;
93
+	vector[2] = 0.0f;
94
+	VectorAdd(cg.freeCamPos, vector, cg.freeCamPos);
95
+
96
+	CG_Printf("CG_FreeCamMoveLeft\n");
97
+}
98
+
99
+void CG_FreeCamMoveRight( void ) {
100
+	vec3_t vector;
101
+	vector[0] = 127.0f;
102
+	vector[1] = 0.0f;
103
+	vector[2] = 0.0f;
104
+	VectorAdd(cg.freeCamPos, vector, cg.freeCamPos);
105
+
106
+	CG_Printf("CG_FreeCamMoveRight\n");
107
+}
108
+
109
+void CG_FreeCamSetPos( void ) {	
110
+	int i;
111
+	char buffer[MAX_TOKEN_CHARS];
112
+	vec3_t origin, angles;	
113
+
114
+	if ( trap_Argc() < 3 ) {
115
+		CG_Printf("usage: setviewpos x y z pitch yaw roll\n");
116
+		return;
117
+	}
118
+
119
+	VectorClear( angles );
120
+
121
+	for ( i = 0 ; i < 3 ; i++ ) {
122
+		trap_Argv( i + 1, buffer, sizeof( buffer ) );
123
+		origin[i] = atof( buffer );
124
+	}
125
+
126
+	trap_Argv( 4, buffer, sizeof( buffer ) );
127
+	angles[PITCH] = atof( buffer );
128
+	trap_Argv( 5, buffer, sizeof( buffer ) );
129
+	angles[YAW] = atof( buffer );
130
+	trap_Argv( 6, buffer, sizeof( buffer ) );
131
+	angles[ROLL] = atof( buffer );
132
+
133
+	VectorCopy( origin, cg.freeCamPos );
134
+	VectorCopy( angles, cg.freeCamAngles );
135
+}
136
+// end camtrace support
137
+
138
 typedef struct {
139
 	char	*cmd;
140
 	void	(*function)(void);
141
@@ -1043,6 +1132,11 @@
142
 	{ "undoSpeaker", CG_UndoSpeaker_f },
143
 	{ "cpm", CG_CPM_f },
144
 	{ "forcetapout", CG_ForceTapOut_f },
145
+
146
+	// sta camtrace support
147
+	{ "freecam", CG_ToggleFreeCam },
148
+	{ "freecamsetpos", CG_FreeCamSetPos },
149
+	// end camtrace support
150
 };
151
 
152
 
153
@@ -1202,6 +1296,11 @@
154
 	trap_AddCommand ("where");
155
 
156
+	// sta camtrace support
157
+	trap_AddCommand ("freecam");
158
+	trap_AddCommand ("freecamsetpos");
159
+	// end camtrace support
160
+
161

    
162
Index: src/cgame/cg_local.h
163
===================================================================
164
--- src/cgame/cg_local.h	(revision 58)
165
+++ src/cgame/cg_local.h	(working copy)
166
@@ -1002,6 +1002,12 @@
167
 	qboolean	cameraMode;		// if rendering from a camera
168
 	// Duffy end
169
 
170
+	// sta camtrace support
171
+	qboolean	freeCam;
172
+	vec3_t		freeCamPos;
173
+	vec3_t		freeCamAngles;
174
+	// end camtrace support
175
+
176
 	// NERVE - SMF - Objective info display
177
 	qboolean	limboMenu;
178
 
179
@@ -2767,6 +2773,15 @@
180
 void CG_dumpStats_f(void);
181
 void CG_toggleSwing_f(void);
182
 
183
+// sta camtrace support
184
+void CG_ToggleFreeCam ( void );
185
+void CG_FreeCamSetPos ( void );
186
+void CG_FreeCamMoveForward ( void );
187
+void CG_FreeCamMoveBackward ( void );
188
+void CG_FreeCamMoveLeft ( void );
189
+void CG_FreeCamMoveRight ( void );
190
+// end camtrace support
191
+
192
 //
193
 // cg_servercmds.c
194
 //
195
Index: src/cgame/cg_view.c
196
===================================================================
197
--- src/cgame/cg_view.c	(revision 58)
198
+++ src/cgame/cg_view.c	(working copy)
199
@@ -1167,6 +1167,29 @@
200
 
201
 	ps = &cg.predictedPlayerState;
202
 
203
+	// sta camtrace support
204
+	if (cg.freeCam) {
205
+
206
+		float fov = 90;
207
+		float x;
208
+		centity_t *cent = &cg_entities[cg.snap->ps.clientNum];
209
+
210
+		VectorCopy( cg.freeCamPos, cg.refdef.vieworg );
211
+		VectorCopy( cg.freeCamAngles, cg.refdefViewAngles);
212
+		AnglesToAxis( cg.refdefViewAngles, cg.refdef.viewaxis );
213
+
214
+		VectorCopy(cg.freeCamPos, cg.refdef_current->vieworg );
215
+		AnglesToAxis( cg.refdefViewAngles, cg.refdef_current->viewaxis );
216
+
217
+		x = cg.refdef.width / tan( fov / 360 * M_PI );
218
+		cg.refdef_current->fov_y = atan2( cg.refdef_current->height, x );
219
+		cg.refdef_current->fov_y = cg.refdef_current->fov_y * 360 / M_PI;
220
+		cg.refdef_current->fov_x = fov;
221
+
222
+		return CG_CalcFov();
223
+	}
224
+	// end camtrace support
225
+
226
 	if (cg.cameraMode) {
227
 		vec3_t origin, angles;
228
 		float fov = 90;