![]() |
|
球の表示 | ||||||||||||
1. glutが無いので、SphereのOBJECTを作成して表示 |
||||||||||||
|
![]() |
Sphere Object |
void createSphere(int Radius, /* 半径 */ int segW, /* 分割 W */ int segH /* 分割 H */ ) { int gridU = segW; int gridV = segH; int gridU1 = gridU + 1; int gridV1 = gridV + 1; int incU = 360 / gridU; int incV = 2 * Radius / gridV; i nt cnt; // 頂点配列 float[] vertices = new float[(2 + (gridV1-2) * gridU) * 3]; cnt = 0; vertices[cnt++] = 0.0f; vertices[cnt++] = (float)-Radius; vertices[cnt++] = 0.0f; double d = Radius; double y, t, r; for( int iv=1; iv<(gridV1 - 1); ++ iv ) { y = iv * incV - d; r = Math.sqrt(d * d - y * y); for( int iu = 0; iu<gridU; ++ iu ) { t = iu * incU * Math.PI / 180; vertices[cnt++] = (float)(r * Math.cos(t)); vertices[cnt++] = (float)y; vertices[cnt++] = (float)(r * Math.sin(t)); } } vertices[cnt++] = 0.0f; vertices[cnt++] = (float)Radius; vertices[cnt++] = 0.0f; //............................................................... // インデックス配列 byte[] indices = new byte[((gridV-1) * gridU * 2) * 3]; cnt = 0; for( int iu = 0; iu < gridU; ++ iu ) { indices[cnt++] = 0; indices[cnt++] = (byte)((iu + 1) % gridU + 1); indices[cnt++] = (byte)(iu + 1); } for( int iv = 1; iv < gridV1 - 2; ++ iv ) { for( int iu = 0; iu < gridU; ++ iu ) { int m = (iv - 1) * gridU; //Triangle A indices[cnt++] = (byte)(iu + 1 + m); indices[cnt++] = (byte)((iu + 1) % gridU + 1 + m); indices[cnt++] = (byte)(iu + 1 + gridU + m); //Triangle B indices[cnt++] = (byte)((iu + 1) % gridU + 1 + gridU + m); indices[cnt++] = (byte)(iu + 1 + gridU + m); indices[cnt++] = (byte)((iu + 1) % gridU + 1 + m); } } int n = (2 + (gridV1-2) * gridU) - 1; for( int iu = n - gridU; iu < n; ++ iu ) { indices[cnt++] = (byte)iu; indices[cnt++] = (byte)(iu % gridU + n - gridU ); indices[cnt++] = (byte)n; } mSpIndicesNum = indices.length; //........................................................ // カラー配列 int[] colors = new int[(2 + (gridV1-2) * gridU) * 4]; cnt = 0; int iro = 0; for( int i=0; i<colors.length; i+=4 ) { switch (iro){ case 0: { colors[cnt++] = 1; colors[cnt++] = 0; colors[cnt++] = 0; break; } case 1: { colors[cnt++] = 0; colors[cnt++] = 1; colors[cnt++] = 0; break; } case 2: { colors[cnt++] = 0; colors[cnt++] = 0; colors[cnt++] = 1; break; } } colors[cnt++] = 1; iro++; if ( iro == 3) iro=0; } //.......................................................... mSpVertexBuffer = makeFloatBuffer(vertices); mSpIndexBuffer = makeByteBuffer(indices); mSpColorBuffer = makeIntBuffer(colors); } |
![]() |
Copyright (C) CRIMSON Systems |