在SceneKit(OpenGL)中实现平滑相机移动的标准方法是什么? 手动更改x,y坐标不够平滑,但使用CoreAnimation会创建“脉冲”移动。关于SceneKit的文档似乎非常有限,因此任何示例都将不胜感激,我目前正在执行以下操作:
- (void)keyDown:(NSEvent *)theEvent {
int key = [theEvent keyCode];
int x = cameraNode.position.x;
int y = cameraNode.position.y;
int z = cameraNode.position.z;
int speed = 4;
if (key==123) {//left
x-=speed;
} else if (key==124) {//right
x+=speed;
} else if (key==125) {//down
y-=speed;
} else if (key==126) {//up
y+=speed;
}
//move the camera
[SCNTransaction begin];
[SCNTransaction setAnimationDuration: 1.0];
// Change properties
cameraNode.position = SCNVector3Make(x, y, z);
[SCNTransaction commit];
}
animationTimingFunction
。确保CAMediaTimingFunction
的函数名称为kCAMediaTimingFunctionLinear,以避免脉冲。 - TheAmateurProgrammer