import android.opengl.Matrix; //导入方法依赖的package包/类
/**
* Handles changes to the size of the underlying surface. Adjusts viewport as needed.
* Must be called before we start drawing.
* (Called from RenderHandler.)
*/
private void surfaceChanged(int width, int height) {
// This method is called when the surface is first created, and shortly after the
// call to setFixedSize(). The tricky part is that this is called when the
// drawing surface is *about* to change size, not when it has *already* changed
// size. A query on the EGL surface will confirm that the surface dimensions
// haven't yet changed. If you re-query after the next swapBuffers() call,
// you will see the new dimensions.
//
// To have a smooth transition, we should continue to draw at the old size until the
// surface query tells us that the size of the underlying buffers has actually
// changed. I don't really expect a "normal" app will want to call setFixedSize()
// dynamically though, so in practice this situation shouldn't arise, and it's
// just not worth the hassle of doing it right.
Log.d(TAG, "surfaceChanged " + width + "x" + height);
// Use full window.
GLES20.glViewport(0, 0, width, height);
// Simple orthographic projection, with (0,0) in lower-left corner.
Matrix.orthoM(mDisplayProjectionMatrix, 0, 0, width, 0, height, -1, 1);
int smallDim = Math.min(width, height);
// Set initial shape size / position / velocity based on window size. Movement
// has the same "feel" on all devices, but the actual path will vary depending
// on the screen proportions. We do it here, rather than defining fixed values
// and tweaking the projection matrix, so that our squares are square.
mTri.setColor(0.1f, 0.9f, 0.1f);
mTri.setTexture(mFineTexture);
mTri.setScale(smallDim / 3.0f, smallDim / 3.0f);
mTri.setPosition(width / 2.0f, height / 2.0f);
mRect.setColor(0.9f, 0.1f, 0.1f);
mRect.setTexture(mCoarseTexture);
mRect.setScale(smallDim / 5.0f, smallDim / 5.0f);
mRect.setPosition(width / 2.0f, height / 2.0f);
mRectVelX = 1 + smallDim / 4.0f;
mRectVelY = 1 + smallDim / 5.0f;
// left edge
float edgeWidth = 1 + width / 64.0f;
mEdges[0].setColor(0.5f, 0.5f, 0.5f);
mEdges[0].setScale(edgeWidth, height);
mEdges[0].setPosition(edgeWidth / 2.0f, height / 2.0f);
// right edge
mEdges[1].setColor(0.5f, 0.5f, 0.5f);
mEdges[1].setScale(edgeWidth, height);
mEdges[1].setPosition(width - edgeWidth / 2.0f, height / 2.0f);
// top edge
mEdges[2].setColor(0.5f, 0.5f, 0.5f);
mEdges[2].setScale(width, edgeWidth);
mEdges[2].setPosition(width / 2.0f, height - edgeWidth / 2.0f);
// bottom edge
mEdges[3].setColor(0.5f, 0.5f, 0.5f);
mEdges[3].setScale(width, edgeWidth);
mEdges[3].setPosition(width / 2.0f, edgeWidth / 2.0f);
// Inner bounding rect, used to bounce objects off the walls.
mInnerLeft = mInnerBottom = edgeWidth;
mInnerRight = width - 1 - edgeWidth;
mInnerTop = height - 1 - edgeWidth;
Log.d(TAG, "mTri: " + mTri);
Log.d(TAG, "mRect: " + mRect);
}