float CASW_Sentry_Top::GetPitchTo(CBaseEntity* pEnt) { if (!pEnt) return 0; Vector diff = pEnt->WorldSpaceCenter() - GetFiringPosition(); if (diff.x == 0 && diff.y == 0 && diff.z == 0) return 0; return UTIL_VecToPitch(diff); }
void CPropVehicleManhack::UpdateHead( void ) { float yaw = GetPoseParameter( "head_yaw" ); float pitch = GetPoseParameter( "head_pitch" ); // If we should be watching our enemy, turn our head CNPC_Manhack *pManhack=GetManhack(); if (pManhack != NULL) { Vector vehicleEyeOrigin; QAngle vehicleEyeAngles; GetAttachment( "vehicle_driver_eyes", vehicleEyeOrigin, vehicleEyeAngles ); // FIXME: cache this Vector vBodyDir; AngleVectors( vehicleEyeAngles, &vBodyDir ); Vector manhackDir = pManhack->GetAbsOrigin() - vehicleEyeOrigin; VectorNormalize( manhackDir ); float angle = UTIL_VecToYaw( vBodyDir ); float angleDiff = UTIL_VecToYaw( manhackDir ); angleDiff = UTIL_AngleDiff( angleDiff, angle + yaw ); SetPoseParameter( "head_yaw", UTIL_Approach( yaw + angleDiff, yaw, 1 ) ); angle = UTIL_VecToPitch( vBodyDir ); angleDiff = UTIL_VecToPitch( manhackDir ); angleDiff = UTIL_AngleDiff( angleDiff, angle + pitch ); SetPoseParameter( "head_pitch", UTIL_Approach( pitch + angleDiff, pitch, 1 ) ); } else { // Otherwise turn the head back to its normal position SetPoseParameter( "head_yaw", UTIL_Approach( 0, yaw, 10 ) ); SetPoseParameter( "head_pitch", UTIL_Approach( 0, pitch, 10 ) ); } }
static int luasrc_UTIL_VecToPitch (lua_State *L) { lua_pushnumber(L, UTIL_VecToPitch(luaL_checkvector(L, 1))); return 1; }