class CubeModel : IBufferSource { private const float halfLength = 0.5f; private static readonly vec3[] positions = new vec3[] { new vec3(+halfLength, +halfLength, +halfLength), // 0 new vec3(+halfLength, +halfLength, -halfLength), // 1 new vec3(+halfLength, -halfLength, +halfLength), // 2 new vec3(+halfLength, -halfLength, -halfLength), // 3 new vec3(-halfLength, +halfLength, +halfLength), // 4 new vec3(-halfLength, +halfLength, -halfLength), // 5 new vec3(-halfLength, -halfLength, +halfLength), // 6 new vec3(-halfLength, -halfLength, -halfLength), // 7 }; private static readonly uint[] indexes = new uint[] { 0, 2, 1, 1, 2, 3, // +X faces. 0, 1, 5, 0, 5, 4, // +Y faces. 0, 4, 2, 2, 4, 6, // +Z faces. 7, 6, 4, 7, 4, 5, // -X faces. 7, 5, 3, 3, 5, 1, // -Z faces. 7, 3, 2, 7, 2, 6, // -Y faces. }; public const string strPosition = "position"; private VertexBuffer positionBuffer; // array in GPU side. private IDrawCommand drawCommand; #region IBufferSource 成员 public IEnumerable<VertexBuffer> GetVertexAttribute(string bufferName) { if (strPosition == bufferName) // requiring position buffer. { if (this.positionBuffer == null) { // transform managed array to vertex buffer. this.positionBuffer = positions.GenVertexBuffer( VBOConfig.Vec3, // mapping to 'in vec3 someVar;' in vertex shader. BufferUsage.StaticDraw); // GL_STATIC_DRAW. } yield return this.positionBuffer; } else { throw new ArgumentException("bufferName"); } } public IEnumerable<IDrawCommand> GetDrawCommand() { if (this.drawCommand == null) { // indexes in GPU side. IndexBuffer indexBuffer = indexes.GenIndexBuffer(BufferUsage.StaticDraw); this.drawCommand = new DrawElementsCmd(indexBuffer, DrawMode.Triangles); // GL_TRIANGLES. } yield return this.drawCommand; } #endregion }逐行分段解释上述程序

时间: 2023-06-14 07:07:07 浏览: 48
这段程序定义了一个名为 CubeModel 的类,实现了 IBufferSource 接口。 ```c# class CubeModel : IBufferSource { ``` 类中定义了一个常量 halfLength,值为 0.5。 ```c# private const float halfLength = 0.5f; ``` 类中定义了一个静态只读的 vec3 数组 positions,包含了八个顶点的位置。 ```c# private static readonly vec3[] positions = new vec3[] { new vec3(+halfLength, +halfLength, +halfLength), // 0 new vec3(+halfLength, +halfLength, -halfLength), // 1 new vec3(+halfLength, -halfLength, +halfLength), // 2 new vec3(+halfLength, -halfLength, -halfLength), // 3 new vec3(-halfLength, +halfLength, +halfLength), // 4 new vec3(-halfLength, +halfLength, -halfLength), // 5 new vec3(-halfLength, -halfLength, +halfLength), // 6 new vec3(-halfLength, -halfLength, -halfLength), // 7 }; ``` 类中定义了一个静态只读的 uint 数组 indexes,包含了组成立方体的三角形面的顶点索引。 ```c# private static readonly uint[] indexes = new uint[] { 0, 2, 1, 1, 2, 3, // +X faces. 0, 1, 5, 0, 5, 4, // +Y faces. 0, 4, 2, 2, 4, 6, // +Z faces. 7, 6, 4, 7, 4, 5, // -X faces. 7, 5, 3, 3, 5, 1, // -Z faces. 7, 3, 2, 7, 2, 6, // -Y faces. }; ``` 类中定义了一个常量 strPosition,值为 "position"。 ```c# public const string strPosition = "position"; ``` 类中定义了一个私有的 VertexBuffer 类型的 positionBuffer,用于在 GPU 中存储顶点位置数据。 ```c# private VertexBuffer positionBuffer; // array in GPU side. ``` 类中定义了一个私有的 IDrawCommand 类型的 drawCommand,用于在 GPU 中绘制立方体。 ```c# private IDrawCommand drawCommand; ``` 接下来是实现 IBufferSource 接口的方法。 ```c# #region IBufferSource 成员 public IEnumerable<VertexBuffer> GetVertexAttribute(string bufferName) { if (strPosition == bufferName) // requiring position buffer. { if (this.positionBuffer == null) { // transform managed array to vertex buffer. this.positionBuffer = positions.GenVertexBuffer( VBOConfig.Vec3, // mapping to 'in vec3 someVar;' in vertex shader. BufferUsage.StaticDraw); // GL_STATIC_DRAW. } yield return this.positionBuffer; } else { throw new ArgumentException("bufferName"); } } ``` GetVertexAttribute 方法返回一个可枚举的 VertexBuffer 集合,根据输入的 bufferName 参数选择返回的 VertexBuffer。如果 bufferName 的值等于 strPosition 常量的值,则返回存储顶点位置数据的 positionBuffer;否则抛出 ArgumentException 异常。 ```c# public IEnumerable<IDrawCommand> GetDrawCommand() { if (this.drawCommand == null) { // indexes in GPU side. IndexBuffer indexBuffer = indexes.GenIndexBuffer(BufferUsage.StaticDraw); this.drawCommand = new DrawElementsCmd(indexBuffer, DrawMode.Triangles); // GL_TRIANGLES. } yield return this.drawCommand; } #endregion ``` GetDrawCommand 方法返回一个可枚举的 IDrawCommand 集合,返回用于绘制立方体的 IDrawCommand。如果 drawCommand 为空,则创建一个 IDrawCommand 对象,存储绘制立方体所需的索引数据,并将其赋值给 drawCommand 变量。然后返回该 drawCommand 变量。

相关推荐

public class DateTimeText : MonoBehaviour { public StringBuilder StrBuilder { get; set; } = new StringBuilder(); public Text m_dateText; public Text m_timeText; public Text m_weekText; DateTime m_lastDateTime; public DateTime CurrentDateTime { get; private set; } = DateTime.Now; void Start() { if (m_dateText != null) { m_dateText.text = GetDate(); } m_lastDateTime = DateTime.Now; } private string GetDate() { return CurrentDateTime.ToString(DateTimeFormat.DateFormat); } private string GetTime() { return CurrentDateTime.ToString(DateTimeFormat.TimeFormat); } private string GetWeek() { return CurrentDateTime.ToString("dddd"); } float m_interval = 0; void Update() { CurrentDateTime=DateTime.Now; m_interval += Time.deltaTime; if (m_interval >= 0.5f) { m_interval -= 0.5f; DateTime time = CurrentDateTime; if (m_dateText != null) { if (m_lastDateTime.Day != time.Day) { m_dateText.text = GetDate(); m_lastDateTime = time; } } if (m_timeText != null) { if (m_lastDateTime.Second != time.Second) { m_timeText.text = GetTime(); m_lastDateTime = time; } } if (m_weekText!=null) { if (m_lastDateTime.DayOfWeek!=time.DayOfWeek) { m_weekText.text = GetWeek(); m_lastDateTime = time; } } } } } public class DateTimeFormat { public const string Moday = "Moday"; public const string Tuesday = "Tuesday"; public const string Wednesday = "Wednesday"; public const string Thursday = "Thursday"; public const string Friday = "Friday"; public const string Saturday = "Saturday"; public const string Sunday = "Sunday"; public const string DateFormat = "yyyy/MM/dd"; public const string TimeFormat = "HH:mm:ss"; }这段代码显示不了星期数,是什么问题,请详细说下

最新推荐

recommend-type

深入探讨C#中的const、readonly关键字

主要介绍了深入探讨C#中的const、readonly关键字,本文可以帮助你深刻理解这两个关键字,而且是面试中最可能面试到的问题哦,需要的朋友可以参考下
recommend-type

k8s1.16的jenkins部署java项目cicd(cd手动)-kubernetes安装包和详细文档笔记整理

k8s1.16的jenkins部署java项目cicd(cd手动)-kubernetes安装包和详细文档笔记整理
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

MATLAB柱状图在信号处理中的应用:可视化信号特征和频谱分析

![matlab画柱状图](https://img-blog.csdnimg.cn/3f32348f1c9c4481a6f5931993732f97.png) # 1. MATLAB柱状图概述** MATLAB柱状图是一种图形化工具,用于可视化数据中不同类别或组的分布情况。它通过绘制垂直条形来表示每个类别或组中的数据值。柱状图在信号处理中广泛用于可视化信号特征和进行频谱分析。 柱状图的优点在于其简单易懂,能够直观地展示数据分布。在信号处理中,柱状图可以帮助工程师识别信号中的模式、趋势和异常情况,从而为信号分析和处理提供有价值的见解。 # 2. 柱状图在信号处理中的应用 柱状图在信号处理
recommend-type

用Spring boot和vue写一个登录注册界面

好的,这是一个比较常见的技术问题,我可以为您提供一些参考资料和思路。首先,您可以使用Spring Boot作为后端框架来处理用户认证和注册的逻辑,比如使用Spring Security实现用户登录认证。同时,您还需要设计相应的数据模型和数据库表结构来存储用户信息。在前端方面,您可以使用Vue.js作为框架来构建登录注册页面,使用Axios来发起API请求并和后端进行交互。当然,在实现过程中,还需要考虑一些具体细节,比如数据校验、安全性和用户体验等方面。希望这些信息能够帮助到您。
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。
recommend-type

"互动学习:行动中的多样性与论文攻读经历"

多样性她- 事实上SCI NCES你的时间表ECOLEDO C Tora SC和NCESPOUR l’Ingén学习互动,互动学习以行动为中心的强化学习学会互动,互动学习,以行动为中心的强化学习计算机科学博士论文于2021年9月28日在Villeneuve d'Asq公开支持马修·瑟林评审团主席法布里斯·勒菲弗尔阿维尼翁大学教授论文指导奥利维尔·皮耶昆谷歌研究教授:智囊团论文联合主任菲利普·普雷教授,大学。里尔/CRISTAL/因里亚报告员奥利维耶·西格德索邦大学报告员卢多维奇·德诺耶教授,Facebook /索邦大学审查员越南圣迈IMT Atlantic高级讲师邀请弗洛里安·斯特鲁布博士,Deepmind对于那些及时看到自己错误的人...3谢谢你首先,我要感谢我的两位博士生导师Olivier和Philippe。奥利维尔,"站在巨人的肩膀上"这句话对你来说完全有意义了。从科学上讲,你知道在这篇论文的(许多)错误中,你是我可以依
recommend-type

MATLAB柱状图在数据分析中的作用:从可视化到洞察

![MATLAB柱状图在数据分析中的作用:从可视化到洞察](https://img-blog.csdnimg.cn/img_convert/1a36558cefc0339f7836cca7680c0aef.png) # 1. MATLAB柱状图概述** 柱状图是一种广泛用于数据可视化的图表类型,它使用垂直条形来表示数据中不同类别或组别的值。在MATLAB中,柱状图通过`bar`函数创建,该函数接受数据向量或矩阵作为输入,并生成相应的高度条形。 柱状图的优点在于其简单性和易于理解性。它们可以快速有效地传达数据分布和组别之间的比较。此外,MATLAB提供了广泛的定制选项,允许用户调整条形颜色、
recommend-type

命名ACL和拓展ACL标准ACL的具体区别

命名ACL和标准ACL的主要区别在于匹配条件和作用范围。命名ACL可以基于协议、端口和其他条件进行匹配,并可以应用到接口、VLAN和其他范围。而标准ACL只能基于源地址进行匹配,并只能应用到接口。拓展ACL则可以基于源地址、目的地址、协议、端口和其他条件进行匹配,并可以应用到接口、VLAN和其他范围。