Skip to content Skip to sidebar Skip to footer

Issue When Rendering A Torus In WebGL

I'm writing a program that is supposed to draw 3D parametric shapes in webgl. The code I have currently seems to work (mostly) for a sphere, but when I switch out the equations use

Solution 1:

Your elevation angle range for a sphere is only PI (from pole to pole), but the range is 2*PI for a torus; Thus

theta = latNumber * Math.PI / latitudeBands

should be

theta = latNumber * 2 * Math.PI / latitudeBands

See WebGL Torus Example.


Solution 2:

Honestly for these type of problems the most likely error arise from the geometry generation code. I suggest consult the excellent THREE.js source code to check for discrepancies. Toros generation code here.

You can find code for other geometry generation here should you need them in the future.


Post a Comment for "Issue When Rendering A Torus In WebGL"