当前位置: 首页>>代码示例>>Java>>正文


Java Matrix.translateM方法代码示例

本文整理汇总了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);
}
 
开发者ID:michelelacorte,项目名称:FlickLauncher,代码行数:10,代码来源:GLES20Canvas.java

示例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;
}
 
开发者ID:AndyZhu1991,项目名称:grafika,代码行数:16,代码来源:Sprite2d.java

示例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);
}
 
开发者ID:victordiaz,项目名称:phonk,代码行数:28,代码来源:LessonOneRenderer.java

示例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;
}
 
开发者ID:snada,项目名称:BitmapFontLoader,代码行数:12,代码来源:Bitmap3DString.java

示例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();
}
 
开发者ID:michelelacorte,项目名称:FlickLauncher,代码行数:8,代码来源:GLES20Canvas.java

示例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);
}
 
开发者ID:biezhihua,项目名称:Android_OpenGL_Demo,代码行数:29,代码来源:LessonOneRenderer.java

示例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);
}
 
开发者ID:khoatd92,项目名称:sensor-graph-opengl-es-android,代码行数:15,代码来源:SensorGraph.java

示例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();
}
 
开发者ID:sdrausty,项目名称:buildAPKsApps,代码行数:63,代码来源:GLLayer.java

示例9: glTranslatef

import android.opengl.Matrix; //导入方法依赖的package包/类
public void glTranslatef(float x, float y, float z) {
	Matrix.translateM(mMatrix, mTop, x, y, z);
}
 
开发者ID:archos-sa,项目名称:aos-MediaLib,代码行数:4,代码来源:MatrixStack.java

示例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();
}
 
开发者ID:biezhihua,项目名称:Android_OpenGL_Demo,代码行数:50,代码来源:Cube.java

示例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();
}
 
开发者ID:biezhihua,项目名称:Android_OpenGL_Demo,代码行数:63,代码来源:Cube.java

示例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();
}
 
开发者ID:biezhihua,项目名称:Android_OpenGL_Demo,代码行数:76,代码来源:Cube.java

示例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();
    }
}
 
开发者ID:biezhihua,项目名称:Android_OpenGL_Demo,代码行数:79,代码来源:LessonSevenRenderer.java

示例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);
	}

}
 
开发者ID:regar007,项目名称:ShapesInOpenGLES2.0,代码行数:76,代码来源:ShapeRenderer.java

示例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();
}
 
开发者ID:biezhihua,项目名称:Android_OpenGL_Demo,代码行数:59,代码来源:LessonTwoRenderer.java


注:本文中的android.opengl.Matrix.translateM方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。