/* * Sphere.java * * Alex S. */ /** * Sphere */ public class Sphere extends Shape { /** * make a globe sphere mesh * * @param m Horizontal splits. * @param n Vertical Splits. */ public float[][][] globeMesh(int m,int n){ float mesh[][][] = new float[m][n][3]; for (int i = 0 ; i < m ; i++){ for (int j = 0 ; j < n ; j++) { float u = i / (m - (float)1.0); float v = j / (n - (float)1.0); float theta = (float)2.0 * (float)Math.PI * u; float phi = (float)Math.PI * v - (float)Math.PI/(float)2.0; mesh[i][j][0] = (float)Math.cos(theta) * (float)Math.cos(phi); mesh[i][j][1] = (float)Math.sin(theta) * (float)Math.cos(phi); mesh[i][j][2] = (float)Math.sin(phi); } } return mesh; } /** * spheres */ public Sphere (Material m){ super(m); float[][][] mesh = globeMesh(16,16); faces = new int[15*15][4]; for(int i=0;i