Skip to content Skip to sidebar Skip to footer

How To Rotate A Texture In A Shader, Android

So I have a texture I want to rotate given the angle rotation. Here are my UV coordinates float[] landscapeVerts = { // X, Y, Z, U, V -ratio, -1.0f, z_0, 1.0f, 0.0f, ra

Solution 1:

I figured it out. Just need to change the order of operation.

float[] identityMatrix = newfloat[16];
Matrix.setIdentityM(identityMatrix, 0); //start with identity matrix
Matrix.translateM(mProjMatrix,0,identityMatrix, 0, 0.5f,0.5f,0.0f); // move back to [0 1] range
Matrix.rotateM(identityMatrix, 0, mProjMatrix, 0, rotation, 0.0f,0.0f,1.0f); // rotate about z axis
Matrix.translateM(mProjMatrix,0, identityMatrix, 0, -0.5f,-0.5f,0.0f); // move center to center [0 1] : [-.5 .5]

Instead of moving to the center, rotating, and moving back; we build the matrix in reverse -> move back, rotate, and then move to center.

Post a Comment for "How To Rotate A Texture In A Shader, Android"