Skip to content

Instantly share code, notes, and snippets.

@chrisdel101
Created September 9, 2022 17:06
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 chrisdel101/03a2bf9a3a0c4b31d42ffbeeafa0d810 to your computer and use it in GitHub Desktop.
Save chrisdel101/03a2bf9a3a0c4b31d42ffbeeafa0d810 to your computer and use it in GitHub Desktop.
Shphere in webgl
// based on text book 2.4 https://inspirit.net.in/books/academic/Interactive%20Computer%20Graphics.pdf
function buildSpherePoints(){
const DegreesToRadians = Math.PI / 180.0; // Math.PI = 3.14159...
let quad_data = []; // 8 rows of 18 quads
let k = 0;
for(let phi = -80.0; phi <= 80.0; phi += 20.0)
{
let phir = phi*DegreesToRadians;
let phir20 = (phi + 20.0)*DegreesToRadians;
for(let theta = -180.0; theta <= 180.0; theta += 20.0)
{
let thetar = theta*DegreesToRadians;
shapes.sphere.points[k] = vec4(
Math.sin(thetar)*Math.cos(phir),
Math.cos(thetar)*Math.cos(phir),
Math.sin(phir),
1);
shapes.sphere.colors.push(lightblue)
k++;
shapes.sphere.points[k] = vec4(
Math.sin(thetar)*Math.cos(phir20),
Math.cos(thetar)*Math.cos(phir20),
Math.sin(phir20),
1
);
shapes.sphere.colors.push(lightblue)
k++;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment