//----------------------------------------------------------------------------- // Purpose: Returns the color given trace information // Input : *trace - trace to get results for // *color - return color, gamma corrected (0.0f to 1.0f) //----------------------------------------------------------------------------- void GetColorForSurface( trace_t *trace, Vector *color ) { Vector baseColor, diffuseColor; Vector end = trace->startpos + ( ( Vector )trace->endpos - ( Vector )trace->startpos ) * 1.1f; if ( trace->DidHitWorld() ) { if ( trace->hitbox == 0 ) { // If we hit the world, then ask the world for the fleck color engine->TraceLineMaterialAndLighting( trace->startpos, end, diffuseColor, baseColor ); } else { // In this case we hit a static prop. staticpropmgr->GetStaticPropMaterialColorAndLighting( trace, trace->hitbox - 1, diffuseColor, baseColor ); } } else { // In this case, we hit an entity. Find out the model associated with it C_BaseEntity *pEnt = trace->m_pEnt; if ( !pEnt ) { Msg("Couldn't find surface in GetColorForSurface()\n"); color->x = 255; color->y = 255; color->z = 255; return; } ICollideable *pCollide = pEnt->GetCollideable(); int modelIndex = pCollide->GetCollisionModelIndex(); model_t* pModel = const_cast<model_t*>(modelinfo->GetModel( modelIndex )); // Ask the model info about what we need to know modelinfo->GetModelMaterialColorAndLighting( pModel, pCollide->GetCollisionOrigin(), pCollide->GetCollisionAngles(), trace, diffuseColor, baseColor ); } //Get final light value color->x = pow( diffuseColor[0], 1.0f/2.2f ) * baseColor[0]; color->y = pow( diffuseColor[1], 1.0f/2.2f ) * baseColor[1]; color->z = pow( diffuseColor[2], 1.0f/2.2f ) * baseColor[2]; }