代码之家  ›  专栏  ›  技术社区  ›  MonkeyBonkey

在iOS/Swift中,MatrixHelper是哪个模块的一部分?

  •  1
  • MonkeyBonkey  · 技术社区  · 9 年前

    https://medium.com/@yatchoi/getting-started-with-arkit-real-life-waypoints-1707e3cb1da2 我在下面 unresolved identifier 'MatrixHelper'

        let translationMatrix = MatrixHelper.translate(
            x: 0,
            y: 0,
            z: distance * -1
        )
        // Rotation matrix theta degrees
        let rotationMatrix = MatrixHelper.rotateAboutY(
            degrees: bearing * -1
        )
    

    2 回复  |  直到 9 年前
        1
  •  3
  •   Retterdesdialogs    9 年前

    与MatrixHelper。rotateAboutY()他调用了如下内容:

    GLKMatrix4 GLKMatrix4Rotate(GLKMatrix4 matrix, float radians, float x, float y, float z);
    

    因此,MatrixHelper中使用的包是GLKit,更准确地说是GLKMatrix4

    https://developer.apple.com/documentation/glkit/glkmatrix4-pce

        2
  •  2
  •   Darius Miliauskas    8 年前

    您可以避免使用MatrixHelper(也可以 GLKit公司

    func getTranslationMatrix(tx: Float, ty: Float, tz: Float) -> simd_float4x4 {
        var translationMatrix = matrix_identity_float4x4
        translationMatrix.columns.3 = simd_float4(tx, ty, tz, 1)
        return translationMatrix
    }
    
    func getRotationYMatrix(angle: Float) -> simd_float3x3 {
        let rows = [
            simd_float3(cos(angle), 0, -sin(angle)),
            simd_float3(0, 1, 0),
            simd_float3(-sin(angle), 0, cos(angle))
        ]
        return float3x3(rows: rows)
    }
    

    或更具体的转换矩阵:

    func getTranslationZMatrix(tz: Float) -> simd_float4x4 {
        var translationMatrix = matrix_identity_float4x4
        translationMatrix.columns.3.z = tz
        return translationMatrix
    }
    

    然后代码看起来像:

    func getTransformGiven(currentLocation: CLLocation) -> matrix_float4x4 {
             let bearing = bearingBetween(
                 startLocation: currentLocation,
                endLocation: location
            )
             let distance: Float = 5
            let originTransform = matrix_identity_float4x4
            // Create a transform with a translation of 5meter away
            //        let translationMatrix = MatrixHelper.translate(
            //            x: 0,
            //            y: 0,
            //            z: distance * -1
           //        )
                  let translationMatrix = getTranslationZMatrix(tz: distance * -1) 
          // Rotation matrix theta degrees               
          //        let rotationMatrix = MatrixHelper.rotateAboutY(
          //            degrees: bearing * -1
          //        )
                  let rotationMatrix = getRotationYMatrix(angle: Float(bearing * 180 / Double.pi))
                  var transformMatrix = simd_mul(rotationMatrix, translationMatrix)
                  return simd_mul(originTransform, transformMatrix)
            }