//----------------------------------------------------------------------------- // Purpose: Draw any debug text overlays // Output : Current text offset from the top //----------------------------------------------------------------------------- int CMomentaryRotButton::DrawDebugTextOverlays(void) { int text_offset = BaseClass::DrawDebugTextOverlays(); if (m_debugOverlays & OVERLAY_TEXT_BIT) { char tempstr[255]; Q_snprintf(tempstr,sizeof(tempstr),"QAngle: %.2f %.2f %.2f", GetLocalAngles()[0], GetLocalAngles()[1], GetLocalAngles()[2]); EntityText(text_offset,tempstr,0); text_offset++; Q_snprintf(tempstr,sizeof(tempstr),"AVelocity: %.2f %.2f %.2f", GetLocalAngularVelocity()[0], GetLocalAngularVelocity()[1], GetLocalAngularVelocity()[2]); EntityText(text_offset,tempstr,0); text_offset++; Q_snprintf(tempstr,sizeof(tempstr),"Target Pos: %3.3f",m_IdealYaw); EntityText(text_offset,tempstr,0); text_offset++; float flCurPos = GetPos(GetLocalAngles()); Q_snprintf(tempstr,sizeof(tempstr),"Current Pos: %3.3f",flCurPos); EntityText(text_offset,tempstr,0); text_offset++; Q_snprintf(tempstr,sizeof(tempstr),"Direction: %s",(m_direction == 1) ? "Forward" : "Backward"); EntityText(text_offset,tempstr,0); text_offset++; } return text_offset; }
//----------------------------------------------------------------------------- // Purpose: Turns a npc towards its ideal yaw. // Input : yawSpeed - Yaw speed in degrees per 1/10th of a second. // flInterval - Time interval to turn, -1 uses time since last think. // Output : Returns the number of degrees turned. //----------------------------------------------------------------------------- void CAI_Motor::UpdateYaw( int yawSpeed ) { // Don't do this if our yaw is locked if ( IsYawLocked() ) return; GetOuter()->SetUpdatedYaw(); float ideal, current, newYaw; if ( yawSpeed == -1 ) yawSpeed = GetYawSpeed(); // NOTE: GetIdealYaw() will never exactly be reached because UTIL_AngleMod // also truncates the angle to 16 bits of resolution. So lets truncate it here. current = UTIL_AngleMod( GetLocalAngles().y ); ideal = UTIL_AngleMod( GetIdealYaw() ); // FIXME: this needs a proper interval float dt = MIN( 0.2, gpGlobals->curtime - GetLastThink() ); newYaw = AI_ClampYaw( (float)yawSpeed * 10.0, current, ideal, dt ); if (newYaw != current) { QAngle angles = GetLocalAngles(); angles.y = newYaw; SetLocalAngles( angles ); } }
//------------------------------------------------------------------------------ // Purpose: MoveDone function for the SetPosition input handler. Tracks our // progress toward a movement goal and updates our outputs. //------------------------------------------------------------------------------ void CMomentaryRotButton::SetPositionMoveDone(void) { float flCurPos = GetPos( GetLocalAngles() ); if ((( flCurPos >= m_IdealYaw ) && ( m_direction == 1 )) || (( flCurPos <= m_IdealYaw ) && ( m_direction == -1 ))) { // // We reached or surpassed our movement goal. // SetLocalAngularVelocity( vec3_angle ); // BUGBUG: Won't this get the player stuck? SetLocalAngles( m_start + m_vecMoveAng * ( m_IdealYaw * m_flMoveDistance ) ); SetNextThink( TICK_NEVER_THINK ); SetMoveDoneTime( -1 ); UpdateTarget( m_IdealYaw, this ); OutputMovementComplete(); return; } // TODO: change this to use a Think function like ReturnThink. QAngle vecNewAngles = m_start + m_vecMoveAng * ( m_IdealYaw * m_flMoveDistance ); float flAngleDelta = fabs( AxisDelta( m_spawnflags, vecNewAngles, GetLocalAngles() )); float dt = flAngleDelta / m_flSpeed; if ( dt < TICK_INTERVAL ) { dt = TICK_INTERVAL; float speed = flAngleDelta / TICK_INTERVAL; SetLocalAngularVelocity( speed * m_vecMoveAng * m_direction ); } dt = clamp( dt, TICK_INTERVAL, TICK_INTERVAL * 6); SetMoveDoneTime( dt ); }
void CWorldItem::Spawn( void ) { CBaseEntity *pEntity = NULL; switch (m_iType) { case 44: // ITEM_BATTERY: pEntity = CBaseEntity::Create( "item_battery", GetLocalOrigin(), GetLocalAngles() ); break; case 45: // ITEM_SUIT: pEntity = CBaseEntity::Create( "item_suit", GetLocalOrigin(), GetLocalAngles() ); break; } if (!pEntity) { Warning("unable to create world_item %d\n", m_iType ); } else { pEntity->m_target = m_target; pEntity->SetName( GetEntityName() ); pEntity->ClearSpawnFlags(); pEntity->AddSpawnFlags( m_spawnflags ); } UTIL_RemoveImmediate( this ); }
void CGERocket::IgniteThink( void ) { EmitSound( "Weapon_RocketLauncher.Ignite" ); AngleVectors( GetLocalAngles(), &m_vForward ); AngleVectors(GetLocalAngles() + QAngle(-90, 0, 0), &m_vUp); m_vRight = CrossProduct(m_vForward, m_vUp); // SetAbsVelocity( m_vForward * GE_ROCKET_MAXVEL * 0.1f ); SetThink( &CGERocket::AccelerateThink ); SetNextThink(gpGlobals->curtime + m_fthinktime); m_fthinktime = 0.1; m_fFuseTime = gpGlobals->curtime + GE_ROCKET_FUSETIME / max(phys_timescale.GetFloat(), 0.01); CreateSmokeTrail(); /* DevMsg("modifiers are.."); if (m_iseed1 < 50) // Vertical Sine Wave DevMsg(", sine"); if (m_iseed1 % 50 < 25) // Horizontal Cosine Wave, overlap with sine wave causes spiral. DevMsg(", cosine"); if (m_iseed1 % 25 < 5) // Comes back DevMsg(", return"); if (m_iseed1 % 20 < 5) // Gravity DevMsg(", gravity"); if (m_iseed1 % 10 < 4) // Random Jitter DevMsg(", jitter"); DevMsg(", and seed 1 is %d, seed 2 is %d, seed 3 is %d.", m_iseed1, m_iseed2, m_iseed3); */ }
//----------------------------------------------------------------------------- // Purpose: Calculate m_vecVelocity and m_flNextThink to reach vecDest from // GetLocalOrigin() traveling at flSpeed. Just like LinearMove, but rotational. // Input : vecDestAngle - // flSpeed - //----------------------------------------------------------------------------- void CBaseToggle::AngularMove( const QAngle &vecDestAngle, float flSpeed ) { ASSERTSZ(flSpeed != 0, "AngularMove: no speed is defined!"); m_vecFinalAngle = vecDestAngle; m_movementType = MOVE_TOGGLE_ANGULAR; // Already there? if (vecDestAngle == GetLocalAngles()) { MoveDone(); return; } // set destdelta to the vector needed to move QAngle vecDestDelta = vecDestAngle - GetLocalAngles(); // divide by speed to get time to reach dest float flTravelTime = vecDestDelta.Length() / flSpeed; const float MinTravelTime = 0.01f; if ( flTravelTime < MinTravelTime ) { // If we only travel for a short time, we can fail WillSimulateGamePhysics() flTravelTime = MinTravelTime; flSpeed = vecDestDelta.Length() / flTravelTime; } // set m_flNextThink to trigger a call to AngularMoveDone when dest is reached SetMoveDoneTime( flTravelTime ); // scale the destdelta vector by the time spent traveling to get velocity SetLocalAngularVelocity( vecDestDelta * (1.0 / flTravelTime) ); }
void CRotButton::Spawn( void ) { Precache(); // set the axis of rotation AxisDir( pev ); // check for clockwise rotation if( FBitSet( pev->spawnflags, SF_ROTBUTTON_ROTATE_BACKWARDS )) pev->movedir = pev->movedir * -1; pev->movetype = MOVETYPE_PUSH; if( FBitSet( pev->spawnflags, SF_ROTBUTTON_PASSABLE )) pev->solid = SOLID_NOT; else pev->solid = SOLID_BSP; // shared code use this flag as BUTTON_DONTMOVE so we need to clear it here ClearBits( pev->spawnflags, SF_ROTBUTTON_PASSABLE ); ClearBits( pev->spawnflags, SF_BUTTON_SPARK_IF_OFF ); ClearBits( pev->spawnflags, SF_BUTTON_DAMAGED_AT_LASER ); SET_MODEL( edict(), GetModel() ); if( pev->speed == 0 ) pev->speed = 40; if( m_flWait == 0 ) m_flWait = 1; if( pev->health > 0 ) { pev->takedamage = DAMAGE_YES; } m_iState = STATE_OFF; m_vecAngle1 = GetLocalAngles(); m_vecAngle2 = GetLocalAngles() + pev->movedir * m_flMoveDistance; ASSERTSZ( m_vecAngle1 != m_vecAngle2, "rotating button start/end positions are equal" ); m_fStayPushed = (m_flWait == -1) ? TRUE : FALSE; m_fRotating = TRUE; // if the button is flagged for USE button activation only, take away it's touch function and add a use function if( !FBitSet( pev->spawnflags, SF_BUTTON_TOUCH_ONLY )) { SetTouch( NULL ); SetUse( &CBaseButton::ButtonUse ); } else { // touchable button SetTouch( &CBaseButton::ButtonTouch ); } UTIL_SetOrigin( this, GetLocalOrigin( )); m_pUserData = WorldPhysic->CreateKinematicBodyFromEntity( this ); }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CRotDoor::Spawn( void ) { BaseClass::Spawn(); // set the axis of rotation CBaseToggle::AxisDir(); // check for clockwise rotation if ( HasSpawnFlags(SF_DOOR_ROTATE_BACKWARDS) ) m_vecMoveAng = m_vecMoveAng * -1; //m_flWait = 2; who the hell did this? (sjb) m_vecAngle1 = GetLocalAngles(); m_vecAngle2 = GetLocalAngles() + m_vecMoveAng * m_flMoveDistance; ASSERTSZ(m_vecAngle1 != m_vecAngle2, "rotating door start/end positions are equal\n"); // Starting open allows a func_door to be lighted in the closed position but // spawn in the open position // // SF_DOOR_START_OPEN_OBSOLETE is an old broken way of spawning open that has // been deprecated. if ( HasSpawnFlags(SF_DOOR_START_OPEN_OBSOLETE) ) { // swap pos1 and pos2, put door at pos2, invert movement direction QAngle vecNewAngles = m_vecAngle2; m_vecAngle2 = m_vecAngle1; m_vecAngle1 = vecNewAngles; m_vecMoveAng = -m_vecMoveAng; // We've already had our physics setup in BaseClass::Spawn, so teleport to our // current position. If we don't do this, our vphysics shadow will not update. Teleport( NULL, &m_vecAngle1, NULL ); m_toggle_state = TS_AT_BOTTOM; } else if ( m_eSpawnPosition == FUNC_DOOR_SPAWN_OPEN ) { // We've already had our physics setup in BaseClass::Spawn, so teleport to our // current position. If we don't do this, our vphysics shadow will not update. Teleport( NULL, &m_vecAngle2, NULL ); m_toggle_state = TS_AT_TOP; } else { m_toggle_state = TS_AT_BOTTOM; } #ifdef HL1_DLL SetSolid( SOLID_VPHYSICS ); #endif // Slam the object back to solid - if we really want it to be solid. if ( m_bSolidBsp ) { SetSolid( SOLID_BSP ); } }
void CMomentaryRotButton :: SetPosition( float value ) { pev->ideal_yaw = bound( 0.0f, value, 1 ); float flCurPos = GetPos( GetLocalAngles( )); if( flCurPos < pev->ideal_yaw ) { // moving forward (from start to end). SetLocalAvelocity( pev->speed * pev->movedir ); m_direction = 1; } else if( flCurPos > pev->ideal_yaw ) { // moving backward (from end to start). SetLocalAvelocity( -pev->speed * pev->movedir ); m_direction = -1; } else { // we're there already; nothing to do. SetLocalAvelocity( g_vecZero ); return; } // g-cont. to avoid moving by user in back direction if( FBitSet( pev->spawnflags, SF_MOMENTARY_ROT_BUTTON_AUTO_RETURN ) && m_returnSpeed > 0 ) m_lastUsed = 1; // play sound on set new pos PlaySound(); SetMoveDone( &CMomentaryRotButton::SetPositionMoveDone ); SetThink( &CMomentaryRotButton::UpdateThink ); SetNextThink( 0 ); // Think again in 0.1 seconds or the time that it will take us to reach our movement goal, // whichever is the shorter interval. This prevents us from overshooting and stuttering when we // are told to change position in very small increments. Vector vecNewAngles = m_start + pev->movedir * ( pev->ideal_yaw * m_flMoveDistance ); float flAngleDelta = fabs( AxisDelta( pev->spawnflags, vecNewAngles, GetLocalAngles( ))); float dt = flAngleDelta / pev->speed; if( dt < gpGlobals->frametime ) { dt = gpGlobals->frametime; float speed = flAngleDelta / gpGlobals->frametime; SetLocalAvelocity( speed * pev->movedir * m_direction ); } dt = bound( gpGlobals->frametime, dt, gpGlobals->frametime * 6 ); SetMoveDoneTime( dt ); }
//----------------------------------------------------------------------------- // Purpose: // // //----------------------------------------------------------------------------- void CFastZombie::HandleAnimEvent( animevent_t *pEvent ) { switch ( pEvent->event ) { case FASTZOMBIE_AE_CLIMB_LEFT: case FASTZOMBIE_AE_CLIMB_RIGHT: if( ++m_iClimbCount % 3 == 0 ) { ENVELOPE_CONTROLLER.SoundChangePitch( m_pLayer2, random->RandomFloat( 100, 150 ), 0.0 ); ENVELOPE_CONTROLLER.SoundPlayEnvelope( m_pLayer2, SOUNDCTRL_CHANGE_VOLUME, envFastZombieVolumeClimb, ARRAYSIZE(envFastZombieVolumeClimb) ); } break; case FASTZOMBIE_AE_LEAP: LeapAttack(); break; case FASTZOMBIE_AE_GALLOP_LEFT: { EmitSound( "NPC_FastZombie.GallopLeft" ); } break; case FASTZOMBIE_AE_GALLOP_RIGHT: { EmitSound( "NPC_FastZombie.GallopRight" ); } break; case ZOMBIE_AE_ATTACK_RIGHT: { Vector right; AngleVectors( GetLocalAngles(), NULL, &right, NULL ); right = right * -50; ClawAttack( 50, 3, QAngle( -3, -5, -3 ), right ); break; } case ZOMBIE_AE_ATTACK_LEFT: { Vector right; AngleVectors( GetLocalAngles(), NULL, &right, NULL ); right = right * 50; ClawAttack( 50, 3, QAngle( -3, 5, -3 ), right ); break; } default: BaseClass::HandleAnimEvent( pEvent ); break; } }
//----------------------------------------- // Spawn //----------------------------------------- void CAPCController::Spawn( void ) { Precache(); m_yawCenter = GetLocalAngles().y; m_pitchCenter = GetLocalAngles().x; if ( IsActive() ) { SetNextThink( gpGlobals->curtime + 1.0f ); } UpdateMatrix(); }
void C_MSS_Player::PreThink( void ) { QAngle vTempAngles = GetLocalAngles(); if ( GetLocalPlayer() == this ) { vTempAngles[PITCH] = EyeAngles()[PITCH]; } else { vTempAngles[PITCH] = m_angEyeAngles[PITCH]; } if ( vTempAngles[YAW] < 0.0f ) { vTempAngles[YAW] += 360.0f; } SetLocalAngles( vTempAngles ); BaseClass::PreThink(); HandleSpeedChanges(); if ( m_HL2Local.m_flSuitPower <= 0.0f ) { if( IsSprinting() ) { StopSprinting(); } } }
//----------------------------------------------------------------------------- // Purpose: Aim the offset barrel at a position in parent space // Input : parentTarget - the position of the target in parent space // Output : Vector - angles in local space //----------------------------------------------------------------------------- QAngle CFuncTank::AimBarrelAt( const Vector &parentTarget ) { Vector target = parentTarget - GetLocalOrigin(); float quadTarget = target.LengthSqr(); float quadTargetXY = target.x*target.x + target.y*target.y; // Target is too close! Can't aim at it if ( quadTarget <= m_barrelPos.LengthSqr() ) { return GetLocalAngles(); } else { // We're trying to aim the offset barrel at an arbitrary point. // To calculate this, I think of the target as being on a sphere with // it's center at the origin of the gun. // The rotation we need is the opposite of the rotation that moves the target // along the surface of that sphere to intersect with the gun's shooting direction // To calculate that rotation, we simply calculate the intersection of the ray // coming out of the barrel with the target sphere (that's the new target position) // and use atan2() to get angles // angles from target pos to center float targetToCenterYaw = atan2( target.y, target.x ); float centerToGunYaw = atan2( m_barrelPos.y, sqrt( quadTarget - (m_barrelPos.y*m_barrelPos.y) ) ); float targetToCenterPitch = atan2( target.z, sqrt( quadTargetXY ) ); float centerToGunPitch = atan2( -m_barrelPos.z, sqrt( quadTarget - (m_barrelPos.z*m_barrelPos.z) ) ); return QAngle( -RAD2DEG(targetToCenterPitch+centerToGunPitch), RAD2DEG( targetToCenterYaw - centerToGunYaw ), 0 ); } }
void CTripwireGrenade::Spawn( void ) { Precache( ); SetMoveType( MOVETYPE_FLY ); SetSolid( SOLID_BBOX ); AddSolidFlags( FSOLID_NOT_SOLID ); SetModel( "models/Weapons/w_slam.mdl" ); m_nMissileCount = 0; UTIL_SetSize(this, Vector( -4, -4, -2), Vector(4, 4, 2)); m_flPowerUp = gpGlobals->curtime + 1.2;//<<CHECK>>get rid of this SetThink( WarningThink ); SetNextThink( gpGlobals->curtime + 1.0f ); m_takedamage = DAMAGE_YES; m_iHealth = 1; m_pRope = NULL; m_pHook = NULL; // Tripwire grenade sits at 90 on wall so rotate back to get m_vecDir QAngle angles = GetLocalAngles(); angles.x -= 90; AngleVectors( angles, &m_vecDir ); }
void CTripwireGrenade::MakeRope( void ) { SetThink( RopeBreakThink ); // Delay first think slightly so rope has time // to appear if person right in front of it SetNextThink( gpGlobals->curtime + 1.0f ); // Create hook for end of tripwire m_pHook = (CTripwireHook*)CBaseEntity::Create( "tripwire_hook", GetLocalOrigin(), GetLocalAngles() ); if (m_pHook) { Vector vShootVel = 800*(m_vecDir + Vector(0,0,0.3)+RandomVector(-0.01,0.01)); m_pHook->SetVelocity( vShootVel, vec3_origin); m_pHook->SetOwnerEntity( this ); m_pHook->m_hGrenade = this; m_pRope = CRopeKeyframe::Create(this,m_pHook,0,0); if (m_pRope) { m_pRope->m_Width = 1; m_pRope->m_RopeLength = 3; m_pRope->m_Slack = 100; CPASAttenuationFilter filter( this,"TripwireGrenade.ShootRope" ); EmitSound( filter, entindex(),"TripwireGrenade.ShootRope" ); } } }
//----------------------------------------------------------------------------- // Purpose: Keeps wobbling down by trying to keep the roller upright. // // // Output : //----------------------------------------------------------------------------- void CNPC_Roller::RemainUpright( void ) { if( !m_RollerController.IsOn() ) { // Don't bother with the math if the controller is off. return; } // We're going to examine the Z component of the Right vector // to see how upright we are. Vector vecRight; AngleVectors( GetLocalAngles(), NULL, &vecRight, NULL ); //Msg( "%f\n", vecRight.z ); if( vecRight.z > 0.0001 ) { Msg( "-torque\n" ); m_RollerController.m_vecAngular.x = ROLLER_UPRIGHT_SPEED; } else if ( vecRight.z < -0.0001 ) { Msg( "+torque\n" ); m_RollerController.m_vecAngular.x = -ROLLER_UPRIGHT_SPEED; } else { m_RollerController.m_vecAngular.x = 0; } }
void C_DODBaseRocket::PostDataUpdate( DataUpdateType_t type ) { BaseClass::PostDataUpdate( type ); if ( type == DATA_UPDATE_CREATED ) { // Now stick our initial velocity into the interpolation history CInterpolatedVar< Vector > &interpolator = GetOriginInterpolator(); interpolator.ClearHistory(); float changeTime = GetLastChangeTime( LATCH_SIMULATION_VAR ); // Add a sample 1 second back. Vector vCurOrigin = GetLocalOrigin() - m_vInitialVelocity; interpolator.AddToHead( changeTime - 1.0, &vCurOrigin, false ); // Add the current sample. vCurOrigin = GetLocalOrigin(); interpolator.AddToHead( changeTime, &vCurOrigin, false ); // do the same for angles CInterpolatedVar< QAngle > &rotInterpolator = GetRotationInterpolator(); rotInterpolator.ClearHistory(); // Add a rotation sample 1 second back QAngle vCurAngles = GetLocalAngles(); rotInterpolator.AddToHead( changeTime - 1.0, &vCurAngles, false ); // Add the current rotation rotInterpolator.AddToHead( changeTime - 1.0, &vCurAngles, false ); } }
void CBaseDoor :: Activate( void ) { CBaseDoor *pDoorList[64]; m_bDoorGroup = true; // force movement groups to sync!!! int doorCount = GetDoorMovementGroup( pDoorList, ARRAYSIZE( pDoorList )); for( int i = 0; i < doorCount; i++ ) { if( pDoorList[i]->pev->movedir == pev->movedir ) { bool error = false; if( pDoorList[i]->IsRotatingDoor() ) { error = ( pDoorList[i]->GetLocalAngles() != GetLocalAngles()) ? true : false; } else { error = ( pDoorList[i]->GetLocalOrigin() != GetLocalOrigin()) ? true : false; } if( error ) { // don't do group blocking m_bDoorGroup = false; // UNDONE: This should probably fixup m_vecPosition1 & m_vecPosition2 ALERT( at_aiconsole, "Door group %s has misaligned origin!\n", GetTargetname( )); } } } }
void CMomentaryRotButton :: UpdateButton( void ) { // reverse our direction and play movement sound every time the player // pauses between uses. bool bPlaySound = false; if( !m_lastUsed ) { bPlaySound = true; m_direction = -m_direction; } m_lastUsed = 1; float flPos = GetPos( GetLocalAngles() ); UpdateSelf( flPos, bPlaySound ); // Think every frame while we are moving. // HACK: Don't reset the think time if we already have a pending think. // This works around an issue with host_thread_mode > 0 when the player's // clock runs ahead of the server. if( !m_pfnThink ) { SetThink( &CMomentaryRotButton::UpdateThink ); SetNextThink( 0 ); } }
//----------------------------------------------------------------------------- // Purpose: Handles the end of motion caused by player use. //----------------------------------------------------------------------------- void CMomentaryRotButton::UseMoveDone( void ) { SetLocalAngularVelocity( vec3_angle ); // Make sure our targets stop where we stopped. float flPos = GetPos( GetLocalAngles() ); UpdateTarget( flPos, this ); // Alert that we've been unpressed m_OnUnpressed.FireOutput( m_hActivator, this ); m_lastUsed = 0; if ( !HasSpawnFlags( SF_BUTTON_TOGGLE ) && m_returnSpeed > 0 ) { SetMoveDone( &CMomentaryRotButton::ReturnMoveDone ); m_direction = -1; // Delay before autoreturn. SetMoveDoneTime( 0.1f ); } else { SetThink( NULL ); SetMoveDone( NULL ); } }
//----------------------------------------------------------------------------- // Purpose: Think function. Called while rotating at a constant angular velocity. //----------------------------------------------------------------------------- void CFuncRotating::RotateMove( void ) { SetMoveDoneTime( 10 ); if ( m_bStopAtStartPos ) { SetMoveDoneTime( GetNextMoveInterval() ); int checkAxis = 2; // See if we got close to the starting orientation if ( m_vecMoveAng[0] != 0 ) { checkAxis = 0; } else if ( m_vecMoveAng[1] != 0 ) { checkAxis = 1; } float angDelta = anglemod( GetLocalAngles()[ checkAxis ] - m_angStart[ checkAxis ] ); if ( angDelta > 180.0f ) angDelta -= 360.0f; QAngle avel = GetLocalAngularVelocity(); // Delta per tick QAngle avelpertick = avel * TICK_INTERVAL; if ( fabs( angDelta ) < fabs( avelpertick[ checkAxis ] ) ) { SetTargetSpeed( 0 ); SetLocalAngles( m_angStart ); m_bStopAtStartPos = false; } } }
//----------------------------------------------------------------------------- // Purpose: MoveDone function for rotating back to the start position. //----------------------------------------------------------------------------- void CMomentaryRotButton::ReturnMoveDone( void ) { float value = GetPos( GetLocalAngles() ); if ( value <= 0 ) { // // Got back to the start, stop spinning. // SetLocalAngularVelocity( vec3_angle ); SetLocalAngles( m_start ); UpdateTarget( 0, NULL ); SetMoveDoneTime( -1 ); SetMoveDone( NULL ); SetNextThink( TICK_NEVER_THINK ); SetThink( NULL ); } else { SetLocalAngularVelocity( -m_returnSpeed * m_vecMoveAng ); SetMoveDoneTime( 0.1f ); SetThink( &CMomentaryRotButton::UpdateThink ); SetNextThink( gpGlobals->curtime + 0.01f ); } }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CTFBaseRocket::PostDataUpdate( DataUpdateType_t type ) { // Pass through to the base class. BaseClass::PostDataUpdate( type ); if ( type == DATA_UPDATE_CREATED ) { // Now stick our initial velocity and angles into the interpolation history. CInterpolatedVar<Vector> &interpolator = GetOriginInterpolator(); interpolator.ClearHistory(); CInterpolatedVar<QAngle> &rotInterpolator = GetRotationInterpolator(); rotInterpolator.ClearHistory(); float flChangeTime = GetLastChangeTime( LATCH_SIMULATION_VAR ); // Add a sample 1 second back. Vector vCurOrigin = GetLocalOrigin() - m_vInitialVelocity; interpolator.AddToHead( flChangeTime - 1.0f, &vCurOrigin, false ); QAngle vCurAngles = GetLocalAngles(); rotInterpolator.AddToHead( flChangeTime - 1.0f, &vCurAngles, false ); // Add the current sample. vCurOrigin = GetLocalOrigin(); interpolator.AddToHead( flChangeTime, &vCurOrigin, false ); rotInterpolator.AddToHead( flChangeTime - 1.0, &vCurAngles, false ); } }
//----------------------------------------------------------------------------- // Purpose: // Input : push - // Output : trace_t //----------------------------------------------------------------------------- void C_BaseEntity::PhysicsPushEntity( const Vector& push, trace_t *pTrace ) { /* if ( m_pMoveParent ) { Warning( "pushing entity (%s) that has m_pMoveParent!\n", STRING( pev->classname ) ); Assert(0); } */ // NOTE: absorigin and origin must be equal because there is no moveparent Vector prevOrigin; VectorCopy( GetAbsOrigin(), prevOrigin ); trace_t trace; PhysicsCheckSweep( prevOrigin, push, pTrace ); if ( pTrace->fraction ) { SetAbsOrigin( pTrace->endpos ); } // CLIENT DLL HACKS m_vecNetworkOrigin = GetLocalOrigin(); m_angNetworkAngles = GetLocalAngles(); // InvalidatePhysicsRecursive( POSITION_CHANGED | ANGLES_CHANGED ); if ( pTrace->m_pEnt ) { PhysicsImpact( pTrace->m_pEnt, *pTrace ); } }
//--------------------------------------------------------- //--------------------------------------------------------- void CNPC_MissileDefense::GetGunAim( Vector *vecAim ) { Vector vecPos; QAngle vecAng; GetAttachment( MD_AP_LGUN, vecPos, vecAng ); vecAng.x = GetLocalAngles().x + GetBoneController( MD_BC_PITCH ); vecAng.z = 0; vecAng.y = GetLocalAngles().y + GetBoneController( MD_BC_YAW ); Vector vecForward; AngleVectors( vecAng, &vecForward ); *vecAim = vecForward; }
void CShower::Spawn( void ) { Vector vecForward; AngleVectors( GetLocalAngles(), &vecForward ); Vector vecNewVelocity; vecNewVelocity = random->RandomFloat( 200, 300 ) * vecForward; vecNewVelocity.x += random->RandomFloat(-100.f,100.f); vecNewVelocity.y += random->RandomFloat(-100.f,100.f); if ( vecNewVelocity.z >= 0 ) vecNewVelocity.z += 200; else vecNewVelocity.z -= 200; SetAbsVelocity( vecNewVelocity ); SetMoveType( MOVETYPE_FLYGRAVITY, MOVECOLLIDE_FLY_BOUNCE ); SetGravity( UTIL_ScaleForGravity( 400 ) ); // fall a bit more slowly than normal SetNextThink( gpGlobals->curtime + 0.1f ); SetSolid( SOLID_NONE ); UTIL_SetSize(this, vec3_origin, vec3_origin ); AddEffects( EF_NODRAW ); m_flSpeed = random->RandomFloat( 0.5, 1.5 ); SetLocalAngles( vec3_angle ); }
void CBaseTrainDoor :: Spawn( void ) { Precache(); pev->movetype = MOVETYPE_PUSH; pev->solid = SOLID_BSP; SET_MODEL( edict(), GetModel( )); // is mapper forget set angles? if( pev->movedir == g_vecZero ) { pev->movedir = Vector( 1, 0, 0 ); SetLocalAngles( g_vecZero ); } // save initial angles m_vecOldAngles = GetLocalAngles(); // ??? m_vecPosition1 = GetLocalOrigin(); // member the initial position if( !pev->speed ) pev->speed = 100; m_pUserData = WorldPhysic->CreateKinematicBodyFromEntity( this ); door_state = TD_CLOSED; SetTouch( NULL ); SetThink( &CBaseTrainDoor :: FindTrain ); SetNextThink( 0.1 ); }
void CMomentaryRotButton :: UseMoveDone( void ) { SetLocalAvelocity( g_vecZero ); // make sure our targets stop where we stopped. float flPos = GetPos( GetLocalAngles( )); UpdateTarget( flPos ); m_lastUsed = 0; if( FBitSet( pev->spawnflags, SF_MOMENTARY_ROT_BUTTON_AUTO_RETURN ) && m_returnSpeed > 0 ) { SetMoveDone( &CMomentaryRotButton::ReturnMoveDone ); m_direction = -1; if( flPos >= 1.0f ) { // disable use until button is waiting SetUse( NULL ); // delay before autoreturn. SetMoveDoneTime( m_flDelay + 0.1f ); } else SetMoveDoneTime( 0.1f ); } else { SetThink( NULL ); SetMoveDone( NULL ); } }
//----------------------------------------------------------------------------- // Purpose: Converts inputed euler angles to internal angle format (quaternions) //----------------------------------------------------------------------------- void CPathKeyFrame::Spawn( void ) { m_Origin = GetLocalOrigin(); m_Angles = GetLocalAngles(); SetKeyAngles( m_Angles ); }
void CMomentaryRotButton :: ReturnMoveDone( void ) { float value = GetPos( GetLocalAngles() ); SetUse( &CMomentaryRotButton::ButtonUse ); if( value <= 0 ) { // Got back to the start, stop spinning. SetLocalAvelocity( g_vecZero ); SetLocalAngles( m_start ); m_iState = STATE_OFF; UpdateTarget( 0 ); SetMoveDoneTime( -1 ); SetMoveDone( NULL ); SetNextThink( -1 ); SetThink( NULL ); } else { m_iState = STATE_TURN_OFF; SetLocalAvelocity( -m_returnSpeed * pev->movedir ); SetMoveDoneTime( 0.1f ); SetThink( &CMomentaryRotButton::UpdateThink ); SetNextThink( 0.01f ); } }