Strange Face Behavior from Triangle_Fan
in
Contributed Library Questions
•
1 year ago
I am trying to use triangle fan to cap the ends of the cylinder I am creating. I have simplified the code below to what is causing the problem. For some reason triangle_fan wants to create a "phantom" face. 15 faces are drawn but the count reads 16.
This can be isolated to show the "phantom face" if change line 37 to read: Somehow it is drawing a face from only two points.
- for ( int i = 0; i < 1; i++ ) {
The code below is what I am having problems with. Any help would be greatly appreciated.
- import unlekker.util.*;
- import unlekker.modelbuilder.*;
- import ec.util.*;
- import processing.opengl.*;
- import peasy.*;
- PeasyCam cam;
- UGeometry cylinder;
- void setup () {
- size (800,800, OPENGL);
- cam = new PeasyCam(this,100);
- cam.setMinimumDistance(100);
- cam.setMaximumDistance(500);
- buildCylinder (16, 8.5, 6, 0, 0);
- }
- void draw () {
- rotateX(-.5);
- rotateY(-.5);
- background(180);
- drawCylinder();
- }
- void buildCylinder (int sides, float r, float h, float xOrgin, float yOrgin) {
- float angle = TWO_PI/sides;
- //Draw Bottom Shape
- cylinder = new UGeometry();
- cylinder.beginShape(TRIANGLE_FAN);
- cylinder.vertex(0,0,-h/2);
- for ( int i = 0; i < sides; i++ ) {
- float x = ( cos ( angle * i ) * r ) + xOrgin;
- float y = ( sin ( angle * i ) * r ) + yOrgin;
- cylinder.vertex (x,y,-h/2);
- }
- cylinder.endShape();
- print(cylinder.faceNum+"\n");
- }
- void drawCylinder(){
- cylinder.draw(this);
- //print(cylinder.faceNum+"\n");
- cylinder.calcFaceNormals();
- }
1