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.
IndexDiscussionExhibition › creating terrain around a sphere
Page Index Toggle Pages: 1
creating terrain around a sphere (Read 1851 times)
creating terrain around a sphere
Nov 24th, 2009, 6:03am
 
Hello everyone,
if you have traer.physics lib you may have a look at my code:
I would try to get a terrain starting from what it seems to me the easiest way to find/use some spherical coordinates.
As you will see, a continuous curveVertex will form the shape of a sphere. Using attractors and springs i got a nice 'live' series of thin lines.

It is ok for me, but i would like to get a terrain and use such points as the vertex of a shape made of 5 vertices (the highest is the one i already have, and the other 4 sould be placed below and around -/+10 let's say pixels around the top vertex).
I have no clue on how to made the calc, is there any of you guys that can help me? At the end i should get a pulsing terrain (sort-of)
Thanks in advance
GianCarlo M



import processing.opengl.*;
import javax.media.opengl.*;
import traer.physics.*;


ParticleSystem physics;

Particle[] p;
Particle cUni, aUni;
int NUM_PARTICLES = 3000;

float rotationX;
float rotationY;
float velocityX;
float velocityY;
float radius = 150;
float zCam = 0;

float theta = 0;
float x,y,z = 0;
 
void setup()
{
 size(800,600,OPENGL);
 lights();
 physics = new ParticleSystem(0.0, 0.05);
 cUni = physics.makeParticle(1, 0,0,0);
 aUni = physics.makeParticle(1, 0,0,0);
 cUni.makeFixed();
 aUni.makeFixed();
 
 p = new Particle[NUM_PARTICLES];  
 rotationX = 0;
 rotationY = 0;
 velocityX = 0;
 velocityY = 0;  
  for(int i = 0; i < NUM_PARTICLES; i++)
   {
     float theta = i/TWO_PI;
     float u = map(i, 0, NUM_PARTICLES, -1, 1); // spyro
     x = radius*cos(theta)*sqrt(1-(u*u));
     y = radius*sin(theta)*sqrt(1-(u*u));
     z = u*radius;
     p[i] = physics.makeParticle(random(1.0, 10.0), x, y, z);  
     physics.makeSpring( cUni, p[i], 0.01, 0.05, 170 );
     physics.makeAttraction( p[i], cUni, 300, 150 );
     
   }
}

void draw()
{
 background(0);
 physics.tick();
 rotationX += velocityX;
 rotationY += velocityY;
 velocityX *= 0.95;
 velocityY *= 0.95;
 
 pushMatrix();
 translate(width/2, height/2, zCam);
 rotateX(radians(-rotationX));
 rotateY(radians(270 - rotationY));
 noFill();
 
 stroke(255, 100);
 beginShape();  
   curveVertex(p[0].position().x(),p[0].position().y(),p[0].position().z());  
   for(int i = 1; i < NUM_PARTICLES-1; i++)
   {
   curveVertex(p[i].position().x(), p[i].position().y(), p[i].position().z());
   }
   curveVertex(p[p.length-1].position().x(),p[p.length-1].position().y(),p[p.length-1].position().z());
 endShape();




 popMatrix();
 

 if(mousePressed){
   velocityX += (mouseY-pmouseY) * 0.05;
   velocityY -= (mouseX-pmouseX) * 0.05;
   
 }
}



void keyPressed()
{
   switch(key) {
   case 'i':
   zCam = 400;
       break;
   
   case 'o':
   zCam = 00;
       break;
   
   case 's':
   saveFrame();
       break;
   }  
}
Re: creating terrain around a sphere
Reply #1 - Nov 24th, 2009, 7:52am
 
Hi GianCarlo, nice work on the sphere, I really like the way the line morph. I did post about uv mapping about a month ago, it may give you a hint, check it ou here http://processing.org/discourse/yabb2/num_1256759256.html#5

Hope that helps
rS
Re: creating terrain around a sphere
Reply #2 - Nov 25th, 2009, 5:39am
 
Hi Ricardo,
it should help, thank you very much! I'll study the code in deep today.
In the meantime,  i want to show you a couple of imegaes taken with a coloured version of the 3dlinemorph:

...
...

Re: creating terrain around a sphere
Reply #3 - Nov 25th, 2009, 5:58am
 
Nice! is there an online verison to play with?

rS
Re: creating terrain around a sphere
Reply #4 - Nov 25th, 2009, 6:02am
 
here it is:
http://www.openprocessing.org/visuals/?visualID=6219

working on the 'terrain' version Wink
Re: creating terrain around a sphere
Reply #5 - Nov 25th, 2009, 6:24am
 
Thanks but I ment an online sketch of the color version

rS
Re: creating terrain around a sphere
Reply #6 - Nov 25th, 2009, 6:47am
 
http://www.openprocessing.org/visuals/?visualID=6221
I've added a slider wich modifies the attractor's mass. Playing with the mass of the attractor, the line morph differently.
Have fun.
Now, got to work on 'terrain around a sphere'.
Re: creating terrain around a sphere
Reply #7 - Nov 29th, 2009, 7:43pm
 
Here is a pretty decent example I found on www.openprocessing.org
...
http://openprocessing.org/visuals/?visualID=6262

Re: creating terrain around a sphere
Reply #8 - Nov 30th, 2009, 12:20am
 
That's exactly what i was trying to do!
Damn he did it first  Tongue
Thank you Andrew.
GC
Page Index Toggle Pages: 1