Author Topic: fire explosion effect  (Read 7188 times)

Offline gamerfan

  • int
  • **
  • Posts: 97
    • View Profile
fire explosion effect
« on: November 26, 2011, 04:33:03 pm »
I want to produce some fire explosion effect.For that, can I use partclemanager.java available in alienRunner-ae? if so how can I use it?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: fire explosion effect
« Reply #1 on: November 27, 2011, 08:18:04 pm »
As long as you don't display too many particles, it should work fine. I'm not 100% sure what i did there...i guess you give a texture name, a direction and some speed or something...just look at the sources on how to use it.

Offline gamerfan

  • int
  • **
  • Posts: 97
    • View Profile
Re: fire explosion effect
« Reply #2 on: November 28, 2011, 05:17:08 am »
sure, Thanks.

Offline gamerfan

  • int
  • **
  • Posts: 97
    • View Profile
Re: fire explosion effect
« Reply #3 on: December 04, 2011, 02:07:38 pm »
I ported explosion code found in robombs in my sample application.But the problem here is explosion does not seem to be happen.All I can see static image on screen.And also, after the explosion is over , it should disappear from the screen. That is not happening.There is a condition check in process method of Explosion.java that checks the following condition:
Code: [Select]
if (cTicks > maxTicks) {
disable();
return true;
}
If I enable this, I am not able to see any explosion.So currently, I just commented the above lines in my application to see something on the screen.I have just used max 32 particles(object3D arrays) for this.What are the things I need to follow to overcome this?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: fire explosion effect
« Reply #4 on: December 04, 2011, 08:53:23 pm »
Which explosion code? The actual explosion of the bombs? If so, they rely on texture coordinate changes. If you use that on compiled objects, you have to make sure that these objects are compiled in a way that allows for this (the default doesn't). If you are using this on Android (are you?), you have to add an explicit call to compile(true, false). But if that "if" makes your explosions to disappear, you might have ported is wrong regarding the ticks. What are you feeding into it as "ticks"?

Offline gamerfan

  • int
  • **
  • Posts: 97
    • View Profile
Re: fire explosion effect
« Reply #5 on: December 05, 2011, 06:38:44 pm »
I have ported your 'explosion' code to JPCT SE, not tAndroid.
This is how I am getting cTicks and maxTicks.
Code: [Select]
public boolean process(long ticks) {
            setVisibility(true);
cTicks = Ticker.getTime() - start;
if (cTicks < 0) {
cTicks = maxTicks;
}

Code: [Select]
maxTicks = maxLength * 15;
where maxLength = 8.
Please find my version of Explosion.java. I have added blueprint.complile() as per your suggestion.But the entire screen is getting darker and no explosion is actually happening, only static  scattered images displayed on the screen .

Code: [Select]
public class Explosion extends Object3D{

static final private long serialVersionUID = 1L;

private static Object3D blueprint = null;
private static final int MAX_PER_SIDE = 4;//Globals.enhancedGraphics ? 8 : 4;

static {
                TextureManager.getInstance().addTexture("explosion", new Texture("textures"+File.separatorChar+"explosion.png"));
blueprint = Primitives.getPlane(1, 10);
blueprint.translate(100000, 100000, 100000);
blueprint.setTexture("explosion");
blueprint.setBillboarding(true);
blueprint.setTransparency(11);
blueprint.setTransparencyMode(Object3D.TRANSPARENCY_MODE_ADD);
blueprint.setAdditionalColor(java.awt.Color.WHITE);
blueprint.getMesh().compress();
                blueprint.compile();
blueprint.build();
}

private Object3D[] blow = new Object3D[MAX_PER_SIDE * 4];
private int[] index = new int[MAX_PER_SIDE * 4];
private int mainIndex = 0;
private long cTicks = 0;
private int maxLength = 20;
private long maxTicks = 1000;
private long start = 0;
private int blows = 3;

private float maxXP = 1000;
private float maxXM = 1000;
private float maxZP = 1000;
private float maxZM = 1000;

private boolean isLocal = false;

public Explosion() {
super(blueprint, true);
setScale(3);
setTransparency(13);
for (int i = 0; i < blow.length; i++) {
    blow[i] = new Object3D(blueprint);
}
}

public void addToWorld(World world) {
world.addObject(this);
for (int i = 0; i < blow.length; i++) {
                       blow[i].setVisibility(false);
world.addObject(blow[i]);
}
setCollisionMode(Object3D.COLLISION_CHECK_SELF);
}

public void remove(World world) {
world.removeObject(this);
for (int i = 0; i < blow.length; i++) {
world.removeObject(blow[i]);
}
setCollisionMode(Object3D.COLLISION_CHECK_NONE);
}

public void enable(SimpleVector startPos) {
                System.out.println("....inside enable meth......");
getTranslationMatrix().setIdentity();
translate(startPos);
setTexture(this, 0);
mainIndex = 0;
setVisibility(false);
maxLength = 8;//bomb.getBackAnimationSpeed();
blows = Math.min((int) (maxLength / 7.5f + 0.5f), MAX_PER_SIDE);
maxTicks = maxLength * 15;//LocalBombManager.DURATION_MUL;
                int ff = blows << 2;
                System.out.println("1....blw size "+"blows:"+blows+" "+ff);
for (int i = 0; i < blows << 2; i++) {
                        System.out.println("XXXXXX");
blow[i].getTranslationMatrix().setIdentity();
blow[i].translate(startPos);
setTexture(blow[i], 0);
index[i] = 0;
blow[i].setVisibility(true);
}
cTicks = 0;
start = Ticker.getTime();
}

public void disable() {
this.setVisibility(false);
for (int i = 0; i < blow.length; i++) {
blow[i].setVisibility(false);
}
}



public boolean process(long ticks) {
            setVisibility(true);
cTicks = Ticker.getTime() - start;
if (cTicks < 0) {
cTicks = maxTicks;
}
mainIndex = Math.min(31, (32 * (int) cTicks / (int) maxTicks));
setTexture(this, mainIndex);

float xp = 1;
float xm = 1;
float zp = 1;
float zm = 1;

float div = ((float) maxLength * (float) cTicks / (float) maxTicks) / (float) blows;
float indDiv = Math.min(31, ((float) 32 * (float) cTicks / (float) maxTicks) / (float) blows);

float blastRadius = 3;
SimpleVector ellips = new SimpleVector(blastRadius, blastRadius, blastRadius);
float range = (float) blows * div;

// xp
float mt = Math.min(maxXP, range);
SimpleVector trans = new SimpleVector(mt, 0, 0);
SimpleVector xpm = checkForCollisionEllipsoid(trans, ellips, 1);
if (xpm.equals(trans)) {
maxXP = 1000;
} else {
maxXP = mt;
}

// xm
mt = Math.min(maxXM, range);
trans = new SimpleVector(-mt, 0, 0);
xpm = checkForCollisionEllipsoid(trans, ellips, 1);
if (xpm.equals(trans)) {
maxXM = 1000;
} else {
maxXM = mt;
}

// zp
mt = Math.min(maxZP, range);
trans = new SimpleVector(0, 0, mt);
xpm = checkForCollisionEllipsoid(trans, ellips, 1);
if (xpm.equals(trans)) {
maxZP = 1000;
} else {
maxZP = mt;
}

// zm
mt = Math.min(maxZM, range);
trans = new SimpleVector(0, 0, -mt);
xpm = checkForCollisionEllipsoid(trans, ellips, 1);
if (xpm.equals(trans)) {
maxZM = 1000;
} else {
maxZM = mt;
}
for (int i = 0; i < blows << 2; i++) {
                       System.out.println("RRRRRRR");
blow[i].getTranslationMatrix().setIdentity();
blow[i].translate(getTranslation());
                        blow[i].setVisibility(true);

int p = i % 4;
if (p == 0) {
// xp
blow[i].translate(Math.min(maxXP, div * xp), 0, 0);
setTexture(blow[i], (int) Math.min(31, (blows + 1 - xp) * indDiv));
xp++;
}
if (p == 1) {
// xm
blow[i].translate(-Math.min(maxXM, div * xm), 0, 0);
setTexture(blow[i], (int) Math.min(31, (blows + 1 - xm) * indDiv));
xm++;
}
if (p == 2) {
// zp
blow[i].translate(0, 0, Math.min(maxZP, div * zp));
setTexture(blow[i], (int) Math.min(31, (blows + 1 - zp) * indDiv));
zp++;
}
if (p == 3) {
// zm
blow[i].translate(0, 0, -Math.min(maxZM, div * zm));
setTexture(blow[i], (int) Math.min(31, (blows + 1 - zm) * indDiv));
zm++;
}
}
System.out.println("sssssss");
       
if (cTicks > maxTicks) {
                    //  setVisibility(false);
//disable();
return true;
}
               
return false;
}

private void setTexture(Object3D obj, int index) {

if (index > 15) {
index = 15 + (16 - index);
}

int v = (index / 4) * 64;
int u = (index % 4) * 64;

PolygonManager pm = obj.getPolygonManager();
int tid = pm.getPolygonTexture(0);
Texture t = TextureManager.getInstance().getTextureByID(tid);
float u1 = (float) u / (float) t.getWidth();
float v1 = (float) v / (float) t.getHeight();
float u2 = (float) (u + 64) / (float) t.getWidth();
float v2 = (float) (v + 64) / (float) t.getHeight();
TextureInfo ti = new TextureInfo(tid, u1, v1, u1, v2, u2, v1);
pm.setPolygonTexture(0, ti);
ti = new TextureInfo(tid, u1, v2, u2, v2, u2, v1);
pm.setPolygonTexture(1, ti);
obj.recreateTextureCoords();
}
}


Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: fire explosion effect
« Reply #6 on: December 05, 2011, 07:57:35 pm »
Actually, ticks should be Ticker.getTicks(). Using the time is way to large.

Offline gamerfan

  • int
  • **
  • Posts: 97
    • View Profile
Re: fire explosion effect
« Reply #7 on: December 06, 2011, 06:13:32 pm »
I initialized Ticker in Explosion.java and changed to Ticker.getTicks(). So the effect is somewhat looks good. But the explosion does not remove after the effect.The problem here is that if cTicks greater than maxTicks, the explosion is not visible.So what is the use of this if block?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: fire explosion effect
« Reply #8 on: December 06, 2011, 09:45:13 pm »
Well, looking at the actual code of Robombs, i stand correctly. Explosion doesn't make use of ticks but really uses getTime() inside to measure the time that has elapsed since the start of the explosion. So your first variant with getTime() was actually fine. If it doesn't work that way for you, you must have screwed something up in the process of extracting this code from Robombs.
Why have you done these changes to the visibility like not setting it to true in the enable()-method but always setting it to true in process? Why not leave everything as it was and just replace the parts that rely on the configuration of Robombs, because that's actually all you have to do IMHO!?

Offline gamerfan

  • int
  • **
  • Posts: 97
    • View Profile
Re: fire explosion effect
« Reply #9 on: December 07, 2011, 05:37:59 am »
Sorry Egon, I had not changed the code initially. I just ported into my application. But what happened was that when I integrated it first time, the expplosion image was already started appearing on the screen, but no explosion effect takes placeat all.So I anaylized the code and found the place where explosion object was prepared.There I made the change to suite to my requirements. Moreover, I need to show this explosion when user press some key.That is why I made this change and when really user presses a key, I set the explosion object set it back to true.But if I change it to Ticker.getTime(), actually the explosion effect does not happen at all. Only some static weired image appears on the screen.Will this work only with your code? If that is the case, what are the other things I need to take into considerations to integrate with my code ? Thanks for your time.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: fire explosion effect
« Reply #10 on: December 07, 2011, 10:10:21 am »
If you strip the Robombs related stuff, it should actually work...i means, just look at it. It doesn't do much...all it does is to animate and translate some quads based on time. Maybe a screenshot helps to understand what you actually mean with "static weird image"...

Offline gamerfan

  • int
  • **
  • Posts: 97
    • View Profile
Re: fire explosion effect
« Reply #11 on: January 13, 2012, 07:38:46 am »
sorry for the late reply.  Actually I want to use some muzzle flash when gun is fired.But now thinking to use some models instead.searching in googles.

Offline gamerfan

  • int
  • **
  • Posts: 97
    • View Profile
Re: fire explosion effect
« Reply #12 on: February 07, 2012, 06:57:41 am »
I got one logic to do this.I saw this technique from other sites.They are having textures for muzzle flash.They just keep changing the textures at different interval. I am thinking to use this tehnique here.For that, use a plane and apply a default texture to it and when the user presses the fire key, changes the textures at a regular interval.Please correct me if I am wrong.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: fire explosion effect
« Reply #13 on: February 07, 2012, 08:19:30 am »
It might be better to change the texture coordinates instead of the texture itself, but for a simple plane, either way will do. That's the same thing the explosion effect in Robombs works btw.

Offline gamerfan

  • int
  • **
  • Posts: 97
    • View Profile
Re: fire explosion effect
« Reply #14 on: February 07, 2012, 09:41:55 am »
Quote
It might be better to change the texture coordinates instead of the texture itself, but for a simple plane, either way will do. That's the same thing the explosion effect in Robombs works btw.
In that, if I am correctly understood the code, are you changing one texture cordinates? That is where I think the code was not able to integrate.However let me try this logic.For that, how can I change different textures to a plane?