本文整理汇总了Java中android.opengl.Matrix.multiplyMM方法的典型用法代码示例。如果您正苦于以下问题:Java Matrix.multiplyMM方法的具体用法?Java Matrix.multiplyMM怎么用?Java Matrix.multiplyMM使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.opengl.Matrix
的用法示例。
在下文中一共展示了Matrix.multiplyMM方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: draw
import android.opengl.Matrix; //导入方法依赖的package包/类
private void draw(float[] cameraView, float[] cameraPerspective) {
// Build the ModelView and ModelViewProjection matrices
// for calculating cube position and light.
Matrix.multiplyMM(mModelViewMatrix, 0, cameraView, 0, mModelMatrix, 0);
Matrix.multiplyMM(mModelViewProjectionMatrix, 0, cameraPerspective, 0, mModelViewMatrix, 0);
// Set the position of the plane
mVertexBuffer.rewind();
GLES20.glVertexAttribPointer(
mPlaneXZPositionAlphaAttribute, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false,
BYTES_PER_FLOAT * COORDS_PER_VERTEX, mVertexBuffer);
// Set the Model and ModelViewProjection matrices in the shader.
GLES20.glUniformMatrix4fv(mPlaneModelUniform, 1, false, mModelMatrix, 0);
GLES20.glUniformMatrix4fv(
mPlaneModelViewProjectionUniform, 1, false, mModelViewProjectionMatrix, 0);
mIndexBuffer.rewind();
GLES20.glDrawElements(GLES20.GL_TRIANGLE_STRIP, mIndexBuffer.limit(),
GLES20.GL_UNSIGNED_SHORT, mIndexBuffer);
ShaderUtil.checkGLError(TAG, "Drawing plane");
}
示例2: drawLight
import android.opengl.Matrix; //导入方法依赖的package包/类
/**
* Draws a point representing the position of the light.
*/
private void drawLight() {
final int pointMVPMatrixHandle = GLES20.glGetUniformLocation(mPointProgramHandle, "u_MVPMatrix");
final int pointPositionHandle = GLES20.glGetAttribLocation(mPointProgramHandle, "a_Position");
// Pass in the position.
GLES20.glVertexAttrib3f(pointPositionHandle, mLightPosInModelSpace[0], mLightPosInModelSpace[1], mLightPosInModelSpace[2]);
// Since we are not using a buffer object, disable vertex arrays for this attribute.
GLES20.glDisableVertexAttribArray(pointPositionHandle);
// Pass in the transformation matrix.
Matrix.multiplyMM(mMVPMatrix, 0, mViewMatrix, 0, mLightModelMatrix, 0);
Matrix.multiplyMM(mMVPMatrix, 0, mProjectionMatrix, 0, mMVPMatrix, 0);
GLES20.glUniformMatrix4fv(pointMVPMatrixHandle, 1, false, mMVPMatrix, 0);
// Draw the point.
GLES20.glDrawArrays(GLES20.GL_POINTS, 0, 1);
}
示例3: drawLight
import android.opengl.Matrix; //导入方法依赖的package包/类
/**
* Draws a point representing the position of the light.
*/
private void drawLight()
{
final int pointMVPMatrixHandle = GLES20.glGetUniformLocation(mPointProgramHandle, "u_MVPMatrix");
final int pointPositionHandle = GLES20.glGetAttribLocation(mPointProgramHandle, "a_Position");
// Pass in the position.
GLES20.glVertexAttrib3f(pointPositionHandle, mLightPosInModelSpace[0], mLightPosInModelSpace[1], mLightPosInModelSpace[2]);
// Since we are not using a buffer object, disable vertex arrays for this attribute.
GLES20.glDisableVertexAttribArray(pointPositionHandle);
// Pass in the transformation matrix.
Matrix.multiplyMM(mMVPMatrix, 0, mViewMatrix, 0, mLightModelMatrix, 0);
Matrix.multiplyMM(mMVPMatrix, 0, mProjectionMatrix, 0, mMVPMatrix, 0);
GLES20.glUniformMatrix4fv(pointMVPMatrixHandle, 1, false, mMVPMatrix, 0);
// Draw the point.
GLES20.glDrawArrays(GLES20.GL_POINTS, 0, 1);
}
示例4: setupRightEye
import android.opengl.Matrix; //导入方法依赖的package包/类
private void setupRightEye() {
Matrix.setLookAtM(mCamera, 0, mRightEyePos[0], mRightEyePos[1], mRightEyePos[2], 0.0f, 0.0f, -SCREEN_FAR, 0.0f, 1.0f, 0.0f);
if (HEAD_TRACKING) Matrix.rotateM(mCamera, 0, (float)mOrientation*90.0f, 0.0f, 0.0f, -1.0f);
Matrix.multiplyMM(mMVP, 0, mCamera, 0, mHeadTransform, 0);
Matrix.multiplyMM(mMVP, 0, mPersp, 0, mMVP, 0);
GLES20.glDisable(GLES20.GL_BLEND);
if (getEffectMode() == VideoEffect.ANAGLYPH_MODE) {
mColorFilter = RED_COLOR_FILTER;
}
GLES20.glScissor(mViewWidth/2, 0, mViewWidth/2, mViewHeight);
GLES20.glViewport(mViewWidth / 2, 0, mViewWidth / 2, mViewHeight);
if (CHECK_GL_ERRORS) OpenGLUtils.checkGlError("glViewport");
GLES20.glVertexAttribPointer(mTexCoordHandle, 2, GLES20.GL_FLOAT,
false, 0, mVideoTextureCoordRight);
if (CHECK_GL_ERRORS) OpenGLUtils.checkGlError("glVertexAttribPointer");
}
示例5: onSurfaceChanged
import android.opengl.Matrix; //导入方法依赖的package包/类
public void onSurfaceChanged (GL10 gl, int width, int height) {
// We need to know the current width and height
mScreenWidth = width;
mScreenHeight = height;
// Redo the Viewport, making it fullscreen
GLES20.glViewport(0, 0, (int)mScreenWidth, (int)mScreenHeight);
// Clear our matrices
for(int i=0;i<16;i++)
{
mtrxProjection[i] = 0.0f;
mtrxView[i] = 0.0f;
mtrxProjectionAndView[i] = 0.0f;
}
// Setup our screen width and height for normal sprite translation.
Matrix.orthoM(mtrxProjection, 0, 0f, mScreenWidth, 0.0f, mScreenHeight, 0, 50);
// Set the camera position (View matrix)
Matrix.setLookAtM(mtrxView, 0, 0f, 0f, 1f, 0f, 0f, 0f, 0f, 1.0f, 0.0f);
// Calculate the projection and view transformation
Matrix.multiplyMM(mtrxProjectionAndView, 0, mtrxProjection, 0, mtrxView, 0);
// Without this line of code, nothing appear on the screen TODO: Why?
// The only part of this that seems to be necessary is the instatiation of a new GameObject
BaseObject.renderSystem.generateTextures(mContext);
}
示例6: gluPerspective
import android.opengl.Matrix; //导入方法依赖的package包/类
public static void gluPerspective(float[] m,
float angle,float aspect,float near,float far) {
float top=near*(float)Math.tan(angle*(Math.PI/360.0));
float bottom=-top;
float left=bottom*aspect;
float right=top*aspect;
float[] frustumM=new float[16];
float[] resultM=new float[16];
Matrix.frustumM(frustumM,0,left,right,bottom,top,near,far);
Matrix.multiplyMM(resultM,0,m,0,frustumM,0);
System.arraycopy(resultM,0,m,0,16);
}
示例7: drawCube
import android.opengl.Matrix; //导入方法依赖的package包/类
/**
* Draws a cube.
*/
private void drawCube() {
// Pass in the position information
mCubePositions.position(0);
GLES20.glVertexAttribPointer(mPositionHandle, mPositionDataSize, GLES20.GL_FLOAT, false,
0, mCubePositions);
GLES20.glEnableVertexAttribArray(mPositionHandle);
// Pass in the normal information
mCubeNormals.position(0);
GLES20.glVertexAttribPointer(mNormalHandle, mNormalDataSize, GLES20.GL_FLOAT, false,
0, mCubeNormals);
GLES20.glEnableVertexAttribArray(mNormalHandle);
// 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(mMVPMatrix, 0, mProjectionMatrix, 0, mMVPMatrix, 0);
// 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]);
// Draw the cube.
GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, 36);
}
示例8: getFinalMatrix
import android.opengl.Matrix; //导入方法依赖的package包/类
/**
* 计算产生总变换矩阵
* @return 总变换矩阵
*/
public static float[] getFinalMatrix(){
//摄像机矩阵乘以变换矩阵
Matrix.multiplyMM(mMVPMatrix , 0 , mVMatrix , 0 , currMatrix , 0);
//投影矩阵乘以上一步的结果矩阵
Matrix.multiplyMM(mMVPMatrix , 0 , mProjMatrix , 0 , mMVPMatrix , 0);
return mMVPMatrix;
}
示例9: onDrawFrame
import android.opengl.Matrix; //导入方法依赖的package包/类
@Override
public void onDrawFrame(GL10 gl) {
final long actionTime = System.currentTimeMillis();
// Log.w("ceshi", "onDrawFrame===");
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);// 清除屏幕和深度缓存
float[] mtx = new float[16];
mSurface.getTransformMatrix(mtx);
mCameraMatrix.draw(mtx);
// Set the camera position (View matrix)
Matrix.setLookAtM(mVMatrix, 0, 0, 0, -3, 0f, 0f, 0f, 0f, 1f, 0f);
// Calculate the projection and view transformation
Matrix.multiplyMM(mMVPMatrix, 0, mProjMatrix, 0, mVMatrix, 0);
mPointsMatrix.draw(mMVPMatrix);
if (isDebug) {
runOnUiThread(new Runnable() {
@Override
public void run() {
final long endTime = System.currentTimeMillis() - actionTime;
debugPrinttext.setText("printTime: " + endTime);
}
});
}
mSurface.updateTexImage();// 更新image,会调用onFrameAvailable方法
if (isStartRecorder) {
flip = !flip;
if (flip) { // ~30fps
synchronized (this) {
// mMediaHelper.frameAvailable(mtx);
mMediaHelper.frameAvailable(mtx);
}
}
}
}
示例10: GraphGLRenderer
import android.opengl.Matrix; //导入方法依赖的package包/类
/** Create a renderer that draws a given duration of time. */
public GraphGLRenderer(Context ctx, int durationSec) {
this.ctx = ctx;
this.durationSec = durationSec;
// Set up the view matrix, projection, then combine to make MVP matrix
float[] mViewMatrix = new float[16];
float[] mProjectionMatrix = new float[16];
Matrix.setLookAtM(mViewMatrix, 0, 0, 0, -3, 0f, 0f, 0f, 0f, 1.0f, 0.0f);
Matrix.frustumM(mProjectionMatrix, 0, -1, 1, -1, 1, 3, 7);
Matrix.multiplyMM(mMVPMatrix, 0, mProjectionMatrix, 0, mViewMatrix, 0);
}
示例11: updateModelMatrix
import android.opengl.Matrix; //导入方法依赖的package包/类
/**
* Updates the object model matrix and applies scaling.
*
* @param modelMatrix A 4x4 model-to-world transformation matrix, stored in column-major order.
* @param scaleFactor A separate scaling factor to apply before the {@code modelMatrix}.
* @see android.opengl.Matrix
*/
public void updateModelMatrix(float[] modelMatrix, float scaleFactor) {
float[] scaleMatrix = new float[16];
Matrix.setIdentityM(scaleMatrix, 0);
scaleMatrix[0] = scaleFactor;
scaleMatrix[5] = scaleFactor;
scaleMatrix[10] = scaleFactor;
Matrix.multiplyMM(mModelMatrix, 0, modelMatrix, 0, scaleMatrix, 0);
}
示例12: drawCube
import android.opengl.Matrix; //导入方法依赖的package包/类
/**
* Draws a cube.
*/
private void drawCube() {
// Pass in the position information.
mCubePositions.position(0);
GLES20.glVertexAttribPointer(
mPositionHandle,
mPositionDataSize,
GLES20.GL_FLOAT,
false,
0,
mCubePositions
);
GLES20.glEnableVertexAttribArray(mPositionHandle);
// Pass in the color information
mCubeColors.position(0);
GLES20.glVertexAttribPointer(
mColorHandle,
mColorDataSize,
GLES20.GL_FLOAT,
false,
0, mCubeColors
);
GLES20.glEnableVertexAttribArray(mColorHandle);
// Pass in the normal information
mCubeNormals.position(0);
GLES20.glVertexAttribPointer(
mNormalHandle,
mNormalDataSize,
GLES20.GL_FLOAT,
false,
0,
mCubeNormals
);
GLES20.glEnableVertexAttribArray(mNormalHandle);
// This multiplies the view matrix by the model matrix
// and stores the result the MVP matrix.
// which currently contains model * view.
Matrix.multiplyMM(mMVPMatrix, 0, mViewMatrix, 0, mModelMatrix, 0);
// Pass in the model view matrix
GLES20.glUniformMatrix4fv(mMVMatrixHandle, 1, false, mMVPMatrix, 0);
// This multiplies the model view matrix by the projection matrix,
// and stores the result in the MVP matrix.
// which now contains model * view * projection.
Matrix.multiplyMM(mMVPMatrix, 0, mProjectionMatrix, 0, mMVPMatrix, 0);
// 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]);
// Draw the cube.
GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, 36);
}
示例13: onDrawFrame
import android.opengl.Matrix; //导入方法依赖的package包/类
public void onDrawFrame(GL10 unused) {
// Redraw background color
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);
// Position the eye behind the origin.
final float eyeX = 0.0f;
final float eyeY = 0.0f;
final float eyeZ = 1.5f;
// We are looking toward the distance
final float lookX = 0.0f;
final float lookY = 0.0f;
final float lookZ = -5.0f;
// Set our up vector. This is where our head would be pointing were we holding the camera.
final float upX = 0.0f;
final float upY = 1.0f;
final float upZ = 0.0f;
// Draw the triangle facing straight on.
Matrix.setIdentityM(mModelMatrix, 0);
Matrix.rotateM(mModelMatrix, 0, angleInDegrees, 0.0f, 0.0f, 1.0f);
// Set the view matrix. This matrix can be said to represent the camera position.
// NOTE: In OpenGL 1, a ModelView matrix is used, which is a combination of a model and
// view matrix. In OpenGL 2, we can keep track of these matrices separately if we choose.
// Matrix.setLookAtM(mViewMatrix, 0, eyeX, eyeY, eyeZ, lookX, lookY, lookZ, upX, upY, upZ);
// Set the camera position (View matrix)
Matrix.setLookAtM(mViewMatrix, 0, 0, 0, -5, 0f, 0f, 0f, 0f, 1.0f, 0.0f);
// 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);
// 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(mMVPMatrix, 0, mProjectionMatrix, 0, mMVPMatrix, 0);
mSquare.draw(mMVPMatrix);
mTriangle.draw(mMVPMatrix);
}
示例14: onDrawFrame
import android.opengl.Matrix; //导入方法依赖的package包/类
@Override
public void onDrawFrame(GL10 unused) {
// Update the spin animation.
long now = System.currentTimeMillis();
float deltaT = Math.min((now - lastFrameTime) * 0.001f, 0.1f);
lastFrameTime = now;
angleDegrees += deltaT * MODEL_ROTATION_SPEED_DPS;
// Draw background color.
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
// Make a model matrix that rotates the model about the Y axis so it appears to spin.
Matrix.setRotateM(modelMatrix, 0, angleDegrees, 0, 1, 0);
// Set the camera position (View matrix)
Matrix.setLookAtM(viewMatrix, 0,
// Camera position.
EYE_X, EYE_Y, EYE_Z,
// Point that the camera is looking at.
TARGET_X, TARGET_Y, TARGET_Z,
// The vector that defines which way is up.
UP_X, UP_Y, UP_Z);
// Calculate the MVP matrix (model-view-projection) by multiplying the model, view, and
// projection matrices together.
Matrix.multiplyMM(tmpMatrix, 0, viewMatrix, 0, modelMatrix, 0); // V * M
Matrix.multiplyMM(mvpMatrix, 0, projMatrix, 0, tmpMatrix, 0); // P * V * M
// objectToRender is volatile, so we capture it in a local variable.
RawObject obj = objectToRender;
if (readyToRender) {
// We're ready to render, so just render using our existing VBOs and IBO.
myShader.render(mvpMatrix, indexCount, ibo, positionsVbo, colorsVbo);
} else if (obj != null) {
// The object is ready, but we haven't consumed it yet. We need to create the VBOs and IBO
// to render the object.
indexCount = obj.indexCount;
ibo = MyGLUtils.createIbo(obj.indices);
positionsVbo = MyGLUtils.createVbo(obj.positions);
colorsVbo = MyGLUtils.createVbo(obj.colors);
// Now we're ready to render the object.
readyToRender = true;
Log.d(TAG, "VBOs/IBO created. Now ready to render object.");
}
}
示例15: onDrawFrame
import android.opengl.Matrix; //导入方法依赖的package包/类
@Override
public void onDrawFrame(GL10 unused) {
angle = ((float) SystemClock.elapsedRealtime() - startTime) * 0.02f;
GLES20.glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
Matrix.setLookAtM(mViewMatrix, 0,
0, 0, -4,
0f, 0f, 0f,
0f, 1.0f, 0.0f);
Matrix.multiplyMM(mMVPMatrix, 0, mProjectionMatrix, 0, mViewMatrix, 0);
Matrix.rotateM(mMVPMatrix, 0, angle, 1.f, 1.f, 1.f);
GLES20.glUseProgram(shaderProgram);
int positionHandle = GLES20.glGetAttribLocation(shaderProgram, "vPosition");
GLES20.glVertexAttribPointer(positionHandle, 3,
GLES20.GL_FLOAT, false,
3 * 4, vertexBuffer);
int colorHandle = GLES20.glGetAttribLocation(shaderProgram, "aColor");
GLES20.glVertexAttribPointer(colorHandle, 4,
GLES20.GL_FLOAT, false,
4 * 4, colorBuffer);
int mMVPMatrixHandle = GLES20.glGetUniformLocation(shaderProgram, "uMVPMatrix");
GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mMVPMatrix, 0);
GLES20.glEnable(GLES20.GL_DEPTH_TEST);
GLES20.glEnableVertexAttribArray(colorHandle);
GLES20.glEnableVertexAttribArray(positionHandle);
GLES20.glDrawElements(
GLES20.GL_TRIANGLES, index.length,
GLES20.GL_UNSIGNED_SHORT, indexBuffer);
GLES20.glDisableVertexAttribArray(positionHandle);
GLES20.glDisableVertexAttribArray(colorHandle);
GLES20.glDisable(GLES20.GL_DEPTH_TEST);
}