void SkillAnimPanel::PaintParticle(SpendParticle* p) { if (!p) return; Color col(255, 255, 255, GetLifeFraction(p) * 255.0f); vgui::surface()->DrawSetColor(col); float fScale = ScreenHeight() / 768.0f; float size = fScale * asw_skill_particle_size.GetFloat() * (1.0f - GetLifeFraction(p)); // particles get bigger as life runs out float x = p->m_fXPos; float y = p->m_fYPos; vgui::Vertex_t points[4] = { vgui::Vertex_t( Vector2D(x-size, y-size), Vector2D(0,0) ), vgui::Vertex_t( Vector2D(x+size, y-size), Vector2D(1,0) ), vgui::Vertex_t( Vector2D(x+size, y+size), Vector2D(1,1) ), vgui::Vertex_t( Vector2D(x-size, y+size), Vector2D(0,1) ) }; vgui::surface()->DrawTexturedPolygon( 4, points ); }
Vector CASW_Rocket::IntegrateRocketThrust( const Vector &vTargetDir, ///< direction of target float flDist ) ///< distance to target const { Vector vNewVelocity; const float flSimulateScale = IsSimulatingOnAlternateTicks() ? 2 : 1 ; // apply thrust in our desired direction Vector vecThrust = vTargetDir * ASW_ROCKET_ACCELERATION * flSimulateScale; if (asw_rocket_debug.GetInt() == 2) { Msg("vecThrust = %s\n", VecToString(vecThrust)); } vNewVelocity = GetAbsVelocity() + vecThrust; // apply drag float fDrag = ASW_ROCKET_DRAG - (0.1f * GetLifeFraction()); // increase drag as lifetime goes on (to help stop rockets spinning around their target) if (flDist < 300.0f && flDist > 0) fDrag -= (1.0f - (flDist / 300.0f)) * 0.1f; // reduce drag further as we get close vNewVelocity *= ASW_ROCKET_DRAG; // cap velocity to our min/max float speed = vNewVelocity.Length(); if ((speed > ASW_ROCKET_MAX_SPEED || speed < ASW_ROCKET_MIN_SPEED) && speed > 0) { vNewVelocity *= (ASW_ROCKET_MAX_SPEED / speed); } // thrust away from the ground if we get too low trace_t tr; UTIL_TraceLine( GetAbsOrigin(), GetAbsOrigin() - Vector( 0, 0, ROCKET_HOVER_HEIGHT ), MASK_SHOT, this, COLLISION_GROUP_NONE, &tr ); if ( tr.fraction != 1.0f ) { if ( vNewVelocity.z < 0 ) { vNewVelocity.z += tr.fraction * ASW_ROCKET_HOVER_THRUST; if ( asw_rocket_debug.GetBool() ) Msg( "Rocket[%d] hover thrusting %f vel.z is now %f\n", entindex(), tr.fraction * ASW_ROCKET_HOVER_THRUST, vNewVelocity.z ); if ( vNewVelocity.z > 0 ) { vNewVelocity.z = 0; } } } return vNewVelocity; }
void CASW_Rocket::SeekThink( void ) { // If we have a grace period, go solid when it ends if ( m_flGracePeriodEndsAt ) { if ( m_flGracePeriodEndsAt < gpGlobals->curtime ) { RemoveSolidFlags( FSOLID_NOT_SOLID ); m_flGracePeriodEndsAt = 0; } } Vector vNewVelocity = GetAbsVelocity(); if ( m_bFlyingWild ) { // wobble crazily. Poll for a new target every quarter second, and if none is found, go // careering off. if ( gpGlobals->curtime >= m_flNextWobbleTime ) { Assert( !m_hHomingTarget.Get() ); CBaseEntity *pHomingTarget = FindPotentialTarget(); if ( pHomingTarget ) { SetTarget( pHomingTarget ); m_bFlyingWild = false; } else { // pick a new wobble direction /* m_vWobbleAngles = GetAbsAngles(); m_vWobbleAngles.y = m_vWobbleAngles.y + RandomFloat( -asw_rocket_wobble_amp.GetFloat(), asw_rocket_wobble_amp.GetFloat() ) ; if ( m_vWobbleAngles.y < 0 ) { m_vWobbleAngles.y = 360 + m_vWobbleAngles.y; } else if ( m_vWobbleAngles.y > 360 ) { m_vWobbleAngles.y = fmod( m_vWobbleAngles.y, 360 ); } */ m_vWobbleAngles = GetAbsAngles(); m_vWobbleAngles.y = fmodf( m_vWobbleAngles.y + RandomFloat( -asw_rocket_wobble_amp.GetFloat(), asw_rocket_wobble_amp.GetFloat() ), 360 ); m_flNextWobbleTime = gpGlobals->curtime + asw_rocket_wobble_freq.GetFloat(); } } } if ( !m_bFlyingWild ) { Vector targetPos; FindHomingPosition( &targetPos ); // find target direction Vector vTargetDir; VectorSubtract( targetPos, GetAbsOrigin(), vTargetDir ); float flDist = VectorNormalize( vTargetDir ); // find current direction Vector vDir = GetAbsVelocity(); //float flSpeed = VectorNormalize( vDir ); vNewVelocity = IntegrateRocketThrust( vTargetDir, flDist ); // face direction of movement QAngle finalAngles; VectorAngles( vNewVelocity, finalAngles ); SetAbsAngles( finalAngles ); // set to the new calculated velocity SetAbsVelocity( vNewVelocity ); } else // wobble crazily { #pragma message("TODO: straighten out this math") if ( gpGlobals->curtime >= m_flNextWobbleTime ) { // pick a new wobble direction m_vWobbleAngles = GetAbsAngles(); m_vWobbleAngles.y = fmodf( m_vWobbleAngles.y + RandomFloat( -asw_rocket_wobble_amp.GetFloat(), asw_rocket_wobble_amp.GetFloat() ), 360 ); m_flNextWobbleTime = gpGlobals->curtime + asw_rocket_wobble_freq.GetFloat(); } QAngle finalAngles = GetAbsAngles(); finalAngles.y = ApproachAngle( m_vWobbleAngles.y, finalAngles.y, 360.f * (gpGlobals->curtime - GetLastThink()) ); Vector forward; AngleVectors( finalAngles, &forward ); vNewVelocity = forward * FastSqrtEst( vNewVelocity.LengthSqr() ); if ( IsWallDodging() ) { ComputeWallDodge( vNewVelocity ); finalAngles.y = ApproachAngle( m_vWobbleAngles.y, finalAngles.y, 360.f * (gpGlobals->curtime - GetLastThink()) ); } vNewVelocity = IntegrateRocketThrust( forward, 0 ); // face direction of movement SetAbsAngles( finalAngles ); // set to the new calculated velocity SetAbsVelocity( vNewVelocity ); } // blow us up after our lifetime if (GetLifeFraction() >= 1.0f) { Explode(); } else { // Think as soon as possible SetNextThink( gpGlobals->curtime ); } }