www.jpct.net

jPCT - a 3d engine for Java => Support => Topic started by: gamerfan on November 26, 2011, 04:33:03 pm

Title: fire explosion effect
Post by: gamerfan 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?
Title: Re: fire explosion effect
Post by: EgonOlsen 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.
Title: Re: fire explosion effect
Post by: gamerfan on November 28, 2011, 05:17:08 am
sure, Thanks.
Title: Re: fire explosion effect
Post by: gamerfan 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?
Title: Re: fire explosion effect
Post by: EgonOlsen 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"?
Title: Re: fire explosion effect
Post by: gamerfan 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();
}
}

Title: Re: fire explosion effect
Post by: EgonOlsen on December 05, 2011, 07:57:35 pm
Actually, ticks should be Ticker.getTicks(). Using the time is way to large.
Title: Re: fire explosion effect
Post by: gamerfan 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?
Title: Re: fire explosion effect
Post by: EgonOlsen 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!?
Title: Re: fire explosion effect
Post by: gamerfan 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.
Title: Re: fire explosion effect
Post by: EgonOlsen 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"...
Title: Re: fire explosion effect
Post by: gamerfan 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.
Title: Re: fire explosion effect
Post by: gamerfan 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.
Title: Re: fire explosion effect
Post by: EgonOlsen 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.
Title: Re: fire explosion effect
Post by: gamerfan 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?
Title: Re: fire explosion effect
Post by: EgonOlsen on February 07, 2012, 10:54:46 am
setTexture()?
Title: Re: fire explosion effect
Post by: gamerfan on February 07, 2012, 12:21:21 pm
I was able to do some mock up kind of thing: this is what I have done.I took a muzzle flash texture from net.
(http://www.google.co.in/imgres?imgurl=http://th02.deviantart.net/fs40/150/f/2009/024/d/e/Muzzle_Flash_by_IanTSRichards.jpg&imgrefurl=http://iantsrichards.deviantart.com/art/Muzzle-Flash-110571773&usg=__gND_se7_uncY7a14-2nNFZgL4gQ=&h=150&w=150&sz=6&hl=en&start=198&zoom=1&tbnid=ZIUlsKEdWLG5mM:&tbnh=120&tbnw=120&ei=mAkxT6XcJefj4QT4geX6BA&prev=/search%3Fq%3Dmuzzle%2Bflash%26hl%3Den%26sa%3DX%26imgurl%3Dhttp://themfalegos.webs.com/FlashPic08.jpg%26imgrefurl%3Dhttp://themfalegos.webs.com/howtomakemuzzleflash.htm%26h%3D480%26w%3D720%26sz%3D41%26biw%3D1280%26bih%3D894%26tbs%3Dsimg:CAESEgmFq2WX6ObyviGOnqeuErwjkA%26tbm%3Disch&itbs=1&iact=hc&vpx=642&vpy=304&dur=7152&hovh=120&hovw=120&tx=88&ty=72&sig=111596732373816332081&page=9&ved=1t:429,r:22,s:197)
In the Car example, I loaded a plane and added this texture to it.Then in the processProjectile() method, just used like a on-off kind of switch.This will however produce gun firing effect.But not perfect.Also, have not tried it with my actual code.

Loading muzzle flash:

Code: [Select]
private void loadMuzzleFlashObject(){
   muzzle = Primitives.getPlane(1,4);
   muzzle.translate(new SimpleVector(0, 10, 0));
   muzzle.scale(10);
   Texture muzzleTexture = new Texture("textures" + File.separatorChar + "MuzzleFlash.jpg");
   texMan.addTexture("muzzleflash", muzzleTexture);
   muzzle.setTexture("muzzleflash");
   muzzle.build();
   theWorld.addObject(muzzle);
   muzzle.setVisibility(false);
}
Displaying muzzle flash:

Code: [Select]
private void displayMuzzleFlash(){
   if(muzzle.getVisibility())
      muzzle.setVisibility(false);
     else
      muzzle.setVisibility(true);   
}
This method is called from the processProjectile() method.Now the issues I am facing are :
1. The image is a .jpg so it will not have transparancy.This is can be rectified.
2. The color of the actual .jpg is yellow.But when I added along with the car example, the color of the texture is changed to violet, ie it is taking the color of the Car.I am not able to figure out why this is happening.I have not manually instructed to change the color to violet.

Title: Re: fire explosion effect
Post by: Marlon on February 08, 2012, 02:40:24 pm
2. The color of the actual .jpg is yellow.But when I added along with the car example, the color of the texture is changed to violet, ie it is taking the color of the Car.I am not able to figure out why this is happening.I have not manually instructed to change the color to violet.

Cool, I just made an explosive effect for my game yesterday. :)
To anwer your second question. Search your code for "setAdditionalColor()". I suppose, that you are filling your particle with an extra color.
Title: Re: fire explosion effect
Post by: gamerfan on February 13, 2012, 11:06:28 am
Quote
Cool, I just made an explosive effect for my game yesterday. :)
To anwer your second question. Search your code for "setAdditionalColor()". I suppose, that you are filling your particle with an extra color.
Sorry I am not using any additionalColor() here. What I am doing is attaching muzzle flash jpg to plane object.That is it.In fact my current code is not all using any particle system nor above method.
Also curious to know how did you do that.  :D