顶点数据的生成

 bool                        YfBuildCylinderVertices
(
Yreal topRadius,
Yreal bottomRadius,
Yreal height,
Yuint slices,
YeOriginPose originPose,
Yuint vertexStriding,
Yuint vertexPos,
void* pVerticesBuffer
)
{
if (slices < || !pVerticesBuffer)
{
return false;
} Yuint numVertices = slices * + ; // 顶点赋值
char* vertexPtr = (char*)pVerticesBuffer + vertexPos;
YsVector3* curVertexPtr = NULL;
Yuint nOffset = ; Yreal originOffsetY = 0.0f;
if (originPose == YE_ORIGIN_POSE_TOP)
{
originOffsetY = -height;
}
else if (originPose == YE_ORIGIN_POSE_CENTER)
{
originOffsetY = -height * 0.5f;
} // 柱顶顶点赋值
{
nOffset = ;
curVertexPtr = (YsVector3*)(vertexPtr + nOffset);
curVertexPtr->x = 0.0f;
curVertexPtr->y = height + originOffsetY;
curVertexPtr->z = 0.0f;
} // 柱底顶点赋值
{
nOffset = (numVertices - ) * vertexStriding;
curVertexPtr = (YsVector3*)(vertexPtr + nOffset);
curVertexPtr->x = 0.0f;
curVertexPtr->y = originOffsetY;
curVertexPtr->z = 0.0f;
} Yreal angleXZ;
Yreal posX, posZ;
for (Yuint i = ; i < slices; i++)
{
angleXZ = YD_REAL_TWAIN_PI * i / slices;
posX = yf_sin(angleXZ);
posZ = yf_cos(angleXZ); // 上顶点
{
nOffset = (i + ) * vertexStriding;
curVertexPtr = (YsVector3*)(vertexPtr + nOffset);
curVertexPtr->x = topRadius * posX;
curVertexPtr->y = height + originOffsetY;
curVertexPtr->z = topRadius * posZ;
} // 下顶点
{
nOffset = (i + + slices) * vertexStriding;
curVertexPtr = (YsVector3*)(vertexPtr + nOffset);
curVertexPtr->x = bottomRadius * posX;
curVertexPtr->y = originOffsetY;
curVertexPtr->z = bottomRadius * posZ;
}
} return true;
}

三角形索引数据的生成

 bool                        YfBuildCylinderTriIndices
(
Yuint slices,
YeIndexType indexType,
Yuint indexStriding,
Yuint indexPos,
void* pTriIndicesBuffer
)
{
if (slices < || !pTriIndicesBuffer)
{
return false;
} Yuint numVertices = slices * + ;
Yuint numTriangles = 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 < slices; i++)
{
nOffset = (i * ) * indexStriding;
triIndexPtr = (YsTriIndex16*)(indexPtr + nOffset);
triIndexPtr->index0 = ;
triIndexPtr->index1 = + i;
triIndexPtr->index2 = + (i + )%slices; nOffset += indexStriding;
triIndexPtr = (YsTriIndex16*)(indexPtr + nOffset);
triIndexPtr->index0 = numVertices - ;
triIndexPtr->index1 = + slices + (i + )%slices;
triIndexPtr->index2 = + slices + i; nOffset += indexStriding;
triIndexPtr = (YsTriIndex16*)(indexPtr + nOffset);
triIndexPtr->index0 = + i;
triIndexPtr->index1 = + slices + i;
triIndexPtr->index2 = + (i + )%slices; nOffset += indexStriding;
triIndexPtr = (YsTriIndex16*)(indexPtr + nOffset);
triIndexPtr->index0 = + (i + )%slices;
triIndexPtr->index1 = + slices + i;
triIndexPtr->index2 = + slices + (i + )%slices;
}
}
else
{
YsTriIndex32* triIndexPtr = NULL;
for (Yuint i= ; i < slices; i++)
{
nOffset = (i * ) * indexStriding;
triIndexPtr = (YsTriIndex32*)(indexPtr + nOffset);
triIndexPtr->index0 = ;
triIndexPtr->index1 = + i;
triIndexPtr->index2 = + (i + )%slices; nOffset += indexStriding;
triIndexPtr = (YsTriIndex32*)(indexPtr + nOffset);
triIndexPtr->index0 = numVertices - ;
triIndexPtr->index1 = + slices + (i + )%slices;
triIndexPtr->index2 = + slices + i; nOffset += indexStriding;
triIndexPtr = (YsTriIndex32*)(indexPtr + nOffset);
triIndexPtr->index0 = + i;
triIndexPtr->index1 = + slices + i;
triIndexPtr->index2 = + (i + )%slices; nOffset += indexStriding;
triIndexPtr = (YsTriIndex32*)(indexPtr + nOffset);
triIndexPtr->index0 = + (i + )%slices;
triIndexPtr->index1 = + slices + i;
triIndexPtr->index2 = + slices + (i + )%slices;
}
} return true;
}

线框索引数据的生成

 bool                        YfBuildCylinderWireIndices
(
Yuint slices,
YeIndexType indexType,
Yuint indexStriding,
Yuint indexPos,
void* pWireIndicesBuffer
)
{
if (slices < || !pWireIndicesBuffer)
{
return false;
} Yuint numVertices = slices * + ;
Yuint numLines = slices * ;
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 i= ; i < slices; i++)
{
nOffset = (i * ) * indexStriding;
lineIndexPtr = (YsLineIndex16*)(indexPtr + nOffset);
lineIndexPtr->index0 = ;
lineIndexPtr->index1 = + i; nOffset += indexStriding;
lineIndexPtr = (YsLineIndex16*)(indexPtr + nOffset);
lineIndexPtr->index0 = + i;
lineIndexPtr->index1 = + (i + )%slices; nOffset += indexStriding;
lineIndexPtr = (YsLineIndex16*)(indexPtr + nOffset);
lineIndexPtr->index0 = + i;
lineIndexPtr->index1 = + slices + i; nOffset += indexStriding;
lineIndexPtr = (YsLineIndex16*)(indexPtr + nOffset);
lineIndexPtr->index0 = + slices + i;
lineIndexPtr->index1 = + slices + (i + )%slices; nOffset += indexStriding;
lineIndexPtr = (YsLineIndex16*)(indexPtr + nOffset);
lineIndexPtr->index0 = numVertices - ;
lineIndexPtr->index1 = + slices + i;
}
}
else
{
YsLineIndex32* lineIndexPtr = NULL;
for (Yuint i= ; i < slices; i++)
{
nOffset = (i * ) * indexStriding;
lineIndexPtr = (YsLineIndex32*)(indexPtr + nOffset);
lineIndexPtr->index0 = ;
lineIndexPtr->index1 = + i; nOffset += indexStriding;
lineIndexPtr = (YsLineIndex32*)(indexPtr + nOffset);
lineIndexPtr->index0 = + i;
lineIndexPtr->index1 = + (i + )%slices; nOffset += indexStriding;
lineIndexPtr = (YsLineIndex32*)(indexPtr + nOffset);
lineIndexPtr->index0 = + i;
lineIndexPtr->index1 = + slices + i; nOffset += indexStriding;
lineIndexPtr = (YsLineIndex32*)(indexPtr + nOffset);
lineIndexPtr->index0 = + slices + i;
lineIndexPtr->index1 = + slices + (i + )%slices; nOffset += indexStriding;
lineIndexPtr = (YsLineIndex32*)(indexPtr + nOffset);
lineIndexPtr->index0 = numVertices - ;
lineIndexPtr->index1 = + slices + i;
}
} return true;
}

[5] 柱台(Cylinder)图形的生成算法的更多相关文章

  1. [20] 鼓状物(Drum)图形的生成算法

    顶点数据的生成 bool YfBuildDrumVertices ( Yreal radius, Yreal assistRadius, Yuint slices, Yuint stacks, YeO ...

  2. [17] 楼梯(Stairs)图形的生成算法

    感觉这图形怎么看怎么像搓衣板. 顶点数据的生成 bool YfBuildStairsVertices ( Yreal width, Yreal length, Yreal height, Yuint ...

  3. [19] 半球形(Hemisphere)图形的生成算法

    顶点数据的生成 bool YfBuildHemisphereVertices ( Yreal radius, Yuint slices, Yuint stacks, YeOriginPose orig ...

  4. [18] 螺旋楼梯(Spiral Stairs)图形的生成算法

    顶点数据的生成 bool YfBuildSpiralStairsVertices ( Yreal radius, Yreal assistRadius, Yreal height, Yuint sli ...

  5. [16] 螺旋面(Spire)图形的生成算法

    顶点数据的生成 bool YfBuildSpireVertices ( Yreal radius, Yreal assistRadius, Yreal height, Yuint slices, Yu ...

  6. [15] 星星(Star)图形的生成算法

    顶点数据的生成 bool YfBuildStarVertices ( Yreal radius, Yreal assistRadius, Yreal height, Yuint slices, YeO ...

  7. [14] 齿轮(Gear Wheel)图形的生成算法

    顶点数据的生成 bool YfBuildGearwheelVertices ( Yreal radius, Yreal assistRadius, Yreal height, Yuint slices ...

  8. [13] 弧面(Arc)图形的生成算法

    顶点数据的生成 bool YfBuildArcVertices ( Yreal radius, Yreal degree, Yreal height, Yuint slices, Yuint stac ...

  9. [12] 扇形体(Fan)图形的生成算法

    顶点数据的生成 bool YfBuildFunVertices ( Yreal radius, Yreal degree, Yreal height, Yuint slices, YeOriginPo ...

随机推荐

  1. mysql 拾遗提高(函数、事务、索引)

    目录 1.tips 2.事务(transaction) 3.索引(index) 4.数据库的导出和备份 5.函数 6.防SQL注入 7.使用Explain分析SQL语句 8.视图(view) 1.ti ...

  2. 基于Laravel开发博客应用系列 —— 十分钟搭建博客系统

    1.创建文章数据表及其模型(0:00~2:30) 我们已经在上一节中为博客项目完成了大部分准备工作,现在首先要做的就是为这个项目创建一个新的文章表 posts及该表对应的模型类 Post,使用如下Ar ...

  3. js把json数据转化成树形数据

    /*转化函数*/ function(data, attributes) { let resData = data; let tree = []; for(let i = 0; i < resDa ...

  4. scala递归实现换零钱算法

    import scala.collection.mutable.ArrayBuffer import scala.util.control.Breaks object Exchange { def d ...

  5. linux 下nginx安装

    一.一键安装四个依赖 yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel 二.创建一个安装目录,并下载nginx安装 ...

  6. 【基础知识】.Net基础加强 第二天

    第02天 .Net基础加强 1. 封装 1> 属性的封装: 属性封装字段:把变化封装一下,保留用户的使用方式 2> 把方法的多个参数封装成一个对象 3> 将一堆代码封装到一个方法中 ...

  7. 时间插件datetimepicker

    相关datetimepicker用法查看官网http://eonasdan.github.io/bootstrap-datetimepicker/ {% load staticfiles %} < ...

  8. DataTable,List,Dictonary互转,筛选及相关写法

    1.创建自定义DataTable  /// 创建自定义DataTable(一) 根据列名字符串数组, /// </summary> /// <param name="sLi ...

  9. 洛谷.4525.[模板]自适应辛普森法1(Simpson积分)

    题目链接 Simpson积分公式:\[\int_a^bf(x)dx\approx\frac{b-a}{6}\left[f(a)+f(b)+4f(\frac{a+b}{2})\right]\] 推导过程 ...

  10. 2018-2019-20172329 《Java软件结构与数据结构》第三周学习总结

    2018-2019-20172329 <Java软件结构与数据结构>第三周学习总结 教材学习内容总结 <Java软件结构与数据结构>第五章-队列 一.概述 1.队列是什么? 队 ...