20.11.2016 Views

ANDROID APP

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

ไลบรารีขั้นสูงที่ใช้ในส่วนการติดต่อกับผู้ใช้งาน<br />

143<br />

*/<br />

class PyramidRenderer implements GLSurfaceView.Renderer {<br />

public PyramidRenderer(boolean useTranslucentBackground) {<br />

mTranslucentBackground = useTranslucentBackground;<br />

mPyramid = new Pyramid();<br />

}<br />

public void onDrawFrame(GL10 gl) {<br />

/* clear the screen */<br />

gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);<br />

/* draw a pyramid rotating */<br />

gl.glMatrixMode(GL10.GL_MODELVIEW);<br />

gl.glLoadIdentity();<br />

gl.glTranslatef(mCenter[0], mCenter[1], mCenter[2]);<br />

gl.glRotatef(mAngle, 0, 1, 0);<br />

gl.glRotatef(mAngle*0.25f, 1, 0, 0);<br />

gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);<br />

gl.glEnableClientState(GL10.GL_COLOR_ARRAY);<br />

mPyramid.draw(gl);<br />

mAngle += mAngleDelta;<br />

/* draw it bouncing off the walls */<br />

mCenter[0] += mVel[0];<br />

mCenter[1] += mVel[1];<br />

}<br />

if(Math.abs(mCenter[0])>4.0f) {<br />

mVel[0] = -mVel[0];<br />

mAngleDelta=(float) (5*(0.5-Math.random()));<br />

}<br />

if(Math.abs(mCenter[1])>6.0f) {<br />

mVel[1] = -mVel[1];<br />

mAngleDelta=(float) (5*(0.5-Math.random()));<br />

}<br />

public void onSurfaceChanged(GL10 gl, int width, int height) {<br />

gl.glViewport(0, 0, width, height);<br />

/* Set a new projection when the viewport is resized */<br />

float ratio = (float) width / height;<br />

gl.glMatrixMode(GL10.GL_PROJECTION);

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!