Last active
March 3, 2020 08:43
-
-
Save companje/a19a6f6ac88f0571fa6bb7b294c4336c to your computer and use it in GitHub Desktop.
orientateOnSphere
This file contains 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
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