Skip to content

Instantly share code, notes, and snippets.

@companje
Last active March 3, 2020 08:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save companje/a19a6f6ac88f0571fa6bb7b294c4336c to your computer and use it in GitHub Desktop.
Save companje/a19a6f6ac88f0571fa6bb7b294c4336c to your computer and use it in GitHub Desktop.
orientateOnSphere
void orientateOnSphere(PVector p) { // p doesn't have to be normalized
rotate(new Quaternion().fromVectors(new PVector(0, 0, 1), p));
translate(0, 0, p.mag());
float a = -(atan2(screen().y-screen(0, 100, 0).y, screen().x-screen(0, 100, 0).x) + HALF_PI); //angle van loodrechte vector
float b = atan2(-(screen().y-p.mag()), -(screen().x-p.mag())) + HALF_PI; //angle tov screen center
rotateZ(a + b);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment