SCNGeometry 立体几何的使用

//
//  GameViewController.m
//  SCNGeometry几何对象
//
//  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];
    
    [self createCustom];
}

// 正方体
-(void)createBox{
    SCNBox *box1 = [SCNBox boxWithWidth:1 height:1 length:1 chamferRadius:0];
    box1.firstMaterial.diffuse.contents = [UIImage imageNamed:@"123.png"];
    
    // 创建节点,绑定几何体
    SCNNode *node1 = [SCNNode nodeWithGeometry:box1];
    node1.position = SCNVector3Make(0, 0, 0);
    // 把节点添加进去场景
    [self.scnView.scene.rootNode addChildNode:node1];
}

// 创建平面
-(void)createPlane{

    SCNPlane *box1 = [SCNPlane planeWithWidth:2 height:2];
    box1.firstMaterial.diffuse.contents = [UIImage imageNamed:@"123.png"];
    
    // 创建节点,绑定几何体
    SCNNode *node1 = [SCNNode nodeWithGeometry:box1];
    node1.position = SCNVector3Make(0, 0, 0);
    // 把节点添加进去场景
    [self.scnView.scene.rootNode addChildNode:node1];
}

// 创建金字塔
-(void)createPyramid{
    
    SCNPyramid *box1 = [SCNPyramid pyramidWithWidth:1 height:1 length:1];
    box1.firstMaterial.diffuse.contents = [UIImage imageNamed:@"123.png"];
    
    // 创建节点,绑定几何体
    SCNNode *node1 = [SCNNode nodeWithGeometry:box1];
    node1.position = SCNVector3Make(0, 0, 0);
    // 把节点添加进去场景
    [self.scnView.scene.rootNode addChildNode:node1];
}

// 创建球体
-(void)createSphere{
    
    SCNSphere *box1 = [SCNSphere sphereWithRadius:1];
    box1.firstMaterial.diffuse.contents = [UIImage imageNamed:@"123.png"];
    
    // 创建节点,绑定几何体
    SCNNode *node1 = [SCNNode nodeWithGeometry:box1];
    node1.position = SCNVector3Make(0, 0, 0);
    // 把节点添加进去场景
    [self.scnView.scene.rootNode addChildNode:node1];
}

// 圆柱体
-(void)createCylinder{
    
    SCNCylinder *box1 = [SCNCylinder cylinderWithRadius:1 height:2];
    box1.firstMaterial.diffuse.contents = [UIImage imageNamed:@"123.png"];
    
    // 创建节点,绑定几何体
    SCNNode *node1 = [SCNNode nodeWithGeometry:box1];
    node1.position = SCNVector3Make(0, 0, 0);
    // 把节点添加进去场景
    [self.scnView.scene.rootNode addChildNode:node1];
}

// 圆锥提
-(void)createCone{
    
    SCNCone *box1 = [SCNCone coneWithTopRadius:0 bottomRadius:1 height:2];
    box1.firstMaterial.diffuse.contents = [UIImage imageNamed:@"123.png"];
    
    // 创建节点,绑定几何体
    SCNNode *node1 = [SCNNode nodeWithGeometry:box1];
    node1.position = SCNVector3Make(0, 0, 0);
    // 把节点添加进去场景
    [self.scnView.scene.rootNode addChildNode:node1];
}

// 管道
-(void)createTube{
    //InnerRadius 内环半径
    //outerRadius 外环半径
    SCNTube *box1 = [SCNTube tubeWithInnerRadius:1 outerRadius:2 height:2];
    box1.firstMaterial.diffuse.contents = [UIImage imageNamed:@"123.png"];
    
    // 创建节点,绑定几何体
    SCNNode *node1 = [SCNNode nodeWithGeometry:box1];
    node1.position = SCNVector3Make(0, 0, 0);
    // 把节点添加进去场景
    [self.scnView.scene.rootNode addChildNode:node1];
}

// 环面
-(void)createTorus{
    //pipeRadius 内环半径
    //RingRadius 外环半径
    SCNTorus *box1 = [SCNTorus torusWithRingRadius:1 pipeRadius:0.5];
    box1.firstMaterial.diffuse.contents = [UIImage imageNamed:@"123.png"];
    
    // 创建节点,绑定几何体
    SCNNode *node1 = [SCNNode nodeWithGeometry:box1];
    node1.position = SCNVector3Make(0, 0, 0);
    // 把节点添加进去场景
    [self.scnView.scene.rootNode addChildNode:node1];
}

// 地板
-(void)createFloor{
    SCNFloor *box1 = [SCNFloor floor];
    box1.firstMaterial.diffuse.contents = [UIImage imageNamed:@"123.png"];
    
    // 创建节点,绑定几何体
    SCNNode *node1 = [SCNNode nodeWithGeometry:box1];
    node1.position = SCNVector3Make(0, -5, 0);
    // 把节点添加进去场景
    [self.scnView.scene.rootNode addChildNode:node1];
}

// 字体
-(void)createText{
    SCNText *box1 = [SCNText textWithString:@"超哥" extrusionDepth:0.5];
    box1.firstMaterial.diffuse.contents = [UIImage imageNamed:@"123.png"];
    box1.font = [UIFont systemFontOfSize:1];
    // 创建节点,绑定几何体
    SCNNode *node1 = [SCNNode nodeWithGeometry:box1];
    node1.position = SCNVector3Make(-2, 0, 0);
    // 把节点添加进去场景
    [self.scnView.scene.rootNode addChildNode:node1];
}

// 自定义形状
-(void)createCustom{
    SCNShape *box1 = [SCNShape shapeWithPath:[UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, 1, 1) cornerRadius:0.5] extrusionDepth:3];
    box1.firstMaterial.diffuse.contents = [UIImage imageNamed:@"123.png"];
    // 创建节点,绑定几何体
    SCNNode *node1 = [SCNNode nodeWithGeometry:box1];
   
    // 把节点添加进去场景
    [self.scnView.scene.rootNode addChildNode:node1];
}


@end

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值