예제 #1
0
BOOL CPowerMode::AddParticles(int x, int y)
{
    ASSERT(m_pmCfg != NULL);

    int count = (int)GetRandRange((double)m_pmCfg->GetMinParticles(), (double)m_pmCfg->GetMaxParticles());

    ::EnterCriticalSection(&m_cs);
    for(int i = 0; i < count; i++)
    {
        double vx = GetRandRange(m_pmCfg->GetVxMin(), m_pmCfg->GetVxMax());
        double vy = GetRandRange(m_pmCfg->GetVyMin(), m_pmCfg->GetVyMax());
        if(m_pmCfg->GetColorMode() == POWER_COLOR_MODE_STATIC)
        {
            m_particles.push_back(CParticle(x, y, vx, vy, m_pmCfg->GetInitialColor()));
        }
        else
        {
            int cr = (int)GetRandRange(1, 255);
            int cg = (int)GetRandRange(1, 255);
            int cb = (int)GetRandRange(1, 255);
            m_particles.push_back(CParticle(x, y, vx, vy, RGB(cr, cg, cb)));
        }
    }
    ::LeaveCriticalSection(&m_cs);

    return TRUE;
}
예제 #2
0
void CBox::SetBox(const Vector& xPos, float fSize, float fParticleMass, int iRigidity)
{
	Allocate(4);

	SetRigidity(iRigidity);

	
	float fRad = fSize * (float) sqrt(2.0f) / 2.0f;
	
	float s = fSize / 2.0f;
	
	Vector Corners[4] = { Vector(-s, -s), Vector(s, -s), Vector(s, s), Vector(-s, s) };
	Corners[0] += xPos;
	Corners[1] += xPos;
	Corners[2] += xPos;
	Corners[3] += xPos;

	//-----------------------------------------------------------
	// simple square box body Some masses will be set to < 0.0f,
	// marking the particle as unmovable.
	//-----------------------------------------------------------
	AddParticle(CParticle(Corners[0], fRad, fParticleMass));
	AddParticle(CParticle(Corners[1], fRad, fParticleMass));
	AddParticle(CParticle(Corners[2], fRad, fParticleMass));
	AddParticle(CParticle(Corners[3], fRad, fParticleMass));

	SetRigidBodyConstraints();
}
예제 #3
0
void init(void)
{
 //背景色
  glClearColor(0.2, 0.2, 0.3, 1.0);

  setCamera();//視点を求める
  setLight(); //光源設定 
	glEnable(GL_DEPTH_TEST);
  glEnable(GL_NORMALIZE);
  printf("マウス/キー操作の説明には'h'キーをプッシュ \n");

  //Terrainデータの作成
	makeTerrainData();
  Bitmap* bm0 = new Bitmap();
  loadBitmap(bm0, "../../bmp/altgrad4.bmp");
  makeTerrainImage(bm0);
  setTerrainTexture();
	//particle
  countP = 0;
  fps = 0;
  elapseTime1 = 0.0;//1sec間以内の経過時間
  elapseTime2 = 0.0; //init()後の総経過時間
  for(int i = 0; i < NUM_PARTICLE; i++) p[i] = CParticle();
  for(int i = 0; i < NUM_PARTICLE2; i++) q[i] = CParticle2();
	frameCount = 0;
}
예제 #4
0
void CChain::SetChain(const Vector& P0, const Vector& P1, int iNumParticles, int iRigidity, float fParticleRadius, float fParticleMass)
{
    Free();

    Allocate(iNumParticles, iNumParticles-1);

    if (iNumParticles < 2)
        return;

    if (iRigidity <= 0)
        iRigidity = 1;

    SetRigidity(iRigidity);

    //-----------------------------------------------------------
    // copy particles
    //-----------------------------------------------------------
    Vector P = P0;
    Vector D = (P0 - P1) / ((float) iNumParticles);

    for(int i = 0; i < iNumParticles; i ++)
    {
        AddParticle(CParticle(P, fParticleRadius, (i != 0)? fParticleMass : 0.0f));

        P += D;
    }

    //------------------------------------------------------------------
    // link particles together
    //------------------------------------------------------------------
    for(int i = 0; i < iNumParticles-1; i ++)
    {
        AddConstraint(CLinConstraint(&GetParticle(i), &GetParticle(i+1)));

        P += D;
    }

    ComputeBoundingSphere();

    m_iSelfCollisionStep = 2;
}
예제 #5
0
/*!****************************************************************************
 @Function		SpawnParticle
 @Output		pParticle	particle to initialize
 @Description	initializes the specified particle with randomly chosen parameters.
******************************************************************************/
void OGLESParticles::SpawnParticle(CParticle *pParticle)
{
	PVRTVec3 fParticleSource(f2vt(0), f2vt(0), f2vt(0));
	PVRTVec3 fParticleSourceVariability(f2vt(1), f2vt(0), f2vt(1));
	PVRTVec3 fParticleVelocity(f2vt(0), f2vt(30), f2vt(0));
	PVRTVec3 fParticleVelocityVariability(f2vt(4), f2vt(15), f2vt(4));
	VERTTYPE fParticleLifeTime = f2vt(8);
	VERTTYPE fParticleLifeTimeVariability = f2vt(1.0);

	float fParticleMass = 100;
	float fParticleMassVariability = 0;
	float fRndFloat;

	// Creates the particle position.
	PVRTVec3 fPos;
	fRndFloat = RandFloat();
	fPos.x = fParticleSource.x + VERTTYPEMUL(f2vt(fRndFloat),fParticleSourceVariability.x);
	fRndFloat = RandFloat();
	fPos.y = fParticleSource.y + VERTTYPEMUL(f2vt(fRndFloat),fParticleSourceVariability.y);
	fRndFloat = RandFloat();
	fPos.z = fParticleSource.z + VERTTYPEMUL(f2vt(fRndFloat),fParticleSourceVariability.z);

	// Creates the particle velocity.
	PVRTVec3 fVel;
	fRndFloat = RandFloat();
	fVel.x = fParticleVelocity.x + VERTTYPEMUL(f2vt(fRndFloat),fParticleVelocityVariability.x);
	fRndFloat = RandFloat();
	fVel.y = fParticleVelocity.y + VERTTYPEMUL(f2vt(fRndFloat),fParticleVelocityVariability.y);
	fRndFloat = RandFloat();
	fVel.z = fParticleVelocity.z + VERTTYPEMUL(f2vt(fRndFloat),fParticleVelocityVariability.z);

	// Creates the particle lifetime and fMass.
	VERTTYPE fLife = fParticleLifeTime + VERTTYPEMUL(f2vt(RandFloat()), fParticleLifeTimeVariability);
	float fMass = fParticleMass + RandFloat() * fParticleMassVariability;

	// Creates the particle from these characteristics.
	*pParticle = CParticle(fPos,fVel,fMass,fLife);

	// Creates the particle colors.
	PVRTVec3 fParticleInitialColour(f2vt(0.6f*255.0f), f2vt(0.5f*255.0f), f2vt(0.5f*255.0f));
	PVRTVec3 fParticleInitialColourVariability(f2vt(0.2f*255.0f), f2vt(0.2f*255.0f), f2vt(0.2f*255.0f));

	PVRTVec3 fParticleHalfwayColour(f2vt(1.0f*255.0f), f2vt(0.0f), f2vt(0.0f));
	PVRTVec3 fParticleHalfwayColourVariability(f2vt(0.8f*255.0f), f2vt(0.0f), f2vt(0.3f*255.0f));

	PVRTVec3 fParticleEndColour(f2vt(0.0f), f2vt(0.0f), f2vt(0.0f));
	PVRTVec3 fParticleEndColourVariability(f2vt(0.0f), f2vt(0.0f), f2vt(0.0f));

	VERTTYPE fRndValue = f2vt(RandFloat());
	pParticle->m_fColour.x = pParticle->m_fInitialColour.x = Clamp(fParticleInitialColour.x + VERTTYPEMUL(fParticleInitialColourVariability.x,fRndValue));
	pParticle->m_fColour.y = pParticle->m_fInitialColour.y = Clamp(fParticleInitialColour.y + VERTTYPEMUL(fParticleInitialColourVariability.y,fRndValue));
	pParticle->m_fColour.z = pParticle->m_fInitialColour.z = Clamp(fParticleInitialColour.z + VERTTYPEMUL(fParticleInitialColourVariability.z,fRndValue));

	fRndFloat = RandFloat();
	pParticle->m_fHalfwayColour.x = Clamp(fParticleHalfwayColour.x + VERTTYPEMUL(f2vt(fRndFloat), fParticleHalfwayColourVariability.x));
	fRndFloat = RandFloat();
	pParticle->m_fHalfwayColour.y = Clamp(fParticleHalfwayColour.y + VERTTYPEMUL(f2vt(fRndFloat), fParticleHalfwayColourVariability.y));
	fRndFloat = RandFloat();
	pParticle->m_fHalfwayColour.z = Clamp(fParticleHalfwayColour.z + VERTTYPEMUL(f2vt(fRndFloat), fParticleHalfwayColourVariability.z));

	fRndFloat = RandFloat();
	pParticle->m_fEndColor.x = Clamp(fParticleEndColour.x + VERTTYPEMUL(f2vt(fRndFloat), fParticleEndColourVariability.x));
	fRndFloat = RandFloat();
	pParticle->m_fEndColor.y = Clamp(fParticleEndColour.y + VERTTYPEMUL(f2vt(fRndFloat), fParticleEndColourVariability.y));
	fRndFloat = RandFloat();
	pParticle->m_fEndColor.z = Clamp(fParticleEndColour.z + VERTTYPEMUL(f2vt(fRndFloat), fParticleEndColourVariability.z));

	// Creates the particle size using a perturbation.
	VERTTYPE fParticleSize = f2vt(2.0f);
	VERTTYPE fParticleSizeVariation = f2vt(1.5f);
	fRndFloat = RandFloat();
	pParticle->m_fSize = fParticleSize + VERTTYPEMUL(f2vt(fRndFloat), fParticleSizeVariation);
}
예제 #6
0
void CSystemInstance::SpawnParticle()
{
	m_iNumParticlesAlive++;
	m_iTotalEmitted++;

	CParticle* pNewParticle = NULL;

	for (size_t i = 0; i < m_aParticles.size(); i++)
	{
		CParticle* pParticle = &m_aParticles[i];

		if (pParticle->m_bActive)
			continue;

		pNewParticle = pParticle;
		break;
	}

	if (!pNewParticle)
	{
		m_aParticles.push_back(CParticle());
		pNewParticle = &m_aParticles[m_aParticles.size()-1];
	}

	Vector vecDistance = Vector(0,0,0);
	if (m_pSystem->GetEmissionMaxDistance() > 0)
	{
		float flYaw = RandomFloat(-180, 180);
		float flDistance = cos(RandomFloat(0, M_PI/2)) * m_pSystem->GetEmissionMaxDistance();
		float flPitch = sin(RandomFloat(-M_PI/2, M_PI/2)) * 90;
		vecDistance = AngleVector(EAngle(flPitch, flYaw, 0)) * flDistance;
	}

	pNewParticle->Reset();
	pNewParticle->m_vecOrigin = m_vecOrigin + m_pSystem->GetSpawnOffset() + vecDistance;
	pNewParticle->m_vecVelocity = m_vecInheritedVelocity * m_pSystem->GetInheritedVelocity();

	if (m_pSystem->GetRandomVelocity().Size().LengthSqr() > 0)
	{
		Vector vecMins = m_pSystem->GetRandomVelocity().m_vecMins;
		Vector vecMaxs = m_pSystem->GetRandomVelocity().m_vecMaxs;
		pNewParticle->m_vecVelocity.x += RandomFloat(vecMins.x, vecMaxs.x);
		pNewParticle->m_vecVelocity.y += RandomFloat(vecMins.y, vecMaxs.y);
		pNewParticle->m_vecVelocity.z += RandomFloat(vecMins.z, vecMaxs.z);
	}

	pNewParticle->m_angAngles = m_angAngles;

	if (m_pSystem->GetRandomModelYaw())
		pNewParticle->m_angAngles.y = RandomFloat(0, 360);

	if (m_pSystem->GetRandomModelRoll())
		pNewParticle->m_angAngles.r = RandomFloat(-180, 180);

	if (m_pSystem->GetRandomAngleVelocity())
		pNewParticle->m_angAngleVelocity = EAngle(RandomFloat(-90, 90), RandomFloat(-180, 180), RandomFloat(-90, 90));

	if (m_pSystem->GetFadeIn())
		pNewParticle->m_flAlpha = 0;
	else
		pNewParticle->m_flAlpha = m_pSystem->GetAlpha();

	pNewParticle->m_flRadius = m_pSystem->GetStartRadius();

	if (m_pSystem->GetRandomBillboardYaw())
		pNewParticle->m_flBillboardYaw = RandomFloat(0, 360);
	else
		pNewParticle->m_flBillboardYaw = 0;
}