Skip to content

Instantly share code, notes, and snippets.

@companje
Last active November 23, 2019 14:01
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/2b8d95e6f4261afe8a1d5eb28134c9cd to your computer and use it in GitHub Desktop.
Save companje/2b8d95e6f4261afe8a1d5eb28134c9cd to your computer and use it in GitHub Desktop.
Tip: distortion when drawing markers on a sphere
/*
When you want to draw markers on a sphere keep in mind that 3D markers (like spheres and boxes) are distorted because you see their top as well as their sides instead of just their top.
*/
perspective(atan(r/distToCam)*2, wdh, distToCam, 10000); //fov=35deg //atan(hd2/distToCam)*2
camera(0, 0, -distToCam, 0, 0, 0, 0, 1, 0);
scale(-1, 1, 1);
background(0);
pushMatrix();
rotateX(HALF_PI);
noFill();
stroke(128);
hint(ENABLE_DEPTH_TEST);
sphere(r * globeScaler);
hint(DISABLE_DEPTH_TEST);
popMatrix();
fill(255); //, 0, 0);
noStroke();
for (float a=-HALF_PI; a<=HALF_PI; a+=PI/30) {
pushMatrix();
rotateY(a);
translate(0, 0, r * globeScaler);
ellipse(0,0,40,40);
popMatrix();
pushMatrix();
rotateX(a);
translate(0, 0, r * globeScaler);
ellipse(0,0,40,40);
popMatrix();
}
@companje
Copy link
Author

companje commented Nov 23, 2019

unwanted:
spheres-on-sphere

desired:
ellipse-on-sphere

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