Created
June 29, 2010 18:55
-
-
Save nervoussystem/457622 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Simple, bad surface splatting. Actually difficult | |
//Does not check for degenerate cases | |
for(int i=0;i<points.size();++i) { | |
PVector pt = (PVector) points.get(i); | |
PVector normal = (PVector) normals.get(i); | |
//draw a circle oriented towards normal at pt | |
//get rotation angles | |
float theta = atan2(normal.y,normal.x); //angle around z axis | |
float psi = atan2(sqrt(normal.x*normal.x+normal.y*normal.y),normal.z); //angle from z axis | |
//get local axes | |
PVector perp1 = normal.cross(new PVector(normal.x,normal.y,0)); | |
perp1.normalize(); | |
PVector perp2 = normal.cross(perp1); | |
perp2.normalize(); | |
//get coordinates of pt in local axis by projecting | |
float localZ = normal.dot(pt); | |
float localY = perp1.dot(pt); | |
float localX = -perp2.dot(pt); | |
pushMatrix(); | |
rotateZ(theta); | |
rotateY(psi); | |
translate(localX,localY,localZ); | |
ellipse(0,0,diameter,diameter); | |
popMatrix(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment