示例#1
0
文件: g_entity.c 项目: jdolan/quetoo
/**
 * @brief
 */
void G_SpawnTech(const g_item_t *item) {

	g_entity_t *spawn = G_SelectTechSpawnPoint();
	g_entity_t *ent = G_DropItem(spawn, item);

	VectorSet(ent->locals.velocity, Randomc() * 250, Randomc() * 250, 200 + (Randomf() * 200));
}
示例#2
0
bool CGmObjSplash3D::Move()
{
	const bool bBlinkOnPrev( m_bBlinkOn );
	if( m_bEnableBlink )
	{
		const unsigned int uiTickInterval( 12 );
		const bool bBlinkOnNext( ( ( m_uiTick_ - m_uiTickRef ) % uiTickInterval ) < ( uiTickInterval - 4 ) );
		if( bBlinkOnNext )
		{
			if( !m_bBlinkOn )
			{
				m_bBlinkOn = bBlinkOnNext;
				
				if( m_poASource && !m_poASource->IsPlaying() )
					m_poASource->Play();
			}
		}
		else
		{
			m_bBlinkOn = false;
			if( m_poASource && m_poASource->IsPlaying() )
				m_poASource->Stop();
		}
	}
	
	if( !( m_uiTick_ % 2 ) )
	//if( m_bTickTrigger8_ )
	{
		const float fT( 0.005f ), fS( 0.005f );
		m_oMatrix.Unit();
		m_oMatrix.Translate( Randomf( -fT, +fT ), m_fOffsetY + Randomf( -fT, +fT ), 0.0f ); //Randomf( -fT, +fT ) );
		m_oMatrix.Scale( 1.0f, 1.0f, 1.0f + Randomf( -fS, +fS ) );
	}
	
	const bool bIsNotOn( CGmObjSplash::Move() );
	if( bIsNotOn && m_bEnableBlink )
	{
		return ( bBlinkOnPrev != m_bBlinkOn && !m_bBlinkOn );
	}
	return bIsNotOn;
}
示例#3
0
/**
 * @brief
 */
static _Bool Cg_UpdateParticle_Weather(cg_particle_t *p, const vec_t delta, const vec_t delta_squared) {

	// free up weather particles that have hit the ground
	if (p->part.org[2] <= p->weather.end_z) {

		if ((cgi.view->weather & WEATHER_RAIN) && Randomf() < 0.3) {
			Cg_RippleEffect((const vec3_t) {
				p->part.org[0],
				p->part.org[1],
				p->weather.end_z + 1.0
			}, 2.0, 2);
		}
示例#4
0
/*
 * @brief
 */
static void Cg_TeleporterEffect(const vec3_t org) {

	vec3_t color;
	cgi.ColorFromPalette(110, color);

	for (int32_t i = 0; i < 64; i++) {
		cg_particle_t *p;

		if (!(p = Cg_AllocParticle(PARTICLE_NORMAL, NULL )))
			break;

		VectorCopy(color, p->part.color);
		Vector4Set(p->color_vel, 1.0, 1.0, 1.0, -1.5 + Randomf() * 0.5);

		p->part.scale = 1.0;
		p->scale_vel = 3.0;

		p->part.org[0] = org[0] + Randomc() * 16.0;
		p->part.org[1] = org[1] + Randomc() * 16.0;
		p->part.org[2] = org[2] + 8.0 + Randomf() * 24.0;

		p->vel[0] = Randomc() * 24.0;
		p->vel[1] = Randomc() * 24.0;
		p->vel[2] = Randomf() * 64.0;

		p->accel[0] = p->accel[1] = 0;
		p->accel[2] = -PARTICLE_GRAVITY * 0.1;
	}

	r_sustained_light_t s;
	VectorCopy(org, s.light.origin);
	s.light.radius = 120.0;
	VectorSet(s.light.color, 0.9, 0.9, 0.9);
	s.sustain = 1000;

	cgi.AddSustainedLight(&s);

	cgi.PlaySample(org, 0, cg_sample_respawn, ATTEN_IDLE);

}
示例#5
0
文件: poisson.cpp 项目: olyd/st
bool Poisson::GetPoissonList(int clientnum, vector<int> &output)
{
	if (output.size() != 0) return false;
	if (clientnum <= 0) return false;
	double temp;
	output.push_back(0);
	for (int i = 0; i < clientnum; ++i) {
		temp = Randomf(0, 1);
		temp = 0 - log(1 - temp) * m_lambda;
		output.push_back(static_cast<int>(temp * 1000000));
	}
	return true;
}
示例#6
0
/*
 * @brief
 */
static void Cg_ItemPickupEffect(const vec3_t org) {

	vec3_t color;
	cgi.ColorFromPalette(110, color);

	for (int32_t i = 0; i < 32; i++) {
		cg_particle_t *p;

		if (!(p = Cg_AllocParticle(PARTICLE_NORMAL, NULL )))
			break;

		VectorCopy(color, p->part.color);
		Vector4Set(p->color_vel, 1.0, 1.0, 1.0, -1.5 + Randomf() * 0.5);

		p->part.scale = 1.0;
		p->scale_vel = 3.0;

		p->part.org[0] = org[0] + Randomc() * 8.0;
		p->part.org[1] = org[1] + Randomc() * 8.0;
		p->part.org[2] = org[2] + 8 + Randomc() * 16.0;

		p->vel[0] = Randomc() * 16.0;
		p->vel[1] = Randomc() * 16.0;
		p->vel[2] = Randomf() * 128.0;

		p->accel[0] = p->accel[1] = 0;
		p->accel[2] = PARTICLE_GRAVITY * 0.2;
	}

	r_sustained_light_t s;
	VectorCopy(org, s.light.origin);
	s.light.radius = 80.0;
	VectorSet(s.light.color, 0.9, 1.0, 1.0);
	s.sustain = 1000;

	cgi.AddSustainedLight(&s);
}
示例#7
0
void Zipf::CreateZipfList(vector<int> &filelist)
{
	vector<double> probability;
	CreateZipfDistribution(probability);
	filelist.clear();
	for(int i = 0; i < m_clientnum; ++i) {
		double temp = Randomf(0, 1);
		double sum = 0.0;
		for(int j = m_resourcenum - 1; j >= 0 ; --j) {
			sum += probability.at(j);
			if (sum > temp) {
				filelist.push_back(i);
				break;
			}
		}
	}
}
示例#8
0
/*
 * @brief Perform PVS and PHS filtering, returning a copy of the specified emit with
 * the correct flags stripped away for this frame.
 */
cg_emit_t *Cg_UpdateEmit(cg_emit_t *e) {
	static cg_emit_t em;

	em = *e;

	if (!cgi.LeafHearable(e->leaf))
		em.flags = 0;
	else if (!cgi.LeafVisible(e->leaf)) {
		em.flags &= ~EMIT_VISIBLE;
	}

	if (em.flags && em.hz && em.time < cgi.client->time) { // update the time stamp
		const vec_t drift = e->drift * Randomf() * 1000.0;
		e->time = cgi.client->time + (1000.0 / e->hz) + drift;
	}

	return &em;
}
示例#9
0
void RenderManager::Render()
{
    char buf[50];
    _itoa_s(fps, buf, 10);
    sText = std::string("FPS: ") + buf;
    std::string hair = "+";

    // Convert the pos to a w string
    std::string xs,ys,zs;
    std::stringstream posx,posy,posz;
    posx << mCam->GetPosition().x;
    xs = posx.str();
    posy << mCam->GetPosition().y;
    ys = posy.str();
    posz << mCam->GetPosition().z;
    zs = posz.str();
    std::string pos = xs + ", " + ys + ", " + zs;

    // Calculate the text width.
    int textWidth = 0;
    for(UINT i = 0; i < sText.length(); ++i)
    {
        WCHAR character = sText[i];
        if(character == ' ') 
        {
            textWidth += mFont.GetSpaceWidth();
        }
        else{
            const CD3D11_RECT& r = mFont.GetCharRect(sText[i]);
            textWidth += (r.right - r.left + 1);
        }
    }

    // Calculate the hair width.
    int hairWidth = 0;
    for(UINT i = 0; i < hair.size(); ++i)
    {
        WCHAR character = hair[i];
        if(character == ' ') 
        {
            hairWidth += mFont.GetSpaceWidth();
        }
        else{
            const CD3D11_RECT& r = mFont.GetCharRect(hair[i]);
            hairWidth += (r.right - r.left);
        }
    }

    // Calculate the pos width
    int posWidth = 0;
    for(UINT i = 0; i < pos.size(); ++i)
    {
        WCHAR character = pos[i];
        if(character == ' ') 
        {
            hairWidth += mFont.GetSpaceWidth();
        }
        else{
            const CD3D11_RECT& r = mFont.GetCharRect(pos[i]);
            posWidth += (r.right - r.left + 1);
        }
    }

    //COSMIC BOOOWLAN
    if((mCurrentScene == CurrentScene::BOWLING) && (cosmicFactor % 41 == 0) && PartyMode == 1)
    {
        int colorNum;

        for(int i = 0; i < 21; i++)
        {
            srand(cosmicFactor++);
            colorNum = rand() % 5;
            
            if(colorNum == 0)
                scene[mCurrentScene]->mPointLights[i].Diffuse = Colors::Red; 
            if(colorNum == 1)
                scene[mCurrentScene]->mPointLights[i].Diffuse = Colors::Blue;  
            if(colorNum == 2)
                scene[mCurrentScene]->mPointLights[i].Diffuse = Colors::Green;  
            if(colorNum == 3)
                scene[mCurrentScene]->mPointLights[i].Diffuse = Colors::Cyan;  
            if(colorNum == 4)
                scene[mCurrentScene]->mPointLights[i].Diffuse = Colors::Magenta; 

            scene[mCurrentScene]->mPointLights[i].Ambient = Colors::Black; 
            scene[mCurrentScene]->mPointLights[i].Range   = 30.0f;
        }
    }
    else if((mCurrentScene == CurrentScene::BOWLING) && (PartyMode == 0))
    {
        for(int i = 0; i < 21; i++)
        {
            scene[mCurrentScene]->mPointLights[i].Diffuse = Colors::NormalDiffuse; 
            scene[mCurrentScene]->mPointLights[i].Ambient = Colors::NormalAmbient; 	
            scene[mCurrentScene]->mPointLights[i].Range   = 40.0f; 	
        }

        PartyMode = -1;	
    }


    cosmicFactor++;


    textPos.x = (LONG)((SCREEN_WIDTH - textWidth) - 2.0f);
    textPos.y = 0;//SCREEN_HEIGHT;

    hairPos.x = (LONG)((SCREEN_WIDTH - hairWidth) / 2.0f);
    hairPos.y = (LONG)((SCREEN_HEIGHT - mFont.GetCharHeight()) / 2.0f) ;

    posPos.x = (LONG)2.0f;
    posPos.y = (LONG)1.0f;


    // clear the back buffer to a deep blue
    mDevcon->ClearDepthStencilView(mZbuffer, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0);
    mDevcon->ClearRenderTargetView(mBackbuffer, D3DXCOLOR(0.0f, 0.2f, 0.4f, 1.0f));
    mDevcon->ClearRenderTargetView(mScreen->mTargetView, D3DXCOLOR(0.0f, 0.0f, 0.0f, 1.0f));

    for( int j = 0; j < scene.size(); j++ )
        for( int i = 0; i < shadows[j].size(); i++ )
            mDevcon->ClearDepthStencilView(shadows[j][i]->pShadowMapDepthView, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0);

    //mDevcon->RSSetState(0);

    XMStoreFloat4x4(&sceneBuff.viewProj, mCam->ViewProj());
    sceneBuff.camPos = mCam->GetPosition();
    //sceneBuff.pad = 1.0f;
    mDevcon->VSSetConstantBuffers(0, 1, &sceneCBuffer);
    mDevcon->PSSetConstantBuffers(0, 1, &sceneCBuffer);

    mDevcon->UpdateSubresource(sceneCBuffer, 0, 0, &sceneBuff , 0, 0);

    if(mCurrentScene != CurrentScene::DARKNESS && mCurrentScene != CurrentScene::BOWLING)
    {
        //Skybox right now doesn't like zbuffers, so dont' set one for it
        mDevcon->OMSetRenderTargets(1, &mScreen->mTargetView, 0);
        mSkyBox->Render(sceneCBuffer, mCam, 0);
    }

    if(mCurrentScene == CurrentScene::DARKNESS)
    {
        scene[mCurrentScene]->mPointLights[0].Position = mCam->GetPosition();
        
        for(int i = 0; i < 2; i++)
        {
            scene[mCurrentScene]->mPointLights[i].Range = Randomf(20.0f, 21.0f);
        }
    }

    mDevcon->OMSetRenderTargets(1, &mScreen->mTargetView/*mBackbuffer*/, mZbuffer);

    mDevcon->PSSetConstantBuffers(2, 1, &dirLightCBuffer);
    mDevcon->UpdateSubresource(dirLightCBuffer, 0, 0, &mDirLight, 0, 0);

    mDevcon->PSSetConstantBuffers(3, 1, &pointLightCBuffer);
    mDevcon->UpdateSubresource(pointLightCBuffer, 0, 0, &scene[mCurrentScene]->mPointLights, 0, 0);
    
    //raster.CullMode = D3D11_CULL_FRONT;
    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    //mDevcon->RSSetState( pState );
    // START SHADOW MAP
    RenderToShadow();

    mDevcon->OMSetRenderTargets(1, &mScreen->mTargetView/*mBackbuffer*/, mZbuffer);

    // MUST PASS IN THE SHADER RESOURCE VIEW AFTER YOU SWITCH TEH RENDER TARGET OTHERWISE ITS NULL
    SetShadowSRV( 6 );

    //***********************
    XMStoreFloat4x4(&sceneBuff.viewProj, mCam->ViewProj());

    sceneBuff.camPos = mCam->GetPosition();

    mDevcon->VSSetConstantBuffers(0, 1, &sceneCBuffer);
    mDevcon->UpdateSubresource(sceneCBuffer, 0, 0, &sceneBuff , 0, 0);
    //***********************
    // END SHADOW MAP
    mDevcon->RSSetViewports(1, mViewport);
    Render(0);


    //Render the screen quad last
    mDevcon->OMSetRenderTargets(1, &mBackbuffer, 0);

    mDevcon->PSSetShaderResources(1, 1, &mDepthShaderResourceView);
    SetShadowSRV( 6 );
    
    //mDevcon->PSSetShaderResources(6, 1, &pShadowMapSRView);

    mDevcon->UpdateSubresource(sceneCBuffer, 0, 0, mScreenCam->ViewProj().m , 0, 0);
    mScreen->Render(sceneCBuffer, mScreenCam, 0);

    //mText.DrawString(mDevcon, mFont, sText, textPos, XMCOLOR(0xffffffff));
    mText.DrawString(mDevcon, mFont, hair, hairPos, XMCOLOR(0xffffffff));
    mText.DrawString(mDevcon, mFont, pos, posPos, XMCOLOR(0xffffffff));

    //if(!((mCam->GetPosition().x > 6.0f || mCam->GetPosition().x < -44.0) ||
    //	(mCam->GetPosition().y > 70.0f || mCam->GetPosition().y < 20.0) ||
    //	(mCam->GetPosition().z > 231.0f || mCam->GetPosition().z < 181.0)) ){
    //mSphere->IsItReflective(true);
    /*}
    else{
    mSphere->IsItReflective(false);
    }*/
}