各地点(双指缩放),Android和OpenGL ES 2.0的扩展缩放、Android、OpenGL、ES

由网友(单身待解救)分享简介:我试图使用方式进行调整围绕这一点:I'm trying to scale around the point using approach:翻译成我要缩放围绕点(双指缩放)比例翻译回它看起来像:@Overridepublic boolean onScale(ScaleGestureDetector detect...

我试图使用方式进行调整围绕这一点:

I'm trying to scale around the point using approach:

翻译成我要缩放围绕点(双指缩放)比例翻译回

它看起来像:

@Override
public boolean onScale(ScaleGestureDetector detector) {

    float scaleFactor = detector.getScaleFactor();

    float focusX = detector.getFocusX();
    float focusY = detector.getFocusY();

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

但是当我创建结果MVP矩阵,如:

But when I create result MVP matrix like:

Matrix.multiplyMM(MVPmatrix, 0,
    projectionMatrix, 0,
    modelMatrix, 0);

我得到不正确的比例,使其扩展,但它不正确缩放围绕该点..

I get incorrect scaling so that it scales but it doesn't scale around the point correctly..

你能不能建议可能是什么原因,以及如何正确缩放围绕点?

Could you advise what could be the reason and how to scale around the point correctly?

推荐答案

据我所知道的,在Android的方法矩阵工具类繁殖新指定的转换从右侧。我没有看到它的文档中指定,但源$ C ​​$ C(http://grep$c$c.com/file/repository.grep$c$c.com/java/ext/com.google.android/android/1.5_r4/android/opengl/Matrix.java)清楚地表明,它以这种方式工作。

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.

有关在你点旋转(focusX,focusY),你首先要通过应用转换( - focusX,-focusY,0.0 F)来您的积分,然后旋转,然后翻译(focusX,focusY,0.0)。由于该呼叫序列是此相反,它应该是:

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);

我也改变了 scaleM的最后一个参数()在这里。既然你有 0 在Z方向上的比例因子,你会压扁整个几何图形到x-y平面。

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.

阅读全文

相关推荐

最新文章