making the arkit camera vertical rather than horizontal

后端 未结 2 415
死守一世寂寞
死守一世寂寞 2021-01-15 19:04

I am trying to make an app where the user enters some text in a textfield and then the app displays this text in front of the ar camera to the user. I positioned the text co

2条回答
  •  感情败类
    2021-01-15 19:24

    You cannot use the matrix identity for any orientation, it has to be rotated depending on device orientation. I have a function in my apps that I call to update that before I perform the matrix multiplication :

    var translation = matrix_identity_float4x4
    
    func updateTranslationMatrix() {
    
        switch UIDevice.current.orientation{
        case .portrait, .portraitUpsideDown, .unknown, .faceDown, .faceUp:
            print("portrait ")
            translation.columns.0.x = -cos(.pi/2)
            translation.columns.0.y = sin(.pi/2)
            translation.columns.1.x = -sin(.pi/2)
            translation.columns.1.y = -cos(.pi/2)
        case .landscapeLeft :
            print("landscape left")
            translation.columns.0.x = 1
            translation.columns.0.y = 0
            translation.columns.1.x = 0
            translation.columns.1.y = 1
        case .landscapeRight :
            print("landscape right")
            translation.columns.0.x = cos(.pi)
            translation.columns.0.y = -sin(.pi)
            translation.columns.1.x = sin(.pi)
            translation.columns.1.y = cos(.pi)
        }
        translation.columns.3.z = -0.6 //60cm in front of the camera
    }
    

提交回复
热议问题