我正在用Xcode14.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
)