What about this one : not real meta-ball but more faster
=> glowx.png must be balls with center highlight and 128*128 size
like this :
- import processing.opengl.*;
- import javax.media.opengl.*;
-
- PGraphicsOpenGL pgl;
- GL gl;
-
- PGraphics ecran1,ecran2,ecran3;
- PImage img1,img2,img3;
- int nbPoint = 150;
- float speed = 1.0;
- Point3D[] tabPoint = new Point3D[nbPoint];
-
- void setup() {
- size(640,480,OPENGL);
- img1 = loadImage("data/glow1.png");
- img2 = loadImage("data/glow2.png");
- img3 = loadImage("data/glow3.png");
- ecran1 = createGraphics(img1.width,img1.height,P2D);
- ecran2 = createGraphics(img2.width,img2.height,P2D);
- ecran3 = createGraphics(img3.width,img3.height,P2D);
- ecran1.background(img1);
- ecran1.mask(img1);
- ecran2.background(img2);
- ecran2.mask(img2);
- ecran3.background(img3);
- ecran3.mask(img3);
- noStroke();
- textureMode(NORMALIZED);
- for(int nb=0; nb<nbPoint; nb++)
- tabPoint[nb] = new Point3D(random(width),
- random(height),
- 0,
- random(3));
- }
- void draw() {
- pgl = (PGraphicsOpenGL) g;
- gl = pgl.beginGL();
- gl.glDisable(GL.GL_DEPTH_TEST);
- gl.glEnable(GL.GL_BLEND);
- gl.glBlendFunc(GL.GL_ONE, GL.GL_ONE);
- pgl.endGL();
- background(0);
- for(int nb=0; nb<nbPoint; nb++) {
- tabPoint[nb].anim();
- tabPoint[nb].drawP();
- }
- }
-
- class Point3D
- {
- PVector point = new PVector();
- float dX,dY;
- int type;
- float angle = random(TWO_PI);
- float delta = TWO_PI/720;
-
Point3D(float x,float y, float z,float type)
{
- point.x = x;
- point.y = y;
- point.z = z;
- dX = random(-speed,speed);
- dY = random(-speed,speed);
- this.type = int(type);
- }
-
- void drawP() {
- PGraphics ecran = null;
- if(type==0)
- ecran = ecran1;
- if(type==1)
- ecran = ecran2;
- if(type==2)
- ecran = ecran3;
- beginShape(QUADS);
- texture(ecran);
- vertex(point.x-ecran.width/2,point.y-ecran.height/2,point.z,0,0);
- vertex(point.x+ecran.width/2,point.y-ecran.height/2,point.z,1,0);
- vertex(point.x+ecran.width/2,point.y+ecran.height/2,point.z,1,1);
- vertex(point.x-ecran.width/2,point.y+ecran.height/2,point.z,0,1);
- endShape(CLOSE);
- }
-
- void anim() {
- point.x = (point.x+dX);
- point.y = (point.y+dY);
- if((point.x>width && dX>0)||(point.x<0 && dX<0))
- dX = -dX;
- if((point.y>height && dY>0)||(point.y<0 && dY<0))
- dY = -dY;
- point.z = 50*sin(angle)+100;
- angle += delta;
- }
- }
(i don't know how to paste code in the right way : i've added carriage return on each line ... <|:-|)
Make something like that :
I'm using this kind of trick
here