当前位置: 首页>>代码示例>>C++>>正文


C++ RandomVector函数代码示例

本文整理汇总了C++中RandomVector函数的典型用法代码示例。如果您正苦于以下问题:C++ RandomVector函数的具体用法?C++ RandomVector怎么用?C++ RandomVector使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了RandomVector函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: LSQRSelfTest

  void LSQRSelfTest() {
    SparseMatrix A;
    Vector b;
    {
      int m=5,n=3,nnz=10;
      A.resize(m,n);
      b.resize(m);
      RandomSparseMatrix(A,nnz,1);
      RandomVector(b,1);
      
      cout<<"Overconstrained test"<<endl;
      TestLSQR(A,b);
    }

    {
      int m=3,n=5,nnz=10;
      A.resize(m,n);
      b.resize(m);
      RandomSparseMatrix(A,nnz,1);
      RandomVector(b,1);
      
      cout<<"Underconstrained test"<<endl;
      TestLSQR(A,b);
    }
  }
开发者ID:HargisJ,项目名称:KrisLibrary,代码行数:25,代码来源:SelfTest.cpp

示例2: RandomVector

void C_Func_Dust::AttemptSpawnNewParticle()
{
	// Find a random spot inside our bmodel.
	static int nTests=10;

	for( int iTest=0; iTest < nTests; iTest++ )
	{
		Vector vPercent = RandomVector( 0, 1 );
		Vector vTest = WorldAlignMins() + (WorldAlignMaxs() - WorldAlignMins()) * vPercent;

		int contents = enginetrace->GetPointContents_Collideable( GetCollideable(), vTest );
		if( contents & CONTENTS_SOLID )
		{
			CFuncDustParticle *pParticle = (CFuncDustParticle*)m_Effect.AddParticle( 10, m_hMaterial, vTest );
			if( pParticle )
			{
				pParticle->m_vVelocity = RandomVector( -m_SpeedMax, m_SpeedMax );
				pParticle->m_vVelocity.z -= m_FallSpeed;

				pParticle->m_flLifetime = 0;
				pParticle->m_flDieTime = RemapVal( rand(), 0, RAND_MAX, m_LifetimeMin, m_LifetimeMax );

				if( m_DustFlags & DUSTFLAGS_SCALEMOTES )
					pParticle->m_flSize = RemapVal( rand(), 0, RAND_MAX, m_flSizeMin/10000.0f, m_flSizeMax/10000.0f );
				else
					pParticle->m_flSize = RemapVal( rand(), 0, RAND_MAX, m_flSizeMin, m_flSizeMax );
			
				pParticle->m_Color = m_Color;
			}

			break;
		}
	}
}
开发者ID:Au-heppa,项目名称:swarm-sdk,代码行数:34,代码来源:c_func_dust.cpp

示例3: initialize

void initialize(int N, int nz, Random R) {
    
    /* initialize vector multipliers and storage for result */
    /* y = A*x;  */
    
    x = RandomVector(N, R);
    y = (double*) malloc(sizeof(double)*N);
    
#if 0
    // initialize square sparse matrix
    //
    // for this test, we create a sparse matrix with M/nz nonzeros
    // per row, with spaced-out evenly between the begining of the
    // row to the main diagonal.  Thus, the resulting pattern looks
    // like
    //             +-----------------+
    //             +*                +
    //             +***              +
    //             +* * *            +
    //             +** *  *          +
    //             +**  *   *        +
    //             +* *   *   *      +
    //             +*  *   *    *    +
    //             +*   *    *    *  +
    //             +-----------------+
    //
    // (as best reproducible with integer artihmetic)
    // Note that the first nr rows will have elements past
    // the diagonal.
#endif
    
    int nr = nz/N;      /* average number of nonzeros per row  */
    int anz = nr *N;    /* _actual_ number of nonzeros         */
    
    val = RandomVector(anz, R);
    col = (int*) malloc(sizeof(int)*nz);
    row = (int*) malloc(sizeof(int)*(N+1));
    int r=0;
    int cycles=1;
    
    row[0] = 0;
    for (int r=0; r<N; r++)
    {
        /* initialize elements for row r */
        
        int rowr = row[r];
        int step = r/ nr;
        int i=0;
        
        row[r+1] = rowr + nr;
        if (step < 1) step = 1;   /* take at least unit steps */
        
        
        for (i=0; i<nr; i++)
            col[rowr+i] = i*step;
        
    }
}
开发者ID:Surtr04,项目名称:PI-CPD,代码行数:58,代码来源:SparseMVMult.cpp

示例4: DefaultReload

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
bool CWeaponG43::Reload( void )
{

	bool fRet;
	float fCacheTime = m_flNextSecondaryAttack;

	fRet = DefaultReload( GetMaxClip1(), GetMaxClip2(), ACT_VM_RELOAD );
	if ( fRet )
	{
		// Undo whatever the reload process has done to our secondary
		// attack timer. We allow you to interrupt reloading to fire
		// a grenade.
		m_flNextSecondaryAttack = GetOwner()->m_flNextAttack = fCacheTime;

		WeaponSound( RELOAD );

		CBasePlayer *pOwner = ToBasePlayer( GetOwner() );
		CEffectData data;
		data.m_vOrigin = pOwner->WorldSpaceCenter() + RandomVector( 0, 0 );
		data.m_vAngles = QAngle( 90, random->RandomInt( 0, 360 ), 0 );
		data.m_nEntIndex = entindex();
		DispatchEffect( "ClipEject", data );
	}

	return fRet;
}
开发者ID:BerntA,项目名称:tfo-code,代码行数:28,代码来源:weapon_g43.cpp

示例5: SparkleCallback

//-----------------------------------------------------------------------------
// Purpose: Callback to create a sparkle effect on the client
// Input  : &data - information about the effect
//-----------------------------------------------------------------------------
void SparkleCallback( const CEffectData &data )
{
	// Create a simple particle emitter
	CSmartPtr<CSimpleEmitter> pSparkleEmitter = CSimpleEmitter::Create( "Sparkle" );

	if ( pSparkleEmitter == NULL )
		return;

	// Make local versions of our passed in data
	Vector	origin = data.m_vOrigin;
	float	scale = data.m_flScale;

	// Set our sort origin to make the system cull properly
	pSparkleEmitter->SetSortOrigin( origin );

	// Find the material handle we wish to use for these particles
	PMaterialHandle hMaterial = pSparkleEmitter->GetPMaterial( "effects/yellowflare" );

	SimpleParticle *pParticle;

	// Make a group of particles in the world
	for ( int i = 0; i < 64; i++ )
	{
		// Create a particle
		pParticle = pSparkleEmitter->AddSimpleParticle( hMaterial, origin );

		if ( pParticle == NULL )
			return;

		// Set our sizes
		pParticle->m_uchStartSize = (unsigned char) scale;
		pParticle->m_uchEndSize = 0;

		// Set our roll
		pParticle->m_flRoll = random->RandomFloat( 0, 2*M_PI );
		pParticle->m_flRollDelta = random->RandomFloat( -DEG2RAD( 180 ), DEG2RAD( 180 ) );

		// Set our color
		pParticle->m_uchColor[0] = 255;	// Red
		pParticle->m_uchColor[1] = 255;	// Green
		pParticle->m_uchColor[2] = 255;	// Blue

		// Set our alpha
		pParticle->m_uchStartAlpha = 0;
		pParticle->m_uchEndAlpha = 255;
		
		// Create a random vector
		Vector velocity = RandomVector( -1.0f, 1.0f );
		VectorNormalize( velocity );

		// Find a random speed for the particle
		float speed = random->RandomFloat( 4.0f, 8.0f ) * scale;

		// Build and set the velocity of the particle
		pParticle->m_vecVelocity = velocity * speed;

		// Declare our lifetime
		pParticle->m_flDieTime = 1.0f;
	}
}
开发者ID:Au-heppa,项目名称:swarm-sdk,代码行数:64,代码来源:c_sdk_env_sparkler.cpp

示例6: SetThink

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" );
		}
	}
}
开发者ID:Adidasman1,项目名称:source-sdk-2013,代码行数:29,代码来源:grenade_tripwire.cpp

示例7: CreateEntityByName

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CAntlionGrub::CreateNugget( void )
{
	CGrubNugget *pNugget = (CGrubNugget *) CreateEntityByName( "item_grubnugget" );
	if ( pNugget == NULL )
		return;

	Vector vecOrigin;
	Vector vecForward;
	GetAttachment( LookupAttachment( "glow" ), vecOrigin, &vecForward );

	// Find out what size to make this nugget!
	int nDenomination = GetNuggetDenomination();
	pNugget->SetDenomination( nDenomination );
	
	pNugget->SetAbsOrigin( vecOrigin );
	pNugget->SetAbsAngles( RandomAngle( 0, 360 ) );
	DispatchSpawn( pNugget );

	IPhysicsObject *pPhys = pNugget->VPhysicsGetObject();
	if ( pPhys )
	{
		Vector vecForward;
		GetVectors( &vecForward, NULL, NULL );
		
		Vector vecVelocity = RandomVector( -35.0f, 35.0f ) + ( vecForward * -RandomFloat( 50.0f, 75.0f ) );
		AngularImpulse vecAngImpulse = RandomAngularImpulse( -100.0f, 100.0f );

		pPhys->AddVelocity( &vecVelocity, &vecAngImpulse );
	}
}
开发者ID:xxauroraxx,项目名称:Source.Python,代码行数:33,代码来源:npc_antliongrub.cpp

示例8: ToBasePlayer

//=========================================================
// Ejecuta una acción al momento que el modelo hace
// la animación correspondiente.
//=========================================================
void CWeapon357::Operator_HandleAnimEvent(animevent_t *pEvent, CBaseCombatCharacter *pOperator)
{
	CBasePlayer *pOwner = ToBasePlayer( GetOwner() );

	switch( pEvent->event )
	{
#ifndef CLIENT_DLL
		case EVENT_WEAPON_RELOAD:
		{
			CEffectData data;

			// Emit six spent shells
			for ( int i = 0; i < 6; i++ )
			{
				data.m_vOrigin = pOwner->WorldSpaceCenter() + RandomVector( -4, 4 );
				data.m_vAngles = QAngle( 90, random->RandomInt( 0, 360 ), 0 );
				data.m_nEntIndex = entindex();

				DispatchEffect( "ShellEject", data );
			}

			break;
		}
#endif
	}
}
开发者ID:InfoSmart,项目名称:InSource-Singleplayer,代码行数:30,代码来源:weapon_357.cpp

示例9: DropMoney

void DropMoney( const Vector &vecOrigin, int amount, CBasePlayer * pTaker )
{
	Vector offsetVec = RandomVector(-4.0, 4.0);
	offsetVec.z = abs(offsetVec.z);
	//Vector newOrigin = vecOrigin + RandomVector(-4,4);
	Vector newOrigin = vecOrigin + offsetVec;

	CItemMoney * money = (CItemMoney*)CBaseEntity::Create( "item_money", newOrigin, vec3_angle );
	if ( money )
	{
		CPASAttenuationFilter filter( pTaker );
		pTaker->EmitSound( filter, pTaker->entindex(), "Grenade_Molotov.Detonate" );		
		
		money->ChangeTeam( pTaker->GetTeamNumber() );
		money->m_iAmount = amount;
		money->m_taker = pTaker;

		//==================================================================================
		// ItemMoney is not a VPhysObject so, the following is actually dead code... for now
		//==================================================================================
		//IPhysicsObject *pPhysicsObject = money->VPhysicsGetObject();
		//if ( pPhysicsObject )
		//{
		//	Vector			vel		= RandomVector( -64.0f, 64.0f );
		//	vel.z = abs(vel.z);
		//	AngularImpulse	angImp	= RandomAngularImpulse( -300.0f, 300.0f );

		//	// Angular velocity is always applied in local space in vphysics
		//	AngularImpulse localAngImp;
		//	pPhysicsObject->WorldToLocalVector( &localAngImp, angImp );
		//	pPhysicsObject->AddVelocity( &vel, &localAngImp );
		//}
	}
}
开发者ID:schroe2a,项目名称:DotaSource2,代码行数:34,代码来源:ItemMoney.cpp

示例10: while

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void C_ObjectEMPGenerator::ClientThink( void )
{
	// Add particles at the target.
	float flCur = gpGlobals->frametime;
	while ( m_ParticleEvent.NextEvent( flCur ) )
	{
		Vector vPos = WorldSpaceCenter( );
		Vector vOffset = RandomVector( -1, 1 );
		VectorNormalize( vOffset );
		vPos += vOffset * RandomFloat( 0, 50 );
		
		SimpleParticle *pParticle = m_pEmitter->AddSimpleParticle( m_hParticleMaterial, vPos );
		if ( pParticle )
		{
			// Move the points along the path.
			pParticle->m_vecVelocity.Init();
			pParticle->m_flRoll = 0;
			pParticle->m_flRollDelta = 0;
			pParticle->m_flDieTime = 0.4f;
			pParticle->m_flLifetime = 0;
			pParticle->m_uchColor[0] = 255; 
			pParticle->m_uchColor[1] = 255;
			pParticle->m_uchColor[2] = 255;
			pParticle->m_uchStartAlpha = 32;
			pParticle->m_uchEndAlpha = 0;
			pParticle->m_uchStartSize = 6;
			pParticle->m_uchEndSize = 4;
			pParticle->m_iFlags = 0;
		}
	}
}
开发者ID:Axitonium,项目名称:SourceEngine2007,代码行数:34,代码来源:c_obj_empgenerator.cpp

示例11: while

void C_MovieExplosion::Update(float fTimeDelta)
{
	if(!m_pParticleMgr)
		return;

	m_EmitterLifetime += fTimeDelta;
	if(m_EmitterLifetime > EXPLOSION_EMITTER_LIFETIME)
		return;

	m_EmitterAlpha = (float)sin(m_EmitterLifetime * 3.14159f / EXPLOSION_EMITTER_LIFETIME);

	// Simulate the emitters and have them spit out particles.
	for(int iEmitter=0; iEmitter < NUM_MOVIEEXPLOSION_EMITTERS; iEmitter++)
	{
		MovieExplosionEmitter *pEmitter = &m_Emitters[iEmitter];

		pEmitter->m_Pos = pEmitter->m_Pos + pEmitter->m_Velocity * fTimeDelta;
		pEmitter->m_Velocity = pEmitter->m_Velocity * 0.9;

		float tempDelta = fTimeDelta;
		while(pEmitter->m_ParticleSpawn.NextEvent(tempDelta))
		{
			StandardParticle_t *pParticle = 
				(StandardParticle_t*)m_ParticleEffect.AddParticle( sizeof(StandardParticle_t), m_iFireballMaterial);

			if(pParticle)
			{
				pParticle->m_Pos = pEmitter->m_Pos;
				pParticle->m_Velocity = pEmitter->m_Velocity * 0.2f + RandomVector(-20, 20);
			}
		}
	}
}
开发者ID:0xFEEDC0DE64,项目名称:UltraGame,代码行数:33,代码来源:c_movie_explosion.cpp

示例12: AngleVectors

//-----------------------------------------------------------------------------
// Purpose: Creates an instance of this entity
//-----------------------------------------------------------------------------
CTFFlameEntity *CTFFlameEntity::Create( const Vector &vecOrigin, const QAngle &vecAngles, CBaseEntity *pOwner, int iDmgType, float flDmgAmount )
{
	CTFFlameEntity *pFlame = static_cast<CTFFlameEntity*>( CBaseEntity::Create( "tf_flame", vecOrigin, vecAngles, pOwner ) );
	if ( !pFlame )
		return NULL;

	// Initialize the owner.
	pFlame->SetOwnerEntity( pOwner );
	pFlame->m_hAttacker = pOwner->GetOwnerEntity();
	CBaseEntity *pAttacker = (CBaseEntity *) pFlame->m_hAttacker;
	if ( pAttacker )
	{
		pFlame->m_iAttackerTeam = pAttacker->GetTeamNumber();
	}

	// Set team.
	pFlame->ChangeTeam( pOwner->GetTeamNumber() );
	pFlame->m_iDmgType = iDmgType;
	pFlame->m_flDmgAmount = flDmgAmount;

	// Setup the initial velocity.
	Vector vecForward, vecRight, vecUp;
	AngleVectors( vecAngles, &vecForward, &vecRight, &vecUp );

	float velocity = tf_flamethrower_velocity.GetFloat();
	pFlame->m_vecBaseVelocity = vecForward * velocity;
	pFlame->m_vecBaseVelocity += RandomVector( -velocity * tf_flamethrower_vecrand.GetFloat(), velocity * tf_flamethrower_vecrand.GetFloat() );
	pFlame->m_vecAttackerVelocity = pOwner->GetOwnerEntity()->GetAbsVelocity();
	pFlame->SetAbsVelocity( pFlame->m_vecBaseVelocity );	
	// Setup the initial angles.
	pFlame->SetAbsAngles( vecAngles );

	return pFlame;
}
开发者ID:Deathreus,项目名称:TF2Classic,代码行数:37,代码来源:tf_weapon_flamethrower.cpp

示例13: GetOwnerEntity

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CWeaponStriderBuster::Detonate( void )
{
	CBaseEntity *pVictim = GetOwnerEntity();
	if ( !m_bDud && pVictim )
	{
		// Kill the strider (with magic effect)
		CBasePlayer *pPlayer = AI_GetSinglePlayer();
		CTakeDamageInfo info( pPlayer, this, RandomVector( -100.0f, 100.0f ), GetAbsOrigin(), pVictim->GetHealth(), DMG_GENERIC );
		pVictim->TakeDamage( info );

		gamestats->Event_WeaponHit( ToBasePlayer( pPlayer ), true, GetClassname(), info );

		// Tracker 62293:  There's a bug where the inflictor/attacker are reversed when calling TakeDamage above so the player never gets
		//  credit for the strider buster kills.  The code has a bunch of assumptions lower level, so it's safer to just fix it here by 
		//  crediting a kill to the player directly.
		gamestats->Event_PlayerKilledOther( pPlayer, pVictim, info );
	}

	m_OnDetonate.FireOutput( this, this );

	// Explode
	if ( !m_bDud )
	{
		CreateDestroyedEffect();
		EmitSound( "Weapon_StriderBuster.Detonate" );
	}
	else
	{
		DispatchParticleEffect( "striderbuster_explode_dummy_core", GetAbsOrigin(), GetAbsAngles() );
		EmitSound( "Weapon_StriderBuster.Dud_Detonate" );
	}

	// Go to bits!
	Shatter( pVictim );
}
开发者ID:FooGames,项目名称:SecobMod,代码行数:38,代码来源:weapon_striderbuster.cpp

示例14: while

//-----------------------------------------------------------------------------
// Purpose: Trail smoke
//-----------------------------------------------------------------------------
void CASW_Shotgun_Pellet_Predicted::ClientThink( void )
{
return;

	CSmartPtr<CSimpleEmitter> pEmitter = CSimpleEmitter::Create( "CASW_Shotgun_Pellet_Predicted::Effect" );
	PMaterialHandle	hSphereMaterial = pEmitter->GetPMaterial( "sprites/chargeball" );

	// Add particles at the target.
	float flCur = gpGlobals->frametime;
	while ( m_ParticleEvent.NextEvent( flCur ) )
	{
		Vector vecOrigin = GetAbsOrigin() + RandomVector( -2,2 );
		pEmitter->SetSortOrigin( vecOrigin );

		SimpleParticle *pParticle = (SimpleParticle *) pEmitter->AddParticle( sizeof(SimpleParticle), hSphereMaterial, vecOrigin );
		if ( pParticle == NULL )
			return;

		pParticle->m_flLifetime	= 0.0f;
		pParticle->m_flDieTime	= random->RandomFloat( 0.1f, 0.3f );

		pParticle->m_uchStartSize	= random->RandomFloat(2,4);
		pParticle->m_uchEndSize		= pParticle->m_uchStartSize + 2;

		pParticle->m_vecVelocity = vec3_origin;
		pParticle->m_uchStartAlpha = 128;
		pParticle->m_uchEndAlpha = 0;
		pParticle->m_flRoll	= random->RandomFloat( 180, 360 );
		pParticle->m_flRollDelta = random->RandomFloat( -1, 1 );

		pParticle->m_uchColor[0] = 128;
		pParticle->m_uchColor[1] = 128;
		pParticle->m_uchColor[2] = 128;
	}
}
开发者ID:Cre3per,项目名称:hl2sdk-csgo,代码行数:38,代码来源:asw_shotgun_pellet_predicted_shared.cpp

示例15: NonIntersectingLine

NpLine NonIntersectingLine(const NpTetrahedron& t)
{
    // Find a point outside the tetrahedron
    double u0, u1, u2;
    do  {
        u0 = NpRand(-10.0, 10.0);
        u1 = NpRand(-10.0, 10.0);
        u2 = NpRand(-10.0, 10.0);
    }  while ((u0 >= 0.0)  &&  (u0 <= 1.0)  &&
              (u1 >= 0.0)  &&  (u1 <= 1.0)  &&
              (u2 >= 0.0)  &&  (u1 <= 1.0)  &&
              (u0+u1+u2 >= 0.0)  &&  (u0+u1+u2 <= 1.0));

    NpVector tetrahedronPt = t.TetrahedronPoint(u0, u1, u2);

    // Find a random direction
    NpVector dir = RandomVector(NpVector(-1, -1, -1), NpVector(1, 1, 1));
    
    // Generate two points on the line
    double t0 = NpRand(-10.0, 0.0);
    NpVector linePt0 = tetrahedronPt + t0*dir;

    double t1 = NpRand(0.0, 10.0);
    NpVector linePt1 = tetrahedronPt + t1*dir;

    return NpLine(linePt0, linePt1);
}
开发者ID:JKolios,项目名称:RayTetra,代码行数:27,代码来源:RandomRayTetra.cpp


注:本文中的RandomVector函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。