Last active
February 16, 2016 16:37
-
-
Save elect86/d7881328fb1011d134d1 to your computer and use it in GitHub Desktop.
sphere
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private void createGeometry(float radius, short rings, short sectors) { | |
| float R = 1f/(float)(rings-1); | |
| float S = 1f/(float)(sectors-1); | |
| short r, s; | |
| float x, y, z; | |
| points = new float[rings * sectors * 3]; | |
| normals = new float[rings * sectors * 3]; | |
| texcoords = new float[rings * sectors * 2]; | |
| int t = 0, v = 0, n = 0; | |
| for(r = 0; r < rings; r++) { | |
| for(s = 0; s < sectors; s++) { | |
| y = (float) Math.sin( -PI_2 + PI * r * R ); | |
| x = (float) (Math.cos(2*PI * s * S) * Math.sin( PI * r * R )); | |
| z = (float) (Math.sin(2*PI * s * S) * Math.sin( PI * r * R )); | |
| texcoords[t++] = s*S; | |
| texcoords[t++] = r*R; | |
| points[v++] = x * radius; | |
| points[v++] = y * radius; | |
| points[v++] = z * radius; | |
| //Log.i("Sphere","Added point (" + x +", " + y + ", " +z +")"); | |
| normals[n++] = x; | |
| normals[n++] = y; | |
| normals[n++] = z; | |
| } | |
| } | |
| int counter = 0; | |
| indices = new short[rings * sectors * 6]; | |
| for(r = 0; r < rings - 1; r++){ | |
| for(s = 0; s < sectors-1; s++) { | |
| indices[counter++] = (short) (r * sectors + s); | |
| indices[counter++] = (short) (r * sectors + (s+1)); | |
| indices[counter++] = (short) ((r+1) * sectors + (s+1)); | |
| indices[counter++] = (short) ((r+1) * sectors + (s+1)); | |
| indices[counter++] = (short) (r * sectors + (s+1)); | |
| indices[counter++] = (short) ((r+1) * sectors + s); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment