//----------------------------------------------------------------------------- // Purpose: // Input : *pPlayer - //----------------------------------------------------------------------------- void CWeaponFrag::RollGrenade( CBasePlayer *pPlayer ) { // BUGBUG: Hardcoded grenade width of 4 - better not change the model :) Vector vecSrc( pPlayer->WorldSpaceCenter().x, pPlayer->WorldSpaceCenter().y, pPlayer->GetAbsMins().z + 4 ); Vector vecFacing = pPlayer->BodyDirection2D( ); // no up/down direction vecFacing.z = 0; VectorNormalize( vecFacing ); vecSrc = vecSrc + (vecFacing * 18.0); trace_t tr; UTIL_TraceLine( vecSrc, vecSrc - Vector(0,0,16), MASK_PLAYERSOLID, pPlayer, COLLISION_GROUP_NONE, &tr ); if ( tr.fraction != 1.0 ) { // compute forward vec parallel to floor plane and roll grenade along that Vector tangent; CrossProduct( vecFacing, tr.plane.normal, tangent ); CrossProduct( tr.plane.normal, tangent, vecFacing ); } Vector vecThrow = vecFacing * 500 + pPlayer->GetAbsVelocity(); // put it on its side QAngle orientation(0,pPlayer->GetLocalAngles().y,-90); // roll it AngularImpulse rotSpeed(0,0,720); Fraggrenade_Create( vecSrc, orientation, vecThrow, rotSpeed, pPlayer, GRENADE_TIMER ); // Play throw sound EmitSound( "WeaponFrag.Roll" ); m_bRedraw = true; }
void CM3::PrimaryAttack() { if (m_iClip <= 0) { PlayEmptySound(); m_flNextPrimaryAttack = 0.15; return; } SendWeaponAnim( M3_SHOOT1 ); m_pPlayer->SetAnimation( PLAYER_ATTACK1 ); m_pPlayer->m_iWeaponFlash = NORMAL_GUN_FLASH; m_pPlayer->m_iWeaponVolume = NORMAL_GUN_VOLUME; m_pPlayer->pev->effects = (int)(m_pPlayer->pev->effects) | EF_MUZZLEFLASH; EMIT_SOUND_DYN( ENT( m_pPlayer->pev ), CHAN_WEAPON,"weapons/m3-1.wav", 1.0, ATTN_NORM, 0, 100 ); m_iClip -= 1; Vector vecSrc( m_pPlayer->GetGunPosition() ); Vector vecAim( m_pPlayer->GetAutoaimVector( AUTOAIM_2DEGREES ) ); Vector vecAcc( 0.08716, 0.04362, 0.00 ); Vector vecDir; vecDir = m_pPlayer->FireBulletsPlayer( 9, vecSrc, vecAim, vecAcc, 8192,0, 0, 20, m_pPlayer->pev, m_pPlayer->random_seed ); #ifndef CLIENT_DLL MESSAGE_BEGIN( MSG_PVS, SVC_TEMPENTITY, vecSrc ); WRITE_BYTE( TE_DLIGHT ); WRITE_COORD( vecSrc.x ); WRITE_COORD( vecSrc.y ); WRITE_COORD( vecSrc.z ); WRITE_BYTE( 30 ); WRITE_BYTE( 210 ); WRITE_BYTE( 200 ); WRITE_BYTE( 60 ); WRITE_BYTE( 1 ); WRITE_BYTE( 1 ); MESSAGE_END(); #endif if( !LeftSpread ) LeftSpread = 1; m_pPlayer->pev->punchangle.x -= 5; PLAYBACK_EVENT_FULL( FEV_NOTHOST, m_pPlayer->edict(), m_event, 0.0, (float *)&g_vecZero, (float *)&g_vecZero, vecDir.x, vecDir.y, 0, 0, (m_iClip ? 0 : 1), 0 ); m_flNextPrimaryAttack = UTIL_WeaponTimeBase() + 0.875; m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + UTIL_SharedRandomFloat(m_pPlayer->random_seed, 1.085,2.085); }
int test_sort_merge() // 归并排序 { // reference: http://www.cprogramming.com/tutorial/computersciencetheory/merge.html std::vector<int> vecSrc(array_src.begin(), array_src.end()); std::vector<int> vecDst(array_src.size()); merge(vecSrc, 0, vecSrc.size(), vecDst); fprintf(stderr, "merge sort result: \n"); print_result(vecDst); return 0; }
ImageData* Manipulation::fwdTransform(ImageData* inputImage, Matrix3x3& M, int& leftMost, int& topMost) { if(inputImage== NULL) { std::cout<< "Manipulation::fwdTransform() parameter inputImageData shouldn't be null !" << std::endl; exit(-1); } ImageData* imageData = new ImageData(); leftMost = INT_MAX; int rightMost = INT_MIN; topMost = INT_MAX; int bottomMost = INT_MIN; for(int i =0; i<= inputImage->height; i+= (inputImage->height)) { for(int j =0; j<= inputImage->width; j+= (inputImage->width)) { // forward transform Vector3d vecSrc(j, i, 1);// source position Vector3d vecDst = M * vecSrc;// destination position vecDst[0] /= vecDst[2]; vecDst[1] /= vecDst[2]; vecDst[2] /= 1; if(vecDst[1] > bottomMost)// determine the boundary of new image bottomMost = vecDst[1]; if(vecDst[1] < topMost) topMost = vecDst[1]; if(leftMost > vecDst[0]) leftMost = vecDst[0]; if(rightMost < vecDst[0]) rightMost = vecDst[0]; } } imageData->width = rightMost - leftMost ;// calculate the width imageData->height = bottomMost - topMost ;// calculate the height imageData->channels = inputImage->channels;// and channel std::cout << "width, height, channels of new image is = " << imageData->width << " " << imageData->height << " "<<imageData->channels << std::endl; imageData->pixels = new float[imageData->width * imageData->height * imageData->channels]; return imageData; }
void CAWP::PrimaryAttack() { if( m_iClip <= 0 ) return; m_iClip--; m_pPlayer->SetAnimation( PLAYER_ATTACK1 ); Vector vecSrc( m_pPlayer->GetGunPosition() ); Vector vecAim( m_pPlayer->GetAutoaimVector( AUTOAIM_2DEGREES ) ); Vector vecAcc( g_vecZero ); if ( !( m_pPlayer->pev->flags & FL_ONGROUND ) ) vecAcc = vec3_t( 0.85, 0.85, 0.85 ); else if ( m_pPlayer->pev->velocity.Length2D() > 140 || !scope ) vecAcc = vec3_t( 0.25, 0.25, 0.25 ); else if ( m_pPlayer->pev->velocity.Length2D() > 10 ) vecAcc = vec3_t( 0.10, 0.10, 0.10 ); else vecAcc = vec3_t( 0, 0, 0 ); Vector vecDir( m_pPlayer->FireBulletsPlayer( 1, vecSrc, vecAim, vecAcc, 8192,0, 0, 114, m_pPlayer->pev, m_pPlayer->random_seed ) ); SendWeaponAnim( AWP_SHOOT1 ); PLAYBACK_EVENT_FULL( FEV_NOTHOST, m_pPlayer->edict(), m_event, 0.0, (float *)&g_vecZero, (float *)&g_vecZero, vecDir.x, vecDir.y, 0, 0, (m_iClip ? 0 : 1), 0 ); m_pPlayer->pev->fov = 0; m_pPlayer->m_iFOV = m_pPlayer->pev->fov; scope = false; g_engfuncs.pfnSetClientMaxspeed(m_pPlayer->edict(), 210 ); #ifndef CLIENT_DLL MESSAGE_BEGIN( MSG_ONE, gmsgScopeToggle, NULL, m_pPlayer->pev ); WRITE_BYTE( 0 ); MESSAGE_END(); #endif m_flNextPrimaryAttack = UTIL_WeaponTimeBase() + 1.45; m_flNextSecondaryAttack = UTIL_WeaponTimeBase() + 1.45; m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 1.45; }
void CBasePlayerWeapon :: DefaultFire( CBasePlayer *m_pPlayer, int cShots, wepspread_t spread, float damage, int anim, char *sound, int genevent, int RadOfBright ) { if (m_iClip <= 0) { PlayEmptySound(); m_flNextPrimaryAttack = 0.15; return; } if( anim >= 0 ) SendWeaponAnim( anim ); m_pPlayer->SetAnimation( PLAYER_ATTACK1 ); m_pPlayer->m_iWeaponFlash = NORMAL_GUN_FLASH; m_pPlayer->m_iWeaponVolume = NORMAL_GUN_VOLUME; m_pPlayer->pev->effects = (int)(m_pPlayer->pev->effects) | EF_MUZZLEFLASH; if( sound ) EMIT_SOUND_DYN( ENT( m_pPlayer->pev ), CHAN_WEAPON, sound, 1.0, ATTN_NORM, 0, 100 ); cShots = min( m_iClip, cShots ); m_iClip -= cShots; Vector vecSrc( m_pPlayer->GetGunPosition() ); Vector vecAim( m_pPlayer->GetAutoaimVector( AUTOAIM_2DEGREES ) ); Vector vecAcc( g_vecZero ); Vector vecDir; if( cShots != 1 ) vecAcc = vec3_t( spread.SpreadX / 100, spread.SpreadY / 100, 0 ); float spead = m_pPlayer->pev->velocity.Length(); if( m_pPlayer->pev->velocity.Length() ) vecAcc = vecAcc + vec3_t( spread.SpreadY / 5000, spread.SpreadY / 5000, 0 ) * m_pPlayer->pev->velocity.Length(); if( iSlot() == 2 && cShots == 1 ) vecAcc = vecAcc / 10; if ( !( m_pPlayer->pev->flags & FL_ONGROUND ) ) vecAcc = vecAcc + vec3_t( spread.SpreadY / 5000, spread.SpreadY / 5000, 0 ) * 250; vecDir = m_pPlayer->FireBulletsPlayer( cShots, vecSrc, vecAim, vecAcc, 8192,0, 0, damage, m_pPlayer->pev, m_pPlayer->random_seed ); MESSAGE_BEGIN( MSG_PVS, SVC_TEMPENTITY, vecSrc ); WRITE_BYTE( TE_DLIGHT ); WRITE_COORD( vecSrc.x ); WRITE_COORD( vecSrc.y ); WRITE_COORD( vecSrc.z ); WRITE_BYTE( RadOfBright ); WRITE_BYTE( 210 ); WRITE_BYTE( 200 ); WRITE_BYTE( 60 ); WRITE_BYTE( 1 ); WRITE_BYTE( 1 ); MESSAGE_END(); if( !LeftSpread ) LeftSpread = 1; m_pPlayer->pev->punchangle.x -= RANDOM_FLOAT( spread.SpreadY / 2, spread.SpreadY ); m_pPlayer->pev->punchangle.y += spread.SpreadX * RANDOM_LONG( -1, 1 ) / 2; if( m_pPlayer->pev->punchangle.x < -spread.MaxSpreadY ) { m_pPlayer->pev->punchangle.x = -spread.MaxSpreadY + RANDOM_LONG( -2, 2 ); m_pPlayer->pev->punchangle.y += spread.SpreadX * LeftSpread; } if( m_pPlayer->pev->punchangle.y <= -spread.MaxSpreadX ) LeftSpread = 1; else if( m_pPlayer->pev->punchangle.y > spread.MaxSpreadX ) LeftSpread = -1; PLAYBACK_EVENT_FULL( FEV_NOTHOST, m_pPlayer->edict(), genevent, 0.0, (float *)&g_vecZero, (float *)&g_vecZero, vecDir.x, vecDir.y, 0, 0, (m_iClip ? 0 : 1), 0 ); }