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  

 

 One issue on explosion demo of SPARK using Irrlicht as a renderer?

Go down 
3 posters
AuthorMessage
qidaozhilong2




Messages : 11
Date d'inscription : 2012-03-31

One issue on explosion demo of SPARK using Irrlicht as a renderer? Empty
PostSubject: One issue on explosion demo of SPARK using Irrlicht as a renderer?   One issue on explosion demo of SPARK using Irrlicht as a renderer? Icon_minitimeMon Apr 09, 2012 5:47 am

Hi SPARK team,

confused
When i ported the ExplosionDemo to Irrlicht, the function "setTextureBlending()" missed, so i canceled this sentence.
"
//xxx->setTextureBlending(GL_MODULATE);
xxx->setBlending(BLENDING_ALPHA);
"

one issue occured:
I found the multi-Layers' alpha effect is wrong.

I know i should use ANOTHER setBlending() as follow:
"void IRRRenderer::setBlending(irr::video::E_BLEND_FACTOR srcFunc,irr::video::E_BLEND_FACTOR destFunc,unsigned int alphaSrc)"

not
"void IRRRenderer::setBlending(BlendingMode blendMode)"

BUT, so many enum chooses
"
enum E_BLEND_FACTOR
{
EBF_ZERO = 0, //!< src & dest (0, 0, 0, 0)
EBF_ONE, //!< src & dest (1, 1, 1, 1)
EBF_DST_COLOR, //!< src (destR, destG, destB, destA)
EBF_ONE_MINUS_DST_COLOR, //!< src (1-destR, 1-destG, 1-destB, 1-destA)
EBF_SRC_COLOR, //!< dest (srcR, srcG, srcB, srcA)
EBF_ONE_MINUS_SRC_COLOR, //!< dest (1-srcR, 1-srcG, 1-srcB, 1-srcA)
EBF_SRC_ALPHA, //!< src & dest (srcA, srcA, srcA, srcA)
EBF_ONE_MINUS_SRC_ALPHA, //!< src & dest (1-srcA, 1-srcA, 1-srcA, 1-srcA)
EBF_DST_ALPHA, //!< src & dest (destA, destA, destA, destA)
EBF_ONE_MINUS_DST_ALPHA, //!< src & dest (1-destA, 1-destA, 1-destA, 1-destA)
EBF_SRC_ALPHA_SATURATE //!< src (min(srcA, 1-destA), idem, ...)
};
"
and so many Renderer
"smokeRenderer, flameRenderer, flashRenderer, spark1Renderer, spark2Renderer, waveRenderer"

How to set these Renderers' Parameters like 'srcFunc, destFunc and alphaSrc'?
Back to top Go down
qidaozhilong2




Messages : 11
Date d'inscription : 2012-03-31

One issue on explosion demo of SPARK using Irrlicht as a renderer? Empty
PostSubject: Re: One issue on explosion demo of SPARK using Irrlicht as a renderer?   One issue on explosion demo of SPARK using Irrlicht as a renderer? Icon_minitimeMon Apr 09, 2012 6:58 am

Another question?

"SPK_IRRRenderer.cpp":
namespace SPK
{
namespace IRR
{
IRRRenderer::IRRRenderer(irr::IrrlichtDevice* d) :
device(d),
currentBuffer(NULL)
{
...
material.MaterialType = irr::video::EMT_ONETEXTURE_BLEND; // To allow complex blending functions
setBlending(BLENDING_NONE); // Blending is disabled per default
...
}

the RED part, does it mean only support one texture blend? Should change its value?

One issue on explosion demo of SPARK using Irrlicht as a renderer? 00110
Back to top Go down
Darktib
Committer
Darktib


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

One issue on explosion demo of SPARK using Irrlicht as a renderer? Empty
PostSubject: Re: One issue on explosion demo of SPARK using Irrlicht as a renderer?   One issue on explosion demo of SPARK using Irrlicht as a renderer? Icon_minitimeMon Apr 09, 2012 1:01 pm

You want to port this demo to SPARK 1.5.5 or SPARK 2.0 ?
You can use function for deep control, but the most common settings are 'NONE' (no blending), 'ALPHA' (particles will have alpha), 'ADD' (particle color will be added to the scene color) (see SPK::BlendMode).
Typically, fire is on 'ADD' and smoke on 'ALPHA'.

qidaozhilong2 wrote:
the RED part, does it mean only support one texture blend? Should change its value?
It means the material is set to use one_texture_blend algorithm : one texture which is blended with the rest of the scene. You don't have to change it.
Normally the renderer system will be reworked in SPARK2 in order to be able to use shaders, for example.

Important: The DirectX driver of Irrlicht has a bug for one_texture_blend: the color won't be added if you specify 'ADD'. I don't know any work around, maybe you'll have to fix this yourself by changing Irrlicht's source code.
Back to top Go down
qidaozhilong2




Messages : 11
Date d'inscription : 2012-03-31

One issue on explosion demo of SPARK using Irrlicht as a renderer? Empty
PostSubject: Re: One issue on explosion demo of SPARK using Irrlicht as a renderer?   One issue on explosion demo of SPARK using Irrlicht as a renderer? Icon_minitimeMon Apr 09, 2012 1:27 pm

Darktib wrote:
You want to port this demo to SPARK 1.5.5 or SPARK 2.0 ?
You can use function for deep control, but the most common settings are 'NONE' (no blending), 'ALPHA' (particles will have alpha), 'ADD' (particle color will be added to the scene color) (see SPK::BlendMode).
Typically, fire is on 'ADD' and smoke on 'ALPHA'.

qidaozhilong2 wrote:
the RED part, does it mean only support one texture blend? Should change its value?
It means the material is set to use one_texture_blend algorithm : one texture which is blended with the rest of the scene. You don't have to change it.
Normally the renderer system will be reworked in SPARK2 in order to be able to use shaders, for example.

Important: The DirectX driver of Irrlicht has a bug for one_texture_blend: the color won't be added if you specify 'ADD'. I don't know any work around, maybe you'll have to fix this yourself by changing Irrlicht's source code.

Darktib, extremely thanks for your reply.

1) SPARK1.5.5
Like the picture i show, multi-texture alpha overlapped. The BLACK not transparent part occured.
The problem of multi-texture alpha error, i guess, is because of 'GL_MODULATE', but i can't find this setting on Irrlicht renderer. You know, 'GL_MODULATE' is an OpenGL parameter and Irrlicht also uses OpenGL.

2) Maybe i neglect an important information that Android Irrlicht using OpenGL1.x-2.0, not DirectX.
Back to top Go down
Darktib
Committer
Darktib


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

One issue on explosion demo of SPARK using Irrlicht as a renderer? Empty
PostSubject: Re: One issue on explosion demo of SPARK using Irrlicht as a renderer?   One issue on explosion demo of SPARK using Irrlicht as a renderer? Icon_minitimeTue Apr 10, 2012 1:12 pm

Android uses OpenGL ES, I don't know how it is supported by Irrlicht.

Have you tried
Code:
renderer->setBlending(SPK::BLENDING_ADD)
?
Back to top Go down
Juff
Developer



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

One issue on explosion demo of SPARK using Irrlicht as a renderer? Empty
PostSubject: Re: One issue on explosion demo of SPARK using Irrlicht as a renderer?   One issue on explosion demo of SPARK using Irrlicht as a renderer? Icon_minitimeTue Apr 10, 2012 2:21 pm

I ve notived problems of blending like that with OpenGL and Irrlicht (in the spark Irrlicht demo). Those problems were not there before. There must be a bug somewhere (either in Irrlicht or SPARK). I ll check that.
Back to top Go down
http://spark.developpez.com
qidaozhilong2




Messages : 11
Date d'inscription : 2012-03-31

One issue on explosion demo of SPARK using Irrlicht as a renderer? Empty
PostSubject: Re: One issue on explosion demo of SPARK using Irrlicht as a renderer?   One issue on explosion demo of SPARK using Irrlicht as a renderer? Icon_minitimeThu Apr 12, 2012 12:40 am

Code:
/***********************************************************************************
 *
 *
 * 11:30:04 AM May 10, 2011
 *
 * zhangbin
 ***********************************************************************************/

/*
 * TODO:
 *  - Load texture files from assets folder
 */

#ifdef ANDROID_NDK
#include <jni.h>
#include <android/log.h>
#endif

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

#include "irrParticle_examples.h"

using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
using namespace SPK;
using namespace SPK::IRR;

#ifdef ANDROID_NDK
int importGLInit();
void importGLDeinit();
#endif

const char * LOG_TAG = "irrParticle_examples";

#ifdef __LINUX
#else
const char * EG_ONE_POINT_TEXTURE="/sdcard/irrParticle_examples/point.bmp";

const char * EG_TWO_MODEL_FILE="/sdcard/irrParticle_examples/SceneFireCamp.obj";
const char * EG_TWO_FIRE_TEXTURE="/sdcard/irrParticle_examples/fire2.bmp";
const char * EG_TWO_EXPO_TEXTURE="/sdcard/irrParticle_examples/explosion.png";

const char * EG_THREE_EXPLO_TEXTURE="/sdcard/irrParticle_examples/explosion.bmp";
const char * EG_THREE_FLASH_TEXTURE="/sdcard/irrParticle_examples/flash.bmp";
const char * EG_THREE_SPARK1_TEXTURE="/sdcard/irrParticle_examples/spark1.bmp";
const char * EG_THREE_SPARK2_TEXTURE="/sdcard/irrParticle_examples/point.bmp";
const char * EG_THREE_WAVE_TEXTURE="/sdcard/irrParticle_examples/wave.bmp";

const char * EG_FOUR_BALL_TEXTURE="/sdcard/irrParticle_examples/ball.bmp";

#endif

// global variables
int  gWindowWidth;
int  gWindowHeight;

IrrlichtDevice *device = NULL;
IVideoDriver* driver = NULL;
ISceneManager* smgr = NULL;
ICameraSceneNode* camera=NULL;
IRRSystem* particleSystem = NULL;
Emitter* smokeEmitter = NULL;
Group* fireGroup = NULL;
Group* smokeGroup = NULL;
ILightSceneNode* lightNode=NULL;
Model* particleModel=NULL;

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

int initialized = 0;

float currenttime;
float oldtime;
float deltaTime;
float step;
float lightTime;

list<IRRSystem*> particleSystems;
SPK_ID BaseSystemID = NO_ID;
float spacePressed = -1.0f;

const size_t NB_PARTICLES = 250;

#ifdef ANDROID_NDK
#define LOG(args...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, args)
#else
#define LOG(args...) printf(args);
#endif

#ifdef ANDROID_NDK
/* For JNI: C++ compiler need this */
extern "C" {
#endif

   /** Activity onCreate */
#ifdef ANDROID_NDK
   void Java_ca_renzhi_Particle_MainActivity_nativeOnCreate( JNIEnv*  env )
#else
   void Java_ca_renzhi_Particle_MainActivity_nativeOnCreate()
#endif
   {
   }

   /** Activity onPause */
#ifdef ANDROID_NDK
   void Java_ca_renzhi_Particle_MainActivity_nativeOnPause( JNIEnv*  env )
#else
   void Java_ca_renzhi_Particle_MainActivity_nativeOnPause()
#endif
   {
   }

   /** Activity onResume */
#ifdef ANDROID_NDK
   void Java_ca_renzhi_Particle_MainActivity_nativeOnResume( JNIEnv*  env )
#else
   void Java_ca_renzhi_Particle_MainActivity_nativeOnResume()
#endif
   {
   }

   /** Activity onDestroy */
#ifdef ANDROID_NDK
   void Java_ca_renzhi_Particle_MainActivity_nativeOnDestroy( JNIEnv*  env )
#else
   void Java_ca_renzhi_Particle_MainActivity_nativeOnDestroy()
#endif
   {
      device->drop();
#ifdef ANDROID_NDK
      importGLDeinit();
#endif
   }

   //SPARK Demo Irrlicht Basic
   void init_exampleOne()
   {
      camera = smgr->addCameraSceneNodeFPS(smgr->getRootSceneNode(),100.0f,0.0005f);
      camera->setPosition(vector3df(0.0f,2.5f,2.0f));
      camera->setTarget(vector3df(0.0f,0.0f,0.3f));
      camera->setNearValue(0.05f);
   
      // Inits Particle Engine
      randomSeed = device->getTimer()->getRealTime();
      // Sets the update step
      IRRSystem::setClampStep(true,0.1f);         // clamp the step to 100 ms
      IRRSystem::useAdaptiveStep(0.001f,0.01f);      // use an adaptive step from 1ms to 10ms (1000fps to 100fps)
   
      Vector3D gravity(0.0f,-0.8f,0.0f);
   
      IRRQuadRenderer* particleRenderer = IRRQuadRenderer::create(device);
      particleRenderer->setTexture(driver->getTexture(EG_ONE_POINT_TEXTURE));
      particleRenderer->setTexturingMode(TEXTURE_2D);
      particleRenderer->setScale(0.05f,0.05f);
      particleRenderer->setBlending(BLENDING_ADD);
      particleRenderer->enableRenderingHint(DEPTH_WRITE,false);
   
      // Model
      particleModel = Model::create(FLAG_RED | FLAG_GREEN | FLAG_BLUE | FLAG_ALPHA);
      particleModel->setParam(PARAM_ALPHA,0.8f); // constant alpha
      particleModel->setLifeTime(8.0f,8.0f);
   
      // Emitter
      SphericEmitter* particleEmitter = SphericEmitter::create(Vector3D(0.0f,1.0f,0.0f),0.1f * PI,0.1f * PI);
      particleEmitter->setZone(Point::create(Vector3D(0.0f,0.02f,0.0f)));
      particleEmitter->setFlow(250);
      particleEmitter->setForce(1.5f,1.5f);
   
      // Obstacle
      Plane* groundPlane = Plane::create();
      Obstacle* obstacle = Obstacle::create(groundPlane,INTERSECT_ZONE,0.6f,1.0f);
   
      // Group
      Group* particleGroup = Group::create(particleModel,2100);
      particleGroup->addEmitter(particleEmitter);
      particleGroup->setRenderer(particleRenderer);
      particleGroup->addModifier(obstacle);
      particleGroup->setGravity(gravity);
      particleGroup->enableAABBComputing(true);
      
      particleSystem = IRRSystem::create(smgr->getRootSceneNode(),smgr);
      particleSystem->addGroup(particleGroup);
      particleSystem->enableAABBComputing(true);
   
      // setup some useful variables
      currenttime=(f32)device->getTimer()->getTime() / 1000.0f;
      step = 0.0f;
   }

   //SPARK Demo Irrlicht Fire
   void init_exampleTwo()
   {
      camera = smgr->addCameraSceneNode(0,vector3df(camPosZ*sinf(angleX*DEGTORAD)*sinf((90.0f-angleY)*DEGTORAD),
                                    camPosZ*cosf((90.0f-angleY)*DEGTORAD),camPosZ*cosf(angleX*DEGTORAD)*sinf((90.0f-angleY)*DEGTORAD)),
                                    vector3df());
      camera->setNearValue(0.05f);

      IMesh* sceneryMesh = smgr->getMesh(EG_TWO_MODEL_FILE);
      ISceneNode* sceneryNode = smgr->addMeshSceneNode(sceneryMesh);
      sceneryNode->setPosition(vector3df(0.0f,-1.5f,0.0f));
      sceneryNode->setScale(vector3df(0.01f,0.01f,0.01f));

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

      lightNode = smgr->addLightSceneNode();
      lightNode->setLightType(ELT_SPOT);
      SLight& lightData = lightNode->getLightData();
      lightData.AmbientColor = SColorf(0.0f,0.0f,0.0f);
      lightData.DiffuseColor = 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
      IRRSystem::setClampStep(true,0.1f);         // clamp the step to 100 ms
      IRRSystem::useAdaptiveStep(0.001f,0.01f);      // use an adaptive step from 1ms to 10ms (1000fps to 100fps)

      // Inits Particle Engine

      // Renderers
      IRRQuadRenderer* fireRenderer = IRRQuadRenderer::create(device);
      fireRenderer->setScale(0.3f,0.3f);
      fireRenderer->setTexture(driver->getTexture(EG_TWO_FIRE_TEXTURE));
      fireRenderer->setTexturingMode(TEXTURE_2D);
      fireRenderer->setBlending(BLENDING_ADD);
      fireRenderer->enableRenderingHint(DEPTH_WRITE,false);
      fireRenderer->setAtlasDimensions(2,2);

      IRRQuadRenderer* smokeRenderer = IRRQuadRenderer::create(device);
      smokeRenderer->setScale(0.3f,0.3f);
      smokeRenderer->setTexture(driver->getTexture(EG_TWO_EXPO_TEXTURE));
      smokeRenderer->setTexturingMode(TEXTURE_2D);
      smokeRenderer->setBlending(BLENDING_ALPHA);
      smokeRenderer->enableRenderingHint(DEPTH_WRITE,false);
      smokeRenderer->setAtlasDimensions(2,2);

      // 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);

      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);

      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
      particleSystem = IRRSystem::create(smgr->getRootSceneNode(),smgr);
      particleSystem->addGroup(smokeGroup);
      particleSystem->addGroup(fireGroup);
      particleSystem->enableAABBComputing(true);

      // setup some useful variables
      currenttime=(f32)device->getTimer()->getTime() / 1000.0f;
      lightTime = 0.05f;
   }

   SPK_ID createParticleSystemBase()
   {
      ///////////////
      // Renderers //
      ///////////////
   
      // smoke renderer
      IRRQuadRenderer* smokeRenderer = IRRQuadRenderer::create(device);
      smokeRenderer->setTexturingMode(TEXTURE_2D);
      smokeRenderer->setTexture(driver->getTexture(EG_THREE_EXPLO_TEXTURE));
      smokeRenderer->setAtlasDimensions(2,2); // uses 4 different patterns in the texture
      smokeRenderer->setBlending(BLENDING_ALPHA);
      smokeRenderer->enableRenderingHint(DEPTH_WRITE,false);
      smokeRenderer->setShared(true);
   
      // flame renderer
      IRRQuadRenderer* flameRenderer = IRRQuadRenderer::create(device);
      flameRenderer->setTexturingMode(TEXTURE_2D);
      flameRenderer->setTexture(driver->getTexture(EG_THREE_EXPLO_TEXTURE));
      flameRenderer->setAtlasDimensions(2,2);
      flameRenderer->setBlending(BLENDING_ADD);
      flameRenderer->enableRenderingHint(DEPTH_WRITE,false);
      flameRenderer->setShared(true);
   
      // flash renderer
      IRRQuadRenderer* flashRenderer = IRRQuadRenderer::create(device);
      flashRenderer->setTexturingMode(TEXTURE_2D);
      flashRenderer->setTexture(driver->getTexture(EG_THREE_FLASH_TEXTURE));
      flashRenderer->setBlending(BLENDING_ADD);
      flashRenderer->enableRenderingHint(DEPTH_WRITE,false);
      flashRenderer->setShared(true);
   
      // spark 1 renderer
      IRRQuadRenderer* spark1Renderer = IRRQuadRenderer::create(device);
      spark1Renderer->setTexturingMode(TEXTURE_2D);
      spark1Renderer->setTexture(driver->getTexture(EG_THREE_SPARK1_TEXTURE));
      spark1Renderer->setBlending(BLENDING_ADD);
      spark1Renderer->enableRenderingHint(DEPTH_WRITE,false);
      spark1Renderer->setOrientation(DIRECTION_ALIGNED); // sparks are oriented function o their velocity
      spark1Renderer->setScale(0.05f,1.0f); // thin rectangles
      spark1Renderer->setShared(true);
   
      // spark 2 renderer
      IRRQuadRenderer* spark2Renderer = IRRQuadRenderer::create(device);
      spark2Renderer->setTexturingMode(TEXTURE_2D);
      spark2Renderer->setTexture(driver->getTexture(EG_THREE_SPARK2_TEXTURE));
      spark2Renderer->setScale(0.02f,0.02f);
      spark2Renderer->setBlending(BLENDING_ADD);
      spark2Renderer->enableRenderingHint(DEPTH_WRITE,false);
      spark2Renderer->setShared(true);
   
      // wave renderer
      IRRQuadRenderer* waveRenderer = IRRQuadRenderer::create(device);
      waveRenderer->setTexturingMode(TEXTURE_2D);
      waveRenderer->setTexture(driver->getTexture(EG_THREE_WAVE_TEXTURE));
      waveRenderer->setBlending(BLENDING_ALPHA);
      waveRenderer->enableRenderingHint(DEPTH_WRITE,false);
      waveRenderer->enableRenderingHint(ALPHA_TEST,true); // uses the alpha test
      waveRenderer->setAlphaTestThreshold(0.0f);
      waveRenderer->setOrientation(FIXED_ORIENTATION); // the orientatin is fixed
      waveRenderer->lookVector.set(0.0f,1.0f,0.0f);
      waveRenderer->upVector.set(1.0f,0.0f,0.0f); // we dont really care about the up axis
      waveRenderer->setShared(true);
   
      ////////////
      // Models //
      ////////////
   
      Interpolator* interpolator = NULL; // pointer to an interpolator that is used to retrieve interpolators
   
      // smoke model
      Model* smokeModel = Model::create(FLAG_RED | FLAG_GREEN | FLAG_BLUE | FLAG_ALPHA | FLAG_SIZE | FLAG_ANGLE | FLAG_TEXTURE_INDEX,
         FLAG_SIZE | FLAG_ANGLE,
         FLAG_SIZE | FLAG_ANGLE | FLAG_TEXTURE_INDEX,
         FLAG_ALPHA);
      smokeModel->setParam(PARAM_RED,0.2f);
      smokeModel->setParam(PARAM_GREEN,0.2f);
      smokeModel->setParam(PARAM_BLUE,0.2f);
      smokeModel->setParam(PARAM_SIZE,0.6f,0.8f,1.0f,1.4f);
      smokeModel->setParam(PARAM_TEXTURE_INDEX,0.0f,4.0f);
      smokeModel->setParam(PARAM_ANGLE,0.0f,PI * 0.5f,0.0f,PI * 0.5f);
      smokeModel->setLifeTime(2.5f,3.0f);
      smokeModel->setShared(true);
   
      interpolator = smokeModel->getInterpolator(PARAM_ALPHA);
      interpolator->addEntry(0.0f,0.0f);
      interpolator->addEntry(0.4f,0.4f,0.6f);
      interpolator->addEntry(0.6f,0.4f,0.6f);
      interpolator->addEntry(1.0f,0.0f);
   
      // flame model
      Model* flameModel = Model::create(FLAG_RED | FLAG_GREEN | FLAG_BLUE | FLAG_ALPHA | FLAG_SIZE | FLAG_ANGLE | FLAG_TEXTURE_INDEX,
         FLAG_ANGLE | FLAG_RED | FLAG_GREEN | FLAG_BLUE,
         FLAG_ANGLE | FLAG_TEXTURE_INDEX,
         FLAG_SIZE | FLAG_ALPHA);
      flameModel->setParam(PARAM_RED,1.0f,0.2f);
      flameModel->setParam(PARAM_GREEN,0.5f,0.2f);
      flameModel->setParam(PARAM_BLUE,0.2f,0.2f);
      flameModel->setParam(PARAM_TEXTURE_INDEX,0.0f,4.0f);
      flameModel->setParam(PARAM_ANGLE,0.0f,PI * 0.5f,0.0f,PI * 0.5f);
      flameModel->setLifeTime(1.5f,2.0f);
      flameModel->setShared(true);
   
      interpolator = flameModel->getInterpolator(PARAM_SIZE);
      interpolator->addEntry(0.0f,0.25f);
      interpolator->addEntry(0.02f,0.6f,0.8f);
      interpolator->addEntry(1.0f,1.0f,1.4f);
   
      interpolator = flameModel->getInterpolator(PARAM_ALPHA);
      interpolator->addEntry(0.5f,1.0f);
      interpolator->addEntry(1.0f,0.0f);
   
      // flash model
      Model* flashModel = Model::create(FLAG_ALPHA | FLAG_SIZE | FLAG_ANGLE,
         FLAG_NONE,
         FLAG_ANGLE,
         FLAG_ALPHA | FLAG_SIZE);
      flashModel->setParam(PARAM_ANGLE,0.0f,2.0f * PI);
      flashModel->setLifeTime(0.5f,0.5f);
      flashModel->setShared(true);
   
      interpolator = flashModel->getInterpolator(PARAM_SIZE);
      interpolator->addEntry(0.0f,0.25f);
      interpolator->addEntry(0.1f,1.0f,2.0f);
   
      interpolator = flashModel->getInterpolator(PARAM_ALPHA);
      interpolator->addEntry(0.0f,1.0f);
      interpolator->addEntry(0.4f,0.0f);
   
      // spark 1 model
      Model* spark1Model = Model::create(FLAG_SIZE | FLAG_ALPHA,
         FLAG_ALPHA,
         FLAG_SIZE);
      spark1Model->setParam(PARAM_ALPHA,1.0f,0.0f);
      spark1Model->setParam(PARAM_SIZE,0.2f,0.4f);
      spark1Model->setLifeTime(0.2f,1.0f);
      spark1Model->setShared(true);
   
      // spark 2 model
      Model* spark2Model = Model::create(FLAG_RED | FLAG_GREEN | FLAG_BLUE | FLAG_ALPHA,
         FLAG_GREEN | FLAG_BLUE | FLAG_ALPHA,
         FLAG_GREEN);
      spark2Model->setParam(PARAM_ALPHA,1.0f,0.0f);
      spark2Model->setParam(PARAM_RED,1.0f);
      spark2Model->setParam(PARAM_GREEN,1.0f,1.0f,0.3f,1.0f);
      spark2Model->setParam(PARAM_BLUE,0.7f,0.3f);
      spark2Model->setLifeTime(1.0f,3.0f);
      spark2Model->setShared(true);
   
      // wave model
      Model* waveModel = Model::create(FLAG_ALPHA | FLAG_SIZE,
         FLAG_SIZE | FLAG_ALPHA);
      waveModel->setParam(PARAM_SIZE,0.0f,4.0f);
      waveModel->setParam(PARAM_ALPHA,0.2f,0.0f);
      waveModel->setLifeTime(0.8f,0.8f);
      waveModel->setShared(true);
   
      //////////////
      // Emitters //
      //////////////
   
      // This zone will be used by several emitters
      Sphere* explosionSphere = Sphere::create(Vector3D(0.0f,0.0f,0.0f),0.4f);
   
      // smoke emitter
      RandomEmitter* smokeEmitter = RandomEmitter::create();
      smokeEmitter->setZone(Sphere::create(Vector3D(0.0f,0.0f,0.0f),0.6f),false);
      smokeEmitter->setFlow(-1);
      smokeEmitter->setTank(15);
      smokeEmitter->setForce(0.02f,0.04f);
   
      // flame emitter
      NormalEmitter* flameEmitter = NormalEmitter::create();
      flameEmitter->setZone(explosionSphere);
      flameEmitter->setFlow(-1);
      flameEmitter->setTank(15);
      flameEmitter->setForce(0.06f,0.1f);
   
      // flash emitter
      StaticEmitter* flashEmitter = StaticEmitter::create();
      flashEmitter->setZone(Sphere::create(Vector3D(0.0f,0.0f,0.0f),0.1f));
      flashEmitter->setFlow(-1);
      flashEmitter->setTank(3);
   
      // spark 1 emitter
      NormalEmitter* spark1Emitter = NormalEmitter::create();
      spark1Emitter->setZone(explosionSphere);
      spark1Emitter->setFlow(-1);
      spark1Emitter->setTank(20);
      spark1Emitter->setForce(2.0f,3.0f);
   
      // spark 2 emitter
      NormalEmitter* spark2Emitter = NormalEmitter::create();
      spark2Emitter->setZone(explosionSphere);
      spark2Emitter->setFlow(-1);
      spark2Emitter->setTank(400);
      spark2Emitter->setForce(0.4f,0.8f);
   
      // wave emitter
      StaticEmitter* waveEmitter = StaticEmitter::create();
      waveEmitter->setZone(Point::create());
      waveEmitter->setFlow(-1);
      waveEmitter->setTank(1);
   
      ////////////
      // Groups //
      ////////////
   
      // smoke group
      Group* smokeGroup = Group::create(smokeModel,15);
      smokeGroup->addEmitter(smokeEmitter);
      smokeGroup->setRenderer(smokeRenderer);
      smokeGroup->setGravity(Vector3D(0.0f,0.05f,0.0f));
   
      // flame group
      Group* flameGroup = Group::create(flameModel,15);
      flameGroup->addEmitter(flameEmitter);
      flameGroup->setRenderer(flameRenderer);
   
      // flash group
      Group* flashGroup = Group::create(flashModel,3);
      flashGroup->addEmitter(flashEmitter);
      flashGroup->setRenderer(flashRenderer);
   
      // spark 1 group
      Group* spark1Group = Group::create(spark1Model,20);
      spark1Group->addEmitter(spark1Emitter);
      spark1Group->setRenderer(spark1Renderer);
      spark1Group->setGravity(Vector3D(0.0f,-1.5f,0.0f));
   
      // spark 2 group
      Group* spark2Group = Group::create(spark2Model,400);
      spark2Group->addEmitter(spark2Emitter);
      spark2Group->setRenderer(spark2Renderer);
      spark2Group->setGravity(Vector3D(0.0f,-0.3f,0.0f));
      spark2Group->setFriction(0.4f);
   
      // wave group
      Group* waveGroup = Group::create(waveModel,1);
      waveGroup->addEmitter(waveEmitter);
      waveGroup->setRenderer(waveRenderer);
      
      ////////////
      // System //
      ////////////
   
      IRRSystem* system = IRRSystem::create(smgr->getRootSceneNode(),smgr);
      system->addGroup(smokeGroup);
      system->addGroup(flameGroup);
      system->addGroup(flashGroup);
      system->addGroup(spark1Group);
      system->addGroup(spark2Group);
      system->addGroup(waveGroup);

      // Gets a pointer to the base
      return system->getSPKID();
   }

   // Creates a particle system from the base system
   IRRSystem* createParticleSystem(const Vector3D& pos)
   {
      // Creates a copy of the base system
      IRRSystem* system = SPK_Copy(IRRSystem,BaseSystemID);
   
      // Locates the system at the given position
      system->setTransformPosition(pos);
      system->updateTransform(); // updates the world transform of system and its children
   
      return system;
   }

   void destroyParticleSystem(IRRSystem*& system)
   {
      // Destroys the given system
      SPK_Destroy(system);
      system = NULL;
   }

   //SPARK Demo Irrlicht Explosion
   void init_exampleThree()
   {
      camera = smgr->addCameraSceneNodeFPS(smgr->getRootSceneNode(),100.0f,0.0005f);
      camera->setPosition(vector3df(0.0f,0.0f,2.5f));
      camera->setTarget(vector3df(0.0f,0.0f,0.3f));
      camera->setNearValue(0.05f);

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

      BaseSystemID = createParticleSystemBase();

      spacePressed = 10.0f;
   }

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

      // Inits Particle Engine
      // Renderers
      IRRRenderer* particleRenderer = NULL;
      IRRQuadRenderer* quadRenderer = IRRQuadRenderer::create(device);
      quadRenderer->setTexturingMode(TEXTURE_2D);
      quadRenderer->setTexture(driver->getTexture(EG_FOUR_BALL_TEXTURE));
      quadRenderer->setScale(0.15f,0.15f);
      particleRenderer = quadRenderer;

      particleRenderer->setBlending(BLENDING_NONE);
      particleRenderer->enableRenderingHint(ALPHA_TEST,true);
      particleRenderer->setAlphaTestThreshold(0.8f);

      // Model
      Model* particleModel = Model::create();
      particleModel->setImmortal(true);

      // Zone
      Sphere* sphere = Sphere::create(Vector3D(),1.0f - 0.15f / 2.0f);
      AABox* cube = AABox::create(Vector3D(),Vector3D(1.2f,1.2f,1.2f));

      // Obstacle
      Obstacle* obstacle = Obstacle::create(sphere,EXIT_ZONE,0.9f,0.9f);

      // Group
      Group* particleGroup = Group::create(particleModel,NB_PARTICLES);
      particleGroup->setRenderer(particleRenderer);
      particleGroup->addModifier(obstacle);
      particleGroup->addModifier(Collision::create(0.15f,0.9f));
      particleGroup->setFriction(0.1f);
      particleGroup->setGravity(Vector3D(0.0f,-1.5f,0.0f));
      particleGroup->enableAABBComputing(true);
      
      particleSystem =  IRRSystem::create(smgr->getRootSceneNode(),smgr);
      particleSystem->addGroup(particleGroup);
      particleSystem->enableAABBComputing(true);
   }

#ifdef ANDROID_NDK
   void init(jint nExample)
#else
   void init(int nExample)
#endif
   {
#ifdef ANDROID_NDK
      importGLInit();
      device = createDevice(EDT_OGLES1, dimension2d<u32>(gWindowWidth, gWindowHeight), 16, false, false, false, 0);
#else
      device = createDevice(EDT_OPENGL, dimension2d<u32>(gWindowWidth, gWindowHeight), 16, false, false, false, 0);
#endif
      driver = device->getVideoDriver();
      smgr = device->getSceneManager();

      switch(nExample)
      {
         //SPARK Demo Irrlicht Basic
      case EXAMPLE_ONE:
         init_exampleOne();
         break;
      case EXAMPLE_TWO:
         //SPARK Demo Irrlicht Fire
         init_exampleTwo();
         break;
      case EXAMPLE_THREE:
         //SPARK Demo Irrlicht Explosion
         init_exampleThree();
         break;
      case EXAMPLE_FOUR:
         //SPARK Demo Irrlicht Collision2
         init_exampleFour();
         break;
      default:
         break;
      }   
   }

#ifdef ANDROID_NDK
   void Java_ca_renzhi_Particle_MainActivity_nativeInitGL(JNIEnv*  env, jobject  thiz, jint w, jint h, jint nEg)
#else
   void Java_ca_renzhi_Particle_MainActivity_nativeInitGL(int w, int h, int nEg)
#endif
   {
      if (w > 0)
         gWindowWidth = w;
      if (h > 0)
         gWindowHeight = h;

      if (!initialized)
      {
         init(nEg);
      }
   }

#ifdef ANDROID_NDK
   void Java_ca_renzhi_Particle_MainActivity_nativeResize(JNIEnv*  env, jobject  thiz, jint w, jint h)
#else
   void Java_ca_renzhi_Particle_MainActivity_nativeResize(int w, int h)
#endif
   {
      gWindowWidth  = w;
      gWindowHeight = h;
        dimension2d<unsigned int> size;
        size.Width = w;
      size.Height = h;
      device->getVideoDriver()->OnResize(size);
   }

   //SPARK Demo Irrlicht Basic
   void drawIteration_exampleOne()
   {
      if(device->isWindowActive())
      {
         oldtime = currenttime;
         currenttime = (f32)device->getTimer()->getTime() / 1000.0f;
         deltaTime = currenttime - oldtime;
      
         // Changes the color of the model over time
         step += deltaTime * 0.5f;
         particleModel->setParam(PARAM_RED,0.6f + 0.4f * sin(step));
         particleModel->setParam(PARAM_GREEN,0.6f + 0.4f * sin(step + PI * 2.0f / 3.0f));
         particleModel->setParam(PARAM_BLUE,0.6f + 0.4f * sin(step + PI * 4.0f / 3.0f));
      
         driver->beginScene(true, true, SColor(0,0,0,0));
      
         // Renders scene
         smgr->drawAll();
      
         driver->endScene();
      }
      else
      {
         device->closeDevice();
         device->drop();
      }
   }

   //SPARK Demo Irrlicht Fire
   void drawIteration_exampleTwo()
   {
      if(device->isWindowActive())
      {
         oldtime = currenttime;
         currenttime = (f32)device->getTimer()->getTime() / 1000.0f;
         deltaTime = currenttime - oldtime;

         lightTime += deltaTime;
         if (lightTime >= 0.05f)
         {
            float lightIntensity = 1.0f - (random(0.0f,0.05f) * 5.0f);
            lightTime -= lightTime;
            lightNode->setPosition(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, SColor(0,0,0,0));

         // Renders scene
         smgr->drawAll();

         driver->endScene();
      }
      else
      {
         device->closeDevice();
         device->drop();
      }
   }

   //SPARK Demo Irrlicht
   void drawIteration_exampleThree()
   {
      if(device->isWindowActive())
      {
         oldtime = currenttime;
         currenttime = (f32)device->getTimer()->getTime() / 1000.0f;
         deltaTime = currenttime - oldtime;

         LOG("spacePressed=%f", spacePressed);
         if (spacePressed >= 0.0f)
         {
            spacePressed += deltaTime;
            if (spacePressed >= 10.0f)
            {
               Vector3D position(random(-2.0f,2.0f),random(-2.0f,2.0f),random(-2.0f,2.0f));
               particleSystems.push_back(createParticleSystem(position));
         
               spacePressed = 0.0f;
            }
         }

         list<IRRSystem*>::Iterator it = particleSystems.begin();
         while(it != particleSystems.end())
         {
            // Updates the particle systems
            if (!(*it)->update(deltaTime * 0.001f))
            {
               // If a system is sleeping, destroys it
               destroyParticleSystem(*it);
               // And erases its entry in the container
               it = particleSystems.erase(it);
            }
            else
               ++it;
         }

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

         // Renders all the particle systems
         for (it = particleSystems.begin(); it != particleSystems.end(); ++it)
            //(*it)->render();
            // Renders scene
            smgr->drawAll();

         driver->endScene();
      }
      else
      {
         device->closeDevice();
         device->drop();
      }

   }

   //SPARK Demo Irrlicht Collision2
   void drawIteration_exampleFour()
   {
      if(device->isWindowActive())
      {
         driver->beginScene(true, true, SColor(0,0,0,0));
      
         // Renders scene
         smgr->drawAll();
      
         driver->endScene();
      }
      else
      {
         device->closeDevice();
         device->drop();
      }

   }

#ifdef ANDROID_NDK
   void drawIteration(jint nExample)
#else
   void drawIteration(int nExample)
#endif
   {
      switch(nExample)
      {
      case EXAMPLE_ONE:
         //SPARK Demo Irrlicht Basic
         drawIteration_exampleOne();
         break;
      case EXAMPLE_TWO:
         //SPARK Demo Irrlicht Fire
         drawIteration_exampleTwo();
         break;
      case EXAMPLE_THREE:
         //SPARK Demo Irrlicht Explosion
         drawIteration_exampleThree();
         break;
      case EXAMPLE_FOUR:
         //SPARK Demo Irrlicht Collision2
         drawIteration_exampleFour();
         break;
      default:
         break;
      }   

   }

#ifdef ANDROID_NDK
   void Java_ca_renzhi_Particle_MainActivity_nativeDrawIteration(JNIEnv* env, jobject  thiz, jint nEg)
#else
   void Java_ca_renzhi_Particle_MainActivity_nativeDrawIteration(int nEg)
#endif
   {
#ifdef __LINUX
      while (device->run()) {
#else
      device->run();
#endif
      drawIteration(nEg);

#ifdef __LINUX
      }
#endif
   }

#ifdef __LINUX
   int main()
   {
      Java_ca_renzhi_irrlicht_MainActivity_nativeInitGL(0, 0, 0);
      Java_ca_renzhi_irrlicht_MainActivity_nativeDrawIteration(0);
      Java_ca_renzhi_irrlicht_MainActivity_nativeOnDestroy();

      return 0;
   }
#endif

#ifdef ANDROID_NDK
}
#endif

@Darktib: yes.
@Juff:
My code, Actually,
Java_ca_renzhi_Particle_MainActivity_nativeInitGL() CALL init()
....
case EXAMPLE_THREE:
//SPARK Demo Irrlicht Explosion
init_exampleThree();

Java_ca_renzhi_Particle_MainActivity_nativeDrawIteration() CALL drawIteration()
....
case EXAMPLE_THREE:
//SPARK Demo Irrlicht Explosion
drawIteration_exampleThree();

Maybe Help.
Back to top Go down
Sponsored content





One issue on explosion demo of SPARK using Irrlicht as a renderer? Empty
PostSubject: Re: One issue on explosion demo of SPARK using Irrlicht as a renderer?   One issue on explosion demo of SPARK using Irrlicht as a renderer? Icon_minitime

Back to top Go down
 
One issue on explosion demo of SPARK using Irrlicht as a renderer?
Back to top 
Page 1 of 1
 Similar topics
-
» [Résolu] Explosion Spark dans Irrlicht
» spark explosion demo crash-vs2010-opengl-sdl
» SPARK Demo Irrlicht - Unresolved externals
» Line trail for irrlicht renderer
» Démo explosion

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