john
YaBB Newbies
Offline
Posts: 11
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)); };