//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CPointSpotlight::InputLightOff( inputdata_t &inputdata ) { if ( m_bSpotlightOn ) { m_bSpotlightOn = false; if ( m_bEfficientSpotlight ) { SpotlightDestroy(); } } }
CAI_Spotlight::~CAI_Spotlight() { SpotlightDestroy(); }
//------------------------------------------------------------------------------ void C_BeamSpotLight::Release() { SpotlightDestroy(); BaseClass::Release(); }
//------------------------------------------------------------------------------ // Purpose : Update the direction and position of my spotlight // Input : // Output : //------------------------------------------------------------------------------ void CPointSpotlight::SpotlightUpdate(void) { // --------------------------------------------------- // If I don't have a spotlight attempt to create one // --------------------------------------------------- if ( !m_hSpotlight ) { if ( m_bSpotlightOn ) { // Make the spotlight SpotlightCreate(); } else { return; } } else if ( !m_bSpotlightOn ) { SpotlightDestroy(); return; } if ( !m_hSpotlightTarget ) { DevWarning( "**Attempting to update point_spotlight but target ent is NULL\n" ); SpotlightDestroy(); SpotlightCreate(); if ( !m_hSpotlightTarget ) return; } m_vSpotlightCurrentPos = SpotlightCurrentPos(); // Update spotlight target velocity Vector vTargetDir; VectorSubtract( m_vSpotlightCurrentPos, m_hSpotlightTarget->GetAbsOrigin(), vTargetDir ); float vTargetDist = vTargetDir.Length(); // If we haven't moved at all, don't recompute if ( vTargetDist < 1 ) { m_hSpotlightTarget->SetAbsVelocity( vec3_origin ); return; } Vector vecNewVelocity = vTargetDir; VectorNormalize(vecNewVelocity); vecNewVelocity *= (10 * vTargetDist); // If a large move is requested, just jump to final spot as we probably hit a discontinuity if (vecNewVelocity.Length() > 200) { VectorNormalize(vecNewVelocity); vecNewVelocity *= 200; VectorNormalize(vTargetDir); m_hSpotlightTarget->SetAbsOrigin( m_vSpotlightCurrentPos ); } m_hSpotlightTarget->SetAbsVelocity( vecNewVelocity ); m_hSpotlightTarget->m_vSpotlightOrg = GetAbsOrigin(); // Avoid sudden change in where beam fades out when cross disconinuities VectorSubtract( m_hSpotlightTarget->GetAbsOrigin(), m_hSpotlightTarget->m_vSpotlightOrg, m_hSpotlightTarget->m_vSpotlightDir ); float flBeamLength = VectorNormalize( m_hSpotlightTarget->m_vSpotlightDir ); m_flSpotlightCurLength = (0.60*m_flSpotlightCurLength) + (0.4*flBeamLength); ComputeRenderInfo(); //NDebugOverlay::Cross3D(GetAbsOrigin(),Vector(-5,-5,-5),Vector(5,5,5),0,255,0,true,0.1); //NDebugOverlay::Cross3D(m_vSpotlightCurrentPos,Vector(-5,-5,-5),Vector(5,5,5),0,255,0,true,0.1); //NDebugOverlay::Cross3D(m_vSpotlightTargetPos,Vector(-5,-5,-5),Vector(5,5,5),255,0,0,true,0.1); }
//----------------------------------------------------------------------------- void C_BeamSpotLight::ClientThink( void ) { float dt = gpGlobals->curtime - m_lastTime; if ( !m_lastTime ) { dt = 0.0f; } m_lastTime = gpGlobals->curtime; // --------------------------------------------------- // If I don't have a spotlight attempt to create one // --------------------------------------------------- if ( !m_hSpotlight ) { if ( m_bSpotlightOn ) { // Make the spotlight SpotlightCreate(); } else { SetNextClientThink( CLIENT_THINK_NEVER ); return; } } else if ( !m_bSpotlightOn ) { SpotlightDestroy(); SetNextClientThink( CLIENT_THINK_NEVER ); return; } // update rotation if ( m_flRotationSpeed != 0.0f ) { QAngle angles = GetAbsAngles(); angles[m_nRotationAxis] += m_flRotationSpeed * dt; angles[m_nRotationAxis] = anglemod(angles[m_nRotationAxis]); if ( !m_pCache ) { m_pCache = new CSpotlightTraceCacheEntry[NUM_CACHE_ENTRIES]; } SetAbsAngles( angles ); } m_vSpotlightCurrentPos = SpotlightCurrentPos(); Assert( m_hSpotlight ); m_hSpotlight->SetStartPos( GetAbsOrigin() ); m_hSpotlight->SetEndPos( m_vSpotlightCurrentPos ); // Avoid sudden change in where beam fades out when cross disconinuities Vector dir = m_vSpotlightCurrentPos - GetAbsOrigin(); float flBeamLength = VectorNormalize( dir ); m_flSpotlightCurLength = (0.60*m_flSpotlightCurLength) + (0.4*flBeamLength); ComputeRenderInfo(); m_hSpotlight->RelinkBeam(); //NDebugOverlay::Cross3D(GetAbsOrigin(),Vector(-5,-5,-5),Vector(5,5,5),0,255,0,true,0.1); //NDebugOverlay::Cross3D(m_vSpotlightCurrentPos,Vector(-5,-5,-5),Vector(5,5,5),0,255,0,true,0.1); //NDebugOverlay::Cross3D(m_vSpotlightTargetPos,Vector(-5,-5,-5),Vector(5,5,5),255,0,0,true,0.1); // Do we need to keep updating? if ( !GetMoveParent() && m_flRotationSpeed == 0 ) { // No reason to think again, we're not going to move unless there's a data change SetNextClientThink( CLIENT_THINK_NEVER ); } }