HomeHome  CalendarCalendar  FAQFAQ  SearchSearch  MemberlistMemberlist  UsergroupsUsergroups  RegisterRegister  Log inLog in  

Share | 
 

 SPARK and C++

View previous topic View next topic Go down 
AuthorMessage
hbraun



Messages : 3
Date d'inscription : 2009-11-24

PostSubject: SPARK and C++   Tue Nov 24, 2009 4:52 pm

First of all I want to thank SPARK for being a shared engine. I´ve successfully compiled SPARK and its demos and manage to make the "RainDemo" to work inside the Irrlicht engine, but when I moved to my big project it stopped working, and the FPS went down.
Things that I´ve changed: I cant use global functions, for example in the RainDemo we have a callback function called "killRain", to use that in a O.O project I had to create a instance of my "ParticleManager" class and call the class method inside a function, like a bridge, anyway I believe that is not the problem. Another thing that I´ve noticed is that the SPK::Particle passed in this customUpdate function is always with error (-1.#IND00 value).
Facts:
- I use a lot of shaders so I change the render target sometimes.
- I am using IRR renderer and OpenGL.
- I´ve been using SPARK only for 3 days... sorry for the noobness Razz

Maybe I forgot something in the initialization process, can anyone give me some help? What does the wrong particle value thing means?

Thanks,

Braun
confused
Back to top Go down
View user profile
Juff
Developer


Messages : 539
Date d'inscription : 2009-07-14
Age : 34

PostSubject: Re: SPARK and C++   Tue Nov 24, 2009 5:07 pm

Hi,

can you show some code ? Specifically how you create your system and how you link the pointer on function to the group fro the callback.
Note that the callback will disappear quite soon as they are not very flexible and can cause problems when copying systems.

Regarding the wrong particle reference that s very strange indeed.

BTW are you using the SVN version of SPARK ? they are some bug fixes for Irrlicht and a lot of new features compared to the version on the website.
Back to top Go down
View user profile http://spark.developpez.com
hbraun



Messages : 3
Date d'inscription : 2009-11-24

PostSubject: Re: SPARK and C++   Tue Nov 24, 2009 7:44 pm

Hi Juff,

Thanks for the quick reply. I believe I am not using the SVN version... but here is some part the code anyway.

Some definition....
Code:
class ParticleManager : public scene::ISceneNode
{
   template<class T> T param(T min,T max)
   {
      return static_cast<T>(min + 0.5f * (max - min)); //rain intensity
   }
private:
   bool isRaining;
   bool isSnowing;
   
   //----------- RAIN
   float time;
   float oldtime;
   float deltaTime;

   float PI;

   float posX;
   float posZ;

   SPK::Group* rainGroup;
   SPK::Group* dropGroup;
   SPK::Group* splashGroup;
   SPK::Emitter* dropEmitter;
   
   Vector3D gravity;
   IRRPointRenderer* dropRenderer;
   IRRLineRenderer* rainRenderer;
   IRRQuadRenderer* splashRenderer;

   Model* rainModel;
   Model* dropModel;
   Model* splashModel;
   AABox* rainZone;
   SphericEmitter* rainEmitter;
   System* particleSystem;
//----------------------

   scene::IParticleSystemSceneNode* ps;
   scene::IParticleEmitter* em;
   scene::IParticleAffector* paf;

   core::dimension2d<s32> screensize;
    core::aabbox3d<f32> box;
    video::SMaterial material;
   

public:
   static ParticleManager* instance;
   ParticleManager();

   void Initialize();
   void Rain(bool);
   void Snow(bool);
   
   //:)
   bool KillRain(Particle& particle,float deltaTime);
   
   virtual ~ParticleManager();
        virtual u32 getMaterialCount() const;
        virtual video::SMaterial& getMaterial(u32 i);
   virtual void OnRegisterSceneNode();
   virtual void render();
   virtual const core::aabbox3d<f32>& getBoundingBox() const;

   static ParticleManager* Instance();

};

bool KillRainF(Particle& particle,float deltaTime);

Okay...Cpp

Code:
bool KillRainF(Particle& particle,float deltaTime)
{
   //printf("Particle Valid - [%f]", particle.position().y);
   return ParticleManager::Instance()->KillRain(particle, deltaTime);
}

ParticleManager* ParticleManager::instance = 0;

ParticleManager* ParticleManager::Instance()
{
   return instance;
}

ParticleManager::ParticleManager() : ISceneNode(0, 0)
{
   instance = this;
}
void ParticleManager::Initialize()
{
   //Rain
   PI = 3.14159265358979323846f;

   time = (f32)DeviceManager::device->getTimer()->getTime() / 1000.0f;

   posX = 0;
   posZ = 0;

   gravity = Vector3D(0.0f,-2.0f,0.0f);

   // point renderer
   dropRenderer = IRRPointRenderer::create(DeviceManager::device);
   dropRenderer->setType(POINT_CIRCLE);
   dropRenderer->setSize(2.0f * 0.7f);
   dropRenderer->setBlending(BLENDING_ADD);
   //dropRenderer->enableRenderingHint(DEPTH_WRITE,false);

   // line renderer
   rainRenderer = IRRLineRenderer::create(DeviceManager::device);
   rainRenderer->setLength(-0.1f);
   rainRenderer->setBlending(BLENDING_ADD);
   //rainRenderer->enableRenderingHint(DEPTH_WRITE,false);

   // quad renderer
   splashRenderer = IRRQuadRenderer::create(DeviceManager::device);
   splashRenderer->setScale(0.05f,0.05f);
   splashRenderer->setTexture(DeviceManager::device->getVideoDriver()->getTexture("sky/waterdrops.bmp"));
   splashRenderer->setTexturingMode(TEXTURE_2D);
   splashRenderer->setBlending(BLENDING_ADD);

   // Models
   // rain model
   rainModel = Model::create(FLAG_GREEN | FLAG_RED | FLAG_BLUE | FLAG_ALPHA | FLAG_MASS,0,   FLAG_MASS);
   rainModel->setParam(PARAM_ALPHA,0.2f);
   rainModel->setImmortal(true);

   // drop model
   dropModel = Model::create(FLAG_GREEN | FLAG_RED | FLAG_BLUE | FLAG_ALPHA | FLAG_MASS,0,FLAG_MASS);
   dropModel->setParam(PARAM_ALPHA,0.6f);

   // splash model
   splashModel = Model::create(FLAG_GREEN | FLAG_RED | FLAG_BLUE | FLAG_ALPHA | FLAG_SIZE | FLAG_ANGLE,   FLAG_SIZE | FLAG_ALPHA,   FLAG_SIZE | FLAG_ANGLE);
   splashModel->setParam(PARAM_ANGLE,0.0f,2.0f * PI);
   splashModel->setParam(PARAM_ALPHA,1.0f,0.0f);

   // rain emitter
   rainZone = AABox::create(Vector3D(0.0f,5.0f,0.0f));
   rainEmitter = SphericEmitter::create(Vector3D(0.0f,-1.0f,0.0f),0.0f,0.03f * PI);
   rainEmitter->setZone(rainZone);

   // drop emitter
   dropEmitter = SphericEmitter::create(Vector3D(0.0f,1.0f,0.0f),0.0f,0.2f * PI);

   // Groups
   // rain group
   rainGroup = Group::create(rainModel,10000);
   rainGroup->setCustomUpdate(&KillRainF);
   rainGroup->setRenderer(rainRenderer);
   rainGroup->addEmitter(rainEmitter);
   rainGroup->setFriction(0.7f);
   rainGroup->setGravity(gravity);
   rainGroup->enableAABBComputing(true);
   
   // drop group
   dropGroup = Group::create(dropModel,22000);
   dropGroup->setRenderer(dropRenderer);
   dropGroup->setFriction(0.7f);
   dropGroup->setGravity(gravity);
   dropGroup->enableAABBComputing(true);

   // splash group
   splashGroup = Group::create(splashModel,3000);
   splashGroup->setRenderer(splashRenderer);
   splashGroup->enableAABBComputing(true);

   //// System
   particleSystem = IRRSystem::create(DeviceManager::device->getSceneManager()->getRootSceneNode(),DeviceManager::device->getSceneManager());
   particleSystem->addGroup(splashGroup);
   particleSystem->addGroup(dropGroup);
   particleSystem->addGroup(rainGroup);
   particleSystem->enableAABBComputing(true);

   SPKFactory::getInstance().traceAll();
   //printf("\nNumber of Factory objects [%d]",SPKFactory::getInstance().getNbObjects());

}
void ParticleManager::Rain(bool raining)
{
   //TODO: enable - disable rain state
   rainModel->setParam(PARAM_RED,param(1.0f,0.40f));
   rainModel->setParam(PARAM_GREEN,param(1.0f,0.40f));
   rainModel->setParam(PARAM_BLUE,param(1.0f,0.42f));
   rainModel->setParam(PARAM_MASS,param(0.4f,0.8f),param(0.8f,1.6f));

   dropModel->setParam(PARAM_RED,param(1.0f,0.40f));
   dropModel->setParam(PARAM_GREEN,param(1.0f,0.40f));
   dropModel->setParam(PARAM_BLUE,param(1.0f,0.42f));
   dropModel->setParam(PARAM_MASS,param(0.4f,0.8f),param(3.0f,4.0f));
   dropModel->setLifeTime(param(0.05f,0.3f),param(0.1f,0.5f));

   splashModel->setParam(PARAM_RED,param(1.0f,0.40f));
   splashModel->setParam(PARAM_GREEN,param(1.0f,0.40f));
   splashModel->setParam(PARAM_BLUE,param(1.0f,0.42f));
   splashModel->setParam(PARAM_SIZE,0.0f,0.0f,param(0.375f,2.25f),param(0.75f,3.78f));
   splashModel->setLifeTime(param(0.2f,0.3f),param(0.4f,0.5f));

   rainEmitter->setFlow(param(0.0f,6000.0f));   
   rainEmitter->setForce(param(3.0f,5.0f),param(6.0f,10.0f));
   rainZone->setDimension(Vector3D(param(40.0f,10.0f),0.0f,param(40.0f,10.0f)));

   dropEmitter->setForce(param(0.1f,1.0f),param(0.2f,2.0f));

   dropRenderer->setSize(param(1.0f,3.0f) * 0.7f);
   rainRenderer->setWidth(param(1.0f,4.0f) * 0.7f);

ParticleManager::~ParticleManager()
{
   SPKFactory::getInstance().traceAll();
   SPKFactory::getInstance().destroyAll();
   SPKFactory::getInstance().traceAll();
}
void ParticleManager::render()
{
   //rain updates
   oldtime = time;
   time = (f32)DeviceManager::device->getTimer()->getTime() / 1000.0f;
        deltaTime = time - oldtime;
   //printf("\nUpdate DeltaTime[%f]", deltaTime);
   particleSystem->update(deltaTime * 0.001f);
}
bool ParticleManager::KillRain(Particle& particle,float deltaTime)
{
   printf("Y Value[%f]", particle.position().y);
   if (particle.position().y <= 0.0f)
   {
      printf("Entrei...\n");
      particle.position().set(particle.position().x,0.01f,particle.position().z);
      splashGroup->addParticles(1,particle.position(),Vector3D());
      dropGroup->addParticles(param(2,8),particle.position(),dropEmitter);
      return true;
   }
   return false;
}

Maybe some more code how it is used?

Code:

...
        particleMngr->Initialize();
        gameMngr->Initialize( characterMngr, terrainMngr, skyMngr, effectMngr, shaderRadialBlur, particleMngr );

   DeviceManager::device->getSceneManager()->getRootSceneNode()->addChild(characterMngr);
        DeviceManager::device->getSceneManager()->getRootSceneNode()->addChild(effectMngr);
        DeviceManager::device->getSceneManager()->getRootSceneNode()->addChild(particleMngr);
...

and the "Rain(true)" is also called...:S

Code:

bool ChapterTwo::Initialize(TerrainManager* trMngr, SkyManager* skMngr, ParticleManager* ptMngr )
{
   terrainMngr = trMngr;
   skyMngr = skMngr;
   particleMngr = ptMngr;

   //create green terrain
   terrainMngr->CreateTerrain(1);
   //create normal night sky
   skyMngr->CreateSky(1);
   //create heavy rain
   particleMngr->Rain(true);
   //camera init
   ICameraSceneNode* camera = DeviceManager::device->getSceneManager()->getActiveCamera();
   //setting radial blur
   //shaderRadialBlur->SetEnabled(false);

   //carregar passaros e o diogo falando
   //SoundManager::LoadSound( "sounds/opening.mp3" );

...

I hope I didnt miss anything, and thanks again for helping Smile

Best Regards,

Braun
Back to top Go down
View user profile
Juff
Developer


Messages : 539
Date d'inscription : 2009-07-14
Age : 34

PostSubject: Re: SPARK and C++   Tue Nov 24, 2009 8:37 pm

First of all, your particleManager is a scene node. The thing is the IRRSystem is an Irrlicht scene node as well. When creating it you re adding it to the scene with :
Code:
particleSystem = IRRSystem::create(DeviceManager::device->getSceneManager()->getRootSceneNode(),DeviceManager::device->getSceneManager());
Then you re adding the particleManager to the scene as well with :
Code:
DeviceManager::device->getSceneManager()->getRootSceneNode()->addChild(particleMngr);
The thing is, by default, the update and rendering of IRRSystems in the scene are performed automatically by the scene manager but your calling it in the render() method of particleManager, therefore the update is called twice per frame. So the system is running twice as fast and is using twice as much processing times.
So either dont call the update of the rain system in the particle manager (the render function is not really the right place to update the systems anyway), or you call the method setAutoUpdateEnabled with false when initializing the rain system (so that the update is not performed automatically by the scene manager anymore).

Regarding your callback, you can use a static function inside the particle manager inside of a global one. The static functions can be used as callbacks. Once again the callback system is gonna change soon.

Moreover i ve noticed you did not set the random seed of SPARK. you ve got to set the random seed once prior to any use of SPARK so that the randomizer can of spark can work. Something like that with Irrlicht :
Code:
SPK::randomSeed = device->getTimer()->getRealTime();

I really suggest you to get the svn version as there are some bug fixes for the Irrlicht module. Those bugs may annoy you later on. You can get it here.

When you say it is not working at all, what result do you have exactly ? Can you trace the number of particles in the system at each frame to see if it is correct ?
Back to top Go down
View user profile http://spark.developpez.com
hbraun



Messages : 3
Date d'inscription : 2009-11-24

PostSubject: Re: SPARK and C++   Wed Nov 25, 2009 11:05 am

It's working now! With a much better performance! I intend to put some videos online about my projects. If you wish I can write down about SPARK in the description.

Thanks,

Braun
Back to top Go down
View user profile
Juff
Developer


Messages : 539
Date d'inscription : 2009-07-14
Age : 34

PostSubject: Re: SPARK and C++   Wed Nov 25, 2009 12:21 pm

That s good to hear.

Concerning credits, the license does not state you must give credit to SPARK but if you do, it will be appreciated Wink
You can also post in the showcase section to show us your project using SPARK.
Back to top Go down
View user profile http://spark.developpez.com
Ulf



Messages : 1
Date d'inscription : 2010-04-26

PostSubject: Re: SPARK and C++   Mon Apr 26, 2010 12:36 pm

Juff wrote:
I really suggest you to get the svn version as there are some bug fixes for the Irrlicht module. Those bugs may annoy you later on. You can get it here.
Is that statement still valid? Or is the main site now updated with the latest SVN version?
I am using version 1.5.1.
If I must use the SVN version, should I use the trunk version? Or the version 2?
Back to top Go down
View user profile
Juff
Developer


Messages : 539
Date d'inscription : 2009-07-14
Age : 34

PostSubject: Re: SPARK and C++   Mon Apr 26, 2010 6:50 pm

The bugs are fixed in the 1.05.01
There have been a few minor bug fixes since then but nothing important.

In the case youd want to use the svn version, you should use the trunk version. The spark 2 part is still being developped and the irrlicht renderers are not implemented yet.
Back to top Go down
View user profile http://spark.developpez.com
Sponsored content




PostSubject: Re: SPARK and C++   Today at 10:13 am

Back to top Go down
 
SPARK and C++
View previous topic View next topic Back to top 
Page 1 of 1

Permissions in this forum:You cannot reply to topics in this forum
 :: English Forum :: Questions (en)-
Jump to: