Would you like to react to this message? Create an account in a few clicks or log in to continue.



 
HomeHome  Latest imagesLatest images  SearchSearch  RegisterRegister  Log inLog in  

 

 Tutorial/Example for Irrlicht, with SPK_Copy(...)

Go down 
3 posters
AuthorMessage
chris
Guest




Tutorial/Example for Irrlicht, with SPK_Copy(...) Empty
PostSubject: Tutorial/Example for Irrlicht, with SPK_Copy(...)   Tutorial/Example for Irrlicht, with SPK_Copy(...) Icon_minitimeMon Feb 22, 2010 2:10 pm

hello!

Do you can write a little example for irrlicht which use a SPK_Copy(...) ???
Because i got problems with duplicate particles in irrlicht.

Duplicated IRRSystem* pointer (by SPK_Copy) shows always nothing! no particles, no anything.
Whats wrong??
Back to top Go down
chris
Guest




Tutorial/Example for Irrlicht, with SPK_Copy(...) Empty
PostSubject: Re: Tutorial/Example for Irrlicht, with SPK_Copy(...)   Tutorial/Example for Irrlicht, with SPK_Copy(...) Icon_minitimeMon Feb 22, 2010 3:19 pm

ok! I fixed it! But still problem...

i got two particles, both are duplicate from baseparticle.
and i got problem with different positions.

both are in one position.

particle1->setTransformPosition(vector3d(5,5,5))
particle2->setTransformPosition(vector3d(1,1,1))

i use getTransformPosition(...) and positions there is ok.

but its render all in position vector3d(1,1,1);
Back to top Go down
Darktib
Committer
Darktib


Messages : 389
Date d'inscription : 2009-07-20
Localisation : A coté de Paris

Tutorial/Example for Irrlicht, with SPK_Copy(...) Empty
PostSubject: Re: Tutorial/Example for Irrlicht, with SPK_Copy(...)   Tutorial/Example for Irrlicht, with SPK_Copy(...) Icon_minitimeMon Feb 22, 2010 3:56 pm

Hello,

Thank you for using the Irrlicht renderer.

For your problem:
Usually, you don't have to manipulate particles directly, the engine does all for you.

Furthermore, I don't understand your problem : you wants to render twice a system by copying a pointer ?
Please post the code.

~Darktib
Back to top Go down
Juff
Developer



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

Tutorial/Example for Irrlicht, with SPK_Copy(...) Empty
PostSubject: Re: Tutorial/Example for Irrlicht, with SPK_Copy(...)   Tutorial/Example for Irrlicht, with SPK_Copy(...) Icon_minitimeMon Feb 22, 2010 4:28 pm

Hi,

I supposed when you speak of particles you are refering to particle systems ?

SPK_Copy will duplicate your system but their might be some problems with irrlicht systems as I didnt test is a lot. I will investigate.

Considering the transformations, you need to call an updateTransform() on the systems for it to be taken into account. But I suggest you use directly Irrlicht transformation system with a setPosition (as IRRSystem is derived from ISceneNode) and every thing will be made automatically.
Back to top Go down
http://spark.developpez.com
chris




Messages : 2
Date d'inscription : 2010-02-22

Tutorial/Example for Irrlicht, with SPK_Copy(...) Empty
PostSubject: Re: Tutorial/Example for Irrlicht, with SPK_Copy(...)   Tutorial/Example for Irrlicht, with SPK_Copy(...) Icon_minitimeMon Feb 22, 2010 5:01 pm

Ok! I quick rewrite a IRRFireDemo.cpp to shows my problem.

I use both methods in procedure CloneParticleSystem(...) are just: SPK_Copy
and BuildParticleSystem(...) with full-code.

//! >>> Always only one Fire.
//! wanted to make 4 fires, around.
//! But still doesnt work? its possible make this in different method?
BuildParticleSystem(&particleSystem1);
particleSystem1->setTransformPosition(Vector3D(-1,0,-1)); particleSystem1->updateTransform();
BuildParticleSystem(&particleSystem2);
particleSystem2->setTransformPosition(Vector3D(+1,0,-1)); particleSystem2->updateTransform();

//! CloneParticleSystem(...) and BuildParticleSystem(...) without effect.
CloneParticleSystem(particleSystem1,&particleSystem3);
particleSystem3->setTransformPosition(Vector3D(-1,0,+1)); particleSystem3->updateTransform();
CloneParticleSystem(particleSystem2,&particleSystem4);
particleSystem4->setTransformPosition(Vector3D(+1,0,+1)); particleSystem4->updateTransform();
//!

... and still always render only one. Smile

Code:


// external libs
#include <irrlicht.h>

// SPARK lib
#include <SPK.h>
#include <SPK_IRR.h>

// windows only
#ifdef _WIN32
#include <windows.h>
#endif

using namespace std;
using namespace irr;
using namespace SPK;
using namespace SPK::IRR;

float angleY = 10.0f;
float angleX = -45.0f;
float camPosZ = 5.0f;

int deltaTime = 0;

const float PI = 3.14159265358979323846f;

const string STR_NB_PARTICLES = "NB PARTICLES : ";
const string STR_FPS = "FPS : ";

video::IVideoDriver* driver;
scene::ISceneManager* smgr;

string strNbParticles = STR_NB_PARTICLES;
string strFps = STR_FPS;

Group* fireGroup = NULL;
Group* smokeGroup = NULL;
Emitter* smokeEmitter = NULL;

System* particleSystem1 = NULL;
System* particleSystem2 = NULL;
System* particleSystem3 = NULL;
System* particleSystem4 = NULL;

IrrlichtDevice* device = NULL;
scene::ICameraSceneNode* cam = NULL;

bool smokeEnabled = true;

// Input Receiver
class MyEventReceiver : public IEventReceiver
{
    public:
      MyEventReceiver() :
        IEventReceiver(),
        init(false)
        {}

        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();
            }
                if(event.KeyInput.Key == KEY_SPACE && event.KeyInput.PressedDown==false)
                {
                    smokeEnabled=!smokeEnabled;
                    smokeGroup->getEmitter(0)->setActive(smokeEnabled);
                    return true;
                }
                if(event.KeyInput.Key == KEY_DELETE && event.KeyInput.PressedDown==false)
                {
                    particleSystem1->empty();
                    return true;
                }
            }
            else if(event.EventType == EET_MOUSE_INPUT_EVENT)
            {
            if (init)
            {
               angleX += (oldMouseX - event.MouseInput.X)*0.1f;
               angleY += (oldMouseY - event.MouseInput.Y)*0.1f;
                   
               if(angleY < 1.0f) angleY=1.0f;
               if(angleY > 70.0f) angleY=70.0f;
               camPosZ -= event.MouseInput.Wheel;
               if(camPosZ < 3.0f) camPosZ=3.0f;
               if(camPosZ > 18.0f) camPosZ=18.0f;

               cam->setPosition(core::vector3df(camPosZ*sinf(angleX*core::DEGTORAD)*sinf((90.0f-angleY)*core::DEGTORAD),
                  camPosZ*cosf((90.0f-angleY)*core::DEGTORAD),camPosZ*cosf(angleX*core::DEGTORAD)*sinf((90.0f-angleY)*core::DEGTORAD)));
               cam->setTarget(core::vector3df());
            }

            init = true;
            oldMouseX=event.MouseInput.X;
            oldMouseY=event.MouseInput.Y;

                return true;
            }
            return false;
        }

        int oldMouseX,oldMouseY;

   private :
   
      bool init;
};

//
void         CloneParticleSystem(System *from, System **output) {
   (*output) = SPK_Copy(System, from->getID());
};

//
void         BuildParticleSystem(System **output) {
   // Inits Particle Engine

   // Renderers
   IRRQuadRenderer* fireRenderer = IRRQuadRenderer::create(device);
   fireRenderer->setScale(0.3f,0.3f);
   fireRenderer->setTexture(driver->getTexture("res\\fire2.bmp"));
   fireRenderer->setTexturingMode(TEXTURE_2D);
   fireRenderer->setBlending(BLENDING_ADD);
   fireRenderer->enableRenderingHint(DEPTH_WRITE,false);
   fireRenderer->setAtlasDimensions(2,2);
   fireRenderer->setShared(true);

   IRRQuadRenderer* smokeRenderer = IRRQuadRenderer::create(device);
   smokeRenderer->setScale(0.3f,0.3f);
   smokeRenderer->setTexture(driver->getTexture("res\\explosion.png"));
   smokeRenderer->setTexturingMode(TEXTURE_2D);
   smokeRenderer->setBlending(BLENDING_ALPHA);
   smokeRenderer->enableRenderingHint(DEPTH_WRITE,false);
   smokeRenderer->setAtlasDimensions(2,2);
   smokeRenderer->setShared(true);

   // Models
   Model* fireModel = Model::create(FLAG_RED | FLAG_GREEN | FLAG_BLUE | FLAG_ALPHA | FLAG_SIZE | FLAG_ANGLE | FLAG_TEXTURE_INDEX,
      FLAG_RED | FLAG_GREEN | FLAG_ALPHA | FLAG_ANGLE,
      FLAG_RED | FLAG_GREEN | FLAG_TEXTURE_INDEX | FLAG_ANGLE,
      FLAG_SIZE);
   fireModel->setParam(PARAM_RED,0.8f,0.9f,0.8f,0.9f);
   fireModel->setParam(PARAM_GREEN,0.5f,0.6f,0.5f,0.6f);
   fireModel->setParam(PARAM_BLUE,0.3f);
   fireModel->setParam(PARAM_ALPHA,0.4f,0.0f);
   fireModel->setParam(PARAM_ANGLE,0.0f,2.0f * PI,0.0f,2.0f * PI);
   fireModel->setParam(PARAM_TEXTURE_INDEX,0.0f,4.0f);
   fireModel->setLifeTime(1.0f,1.5f);
   fireModel->setShared(true);

   Interpolator* interpolator = fireModel->getInterpolator(PARAM_SIZE);
   interpolator->addEntry(0.5f,2.0f,5.0f);
   interpolator->addEntry(1.0f,0.0f);

   Model* smokeModel = Model::create(FLAG_RED | FLAG_GREEN | FLAG_BLUE | FLAG_ALPHA | FLAG_SIZE | FLAG_ANGLE | FLAG_TEXTURE_INDEX,
      FLAG_RED | FLAG_GREEN | FLAG_SIZE | FLAG_ANGLE,
      FLAG_TEXTURE_INDEX | FLAG_ANGLE,
      FLAG_ALPHA);
   smokeModel->setParam(PARAM_RED,0.3f,0.2f);
   smokeModel->setParam(PARAM_GREEN,0.25f,0.2f);
   smokeModel->setParam(PARAM_BLUE,0.2f);
   smokeModel->setParam(PARAM_ALPHA,0.2f,0.0f);
   smokeModel->setParam(PARAM_SIZE,5.0,10.0f);
   smokeModel->setParam(PARAM_TEXTURE_INDEX,0.0f,4.0f);
   smokeModel->setParam(PARAM_ANGLE,0.0f,2.0f * PI,0.0f,2.0f * PI);
   smokeModel->setLifeTime(5.0f,5.0f);
   smokeModel->setShared(true);

   interpolator = smokeModel->getInterpolator(PARAM_ALPHA);
   interpolator->addEntry(0.0f,0.0f);
   interpolator->addEntry(0.2f,0.2f);
   interpolator->addEntry(1.0f,0.0f);

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

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

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

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

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

   smokeEmitter = SphericEmitter::create(Vector3D(0.0f,1.0f,0.0f),0.0f,0.5f * PI);
   smokeEmitter->setZone(Sphere::create(Vector3D(),1.2f));
   smokeEmitter->setFlow(25);
   smokeEmitter->setForce(0.5f,1.0f);

   // Groups
   fireGroup = Group::create(fireModel,135);
   fireGroup->addEmitter(fireEmitter1);
   fireGroup->addEmitter(fireEmitter2);
   fireGroup->addEmitter(fireEmitter3);
   fireGroup->addEmitter(fireEmitter4);
   fireGroup->addEmitter(fireEmitter5);
   fireGroup->setRenderer(fireRenderer);
   fireGroup->setGravity(Vector3D(0.0f,3.0f,0.0f));
   fireGroup->enableAABBComputing(true);

   smokeGroup = Group::create(smokeModel,135);
   smokeGroup->addEmitter(smokeEmitter);
   smokeGroup->setRenderer(smokeRenderer);
   smokeGroup->setGravity(Vector3D(0.0f,0.4f,0.0f));
   smokeGroup->enableAABBComputing(true);
   
   // System
   (*output) = IRRSystem::create(smgr->getRootSceneNode(),smgr);
   (*output)->addGroup(smokeGroup);
   (*output)->addGroup(fireGroup);
   (*output)->enableAABBComputing(true);
};

// Main function
int main(int argc, char *argv[])
{
   //!IRRLICHT
    video::E_DRIVER_TYPE chosenDriver = video::EDT_OPENGL;

    //!IRRLICHT
   MyEventReceiver* evtrcv = new MyEventReceiver;
   device = createDevice(chosenDriver,
      core::dimension2d<u32>(640,480),
      32,
      false,false,false,
      evtrcv);

    driver = device->getVideoDriver();
    smgr = device->getSceneManager();
    gui::IGUIEnvironment* guienv = device->getGUIEnvironment();

    device->setWindowCaption(L"SPARK Fire Demo using Irrlicht");
   device->getCursorControl()->setVisible(false);
    cam = smgr->addCameraSceneNode(0,core::vector3df(camPosZ*sinf(angleX*core::DEGTORAD)*sinf((90.0f-angleY)*core::DEGTORAD),
        camPosZ*cosf((90.0f-angleY)*core::DEGTORAD),camPosZ*cosf(angleX*core::DEGTORAD)*sinf((90.0f-angleY)*core::DEGTORAD)),
        core::vector3df());
    cam->setNearValue(0.05f);

   scene::IMesh* sceneryMesh = smgr->getMesh("res/SceneFireCamp.obj");
   scene::ISceneNode* sceneryNode = smgr->addMeshSceneNode(sceneryMesh);
   sceneryNode->setPosition(core::vector3df(0.0f,-1.5f,0.0f));
   sceneryNode->setScale(core::vector3df(0.01f,0.01f,0.01f));

   smgr->setAmbientLight(video::SColorf(0.15f,0.15f,0.25f));

   scene::ILightSceneNode* lightNode = smgr->addLightSceneNode();
   lightNode->setLightType(video::ELT_SPOT);
   video::SLight& lightData = lightNode->getLightData();
   lightData.AmbientColor = video::SColorf(0.0f,0.0f,0.0f);
   lightData.DiffuseColor = video::SColorf(1.0f,0.75f,0.25f);
   lightData.InnerCone = 180.0f;
   lightData.OuterCone = 180.0f;
   lightData.Attenuation.X = 0.0f;
   lightData.Attenuation.Y = 0.0f;

   // random seed
   randomSeed = device->getTimer()->getRealTime();
   // Sets the update step
   System::setClampStep(true,0.1f);         // clamp the step to 100 ms
   System::useAdaptiveStep(0.001f,0.01f);      // use an adaptive step from 1ms to 10ms (1000fps to 100fps)

   //! >>> Always only one Fire.
   //! wanted to make 4 fires, around.
   //! But still doesnt work? its possible make this in different method?
   BuildParticleSystem(&particleSystem1);
   particleSystem1->setTransformPosition(Vector3D(-1,0,-1));   particleSystem1->updateTransform();
   BuildParticleSystem(&particleSystem2);
   particleSystem2->setTransformPosition(Vector3D(+1,0,-1));   particleSystem2->updateTransform();

   //! CloneParticleSystem(...) and BuildParticleSystem(...) without effect.
   CloneParticleSystem(particleSystem1,&particleSystem3);
   particleSystem3->setTransformPosition(Vector3D(-1,0,+1));   particleSystem3->updateTransform();
   CloneParticleSystem(particleSystem2,&particleSystem4);
   particleSystem4->setTransformPosition(Vector3D(+1,0,+1));   particleSystem4->updateTransform();
   //!

   // setup some useful variables
   float time=(f32)device->getTimer()->getTime() / 1000.0f,oldtime,deltaTime;
   float step = 0.0f;

   cout << "\nSPARK FACTORY AFTER INIT :" << endl;
   SPKFactory::getInstance().traceAll();

   float lightTime = 0.05f;

   while(device->run())
   {
      oldtime = time;
        time = (f32)device->getTimer()->getTime() / 1000.0f;
        deltaTime = time - oldtime;

      lightTime += deltaTime;
      if (lightTime >= 0.05f)
      {
         float lightIntensity = 1.0f - (random(0.0f,0.05f) * 5.0f);
         lightTime -= lightTime;
         lightNode->setPosition(core::vector3df(random(-0.5f,0.5f),0.5f + random(-0.5f,0.5f),random(-0.5f,0.5f)));
         lightNode->getLightData().Attenuation.Z = 15.0f / lightIntensity;
      }

      driver->beginScene(true, true, video::SColor(0,0,0,0));

      // Renders scene
      smgr->drawAll();

      core::stringw infos; infos+="FPS: "; infos+=driver->getFPS(); infos+=" - Nb Particles (1): "; infos+=particleSystem1->getNbParticles();
      infos+=" - Nb Particles (2): "; infos+=particleSystem2->getNbParticles();
      infos+=" - Nb Particles (3): "; infos+=particleSystem3->getNbParticles();
      infos+=" - Nb Particles (4): "; infos+=particleSystem4->getNbParticles();
        guienv->getBuiltInFont()->draw(infos.c_str(),core::rect<s32>(0,0,170,20),video::SColor(255,255,255,255));

      driver->endScene();

      // clip mouse
        if(device->getCursorControl()->getPosition().X < 20)
        {
            device->getCursorControl()->setPosition(620,device->getCursorControl()->getPosition().Y);
            evtrcv->oldMouseX = 620;
        }
        if(device->getCursorControl()->getPosition().X > 620)
        {
            device->getCursorControl()->setPosition(20,device->getCursorControl()->getPosition().Y);
            evtrcv->oldMouseX = 20;
        }
        if(device->getCursorControl()->getPosition().Y < 20)
        {
            device->getCursorControl()->setPosition(device->getCursorControl()->getPosition().X,460);
            evtrcv->oldMouseY = 460;
        }
        if(device->getCursorControl()->getPosition().Y > 460)
        {
            device->getCursorControl()->setPosition(device->getCursorControl()->getPosition().X,20);
            evtrcv->oldMouseY = 20;
        }
   }

   cout << "\nSPARK FACTORY BEFORE DESTRUCTION :" << endl;
   SPKFactory::getInstance().traceAll();
   SPKFactory::getInstance().destroyAll();
   cout << "\nSPARK FACTORY AFTER DESTRUCTION :" << endl;
   SPKFactory::getInstance().traceAll();
   device->drop();

   cout << endl;
   system("pause"); // Waits for the user to close the console

   return 0;
}
Back to top Go down
Juff
Developer



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

Tutorial/Example for Irrlicht, with SPK_Copy(...) Empty
PostSubject: Re: Tutorial/Example for Irrlicht, with SPK_Copy(...)   Tutorial/Example for Irrlicht, with SPK_Copy(...) Icon_minitimeMon Feb 22, 2010 6:11 pm

ok, I have made some tests and there is a problem with the Irrlicht module when copying systems. I m on it. I let you know later on
Back to top Go down
http://spark.developpez.com
Juff
Developer



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

Tutorial/Example for Irrlicht, with SPK_Copy(...) Empty
PostSubject: Re: Tutorial/Example for Irrlicht, with SPK_Copy(...)   Tutorial/Example for Irrlicht, with SPK_Copy(...) Icon_minitimeMon Feb 22, 2010 8:12 pm

I have corrected and uploaded on the svn some fix for the Irrlicht module. Now it works fine. I am gonna release a new version of the lib as there were some big bug fixed. Sorry about the trouble.
Back to top Go down
http://spark.developpez.com
Sponsored content





Tutorial/Example for Irrlicht, with SPK_Copy(...) Empty
PostSubject: Re: Tutorial/Example for Irrlicht, with SPK_Copy(...)   Tutorial/Example for Irrlicht, with SPK_Copy(...) Icon_minitime

Back to top Go down
 
Tutorial/Example for Irrlicht, with SPK_Copy(...)
Back to top 
Page 1 of 1
 Similar topics
-
» 2D in irrlicht
» irrlicht and rain
» irrlicht and iPhone
» Module Irrlicht en développement
» Implementing rain example with irrlicht

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