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 › How it feels to be the sun: OPENGL/physics probs
Page Index Toggle Pages: 1
How it feels to be the sun: OPENGL/physics probs (Read 445 times)
How it feels to be the sun: OPENGL/physics probs
Aug 1st, 2008, 3:47pm
 
Hello hello

I've been adapting the physics engine example from http://www.cs.princeton.edu/~traer/cloud/ (My code pasted at the end of this.) I have a couple of questions...

1. On publishing, I don't seem to be able to get an OPENGL sketch running. P3D fine, OPENGL no. OPENGL works fine for other sketches in my browser e.g.

http://www.hardcorepawn.com/galaxy/

... but not for my lil ol sketch. Is this not working for others? -

http://www.personal.leeds.ac.uk/~gy06do/processing/howthesunfeels2/applet/

(Here's the P3D one: works, but considerably slower. Note, code is messier for this one too...)

http://www.personal.leeds.ac.uk/~gy06do/processing/howthesunfeels/

2. This is perhaps one to ask over on the libraries forum, but I'll try here:

The physics engine does something odd. I load all an array of particles in, like the original example:

physics.makeAttraction( mouse, others[i], 10000, 50 );

Later, a mousekey press toggles the following lines for each particle -

physics.makeAttraction( mouse, others[i], 10000, 50 );  
physics.makeAttraction( mouse, others[i], -10000, -50 );

Thing is - a) the second line shouldn't do what it does. And when it toggles back to attracting, it doesn't do what it did originally, despite being exactly the same line in exactly the same for loop. It does do something *interesting* - but why is it different? Any ideas? (Worth trying: when toggling back to attract, particles only get a certain distance - 50 presumably - from the attraction point. This is a change of behaviour from the starting makeAttraction. Why?)

Any thoughts? Bye for now,

Dan

===

OPENGL version:

Mouseclick toggles attract repel
Spacebar toggles plane of movement from x,y to x,z
H toggles trail length

===

import damkjer.ocd.*;
import processing.opengl.*;
import traer.physics.*;


Particle mouse, b, c;
Particle[] others;
ParticleSystem physics;

Camera camera1;

int[] randomCol;

//3d mousepositions
int mouseXx, mouseYy, mouseZz;

//for getting 3d distance
int dx, dy, dz, distance;

boolean ting, attr, hallucinate;


void setup()
{
 size( 500, 500, OPENGL );
 //framerate( 24 );
 //cursor( CROSS );
 noCursor();
 camera1 = new Camera(this, 0, 0, 500);

 


 physics = new ParticleSystem( 0, 0.1 );
 mouse = physics.makeParticle();
 
   mouse.makeFixed();
 mouse.moveTo(0,0,0);

 others = new Particle[4000];
 for ( int i = 0; i < others.length; i++ )
 {
   others[i] = physics.makeParticle( 1.0, random( -width, width ), random( -height, height ), random( -height, height ) );
   //others[i] = physics.makeParticle ( 1.0, mouse.position().x()+random(0,100), mouse.position().y(), mouse.position().z() );
   physics.makeAttraction( mouse, others[i], 10000, 50 );
 }



 hint(DISABLE_DEPTH_TEST);


}

void draw() {

 
 if(!hallucinate) {
   fill(0,40);
   rect(-width,-height,width*2,height*2);
 }
 else {
   fill(0,10);
   rect(-width,-height,width*2,height*2);
 }



 physics.tick();

 //stick a sphere where the 'mouse' is -
 translate(mouseXx, mouseYy, mouseZz);
 fill(255,0,0);
 noStroke();
 sphere(10);
 translate(-mouseXx, -mouseYy, -mouseZz);


 for ( int i = 0; i < others.length; i++ )
 {
   Particle p = others[i];
   
   //Make the colour change depending on distance to mouse
   dx = int(mouse.position().x() - p.position().x());
   dy = int(mouse.position().y() - p.position().y());
   dz = int(mouse.position().z() - p.position().z());
   distance = int(sqrt(dx*dx + dy*dy + dz*dz));

   //So what do we do with that number? Well
   //Make it 0 to 255 where anything over 255 is 255
   //Make 0 red and 255 green
   //distance = +distance; //make positive
   if(distance > 510) {
     distance = 510;
   }
   distance /= 2;

   fill(255-distance, distance, 0, 200  );

   //fill(randomCol[i],randomCol[i],255-randomCol[i],128);
   //box(20);
   //translate( - p.position().x(), - p.position().y(), - p.position().z() );
   //strokeWeight(4);
   //stroke(255,255,255);
   beginShape(TRIANGLES);
   vertex(p.position().x(),p.position().y(),p.position().z());
   vertex(p.position().x()+5,p.position().y()+5,p.position().z());
   vertex(p.position().x(),p.position().y()+5,p.position().z()+5);
   endShape();

 }

 
 //camera1.circle(radians(0.25));

 
 camera1.tumble(radians((mouseX - pmouseX)/25f), radians(mouseY - pmouseY)/30f);

 camera1.feed();




}

void mouseMoved() {

 mouseXx = (mouseX*2) - width;

 if(ting) {
   mouseZz = (mouseY*2) - height;
 }
 else
 {
   mouseYy = (mouseY*2) - height;
 }

 mouse.moveTo(mouseXx, mouseYy, mouseZz);

}

void keyPressed() {

 if(key==' ') {

   if (ting) {
     ting = false;
   }
   else {
     ting = true;
   }

 }
 else if (key =='h' || key =='H') {

   if(hallucinate) {
     hallucinate = false;
   }
   else {
     hallucinate = true;
   }

 }

}

void mousePressed() {

 if (attr) {

   for ( int i = 0; i < others.length; i++ ) {
     
     physics.makeAttraction( mouse, others[i], 10000, 50 );  
     //others[i].setStrength(10000);

   }

   attr = false;
 }
 else {

   for ( int i = 0; i < others.length; i++ ) {

     physics.makeAttraction( mouse, others[i], -10000, -50 );

   }

   attr = true;
 }

}
Page Index Toggle Pages: 1