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 3D umbrella, dome, or hemisphere
Page Index Toggle Pages: 1
Help drawing 3D umbrella, dome, or hemisphere (Read 3320 times)
Help drawing 3D umbrella, dome, or hemisphere
Oct 8th, 2009, 3:34am
 
Hi, I am trying to draw a 3D umbrella but I am not sure if this is the best way to do it

Here is what I got so far
Code:
float roty = 0.0;

void setup() {
 size(320, 240, P3D);
 //smooth();
 noStroke();
}


void draw() {
 background(0);
   
 noStroke();
 fill(255);
 
 pushMatrix();
   translate(width * 0.5, height * 0.5, 110.0);
   rotateY(roty);
   beginShape();
     vertex(0.0, 0.0, 0.0);
     bezierVertex(10.0, 10.0, 30.0, 10.0, 30.0, 30.0, 10.0, 30.0, 30.0);
     vertex(-10.0, 30.0, 30.0);
     bezierVertex(-10.0, 30.0, 30.0, -10.0, 10.0, 30.0, 0.0, 0.0, 0.0);
   endShape();
 popMatrix();
 roty += 0.02;
}

So once I get that section draw properly, I will for-loop and draw the rest, this is the firt time I use bezierVertex, once I get use to how they draw, I will change those numbers to variables

What do you think? is there a better way to do this?

Cheers
rS
Re: Help drawing 3D umbrella, dome, or hemisphere
Reply #1 - Oct 8th, 2009, 9:05am
 
Ok, I got a very raw umbrella with vertex points, now I need to mix, the previous code and this one, I hope that works; bezierVertex here we go! wish me luck...

Code:
int numSegments = 18;
float Ra = 60.0;  // aperture / radius
float Ha = 40.0;  // height
float angleSpace = TWO_PI / numSegments;
float offsetX, offsetY;
float rot = 0.0;
float[][] points = new float[numSegments][2];


void setup() {
 size(320, 240, P3D);
 
 offsetX = width * 0.5;
 offsetY = height * 0.5;
 
 for (int i = 0; i < numSegments; i++) {
   float x = cos(i * angleSpace) * Ra;
   float y = sin(i * angleSpace) * Ra;
   points[i][0] = x;
   points[i][1] = y;
 }
}

void draw() {
 background(0);
 noFill();
 
 pushMatrix();
 // align the umbrella in the center
 translate(offsetX, offsetY);
 // perform rotation just to appreciate the geometry
 rotateY(rot);
 rotateZ(rot);
 
 // draw the umbrella
 for (int i = 0; i < numSegments - 1; i++) {
   stroke(0, 127, 255);
   umbrellaSegment(points[i][0], points[i][1], points[i + 1][0], points[i + 1][1], Ha);
 }
 
 // draw last segment of the umbrella
 stroke(0, 200, 255);
 umbrellaSegment(points[numSegments - 1][0], points[numSegments - 1][1], points[0][0], points[0][1], Ha);
 
 popMatrix();
 
 rot += 0.01;
}

void umbrellaSegment(float x1, float y1, float x2, float y2, float h) {
 beginShape();
 vertex(0.0, 0.0, h);
 vertex(x1, y1, 0.0);
 vertex(x2, y2, 0.0);
 endShape(CLOSE);
}

Cheers
rS
Re: Help drawing 3D umbrella, dome, or hemisphere
Reply #2 - Oct 8th, 2009, 10:58am
 
Ok, addingBezierVertex wasnt that painfull... YET! I am having problems rendering the solid shape, wireframe looks ok, but I am not sure why it does not render the fill as it shoud be.

Here is the code Code:
int numSegments = 18;
float Ra = 150.0;  // aperture / radius
float Ha = 100.0;  // height
float angleSpace = TWO_PI / numSegments;
float offsetX, offsetY;
float rot = 0.0;
float[][] points = new float[numSegments][2];


void setup() {
 size(640, 480, P3D);

 offsetX = width * 0.5;
 offsetY = height * 0.5;

 for (int i = 0; i < numSegments; i++) {
   float x = cos(i * angleSpace) * Ra;
   float y = sin(i * angleSpace) * Ra;
   points[i][0] = x;
   points[i][1] = y;
 }
}

void draw() {
 background(0);
 //noFill();

 directionalLight(51, 102, 126, -100, 100, 0);
 directionalLight(51, 102, 126, 100, -200, 0);

 pushMatrix();
 // align the umbrella in the center
 translate(offsetX, offsetY);
 // perform rotation just to appreciate the geometry
 rotateY(rot);
 // rotate the umbrella 90 degrees, so it stands normally
 rotateX(HALF_PI + 0.1);

 // draw the umbrella
 for (int i = 0; i < numSegments - 1; i++) {
   umbrellaSegment(points[i][0], points[i][1], points[i + 1][0], points[i + 1][1], Ha, true);
 }
 // draw last segment of the umbrella
 umbrellaSegment(points[numSegments - 1][0], points[numSegments - 1][1], points[0][0], points[0][1], Ha, true);

 popMatrix();

 rot += 0.015;
}

void umbrellaSegment(float x1, float y1, float x2, float y2, float h, boolean debugrender) {

 if (debugrender == true) {
   stroke(0, 127, 255);
   noFill();
 }
 else {
   noStroke();
   fill(0, 127, 255, 255);
 }
 beginShape();
 // draw absolute
 //vertex(0.0, 0.0, h);
 //vertex(x1, y1, 0.0);
 //vertex(x2, y2, 0.0);
 
 // draw smooth
 vertex(0.0, 0.0, h);
 bezierVertex(x1, y1, h * 0.5, x1, y1, 0.0, x1, y1, 0.0);
 vertex(x2, y2, 0.0);
 bezierVertex(x2, y2, 0.0, x2, y2, h * 0.5, 0.0, 0.0, h);
 endShape(CLOSE);
}

Change the last parameter of the umbrellaSegment method to false to view the fill deformation

Any ideas why, what am I missing?

Cheers
rS
Re: Help drawing 3D umbrella, dome, or hemisphere
Reply #3 - Oct 8th, 2009, 2:54pm
 
Are you sure that Processing supports 3D curved surfaces?  From my - admittedly limited - understanding there's a good reason most 3d engines break 3d shapes up into flat triangular surfaces...
Re: Help drawing 3D umbrella, dome, or hemisphere
Reply #4 - Oct 8th, 2009, 3:34pm
 
I dont know, but it looks like there is a bezier control point miss place, if you are correct I will be in a world of s**t private pile!

Cheers
rS
Re: Help drawing 3D umbrella, dome, or hemisphere
Reply #5 - Oct 8th, 2009, 3:48pm
 
Maybe that helps : http://local.wasp.uwa.edu.au/~pbourke/geometry/prolatespheroid/
Re: Help drawing 3D umbrella, dome, or hemisphere
Reply #6 - Oct 8th, 2009, 7:31pm
 
Forget my last post.
looking at your code i had a stupid idea and thought i give it a try.
i am not sure if it is useful to do it this way. but looks good.

What i did was taking your vertexes , used beziercurve to get different steps and connected them by a triangle strip.

What do you think ?
Oh and like you see i added some moving/morphing.


Btw, got your email and will answer it tomorrow.


Code:
int numSegments = 18;
float Ra = 150.0; // aperture / radius
float Ha = 100.0; // height
float angleSpace = TWO_PI / numSegments;
float offsetX, offsetY;
float rot = 0.0;
float[][] points = new float[numSegments][2];


void setup() {
size(640, 480, P3D);

offsetX = width * 0.5;
offsetY = height * 0.65;


}

void draw() {
background(0);
//noFill();
Ha = 100+((1+sin(frameCount/20.0))/2.0)*200;
Ra = 60+((1+cos(frameCount/20.0))/2.0)*140;
println(Ha);

for (int i = 0; i < numSegments; i++) {
float x = cos(i * angleSpace) * Ra;
float y = sin(i * angleSpace) * Ra;
points[i][0] = x;
points[i][1] = y;
}

directionalLight(51, 102, 126, -100, 100, 0);
directionalLight(51, 102, 126, 100, -200, 0);

pushMatrix();
// align the umbrella in the center
translate(offsetX, offsetY);
// perform rotation just to appreciate the geometry
rotateY(rot);
// rotate the umbrella 90 degrees, so it stands normally
rotateX(HALF_PI + 0.1);

// draw the umbrella
for (int i = 0; i < numSegments - 1; i++) {
umbrellaSegment(points[i][0], points[i][1], points[i + 1][0], points[i + 1][1], Ha, true);
}
// draw last segment of the umbrella
umbrellaSegment(points[numSegments - 1][0], points[numSegments - 1][1], points[0][0], points[0][1], Ha, true);

popMatrix();

rot += 0.015;
}

void umbrellaSegment(float x1, float y1, float x2, float y2, float h, boolean debugrender) {

if (debugrender == true) {
stroke(0, 127, 255);
noFill();
}
else {
noStroke();
fill(0, 127, 255, 255);
}


for (int i = 0; i <= 6; i++) {
float t = i / 6.0;
float x =bezierPoint(x1, x1, x1, 0, t);
float y =bezierPoint(y1, y1, y1, 0, t);
float z =bezierPoint(0, h * 0.5, h*0.4, h, t);
bezier(x1, y1, 0 ,x1, y1, h * 0.5, x1, y1, h*0.4 ,0, 0, h );

pushMatrix();
translate(x,y,z);
box(3);
popMatrix();
}

fill(255 );
stroke(0, 127, 255,100);
beginShape(TRIANGLE_STRIP);

int steps = 10;

for (int i = 0; i <= steps; i++) {
float t = i / float(steps) ;
float x =bezierPoint(x1, x1, x1, 0, t);
float y =bezierPoint(y1, y1, y1, 0, t);
float z =bezierPoint(0, h * 0.5, h*0.4, h, t);

float bx =bezierPoint(x2, x2, x2, 0, t);
float by =bezierPoint(y2, y2, y2, 0, t);
float bz =bezierPoint(0, h * 0.5, h*0.4, h, t);

vertex(x,y,z);
vertex(bx,by,bz);
}

endShape(CLOSE);
}

Re: Help drawing 3D umbrella, dome, or hemisphere
Reply #7 - Oct 9th, 2009, 1:08am
 
Hi Cedric, that is just perfect!

I will play with this over the weekend, and let you know the progress

Thanks to Cedric and blindfish again!
rS
Re: Help drawing 3D umbrella, dome, or hemisphere
Reply #8 - Oct 11th, 2009, 10:57pm
 
Cedric-

Rad.
Re: Help drawing 3D umbrella, dome, or hemisphere
Reply #9 - Oct 11th, 2009, 11:58pm
 
rad ?
Page Index Toggle Pages: 1