void C_PropForklift::Simulate( void ) { // The dim light is the flashlight. if ( m_bHeadlightIsOn ) { if ( m_pHeadlight == NULL ) { // Turned on the headlight; create it. m_pHeadlight = new CHeadlightEffect; if ( m_pHeadlight == NULL ) return; m_pHeadlight->TurnOn(); } QAngle vAngle; Vector vVector; Vector vecForward, vecRight, vecUp; int iAttachment = LookupAttachment( "headlight" ); if ( iAttachment != -1 ) { GetAttachment( iAttachment, vVector, vAngle ); AngleVectors( vAngle, &vecForward, &vecRight, &vecUp ); m_pHeadlight->UpdateLight( vVector, vecForward, vecRight, vecUp, Forklift_HEADLIGHT_DISTANCE ); } } else if ( m_pHeadlight ) { // Turned off the flashlight; delete it. delete m_pHeadlight; m_pHeadlight = NULL; } BaseClass::Simulate(); }
//----------------------------------------------------------------------------- // Purpose: Creates, destroys, and updates the headlight effect as needed. //----------------------------------------------------------------------------- void C_PropJeepEpisodic::UpdateHeadlight() { if (m_bHeadlightIsOn) { if (!m_pHeadlight) { // Turned on the headlight; create it. m_pHeadlight = new CHeadlightEffect(); if (!m_pHeadlight) return; m_pHeadlight->TurnOn(); } // The headlight is emitted from an attachment point so that it can move // as we turn the handlebars. int nHeadlightIndex = LookupAttachment( "vehicle_headlight" ); Vector vecLightPos; QAngle angLightDir; GetAttachment(nHeadlightIndex, vecLightPos, angLightDir); Vector vecLightDir, vecLightRight, vecLightUp; AngleVectors( angLightDir, &vecLightDir, &vecLightRight, &vecLightUp ); // Update the light with the new position and direction. m_pHeadlight->UpdateLight( vecLightPos, vecLightDir, vecLightRight, vecLightUp, HEADLIGHT_DISTANCE ); } else if (m_pHeadlight) { // Turned off the headlight; delete it. delete m_pHeadlight; m_pHeadlight = NULL; } }