IterationRetval_t EnumElement( IHandleEntity *pHandleEntity ) { ICollideable *pCollide; const char *pDbgName; m_pEngineTrace->HandleEntityToCollideable( pHandleEntity, &pCollide, &pDbgName ); if (!pCollide) return ITERATION_CONTINUE; // Deal with static props // NOTE: I could have added static props to a different list and // enumerated them separately, but that would have been less efficient if ( StaticPropMgr()->IsStaticProp( pHandleEntity ) ) { Ray_t ray; trace_t trace; ray.Init( m_Pos, m_Pos ); m_pEngineTrace->ClipRayToCollideable( ray, MASK_ALL, pCollide, &trace ); if (trace.startsolid) { // We're in a static prop; that's solid baby // Pretend we hit the world m_Contents = CONTENTS_SOLID; m_pCollide = m_pEngineTrace->GetWorldCollideable(); return ITERATION_STOP; } return ITERATION_CONTINUE; } // We only care about solid volumes if ((pCollide->GetSolidFlags() & FSOLID_VOLUME_CONTENTS) == 0) return ITERATION_CONTINUE; model_t* pModel = (model_t*)pCollide->GetCollisionModel(); if ( pModel && pModel->type == mod_brush ) { Assert( pCollide->GetCollisionModelIndex() < MAX_MODELS && pCollide->GetCollisionModelIndex() >= 0 ); int nHeadNode = GetModelHeadNode( pCollide ); int contents = CM_TransformedPointContents( m_Pos, nHeadNode, pCollide->GetCollisionOrigin(), pCollide->GetCollisionAngles() ); if (contents != CONTENTS_EMPTY) { // Return the contents of the first thing we hit m_Contents = contents; m_pCollide = pCollide; return ITERATION_STOP; } } return ITERATION_CONTINUE; }
IterationRetval_t EnumElement( IHandleEntity *pHandleEntity ) { // Static props should never be in the trigger list Assert( !StaticPropMgr()->IsStaticProp( pHandleEntity ) ); IServerNetworkable *pNetworkable = static_cast<IServerNetworkable*>( pHandleEntity ); Assert( pNetworkable ); // Convert the IHandleEntity to an edict_t*... // Context is the thing we're testing everything against edict_t* pTouch = pNetworkable->GetEdict(); // Can't bump against itself if ( pTouch == m_pEnt ) return ITERATION_CONTINUE; IServerEntity *serverEntity = pTouch->GetIServerEntity(); if ( !serverEntity ) return ITERATION_CONTINUE; // Hmmm.. everything in this list should be a trigger.... ICollideable *pCollideable = serverEntity->GetCollideable(); Assert(pCollideable->GetSolidFlags() & FSOLID_TRIGGER ); if ( (pCollideable->GetSolidFlags() & FSOLID_TRIGGER) == 0 ) return ITERATION_CONTINUE; model_t* pModel = sv.GetModel( pCollideable->GetCollisionModelIndex() ); if ( pModel && pModel->type == mod_brush ) { int headnode = SV_HullForEntity( pTouch ); int contents; if (!m_Ray.m_IsSwept) { contents = CM_TransformedBoxContents( m_Ray.m_Start, m_mins, m_maxs, headnode, serverEntity->GetAbsOrigin(), serverEntity->GetAbsAngles() ); } else { trace_t trace; CM_TransformedBoxTrace( m_Ray, headnode, MASK_ALL, serverEntity->GetAbsOrigin(), serverEntity->GetAbsAngles(), trace ); contents = trace.contents; } if ( !(contents & MASK_SOLID) ) return ITERATION_CONTINUE; } m_TouchedEntities.AddToTail( pTouch ); return ITERATION_CONTINUE; }
//----------------------------------------------------------------------------- // 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]; }