void CConveyorMaterialProxy::OnBind( void *pC_BaseEntity ) { if( !pC_BaseEntity ) return; C_BaseEntity *pEntity = BindArgToEntity( pC_BaseEntity ); if ( !pEntity ) return; C_FuncConveyor *pConveyor = dynamic_cast<C_FuncConveyor*>(pEntity); if ( !pConveyor ) return; if ( !m_pTextureScrollVar ) { return; } float flConveyorSpeed = pConveyor->GetConveyorSpeed(); float flRate = abs( flConveyorSpeed ) / 128.0; float flAngle = (flConveyorSpeed >= 0) ? 180 : 0; float sOffset = gpGlobals->curtime * cos( flAngle * ( M_PI / 180.0f ) ) * flRate; float tOffset = gpGlobals->curtime * sin( flAngle * ( M_PI / 180.0f ) ) * flRate; // make sure that we are positive if( sOffset < 0.0f ) { sOffset += 1.0f + -( int )sOffset; } if( tOffset < 0.0f ) { tOffset += 1.0f + -( int )tOffset; } // make sure that we are in a [0,1] range sOffset = sOffset - ( int )sOffset; tOffset = tOffset - ( int )tOffset; if (m_pTextureScrollVar->GetType() == MATERIAL_VAR_TYPE_MATRIX) { VMatrix mat; MatrixBuildTranslation( mat, sOffset, tOffset, 0.0f ); m_pTextureScrollVar->SetMatrixValue( mat ); } else { m_pTextureScrollVar->SetVecValue( sOffset, tOffset, 0.0f ); } }
void CTextureScrollMaterialProxy::OnBind( void *pC_BaseEntity ) { if( !m_pTextureScrollVar ) { return; } float rate, angle, scale; // set default values if these variables don't exist. rate = m_TextureScrollRate.GetFloat(); angle = m_TextureScrollAngle.GetFloat(); scale = m_TextureScale.GetFloat(); float sOffset, tOffset; sOffset = gpGlobals->curtime * cos( angle * ( M_PI / 180.0f ) ) * rate; tOffset = gpGlobals->curtime * sin( angle * ( M_PI / 180.0f ) ) * rate; // make sure that we are positive if( sOffset < 0.0f ) { sOffset += 1.0f + -( int )sOffset; } if( tOffset < 0.0f ) { tOffset += 1.0f + -( int )tOffset; } // make sure that we are in a [0,1] range sOffset = sOffset - ( int )sOffset; tOffset = tOffset - ( int )tOffset; if (m_pTextureScrollVar->GetType() == MATERIAL_VAR_TYPE_MATRIX) { VMatrix mat( scale, 0.0f, 0.0f, sOffset, 0.0f, scale, 0.0f, tOffset, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f ); m_pTextureScrollVar->SetMatrixValue( mat ); } else { m_pTextureScrollVar->SetVecValue( sOffset, tOffset, 0.0f ); } if ( ToolsEnabled() ) { ToolFramework_RecordMaterialParams( GetMaterial() ); } }