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 & HelpOpenGL and 3D Libraries › filling a shape doesn't seem to work in 3D
Page Index Toggle Pages: 1
filling a shape doesn't seem to work in 3D (Read 1640 times)
filling a shape doesn't seem to work in 3D
May 14th, 2005, 5:30pm
 
I don't understand how to fill a simple polygon in 3D. Here is some code that I thought would work but I've fiddled with it quite a lot and I just can't seem to fill my beloved circle shapes. Do I have to use a texture or what?

While I am at it..can somebody explain how to put a fog/semi-transparent colored flat surface up in 3D?

Thanks to all in advance! Her is the code:

// import processing.opengl.*;
// 3D circle on Sphere class
class sCircle{
float oangle, theta, phi;
sCircle(float _theta, float _phi, float _oangle){
oangle=_oangle%PI;
theta=_theta%PI;
phi=_phi*TWO_PI;
};
sCircle(float centx, float centy, float centz, float ex, float ey, float ez){
float normc=sqrt(centx*centx+centy*centy+centz*centz);
float norme=sqrt(ex*ex+ey*ey+ez*ez);
theta=acos(centz/normc);
phi=atan(centy/centx);
oangle=acos((centx*ex+centy*ey+centz*ez)/(normc*norme));
};
void setAngles(float _theta, float _phi, float _oangle){
oangle=_oangle%PI;
theta=_theta%PI;
phi=_phi*TWO_PI;
};
void setPoints(float centx, float centy, float centz, float ex, float ey, float ez){
float normc=sqrt(centx*centx+centy*centy+centz*centz);
float norme=sqrt(ex*ex+ey*ey+ez*ez);
theta=acos(centz/normc);
phi=atan(centy/centx);
oangle=acos((centx*ex+centy*ey+centz*ez)/(normc*norme));
};
// a simple drawing function using THE MATRIX to orient our circle
void drawCircle(float rScale, int rd, int gr, int bl){
float rad=sin(oangle);
float py=cos(oangle);
float dangle=TWO_PI/250;
float angle=0;
float px,pz;
pushMatrix();
scale(rScale);
rotateZ(phi);
rotateX(theta);
stroke(rd,gr,bl);
fill(rd,gr,bl,255); // ????? WHy doesn't this work?
beginShape(POLYGON);
for(int i=0;i<250;i++){
px=rad*cos(angle);
pz=rad*sin(angle);
vertex(px,py,pz);
angle+=dangle;
};
endShape();
popMatrix();
};
};

// set up a circle
sCircle aCircle;

// get ready to rock
void setup(){
size(800,800,P3D);
background(0);
aCircle=new sCircle(0,0,0);
framerate(3);
}
// let her rip
void draw(){
background(20);
translate(0.5*width,0.5*height,0.25*(width+height));
lights();
ambientLight(200,200,200);

aCircle.setPoints(random(1,10), random(-10,10),random(-10,10),random(-10,10),random(-10,10),random(-10,10));
aCircle.drawCircle(100,(int) random(128,255),(int) random(128,255),(int) random(128,255));

};
Re: filling a shape doesn't seem to work in 3D
Reply #1 - May 14th, 2005, 6:00pm
 
Ok, sorry, I have done a bit more mucking about. It seems that fill does work in all its glory with TRIANGLES  where the surface is a planar figure. Apparently no such assumption is made for poor POLYGON...as I guess it should not..and then some more complex algorithm would be required to attempt a fill... what happens when QUADS has non-coplanar vertices? Does it just stop or subdivide into triangles..which is what I was expecting for the polygon case... Sorry for taking up the board space...
jd
Page Index Toggle Pages: 1