Project

General

Profile

« Previous | Next » 

Revision 35fd8f64

Added by Leszek Koltunski over 1 year ago

Implement the android.opengl.Matrix functions ourselves.

View differences:

src/main/java/org/distorted/examples/aroundtheworld/AroundTheWorldRendererPicker.java
30 30
import android.opengl.GLSurfaceView;
31 31
import android.opengl.Matrix;
32 32

  
33
import org.distorted.library.helpers.MatrixHelper;
34

  
33 35
///////////////////////////////////////////////////////////////////////////////////////////////////
34 36

  
35 37
class AroundTheWorldRendererPicker implements GLSurfaceView.Renderer
......
41 43
	private static final int COLOR_OFFSET       = 3;
42 44
	private static final int COLOR_DATA_SIZE    = 4;
43 45

  
44
  private float[] mModelMatrix      = new float[16];
45
	private float[] mViewMatrix       = new float[16];
46
	private float[] mProjectionMatrix = new float[16];
47
	private float[] mMVPTriangleMatrix= new float[16];
48
  private float[] mMVPSquareMatrix  = new float[16];
46
  private final float[] mModelMatrix      = new float[16];
47
	private final float[] mViewMatrix       = new float[16];
48
	private final float[] mProjectionMatrix = new float[16];
49
	private final float[] mMVPTriangleMatrix= new float[16];
50
  private final float[] mMVPSquareMatrix  = new float[16];
51
  private final float[] mTmpMatrix        = new float[16];
49 52

  
50 53
	private final FloatBuffer mTriangleVert, mSquareVert;
51 54

  
......
59 62

  
60 63
	AroundTheWorldRendererPicker()
61 64
	  {
62
	  Matrix.setIdentityM(mModelMatrix, 0);
65
	  MatrixHelper.setIdentity(mModelMatrix);
63 66

  
64 67
		final float[] triangleVertData = {
65 68
				      -0.865f, 1.5f, 0.0f,    1.0f, 1.0f, 1.0f, 1.0f,   // x,y,z,  r,g,b,a
......
237 240
		final float near   = 1.0f;
238 241
		final float far    = 2.0f;
239 242

  
240
		Matrix.frustumM(mProjectionMatrix, 0, left, right, bottom, top, near, far);
241
		Matrix.multiplyMM(mMVPTriangleMatrix, 0, mProjectionMatrix, 0, mViewMatrix, 0);
243
		MatrixHelper.frustum(mProjectionMatrix, left, right, bottom, top, near, far);
244
		MatrixHelper.multiply(mMVPTriangleMatrix, mProjectionMatrix, mViewMatrix);
242 245
	  }
243 246

  
244 247
///////////////////////////////////////////////////////////////////////////////////////////////////
......
268 271
    GLES31.glVertexAttribPointer(mColorH, COLOR_DATA_SIZE, GLES31.GL_FLOAT, false, STRIDE_BYTES, mSquareVert);
269 272
    GLES31.glEnableVertexAttribArray(mColorH);
270 273

  
271
    Matrix.multiplyMM(mMVPSquareMatrix, 0, mViewMatrix, 0, mModelMatrix, 0);
272
    Matrix.multiplyMM(mMVPSquareMatrix, 0, mProjectionMatrix, 0, mMVPSquareMatrix, 0);
274
    MatrixHelper.multiply(mTmpMatrix, mViewMatrix, mModelMatrix);
275
    MatrixHelper.multiply(mMVPSquareMatrix,  mProjectionMatrix, mTmpMatrix );
273 276

  
274 277
    GLES31.glUniformMatrix4fv(mMVPMatrixH, 1, false, mMVPSquareMatrix, 0);
275 278
		GLES31.glDrawArrays(GLES31.GL_TRIANGLE_STRIP, 0,4);

Also available in: Unified diff