public class Sphere extends Shape {
	final int LATS, LONGS;
	public Sphere(int lats, int longs) {
		LATS = lats;
		LONGS = longs;
		init(LATS*LONGS,(LATS-1)*LONGS,4);
		for(int n = 0; n<LATS; ++n)
			for(int m = 0; m<LONGS; ++m) {
				double th = 2*Math.PI*m/LONGS,
					phi = Math.PI*((double)n/(LATS-1) - .5),
					x = Math.cos(th)*Math.cos(phi),
					y = Math.sin(th)*Math.cos(phi),
					z = Math.sin(phi);
				Vector3D pt = new Vector3D(x,y,z);
				vertices_[n*LONGS+m] = new PointyPoint(pt,pt);
			}
		for(int n = 0; n<LATS-1; ++n)
			for(int m = 0; m<LONGS; ++m) {
				int face = n*LONGS+m;
				faces_[face][0] = n*LONGS+m;
				faces_[face][1] = n*LONGS+(m+1)%LONGS;
				faces_[face][2] = (n+1)*LONGS+(m+1)%LONGS;
				faces_[face][3] = (n+1)*LONGS+m;
				//System.out.println("face " + face + " is " + faces_[face][0] + " " + faces_[face][1] + " " + faces_[face][2] + " " + faces_[face][3]);			
			}
	}
}
