本文整理匯總了Java中android.opengl.Matrix.translateM方法的典型用法代碼示例。如果您正苦於以下問題:Java Matrix.translateM方法的具體用法?Java Matrix.translateM怎麽用?Java Matrix.translateM使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.opengl.Matrix
的用法示例。
在下文中一共展示了Matrix.translateM方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: setSize
import android.opengl.Matrix; //導入方法依賴的package包/類
@Override
public void setSize(int width, int height) {
GLES20.glViewport(0, 0, width, height);
checkError();
Matrix.setIdentityM(mMatrices, mCurrentMatrixIndex);
Matrix.orthoM(mProjectionMatrix, 0, 0, width, 0, height, -1, 1);
Matrix.translateM(mMatrices, mCurrentMatrixIndex, 0, height, 0);
Matrix.scaleM(mMatrices, mCurrentMatrixIndex, 1, -1, 1);
}
示例2: recomputeMatrix
import android.opengl.Matrix; //導入方法依賴的package包/類
/**
* Re-computes mModelViewMatrix, based on the current values for rotation, scale, and
* translation.
*/
private void recomputeMatrix() {
float[] modelView = mModelViewMatrix;
Matrix.setIdentityM(modelView, 0);
Matrix.translateM(modelView, 0, mPosX, mPosY, 0.0f);
if (mAngle != 0.0f) {
Matrix.rotateM(modelView, 0, mAngle, 0.0f, 0.0f, 1.0f);
}
Matrix.scaleM(modelView, 0, mScaleX, mScaleY, 1.0f);
mMatrixReady = true;
}
示例3: onDrawFrame
import android.opengl.Matrix; //導入方法依賴的package包/類
@Override
public void onDrawFrame(GL10 glUnused) {
GLES20.glClear(GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);
// Do a complete rotation every 10 seconds.
long time = SystemClock.uptimeMillis() % 10000L;
float angleInDegrees = (360.0f / 10000.0f) * ((int) time);
// Draw the triangle facing straight on.
Matrix.setIdentityM(mModelMatrix, 0);
Matrix.rotateM(mModelMatrix, 0, angleInDegrees, 0.0f, 0.0f, 1.0f);
drawTriangle(mTriangle1Vertices);
// Draw one translated a bit down and rotated to be flat on the ground.
Matrix.setIdentityM(mModelMatrix, 0);
Matrix.translateM(mModelMatrix, 0, 0.0f, -1.0f, 0.0f);
Matrix.rotateM(mModelMatrix, 0, 90.0f, 1.0f, 0.0f, 0.0f);
Matrix.rotateM(mModelMatrix, 0, angleInDegrees, 0.0f, 0.0f, 1.0f);
drawTriangle(mTriangle2Vertices);
// Draw one translated a bit to the right and rotated to be facing to the left.
Matrix.setIdentityM(mModelMatrix, 0);
Matrix.translateM(mModelMatrix, 0, 1.0f, 0.0f, 0.0f);
Matrix.rotateM(mModelMatrix, 0, 90.0f, 0.0f, 1.0f, 0.0f);
Matrix.rotateM(mModelMatrix, 0, angleInDegrees, 0.0f, 0.0f, 1.0f);
drawTriangle(mTriangle3Vertices);
}
示例4: getTranslationMatrix
import android.opengl.Matrix; //導入方法依賴的package包/類
/**
* Gets the matrix that will be used to translate this 3DString
* @return float[] object
*/
public float[] getTranslationMatrix() {
Matrix.setIdentityM(this.translationMatrix, 0);
Matrix.translateM(this.translationMatrix, 0, this.getPositionX(), this.getPositionY(), this.getPositionZ());
return this.translationMatrix;
}
示例5: setMatrix
import android.opengl.Matrix; //導入方法依賴的package包/類
private void setMatrix(ShaderParameter[] params, float x, float y, float width, float height) {
Matrix.translateM(mTempMatrix, 0, mMatrices, mCurrentMatrixIndex, x, y, 0f);
Matrix.scaleM(mTempMatrix, 0, width, height, 1f);
Matrix.multiplyMM(mTempMatrix, MATRIX_SIZE, mProjectionMatrix, 0, mTempMatrix, 0);
GLES20.glUniformMatrix4fv(params[INDEX_MATRIX].handle, 1, false, mTempMatrix, MATRIX_SIZE);
checkError();
}
示例6: onDrawFrame
import android.opengl.Matrix; //導入方法依賴的package包/類
@Override
public void onDrawFrame(GL10 glUnused)
{
GLES20.glClear(GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);
// Do a complete rotation every 10 seconds.
long time = SystemClock.uptimeMillis() % 10000L;
float angleInDegrees = (360.0f / 10000.0f) * ((int) time);
// Draw the triangle facing straight on.
Matrix.setIdentityM(mModelMatrix, 0);
Matrix.rotateM(mModelMatrix, 0, angleInDegrees, 0.0f, 0.0f, 1.0f);
drawTriangle(mTriangle1Vertices);
// Draw one translated a bit down and rotated to be flat on the ground.
Matrix.setIdentityM(mModelMatrix, 0);
Matrix.translateM(mModelMatrix, 0, 0.0f, -1.0f, 0.0f);
Matrix.rotateM(mModelMatrix, 0, 90.0f, 1.0f, 0.0f, 0.0f);
Matrix.rotateM(mModelMatrix, 0, angleInDegrees, 0.0f, 0.0f, 1.0f);
drawTriangle(mTriangle2Vertices);
// Draw one translated a bit to the right and rotated to be facing to the left.
Matrix.setIdentityM(mModelMatrix, 0);
Matrix.translateM(mModelMatrix, 0, 1.0f, 0.0f, 0.0f);
Matrix.rotateM(mModelMatrix, 0, 90.0f, 0.0f, 1.0f, 0.0f);
Matrix.rotateM(mModelMatrix, 0, angleInDegrees, 0.0f, 0.0f, 1.0f);
drawTriangle(mTriangle3Vertices);
}
示例7: bindData
import android.opengl.Matrix; //導入方法依賴的package包/類
@Override public void bindData(ShaderProgram shaderProgram, float[] projectionMatrix, float[] modelViewMatrix) {
GraphShaderProgram graphShaderProgram = (GraphShaderProgram) shaderProgram;
// Calculate the projection and view transformation
Matrix.multiplyMM(modelMatrix, 0, projectionMatrix, 0, modelViewMatrix, 0);
Matrix.translateM(modelMatrix, 0, 0f, graphInfo.getyPositionToDraw(), 0f);
graphShaderProgram.setUniforms(modelMatrix);
GLES20.glEnableVertexAttribArray(graphShaderProgram.getPositionAttributeLocation());
GLES20.glVertexAttribPointer(graphShaderProgram.getPositionAttributeLocation(), 1, GLES20.GL_FLOAT, false, 0, vertexData);
GLES20.glEnableVertexAttribArray(graphShaderProgram.getSensorValue());
GLES20.glVertexAttribPointer(graphShaderProgram.getSensorValue(), 1, GLES20.GL_FLOAT, false, 0, vertexSensor);
}
示例8: onDrawFrame
import android.opengl.Matrix; //導入方法依賴的package包/類
@Override
public void onDrawFrame(GL10 glUnused) {
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
final String vertexShader = getVertexShader();
final String fragmentShader = getFragmentShader();
final int vertexShaderHandle = ShaderHelper.compileShader(
GLES20.GL_VERTEX_SHADER, vertexShader);
final int fragmentShaderHandle = ShaderHelper.compileShader(
GLES20.GL_FRAGMENT_SHADER, fragmentShader);
mProgramHandle = ShaderHelper.createAndLinkProgram(vertexShaderHandle,
fragmentShaderHandle, new String[] { "a_Position",
"a_TexCoordinate" });
// Set our per-vertex lighting program.
GLES20.glUseProgram(mProgramHandle);
// Set program handles for cube drawing.
mMVPMatrixHandle = GLES20.glGetUniformLocation(mProgramHandle,
"u_MVPMatrix");
mTextureUniformHandle0 = GLES20.glGetUniformLocation(mProgramHandle,
"u_Texture0");
mTextureUniformHandle1 = GLES20.glGetUniformLocation(mProgramHandle,
"u_Texture1");
mPositionHandle = GLES20.glGetAttribLocation(mProgramHandle,
"a_Position");
mTextureCoordinateHandle = GLES20.glGetAttribLocation(mProgramHandle,
"a_TexCoordinate");
/**
* First texture map
*/
// Set the active texture0 unit to texture unit 0.
GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
// Bind the texture to this unit.
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureDataHandle0);
// Tell the texture uniform sampler to use this texture in the shader by
// binding to texture unit 0.
GLES20.glUniform1i(mTextureUniformHandle0, 0);
/**
* Second texture map
*/
// Set the active texture1 unit to texture unit 1.
GLES20.glActiveTexture(GLES20.GL_TEXTURE1);
// Bind the texture to this unit.
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureDataHandle1);
// Tell the texture uniform sampler to use this texture in the shader by
// binding to texture unit 1.
GLES20.glUniform1i(mTextureUniformHandle1, 1);
// Draw some cubes.
Matrix.setIdentityM(mModelMatrix, 0);
Matrix.translateM(mModelMatrix, 0, 0.0f, 0.0f, -3.2f);
Matrix.rotateM(mModelMatrix, 0, 0.0f, 1.0f, 1.0f, 0.0f);
drawCube();
}
示例9: glTranslatef
import android.opengl.Matrix; //導入方法依賴的package包/類
public void glTranslatef(float x, float y, float z) {
Matrix.translateM(mMatrix, mTop, x, y, z);
}
示例10: draw
import android.opengl.Matrix; //導入方法依賴的package包/類
public void draw() {
if (mBlendng) {
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
} else {
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
}
// Do a compile rotation every 10 seconds.
long time = SystemClock.uptimeMillis() % 10000L;
float angleInDegrees = (360.0f / 10000.0f) * ((int) time);
// Set our pre-vertex lighting program.
GLES20.glUseProgram(mProgramHandle);
// Set program handle for cube drawing.
mMVPMatrixHandle = GLES20.glGetUniformLocation(mProgramHandle, "u_MVPMatrix");
mPositionHandle = GLES20.glGetAttribLocation(mProgramHandle, "a_Position");
mColorHandle = GLES20.glGetAttribLocation(mProgramHandle, "a_Color");
// right
Matrix.setIdentityM(mModelMatrix, 0);
Matrix.translateM(mModelMatrix, 0, 4.0f, 0.0f, -7.0f);
Matrix.rotateM(mModelMatrix, 0, angleInDegrees, 1.0f, 0.0f, 0.0f);
drawCube();
// left
Matrix.setIdentityM(mModelMatrix, 0);
Matrix.translateM(mModelMatrix, 0, -4.0f, 0.0f, -7.0f);
Matrix.rotateM(mModelMatrix, 0, angleInDegrees, 0.0f, 1.0f, 0.0f);
drawCube();
// top
Matrix.setIdentityM(mModelMatrix, 0);
Matrix.translateM(mModelMatrix, 0, 0.0f, 4.0f, -7.0f);
Matrix.rotateM(mModelMatrix, 0, angleInDegrees, 0.0f, 0.0f, 1.0f);
drawCube();
// bottom
Matrix.setIdentityM(mModelMatrix, 0);
Matrix.translateM(mModelMatrix, 0, 0.0f, -4.0f, -7.0f);
Matrix.rotateM(mModelMatrix, 0, angleInDegrees, 0.0f, 1.0f, 0.0f);
drawCube();
// center
Matrix.setIdentityM(mModelMatrix, 0);
Matrix.translateM(mModelMatrix, 0, 0.0f, 0.0f, -5.0f);
Matrix.rotateM(mModelMatrix, 0, angleInDegrees, 1.0f, 1.0f, 1.0f);
drawCube();
}
示例11: draw
import android.opengl.Matrix; //導入方法依賴的package包/類
public void draw() {
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
// Do a compile rotation every 10 seconds.
long time = SystemClock.uptimeMillis() % 10000L;
float angleInDegrees = (360.0f / 10000.0f) * ((int) time);
// Set our pre-vertex lighting program.
GLES20.glUseProgram(mPerVertexProgramHandle);
// Set program handle for cube drawing.
mMVPMatrixHandle = GLES20.glGetUniformLocation(mPerVertexProgramHandle, "u_MVPMatrix");
mMVMatrixHandle = GLES20.glGetUniformLocation(mPerVertexProgramHandle, "u_MVMatrix");
mLightPosHandle = GLES20.glGetUniformLocation(mPerVertexProgramHandle, "u_LightPos");
mPositionHandle = GLES20.glGetAttribLocation(mPerVertexProgramHandle, "a_Position");
mColorHandle = GLES20.glGetAttribLocation(mPerVertexProgramHandle, "a_Color");
mNormalHandle = GLES20.glGetAttribLocation(mPerVertexProgramHandle, "a_Normal");
// Calculate position of the light.
// Rotate and then push into the distance.
Matrix.setIdentityM(mLightModelMatrix, 0);
Matrix.translateM(mLightModelMatrix, 0, 0.0f, 0.0f, -5.0f);
Matrix.rotateM(mLightModelMatrix, 0, angleInDegrees, 0.0f, 1.0F, 0.0f);
Matrix.translateM(mLightModelMatrix, 0, 0.0f, 0.0f, 2.0f);
Matrix.multiplyMV(mLightPosInWorldSpace, 0, mLightModelMatrix, 0, mLightPosInModelSpace, 0);
Matrix.multiplyMV(mLightPosInEyeSpace, 0, mViewMatrix, 0, mLightPosInWorldSpace, 0);
// right
Matrix.setIdentityM(mModelMatrix, 0);
Matrix.translateM(mModelMatrix, 0, 4.0f, 0.0f, -7.0f);
Matrix.rotateM(mModelMatrix, 0, angleInDegrees, 1.0f, 0.0f, 0.0f);
drawCube();
// left
Matrix.setIdentityM(mModelMatrix, 0);
Matrix.translateM(mModelMatrix, 0, -4.0f, 0.0f, -7.0f);
Matrix.rotateM(mModelMatrix, 0, angleInDegrees, 0.0f, 1.0f, 0.0f);
drawCube();
// top
Matrix.setIdentityM(mModelMatrix, 0);
Matrix.translateM(mModelMatrix, 0, 0.0f, 4.0f, -7.0f);
Matrix.rotateM(mModelMatrix, 0, angleInDegrees, 0.0f, 0.0f, 1.0f);
drawCube();
// bottom
Matrix.setIdentityM(mModelMatrix, 0);
Matrix.translateM(mModelMatrix, 0, 0.0f, -4.0f, -7.0f);
Matrix.rotateM(mModelMatrix, 0, angleInDegrees, 0.0f, 1.0f, 0.0f);
drawCube();
// center
Matrix.setIdentityM(mModelMatrix, 0);
Matrix.translateM(mModelMatrix, 0, 0.0f, 0.0f, -5.0f);
Matrix.rotateM(mModelMatrix, 0, angleInDegrees, 1.0f, 1.0f, 1.0f);
drawCube();
// Draw a point to indicate the light.
GLES20.glUseProgram(mPointProgramHandle);
drawLight();
}
示例12: draw
import android.opengl.Matrix; //導入方法依賴的package包/類
public void draw() {
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
// Do a compile rotation every 10 seconds.
long time = SystemClock.uptimeMillis() % 10000L;
float angleInDegrees = (360.0f / 10000.0f) * ((int) time);
// Set our pre-vertex lighting program.
GLES20.glUseProgram(mPerVertexProgramHandle);
// Set program handle for cube drawing.
mMVPMatrixHandle = GLES20.glGetUniformLocation(mPerVertexProgramHandle, "u_MVPMatrix");
mMVMatrixHandle = GLES20.glGetUniformLocation(mPerVertexProgramHandle, "u_MVMatrix");
mLightPosHandle = GLES20.glGetUniformLocation(mPerVertexProgramHandle, "u_LightPos");
mTextureUniformHandle = GLES20.glGetUniformLocation(mPerVertexProgramHandle, "u_Texture");
mPositionHandle = GLES20.glGetAttribLocation(mPerVertexProgramHandle, "a_Position");
mColorHandle = GLES20.glGetAttribLocation(mPerVertexProgramHandle, "a_Color");
mNormalHandle = GLES20.glGetAttribLocation(mPerVertexProgramHandle, "a_Normal");
mTextureCoordinateHandle = GLES20.glGetAttribLocation(mPerVertexProgramHandle, "a_TexCoordinate");
// Set the active texture unit to texture unit 0.
GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
// Bind the texture to this unit
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureDataHandle);
// Tell the texture uniform sampler to use the texture
// in the shader by binding to texture unit 0.
GLES20.glUniform1i(mTextureUniformHandle, 0);
// Calculate position of the light.
// Rotate and then push into the distance.
Matrix.setIdentityM(mLightModelMatrix, 0);
Matrix.translateM(mLightModelMatrix, 0, 0.0f, 0.0f, -5.0f);
Matrix.rotateM(mLightModelMatrix, 0, angleInDegrees, 0.0f, 1.0F, 0.0f);
Matrix.translateM(mLightModelMatrix, 0, 0.0f, 0.0f, 2.0f);
Matrix.multiplyMV(mLightPosInWorldSpace, 0, mLightModelMatrix, 0, mLightPosInModelSpace, 0);
Matrix.multiplyMV(mLightPosInEyeSpace, 0, mViewMatrix, 0, mLightPosInWorldSpace, 0);
// right
Matrix.setIdentityM(mModelMatrix, 0);
Matrix.translateM(mModelMatrix, 0, 4.0f, 0.0f, -7.0f);
Matrix.rotateM(mModelMatrix, 0, angleInDegrees, 1.0f, 0.0f, 0.0f);
drawCube();
// left
Matrix.setIdentityM(mModelMatrix, 0);
Matrix.translateM(mModelMatrix, 0, -4.0f, 0.0f, -7.0f);
Matrix.rotateM(mModelMatrix, 0, angleInDegrees, 0.0f, 1.0f, 0.0f);
drawCube();
// top
Matrix.setIdentityM(mModelMatrix, 0);
Matrix.translateM(mModelMatrix, 0, 0.0f, 4.0f, -7.0f);
Matrix.rotateM(mModelMatrix, 0, angleInDegrees, 0.0f, 0.0f, 1.0f);
drawCube();
// bottom
Matrix.setIdentityM(mModelMatrix, 0);
Matrix.translateM(mModelMatrix, 0, 0.0f, -4.0f, -7.0f);
Matrix.rotateM(mModelMatrix, 0, angleInDegrees, 0.0f, 1.0f, 0.0f);
drawCube();
// center
Matrix.setIdentityM(mModelMatrix, 0);
Matrix.translateM(mModelMatrix, 0, 0.0f, 0.0f, -5.0f);
Matrix.rotateM(mModelMatrix, 0, angleInDegrees, 1.0f, 1.0f, 1.0f);
drawCube();
// Draw a point to indicate the light.
GLES20.glUseProgram(mPointProgramHandle);
drawLight();
}
示例13: onDrawFrame
import android.opengl.Matrix; //導入方法依賴的package包/類
@Override
public void onDrawFrame(GL10 glUnused) {
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
// Set our per-vertex lighting program.
GLES20.glUseProgram(mProgramHandle);
// Set program handles for cube drawing.
mMVPMatrixHandle = GLES20.glGetUniformLocation(mProgramHandle, "u_MVPMatrix");
mMVMatrixHandle = GLES20.glGetUniformLocation(mProgramHandle, "u_MVMatrix");
mLightPosHandle = GLES20.glGetUniformLocation(mProgramHandle, "u_LightPos");
mTextureUniformHandle = GLES20.glGetUniformLocation(mProgramHandle, "u_Texture");
mPositionHandle = GLES20.glGetAttribLocation(mProgramHandle, "a_Position");
mNormalHandle = GLES20.glGetAttribLocation(mProgramHandle, "a_Normal");
mTextureCoordinateHandle = GLES20.glGetAttribLocation(mProgramHandle, "a_TexCoordinate");
// Calculate position of the light. Push into the distance.
Matrix.setIdentityM(mLightModelMatrix, 0);
Matrix.translateM(mLightModelMatrix, 0, 0.0f, 0.0f, -1.0f);
Matrix.multiplyMV(mLightPosInWorldSpace, 0, mLightModelMatrix, 0, mLightPosInModelSpace, 0);
Matrix.multiplyMV(mLightPosInEyeSpace, 0, mViewMatrix, 0, mLightPosInWorldSpace, 0);
// Draw a cube.
// Translate the cube into the screen.
Matrix.setIdentityM(mModelMatrix, 0);
Matrix.translateM(mModelMatrix, 0, 0.0f, 0.0f, -3.5f);
// Set a matrix that contains the current rotation.
Matrix.setIdentityM(mCurrentRotation, 0);
Matrix.rotateM(mCurrentRotation, 0, mDeltaX, 0.0f, 1.0f, 0.0f);
Matrix.rotateM(mCurrentRotation, 0, mDeltaY, 1.0f, 0.0f, 0.0f);
mDeltaX = 0.0f;
mDeltaY = 0.0f;
// Multiply the current rotation by the accumulated rotation, and then set the accumulated rotation to the result.
Matrix.multiplyMM(mTemporaryMatrix, 0, mCurrentRotation, 0, mAccumulatedRotation, 0);
System.arraycopy(mTemporaryMatrix, 0, mAccumulatedRotation, 0, 16);
// Rotate the cube taking the overall rotation into account.
Matrix.multiplyMM(mTemporaryMatrix, 0, mModelMatrix, 0, mAccumulatedRotation, 0);
System.arraycopy(mTemporaryMatrix, 0, mModelMatrix, 0, 16);
// This multiplies the view matrix by the model matrix, and stores
// the result in the MVP matrix
// (which currently contains model * view).
Matrix.multiplyMM(mMVPMatrix, 0, mViewMatrix, 0, mModelMatrix, 0);
// Pass in the modelview matrix.
GLES20.glUniformMatrix4fv(mMVMatrixHandle, 1, false, mMVPMatrix, 0);
// This multiplies the modelview matrix by the projection matrix,
// and stores the result in the MVP matrix
// (which now contains model * view * projection).
Matrix.multiplyMM(mTemporaryMatrix, 0, mProjectionMatrix, 0, mMVPMatrix, 0);
System.arraycopy(mTemporaryMatrix, 0, mMVPMatrix, 0, 16);
// Pass in the combined matrix.
GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mMVPMatrix, 0);
// Pass in the light position in eye space.
GLES20.glUniform3f(mLightPosHandle, mLightPosInEyeSpace[0], mLightPosInEyeSpace[1], mLightPosInEyeSpace[2]);
// Pass in the texture information
// Set the active texture unit to texture unit 0.
GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
// Bind the texture to this unit.
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mAndroidDataHandle);
// Tell the texture uniform sampler to use this texture in the
// shader by binding to texture unit 0.
GLES20.glUniform1i(mTextureUniformHandle, 0);
if (mCubes != null) {
mCubes.render();
}
}
示例14: onDrawFrame
import android.opengl.Matrix; //導入方法依賴的package包/類
@Override
public void onDrawFrame(GL10 glUnused)
{
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
// Do a complete rotation every 10 seconds.
long time = SystemClock.uptimeMillis() % 10000L;
float angleInDegrees = (360.0f / 10000.0f) * ((int) time);
// Calculate position of the light. Push into the distance.
Matrix.setIdentityM(aLightModelMatrix, 0);
Matrix.translateM(aLightModelMatrix, 0, 0.0f, 0.0f, -5.0f);
Matrix.multiplyMV(aLightPosInWorldSpace, 0, aLightModelMatrix, 0, aLightPosInModelSpace, 0);
Matrix.multiplyMV(aLightPosInEyeSpace, 0, aViewMatrix, 0, aLightPosInWorldSpace, 0);
// Translate the cube into the screen.
Matrix.setIdentityM(aModelMatrix, 0);
if(aHeightMap != null){
Matrix.translateM(aModelMatrix, 0, 0, 0, -300.5f);
}else {
Matrix.translateM(aModelMatrix, 0, 0, 0, -3.5f);
}
if(aDeltaX != 0 || aDeltaY != 0) {
aRotationStatus = false;
}
if(aRotationStatus) {
Matrix.rotateM(aModelMatrix, 0, angleInDegrees, 1.0f, 0.0f, 0.0f);
Matrix.rotateM(aModelMatrix, 0, angleInDegrees, 0.0f, 1.0f, 0.0f);
Matrix.rotateM(aModelMatrix, 0, angleInDegrees, 0.0f, 0.0f, 1.0f);
}
// Set a matrix that contains the current rotation.
Matrix.setIdentityM(aCurrentRotation, 0);
Matrix.rotateM(aCurrentRotation, 0, aDeltaX, 0.0f, 1.0f, 0.0f);
Matrix.rotateM(aCurrentRotation, 0, aDeltaY, 1.0f, 0.0f, 0.0f);
aDeltaX = 0.0f;
aDeltaY = 0.0f;
// Multiply the current rotation by the accumulated rotation, and then set the accumulated rotation to the result.
Matrix.multiplyMM(aTemporaryMatrix, 0, aCurrentRotation, 0, aAccumulatedRotation, 0);
System.arraycopy(aTemporaryMatrix, 0, aAccumulatedRotation, 0, 16);
// Rotate the cube taking the overall rotation into account.
Matrix.multiplyMM(aTemporaryMatrix, 0, aModelMatrix, 0, aAccumulatedRotation, 0);
System.arraycopy(aTemporaryMatrix, 0, aModelMatrix, 0, 16);
// This multiplies the view matrix by the model matrix, and stores
// the result in the MVP matrix
// (which currently contains model * view).
Matrix.multiplyMM(aMVPMatrix, 0, aViewMatrix, 0, aModelMatrix, 0);
// This multiplies the modelview matrix by the projection matrix,
// and stores the result in the MVP matrix
// (which now contains model * view * projection).
Matrix.multiplyMM(aTemporaryMatrix, 0, aProjectionMatrix, 0, aMVPMatrix, 0);
System.arraycopy(aTemporaryMatrix, 0, aMVPMatrix, 0, 16);
if(aPoints != null){
aPoints.render(aMVPMatrix);
}else if(aLines != null){
aLines.render(aMVPMatrix);
}else if(aTriangles != null){
aTriangles.render(aMVPMatrix);
}else if(aQuad != null){
aQuad.render(aMVPMatrix, aTexture);
}else if(aCubes != null){
aCubes.render(aMVPMatrix, aTexture);
}else if(aSpheres != null){
aSpheres.render(aMVPMatrix);
}else if(aHeightMap != null){
aHeightMap.render(aMVPMatrix);
}
}
示例15: onDrawFrame
import android.opengl.Matrix; //導入方法依賴的package包/類
@Override
public void onDrawFrame(GL10 glUnused)
{
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
// Do a complete rotation every 10 seconds.
long time = SystemClock.uptimeMillis() % 10000L;
float angleInDegrees = (360.0f / 10000.0f) * ((int) time);
// Set our per-vertex lighting program.
GLES20.glUseProgram(mPerVertexProgramHandle);
// Set program handles for cube drawing.
mMVPMatrixHandle = GLES20.glGetUniformLocation(mPerVertexProgramHandle, "u_MVPMatrix");
mMVMatrixHandle = GLES20.glGetUniformLocation(mPerVertexProgramHandle, "u_MVMatrix");
mLightPosHandle = GLES20.glGetUniformLocation(mPerVertexProgramHandle, "u_LightPos");
mPositionHandle = GLES20.glGetAttribLocation(mPerVertexProgramHandle, "a_Position");
mColorHandle = GLES20.glGetAttribLocation(mPerVertexProgramHandle, "a_Color");
mNormalHandle = GLES20.glGetAttribLocation(mPerVertexProgramHandle, "a_Normal");
// Calculate position of the light. Rotate and then push into the distance.
Matrix.setIdentityM(mLightModelMatrix, 0);
Matrix.translateM(mLightModelMatrix, 0, 0.0f, 0.0f, -5.0f);
Matrix.rotateM(mLightModelMatrix, 0, angleInDegrees, 0.0f, 1.0f, 0.0f);
Matrix.translateM(mLightModelMatrix, 0, 0.0f, 0.0f, 2.0f);
Matrix.multiplyMV(mLightPosInWorldSpace, 0, mLightModelMatrix, 0, mLightPosInModelSpace, 0);
Matrix.multiplyMV(mLightPosInEyeSpace, 0, mViewMatrix, 0, mLightPosInWorldSpace, 0);
// Draw some cubes.
Matrix.setIdentityM(mModelMatrix, 0);
Matrix.translateM(mModelMatrix, 0, 4.0f, 0.0f, -7.0f);
Matrix.rotateM(mModelMatrix, 0, angleInDegrees, 1.0f, 0.0f, 0.0f);
drawCube();
Matrix.setIdentityM(mModelMatrix, 0);
Matrix.translateM(mModelMatrix, 0, -4.0f, 0.0f, -7.0f);
Matrix.rotateM(mModelMatrix, 0, angleInDegrees, 0.0f, 1.0f, 0.0f);
drawCube();
Matrix.setIdentityM(mModelMatrix, 0);
Matrix.translateM(mModelMatrix, 0, 0.0f, 4.0f, -7.0f);
Matrix.rotateM(mModelMatrix, 0, angleInDegrees, 0.0f, 0.0f, 1.0f);
drawCube();
Matrix.setIdentityM(mModelMatrix, 0);
Matrix.translateM(mModelMatrix, 0, 0.0f, -4.0f, -7.0f);
drawCube();
Matrix.setIdentityM(mModelMatrix, 0);
Matrix.translateM(mModelMatrix, 0, 0.0f, 0.0f, -5.0f);
Matrix.rotateM(mModelMatrix, 0, angleInDegrees, 1.0f, 1.0f, 0.0f);
drawCube();
// Draw a point to indicate the light.
GLES20.glUseProgram(mPointProgramHandle);
drawLight();
}