//
// GameViewController.m
// SCNAction
//
// 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.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];
node1.position = SCNVector3Make(0, 0, -20);
// 把节点添加进去场景
[self.scnView.scene.rootNode addChildNode:node1];
// 添加动画行为 沿着y轴旋转
SCNAction *rotation = [SCNAction rotateByAngle:10 aroundAxis:SCNVector3Make(0, 1, 0) duration:2];
SCNAction *moveUp = [SCNAction moveTo:SCNVector3Make(0, 5, 0) duration:1];
SCNAction *moveDown = [SCNAction moveTo:SCNVector3Make(0, -5, 0) duration:1];
//顺序执行动画
SCNAction *sequence = [SCNAction sequence:@[moveUp,moveDown]];
//组合动画之行
SCNAction *group = [SCNAction group:@[sequence,rotation]];
[node1 runAction:[SCNAction repeatActionForever:group]];
}
- (BOOL)shouldAutorotate
{
return YES;
}
- (BOOL)prefersStatusBarHidden {
return YES;
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
return UIInterfaceOrientationMaskAllButUpsideDown;
} else {
return UIInterfaceOrientationMaskAll;
}
}
@end