java matrix_Java Matrix.orthoM方法代码示例

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);

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值