Michael
Michael

Reputation: 1

3-D Rotation on any axis causes mesh skew on some but not all Android devices

I am currently working on developing a 3-D game engine for Android, and everything works fine on my Lenovo TAB 10, but rotation about any axis causes the meshes to flatten (skew) during the rotation. I don't know where to start looking since it works on one device. Any ideas?

I rotate everything around arbitrary axes (right, up, and forward) relative to the objects themselves. The rotated axes are then put into a rotation matrix as follows:

mMatRotate = new cMatrix4(
        mvRight.mX,     mvUp.mX,    mvForward.mX,   0.0f,
        mvRight.mY,     mvUp.mY,    mvForward.mY,   0.0f,
        mvRight.mZ,     mvUp.mZ,    mvForward.mZ,   0.0f,
        0.0f,           0.0f,       0.0f,           1.0f);

The actual matrix is defined as follows:

cMatrix4(   float a, float b, float c, float d,
            float e, float f, float g, float h,
            float i, float j, float k, float l,
            float m, float n, float o, float p )
{
    mfMatrixData[0] = a;    mfMatrixData[1] = b;    mfMatrixData[2] = c;    mfMatrixData[3] = d;
    mfMatrixData[4] = e;    mfMatrixData[5] = f;    mfMatrixData[6] = g;    mfMatrixData[7] = h;
    mfMatrixData[8] = i;    mfMatrixData[9] = j;    mfMatrixData[10] = k;   mfMatrixData[11] = l;
    mfMatrixData[12] = m;   mfMatrixData[13] = n;   mfMatrixData[14] = o;   mfMatrixData[15] = p;
}

Inside my draw() function looks like this:

Matrix.setIdentityM(mMesh.mModelMatrix, 0);
Matrix.translateM(mMesh.mModelMatrix, 0, mvLocation.mX, mvLocation.mY, mvLocation.mZ);
Matrix.scaleM(mMesh.mModelMatrix, 0, mfScale, mfScale, mfScale);
Matrix.multiplyMM(mMesh.mModelMatrix, 0, mMesh.mModelMatrix, 0, mMatRotate.getFloatArray(), 0);
mMesh.draw(viewMatrix, projMatrix, Renderer);

And the final transform looks like this:

Matrix.multiplyMM(mtrx, 0, viewMatrix, 0, mModelMatrix, 0);
GLES20.glUniformMatrix4fv(mMVMatrixHandle, 1, false, mtrx, 0);
Matrix.multiplyMM(mtrx, 0, projMatrix, 0, mtrx, 0);
GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mtrx, 0);

I'm kind of stuck on this one. Any suggestions would be helpful.

Upvotes: 0

Views: 53

Answers (1)

Michael
Michael

Reputation: 1

Okay, I solved the problem myself, and I'll post it here in case anyone else is interested or encounters a similar issue. It all comes down t the fact that the Lenovo TAB 10 relies entirely on hardware, while the Samsung Galaxy Core Prime does not. The issue is in the line:

Matrix.multiplyMM(mMesh.mModelMatrix, 0, mMesh.mModelMatrix, 0, mMatRotate.getFloatArray(), 0);

In hardware, it seems, it is okay to perform a matrix multiply and place the result into one of the input matrices; but the software implementation does not function the same. This makes sense, I guess, because it would take too long to make a copy every time you do a matrix multiply.

Upvotes: 0

Related Questions