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
curveVertex problem (Read 1017 times)
curveVertex problem
Jan 7th, 2006, 9:05pm
 
OK, I'm quite a newbie here but heck, I thought I should be able to build a simple 3D poly-curve.  But I apparently don't know how to use curveVertex in 3D correctly.

This program draws a box and two planar polygons.  To the right initially you see a triangle, and I was hoping to have to the left a half-circle.  Nothing shows up there.  If I replace the curveVertex calls with simple vertex calls, I get a triangle to the left.  So the code is not completely nuts!

Am I using the curveVertex primitive incorrectly?  Or is there a problem with it in 3D?

Thanks!!

Owen

import processing.opengl.*;

void setup() {
 size(512, 512, OPENGL); // OPENGL or P3D
 framerate(15);
 drawScene(0,0);
}
void draw() {
 if (mousePressed) {
   drawScene((mouseY - height/2)*.01,(mouseX - width/2)*.01);
 }
}

void drawScene(float xrot, float yrot) {
 background(128);
 translate(width/2, height/2);
 scale (width/4, width/4, width/4);
 rotateX(xrot);
 rotateY(yrot);
 
 box(.5);

 beginShape(POLYGON);
 vertex(0, 1, 0);
 vertex(1, 0, 0);
 vertex(0, -1, 0);
 endShape();

 beginShape(POLYGON);
 curveVertex(0, 1, 0);
 curveVertex(-1, 0, 0);
 curveVertex(0, -1, 0);
 endShape();
}
Re: curveVertex problem
Reply #1 - Jan 9th, 2006, 7:57pm
 
curve/curveVertex generates a spline curve, based on a  catmull-rom implementation. This just means that each a point on the curve is determined by 2 control points, one that comes before and one that comes after it. In your sketch only your middle vertex has control points on either side. Since you're generating a closed a form, I just reused the ending and starting points, which allowed your curve to go through all your points, which is another characteristic of catmull-rom curves.
Also, You can specify the tightness of the curve with curveTightness().
Code:

curveTightness(-.25);
beginShape(POLYGON);
curveVertex(0, -1, 0);
curveVertex(0, 1, 0);
curveVertex(-1, 0, 0);
curveVertex(0, -1, 0);
curveVertex(0, 1, 0);
endShape();


I hope this helps.
ira
Re: curveVertex problem
Reply #2 - Jan 12th, 2006, 7:28pm
 
Wow, thanks!

Owen
Page Index Toggle Pages: 1