Пример #1
0
    /// <summary>
    /// 世界空间到模型空间变换对比
    /// 这里直接对比变换矩阵是否相同
    /// </summary>
    void TestWorldSpaceToModelSpace()
    {
        //检查世界空间到模型空间
        Transform _parent = trans1.parent;
        //模型空间转世界空间
        Matrix4x4 matrix = TransformationMatrixUtil.MToWMatrix(_parent.localScale, _parent.localEulerAngles, _parent.localPosition);

        //世界空间转模型空间;就是matrix的逆矩阵
        matrix = matrix.inverse;
        Debug.LogFormat("matrix:\n{0}\n\nworldToLocalMatrix:\n{1}\n\n是否相等:{2}", matrix, _parent.worldToLocalMatrix, matrix == _parent.worldToLocalMatrix);
    }
Пример #2
0
    /// <summary>
    /// 模型空间转世界空间的坐标
    /// </summary>
    void TestModelSpaceToWorldSpace()
    {
        Transform _parent = trans1.parent;
        //模型空间转世界空间
        Vector3 p = TransformationMatrixUtil.MToWPosition(_parent.localScale, _parent.localEulerAngles, _parent.localPosition, trans1.localPosition);

        Debug.Log("模型空间转世界空间的坐标:" + p);
        Debug.Log("物体的世界坐标" + trans1.position);
        //模型空间转世界空间
        Matrix4x4 matrix = TransformationMatrixUtil.MToWMatrix(_parent.localScale, _parent.localEulerAngles, _parent.localPosition);

        Debug.LogFormat("matrix:\n{0}\n\nlocalToWorldMatrix:\n{1}\n\n是否相等:{2}", matrix, _parent.localToWorldMatrix, matrix == _parent.localToWorldMatrix);
    }