FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
   Programs
(Moderators: fry, REAS)
   texture on a sphere
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: texture on a sphere  (Read 457 times)
tobt


texture on a sphere
« on: Jul 20th, 2004, 5:21pm »

i would like to map a texture to a sphere.  
 
in one thread i read about loading an image and place it with texture(theimage) in the beginShape, endShape term.
 
in another thread i read about to draw a sphere by using the following method. (from toxi.)
 
but how can i put these two elements together?
(How works the texture() - there is no reference)
 
thanks, tobt.
 
 
 
CODE:
 
 void xsphere(float r) {  
  if (g.sphere_detail == 0) {  
  sphereDetail(30);  
  }  
  int sd=g.sphere_detail;  
  float[] sx=g.sphereX;  
  float[] sy=g.sphereY;  
  float[] sz=g.sphereZ;  
  int v1,v2;  
  push();  
  // scale(r); // REMOVED!!!  
 
  // 1st ring from south pole  
  beginShape(TRIANGLE_STRIP);  
  for (int i = 0; i <= sd; i++) {  
  v2 = i % sd;  
  vertex(0, -r, 0);  
  vertex(sx[v2]*r, sy[v2]*r, sz[v2]*r);  
  }  
  endShape();  
 
  // middle rings  
  int voff = 0;  
  for(int i = 2; i < sd; i++) {  
  voff += sd;  
  beginShape(TRIANGLE_STRIP);  
  for (int j = 0; j <= sd; j++) {  
 v1 = voff - sd + j % sd;  
 v2 = voff + j % sd;  
 vertex(sx[v1]*r, sy[v1]*r, sz[v1]*r);  
 vertex(sx[v2]*r, sy[v2]*r, sz[v2]*r);  
  }  
  endShape();  
  }  
 
  // add the northern cap  
  beginShape(TRIANGLE_STRIP);  
  for (int i = 0; i <= sd; i++) {  
  v2 = voff + i % sd;  
  vertex(0, r, 0);  
  vertex(sx[v2]*r, sy[v2]*r, sz[v2]*r);  
  }  
  endShape();  
  pop();  
 }
}
« Last Edit: Jul 20th, 2004, 5:21pm by tobt »  
Koenie

170825270170825270koeniedesign WWW Email
Re: texture on a sphere
« Reply #1 on: Jul 20th, 2004, 9:32pm »

Check out this thread: http://processing.org/discourse/yabb/board_Syntax_action_displa_y_num_1067005325.html
 
I made a textured sphere thing, you can find it at the bottom of the thread.
 
Koenie
 

http://koeniedesign.com
Pages: 1 

« Previous topic | Next topic »