VR+全景播放器+头控讲解-01-知识储备
VR+全景播放器+头控讲解-02-创建球体
VR+全景播放器+头控讲解-03-渲染视频
VR+全景播放器+头控讲解-04-滑动手势
VR+全景播放器+头控讲解-05-伸缩画面
VR+全景播放器+头控讲解-06-头控实现
VR+全景播放器+头控讲解-07-分屏技术
本节学习目标
捏合手势如何缩放画面
实现步骤
1.创建捏合手势添加到视图中去,这个视图也是最外层的视图
self.pinchGesture = [[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(pinchGesture:)];
[view addGestureRecognizer:self.pinchGesture];
2.算法处理,改变Camera属性的xFov ,yFov
-(void)pinchGesture:(UIPinchGestureRecognizer*)pinchGesture{
if (pinchGesture.state != UIGestureRecognizerStateEnded && pinchGesture.state != UIGestureRecognizerStateFailed) {
if (pinchGesture.scale != NAN && pinchGesture.scale != 0.0) {
float scale = pinchGesture.scale - 1;
if (scale < 0) scale *= (sScaleMax - sScaleMin);
_currentScale = scale + _prevScale;
_currentScale = [self validateScale:_currentScale];
CGFloat valScale = [self validateScale:_currentScale];
double xFov = CAMERA_FOX * (1-(valScale-1)*0.15);
double yFov = CAMERA_HEIGHT * (1-(valScale-1)*0.15);
}
} else if(pinchGesture.state == UIGestureRecognizerStateEnded){
_prevScale = _currentScale;
}
}
-(float)validateScale:(float)scale{
if (scale < sScaleMin)
scale = sScaleMin;
else if (scale > sScaleMax) scale = sScaleMax;
return scale;
}
3.改变照相机节点的属性xFov,yFov
self.eyeNode.camera.xFov = xFov;
self.eyeNode.camera.yFov = yFor;
问题:
为什么缩放不是改变球体的半径呢?
答:因为照相机的视野范围不改变,无论球体半径多大,呈现出来的部分都不会改变,如下
本节讲解完毕
SceneKit 中文教程