1 /*
2 ===========================================================================
3 Copyright (C) 1999 - 2005, Id Software, Inc.
4 Copyright (C) 2000 - 2013, Raven Software, Inc.
5 Copyright (C) 2001 - 2013, Activision, Inc.
6 Copyright (C) 2013 - 2015, OpenJK contributors
7
8 This file is part of the OpenJK source code.
9
10 OpenJK is free software; you can redistribute it and/or modify it
11 under the terms of the GNU General Public License version 2 as
12 published by the Free Software Foundation.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, see <http://www.gnu.org/licenses/>.
21 ===========================================================================
22 */
23
24 // tr_main.c -- main control flow for each frame
25 #include "tr_local.h"
26 #include "ghoul2/g2_local.h"
27
28 trGlobals_t tr;
29
30 refimport_t ri;
31
32 void R_AddTerrainSurfaces(void);
33
34 /*
35 ** R_CullLocalPointAndRadius
36 */
R_CullLocalPointAndRadius(const vec3_t pt,float radius)37 int R_CullLocalPointAndRadius( const vec3_t pt, float radius )
38 {
39 vec3_t transformed;
40
41 R_LocalPointToWorld( pt, transformed );
42
43 return R_CullPointAndRadius( transformed, radius );
44 }
45
46 /*
47 ** R_CullPointAndRadius
48 */
R_CullPointAndRadius(const vec3_t pt,float radius)49 int R_CullPointAndRadius( const vec3_t pt, float radius )
50 {
51 int i;
52 float dist;
53 cplane_t *frust;
54 qboolean mightBeClipped = qfalse;
55
56 if ( r_nocull->integer==1 ) {
57 return CULL_CLIP;
58 }
59
60 // check against frustum planes
61 for (i = 0 ; i < 4 ; i++)
62 {
63 frust = &tr.viewParms.frustum[i];
64
65 dist = DotProduct( pt, frust->normal) - frust->dist;
66 if ( dist < -radius )
67 {
68 return CULL_OUT;
69 }
70 else if ( dist <= radius )
71 {
72 mightBeClipped = qtrue;
73 }
74 }
75
76 if ( mightBeClipped )
77 {
78 return CULL_CLIP;
79 }
80
81 return CULL_IN; // completely inside frustum
82 }
83
84 /*
85 =================
86 R_LocalPointToWorld
87
88 =================
89 */
R_LocalPointToWorld(const vec3_t local,vec3_t world)90 void R_LocalPointToWorld (const vec3_t local, vec3_t world) {
91 world[0] = local[0] * tr.ori.axis[0][0] + local[1] * tr.ori.axis[1][0] + local[2] * tr.ori.axis[2][0] + tr.ori.origin[0];
92 world[1] = local[0] * tr.ori.axis[0][1] + local[1] * tr.ori.axis[1][1] + local[2] * tr.ori.axis[2][1] + tr.ori.origin[1];
93 world[2] = local[0] * tr.ori.axis[0][2] + local[1] * tr.ori.axis[1][2] + local[2] * tr.ori.axis[2][2] + tr.ori.origin[2];
94 }
95