In order to rotate/translate object (rotation only about z-axis and translation only in xy plane) not just w.r.t to global center (device center) but also w.r.t other arbitrary points, I created an algorithm, which is correct (because all senior coders I have discussed with consider it correct), but it is taking a lot of time to remove an undesired translation in the implementation (algorithm was created on August 4 and was implemented on the same day, since then the code has been revised 15 times).
Here is the implementation http://www.pixdip.com/opengles/transform.php#ALGO1
The lines of code that are producing undesired translation are inside:
private static void updateModel(int upDown, float xAngle, float yAngle, float zAngle) {
and are listed below:
Matrix.multiplyMV(GLES20Renderer._uBodyCentreMatrix, 0, GLES20Renderer._ModelMatrixBody, 0, GLES20Renderer._uBodyCentre, 0);
objX = GLES20Renderer._uBodyCentreMatrix[0];
objY = GLES20Renderer._uBodyCentreMatrix[1];
The undesired translation along +Y persists even if the following changes are made:
objY = _uBodyCentreMatrix[1] - _uBodyCentre[1];
zAngle = 0;
ds = 0;
The value -0.545867f
is added to the Y coordinate on every call to onDrawFrame()
, because of these fields of the Renderer class:
private static final float[] _uBodyCentre = new float[]{-0.019683f, -0.545867f, -0.000409f, 1.0f};
protected static float[] _uBodyCentreMatrix = new float[4];
in http://www.pixdip.com/opengles/transform.php#FIELDS
I need help to understand why does that undesired translation happen, what is exactly wrong with the transformations, or is it the algorithm that is wrong.
Can Gimbal lock be an issue here ?
Please do not ask me to perform/practice simpler examples, because I have prepared the Renderer class for rotation/translation about global z-axis, and this new task that I am into, uses the same class with slight modification in updateModel()
(Please note that the desired rotation is only about z-axis and translation only in xy plane)
[API 10->15]
The actual Renderer class has two objects: tank turret(nozzle) and tank body, while turret(nozzle) has undesired forward translation, the body has undesired backward translation
Apk for translation/rotation about device center (which is easy to make in opengles 2.0):
http://www.pixdip.com/opengles/global.php
Apk for translation/rotation about arbitrary points (which has undesired translation along +Y):
http://www.pixdip.com/opengles/local.php
Apk for translation/rotation about arbitrary points in which updateModel() is called 4 times only:
http://www.pixdip.com/opengles/limited.php
and required code (which should be sufficient) is here: http://www.pixdip.com/opengles/code.php
Parts of object (nozzle/turret,body) are currently rotating about their own centres not the centre of object (which is _playerCentre), I will modify that later.
I have tried to demonstrate logic http://www.pixdip.com/opengles/images.php
See Question&Answers more detail:
os