Scaling around point (pinch zoom) with Android and OpenGL ES 2.0

六眼飞鱼酱① 提交于 2019-12-04 17:12:47

As far as I can tell, the methods in the Android Matrix utility class multiply the newly specified transformations from the right. I don't see it specified in the documentation, but the source code (http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/1.5_r4/android/opengl/Matrix.java) clearly suggests that it works this way.

This means that when you combine a transformation matrix from a sequence of sub-transformations, the last method you invoke specifies the sub-transformation that is applied to your points first. In other words, you specify the matrices in the reverse of the order that they are applied to your points.

For the rotation around your point (focusX, focusY), you first want to apply the translation by (-focusX, -focusY, 0.0f) to your points, then the rotation, then the translation by (focusX, focusY, 0.0f). Since the call sequence is the reverse of this, it should be:

Matrix.translateM(modelMatrix, 0, focusX, focusY, 0.0f);
Matrix.scaleM(modelMatrix, 0, scaleFactor, scaleFactor, scaleFactor);
Matrix.translateM(modelMatrix, 0, -focusX, -focusY, 0.0f);

I also changed the last argument of scaleM() here. Since you had 0 for the scale factor in z-direction, you would be flattening the entire geometry into the x-y plane.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!