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


Java Matrix.multiplyMV方法代码示例

本文整理汇总了Java中android.opengl.Matrix.multiplyMV方法的典型用法代码示例。如果您正苦于以下问题:Java Matrix.multiplyMV方法的具体用法?Java Matrix.multiplyMV怎么用?Java Matrix.multiplyMV使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.opengl.Matrix的用法示例。


在下文中一共展示了Matrix.multiplyMV方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setRotationDelta

import android.opengl.Matrix; //导入方法依赖的package包/类
public void setRotationDelta(float deltaX, float deltaY) {

        float[] centerVector = new float[4];
        float[] center = mTriMesh.getCenter();
        centerVector[0] = center[0];
        centerVector[1] = center[1];
        centerVector[2] = center[2];
        centerVector[3] = 1.0f;

        //convert vector to be in camera space
        Matrix.multiplyMV(centerVector, 0, mModelViewMatrix, 0, centerVector, 0);

        float[] translationMatrix = new float[16];
        float[] rotationMatrix = new float[16];
        float[] reversedTranslationMatrix = new float[16];

        Matrix.setIdentityM(translationMatrix, 0);
        Matrix.translateM(translationMatrix, 0, -centerVector[0], -centerVector[1], -centerVector[2]);

        Matrix.setIdentityM(rotationMatrix, 0);
        Matrix.rotateM(rotationMatrix, 0, deltaX, 0.0f, 1.0f, 0.0f);
        Matrix.rotateM(rotationMatrix, 0, deltaY, 1.0f, 0.0f, 0.0f);

        Matrix.setIdentityM(reversedTranslationMatrix, 0);
        Matrix.translateM(reversedTranslationMatrix, 0, centerVector[0], centerVector[1], centerVector[2]);

        Matrix.multiplyMM(mModelViewMatrix, 0, translationMatrix, 0, mModelViewMatrix, 0);

        Matrix.multiplyMM(mModelViewMatrix, 0, rotationMatrix, 0, mModelViewMatrix, 0);

        Matrix.multiplyMM(mModelViewMatrix, 0, reversedTranslationMatrix, 0, mModelViewMatrix, 0);
    }
 
开发者ID:WissamElkadi,项目名称:TriMeshKit,代码行数:33,代码来源:RenderingShader.java

示例2: transformTextureCoordinates

import android.opengl.Matrix; //导入方法依赖的package包/类
/**
 * 图像旋转
 */
private float[] transformTextureCoordinates(float[] coords, float[] matrix) {
	float[] result = new float[coords.length];
	float[] vt = new float[4];

	for (int i = 0; i < coords.length; i += 2) {
		float[] v = { coords[i], coords[i + 1], 0, 1 };
		// for (int j = 0; j < v.length; j ++) {
		// Log.w("ceshi", "v[" + j + "]======" + coords[j]);
		// }
		Matrix.multiplyMV(vt, 0, matrix, 0, v, 0);
		result[i] = vt[0];// x轴镜像
		// result[i + 1] = vt[1];y轴镜像
		result[i + 1] = coords[i + 1];
	}
	//
	// for (int i = 0; i < coords.length; i ++) {
	// Log.w("ceshi", "coords[" + i + "]======" + coords[i]);
	// }
	//
	// for (int i = 0; i < result.length / 2; i ++) {
	// Log.w("ceshi", "result[" + i + "]======" + result[i]);
	// }

	// [0.0, 1.0, 1.0, 1.0]; v
	// [0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0]; coords
	// [1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0]; result

	return result;
}
 
开发者ID:FacePlusPlus,项目名称:MegviiFacepp-Android-SDK,代码行数:33,代码来源:CameraMatrix.java

示例3: 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

示例4: 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(program);

    // Set program handles for cube drawing.
    mvpMatrixUniform = GLES20.glGetUniformLocation(program, MVP_MATRIX_UNIFORM);
    mvMatrixUniform = GLES20.glGetUniformLocation(program, MV_MATRIX_UNIFORM);
    lightPosUniform = GLES20.glGetUniformLocation(program, LIGHT_POSITION_UNIFORM);
    positionAttribute = GLES20.glGetAttribLocation(program, POSITION_ATTRIBUTE);
    normalAttribute = GLES20.glGetAttribLocation(program, NORMAL_ATTRIBUTE);
    colorAttribute = GLES20.glGetAttribLocation(program, COLOR_ATTRIBUTE);

    // Calculate position of the light. Push into the distance.
    Matrix.setIdentityM(lightModelMatrix, 0);
    Matrix.translateM(lightModelMatrix, 0, 0.0f, 7.5f, -8.0f);

    Matrix.multiplyMV(lightPosInWorldSpace, 0, lightModelMatrix, 0, lightPosInModelSpace, 0);
    Matrix.multiplyMV(lightPosInEyeSpace, 0, viewMatrix, 0, lightPosInWorldSpace, 0);

    // Draw the heightmap.
    // Translate the heightmap into the screen.
    Matrix.setIdentityM(modelMatrix, 0);
    Matrix.translateM(modelMatrix, 0, 0.0f, 0.0f, -12f);

    // Set a matrix that contains the current rotation.
    Matrix.setIdentityM(currentRotation, 0);
    Matrix.rotateM(currentRotation, 0, deltaX, 0.0f, 1.0f, 0.0f);
    Matrix.rotateM(currentRotation, 0, deltaY, 1.0f, 0.0f, 0.0f);
    deltaX = 0.0f;
    deltaY = 0.0f;

    // Multiply the current rotation by the accumulated rotation, and then
    // set the accumulated rotation to the result.
    Matrix.multiplyMM(temporaryMatrix, 0, currentRotation, 0, accumulatedRotation, 0);
    System.arraycopy(temporaryMatrix, 0, accumulatedRotation, 0, 16);

    // Rotate the cube taking the overall rotation into account.
    Matrix.multiplyMM(temporaryMatrix, 0, modelMatrix, 0, accumulatedRotation, 0);
    System.arraycopy(temporaryMatrix, 0, modelMatrix, 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(mvpMatrix, 0, viewMatrix, 0, modelMatrix, 0);

    // Pass in the modelview matrix.
    GLES20.glUniformMatrix4fv(mvMatrixUniform, 1, false, mvpMatrix, 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(temporaryMatrix, 0, projectionMatrix, 0, mvpMatrix, 0);
    System.arraycopy(temporaryMatrix, 0, mvpMatrix, 0, 16);

    // Pass in the combined matrix.
    GLES20.glUniformMatrix4fv(mvpMatrixUniform, 1, false, mvpMatrix, 0);

    // Pass in the light position in eye space.
    GLES20.glUniform3f(lightPosUniform, lightPosInEyeSpace[0], lightPosInEyeSpace[1], lightPosInEyeSpace[2]);

    // Render the heightmap.
    heightMap.render();
}
 
开发者ID:biezhihua,项目名称:Android_OpenGL_Demo,代码行数:67,代码来源:LessonEightRenderer.java

示例5: 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

示例6: 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

示例7: 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

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

	// Set our per-vertex lighting program.
	GLES20.glUseProgram(program);

	// Set program handles for cube drawing.
	mvpMatrixUniform = GLES20.glGetUniformLocation(program, MVP_MATRIX_UNIFORM);
	mvMatrixUniform = GLES20.glGetUniformLocation(program, MV_MATRIX_UNIFORM);
	lightPosUniform = GLES20.glGetUniformLocation(program, LIGHT_POSITION_UNIFORM);
	positionAttribute = GLES20.glGetAttribLocation(program, POSITION_ATTRIBUTE);
	normalAttribute = GLES20.glGetAttribLocation(program, NORMAL_ATTRIBUTE);
	colorAttribute = GLES20.glGetAttribLocation(program, COLOR_ATTRIBUTE);

	// Calculate position of the light. Push into the distance.
	Matrix.setIdentityM(lightModelMatrix, 0);
	Matrix.translateM(lightModelMatrix, 0, 0.0f, 7.5f, -8.0f);

	Matrix.multiplyMV(lightPosInWorldSpace, 0, lightModelMatrix, 0, lightPosInModelSpace, 0);
	Matrix.multiplyMV(lightPosInEyeSpace, 0, viewMatrix, 0, lightPosInWorldSpace, 0);

	// Draw the heightmap.
	// Translate the heightmap into the screen.
	Matrix.setIdentityM(modelMatrix, 0);
	Matrix.translateM(modelMatrix, 0, 0.0f, 0.0f, -12f);

	// Set a matrix that contains the current rotation.
	Matrix.setIdentityM(currentRotation, 0);
	Matrix.rotateM(currentRotation, 0, deltaX, 0.0f, 1.0f, 0.0f);
	Matrix.rotateM(currentRotation, 0, deltaY, 1.0f, 0.0f, 0.0f);
	deltaX = 0.0f;
	deltaY = 0.0f;

	// Multiply the current rotation by the accumulated rotation, and then
	// set the accumulated rotation to the result.
	Matrix.multiplyMM(temporaryMatrix, 0, currentRotation, 0, accumulatedRotation, 0);
	System.arraycopy(temporaryMatrix, 0, accumulatedRotation, 0, 16);

	// Rotate the cube taking the overall rotation into account.
	Matrix.multiplyMM(temporaryMatrix, 0, modelMatrix, 0, accumulatedRotation, 0);
	System.arraycopy(temporaryMatrix, 0, modelMatrix, 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(mvpMatrix, 0, viewMatrix, 0, modelMatrix, 0);

	// Pass in the modelview matrix.
	GLES20.glUniformMatrix4fv(mvMatrixUniform, 1, false, mvpMatrix, 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(temporaryMatrix, 0, projectionMatrix, 0, mvpMatrix, 0);
	System.arraycopy(temporaryMatrix, 0, mvpMatrix, 0, 16);

	// Pass in the combined matrix.
	GLES20.glUniformMatrix4fv(mvpMatrixUniform, 1, false, mvpMatrix, 0);

	// Pass in the light position in eye space.
	GLES20.glUniform3f(lightPosUniform, lightPosInEyeSpace[0], lightPosInEyeSpace[1], lightPosInEyeSpace[2]);

	// Render the heightmap.
	heightMap.render();
}
 
开发者ID:biezhihua,项目名称:Android_OpenGL_Demo,代码行数:67,代码来源:LessonEightRenderer.java

示例9: 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(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");
       mColorHandle = GLES20.glGetAttribLocation(mProgramHandle, "a_Color");
       mNormalHandle = GLES20.glGetAttribLocation(mProgramHandle, "a_Normal"); 
       mTextureCoordinateHandle = GLES20.glGetAttribLocation(mProgramHandle, "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 this 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);                        
       
       // 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,代码行数:70,代码来源:LessonFourRenderer.java

示例10: 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,代码行数:80,代码来源:LessonSevenRenderer.java

示例11: 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


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