15
« 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.
public boolean process(long ticks) {
setVisibility(true);
cTicks = Ticker.getTime() - start;
if (cTicks < 0) {
cTicks = maxTicks;
}
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 .
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();
}
}