當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。