[13] 弧面(Arc)图形的生成算法
顶点数据的生成
- bool YfBuildArcVertices
- (
- Yreal radius,
- Yreal degree,
- Yreal height,
- Yuint slices,
- Yuint stacks,
- YeOriginPose originPose,
- Yuint vertexStriding,
- Yuint vertexPos,
- void* pVerticesBuffer
- )
- {
- if (degree < || degree > || !pVerticesBuffer)
- {
- return false;
- }
- if (slices < || stacks < || !pVerticesBuffer)
- {
- return false;
- }
- Yuint numVertices = slices * (stacks - ) + ;
- char* vertexPtr = (char*)pVerticesBuffer + vertexPos;
- YsVector3* curVertexPtr = NULL;
- Yuint nOffset = ;
- Yreal originOffsetY = 0.0f;
- if (originPose == YE_ORIGIN_POSE_TOP)
- {
- originOffsetY = -radius;
- }
- else if (originPose == YE_ORIGIN_POSE_BOTTOM)
- {
- originOffsetY = radius;
- }
- Yreal* pSinList = YD_NEW_ARRAY(Yreal, slices);
- Yreal* pCosList = YD_NEW_ARRAY(Yreal, slices);
- Yreal angleXZ;
- for (Yuint j = ; j < slices; j++)
- {
- angleXZ = YD_REAL_TWAIN_PI * j / slices;
- pSinList[j] = yf_sin(angleXZ);
- pCosList[j] = yf_cos(angleXZ);
- }
- // 赋值
- {
- Yreal radian = YD_DEGREE_TO_RADIAN(degree);
- for (Yuint i = ; i < stacks; i++)
- {
- if (i == ) // 第一个顶点
- {
- nOffset = ;
- curVertexPtr = (YsVector3*)(vertexPtr + nOffset);
- curVertexPtr->x = 0.0f;
- curVertexPtr->y = radius + originOffsetY;
- curVertexPtr->z = 0.0f;
- continue;
- }
- Yreal angleY = radian * i / (stacks - );
- Yreal posY = radius * yf_cos(angleY);
- Yreal radiusXZ = radius * yf_sin(angleY);
- Yreal posX, posZ;
- for (Yuint j = ; j < slices; j++)
- {
- posX = radiusXZ * pSinList[j % slices];
- posZ = radiusXZ * pCosList[j % slices];
- nOffset = ( + (i - ) * slices + j) * vertexStriding;
- curVertexPtr = (YsVector3*)(vertexPtr + nOffset);
- curVertexPtr->x = posX;
- curVertexPtr->y = posY + originOffsetY;
- curVertexPtr->z = posZ;
- }
- }
- }
- YD_SAFE_DELETE_ARRAY(pSinList);
- YD_SAFE_DELETE_ARRAY(pCosList);
- return true;
- }
三角形索引数据的生成
- bool YfBuildArcTriIndices
- (
- Yuint slices,
- Yuint stacks,
- YeIndexType indexType,
- Yuint indexStriding,
- Yuint indexPos,
- void* pTriIndicesBuffer
- )
- {
- if (slices < || stacks < || !pTriIndicesBuffer)
- {
- return false;
- }
- Yuint numVertices = slices * (stacks - ) + ;
- Yuint numTriangles = slices * (stacks - ) * + slices;
- if (indexType == YE_INDEX_16_BIT &&
- numVertices > YD_MAX_UNSIGNED_INT16)
- {
- return false;
- }
- // 索引赋值
- char* indexPtr = (char*)pTriIndicesBuffer + indexPos;
- Yuint nOffset = ;
- if (indexType == YE_INDEX_16_BIT)
- {
- YsTriIndex16* triIndexPtr = NULL;
- // 赋值
- for (Yuint i = ; i < stacks - ; i++)
- {
- if (i == ) // 第一层
- {
- for (Yuint j = ; j < slices; j++)
- {
- nOffset = j * indexStriding;
- triIndexPtr = (YsTriIndex16*)(indexPtr + nOffset);
- triIndexPtr->index0 = ;
- triIndexPtr->index1 = + j;
- triIndexPtr->index2 = + (j + )%slices;
- }
- }
- else
- {
- for (Yuint j = ; j < slices; j++)
- {
- nOffset = ((i - )*slices * + slices + j * ) * indexStriding;
- triIndexPtr = (YsTriIndex16*)(indexPtr + nOffset);
- triIndexPtr->index0 = + slices * (i - ) + j;
- triIndexPtr->index1 = + slices * i + j;
- triIndexPtr->index2 = + slices * (i - ) + (j + )%slices;
- nOffset += indexStriding;
- triIndexPtr = (YsTriIndex16*)(indexPtr + nOffset);
- triIndexPtr->index0 = + slices * (i - ) + (j + )%slices;
- triIndexPtr->index1 = + slices * i + j;
- triIndexPtr->index2 = + slices * i + (j + )%slices;
- }
- }
- }
- }
- else
- {
- YsTriIndex32* triIndexPtr = NULL;
- // 赋值
- for (Yuint i = ; i < stacks - ; i++)
- {
- if (i == ) // 第一层
- {
- for (Yuint j = ; j < slices; j++)
- {
- nOffset = j * indexStriding;
- triIndexPtr = (YsTriIndex32*)(indexPtr + nOffset);
- triIndexPtr->index0 = ;
- triIndexPtr->index1 = + j;
- triIndexPtr->index2 = + (j + )%slices;
- }
- }
- else
- {
- for (Yuint j = ; j < slices; j++)
- {
- nOffset = ((i - )*slices * + slices + j * ) * indexStriding;
- triIndexPtr = (YsTriIndex32*)(indexPtr + nOffset);
- triIndexPtr->index0 = + slices * (i - ) + j;
- triIndexPtr->index1 = + slices * i + j;
- triIndexPtr->index2 = + slices * (i - ) + (j + )%slices;
- nOffset += indexStriding;
- triIndexPtr = (YsTriIndex32*)(indexPtr + nOffset);
- triIndexPtr->index0 = + slices * (i - ) + (j + )%slices;
- triIndexPtr->index1 = + slices * i + j;
- triIndexPtr->index2 = + slices * i + (j + )%slices;
- }
- }
- }
- }
- return true;
- }
线框索引数据的生成
- bool YfBuildArcWireIndices
- (
- Yuint slices,
- Yuint stacks,
- YeIndexType indexType,
- Yuint indexStriding,
- Yuint indexPos,
- void* pWireIndicesBuffer
- )
- {
- if (slices < || !pWireIndicesBuffer)
- {
- return false;
- }
- Yuint numVertices = slices * (stacks - ) + ;
- Yuint numLines = slices * (stacks - ) + slices * (stacks - );
- if (indexType == YE_INDEX_16_BIT &&
- numVertices > YD_MAX_UNSIGNED_INT16)
- {
- return false;
- }
- // 索引赋值
- char* indexPtr = (char*)pWireIndicesBuffer + indexPos;
- Yuint nOffset = ;
- if (indexType == YE_INDEX_16_BIT)
- {
- YsLineIndex16* lineIndexPtr = NULL;
- // 行
- for (Yuint j = ; j < stacks; j++)
- {
- for (Yuint i = ; i < slices; i++)
- {
- nOffset = ((j - )*slices + i) * indexStriding;
- lineIndexPtr = (YsLineIndex16*)(indexPtr + nOffset);
- lineIndexPtr->index0 = + (j - )*slices + i;
- lineIndexPtr->index1 = + (j - )*slices + (i + )%slices;
- }
- }
- // 列
- Yuint half = slices * (stacks - );
- for (Yuint i = ; i < slices; i++)
- {
- nOffset = (half + i) * indexStriding;
- lineIndexPtr = (YsLineIndex16*)(indexPtr + nOffset);
- lineIndexPtr->index0 = ;
- lineIndexPtr->index1 = + i;
- }
- half += slices;
- for (Yuint j = ; j < stacks - ; j++)
- {
- for (Yuint i = ; i < slices; i++)
- {
- nOffset = (half + (j - )*slices + i) * indexStriding;
- lineIndexPtr = (YsLineIndex16*)(indexPtr + nOffset);
- lineIndexPtr->index0 = + (j - )*slices + i;
- lineIndexPtr->index1 = + j*slices + i;
- }
- }
- //// 列
- //Yuint half = slices * (stacks - 1);
- //for (Yuint i = 0; i < slices; i++)
- //{
- // for (Yuint j = 0; j < stacks - 2; j++)
- // {
- // nOffset = (half + (i*(stacks - 1) + j)) * indexStriding;
- // lineIndexPtr = (YsLineIndex16*)(indexPtr + nOffset);
- // if (j == 0)
- // {
- // lineIndexPtr->index0 = 0;
- // }
- // else
- // {
- // lineIndexPtr->index0 = 1 + (j - 1)*slices + i;
- // }
- // lineIndexPtr->index1 = 1 + j*slices + i;
- // }
- //}
- }
- else
- {
- YsLineIndex32* lineIndexPtr = NULL;
- // 行
- for (Yuint j = ; j < stacks; j++)
- {
- for (Yuint i = ; i < slices; i++)
- {
- nOffset = ((j - )*slices + i) * indexStriding;
- lineIndexPtr = (YsLineIndex32*)(indexPtr + nOffset);
- lineIndexPtr->index0 = + (j - )*slices + i;
- lineIndexPtr->index1 = + (j - )*slices + (i + )%slices;
- }
- }
- // 列
- Yuint half = slices * (stacks - );
- for (Yuint i = ; i < slices; i++)
- {
- nOffset = (half + i) * indexStriding;
- lineIndexPtr = (YsLineIndex32*)(indexPtr + nOffset);
- lineIndexPtr->index0 = ;
- lineIndexPtr->index1 = + i;
- }
- half += slices;
- for (Yuint j = ; j < stacks - ; j++)
- {
- for (Yuint i = ; i < slices; i++)
- {
- nOffset = (half + (j - )*slices + i) * indexStriding;
- lineIndexPtr = (YsLineIndex32*)(indexPtr + nOffset);
- lineIndexPtr->index0 = + (j - )*slices + i;
- lineIndexPtr->index1 = + j*slices + i;
- }
- }
- // 列
- //Yuint half = slices * (stacks - 1);
- //for (Yuint i = 0; i < slices; i++)
- //{
- // for (Yuint j = 0; j < stacks - 2; j++)
- // {
- // nOffset = (half + (i*(stacks - 1) + j)) * indexStriding;
- // lineIndexPtr = (YsLineIndex32*)(indexPtr + nOffset);
- // if (j == 0)
- // {
- // lineIndexPtr->index0 = 0;
- // }
- // else
- // {
- // lineIndexPtr->index0 = 1 + (j - 1)*slices + i;
- // }
- // lineIndexPtr->index1 = 1 + j*slices + i;
- // }
- //}
- }
- return true;
- }
[13] 弧面(Arc)图形的生成算法的更多相关文章
- [20] 鼓状物(Drum)图形的生成算法
顶点数据的生成 bool YfBuildDrumVertices ( Yreal radius, Yreal assistRadius, Yuint slices, Yuint stacks, YeO ...
- [17] 楼梯(Stairs)图形的生成算法
感觉这图形怎么看怎么像搓衣板. 顶点数据的生成 bool YfBuildStairsVertices ( Yreal width, Yreal length, Yreal height, Yuint ...
- [19] 半球形(Hemisphere)图形的生成算法
顶点数据的生成 bool YfBuildHemisphereVertices ( Yreal radius, Yuint slices, Yuint stacks, YeOriginPose orig ...
- [18] 螺旋楼梯(Spiral Stairs)图形的生成算法
顶点数据的生成 bool YfBuildSpiralStairsVertices ( Yreal radius, Yreal assistRadius, Yreal height, Yuint sli ...
- [16] 螺旋面(Spire)图形的生成算法
顶点数据的生成 bool YfBuildSpireVertices ( Yreal radius, Yreal assistRadius, Yreal height, Yuint slices, Yu ...
- [15] 星星(Star)图形的生成算法
顶点数据的生成 bool YfBuildStarVertices ( Yreal radius, Yreal assistRadius, Yreal height, Yuint slices, YeO ...
- [14] 齿轮(Gear Wheel)图形的生成算法
顶点数据的生成 bool YfBuildGearwheelVertices ( Yreal radius, Yreal assistRadius, Yreal height, Yuint slices ...
- [12] 扇形体(Fan)图形的生成算法
顶点数据的生成 bool YfBuildFunVertices ( Yreal radius, Yreal degree, Yreal height, Yuint slices, YeOriginPo ...
- [11] 楔形体(Wedge)图形的生成算法
顶点数据的生成 bool YfBuildWedgeVertices ( Yreal width, Yreal length, Yreal height, YeOriginPose originPose ...
随机推荐
- Python之路【第十篇】: python基础之socket编程
阅读目录 一 客户端/服务器架构 二 osi七层 三 socket层 四 socket是什么 五 套接字发展史及分类 六 套接字工作流程 七 基于TCP的套接字 八 基于UDP的套接字 九 recv与 ...
- 深入理解Git - Git底层对象
前篇: 深入理解Git - 一切皆commit 如何从稍微底层一点的角度,从底层实现理解一切皆commit ? 配合希沃白板课件食用,效果更佳: [希沃白板5]课件分享 : <Git 进阶 - ...
- CSUOJ 1021 组合数末尾的零 二进制
Description 从m个不同元素中取出n (n ≤ m)个元素的所有组合的个数,叫做从m个不同元素中取出n个元素的组合数.组合数的计算公式如下: C(m, n) = m!/((m - n)!n! ...
- [ 原创 ] Java基础9--final throw throws finally的区别
final修饰的类不可被继承,final修饰的方法可以被继承但不能被重写(覆盖) final用于可以声明属性和方法,分别表示属性的不可变及方法的不可覆盖.不是方法的不可继承 throw是用来明确地抛出 ...
- [ 原创 ]linux centos下配置java环境教程
一.环境 centos 7.2 二.目标 在CentOS7.2上安装jdk1.8(tar.gz安装包),并配置环境变量 jdk安装在/home/soft/jdk1.8.0-131目录下 具体步骤 1. ...
- Linux驱动之PCI
<背景> PCI设备有许多地址配置的寄存器,初始化时这寄存器来配置设备的总线地址,配置好后CPU就可以访问该设备的各项资源了.(提炼:配置总线地址) <配置寄存器> ( ...
- php 安全模式限制函数
表 42-2. 安全模式限制函数 函数名 限制 dbmopen() 检查被操作的文件或目录是否与正在执行的脚本有相同的 UID(所有者). dbase_open() 检查被操作的文件或目录是否与正在执 ...
- Gunicorn配置部分的翻译
写在前面,虽然翻译得很烂,但也是我的劳动成果,转载请注明出处,谢谢. Gunicorn版本号19.7.1 Gunicorn配置 概述 三种配置方式 优先级如下,越后的优先级越大 1.框架的设置(现在只 ...
- 安装gitlab管理自己的代码
安装gitlab的资料网上搜索很多,但发现很多都是比较老的资料了.我把我安装的过程记录一下,应该是最简单的过程了 1. 到 https://about.gitlab.com/downloads/ 下载 ...
- C#高级编程9-第4章 继承
继承是面向对象的一大特征.要深刻学习继承,需要学会使用调试的技巧来学习它,因为它比较抽象. 继承 继承是指一个具体的类型直接使用另一类型的某些数据成员或函数成员,继承的类是基类(父类),被继承的类是派 ...