Skip to content

Instantly share code, notes, and snippets.

@roxlu
Created April 6, 2012 19:55
Show Gist options
  • Save roxlu/2322523 to your computer and use it in GitHub Desktop.
Save roxlu/2322523 to your computer and use it in GitHub Desktop.
Calculate coordinate system based on direction vector
void Tubes::computeEdgeCoordinateSystems() {
Vec3 dir;
float inv = 0.0f;
vector<Edge*>::iterator it = graph.edges.begin();
while(it != graph.edges.end()) {
Edge* e = (*it);
dir = graph.getEdgeDirection(e).normalize();
e->z_axis = dir;
if(fabsf(dir.x) > fabsf(dir.y)) {
inv = 1.0f / sqrtf(dir.x*dir.x + dir.z*dir.z);
e->y_axis.set(-dir.z * inv, 0.0f, dir.x * inv);
}
else {
inv = 1.0f / sqrtf(dir.y*dir.y + dir.z*dir.z);
e->y_axis.set(0.0f, dir.z * inv, -dir.y * inv);
}
e->x_axis = cross(e->z_axis, e->y_axis);
++it;
}
}
@roxlu
Copy link
Author

roxlu commented Apr 6, 2012

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