AS3: Getting the scale of a Matrix object

前端 未结 3 1605
余生分开走
余生分开走 2021-01-16 08:49

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

My question is, how to you GET the scale of a Matrix (

3条回答
  •  忘掉有多难
    2021-01-16 09:32

    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.

    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
    

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

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

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

提交回复
热议问题