Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/apache-flex/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 如何在flex 3中围绕质心旋转矩形_Actionscript 3_Apache Flex_Matrix_Actionscript_Flex3 - Fatal编程技术网

Actionscript 3 如何在flex 3中围绕质心旋转矩形

Actionscript 3 如何在flex 3中围绕质心旋转矩形,actionscript-3,apache-flex,matrix,actionscript,flex3,Actionscript 3,Apache Flex,Matrix,Actionscript,Flex3,我正在使用matrix.rotate方法旋转矩形(在我的例子中是长方体)。 我的旋转事件如下所示 公共函数transformObject(transformEvent:transformEvent):无效{ sourceMatrix = MatrixTransformer.rotate(sourceMatrix, rotation, "degrees"); return sourceMatrix; } /** * Rotates

我正在使用matrix.rotate方法旋转矩形(在我的例子中是长方体)。 我的旋转事件如下所示

公共函数transformObject(transformEvent:transformEvent):无效{

        sourceMatrix = MatrixTransformer.rotate(sourceMatrix, rotation, "degrees");

        return sourceMatrix;
    }



    /**
     * Rotates a matrix and returns the result. The unit parameter lets the user specify "degrees", 
     * "gradients", or "radians". 
     */
    public static function rotate(sourceMatrix:Matrix, angle:Number, unit:String = "radians"):Matrix {
        if (unit == "degrees") 
        {
            angle = Math.PI * 2 *( angle / 360);
        }

        sourceMatrix. rotate(angle)
        return sourceMatrix;
    }
问题是x和y是长方体的左核心,因此它围绕左角旋转。但是,如果我尝试将温度x和温度y作为质心值,它不会围绕质心旋转吗

有人能告诉我我做错了什么吗

谢谢
Akshay

如果您确实想要或必须直接使用矩阵,可以使用内置的flash类更方便地执行此操作:
fl.motion.MatrixTransformer

MatrixTransformer.rotateAroundInternalPoint(matrix, centroidX, centroidY, angleInDegrees);
有关更多信息,请参阅MatrixTransformer上的Adobe

但是,如果不需要使用转换矩阵,则更简单的解决方案是:

  • 以(0,0)为质心的方式绘制对象
  • 使用
    DisplayObject
    中的简单
    rotation
    属性,它以更简单的方式实现相同的目标

    • 找到了答案。看来我没有在旋转前后将它们转换到适当的坐标位置

               tempMatrix.translate(tempx,tempy);
      
      //步骤1:固定矩形的坐标。我将它们添加到事件中,以便它们保持静态

          if (TransformEvent.X == 0 && TransformEvent.Y == 0)
              {
               TransformEvent.X = chld.x;
                 TransformEvent.Y = chld.y;
               }
      
      //接下来得到矩形的质心

             tempx = TransformEvent.X + width/2;
             tempy= TransformEvent.Y +height/2;
      
      //步骤3:旋转前平移

              tempMatrix.translate(-1*tempx,-1*tempy);
      
      //旋转矩形

              tempMatrix = MatrixTransformer.transform(tempMatrix,transformEvent.angle);
      
               chld.transform.matrix = tempMatrix;
      
      //旋转后平移到质心

               tempMatrix.translate(tempx,tempy);
      
      //将矩阵重新指定给矩形

              tempMatrix = MatrixTransformer.transform(tempMatrix,transformEvent.angle);
      
               chld.transform.matrix = tempMatrix;
      
      谢谢你的帮助。这个网站也帮了我翻译

      这是问题的答案,谢谢Jakub的回答。但是fl.motion.MatrixTransformer是否可以在flex中导入?我试图查找,但没有这样的库。我应该下载一些库吗?我没有导入fl库,但是对象在每次旋转后都以螺旋运动。我将发布c快颂