Drawing a Sphere using WebGL
4:00 PM
Going off the track for a little bit, I wanted to draw some real 3D shapes. So I started with a circle. Yes, I know, it's a 2D shape you will say. But to be able to draw a sphere, I should at least know how to draw a circle.
So I tried drawing it with the dividing polygon method. That is, first I drew only the 4 vertices at the ends of the principal axes. After that, I increased the segment count, by drawing another vertex between every two vertex. This new vertex point was calculated using sin and cosine, and multiplied by the radius. Applying this for increasing segment numbers, we get a very good approximation of a circle.
For the sphere, we need to have 2 angles, Lattitude and Longitude. Longitude are the horizontal lines of the sphere, and lattitude are the horizontal ones. computing x, y and z according to a known formula, here is what happens:
Comments
Post a Comment