//////////////////////////////////////////////////////////////////////////////////
// SPARK Irrlicht Rendering library //
// Copyright (C) 2008-2013 //
// Julien Fryer -
julienfryer@gmail.com //
// Thibault Lescoat - info-tibo <at> orange <dot> fr //
// //
// //
// This software is provided 'as-is', without any express or implied //
// warranty. In no event will the authors be held liable for any damages //
// arising from the use of this software. //
// //
// Permission is granted to anyone to use this software for any purpose, //
// including commercial applications, and to alter it and redistribute it //
// freely, subject to the following restrictions: //
// //
// 1. The origin of this software must not be misrepresented; you must not //
// claim that you wrote the original software. If you use this software //
// in a product, an acknowledgment in the product documentation would be //
// appreciated but is not required. //
// 2. Altered source versions must be plainly marked as such, and must not be //
// misrepresented as being the original software. //
// 3. This notice may not be removed or altered from any source distribution. //
//////////////////////////////////////////////////////////////////////////////////
// external libs
#include <irrlicht.h>
// SPARK lib
#include <SPARK.h>
#include <SPARK_IRR.h>
using namespace irr;
using namespace std;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
IrrlichtDevice* device = NULL;
// Input Receiver
class MyEventReceiver : public IEventReceiver
{
public:
virtual bool OnEvent(const SEvent& event)
{
if(event.EventType==EET_KEY_INPUT_EVENT)
{
if(event.KeyInput.Key == KEY_ESCAPE && event.KeyInput.PressedDown==false)
{
device->closeDevice();
}
}
return false;
}
int oldMouseX,oldMouseY;
};
SPK::Ref<SPK::System> createMagicSystem(irr::IrrlichtDevice* device, bool reverse)
{
const float scale = 40.0f;
SPK::Ref<SPK::System> system = SPK::System::create();
SPK::Ref<SPK::IRR::IRRQuadRenderer> quadRenderer = SPK::IRR::IRRQuadRenderer::create(device);
quadRenderer->setBlendMode(SPK::BLEND_MODE_ADD);
quadRenderer->enableRenderingOption(SPK::RENDERING_OPTION_DEPTH_WRITE, false);
quadRenderer->setTexture(device->getVideoDriver()->getTexture("res\\flare.bmp"));
quadRenderer->setTexturingMode(SPK::TEXTURE_MODE_2D);
SPK::Ref<SPK::RandomEmitter> emitter = SPK::RandomEmitter::create(SPK::Point::create());
emitter->setForce(0.4f * scale, 0.6f * scale);
emitter->setFlow(200);
SPK::Ref<SPK::ColorGraphInterpolator> graphInterpolator = SPK::ColorGraphInterpolator::create();
graphInterpolator->addEntry(reverse ? 1.0f : 0.0f, 0xFF000088);
graphInterpolator->addEntry(0.5f, 0x00FF0088);
graphInterpolator->addEntry(reverse ? 0.0f : 1.0f, 0x0000FF88);
SPK::Ref<SPK::Group> group = system->createGroup(400);
group->setRadius(0.15f);
group->setLifeTime(1.0f, 2.0f);
group->setColorInterpolator(graphInterpolator);
group->setParamInterpolator(SPK::PARAM_SCALE, SPK::FloatRandomInterpolator::create(0.8f * scale, 1.2f * scale, 0.0f, 0.0f));
group->setParamInterpolator(SPK::PARAM_ANGLE, SPK::FloatRandomInitializer::create(0.0f, 2 * 3.14159f));
group->addEmitter(emitter);
group->addModifier(SPK::Gravity::create(SPK::Vector3D(0.0f, -0.5f, 0.0f)));
group->addModifier(SPK::Friction::create(0.2f));
group->setRenderer(quadRenderer);
return system;
}
// Main function
int main(int argc, char *argv[])
{
//!IRRLICHT
video::E_DRIVER_TYPE chosenDriver = video::EDT_OPENGL;
//!IRRLICHT
device = createDevice(chosenDriver,
core::dimension2d<u32>(1600, 900),
32,
false,
false,
false,
new MyEventReceiver);
video::IVideoDriver* driver = device->getVideoDriver();
scene::ISceneManager* smgr = device->getSceneManager();
gui::IGUIEnvironment* guienv = device->getGUIEnvironment();
device->setWindowCaption(L"SPARK Irrlicht test - Attaching to joint");
device->getCursorControl()->setVisible(false);
// add camera
scene::ICameraSceneNode* camera = smgr->addCameraSceneNodeFPS();
device->getCursorControl()->setVisible(false);
camera->setNearValue(0.1f);
camera->setFarValue(999999.0f);
camera->setFOV(70);
scene::IAnimatedMesh* mesh = smgr->getMesh("media//dwarf.x");
scene::ISkinnedMesh* skinMesh = (scene::ISkinnedMesh*)mesh;
scene::IAnimatedMeshSceneNode* node = 0;
node = smgr->addAnimatedMeshSceneNode(skinMesh);
node->setMaterialFlag(EMF_LIGHTING, false);
irr::scene::ISceneNode* rightJointNode = node->getJointNode("rwrist");
irr::scene::ISceneNode* leftJointNode = node->getJointNode("lwrist");
// Inits Particle Engine
// Sets the update step
SPK::System::setClampStep(true, 1.0f); // clamp the step to 100 ms
SPK::System::useAdaptiveStep(0.001f, 0.01f); // use an adaptive step from 1ms to 10ms (1000fps to 100fps)
scene::CSPKParticleSystemNode* rsystem = new scene::CSPKParticleSystemNode(createMagicSystem(device, false), rightJointNode, smgr);
scene::CSPKParticleSystemNode* lsystem = new scene::CSPKParticleSystemNode(createMagicSystem(device, true), leftJointNode, smgr);
rsystem->drop(); // We let the scene manager take care of the system life time
lsystem->drop();
{
irr::ITimer* timer = device->getTimer();
float oldTime=0.0f, deltaTime=0.0f, time = timer->getTime() / 1000.0f;
while(device->run())
{
// Update time
oldTime = time;
time = timer->getTime() / 1000.0f;
deltaTime = time - oldTime;
driver->beginScene(true, true, irr::video::SColor(0,0,0,0));
// Renders scene
smgr->drawAll();
irr::core::stringw infos; infos+="FPS: "; infos+=driver->getFPS();
infos += " - Nb Particles: "; infos += rsystem->getNbParticles() + lsystem->getNbParticles();
guienv->getBuiltInFont()->draw(infos.c_str(),irr::core::rect<irr::s32>(0,0,170,20),irr::video::SColor(255,255,255,255));
driver->endScene();
}
SPK_DUMP_MEMORY
}
device->drop();
SPK_DUMP_MEMORY
return 0;
}