/** If necessary defines a new particle type for the terrain emitter. Then 
 *  adjusts the location of the terrain emitter to be in synch with the 
 *  current wheel position, and defines the emission rate depending on speed,
 *  steering, and skidding.
 *  \param pk Particle type to use.
 */
void KartGFX::updateTerrain(const ParticleKind *pk)
{
   ParticleEmitter *pe = m_all_emitters[KGFX_TERRAIN];
    if(!pe) return;

    pe->setParticleType(pk);
 
    const btWheelInfo &wi = m_kart->getVehicle()
                                  ->getWheelInfo(2+m_wheel_toggle);
    Vec3 xyz = wi.m_raycastInfo.m_contactPointWS;
    // FIXME: the X and Z position is not always accurate.
    xyz.setX(xyz.getX()+ 0.06f * (m_wheel_toggle ? +1 : -1));
    xyz.setZ(xyz.getZ()+0.06f);
    pe->setPosition(xyz);

    // Now compute the particle creation rate:
    float rate           = 0;
    const float speed    = fabsf(m_kart->getSpeed());
    const float skidding = m_kart->getSkidding()->getSkidFactor();
    // Only create particles when the kart is actually on ground
    bool on_ground       = m_kart->isOnGround() &&
                           m_kart->getSkidding()->getGraphicalJumpOffset()==0;
    if (skidding > 1.0f && on_ground)
        rate = fabsf(m_kart->getControls().m_steer) > 0.8 ? skidding - 1 : 0;
    else if (speed >= 0.5f && on_ground)
        rate = speed/m_kart->getKartProperties()->getMaxSpeed();
    else
    {
        pe->setCreationRateAbsolute(0);
        return;
    }
    // m_skidding can be > 2, and speed > maxSpeed (if powerups are used).
    if(rate>1.0f) rate = 1.0f;
    pe->setCreationRateRelative(rate);
}   // updateTerrain
Ejemplo n.º 2
0
/** Defines the new position of the specified emitter.
 *  \param type The emitter to set a new position for.
 *  \param xyz The new position of the emitter.
 */
void KartGFX::setXYZ(const KartGFXType type, const Vec3 &xyz)
{
#ifndef SERVER_ONLY
    ParticleEmitter *pe = m_all_emitters[KGFX_TERRAIN];
    if(!pe) return;
    pe->setPosition(xyz);
#endif
}   // setXYZ
Ejemplo n.º 3
0
void CScene::UpdateWeather(Camera* cam, float mul)
{
	const Vector3& pos = cam->getPosition(), dir = cam->getDirection();
	static Vector3 oldPos = Vector3::ZERO;

	Vector3 vel = (pos-oldPos) * app->mWindow->getLastFPS();  oldPos = pos;
	Vector3 par = pos + dir * 12.f + vel * 0.6f;

	if (pr && sc->rainEmit > 0)
	{
		ParticleEmitter* pe = pr->getEmitter(0);
		pe->setPosition(par);
		pe->setEmissionRate(mul * sc->rainEmit);
	}
	if (pr2 && sc->rain2Emit > 0)
	{
		ParticleEmitter* pe = pr2->getEmitter(0);
		pe->setPosition(par);
		pe->setEmissionRate(mul * sc->rain2Emit);
	}
}
Ejemplo n.º 4
0
void ParticleSystem::_applyMotion(Real timeElapsed)
{
    ActiveParticleList::iterator i, itEnd;
    Particle* pParticle;
    ParticleEmitter* pParticleEmitter;
    itEnd = mActiveParticles.end();
    for (i = mActiveParticles.begin(); i != itEnd; ++i)
    {
        pParticle = static_cast<Particle*>(*i);
        pParticle->position += (pParticle->direction * timeElapsed);

	    if (pParticle->particleType == Particle::Emitter)
	    {
	        // If it is an emitter, the emitter position must also be updated
	        // Note, that position of the emitter becomes a position in worldspace if mLocalSpace is set 
	        // to false (will this become a problem?)
	        pParticleEmitter = static_cast<ParticleEmitter*>(*i);
	        pParticleEmitter->setPosition(pParticle->position);
	    }
    }

    // Notify renderer
    mRenderer->_notifyParticleMoved(mActiveParticles);
}
/** Defines the new position of the specified emitter.
 *  \param type The emitter to set a new position for.
 *  \param xyz The new position of the emitter.
 */
void KartGFX::setXYZ(const KartGFXType type, const Vec3 &xyz)
{
    ParticleEmitter *pe = m_all_emitters[KGFX_TERRAIN];
    if(!pe) return;
    pe->setPosition(xyz);
}   // setXYZ
Ejemplo n.º 6
0
ParticleEmitter* ParticleEmitter::create(Properties* properties)
{
    if (!properties || strcmp(properties->getNamespace(), "particle") != 0)
    {
        GP_ERROR("Properties object must be non-null and have namespace equal to 'particle'.");
        return NULL;
    }

    Properties* sprite = properties->getNextNamespace();
    if (!sprite || strcmp(sprite->getNamespace(), "sprite") != 0)
    {
        GP_ERROR("Failed to load particle emitter: required namespace 'sprite' is missing.");
        return NULL;
    }

    // Load sprite properties.
    // Path to image file is required.
    const char* texturePath = sprite->getString("path");
    if (!texturePath || strlen(texturePath) == 0)
    {
        GP_ERROR("Failed to load particle emitter: required image file path ('path') is missing.");
        return NULL;
    }

    const char* blendingString = sprite->getString("blending");
    TextureBlending textureBlending = getTextureBlendingFromString(blendingString);
    int spriteWidth = sprite->getInt("width");
    int spriteHeight = sprite->getInt("height");
    bool spriteAnimated = sprite->getBool("animated");
    bool spriteLooped = sprite->getBool("looped");
    int spriteFrameCount = sprite->getInt("frameCount");
    int spriteFrameRandomOffset = sprite->getInt("frameRandomOffset");
    float spriteFrameDuration = sprite->getFloat("frameDuration");

    // Emitter properties.
    unsigned int particleCountMax = (unsigned int)properties->getInt("particleCountMax");
    if (particleCountMax == 0)
    {
        // Set sensible default.
        particleCountMax = PARTICLE_COUNT_MAX;
    }

    unsigned int emissionRate = (unsigned int)properties->getInt("emissionRate");
    if (emissionRate == 0)
    {
        emissionRate = PARTICLE_EMISSION_RATE;
    }

    bool ellipsoid = properties->getBool("ellipsoid");
    float sizeStartMin = properties->getFloat("sizeStartMin");
    float sizeStartMax = properties->getFloat("sizeStartMax");
    float sizeEndMin = properties->getFloat("sizeEndMin");
    float sizeEndMax = properties->getFloat("sizeEndMax");
    long energyMin = properties->getLong("energyMin");
    long energyMax = properties->getLong("energyMax");

    Vector4 colorStart;
    Vector4 colorStartVar;
    Vector4 colorEnd;
    Vector4 colorEndVar;
    properties->getVector4("colorStart", &colorStart);
    properties->getVector4("colorStartVar", &colorStartVar);
    properties->getVector4("colorEnd", &colorEnd);
    properties->getVector4("colorEndVar", &colorEndVar);

    Vector3 position;
    Vector3 positionVar;
    Vector3 velocity;
    Vector3 velocityVar;
    Vector3 acceleration;
    Vector3 accelerationVar;
    Vector3 rotationAxis;
    Vector3 rotationAxisVar;
    properties->getVector3("position", &position);
    properties->getVector3("positionVar", &positionVar);
    properties->getVector3("velocity", &velocity);
    properties->getVector3("velocityVar", &velocityVar);
    properties->getVector3("acceleration", &acceleration);
    properties->getVector3("accelerationVar", &accelerationVar);
    float rotationPerParticleSpeedMin = properties->getFloat("rotationPerParticleSpeedMin");
    float rotationPerParticleSpeedMax = properties->getFloat("rotationPerParticleSpeedMax");
    float rotationSpeedMin = properties->getFloat("rotationSpeedMin");
    float rotationSpeedMax = properties->getFloat("rotationSpeedMax");
    properties->getVector3("rotationAxis", &rotationAxis);
    properties->getVector3("rotationAxisVar", &rotationAxisVar);
    bool orbitPosition = properties->getBool("orbitPosition");
    bool orbitVelocity = properties->getBool("orbitVelocity");
    bool orbitAcceleration = properties->getBool("orbitAcceleration");

    // Apply all properties to a newly created ParticleEmitter.
    ParticleEmitter* emitter = ParticleEmitter::create(texturePath, textureBlending, particleCountMax);
    if (!emitter)
    {
        GP_ERROR("Failed to create particle emitter.");
        return NULL;
    }
    emitter->setEmissionRate(emissionRate);
    emitter->setEllipsoid(ellipsoid);
    emitter->setSize(sizeStartMin, sizeStartMax, sizeEndMin, sizeEndMax);
    emitter->setEnergy(energyMin, energyMax);
    emitter->setColor(colorStart, colorStartVar, colorEnd, colorEndVar);
    emitter->setPosition(position, positionVar);
    emitter->setVelocity(velocity, velocityVar);
    emitter->setAcceleration(acceleration, accelerationVar);
    emitter->setRotationPerParticle(rotationPerParticleSpeedMin, rotationPerParticleSpeedMax);
    emitter->setRotation(rotationSpeedMin, rotationSpeedMax, rotationAxis, rotationAxisVar);

    emitter->setSpriteAnimated(spriteAnimated);
    emitter->setSpriteLooped(spriteLooped);
    emitter->setSpriteFrameRandomOffset(spriteFrameRandomOffset);
    emitter->setSpriteFrameDuration(spriteFrameDuration);
    emitter->setSpriteFrameCoords(spriteFrameCount, spriteWidth, spriteHeight);

    emitter->setOrbit(orbitPosition, orbitVelocity, orbitAcceleration);

    return emitter;
}
Ejemplo n.º 7
0
void ParticleSystem::_executeTriggerEmitters(ParticleEmitter* emitter, unsigned requested, Real timeElapsed)
{
    ParticleAffectorList::iterator itAff, itAffEnd;
    Real timePoint = 0.0f;

    // avoid any divide by zero conditions
    if (!requested) 
    {
	return;
    }

    Real timeInc = timeElapsed / requested;

    for (unsigned int j = 0; j < requested; ++j)
    {
	// Create a new particle & init using emitter
	// The particle is a visual particle if the emit_emitter property of the emitter isn't set 
	Particle* p = 0;
	String	emitterName = emitter->getEmittedEmitter();
	if (emitterName == "")
        {
	    p = createParticle();
        }
	else
        {
	    p = createEmitterParticle(emitterName);
        }

	// Only continue if the particle was really created (not null)
	if (!p)
        {
	    return;
        }

	emitter->_initParticle(p);

	// apply partial frame motion to this particle
        p->position += (p->direction * timePoint);

	// apply particle initialization by the affectors
	itAffEnd = mAffectors.end();
	for (itAff = mAffectors.begin(); itAff != itAffEnd; ++itAff)
        {
	    (*itAff)->_initParticle(p);
        }

	// Increment time fragment
	timePoint += timeInc;

	if (p->particleType == Particle::Emitter)
	{
	    // If the particle is an emitter, the position on the emitter side must also be initialised
	    // Note, that position of the emitter becomes a position in worldspace if mLocalSpace is set 
	    // to false (will this become a problem?)
	    ParticleEmitter* pParticleEmitter = static_cast<ParticleEmitter*>(p);
	    pParticleEmitter->setPosition(p->position);
	}

        // Notify renderer
        mRenderer->_notifyParticleEmitted(p);
    }
}
//-------------------------------------------------------------------------------------------------------
//  Update
//-------------------------------------------------------------------------------------------------------
void CarModel::Update(PosInfo& posInfo, PosInfo& posInfoCam, float time)
{	
	pReflect->camPosition = pMainNode->getPosition();
	int w,i;
	
	//  upd chk mtr
	if (bChkUpd && entNextChk)
	{
		MaterialPtr mtr = MaterialManager::getSingleton().getByName(sChkMtr);
		if (!mtr.isNull())
			entNextChk->setMaterial(mtr);
	}

	//  stop/resume par sys
	float fa = pGame->pause ? 0.f : 1.f;
	for (w=0; w < numWheels; ++w)
	{
		for (i=0; i < PAR_ALL; ++i)
			if (par[i][w])  par[i][w]->setSpeedFactor(fa);
		if (w < PAR_BOOST && parBoost[w])  parBoost[w]->setSpeedFactor(fa);
		if (parHit)  parHit->setSpeedFactor(fa);
	}
	for (w=0; w < PAR_THRUST*2; ++w)
		if (parThrust[w])  parThrust[w]->setSpeedFactor(fa);


	if (!posInfo.bNew)  return;  // new only ?
	posInfo.bNew = false;
	/// dont get anything from pCar or car.dynamics here
	/// all must be read from posInfo (it is filled from vdrift car or from replay)
	
	if (!pMainNode)  return;

	//  set car pos and rot
	pMainNode->setPosition(posInfo.pos);
	if (vtype == V_Sphere)
		pMainNode->setOrientation(Quaternion(Quaternion(Degree(-posInfo.hov_roll),Vector3::UNIT_Y)));
	else
	if (vtype == V_Spaceship)  // roll  vis only
		pMainNode->setOrientation(posInfo.rot * Quaternion(Degree(posInfo.hov_roll),Vector3::UNIT_X));
	else
		pMainNode->setOrientation(posInfo.rot);
	
	///()  grass sphere pos
	Vector3 vx(1,0,0);  // car x dir
	vx = posInfo.rot * vx * 1.1;  //par
	posSph[0] = posInfo.pos + vx;  posSph[0].y += 0.5f;
	posSph[1] = posInfo.pos - vx;  posSph[1].y += 0.5f;
	if (ndSph)  // sph test
	{	ndSph->setPosition(posSph[0]);
		ndSph->setScale(Vector3::UNIT_SCALE * 1.7 *2/0.6f);  //par
	}

	//  set camera view
	if (fCam)
	{	fCam->Apply(posInfoCam);
		
		///~~  camera in fluid fog, detect and compute
		iCamFluid = -1;  fCamFl = 0.f;  // none
		const size_t sf = sc->fluids.size();
		if (sf > 0  && pSet->game.local_players == 1)
		{
			const Vector3& p = posInfo.camPos;
			const float r = 0.2f;  //par, near cam?
			
			//  check if any fluid box overlaps camera pos sphere
			bool srch = true;  size_t f = 0;
			while (srch && f < sf)
			{
				const FluidBox& fb = sc->fluids[f];
				const Vector3& fp = fb.pos;
				Vector3 fs = fb.size;  fs.x *= 0.5f;  fs.z *= 0.5f;
				
				bool inFl =  //  p +r   -fs fp +fs  -r p
					p.y +r > fp.y - fs.y && p.y -r < fp.y &&
					p.x +r > fp.x - fs.x && p.x -r < fp.x + fs.x &&
					p.z +r > fp.z - fs.z && p.z -r < fp.z + fs.z;
				
				if (inFl)  // 1st only
				{	iCamFluid = f;  fCamFl = std::min(1.f, std::max(0.f, fp.y - p.y)) * 3.f;
					srch = false;  }
				++f;
			}
	}	}

	//  upd rotY for minimap
	if (vtype == V_Sphere)
		angCarY = posInfo.hov_roll * 180.f / PI_d + 180.f;
	else
	{	Quaternion q = posInfo.rot * Quaternion(Degree(90),Vector3(0,1,0));
		angCarY = q.getYaw().valueDegrees() + 90.f;
	}
	
	//  brake state
	#ifndef CAR_PRV
	bool braking = posInfo.braking > 0;
	if (bBraking != braking)
	{
		bBraking = braking;
		UpdateBraking();
	}
	#endif
	
	//  terrain lightmap enable/disable (depending on distance to terrain)
	#define MAX_TERRAIN_DIST 2.0  // meters
	bool changed = false;
	if (terrain)
	{
		Vector3 carPos = pMainNode->getPosition();
		float terrainHeight = terrain->getHeightAtWorldPosition(carPos);
		float diff = std::abs(carPos.y - terrainHeight);
		if (diff > MAX_TERRAIN_DIST)
		{
			if (bLightMapEnabled)
			{	changed = true;  bLightMapEnabled = false;	}
		}
		else if (!bLightMapEnabled)
		{	changed = true;  bLightMapEnabled = true;	}
	}
	//  if no terrain, disable
	else if (bLightMapEnabled)
	{	changed = true;  bLightMapEnabled = false;	}
	
	if (changed)
		UpdateLightMap();
		

	//  update particle emitters
	if (pSet->particles && pCar)
	{
		//  boost
		for (i=0; i < PAR_BOOST; ++i)  if (parBoost[i])
		{
			/// <><> damage reduce
			float dmg = pCar->dynamics.fDamage >= 80.f ? 0.f : std::max(0.f, 1.4f - pCar->dynamics.fDamage*0.01f);
			float emitB = posInfo.fboost * 40.f * dmg;  // par
			ParticleEmitter* pe = parBoost[i]->getEmitter(0);
			pe->setEmissionRate(emitB);
		}
		//  spaceship thrusters
		for (i=0; i < PAR_THRUST*2; ++i)  if (parThrust[i])
		{
			float dmg = 1.f - 0.5f * pCar->dynamics.fDamage*0.01f;
			float emitT = posInfo.hov_throttle * 60.f * dmg;  // par
			ParticleEmitter* pe = parThrust[i]->getEmitter(0);
			pe->setEmissionRate(emitT);
		}
	}

	//  world hit
	if (parHit)
	{	ParticleEmitter* pe = parHit->getEmitter(0);
		if (posInfo.fHitTime > 0.f && pSet->particles)
		{
			pe->setPosition(posInfo.vHitPos);
			pe->setDirection(posInfo.vHitNorm);

			pe->setEmissionRate(pSet->particles_len * std::min(160.f, posInfo.fParIntens) * posInfo.fHitTime);
			pe->setParticleVelocity(posInfo.fParVel);
		}else
			pe->setEmissionRate(0.f);
	}

	//  wheels  ------------------------------------------------------------------------
	const float trlH = sc->ter ? 0.90f : 0.76f;  // vdr needs up (ter bumps), no ter  ..get from wheel contact ?rpl

	for (w=0; w < numWheels; ++w)
	{
		float wR = whRadius[w];
		#ifdef CAM_TILT_DBG  // cam debug test only
			if (fCam)
				ndWh[w]->setPosition(fCam->posHit[w]);
			ndWh[w]->setScale(0.5f*Vector3::UNIT_SCALE);
		#else
		ndWh[w]->setPosition(posInfo.whPos[w]);
		#endif
		ndWh[w]->setOrientation(posInfo.whRot[w]);

		///  Update particles and trails
		if (isGhostTrk())
			continue;  // doesnt have any
		
		int whMtr = posInfo.whTerMtr[w];
		int whRd = posInfo.whRoadMtr[w];
		
		bool pipe = whRd >= 30 && whRd < 60;  //old: whRd == 2;
		//todo: road,pipe 4mtr [whRd] layer params..
		float whVel = posInfo.whVel[w] * 3.6f;  //kmh
		float slide = posInfo.whSlide[w], squeal = posInfo.whSqueal[w];
			//LogO(" slide:"+fToStr(slide,3,5)+" squeal:"+fToStr(squeal,3,5));
		float onGr = slide < 0.f ? 0.f : 1.f;

		//  wheel temp
		whTemp[w] += std::min(12.f, std::max(0.f, squeal*8 - slide*2 + squeal*slide*2)*time);
		whTemp[w] = std::min(1.5f, whTemp[w]);  ///*
		whTemp[w] -= time*7.f;  if (whTemp[w] < 0.f)  whTemp[w] = 0.f;
			//LogO(toStr(w)+" wht "+fToStr(wht[w],3,5));

		///  emit rates +
		Real sq = squeal* std::min(1.f, whTemp[w]), l = pSet->particles_len * onGr;
		Real emitS = sq * (whVel * 30) * l * 0.45f;  ///*
		Real emitM = slide < 1.4f ? 0.f :  (8.f * sq * std::min(5.f, slide) * l);
		Real emitD = (std::min(140.f, whVel) / 3.5f + slide * 1.f ) * l;  
		Real sizeD = (0.8f + 0.6f * std::min(140.f, whVel) / 140.f) * (w < 2 ? 0.7f : 1.1f);

		//  ter mtr factors
		int mtr = std::max(0, std::min(whMtr-1, (int)(sc->td.layers.size()-1)));
		int rd  = sc->td.road1mtr ? 0 : std::max(0, std::min(3, whRd));

		TerLayer& lay = whMtr==0 ? sc->td.layerRoad[rd] : sc->td.layersAll[sc->td.layers[mtr]];
		emitD *= lay.dust;  emitM *= lay.mud;  sizeD *= lay.dustS;  emitS *= lay.smoke;

		if (pipe)  emitD = 0;  // no dust in pipes
		if (posInfo.whH[w] > 0.1f)  emitD = 0;  // no dust in fluids

		bool ghost = isGhost();  // opt dis for ghost
		bool ghPar = !(ghost && !pSet->rpl_ghostpar);
		if (!ghPar)
		{	emitD = 0.f;  emitM = 0.f;  emitS = 0.f;  }

		///  emit particles
		Vector3 vpos = posInfo.whPos[w];
		if (pSet->particles)
		{
			ParticleSystem* ps = par[PAR_Smoke][w];
			if (ps)  //  smoke
			{	ParticleEmitter* pe = ps->getEmitter(0);
				pe->setPosition(vpos + posInfo.carY * wR*0.7f);  ///*
				ps->getAffector(0)->setParameter("alpha", toStr(-0.2f - 0.023f * whVel));  // fade out speed
				pe->setTimeToLive( std::max(0.12f, 2.f - whVel * 0.06f) );  // live time
				pe->setDirection(-posInfo.carY);	pe->setEmissionRate(emitS);
			}
			ps = par[PAR_Mud][w];
			if (ps)	 //  mud
			{	ParticleEmitter* pe = ps->getEmitter(0);
				//pe->setDimensions(sizeM,sizeM);
				pe->setPosition(vpos + posInfo.carY * wR*0.7f);
				pe->setDirection(-posInfo.carY);	pe->setEmissionRate(emitM);
			}
			ps = par[PAR_Dust][w];
			if (ps)	 //  dust
			{	ps->setDefaultDimensions(sizeD,sizeD);
				ParticleEmitter* pe = ps->getEmitter(0);
				pe->setPosition(vpos + posInfo.carY * wR*0.31f);
				pe->setDirection(-posInfo.carY);	pe->setEmissionRate(emitD);
			}

			//  fluids .::.
			ps = par[PAR_Water][w];
			int idPar = posInfo.whP[w];
			if (ps)  //  Water ~
			{
				float vel = posInfo.speed;  // depth.. only on surface?
				bool e = idPar == 0 && ghPar &&  vel > 10.f && posInfo.whH[w] < 1.f;
				float emitW = e ?  std::min(80.f, 5.0f * vel)  : 0.f;

				ParticleEmitter* pe = ps->getEmitter(0);
				pe->setPosition(vpos + posInfo.carY * wR*0.51f);
				pe->setMinParticleVelocity(0.07* vel);
				pe->setMaxParticleVelocity(0.20* vel);
				pe->setDirection(-posInfo.carY);	pe->setEmissionRate(emitW * pSet->particles_len);
			}
			ps = par[PAR_MudHard][w];
			if (ps)  //  Mud ^
			{
				float vel = Math::Abs(posInfo.whAngVel[w]);
				bool e = idPar == 2 && ghPar &&  vel > 30.f;
				float emitM = e ?  posInfo.whH[w] * std::min(80.f, 1.5f * vel)  : 0.f;

				ParticleEmitter* pe = ps->getEmitter(0);
				pe->setPosition(vpos + posInfo.carY * wR*0.51f);
				pe->setDirection(-posInfo.carY);	pe->setEmissionRate(emitM * pSet->particles_len);
			}
			ps = par[PAR_MudSoft][w];
			if (ps)  //  Mud soft ^
			{
				float vel = Math::Abs(posInfo.whAngVel[w]);
				bool e = idPar == 1 && ghPar &&  vel > 30.f;
				float emitM = e ?  posInfo.whH[w] * std::min(160.f, 3.f * vel)  : 0.f;

				ParticleEmitter* pe = ps->getEmitter(0);
				pe->setPosition(vpos + posInfo.carY * wR*0.51f);
				pe->setDirection(-posInfo.carY);	pe->setEmissionRate(emitM * pSet->particles_len);
			}
		}

		//  update trails h+
		if (pSet->trails)
		{	if (ndWhE[w])
			{	Vector3 vp = vpos + posInfo.carY * wR*trlH;
				if (terrain && whMtr > 0)
					vp.y = terrain->getHeightAtWorldPosition(vp) + 0.02f;  // 0.05f
					//if (/*whOnRoad[w]*/whMtr > 0 && road)  // on road, add ofs
					//	vp.y += road->fHeight;	}/**/
				ndWhE[w]->setPosition(vp);
				ndWhE[w]->setOrientation(posInfo.rot);
			}
			//  const trail alpha
			float ac = pipe ? 0.f : /*own par..*/lay.smoke < 0.5f ? 0.14f : 0.f;
			float al = (ac + 0.6f * std::min(1.f, 0.7f * whTemp[w]) ) * onGr;  // par+
			if (whTrail[w])
			{	whTrail[w]->setInitialColour(0,
				lay.tcl.x, lay.tcl.y, lay.tcl.z, lay.tcl.w * al/**/);
				if (iFirst > 10)  //par
					whTrail[w]->setInitialWidth(0, whWidth[w]);
			}
		}
	}
	
	//  blendmap
	UpdWhTerMtr();
	
	//  update brake meshes orientation
	for (w=0; w < numWheels; ++w)
	{
		if (ndBrake[w])
		{
			ndBrake[w]->_setDerivedOrientation( pMainNode->getOrientation() );
			
			// this transformation code is just so the brake mesh can have the same alignment as the wheel mesh
			ndBrake[w]->yaw(Degree(-90), Node::TS_LOCAL);
			if (w%2 == 1)
				ndBrake[w]->setScale(-1, 1, 1);
				
			ndBrake[w]->pitch(Degree(180), Node::TS_LOCAL);
			
			if (w < 2)  // turn only front wheels
				ndBrake[w]->yaw(-Degree(posInfo.whSteerAng[w]));
		}
	}
	
	if (iFirst <= 10)  ++iFirst;  //par
	
	UpdateKeys();
}
Ejemplo n.º 9
0
void ParticlesGame::controlEvent(Control* control, EventType evt)
{
    std::string id = control->getId();

    // Handle UI events.
    ParticleEmitter* emitter = _particleEmitterNode->getParticleEmitter();
    switch(evt)
    {
    case Listener::VALUE_CHANGED:
        if (control == _startRed)
        {
            Vector4 startColor = emitter->getColorStart();
            startColor.x = _startRed->getValue();
            emitter->setColor(startColor, emitter->getColorStartVariance(), emitter->getColorEnd(), emitter->getColorEndVariance());
        }
        else if (control == _startGreen)
        {
            Vector4 startColor = emitter->getColorStart();
            startColor.y = _startGreen->getValue();
            emitter->setColor(startColor, emitter->getColorStartVariance(), emitter->getColorEnd(), emitter->getColorEndVariance());
        }
        else if (control == _startBlue)
        {
            Vector4 startColor = emitter->getColorStart();
            startColor.z = _startBlue->getValue();
            emitter->setColor(startColor, emitter->getColorStartVariance(), emitter->getColorEnd(), emitter->getColorEndVariance());
        }
        else if (control == _startAlpha)
        {
            Vector4 startColor = emitter->getColorStart();
            startColor.w = _startAlpha->getValue();
            emitter->setColor(startColor, emitter->getColorStartVariance(), emitter->getColorEnd(), emitter->getColorEndVariance());
        }
        else if (control == _endRed)
        {
            Vector4 endColor = emitter->getColorEnd();
            endColor.x = _endRed->getValue();
            emitter->setColor(emitter->getColorStart(), emitter->getColorStartVariance(), endColor, emitter->getColorEndVariance());
        }
        else if (control == _endGreen)
        {
            Vector4 endColor = emitter->getColorEnd();
            endColor.y = _endGreen->getValue();
            emitter->setColor(emitter->getColorStart(), emitter->getColorStartVariance(), endColor, emitter->getColorEndVariance());
        }
        else if (control == _endBlue)
        {
            Vector4 endColor = emitter->getColorEnd();
            endColor.z = _endBlue->getValue();
            emitter->setColor(emitter->getColorStart(), emitter->getColorStartVariance(), endColor, emitter->getColorEndVariance());
        }
        else if (control == _endAlpha)
        {
            Vector4 endColor = emitter->getColorEnd();
            endColor.w = _endAlpha->getValue();
            emitter->setColor(emitter->getColorStart(), emitter->getColorStartVariance(), endColor, emitter->getColorEndVariance());
        }
        else if (control == _startMin)
        {
            emitter->setSize(_startMin->getValue(), emitter->getSizeStartMax(), emitter->getSizeEndMin(), emitter->getSizeEndMax());
        }
        else if (control == _startMax)
        {
            emitter->setSize(emitter->getSizeStartMin(), _startMax->getValue(), emitter->getSizeEndMin(), emitter->getSizeEndMax());
        }
        else if (control == _endMin)
        {
            emitter->setSize(emitter->getSizeStartMin(), emitter->getSizeStartMax(), _endMin->getValue(), emitter->getSizeEndMax());
        }
        else if (control == _endMax)
        {
            emitter->setSize(emitter->getSizeStartMin(), emitter->getSizeStartMax(), emitter->getSizeEndMin(), _endMax->getValue());
        }
        else if (control == _energyMin)
        {
            emitter->setEnergy(_energyMin->getValue(), emitter->getEnergyMax());
        }
        else if (control == _energyMax)
        {
            emitter->setEnergy(emitter->getEnergyMin(), _energyMax->getValue());
        }
        else if (control == _emissionRate)
        {
            emitter->setEmissionRate(_emissionRate->getValue());
        }
        else if (id == "posX")
        {
            Vector3 pos(emitter->getPosition());
            pos.x = ((Slider*)control)->getValue();
            emitter->setPosition(pos, emitter->getPositionVariance());
        }
        else if (id == "posY")
        {
            Vector3 pos(emitter->getPosition());
            pos.y = ((Slider*)control)->getValue();
            emitter->setPosition(pos, emitter->getPositionVariance());
        }
        else if (id == "posZ")
        {
            Vector3 pos(emitter->getPosition());
            pos.z = ((Slider*)control)->getValue();
            emitter->setPosition(pos, emitter->getPositionVariance());
        }
        else if (control == _posVarX)
        {
            Vector3 posVar = emitter->getPositionVariance();
            posVar.x = _posVarX->getValue();
            emitter->setPosition(emitter->getPosition(), posVar);
        }
        else if (control == _posVarY)
        {
            Vector3 posVar = emitter->getPositionVariance();
            posVar.y = _posVarY->getValue();
            emitter->setPosition(emitter->getPosition(), posVar);
        }
        else if (control == _posVarZ)
        {
            Vector3 posVar = emitter->getPositionVariance();
            posVar.z = _posVarZ->getValue();
            emitter->setPosition(emitter->getPosition(), posVar);
        }
        else if (control == _velX)
        {
            Vector3 vel = emitter->getVelocity();
            vel.x = _velX->getValue();
            emitter->setVelocity(vel, emitter->getVelocityVariance());
        }
        else if (control == _velY)
        {
            Vector3 vel = emitter->getVelocity();
            vel.y = _velY->getValue();
            emitter->setVelocity(vel, emitter->getVelocityVariance());
        }
        else if (control == _velZ)
        {
            Vector3 vel = emitter->getVelocity();
            vel.z = _velZ->getValue();
            emitter->setVelocity(vel, emitter->getVelocityVariance());
        }
        else if (control == _velVarX)
        {
            Vector3 velVar = emitter->getVelocityVariance();
            velVar.x = _velVarX->getValue();
            emitter->setVelocity(emitter->getVelocity(), velVar);
        }
        else if (control == _velVarY)
        {
            Vector3 velVar = emitter->getVelocityVariance();
            velVar.y = _velVarY->getValue();
            emitter->setVelocity(emitter->getVelocity(), velVar);
        }
        else if (control == _velVarZ)
        {
            Vector3 velVar = emitter->getVelocityVariance();
            velVar.z = _velVarZ->getValue();
            emitter->setVelocity(emitter->getVelocity(), velVar);
        }
        else if (control == _accelX)
        {
            Vector3 accel = emitter->getAcceleration();
            accel.x = _accelX->getValue();
            emitter->setAcceleration(accel, emitter->getAccelerationVariance());
        }
        else if (control == _accelY)
        {
            Vector3 accel = emitter->getAcceleration();
            accel.y = _accelY->getValue();
            emitter->setAcceleration(accel, emitter->getAccelerationVariance());
        }
        else if (control == _accelZ)
        {
            Vector3 accel = emitter->getAcceleration();
            accel.z = _accelZ->getValue();
            emitter->setAcceleration(accel, emitter->getAccelerationVariance());
        }
        else if (control == _accelVarX)
        {
            Vector3 accelVar = emitter->getAccelerationVariance();
            accelVar.x = _accelVarX->getValue();
            emitter->setAcceleration(emitter->getAcceleration(), accelVar);
        }
        else if (control == _accelVarY)
        {
            Vector3 accelVar = emitter->getAccelerationVariance();
            accelVar.y = _accelVarY->getValue();
            emitter->setAcceleration(emitter->getAcceleration(), accelVar);
        }
        else if (control == _accelVarZ)
        {
            Vector3 accelVar = emitter->getAccelerationVariance();
            accelVar.z = _accelVarZ->getValue();
            emitter->setAcceleration(emitter->getAcceleration(), accelVar);
        }
        else if (control == _spinSpeedMin)
        {
            emitter->setRotationPerParticle(_spinSpeedMin->getValue(), emitter->getRotationPerParticleSpeedMax());
        }
        else if (control == _spinSpeedMax)
        {
            emitter->setRotationPerParticle(emitter->getRotationPerParticleSpeedMin(), _spinSpeedMax->getValue());
        }
        else if (control == _axisX)
        {
            Vector3 axis = emitter->getRotationAxis();
            axis.x = _axisX->getValue();
            emitter->setRotation(emitter->getRotationSpeedMin(), emitter->getRotationSpeedMax(), axis, emitter->getRotationAxisVariance());
        }
        else if (control == _axisY)
        {
            Vector3 axis = emitter->getRotationAxis();
            axis.y = _axisY->getValue();
            emitter->setRotation(emitter->getRotationSpeedMin(), emitter->getRotationSpeedMax(), axis, emitter->getRotationAxisVariance());
        }
        else if (control == _axisZ)
        {
            Vector3 axis = emitter->getRotationAxis();
            axis.z = _axisZ->getValue();
            emitter->setRotation(emitter->getRotationSpeedMin(), emitter->getRotationSpeedMax(), axis, emitter->getRotationAxisVariance());
        }
        else if (control == _axisVarX)
        {
            Vector3 axisVar = emitter->getRotationAxisVariance();
            axisVar.x = _axisVarX->getValue();
            emitter->setRotation(emitter->getRotationSpeedMin(), emitter->getRotationSpeedMax(), emitter->getRotationAxis(), axisVar);
        }
        else if (control == _axisVarY)
        {
            Vector3 axisVar = emitter->getRotationAxisVariance();
            axisVar.y = _axisVarY->getValue();
            emitter->setRotation(emitter->getRotationSpeedMin(), emitter->getRotationSpeedMax(), emitter->getRotationAxis(), axisVar);
        }
        else if (control == _axisVarZ)
        {
            Vector3 axisVar = emitter->getRotationAxisVariance();
            axisVar.z = _axisVarZ->getValue();
            emitter->setRotation(emitter->getRotationSpeedMin(), emitter->getRotationSpeedMax(), emitter->getRotationAxis(), axisVar);
        }
        else if (control == _rotationSpeedMin)
        {
            emitter->setRotation(_rotationSpeedMin->getValue(), emitter->getRotationSpeedMax(), emitter->getRotationAxis(), emitter->getRotationAxisVariance());
        }
        else if (control == _rotationSpeedMax)
        {
            emitter->setRotation(emitter->getRotationSpeedMin(), _rotationSpeedMax->getValue(), emitter->getRotationAxis(), emitter->getRotationAxisVariance());
        }
        else if (control == _started)
        {
            if (_started->isChecked())
            {
                emitter->start();
            }
            else
            {
                emitter->stop();
            }
        }
        else if (control == _vsync)
        {
            Game::getInstance()->setVsync(_vsync->isChecked());
        }
        else if (id == "additive")
        {
            if (((RadioButton*)control)->isSelected())
                emitter->setTextureBlending(ParticleEmitter::BLEND_ADDITIVE);
        }
        else if (id == "transparent")
        {
            if (((RadioButton*)control)->isSelected())
                emitter->setTextureBlending(ParticleEmitter::BLEND_TRANSPARENT);
        }
        else if (id == "multiply")
        {
            if (((RadioButton*)control)->isSelected())
                emitter->setTextureBlending(ParticleEmitter::BLEND_MULTIPLIED);
        }
        else if (id == "opaque")
        {
            if (((RadioButton*)control)->isSelected())
                emitter->setTextureBlending(ParticleEmitter::BLEND_OPAQUE);
        }
        break;
    case Listener::CLICK:
        if (control == _reset)
        {
            // Re-load the current emitter and reset the view
            _particleEmitter = ParticleEmitter::create(_url.c_str());
            emitterChanged();
        }
        else if (control == _emit)
        {
            // Emit a burst of particles.
            unsigned int burstSize = (unsigned int)_burstSize->getValue();
            emitter->emitOnce(burstSize);
        }
        else if (id == "sprite")
        {
            updateTexture();
        }
        else if (id == "updateFrames")
        {
            updateFrames();
        }
        break;
    case Listener::PRESS:
        if (control == _zoomIn)
        {
            _wDown = true;
        }
        else if (control == _zoomOut)
        {
            _sDown = true;
        }
        break;
    case Listener::RELEASE:
        if (control == _zoomIn)
        {
            _wDown = false;
        }
        else if (control == _zoomOut)
        {
            _sDown = false;
        }
        else if (control == _save)
        {
            Game::getInstance()->pause();
            saveFile();
            Game::getInstance()->resume();
        }
        else if (control == _load)
        {
            Game::getInstance()->pause();
            std::string filename = FileSystem::displayFileDialog(FileSystem::OPEN, "Select Particle File", "Particle Files", "particle", "res");
            if (filename.length() > 0)
            {
                _url = filename;
                _particleEmitter = ParticleEmitter::create(_url.c_str());
                emitterChanged();
            }
            Game::getInstance()->resume();
        }
        break;
    }
}