glenn
Junior Member
Offline
Posts: 86
Re: CurVertex():similar tech as curvePoints(
Reply #3 - Jul 16th , 2008, 10:42am
this is a bit if a crude extraction from the program im working on, sorry its a bit messy, but hopefully you'll get the idea. i use a particle system to create a flowing list of points, then iterate through the list using below loop to create a tri strip, which has a triwidth var to control width. Particle p = physics.makeParticle( 1.0, xvel, yvel, 0 ); int num=physics.numberOfParticles()-1; ptest=p; previous=last; //first 2 tangents float p1x1=previous.position().x(); float p1y1=previous.position().y(); float p1x2=last.position().x(); float p1y2=last.position().y(); //second 2 tangents float p2x1=last.position().x(); float p2y1=last.position().y(); float p2x2=ptest.position().x(); float p2y2=ptest.position().y(); //start your loop here beginShape(TRIANGLE_STRIP); Particle ptest = physics.getParticle( i ); //***************** float p1x1,p1y1,p1x2,p1y2,p1x3,p1y3,p1x4,p1y4,p2x1,p2y1,p2x2,p2y2,p2x3,p2y3,p2x4,p2y4; float triwidth; float ang; //***************** //first 2 tangents p1x1=previous.position().x(); p1y1=previous.position().y(); p1x2=last.position().x(); p1y2=last.position().y(); //second 2 tangents p2x1=last.position().x(); p2y1=last.position().y(); p2x2=ptest.position().x(); p2y2=ptest.position().y(); //width of snake/curve triwidth=5; //set actual x,y pos ang=atan2(p1y2-p1y1,p1x2-p1x1)-HALF_PI; p1x3=triwidth*cos(ang); p1y3=triwidth*sin(ang); p1x4=triwidth*cos(ang); p1y4=triwidth*sin(ang); ang=atan2(p2y2-p2y1,p2x2-p2x1)-HALF_PI; p2x3=triwidth*cos(ang); p2y3=triwidth*sin(ang); p2x4=triwidth*cos(ang); p2y4=triwidth*sin(ang); //draw trianglestrip vertex(p1x3+p2x1,p1y3+p2y1,0); vertex(p1x4+p2x1,p1y4+p2y1,0); vertex(p2x3+p2x1,p2y3+p2y1,0); vertex(p2x4+p2x1,p2y4+p2y1,0); previous=last; last=ptest; endShape(); // end of loop