PDA

View Full Version : Android OpenGL ES 2.0 rotation

zippy1
04-05-2013, 05:23 PM
Hey all,

I got a small problem with my Open GL ES 2.0 rotation (I'm developing this for Android).

When I rotate by a positive angle (say +45 degrees for example), it rotates anti-clockwise

Any reason for this?!

Thanks guys & girls!!

"uniform mat4 uMVPMatrix;" +
"uniform mat4 uRotate;" +
"attribute vec4 a_position;\n"+
"attribute vec2 a_texCoords;" +
"varying vec2 v_texCoords;" +
"void main()\n" +
"{\n" +
"gl_Position = uMVPMatrix * a_position;\n"+
"v_texCoords = a_texCoords;" +
"}";

"precision mediump float;" +
"varying vec2 v_texCoords;" +
"uniform sampler2D u_baseMap;" +
"void main()" +
"{" +
"gl_FragColor = texture2D(u_baseMap, v_texCoords);" +
"}";

Then in my onSurfaceChanged:

float ratio = (float) width / height;
Matrix.frustumM(mProjMatrix, 0, -ratio, ratio, -1, 1, 3, 7);

In onDrawFrame:

// Set the camera position (View matrix) so looking from the front
Matrix.setLookAtM(mVMatrix, 0, 0, 0, 3, 0f, 0f, 0f, 0f, 1.0f, 0.0f);

// Calculate the projection and view transformation and store results in mMVPMatrix, 0, mProjMatrix, 0, mVMatrix, 0
Matrix.multiplyMM(mMVPMatrix, 0, mProjMatrix, 0, mVMatrix, 0);

And also my rotation matrix transformations:

Matrix.setRotateM(mRotationMatrix, 0, angle, 0, 0, 0.1f);

Matrix.translateM(mRotationMatrix, 0, 0, 0, -1f);

// Combine the rotation matrix with the projection and camera view
Matrix.multiplyMM(mvpMatrix2, 0, mRotationMatrix, 0, mvpMatrix, 0);

My vertices are like so:

float[] vertices = {

-.5f,.5f,0, 0,0,
.5f,.5f,0, 1,0,
-.5f,-.5f,0, 0,1,
.5f,-.5f,0, 1,1

}

Thank you all ;)