@@ -28,6 +28,58 @@ CPointCamera* GetPointCameraList()
2828 return g_PointCameraList.m_pClassList ;
2929}
3030
31+ #ifdef MAPBASE
32+ // -----------------------------------------------------------------------------
33+ // Purpose: Returns true if a camera is in the PVS of the specified entity
34+ // -----------------------------------------------------------------------------
35+ edict_t *UTIL_FindRTCameraInEntityPVS ( edict_t *pEdict )
36+ {
37+ CBaseEntity *pe = GetContainingEntity ( pEdict );
38+ if ( !pe )
39+ return NULL ;
40+
41+ bool bGotPVS = false ;
42+ Vector org;
43+ static byte pvs[ MAX_MAP_CLUSTERS /8 ];
44+ static int pvssize = sizeof ( pvs );
45+
46+ for ( CPointCamera *pCameraEnt = GetPointCameraList (); pCameraEnt != NULL ; pCameraEnt = pCameraEnt->m_pNext )
47+ {
48+ if (!pCameraEnt->IsActive ())
49+ continue ;
50+
51+ if (!bGotPVS)
52+ {
53+ // Getting the PVS during the loop like this makes sure we only get the PVS if there's actually an active camera in the level
54+ org = pe->EyePosition ();
55+ int clusterIndex = engine->GetClusterForOrigin ( org );
56+ Assert ( clusterIndex >= 0 );
57+ engine->GetPVSForCluster ( clusterIndex, pvssize, pvs );
58+ bGotPVS = true ;
59+ }
60+
61+ Vector vecCameraEye = pCameraEnt->EyePosition ();
62+
63+ Vector vecCameraDirection;
64+ pCameraEnt->GetVectors ( &vecCameraDirection, NULL , NULL );
65+
66+ Vector los = (org - vecCameraEye);
67+ float flDot = DotProduct ( los, vecCameraDirection );
68+
69+ // Make sure we're in the camera's FOV before checking PVS
70+ if ( flDot <= cos ( DEG2RAD ( pCameraEnt->GetFOV () / 2 ) ) )
71+ continue ;
72+
73+ if ( engine->CheckOriginInPVS ( vecCameraEye, pvs, pvssize ) )
74+ {
75+ return pCameraEnt->edict ();
76+ }
77+ }
78+
79+ return NULL ;
80+ }
81+ #endif
82+
3183// These are already built into CBaseEntity
3284// DEFINE_KEYFIELD( m_iName, FIELD_STRING, "targetname" ),
3385// DEFINE_KEYFIELD( m_iParent, FIELD_STRING, "parentname" ),
0 commit comments