/* * 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 = (float)(i / (m - 1.0)); float v = (float)(j / (n - 1.0)); float theta = (float)(2.0 * Math.PI * u); float phi = (float)(Math.PI * v - Math.PI/2.0); mesh[i][j][0] = (float)(Math.cos(theta) * Math.cos(phi)); mesh[i][j][1] = (float)(Math.sin(theta) * Math.cos(phi)); mesh[i][j][2] = (float)(Math.sin(phi)); } } return mesh; } /** * spheres */ public Sphere (Material m){ super(m); int detail = 32; float[][][] mesh = globeMesh(detail,detail); faces = new int[(detail-1)*(detail-1)][4]; for(int i=0;i