![]() |
|
球の表示 | ||||||||||||||||||||||||
1. glutが無いので、SphereのOBJECTを作成して表示 |
||||||||||||||||||||||||
|
![]() |
頂点配列 |
int mSpIndicesNum; FloatBuffer mSpVertexBuffer; ByteBuffer mSpIndexBuffer; IntBuffer mSpColorBuffer; |
|
![]() |
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; Random rand = new Random(); for( int i = 0; i < colors.length; i += 4 ) { colors[cnt++] = rand.nextInt(); colors[cnt++] = rand.nextInt(); colors[cnt++] = rand.nextInt(); colors[cnt++] = 0x10000; } //.......................................................... mSpVertexBuffer = makeFloatBuffer(vertices); mSpIndexBuffer = makeByteBuffer(indices); mSpColorBuffer = makeIntBuffer(colors); } |
|
![]() |
頂点配列のセット |
public static FloatBuffer makeFloatBuffer(float vertices[]) { ByteBuffer byteBuffer = ByteBuffer.allocateDirect(vertices.length*4); byteBuffer.order(ByteOrder.nativeOrder()); FloatBuffer fb = byteBuffer.asFloatBuffer(); fb.put(vertices); fb.position(0); return fb; } |
|
public static ShortBuffer makeShortBuffer(short colors[]) { ByteBuffer byteBuffer = ByteBuffer.allocateDirect(colors.length*2); byteBuffer.order(ByteOrder.nativeOrder()); ShortBuffer cb = byteBuffer.asShortBuffer(); cb.put(colors); cb.position(0); return cb; } |
|
public static IntBuffer makeIntBuffer(int vertices[]) { ByteBuffer byteBuffer = ByteBuffer.allocateDirect(vertices.length*4); byteBuffer.order(ByteOrder.nativeOrder()); IntBuffer ib = byteBuffer.asIntBuffer(); ib.put(vertices); ib.position(0); return ib; } |
|
public static ByteBuffer makeByteBuffer(byte[] byteArray){ ByteBuffer tmpBb = ByteBuffer.allocateDirect(byteArray.length); tmpBb.put(byteArray); tmpBb.position(0); return tmpBb; } |
|
![]() |
フルスクリーンモードの指定方法 |
public class MainActivity extends Activity { private GLSurfaceView mGLView; private MyRender mMyRender; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // フルスクリーン指定 this.requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN ); mGLView = new GLSurfaceView(this); mGLView.setRenderer(new MyRender(this)); setContentView(mGLView); } |
![]() |
Copyright (C) CRIMSON Systems |