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 & HelpSyntax Questions › Help drawing a hemisphere the right way
Page Index Toggle Pages: 1
Help drawing a hemisphere the right way (Read 1302 times)
Help drawing a hemisphere the right way
Oct 29th, 2009, 7:49am
 
Ok, I  post about this before, and in my previous post you can see I am using different methods to achive the hemisphere, this one in particular I got it from a opengl forum (different pices here and there), but for some reason when I translate the code it doesnt render the complete geometry

Code:

import peasy.*;

PeasyCam pCamera;

float radius = 50.0;
float rho = radius;
float factor = 0.3;

PVector[] sphereVertexPoints;
int numSpherePoints;
int i = 0;

void setup() {
 size(320, 240, P3D);
 
 pCamera = new PeasyCam(this, 150);
 
 numSpherePoints = int(TWO_PI / factor) * int(HALF_PI / factor);
 sphereVertexPoints = new PVector[numSpherePoints];
 
 for(float theta = 0.0; theta < TWO_PI; theta += factor) {
   for(float phi = 0.0; phi < HALF_PI; phi += factor) {
     if (i < numSpherePoints) sphereVertexPoints[i++] = getVertex(rho, phi, theta);
   }
 }
}


void draw() {
 background(50);
 
 for (int i = 0; i < numSpherePoints; i++) {
   stroke(255);
   beginShape(POINT);
   vertex(sphereVertexPoints[i].x, sphereVertexPoints[i].y, sphereVertexPoints[i].z);
   endShape();
 }
}


PVector getVertex(float rho, float phi, float theta) {
 PVector v = new PVector();
 v.x = rho * sin(phi) * cos(theta);
 v.y = rho * sin(phi) * sin(theta);
 v.z = rho * cos(phi);
 return v;
}


As usual any help will be much appreciated

Cheers
rS
Re: Help drawing a hemisphere the right way
Reply #1 - Oct 29th, 2009, 8:57am
 
I can't help you much because I haven't dipped yet in 3D in Processing.
But FIY, your last questions aren't really syntax questions, they are questions about 3D, perhaps they will get a more specialized/knowledgeable audience in the OpenGL and 3D Libraries section.
Re: Help drawing a hemisphere the right way
Reply #2 - Oct 29th, 2009, 9:00am
 
Ok for those who are following, I got the full circle

Code:

import peasy.*;

PeasyCam pCamera;

float radius = 50.0;
float rho = radius;
float factor = 0.3;
float x, y, z;

PVector[] sphereVertexPoints;


void setup() {
 size(320, 240, P3D);
 
 pCamera = new PeasyCam(this, 150);
 
}


void draw() {
 background(50);
 stroke(255);
 for(float theta = 0.0; theta < TWO_PI; theta += factor) {
   beginShape(POINTS);
   for(float phi = 0.0; phi < PI; phi += factor) {
     x = rho * sin(phi) * cos(theta);
     y = rho * sin(phi) * sin(theta);
     z = rho * cos(phi);
     vertex(x, y, z);
   }
   endShape();
 }
}


If you need a hemisphere(like I do) just change this line
for(float phi = 0.0; phi < HALF_PI; phi += factor)

Now I need to conver this into a QUAD_STRIP mesh, and then try to apply uv texture, hope I get there some day

Cheers
rS
Re: Help drawing a hemisphere the right way
Reply #3 - Oct 29th, 2009, 9:14am
 
Yes, you are right, I just ask for this to be move

Cheers
rS
Re: Help drawing a hemisphere the right way
Reply #4 - Oct 29th, 2009, 9:20am
 
Another update, I now have a quad_strip mesh, but...

Code:

import peasy.*;

PeasyCam pCamera;

float radius = 50.0;
float rho = radius;
float factor = 0.2;
float x, y, z;

PVector[] sphereVertexPoints;


void setup() {
size(320, 240, P3D);

pCamera = new PeasyCam(this, 150);

}


void draw() {
background(50);
noFill(); stroke(255);

for(float phi = 0.0; phi < HALF_PI; phi += factor) {
beginShape(QUAD_STRIP);
for(float theta = 0.0; theta < TWO_PI; theta += factor) {
x = rho * sin(phi) * cos(theta);
y = rho * sin(phi) * sin(theta);
z = rho * cos(phi);
vertex(x, y, z);

x = rho * sin(phi + factor) * cos(theta);
y = rho * sin(phi + factor) * sin(theta);
z = rho * cos(phi + factor);
vertex(x, y, z);
}
endShape(CLOSE);
}
}


There is a gap, how can I close it?

Cheers
rS
Re: Help drawing a hemisphere the right way
Reply #5 - Oct 29th, 2009, 11:15am
 
Ok the gap issue has been fix, here is the code

Check out the line
float factor = TWO_PI / 20.0;
this way factor is evenly distributed

also the line
for(float theta = 0.0; theta < TWO_PI + factor; theta += factor)

Code:
import peasy.*;

PeasyCam pCamera;

float radius = 50.0;
float rho = radius;
float factor = TWO_PI / 20.0;
float x, y, z;

PVector[] sphereVertexPoints;

void setup() {
 size(320, 240, P3D);
 
 pCamera = new PeasyCam(this, 150);
}


void draw() {
 background(50);
 noFill(); stroke(255);
 
 for(float phi = 0.0; phi < HALF_PI; phi += factor) {
   beginShape(QUAD_STRIP);
   for(float theta = 0.0; theta < TWO_PI + factor; theta += factor) {
     x = rho * sin(phi) * cos(theta);
     z = rho * sin(phi) * sin(theta);
     y = -rho * cos(phi);
     
     vertex(x, y, z);
     
     x = rho * sin(phi + factor) * cos(theta);
     z = rho * sin(phi + factor) * sin(theta);
     y = -rho * cos(phi + factor);
     
     vertex(x, y, z);
   }
   endShape(CLOSE);
 }
}

Hope this helps someone

Cheers
rS
Page Index Toggle Pages: 1