AS3:获取 Matrix 对象的比例 [英] AS3: Getting the scale of a Matrix object

查看:31
本文介绍了AS3:获取 Matrix 对象的比例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大多数情况下,会询问有关如何缩放 DisplayObject 的问题,答案通常是使用矩阵.

Most often, questions are asked about how to scale a DisplayObject, and the answer is usually to use a Matrix.

我的问题是,如何获得矩阵的尺度(scaleX 和 scaleY)?

My question is, how to you GET the scale of a Matrix (scaleX and scaleY)?

有一个 Matrix.scale 方法来设置 scaleX 和 scaleY,但它不返回值,并且不存在其他属性来读取它.

There's a Matrix.scale method to set the scaleX and scaleY, but it doesn't return a value, and no other properties exist to read it back.

我问的原因是,我正在使用深埋在显示列表中的对象,每个对象都可能被转换.所以我使用了子对象的 sprite.transform.concatenatedMatrix getter,但在这一点上我不知道如何从中读取比例.

The reason I ask, I'm using object burried deep down into a Display list, and each may be transformed. So I use the child object's sprite.transform.concatenatedMatrix getter, but am stuck at this point on how to read the scale from it.

家里有数学奇才吗?

推荐答案

通常,隔离矩阵中缩放分量的可靠​​方法是使用所讨论的矩阵沿轴变换单位向量,然后测量结果向量的长度.

Generally, a reliable way to isolate the scaling component in a matrix is to use the matrix in question to transform the unit vectors along the axes, and then measure the length of the resulting vectors.

例如,给定来自 DisplayObject 的 transform,并使用 Matrix3D,将按如下方式获得 scaleX:

For instance, given the transform from a DisplayObject, and using the Matrix3D, the scaleX would be obtained as follows:

transform.matrix3D.deltaTransformVector(Vector3D.X_AXIS).length

或者,如果您使用连接的 2D 矩阵,scaleY 将是:

Or, if you use the concatenated 2D Matrix, the scaleY would be:

transform.concatenatedMatrix.deltaTransformPoint(new Point(0,1)).length

请注意,deltaTransform* 函数忽略了矩阵的平移效果,这对缩放没有影响.

Note that the deltaTransform* functions ignore the translation effects of the matrices, which have no effect on the scaling.

这篇关于AS3:获取 Matrix 对象的比例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆