/**
*
In this example a 2D polygon profile is being swept along a
* 3D spline path and aligned to the path direction using quaternions.
* The example demonstrates both the usage of the alignment quaternion
* in combination with a 4x4 transformation matrix, as well as the use
* of the toAxisAngle() method to compute a rotation axis from a quat.
*
*
* Usage:
* - l: toggle between line/dot rendering
* - r: restart animation
*
*/
/*
* Copyright (c) 2011 Karsten Schmidt
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* http://creativecommons.org/licenses/LGPL/2.1/
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
import toxi.geom.*;
import toxi.geom.mesh.*;
import toxi.processing.*;
ToxiclibsSupport gfx;
Polygon2D profile=new Circle(40).toPolygon2D(60);
List path;
ArrayList tubeVertices=new ArrayList();
int pathID=0;
boolean doRenderPoints;
void setup() {
size(680,382,P3D);
gfx=new ToxiclibsSupport(this);
// compute spiral key points (every 45 degrees)
ArrayList points = new ArrayList();
for (float theta=-TWO_PI, r=100; theta<8*TWO_PI; theta+=QUARTER_PI) {
Vec3D p=Vec3D.fromXYTheta(theta).scale(r).add(200,0,0).rotateY(theta/9);
points.add(p);
}
// use points to compute a spline and sample at regular interval
Spline3D s=new Spline3D(points);
s.computeVertices(10);
path=s.getDecimatedVertices(4);
}
void draw() {
background(51);
lights();
translate(width / 2, height / 2, 0);
rotateX(mouseY * 0.01f);
rotateY(mouseX * 0.01f);
noStroke();
gfx.origin(300);
stroke(255,0,255);
gfx.lineStrip3D(path);
if (pathID