Ejemplo n.º 1
0
//[-------------------------------------------------------]
//[ Private virtual PLScene::SceneNode functions          ]
//[-------------------------------------------------------]
void SNFireSample::InitFunction()
{
	// Call base implementation
	SNSystem::InitFunction();

	// Get the instance of the used renderer
	Renderer &cRenderer = GetSceneContext()->GetRendererContext().GetRenderer();

	// Inits Particle Engine
	// Renderers
	SPARK_PL::SPK_PLQuadRenderer *pFireRenderer = CreateSPK_PLQuadRenderer(cRenderer);
	pFireRenderer->setScale(0.3f,0.3f);
	pFireRenderer->setTexturingMode(SPK::TEXTURE_2D);
	pFireRenderer->SetTexture(GetSceneContext()->GetRendererContext().GetTextureManager().LoadResource("Data/Textures/SPARK/Fire2.dds"));
	pFireRenderer->setBlending(SPK::BLENDING_ADD);
	pFireRenderer->enableRenderingHint(SPK::DEPTH_WRITE, false);
	pFireRenderer->setAtlasDimensions(2, 2);

	SPARK_PL::SPK_PLQuadRenderer *pSmokeRenderer = CreateSPK_PLQuadRenderer(cRenderer);
	pSmokeRenderer->setScale(0.3f, 0.3f);
	pSmokeRenderer->setTexturingMode(SPK::TEXTURE_2D);
	pSmokeRenderer->SetTexture(GetSceneContext()->GetRendererContext().GetTextureManager().LoadResource("Data/Textures/SPARK/Explosion.dds"));
	pSmokeRenderer->setBlending(SPK::BLENDING_ALPHA);
	pSmokeRenderer->enableRenderingHint(SPK::DEPTH_WRITE, false);
	pSmokeRenderer->setAtlasDimensions(2, 2);

	// Create the SPARK particle models
	SPK::Model *pFireModel = SPK::Model::create(SPK::FLAG_RED | SPK::FLAG_GREEN | SPK::FLAG_BLUE | SPK::FLAG_ALPHA | SPK::FLAG_SIZE | SPK::FLAG_ANGLE | SPK::FLAG_TEXTURE_INDEX,
		SPK::FLAG_RED | SPK::FLAG_GREEN | SPK::FLAG_ALPHA | SPK::FLAG_ANGLE,
		SPK::FLAG_RED | SPK::FLAG_GREEN | SPK::FLAG_TEXTURE_INDEX | SPK::FLAG_ANGLE,
		SPK::FLAG_SIZE);
	pFireModel->setParam(SPK::PARAM_RED, 0.8f, 0.9f, 0.8f, 0.9f);
	pFireModel->setParam(SPK::PARAM_GREEN, 0.5f, 0.6f, 0.5f, 0.6f);
	pFireModel->setParam(SPK::PARAM_BLUE, 0.3f);
	pFireModel->setParam(SPK::PARAM_ALPHA, 0.4f, 0.0f);
	pFireModel->setParam(SPK::PARAM_ANGLE, 0.0f, static_cast<float>(2.0f*Math::Pi), 0.0f, static_cast<float>(2.0f*Math::Pi));
	pFireModel->setParam(SPK::PARAM_TEXTURE_INDEX, 0.0f, 4.0f);
	pFireModel->setLifeTime(1.0f, 1.5f);

	SPK::Interpolator *pInterpolator = pFireModel->getInterpolator(SPK::PARAM_SIZE);
	pInterpolator->addEntry(0.5f, 2.0f, 5.0f);
	pInterpolator->addEntry(1.0f, 0.0f);

	SPK::Model *pSmokeModel = SPK::Model::create(SPK::FLAG_RED | SPK::FLAG_GREEN | SPK::FLAG_BLUE | SPK::FLAG_ALPHA | SPK::FLAG_SIZE | SPK::FLAG_ANGLE | SPK::FLAG_TEXTURE_INDEX,
		SPK::FLAG_RED | SPK::FLAG_GREEN | SPK::FLAG_SIZE | SPK::FLAG_ANGLE,
		SPK::FLAG_TEXTURE_INDEX | SPK::FLAG_ANGLE,
		SPK::FLAG_ALPHA);
	pSmokeModel->setParam(SPK::PARAM_RED, 0.3f, 0.2f);
	pSmokeModel->setParam(SPK::PARAM_GREEN, 0.25f, 0.2f);
	pSmokeModel->setParam(SPK::PARAM_BLUE, 0.2f);
	pSmokeModel->setParam(SPK::PARAM_ALPHA, 0.2f, 0.0f);
	pSmokeModel->setParam(SPK::PARAM_SIZE, 5.0, 10.0f);
	pSmokeModel->setParam(SPK::PARAM_TEXTURE_INDEX, 0.0f, 4.0f);
	pSmokeModel->setParam(SPK::PARAM_ANGLE, 0.0f, static_cast<float>(2.0f*Math::Pi), 0.0f, static_cast<float>(2.0f*Math::Pi));
	pSmokeModel->setLifeTime(5.0f, 5.0f);

	pInterpolator = pSmokeModel->getInterpolator(SPK::PARAM_ALPHA);
	pInterpolator->addEntry(0.0f, 0.0f);
	pInterpolator->addEntry(0.2f, 0.2f);
	pInterpolator->addEntry(1.0f, 0.0f);

	// Create the SPARK particle emitters
	// The emitters are arranged so that the fire looks realistic
	SPK::StraightEmitter *pFireEmitter1 = SPK::StraightEmitter::create(SPK::Vector3D(0.0f, 1.0f, 0.0f));
	pFireEmitter1->setZone(SPK::Sphere::create(SPK::Vector3D(0.0f, -1.0f, 0.0f), 0.5f));
	pFireEmitter1->setFlow(40);
	pFireEmitter1->setForce(1.0f, 2.5f);

	SPK::StraightEmitter *pFireEmitter2 = SPK::StraightEmitter::create(SPK::Vector3D(1.0f, 0.6f, 0.0f));
	pFireEmitter2->setZone(SPK::Sphere::create(SPK::Vector3D(0.15f, -1.2f, 0.075f), 0.1f));
	pFireEmitter2->setFlow(15);
	pFireEmitter2->setForce(0.5f, 1.5f);

	SPK::StraightEmitter *pFireEmitter3 = SPK::StraightEmitter::create(SPK::Vector3D(-0.6f, 0.8f, -0.8f));
	pFireEmitter3->setZone(SPK::Sphere::create(SPK::Vector3D(-0.375f, -1.15f, -0.375f), 0.3f));
	pFireEmitter3->setFlow(15);
	pFireEmitter3->setForce(0.5f, 1.5f);

	SPK::StraightEmitter *pFireEmitter4 = SPK::StraightEmitter::create(SPK::Vector3D(-0.8f, 0.5f, 0.2f));
	pFireEmitter4->setZone(SPK::Sphere::create(SPK::Vector3D(-0.255f, -1.2f, 0.225f), 0.2f));
	pFireEmitter4->setFlow(10);
	pFireEmitter4->setForce(0.5f, 1.5f);

	SPK::StraightEmitter *pFireEmitter5 = SPK::StraightEmitter::create(SPK::Vector3D(0.1f, 0.8f, -1.0f));
	pFireEmitter5->setZone(SPK::Sphere::create(SPK::Vector3D(-0.075f, -1.2f, -0.3f), 0.2f));
	pFireEmitter5->setFlow(10);
	pFireEmitter5->setForce(0.5f, 1.5f);

	SPK::Emitter *smokeEmitter = SPK::SphericEmitter::create(SPK::Vector3D(0.0f, 1.0f, 0.0f), 0.0f, static_cast<float>(0.5f*Math::Pi));
	smokeEmitter->setZone(SPK::Sphere::create(SPK::Vector3D(), 1.2f));
	smokeEmitter->setFlow(25);
	smokeEmitter->setForce(0.5f, 1.0f);

	// Create the SPARK particle groups
	SPK::Group *pFireGroup = SPK::Group::create(pFireModel, 135);
	pFireGroup->addEmitter(pFireEmitter1);
	pFireGroup->addEmitter(pFireEmitter2);
	pFireGroup->addEmitter(pFireEmitter3);
	pFireGroup->addEmitter(pFireEmitter4);
	pFireGroup->addEmitter(pFireEmitter5);
	pFireGroup->setRenderer(pFireRenderer);
	pFireGroup->setGravity(SPK::Vector3D(0.0f, 3.0f, 0.0f));
	pFireGroup->enableAABBComputing(true);

	SPK::Group *pSmokeGroup = SPK::Group::create(pSmokeModel, 135);
	pSmokeGroup->addEmitter(smokeEmitter);
	pSmokeGroup->setRenderer(pSmokeRenderer);
	pSmokeGroup->setGravity(SPK::Vector3D(0.0f, 0.4f, 0.0f));
	pSmokeGroup->enableAABBComputing(true);

	// Create the SPARK particle system
	m_pParticleSystem = SPK::System::create();
	m_pParticleSystem->addGroup(pSmokeGroup);
	m_pParticleSystem->addGroup(pFireGroup);
	m_pParticleSystem->enableAABBComputing(true);
}
//[-------------------------------------------------------]
//[ Private virtual PLScene::SceneNode functions          ]
//[-------------------------------------------------------]
void SNGalaxySample::InitFunction()
{
	// Call base implementation
	SNSystem::InitFunction();

	// Get the instance of the used renderer
	Renderer &cRenderer = GetSceneContext()->GetRendererContext().GetRenderer();

	// Renderers
	SPARK_PL::SPK_PLQuadRenderer *pParticleRenderer = CreateSPK_PLQuadRenderer(cRenderer);
	pParticleRenderer->setTexturingMode(SPK::TEXTURE_2D);
	pParticleRenderer->SetTexture(GetSceneContext()->GetRendererContext().GetTextureManager().LoadResource("Data/Textures/SPARK/Flare.dds"));
	pParticleRenderer->setScale(0.05f, 0.05f);
	pParticleRenderer->setBlending(SPK::BLENDING_ADD);
	pParticleRenderer->enableRenderingHint(SPK::DEPTH_WRITE, false);

	// Create the SPARK particle model
	SPK::Model *pGalaxyModel = SPK::Model::create(SPK::FLAG_RED | SPK::FLAG_GREEN | SPK::FLAG_BLUE | SPK::FLAG_ALPHA | SPK::FLAG_SIZE,	// Enable
		SPK::FLAG_RED | SPK::FLAG_GREEN | SPK::FLAG_BLUE,	// Mutable
		SPK::FLAG_RED | SPK::FLAG_GREEN | SPK::FLAG_SIZE,	// Random
		SPK::FLAG_ALPHA);	// Interpolated
	pGalaxyModel->setParam(SPK::PARAM_RED,0.0f, 0.3f, 0.5f, 0.5f);
	pGalaxyModel->setParam(SPK::PARAM_GREEN, 0.0f, 0.3f, 0.5f, 0.5f);
	pGalaxyModel->setParam(SPK::PARAM_BLUE, 1.0f, 0.1f);
	pGalaxyModel->setParam(SPK::PARAM_SIZE, 0.1f, 5.0f);
	pGalaxyModel->setLifeTime(35.0f, 40.0f);

	SPK::Interpolator *pAlphaInterpolator = pGalaxyModel->getInterpolator(SPK::PARAM_ALPHA);
	pAlphaInterpolator->addEntry(0.0f, 0.0f);			// First the alpha is at 0
	pAlphaInterpolator->addEntry(0.95f, 0.6f, 1.0f);	// Then ot reaches its values between 0.6 and 1 (slow fade in)
	pAlphaInterpolator->addEntry(1.0f, 0.0f);			// At the end of the particle life, it quickly fades out

	// Create the SPARK particle emitter
	SPK::RandomEmitter *pLineEmitter1 = SPK::RandomEmitter::create();
	pLineEmitter1->setZone(SPK::Line::create(SPK::Vector3D(-2.5f, 0.0f, -2.5f), SPK::Vector3D(2.5f, 0.0f, 2.5f)));
	pLineEmitter1->setFlow(100);
	pLineEmitter1->setForce(0.0f, 0.01f);

	SPK::RandomEmitter *pLineEmitter2 = SPK::RandomEmitter::create();
	pLineEmitter2->setZone(SPK::Line::create(SPK::Vector3D(-2.5f, 0.0f, 2.5f), SPK::Vector3D(2.5f, 0.0f, -2.5f)));
	pLineEmitter2->setFlow(100);
	pLineEmitter2->setForce(0.0f, 0.01f);

	SPK::Vortex *pVortex = SPK::Vortex::create();
	pVortex->setRotationSpeed(0.4f, false);
	pVortex->setAttractionSpeed(0.04f, true);
	pVortex->setEyeRadius(0.05f);
	pVortex->enableParticleKilling(true);

	// Create the SPARK particle groups
	SPK::Group *pGalaxyGroup = SPK::Group::create(pGalaxyModel, 8000);
	pGalaxyGroup->addEmitter(pLineEmitter1);
	pGalaxyGroup->addEmitter(pLineEmitter2);
	pGalaxyGroup->setRenderer(pParticleRenderer);
	pGalaxyGroup->addModifier(pVortex);
	pGalaxyGroup->enableAABBComputing(true);

	// Create the SPARK particle system
	m_pParticleSystem = SPK::System::create();
	m_pParticleSystem->addGroup(pGalaxyGroup);
	m_pParticleSystem->enableAABBComputing(true);
}