當前位置: 首頁>>代碼示例>>Java>>正文


Java Matrix類代碼示例

本文整理匯總了Java中android.opengl.Matrix的典型用法代碼示例。如果您正苦於以下問題:Java Matrix類的具體用法?Java Matrix怎麽用?Java Matrix使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Matrix類屬於android.opengl包,在下文中一共展示了Matrix類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

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

    if (scene != null) {
        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, 0.8f, 2.f, 1.f);

        GLES20.glUseProgram(shaderProgram);

        int mMVPMatrixHandle = GLES20.glGetUniformLocation(shaderProgram, "uMVPMatrix");
        GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mMVPMatrix, 0);

        scene.render(shaderProgram, "vPosition", "aColor");
    }
}
 
開發者ID:PacktPublishing,項目名稱:Building-Android-UIs-with-Custom-Views,代碼行數:24,代碼來源:GLDrawer.java

示例2: gluLookAt

import android.opengl.Matrix; //導入依賴的package包/類
public static void gluLookAt(float[] m,
                             float eyeX,float eyeY,float eyeZ,
                             float focusX,float focusY,float focusZ,
                             float upX,float upY,float upZ) {
    float[] lookAtM=new float[16];
    float[] resultM=new float[16];
    Matrix.setLookAtM(lookAtM,0,
            eyeX,eyeY,eyeZ,focusX,focusY,focusZ,upX,upY,upZ);
    Matrix.multiplyMM(resultM,0,m,0,lookAtM,0);
    System.arraycopy(resultM,0,m,0,16);
}
 
開發者ID:jphacks,項目名稱:TK_1701,代碼行數:12,代碼來源:GLES.java

示例3: initViewMatrix

import android.opengl.Matrix; //導入依賴的package包/類
private void initViewMatrix() {
    // Position the eye in front of the origin
    final float eyeX = 0.0f;
    final float eyeY = 0.0f;
    final float eyeZ = 0f;

    // 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;

    // Set the view matrix.
    // This matrix can be said to represent the camera position,
    Matrix.setLookAtM(mViewMatrix, 0,
            eyeX, eyeY, eyeZ,
            lookX, lookY, lookZ,
            upX, upY, upZ);
}
 
開發者ID:biezhihua,項目名稱:Android_OpenGL_Demo,代碼行數:26,代碼來源:Cube.java

示例4: 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);
}
 
開發者ID:biezhihua,項目名稱:Android_OpenGL_Demo,代碼行數:23,代碼來源:LessonFourRenderer.java

示例5: onSurfaceChanged

import android.opengl.Matrix; //導入依賴的package包/類
@Override
public void onSurfaceChanged(GL10 glUnused, int width, int height) {
    // Set the OpenGL viewport to the same size as the surface.
    GLES20.glViewport(0, 0, width, height);

    // Create a new perspective projection matrix. The height will stay the same
    // while the width will vary as per aspect ratio.
    final float ratio = (float) width / height;
    final float left = -ratio;
    final float right = ratio;
    final float bottom = -1.0f;
    final float top = 1.0f;
    final float near = 1.0f;
    final float far = 10.0f;

    Matrix.frustumM(mProjectionMatrix, 0, left, right, bottom, top, near, far);
}
 
開發者ID:victordiaz,項目名稱:phonk,代碼行數:18,代碼來源:LessonOneRenderer.java

示例6: _drawBox

import android.opengl.Matrix; //導入依賴的package包/類
private void _drawBox(float x, float y, float sx, float sy, float r, float g, float b, float a, int tex){
    // scale and translate
  	float[] m = new float[16];
  	Matrix.setIdentityM(m, 0);
  	Matrix.scaleM(m, 0, 2.0f*sx, 2.0f*sy, 1.0f);
  	m[3] += (1.0-2.0*x);
  	m[7] += (1.0/_ratio-2.0*y);
  	//Log.v(TAG,"RATIO IS "+_ratio);
  	float[] m2 = new float[16];      	
  	Matrix.multiplyMM(m2, 0, m, 0, mMVPMatrix, 0);
  	if (tex == -1)
  		mSquare.draw(m2, r, g, b, a);
  	else
  		mSquareTex.draw(m2,r,g,b,a,tex);
    checkGlError("draw");
}
 
開發者ID:efroemling,項目名稱:bombsquad-remote-android,代碼行數:17,代碼來源:GLRenderer.java

示例7: draw

import android.opengl.Matrix; //導入依賴的package包/類
public final void draw(final int tex_id, final float[] tex_matrix, final float[] mvp_matrix) {
		synchronized (mSync) {
			if (mRequestRelease) return;
			mTexId = tex_id;
			if ((tex_matrix != null) && (tex_matrix.length >= 16)) {
				System.arraycopy(tex_matrix, 0, mMatrix, 0, 16);
			} else {
				Matrix.setIdentityM(mMatrix, 0);
			}
			if ((mvp_matrix != null) && (mvp_matrix.length >= 16)) {
				System.arraycopy(mvp_matrix, 0, mMatrix, 16, 16);
			} else {
				Matrix.setIdentityM(mMatrix, 16);
			}
			mRequestDraw++;
			mSync.notifyAll();
/*			try {
				mSync.wait();
			} catch (final InterruptedException e) {
			} */
		}
	}
 
開發者ID:FacePlusPlus,項目名稱:MegviiFacepp-Android-SDK,代碼行數:23,代碼來源:RenderHandler.java

示例8: 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);
}
 
開發者ID:biezhihua,項目名稱:Android_OpenGL_Demo,代碼行數:23,代碼來源:LessonTwoRenderer.java

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

示例10: testGetTranslationMatrix

import android.opengl.Matrix; //導入依賴的package包/類
@Test
public void testGetTranslationMatrix() throws Exception {
    Bitmap3DString o = new Bitmap3DString(font, string);
    o.setPositionX(2.0f);

    PowerMockito.doAnswer(new Answer<Object>() {
        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            float[] matrix = (float[])invocation.getArguments()[0];

            for(int counter = 0; counter < matrix.length; counter++) {
                matrix[counter] = 2.0f;
            }
            return null;
        }
    }).when(Matrix.class, "translateM", o.translationMatrix, 0, o.getPositionX(), o.getPositionY(), o.getPositionZ());

    float[] expected = { 2.0f, 2.0f, 2.0f, 2.0f, 2.0f, 2.0f, 2.0f, 2.0f, 2.0f, 2.0f, 2.0f, 2.0f, 2.0f, 2.0f, 2.0f, 2.0f };
    assertArrayEquals(expected, o.getTranslationMatrix(), 0);
}
 
開發者ID:snada,項目名稱:BitmapFontLoader,代碼行數:21,代碼來源:Bitmap3DStringTest.java

示例11: 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);
}
 
開發者ID:biezhihua,項目名稱:Android_OpenGL_Demo,代碼行數:22,代碼來源:Cube.java

示例12: onSurfaceChanged

import android.opengl.Matrix; //導入依賴的package包/類
@Override
public void onSurfaceChanged(GL10 glUnused, int width, int height) {
	// Set the OpenGL viewport to the same size as the surface.
	GLES20.glViewport(0, 0, width, height);

	// Create a new perspective projection matrix. The height will stay the
	// same while the width will vary as per aspect ratio.
	final float ratio = (float) width / height;
	final float left = -ratio;
	final float right = ratio;
	final float bottom = -1.0f;
	final float top = 1.0f;
	final float near = 1.0f;
	final float far = 1000.0f;

	Matrix.frustumM(projectionMatrix, 0, left, right, bottom, top, near, far);
}
 
開發者ID:biezhihua,項目名稱:Android_OpenGL_Demo,代碼行數:18,代碼來源:LessonEightRenderer.java

示例13: onSurfaceCreated

import android.opengl.Matrix; //導入依賴的package包/類
@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
    Log.d(TAG, "onSurfaceCreated");

    final CameraView cameraView = mCameraViewRef.get();
    if (cameraView != null) {
        cameraView.mGLSurfaceFilter = new GLSurfaceFilter();

        Matrix.setIdentityM(mMvpMatrix, 0);
        mTextureId = cameraView.mGLSurfaceFilter.createTexture();
        cameraView.mSurfaceTexture = new SurfaceTexture(mTextureId);
        cameraView.mSurfaceTexture.setOnFrameAvailableListener(cameraView);
        if (cameraView.mCameraSurfaceListener != null) {
            cameraView.mCameraSurfaceListener.onCameraSurfaceCreate(cameraView.mSurfaceTexture);
        }
    }
}
 
開發者ID:LeonHover,項目名稱:MediaCodecRecorder,代碼行數:18,代碼來源:CameraView.java

示例14: onSurfaceChanged

import android.opengl.Matrix; //導入依賴的package包/類
@Override
public void onSurfaceChanged(GL10 glUnused, int width, int height) {
	// Set the OpenGL viewport to the same size as the surface.
	GLES20.glViewport(0, 0, width, height);

	// Create a new perspective projection matrix. The height will stay the
	// same
	// while the width will vary as per aspect ratio.
	final float ratio = (float) width / height;
	final float left = -ratio;
	final float right = ratio;
	final float bottom = -1.0f;
	final float top = 1.0f;
	final float near = 1.0f;
	final float far = 10.0f;
	
	Matrix.frustumM(mProjectionMatrix, 0, left, right, bottom, top, near, far);
}
 
開發者ID:sdrausty,項目名稱:buildAPKsApps,代碼行數:19,代碼來源:GLLayer.java

示例15: 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(mTemporaryMatrix, 0, mProjectionMatrix, 0, mMVPMatrix, 0);
	System.arraycopy(mTemporaryMatrix, 0, mMVPMatrix, 0, 16);
	GLES20.glUniformMatrix4fv(pointMVPMatrixHandle, 1, false, mMVPMatrix, 0);
	
	// Draw the point.
	GLES20.glDrawArrays(GLES20.GL_POINTS, 0, 1);
}
 
開發者ID:biezhihua,項目名稱:Android_OpenGL_Demo,代碼行數:24,代碼來源:LessonSixRenderer.java


注:本文中的android.opengl.Matrix類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。