//----------------------------------------------------------------------------- // Computes the bounding box of a beam local to the origin of the beam //----------------------------------------------------------------------------- void CBeam::ComputeBounds( Vector& mins, Vector& maxs ) { Vector vecAbsStart = GetAbsStartPos(); Vector vecAbsEnd = GetAbsEndPos(); // May need extra points for creating the min/max bounds bool bUseExtraPoints = false; Vector vecAbsExtra1, vecAbsExtra2; switch( GetType() ) { case BEAM_LASER: case BEAM_ENTS: case BEAM_SPLINE: case BEAM_ENTPOINT: { // Compute the bounds here... Vector attachmentPoint( 0, 0, 0 ); mins.Init( 99999, 99999, 99999 ); maxs.Init( -99999, -99999, -99999 ); for (int i = 0; i < m_nNumBeamEnts; ++i ) { C_BaseEntity *pTestEnt = m_hAttachEntity[i].Get(); if ( pTestEnt ) { if ( pTestEnt == this ) { mins = maxs = GetAbsOrigin(); } else { // We do this so we don't have to calculate attachments (and do expensive bone-setup calculations) on our attachments. Vector attMins, attMaxs; m_hAttachEntity[i]->GetRenderBoundsWorldspace( attMins, attMaxs ); mins = mins.Min( attMins ); mins = mins.Min( attMaxs ); maxs = maxs.Max( attMins ); maxs = maxs.Max( attMaxs ); } //ASSERT_COORD( mins ); //ASSERT_COORD( maxs ); } else { if (i == 0) { VectorCopy( vecAbsStart, attachmentPoint ); } else if (i == 1) { VectorCopy( vecAbsEnd, attachmentPoint ); } else { Assert(0); } mins = mins.Min( attachmentPoint ); maxs = maxs.Max( attachmentPoint ); } } } break; case BEAM_POINTS: default: { for (int i = 0; i < 3; ++i) { if (vecAbsStart[i] < vecAbsEnd[i]) { mins[i] = vecAbsStart[i]; maxs[i] = vecAbsEnd[i]; } else { mins[i] = vecAbsEnd[i]; maxs[i] = vecAbsStart[i]; } } } break; } if ( bUseExtraPoints ) { mins = mins.Min( vecAbsExtra1 ); mins = mins.Min( vecAbsExtra2 ); maxs = maxs.Max( vecAbsExtra1 ); maxs = maxs.Max( vecAbsExtra2 ); } // bloat the bounding box by the width of the beam float rad = 0.5f * MAX( m_fWidth.Get(), m_fEndWidth.Get() ); Vector vecRad( rad, rad, rad ); mins -= vecRad; maxs += vecRad; // Make sure the bounds are measured in *relative coords* Vector vecAbsOrigin = GetAbsOrigin(); mins -= vecAbsOrigin; maxs -= vecAbsOrigin; }
//----------------------------------------------------------------------------- // Computes the bounding box of a beam local to the origin of the beam //----------------------------------------------------------------------------- void CBeam::ComputeBounds( Vector& mins, Vector& maxs ) { Vector vecAbsStart = GetAbsStartPos(); Vector vecAbsEnd = GetAbsEndPos(); // May need extra points for creating the min/max bounds bool bUseExtraPoints = false; Vector vecAbsExtra1, vecAbsExtra2; #ifdef PORTAL CBaseEntity *pStartEntity = GetStartEntityPtr(); CTraceFilterSkipClassname traceFilter( pStartEntity, "prop_energy_ball", COLLISION_GROUP_NONE ); ITraceFilter *pEntityBeamTraceFilter = NULL; if ( pStartEntity ) pEntityBeamTraceFilter = pStartEntity->GetBeamTraceFilter(); CTraceFilterChain traceFilterChain( &traceFilter, pEntityBeamTraceFilter ); bUseExtraPoints = UTIL_Portal_Trace_Beam( this, vecAbsStart, vecAbsEnd, vecAbsExtra1, vecAbsExtra2, &traceFilterChain ); #endif switch( GetType() ) { case BEAM_LASER: case BEAM_ENTS: case BEAM_SPLINE: case BEAM_ENTPOINT: { // Compute the bounds here... Vector attachmentPoint( 0, 0, 0 ); mins.Init( 99999, 99999, 99999 ); maxs.Init( -99999, -99999, -99999 ); for (int i = 0; i < m_nNumBeamEnts; ++i ) { C_BaseEntity *pTestEnt = m_hAttachEntity[i].Get(); if ( pTestEnt ) { if ( pTestEnt == this ) { mins = maxs = GetAbsOrigin(); } else { // We do this so we don't have to calculate attachments (and do expensive bone-setup calculations) on our attachments. Vector attMins, attMaxs; m_hAttachEntity[i]->GetRenderBoundsWorldspace( attMins, attMaxs ); mins = mins.Min( attMins ); mins = mins.Min( attMaxs ); maxs = maxs.Max( attMins ); maxs = maxs.Max( attMaxs ); } //ASSERT_COORD( mins ); //ASSERT_COORD( maxs ); } else { if (i == 0) { VectorCopy( vecAbsStart, attachmentPoint ); } else if (i == 1) { VectorCopy( vecAbsEnd, attachmentPoint ); } else { Assert(0); } mins = mins.Min( attachmentPoint ); maxs = maxs.Max( attachmentPoint ); } } } break; case BEAM_POINTS: default: { for (int i = 0; i < 3; ++i) { if (vecAbsStart[i] < vecAbsEnd[i]) { mins[i] = vecAbsStart[i]; maxs[i] = vecAbsEnd[i]; } else { mins[i] = vecAbsEnd[i]; maxs[i] = vecAbsStart[i]; } } } break; } if ( bUseExtraPoints ) { mins = mins.Min( vecAbsExtra1 ); mins = mins.Min( vecAbsExtra2 ); maxs = maxs.Max( vecAbsExtra1 ); maxs = maxs.Max( vecAbsExtra2 ); } // Make sure the bounds are measured in *relative coords* Vector vecAbsOrigin = GetAbsOrigin(); mins -= vecAbsOrigin; maxs -= vecAbsOrigin; }
//----------------------------------------------------------------------------- // Computes the bounding box of a beam local to the origin of the beam //----------------------------------------------------------------------------- void CBeam::ComputeBounds( Vector& mins, Vector& maxs ) { switch( GetType() ) { case BEAM_LASER: case BEAM_ENTS: case BEAM_SPLINE: case BEAM_ENTPOINT: { // Compute the bounds here... Vector attachmentPoint( 0, 0, 0 ); mins.Init( 99999, 99999, 99999 ); maxs.Init( -99999, -99999, -99999 ); for (int i = 0; i < m_nNumBeamEnts; ++i ) { C_BaseEntity *pTestEnt = m_hAttachEntity[i].Get(); if ( pTestEnt ) { if ( pTestEnt == this ) { mins = maxs = GetAbsOrigin(); } else { // We do this so we don't have to calculate attachments (and do expensive bone-setup calculations) on our attachments. Vector attMins, attMaxs; m_hAttachEntity[i]->GetRenderBoundsWorldspace( attMins, attMaxs ); mins = mins.Min( attMins ); mins = mins.Min( attMaxs ); maxs = maxs.Max( attMins ); maxs = maxs.Max( attMaxs ); } //ASSERT_COORD( mins ); //ASSERT_COORD( maxs ); } else { if (i == 0) { VectorCopy( GetAbsStartPos(), attachmentPoint ); } else if (i == 1) { VectorCopy( GetAbsEndPos(), attachmentPoint ); } else { Assert(0); } mins = mins.Min( attachmentPoint ); maxs = maxs.Max( attachmentPoint ); } } } break; case BEAM_POINTS: default: { Vector vecAbsStart = GetAbsStartPos(); Vector vecAbsEnd = GetAbsEndPos(); for (int i = 0; i < 3; ++i) { if (vecAbsStart[i] < vecAbsEnd[i]) { mins[i] = vecAbsStart[i]; maxs[i] = vecAbsEnd[i]; } else { mins[i] = vecAbsEnd[i]; maxs[i] = vecAbsStart[i]; } } } break; } // Make sure the bounds are measured in *relative coords* Vector vecAbsOrigin = GetAbsOrigin(); mins -= vecAbsOrigin; maxs -= vecAbsOrigin; }