We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › 3D particles face camera!
Page Index Toggle Pages: 1
3D particles face camera! (Read 526 times)
3D particles face camera!
Dec 20th, 2007, 8:47pm
 
I am currently working on my first simple particle thing in 3D which get createt through 2D ellipses or images. My problem is that if you rotate the camera, you see that the particles are actually 2D.
In my mind I thought I could simply fix that issue by turning each particle kinda like with the camera so that they always face the camera.

I unfortunately failed due to my bad understanding of math and angles in general. Can anybody help me out?

some code:

PImage b;

int countParticles = 0;
int maxParticles = 100;
Particles[] particle;

void setup(){
 size(screen.width,screen.height, OPENGL);
 hint(ENABLE_OPENGL_4X_SMOOTH);
 hint(DISABLE_ERROR_REPORT);
 frameRate(30);
 colorMode(RGB,255,255,255,100);
 smooth();
 b = loadImage("test.png");
 particle  = new Particles[maxParticles];
}

void draw(){
 background(#000000);
 translate(0, 0, -1000);
 if(countParticles < maxParticles){
 particle[countParticles] = new Particles(countParticles);
 countParticles++;
 }
 for (int i=0; i<countParticles; i++){
 particle[i].render();
 }
 myCamera();
}

void myCamera(){
 float fov = mouseX/float(width) * PI/2;
 float cameraY = height/2.0;
 float cameraZ = cameraY / tan(fov / 2.0);
 beginCamera();
 perspective(fov, float(width) / float(height),cameraZ/10.0 , cameraZ*10.0);
 rotateX(radians(0.5));
 endCamera();
}

class Particles {
  int id;
  float mySize = 30.0;
  float myAlpha = 0;
  float _t= random(width);
 
  Particles(int sentID){
    id = sentID;
  }
 
  void render(){
   float t= (frameCount/200.0)+_t;
   float x=noise(t)*width;
   float y=noise(t,1)*height;
   float z=noise(t,1,2)*width*3;
   float thisAlpha;
   if(myAlpha < 100){
   myAlpha = myAlpha + 1;
   thisAlpha = myAlpha;
   }
   pushMatrix();
   tint(#f1248e, thisAlpha);
   translate(x,y,z);
   rotateX(-radians(0.5));
   image(b, round(-mySize/2.0), round(-mySize/2.0) , mySize, mySize);
   popMatrix();
  }

}


as you can see I rotate the camera X radians(0.5) each frame. I hoped rotating each particle -radians(0.5) would be enough but it didnt work at all. I simply need a point to start from since I am really stuck with this one.

Re: 3D particles face camera!
Reply #1 - Dec 21st, 2007, 10:39am
 
nobody?
Page Index Toggle Pages: 1