固体对象
来源:互联网 发布:js面向对象的理解 编辑:程序博客网 时间:2024/04/30 15:43
固体对象
“固态的3D对象(实际上是一个技术上所谓的空洞对象,但它以固态呈现)”
效果图
实现
- (void)viewDidLoad {[super viewDidLoad];CATransform3D perspective = CATransform3DIdentity;perspective.m34 = -1.0 / 500.0;//以相机角度查看 perspective = CATransform3DRotate(perspective, -M_PI_4, 1, 0, 0);perspective = CATransform3DRotate(perspective, -M_PI_4, 0, 1, 0);self.containerView.layer.sublayerTransform = perspective;//add cube face 1CATransform3D transform = CATransform3DMakeTranslation(0, 0, 50);[self addFace:0 withTransform:transform];//add cube face 2transform = CATransform3DMakeTranslation(50, 0, 0);transform = CATransform3DRotate(transform, M_PI_2, 0, 1, 0);[self addFace:1 withTransform:transform];//add cube face 3transform = CATransform3DMakeTranslation(0, -50, 0);transform = CATransform3DRotate(transform, M_PI_2, 1, 0, 0);[self addFace:2 withTransform:transform];//add cube face 4transform = CATransform3DMakeTranslation(0, 50, 0);transform = CATransform3DRotate(transform, -M_PI_2, 1, 0, 0);[self addFace:3 withTransform:transform];//add cube face 5transform = CATransform3DMakeTranslation(-50, 0, 0);transform = CATransform3DRotate(transform, -M_PI_2, 0, 1, 0);[self addFace:4 withTransform:transform];//add cube face 6transform = CATransform3DMakeTranslation(0, 0, -50);transform = CATransform3DRotate(transform, M_PI, 0, 1, 0);[self addFace:5 withTransform:transform];// Do any additional setup after loading the view.}- (void)addFace:(NSInteger)index withTransform:(CATransform3D)transform{//get the face view and add it to the containerUIView *face = self.faces[index];[self.containerView addSubview:face];//center the face view within the containerCGSize containerSize = self.containerView.bounds.size;face.center = CGPointMake(containerSize.width / 2.0, containerSize.height / 2.0);// apply the transformface.layer.transform = transform;}
光亮和阴影
- (void)applyLightingToFace:(CALayer *)face{//add lighting layerCALayer *layer = [CALayer layer];layer.frame = face.bounds;[face addSublayer:layer];//convert the face transform to matrix//(GLKMatrix4 has the same structure as CATransform3D)//译者注:GLKMatrix4和CATransform3D内存结构一致,但坐标类型有长度区别,所以理论上应该做一次float到CGFloat的转换,感谢[@zihuyishi](https://github.com/zihuyishi)同学~CATransform3D transform = face.transform;GLKMatrix4 matrix4 = *(GLKMatrix4 *)&transform;GLKMatrix3 matrix3 = GLKMatrix4GetMatrix3(matrix4);//get face normalGLKVector3 normal = GLKVector3Make(0, 0, 1);normal = GLKMatrix3MultiplyVector3(matrix3, normal);normal = GLKVector3Normalize(normal);//get dot product with light directionGLKVector3 light = GLKVector3Normalize(GLKVector3Make(LIGHT_DIRECTION));float dotProduct = GLKVector3DotProduct(light, normal);//set lighting layer opacityCGFloat shadow = 1 + dotProduct - AMBIENT_LIGHT;UIColor *color = [UIColor colorWithWhite:0 alpha:shadow];layer.backgroundColor = color.CGColor;}
上述代码未实行效果图 GLKit
框架有待学习
点击事件
将上面添加视图代码,视图3放在最后添加,避免其他视图覆盖上面,影响事件的传递,或者将上面的视图的
userInteractionEnabled
设置为NO
阅读全文
0 0
- 固体对象
- 固体油墨打印机
- 固体物理基础
- 固体的结合
- 固体的弹性性质
- 固体模拟简介(Introduction to solid)
- 固体表和DUAL表的介绍
- 固体力学之非线性、小变形假设
- 关于固体结构和性质理论研究工作的概况
- 别激动1280cpu固体硬盘也是天下
- 固体物理小笔记1-晶体的结构
- 新型固体运载火箭KZ-11明年首飞 将实现“一箭六星”
- Matlab物化实验——雷诺法作图(固体和液体燃烧热的测定)
- 对象
- 对象
- 对象
- 对象
- 对象
- jQuery JSONView-格式化和语法高亮JSON格式数据查看插件
- 使用点阵图形上下文创建Image对象
- 排序算法
- AMOS分析技术:验证性因子分析介绍;信度与效度指标详解
- 半导体传感器的零点漂移
- 固体对象
- IT风投与中国
- leetcode 502. IPO 贪心算法
- linux 系统如何自动关机和开机
- 关于socket 使用实战总结
- leetcode2 查找最长不重复字串问题
- SpringCloud(第 053 篇)CentOS7 中用 Docker 部署一个简单的基于 Eureka 服务治理发现的项目
- Servlet技术入门
- eoj 3442