Questions concerning transparent panels / particle systems

Started by manumoi, February 20, 2006, 09:08:26 PM

Previous topic - Next topic

manumoi

Hello everybody :P,

I would like to know what is the correct way people use to do transparent option/text panels (with or without AWTGLRENDERER). Do you use awt panels with an opaque color? Do you blit everything? Is it performance killing?
(if you have some code to show, that would be appreciated).

And another question for Egon, I ve seen that you did a particle system with JPCT and you put it in demos. I m not familiar with that concept but I may be interested in using such a thing. Is it possible to see the code if it isn t lost? If not, do you have good resources on how to design it with java? Concerning the particle, do each of them are Object3D? and again, have you made some test concerning performance?

Thanks for all,

Manu

EgonOlsen

Quote from: "manumoi"And another question for Egon, I ve seen that you did a particle system with JPCT and you put it in demos. I m not familiar with that concept but I may be interested in using such a thing. Is it possible to see the code if it isn t lost? If not, do you have good resources on how to design it with java? Concerning the particle, do each of them are Object3D? and again, have you made some test concerning performance?
The basics are quite simple. Each particle has a position and a velocity and its influenced by additional forces like gravity, wind...whatever you implement. Here's some hacky code i've written to play around with it. Each Particle IS an Object3D in this example. To do it different may be possible but complicated. Performance is ok IMHO...not breathtaking, but suitable for simpler particle systems.

import java.awt.*;
import com.threed.jpct.*;
import org.lwjgl.input.*;

public class Particles {

 private final static int PARTICLE_COUNT = 40;
 static Object3D box = null;

 public static void main(String[] args) {
   Config.maxPolysVisible = 10000;
   Config.saveMemory = true;
   Config.polygonBufferSize = 10;
   Config.glVertexArrays = true;
   Config.glTrilinear = false;

   FrameBuffer buffer = new FrameBuffer(800, 600, FrameBuffer.SAMPLINGMODE_NORMAL);
   buffer.disableRenderer(IRenderer.RENDERER_SOFTWARE);
   buffer.enableRenderer(IRenderer.RENDERER_OPENGL);

   World world = new World();
   world.setAmbientLight(255, 255, 255);
   world.getCamera().moveCamera(new SimpleVector(0, -7, -7).normalize(), 70);
   box = Primitives.getBox(1, 2);
   world.addObject(box);
   world.getLights().setRGBScale(Lights.RGB_SCALE_2X);

   TextureManager.getInstance().addTexture("ring", new Texture("envmap.jpg"));
   TextureManager.getInstance().addTexture("fire", new Texture("envmap2.jpg"));

   world.getCamera().lookAt(SimpleVector.ORIGIN);

   ParticleManager pm = new ParticleManager();
   long t = System.currentTimeMillis();

   int fps = 0;
   float cnt = 0;
   long start = System.currentTimeMillis();
   int cngcnt = 0;
   try {
     Keyboard.create();
     Mouse.create();
     boolean exit = false;
     while (!exit) {
       if (System.currentTimeMillis() - t > 30) {

         int x = 800 - Mouse.getX();
         int y = 600 - Mouse.getY();

         cngcnt++;
         if (Mouse.isButtonDown(0) && cngcnt > 10) {
           pm.cycleTexture();
           cngcnt = 0;
         }

         SimpleVector org = new SimpleVector( (400 - x) / 10, 0, (300 - y) / 10);
         box.setOrigin(org);

         Keyboard.poll();
         if (Keyboard.next()) {
           if (Keyboard.getEventKey() == Keyboard.KEY_ESCAPE) {
             exit = true;
           }
         }
         for (int i = 0; i < PARTICLE_COUNT; i++) {
           pm.addParticle(world, org, new SimpleVector(1 - Math.random() * 2,  -1.4 - (Math.random() / 2f), 1 - Math.random() * 2));

         }
         cnt += 0.04;

         pm.move(1);
         t = System.currentTimeMillis();
       }
       buffer.clear();
       world.renderScene(buffer);
       world.draw(buffer);
       buffer.update();
       buffer.display(null);
       fps++;
       if (System.currentTimeMillis() - start >= 1000) {
         start = System.currentTimeMillis();
         System.out.println(fps + "fps" + "/" + world.getSize());
         fps = 0;
       }
     }
     Keyboard.destroy();
     Mouse.destroy();
   }
   catch (Exception e) {}
 }
}

class ParticleManager {
 private Particle[] parts = null;
 private int count = 0;
 private String ct = "ring";
 private int pos = 0;
 private String[] ts = {"ring", "fire"};

 ParticleManager() {
   parts = new Particle[5000];
 }

 void cycleTexture() {
   pos++;
   pos %= 2;
   ct = ts[pos];
 }

 void move(int ticks) {
   for (int i = 0; i < count; i++) {
     Particle pp = parts[i];
     if (pp.getVisibility()) {
       pp.move(ticks);
     }
   }
 }

 void addParticle(World w, SimpleVector pos, SimpleVector vel) {
   Particle p = getParticle(w);
   p.setTranslationMatrix(new Matrix());
   p.setOrigin(pos);
   p.setVelocity(vel);
   p.reset();
   p.setTexture(ct);
 }

 private Particle getParticle(World w) {
   for (int i = 0; i < count; i++) {
     Particle pp = parts[i];
     if (!pp.getVisibility()) {
       pp.setVisibility(Object3D.OBJ_VISIBLE);
       return pp;
     }
   }
   Particle p = new Particle();
   w.addObject(p);
   parts[count] = p;
   count++;
   return p;
 }
}

class Particle extends Object3D {

 private SimpleVector vel = new SimpleVector();
 private long time = 0;
 private long maxTime = 2500;
 private static Object3D PLANE = null;
 private static final SimpleVector GRAV = new SimpleVector(0, 0.1, 0);

 static {
   Config.saveMemory = true;
   PLANE = new Object3D(1);
   PLANE.addTriangle(new SimpleVector( -0.5, -0.5, 0), 0, 0,
                     new SimpleVector(0.5, -0.5, 0), 1, 0,
                     new SimpleVector(0.5, 0.5, 0), 1, 1);
   PLANE.setTexture("ring");
   PLANE.build();
 }

 Particle() {
   super(PLANE);
   setMesh(PLANE.getMesh());
   setBillboarding(Object3D.BILLBOARDING_ENABLED);
   setVisibility(Object3D.OBJ_VISIBLE);
   setCulling(Object3D.CULLING_DISABLED);
   setTransparency(0);
   setAdditionalColor(Color.white);
   setLighting(Object3D.LIGHTING_NO_LIGHTS);
   enableLazyTransformations();
   reset();
 }

 void setVelocity(SimpleVector vel) {
   this.vel.set(vel);
 }

 void reset() {
   time = System.currentTimeMillis();
   getTranslationMatrix().setIdentity();
 }

 void move(int ticks) {
   if (getVisibility()) {
     for (int i = 0; i < ticks; i++) {
       vel.add(GRAV);
       translate(vel);
     }
     if (System.currentTimeMillis() - time > maxTime) {
       reset();
       setVisibility(Object3D.OBJ_INVISIBLE);
     }
   }
 }
}

manumoi

Thanks Egon, your help is very appreciated. I will let you know if I do something interesting

gamerfan

Can I get the textures used in this example for my application? Can you please upload those images?

EgonOlsen

Well, this thread is 4 years+ old. I've no idea about the textures. Because my particle "systems" tend to use single polygons per object and i don't apply any special mapping, i'm usually using a texture where the actual content is located in the upper right half. The rest of the texture is empty.

gamerfan

@Egon, I have envmap.jpg  that is used in robombs.But  there is no envmap2.jpg. So my clarification is can I get the same effect if I use a single texture( ie envmap.jpg)?

gamerfan

Quick update.Egon, I have used my texture for testing particle.It is working.But it does not provide me the exact feeling of an 'Explosion', though it is emitting so many particles.I updated the size of the triangle.But still not working.I want this one to be used for my fire explosion.What are the parameters I need to modify here so as to make a complete explosion effect?

EgonOlsen

I'm not sure if that will ever look like an explosion. You can try to increase velocity and decrease GRAV and see if that helps.