Apple Metal iOS 为什么 GLKMatrix4MakeLookAt 来回晃动

问题描述 投票:0回答:0

我正在使用 Xcode 14.3 在 iOS 16.1 上开发 3D 场景。我有一个倾斜的绕原点旋转的矩形平面,我想使用 GLKMatrix4MakeLookAt 使平面始终面向原点。

我正在使用下面的代码。飞机在旋转时确实“面向”原点,但是我也看到这种不希望的来回“摇摆”(偏航)。请观看随附的视频以了解它的外观。

为什么它会摇摆?我怎样才能摆脱摇摆但仍然让飞机绕原点运行并始终面对它?谢谢。

代码:

// Get the lookat scene origin matrix for the rectangle
var lookAtSceneOriginGLKMatrix = GLKMatrix4Identity
var lookAtSceneOriginInverse = GLKMatrix4Identity
var rectangleModelMatrix = float4x4()
var lookAtSceneOriginMat = float4x4()

lookAtSceneOriginGLKMatrix = GLKMatrix4Multiply(lookAtSceneOriginGLKMatrix, GLKMatrix4MakeLookAt(self.currentSatX * self.appDelegate.getCurrentRectangle().getRenderHeight(), self.currentSatY * self.appDelegate.getCurrentRectangle().getRenderHeight(), self.currentSatZ * self.appDelegate.getCurrentRectangle().getRenderHeight(), 0, 0, 0, 0, 1, 0))
var isInvertible = true
lookAtSceneOriginInverse = GLKMatrix4Invert(lookAtSceneOriginGLKMatrix, &isInvertible)
lookAtSceneOriginMat = float4x4(convertToFloat4x4FromGLKMatrix: lookAtSceneOriginInverse)
rectangleModelMatrix = accumulatedRotationMatrix * lookAtSceneOriginMat * float4x4(scaleBy: 0.35)

// Draw the rectangular plane
scene.rectanglePlane?.draw(
    encoder: commandEncoder, modelMatrix: rectangleModelMatrix,
    projectionMatrix: projectionMatrix * viewMatrix
)
ios swift metal glkit metalkit
© www.soinside.com 2019 - 2024. All rights reserved.