GianCarlo 
		
		Junior Member
		 
		Offline 
		
		
		Posts: 78
		 Italy
		
		
		
 
	 
	
		
			
				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;     }   }