本文整理汇总了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");
}
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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");
}
示例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) {
} */
}
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
}
}
示例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);
}
示例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);
}