Skip to content Skip to sidebar Skip to footer

Drift In Rotation About Z-axis

In an application, while trying to rotate an object using touch, I noticed drift in position of object after sometime (without any translation applied !!). The rotation is only a

Solution 1:

Sometimes floating point errors get accumulated because of matrix stack.

This can be removed by using separate matrices for some critical transformations:

private staticfloat[] _TMatrix =newfloat[16];
private staticfloat[] _ModelMatrix =newfloat[16];
Matrix.setIdentity(Renderer._ModelMatrix);
Matrix.setIdentity(Renderer._TMatrix);
Matrix.translate(Renderer._ModelMatrix, xmov,ymov,0);
Matrix.translate(Renderer._TMatrix, -xmov,-ymov,0);
Matrix.multiply(Renderer._ModelMatrix, Renderer._TMatrix, Renderer._ModelMatrix);
// will resultin an identity model matrix, withoutany floating point errors

Post a Comment for "Drift In Rotation About Z-axis"