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.
Page Index Toggle Pages: 1
3D Oval?? (Read 1232 times)
3D Oval??
Jun 3rd, 2009, 11:23pm
 
How do I create a 3D Oval, not a perfect sphere? Sorry if this is a beginner question, but I'm kinda new at using Processing. I am trying to do a 3d sketch of some sort of flying insect, maybe a bee, and the body looks pretty lame as just a sphere. Here is what I have got so far

Quote:
import processing.opengl.*;

float r = 25;
float theta = 0;

void setup() {
 size(300,300,OPENGL);
}
 
void draw() {
 background(255);

 float z = r * sin(theta);
 
 noStroke();
 translate(width/2,height/2);
 rotateX(PI*mouseY/height);
 rotateY(PI*mouseX/width);
 lights();

 sphere(20);
 
 
 stroke(255, 102, 0);
 //line(-50, 50, 0, -10, 10, 0);
 //line(-50, -50, 0, -10, -10, 0);
 //line(50, 50, 0, 10, 10, 0);
 //line(50, -50, 0, 10, -10, 0);
 
 stroke(0,0,0);
 bezier(-10, 10, 0, -50, 50, z, -50, -50, z, -10, -10, 0);
 bezier(10, 10, 0, 50, 50, z, 50, -50, z, 10, -10, 0);
 
 theta += 0.05;

}


Re: 3D Oval??
Reply #1 - Jun 4th, 2009, 8:24am
 
You could scale a sphere in one direction (Y is better with the default sphere algorithm in P5). You get a superEllipsoid:

Code:
import processing.opengl.*;

void setup(){
 size(800,400,OPENGL);
}

void draw(){
 background(255);

 //Only for display
 translate(width/2,height/2);
 rotateZ(mouseX/100f);
 rotateX(mouseY/100f);

 //Your Object
 pushMatrix();
 scale(1,2,1);
 sphere(100);
 popMatrix();
}
Re: 3D Oval??
Reply #2 - Jun 4th, 2009, 9:07am
 
Smiley Hey thanks! That was exactly what I was looking for.
Page Index Toggle Pages: 1