![]() |
|
立方体と三角錐の表示 | ||
1. 2つのOBJECTを表示 |
||
|
![]() |
頂点配列 |
// Cube private FloatBuffer mVertexBuffer; // for Pyramid private FloatBuffer mPyVertexA,mPyVertexB,mPyVertexC,mPyVertexD,mPyVertexS; private ShortBuffer mPyColors; |
|
![]() |
Cube |
public void createCube() { // 立方体 float one = 0.5f; float[] vertex = { // FRONT -one, -one, one, one, -one, one, -one, one, one, one, one, one, // BACK -one, -one, -one, -one, one, -one, one, -one, -one, one, one, -one, // LEFT -one, -one, one, -one, one, one, -one, -one, -one, -one, one, -one, // RIGHT one, -one, -one, one, one, -one, one, -one, one, one, one, one, // TOP -one, one, one, one, one, one, -one, one, -one, one, one, -one, // BOTTOM -one, -one, one, -one, -one, -one, one, -one, one, one, -one, -one, }; mVertexBuffer = makeFloatBuffer(vertex); } |
|
![]() |
Pyramid |
public void createPyramid() { // ピラミッドの底面の頂点 float[] squareVertices = { -0.5f, -0.5f, 0.5f, 0.5f, -0.5f, 0.5f, 0.5f, -0.5f, -0.5f, -0.5f, -0.5f, -0.5f, }; // ピラミッド側面(三角形)の頂点を定義 float[] triangleVerticesA = { 0.0f, 0.5f, 0.0f, // Front -0.5f,-0.5f, 0.5f, 0.5f,-0.5f, 0.5f, }; float[] triangleVerticesB = { 0.0f, 0.5f, 0.0f, // Right 0.5f,-0.5f, 0.5f, 0.5f,-0.5f, -0.5f, }; float[] triangleVerticesC = { 0.0f, 0.5f, 0.0f, // Back 0.5f,-0.5f, -0.5f, -0.5f,-0.5f, -0.5f, }; float[] triangleVerticesD = { 0.0f, 0.5f, 0.0f, // Left -0.5f,-0.5f,-0.5f, -0.5f,-0.5f, 0.5f, }; //色 short[] squareColors = { 255, 255, 0, 255, 0, 255, 255, 255, 0, 0, 0, 0, 255, 0, 255, 255, }; mPyVertexS = makeFloatBuffer(squareVertices); mPyVertexA = makeFloatBuffer(triangleVerticesA); mPyVertexB = makeFloatBuffer(triangleVerticesB); mPyVertexC = makeFloatBuffer(triangleVerticesC); mPyVertexD = makeFloatBuffer(triangleVerticesD); mPyColors = makeShortBuffer(squareColors); } |
|
![]() |
頂点配列のセット |
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; } |
![]() |
Copyright (C) CRIMSON Systems |