Ejemplo n.º 1
0
///
/// \brief  Render
///
/// \param  pd3dDevice  [I ] D3D Device
///
/// \return ALT_S_SUCCESS   success
/// \return ALT_E_ERROR     error
///
alt_t Test5_1_Panel::Render(IDirect3DDevice9 * pDevice)
{
  altLight      oLight;
  D3DXVECTOR3   vecDirection(0,0,1);
  D3DCOLORVALUE Diffuse;
  D3DCOLORVALUE Specular;

  Diffuse.r  = 1.0f;
  Diffuse.g  = 1.0f;
  Diffuse.b  = 1.0f;
  Specular.r = 1.0f;
  Specular.g = 1.0f;
  Specular.b = 1.0f;

  oLight.SetLight (vecDirection, D3DLIGHT_DIRECTIONAL, Diffuse, Specular, 200.0f);

  aiDX.GetDevice()->Clear (0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(100,100,100), 1.0f, 0);

  return (altComponent::Render (pDevice));
}
Ejemplo n.º 2
0
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
float CEnvMeteorSpawnerShared::MeteorThink( float flTime )
{
	// Check for spawn.
	if ( flTime < m_flNextSpawnTime )
		return m_flNextSpawnTime;

	while ( m_flNextSpawnTime < flTime )
	{
		// Get a random number of meteors to spawn and spawn them.
		int nMeteorCount = GetRandomInt( m_nMinSpawnCount, m_nMaxSpawnCount );
		for ( int iMeteor = 0; iMeteor < nMeteorCount; iMeteor++ )
		{
			// Increment the number of meteors created (starting with 1).
			m_nMeteorCount++;

			// Get a random meteor position.
			Vector meteorOrigin( GetRandomFloat( m_vecMinBounds.GetX(), m_vecMaxBounds.GetX() ) /* x */,
				                 GetRandomFloat( m_vecMinBounds.GetY(), m_vecMaxBounds.GetY() ) /* y */,
				                 GetRandomFloat( m_vecMinBounds.GetZ(), m_vecMaxBounds.GetZ() ) /* z */ );
			
			// Calculate the direction of the meteor based on "targets."
			Vector vecDirection( 0.0f, 0.0f, -1.0f );
			if ( m_aTargets.Count() > 0 )
			{
				float flFreq = 1.0f / m_aTargets.Count();
				float flFreqAccum = flFreq;

				int iTarget;
				for( iTarget = 0; iTarget < m_aTargets.Count(); ++iTarget )
				{
					float flRandom = GetRandomFloat( 0.0f, 1.0f );
					if ( flRandom < flFreqAccum )
						break;

					flFreqAccum += flFreq;
				}

				// Should ever be here!
				if ( iTarget == m_aTargets.Count() )
				{
					iTarget--;
				}

				// Just set it to the first target for now!!!
				// NOTE: Will randomly generate from list of targets when more than 1 in
				//       the future.

				// Move the meteor into the "world."
				Vector vecPositionInWorld;
				Vector vecSkyboxOrigin;
				g_pMapData->Get3DSkyboxOrigin( vecSkyboxOrigin );
				vecPositionInWorld = ( meteorOrigin - vecSkyboxOrigin );
				vecPositionInWorld *= g_pMapData->Get3DSkyboxScale();

				Vector vecTargetPos = m_aTargets[iTarget].m_vecPosition;
				vecTargetPos.x += GetRandomFloat( -m_aTargets[iTarget].m_flRadius, m_aTargets[iTarget].m_flRadius );
				vecTargetPos.y += GetRandomFloat( -m_aTargets[iTarget].m_flRadius, m_aTargets[iTarget].m_flRadius );
				vecTargetPos.z += GetRandomFloat( -m_aTargets[iTarget].m_flRadius, m_aTargets[iTarget].m_flRadius );

				vecDirection = vecTargetPos - vecPositionInWorld;
				VectorNormalize( vecDirection );
			}
			
			// Pass in the randomized position, randomized speed, and start time.
			m_pFactory->CreateMeteor( m_nMeteorCount, m_iMeteorType, meteorOrigin,
				                      vecDirection /* direction */,
				                      GetRandomFloat( m_flMinSpeed, m_flMaxSpeed ) /* speed */,
									  m_flNextSpawnTime, m_flMeteorDamageRadius,
				                      m_vecTriggerMins, m_vecTriggerMaxs );
		}
		
		// Set next spawn time.
		m_flNextSpawnTime += GetRandomFloat( m_flMinSpawnTime, m_flMaxSpawnTime );
	}

	// Return the next spawn time.
	return ( m_flNextSpawnTime - gpGlobals->curtime );
}