CSNCamera-照相机

//
//  GameViewController.m
//  CSNCamera-照相机
//
//  Created by 柯木超 on 2019/4/9.
//  Copyright © 2019年 柯木超. All rights reserved.
//

#import "GameViewController.h"

@implementation GameViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.scnView = [[SCNView alloc]initWithFrame:self.view.bounds];
    self.scnView.backgroundColor = [UIColor grayColor];
    [self.view addSubview: self.scnView];
    
    self.scnView.allowsCameraControl = YES;
    // 设置场景
    self.scnView.scene = [SCNScene scene];
    
    // 添加照相机
    SCNCamera *camera = [SCNCamera camera];
    camera.xFov = 20;
    camera.yFov = 20;
    
    // 设置正投影
    camera.usesOrthographicProjection = YES;
    // 设置正投影比例
    camera.orthographicScale = 10;
    
    SCNNode *caNode = [SCNNode node];
    caNode.camera = camera;
    caNode.position = SCNVector3Make(0, 0, 50);
    // 把节点添加进去场景
    [self.scnView.scene.rootNode addChildNode:caNode];
    
    //添加两个正方体
    // 创建几何立体
    SCNBox *box1 = [SCNBox boxWithWidth:0.5 height:0.5 length:0.5 chamferRadius:0];
    
    // 创建节点,绑定几何体
    SCNNode *node1 = [SCNNode nodeWithGeometry:box1];
    // 把节点添加进去场景
    [self.scnView.scene.rootNode addChildNode:node1];
    
    // 创建几何立体
    SCNBox *box2 = [SCNBox boxWithWidth:0.5 height:0.5 length:0.5 chamferRadius:0];
    
    // 创建节点,绑定几何体
    SCNNode *node2 = [SCNNode nodeWithGeometry:box2];
    node2.position = SCNVector3Make(0, 10, -20);
    // 把节点添加进去场景
    [self.scnView.scene.rootNode addChildNode:node2];
    
    // 具体操作:
//    是否开启控制摄像机:
    self.scnView.allowsCameraControl =  YES;
//    一个手指操作的时候,摄像机对准(0,0,0)沿着球体表面旋转
//    连个手指平移手势,照相机是在x轴和y轴运动
//    捏合e手势,是在Z 轴移动
}

- (BOOL)shouldAutorotate
{
    return YES;
}

- (BOOL)prefersStatusBarHidden {
    return YES;
}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
        return UIInterfaceOrientationMaskAllButUpsideDown;
    } else {
        return UIInterfaceOrientationMaskAll;
    }
}

@end
发布了79 篇原创文章 · 获赞 42 · 访问量 4万+

猜你喜欢

转载自blog.csdn.net/s12117719679/article/details/89158407