FileDocCategorySizeDatePackage
GLWorld.javaAPI DocAndroid 1.5 API2885Wed May 06 22:41:08 BST 2009com.example.android.apis.graphics.kube

GLWorld

public class GLWorld extends Object

Fields Summary
int
count
private ArrayList
mShapeList
private ArrayList
mVertexList
private int
mIndexCount
private IntBuffer
mVertexBuffer
private IntBuffer
mColorBuffer
private ShortBuffer
mIndexBuffer
Constructors Summary
Methods Summary
public voidaddShape(GLShape shape)

		mShapeList.add(shape);
		mIndexCount += shape.getIndexCount();
	
public GLVertexaddVertex(float x, float y, float z)

		GLVertex vertex = new GLVertex(x, y, z, mVertexList.size());
		mVertexList.add(vertex);
		return vertex;
	
public voiddraw(javax.microedition.khronos.opengles.GL10 gl)

       
    
		mColorBuffer.position(0);
		mVertexBuffer.position(0);
		mIndexBuffer.position(0);

		gl.glFrontFace(GL10.GL_CW);
        gl.glShadeModel(GL10.GL_FLAT);
        gl.glVertexPointer(3, GL10.GL_FIXED, 0, mVertexBuffer);
        gl.glColorPointer(4, GL10.GL_FIXED, 0, mColorBuffer);
        gl.glDrawElements(GL10.GL_TRIANGLES, mIndexCount, GL10.GL_UNSIGNED_SHORT, mIndexBuffer);
        count++;
    
public voidgenerate()

		
	    ByteBuffer bb = ByteBuffer.allocateDirect(mVertexList.size()*4*4);
	    bb.order(ByteOrder.nativeOrder());
		mColorBuffer = bb.asIntBuffer();

	    bb = ByteBuffer.allocateDirect(mVertexList.size()*4*3);
	    bb.order(ByteOrder.nativeOrder());
	    mVertexBuffer = bb.asIntBuffer();

	    bb = ByteBuffer.allocateDirect(mIndexCount*2);
	    bb.order(ByteOrder.nativeOrder());
	    mIndexBuffer = bb.asShortBuffer();

		Iterator<GLVertex> iter2 = mVertexList.iterator();
		while (iter2.hasNext()) {
			GLVertex vertex = iter2.next();
			vertex.put(mVertexBuffer, mColorBuffer);
		}

		Iterator<GLShape> iter3 = mShapeList.iterator();
		while (iter3.hasNext()) {
			GLShape shape = iter3.next();
			shape.putIndices(mIndexBuffer);
		}
	
public static floattoFloat(int x)

    	return x/65536.0f;
    
public voidtransformVertex(GLVertex vertex, M4 transform)

		vertex.update(mVertexBuffer, transform);