Created
September 9, 2022 17:06
-
-
Save chrisdel101/03a2bf9a3a0c4b31d42ffbeeafa0d810 to your computer and use it in GitHub Desktop.
Shphere in webgl
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
// 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