Skip to content

Instantly share code, notes, and snippets.

@roxlu
Created June 2, 2012 19:03
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roxlu/2859605 to your computer and use it in GitHub Desktop.
Save roxlu/2859605 to your computer and use it in GitHub Desktop.
Generalizing Parallel Transport Frames
#include "ParallelTransportFrames.h"
#include "OpenGL.h"
void ParallelTransportFrames::addPoint(const Vec3& p) {
points.push_back(p);
}
void ParallelTransportFrames::create(Vec3 V) {
Vec3 V_prev = V;
for(int i = 0; i < points.size()-2; ++i) {
Vec3 t0 = (points[i+1] - points[i]).getNormalized();
Vec3 t1 = (points[i+2] - points[i+1]).getNormalized();
Vec3 B = cross(t0,t1);
if(B.length() <= 0.01) {
V = V_prev;
}
else {
B.normalize();
float theta = acosf(dot(t0, t1));
V.rotate(theta,B);
}
Vec3 binorm = cross(t0, V).getNormalized();
ParallelTransportFrame frame = {t0, V, binorm, points[i]};
frames.push_back(frame);
V_prev = V;
}
}
void ParallelTransportFrames::debugDraw(float s) {
glColor3f(1,1,1);
glBegin(GL_LINE_STRIP);
for(int i = 0; i < frames.size(); ++i) {
ParallelTransportFrame frame = frames[i];
glVertex3fv(frame.position.getPtr());
}
glEnd();
glBegin(GL_LINES);
for(int i = 0; i < frames.size(); ++i) {
ParallelTransportFrame frame = frames[i];
glColor3f(1,0,0);
glVertex3fv(frame.position.getPtr());
glVertex3fv((frame.position+(frame.N * s)).getPtr());
glColor3f(0,1,1);
glVertex3fv(frame.position.getPtr());
glVertex3fv((frame.position+(frame.B * s)).getPtr());
glColor3f(1,1,0);
glVertex3fv(frame.position.getPtr());
glVertex3fv((frame.position+(frame.T * s)).getPtr());
}
glEnd();
}
#ifndef ROXLU_PTF_H
#define ROXLU_PTF_H
#include "Vec3.h"
#include "Mat3.h"
#include <vector>
using namespace roxlu;
using std::vector;
struct ParallelTransportFrame {
Vec3 T;
Vec3 N;
Vec3 B;
Vec3 position;
};
class ParallelTransportFrames {
public:
void addPoint(const Vec3& v);
void create(Vec3 N);
void debugDraw(float axisSize = 3.0f);
size_t size();
vector<Vec3> points;
vector<ParallelTransportFrame> frames;
ParallelTransportFrame& at(const unsigned int& dx) {
return frames.at(dx);
}
ParallelTransportFrame& operator[](const unsigned int& dx) {
return frames[dx];
}
};
inline size_t ParallelTransportFrames::size() {
return frames.size();
}
#endif
@roxlu
Copy link
Author

roxlu commented Jun 2, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment