顶点数据的生成

 bool                        YfBuildPipeVertices
(
Yreal radius,
Yreal assistRadius,
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;
} 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 = radius * posX;
curVertexPtr->y = height + originOffsetY;
curVertexPtr->z = radius * posZ; // 内
nOffset += vertexStriding;
curVertexPtr = (YsVector3*)(vertexPtr + nOffset);
curVertexPtr->x = assistRadius * posX;
curVertexPtr->y = height + originOffsetY;
curVertexPtr->z = assistRadius * posZ;
} // 下顶点
{
// 外
nOffset = (slices * + i * ) * vertexStriding;
curVertexPtr = (YsVector3*)(vertexPtr + nOffset);
curVertexPtr->x = radius * posX;
curVertexPtr->y = originOffsetY;
curVertexPtr->z = radius * posZ; // 内
nOffset += vertexStriding;
curVertexPtr = (YsVector3*)(vertexPtr + nOffset);
curVertexPtr->x = assistRadius * posX;
curVertexPtr->y = originOffsetY;
curVertexPtr->z = assistRadius * posZ;
}
} return true;
}

三角形索引数据的生成

 bool                        YfBuildPipeTriIndices
(
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;
} Yuint halfVtxNum = numVertices / ; // 索引赋值
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 = i * ;
triIndexPtr->index1 = halfVtxNum + i * ;
triIndexPtr->index2 = (i + ) % slices * ; nOffset += indexStriding;
triIndexPtr = (YsTriIndex16*)(indexPtr + nOffset);
triIndexPtr->index0 = (i + ) % slices * ;
triIndexPtr->index1 = halfVtxNum + i * ;
triIndexPtr->index2 = halfVtxNum + (i + ) % slices * ; // 里面
nOffset += indexStriding;
triIndexPtr = (YsTriIndex16*)(indexPtr + nOffset);
triIndexPtr->index0 = i * + ;
triIndexPtr->index1 = (i + ) % slices * + ;
triIndexPtr->index2 = halfVtxNum + i * + ; nOffset += indexStriding;
triIndexPtr = (YsTriIndex16*)(indexPtr + nOffset);
triIndexPtr->index0 = (i + ) % slices * + ;
triIndexPtr->index1 = halfVtxNum + (i + ) % slices * + ;
triIndexPtr->index2 = halfVtxNum + i * + ; // 上面
nOffset += indexStriding;
triIndexPtr = (YsTriIndex16*)(indexPtr + nOffset);
triIndexPtr->index0 = i * ;
triIndexPtr->index1 = (i + ) % slices * + ;
triIndexPtr->index2 = i * + ; nOffset += indexStriding;
triIndexPtr = (YsTriIndex16*)(indexPtr + nOffset);
triIndexPtr->index0 = i * ;
triIndexPtr->index1 = (i + ) % slices * ;
triIndexPtr->index2 = (i + ) % slices * + ; // 下面
nOffset += indexStriding;
triIndexPtr = (YsTriIndex16*)(indexPtr + nOffset);
triIndexPtr->index0 = halfVtxNum + i * ;
triIndexPtr->index1 = halfVtxNum + i * + ;
triIndexPtr->index2 = halfVtxNum + (i + ) % slices * + ; nOffset += indexStriding;
triIndexPtr = (YsTriIndex16*)(indexPtr + nOffset);
triIndexPtr->index0 = halfVtxNum + i * ;
triIndexPtr->index1 = halfVtxNum + (i + ) % slices * + ;
triIndexPtr->index2 = halfVtxNum + (i + ) % slices * ;
}
}
else
{
YsTriIndex32* triIndexPtr = NULL;
for (Yuint i = ; i < slices; i++)
{
// 外面
nOffset = (i * ) * indexStriding;
triIndexPtr = (YsTriIndex32*)(indexPtr + nOffset);
triIndexPtr->index0 = i * ;
triIndexPtr->index1 = halfVtxNum + i * ;
triIndexPtr->index2 = (i + ) % slices * ; nOffset += indexStriding;
triIndexPtr = (YsTriIndex32*)(indexPtr + nOffset);
triIndexPtr->index0 = (i + ) % slices * ;
triIndexPtr->index1 = halfVtxNum + i * ;
triIndexPtr->index2 = halfVtxNum + (i + ) % slices * ; // 里面
nOffset += indexStriding;
triIndexPtr = (YsTriIndex32*)(indexPtr + nOffset);
triIndexPtr->index0 = i * + ;
triIndexPtr->index1 = (i + ) % slices * + ;
triIndexPtr->index2 = halfVtxNum + i * + ; nOffset += indexStriding;
triIndexPtr = (YsTriIndex32*)(indexPtr + nOffset);
triIndexPtr->index0 = (i + ) % slices * + ;
triIndexPtr->index1 = halfVtxNum + (i + ) % slices * + ;
triIndexPtr->index2 = halfVtxNum + i * + ; // 上面
nOffset += indexStriding;
triIndexPtr = (YsTriIndex32*)(indexPtr + nOffset);
triIndexPtr->index0 = i * ;
triIndexPtr->index1 = (i + ) % slices * + ;
triIndexPtr->index2 = i * + ; nOffset += indexStriding;
triIndexPtr = (YsTriIndex32*)(indexPtr + nOffset);
triIndexPtr->index0 = i * ;
triIndexPtr->index1 = (i + ) % slices * ;
triIndexPtr->index2 = (i + ) % slices * + ; // 下面
nOffset += indexStriding;
triIndexPtr = (YsTriIndex32*)(indexPtr + nOffset);
triIndexPtr->index0 = halfVtxNum + i * ;
triIndexPtr->index1 = halfVtxNum + i * + ;
triIndexPtr->index2 = halfVtxNum + (i + ) % slices * + ; nOffset += indexStriding;
triIndexPtr = (YsTriIndex32*)(indexPtr + nOffset);
triIndexPtr->index0 = halfVtxNum + i * ;
triIndexPtr->index1 = halfVtxNum + (i + ) % slices * + ;
triIndexPtr->index2 = halfVtxNum + (i + ) % slices * ;
}
} return true;
}

线框索引数据的生成

 bool                        YfBuildPipeWireIndices
(
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;
} Yuint halfVtxNum = numVertices / ; // 索引赋值
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 = i * ;
lineIndexPtr->index1 = halfVtxNum + i * ; // 里面
nOffset += indexStriding;
lineIndexPtr = (YsLineIndex16*)(indexPtr + nOffset);
lineIndexPtr->index0 = i * + ;
lineIndexPtr->index1 = halfVtxNum + i * + ; // 上面
nOffset += indexStriding;
lineIndexPtr = (YsLineIndex16*)(indexPtr + nOffset);
lineIndexPtr->index0 = i * ;
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 = (i + ) % slices * + ; // 下面
nOffset += indexStriding;
lineIndexPtr = (YsLineIndex16*)(indexPtr + nOffset);
lineIndexPtr->index0 = halfVtxNum + i * ;
lineIndexPtr->index1 = halfVtxNum + i * + ; nOffset += indexStriding;
lineIndexPtr = (YsLineIndex16*)(indexPtr + nOffset);
lineIndexPtr->index0 = halfVtxNum + i * ;
lineIndexPtr->index1 = halfVtxNum + (i + ) % slices * ; nOffset += indexStriding;
lineIndexPtr = (YsLineIndex16*)(indexPtr + nOffset);
lineIndexPtr->index0 = halfVtxNum + i * + ;
lineIndexPtr->index1 = halfVtxNum + (i + ) % slices * + ;
}
}
else
{
YsLineIndex32* lineIndexPtr = NULL;
for (Yuint i= ; i < slices; i++)
{
// 外面
nOffset = (i * ) * indexStriding;
lineIndexPtr = (YsLineIndex32*)(indexPtr + nOffset);
lineIndexPtr->index0 = i * ;
lineIndexPtr->index1 = halfVtxNum + i * ; // 里面
nOffset += indexStriding;
lineIndexPtr = (YsLineIndex32*)(indexPtr + nOffset);
lineIndexPtr->index0 = i * + ;
lineIndexPtr->index1 = halfVtxNum + i * + ; // 上面
nOffset += indexStriding;
lineIndexPtr = (YsLineIndex32*)(indexPtr + nOffset);
lineIndexPtr->index0 = i * ;
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 = (i + ) % slices * + ; // 下面
nOffset += indexStriding;
lineIndexPtr = (YsLineIndex32*)(indexPtr + nOffset);
lineIndexPtr->index0 = halfVtxNum + i * ;
lineIndexPtr->index1 = halfVtxNum + i * + ; nOffset += indexStriding;
lineIndexPtr = (YsLineIndex32*)(indexPtr + nOffset);
lineIndexPtr->index0 = halfVtxNum + i * ;
lineIndexPtr->index1 = halfVtxNum + (i + ) % slices * ; nOffset += indexStriding;
lineIndexPtr = (YsLineIndex32*)(indexPtr + nOffset);
lineIndexPtr->index0 = halfVtxNum + i * + ;
lineIndexPtr->index1 = halfVtxNum + (i + ) % slices * + ;
}
} return true;
}

[10] 圆管(Pipe)图形的生成算法的更多相关文章

  1. [8] 圆面(Round)图形的生成算法

    顶点数据的生成 bool YfBuildRoundVertices ( Yreal radius, Yreal height, Yuint slices, YeOriginPose originPos ...

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

随机推荐

  1. @ControllerAdvice + @ExceptionHandler 处理 全部Controller层异常

    对于与数据库相关的 Spring MVC 项目,我们通常会把 事务 配置在 Service层,当数据库操作失败时让 Service 层抛出运行时异常,Spring 事物管理器就会进行回滚. 如此一来, ...

  2. leetcode easy problem set

     *勿以浮沙筑高台* 持续更新........     题目网址:https://leetcode.com/problemset/all/?difficulty=Easy 1. Two Sum [4m ...

  3. (视频)asp.net core系列之k8s集群部署视频

    0.前言 应许多网友的要求,特此录制一下k8s集群部署的视频.在录制完成后发现视频的声音存在一点瑕疵,不过不影响大家的观感. 一.视频说明 1.视频地址: 如果有不懂,或者有疑问的欢迎留言.视频分为两 ...

  4. Xshell拖拽上传文件插件

    lrzsz是一款在linux里可代替ftp上传和下载的程序.在linux中支持直接拖拽上传的插件:同时也支持rz和sz进行命令上传和下载. 插件安装 yum -y install lrzsz 上传(r ...

  5. [WC2018]州区划分(状压DP+FWT/FMT)

    很裸的子集反演模板题,套上一些莫名其妙的外衣. 先预处理每个集合是否合法,再作显然的状压DP.然后发现可以写成子集反演的形式,直接套模板即可. 子集反演可以看这里. 子集反演的过程就是多设一维代表集合 ...

  6. BZOJ 2118 墨墨的等式(最短路)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=2118 [题目大意] 求a1x1+a2y2+…+anxn=B在B的取值范围,有多少B可以 ...

  7. vijos p1881 线段树

    题意:点我 我就想问,现在换代码风格还来得及吗? 2015-05-19:线段树进一步加强,看来不用换风格了 维护左右节点左右端颜色和长度即可 #include<cstdio> #inclu ...

  8. 【转载】CMarkup函数说明

    1.初始化Load    导入一个XML文件到CMarkup的对象中,并对它进行解析.类似C#的Load.SetDoc  从字符串中导入XML数据,并对它解析.类似C#的LoadXml. 2.输出Sa ...

  9. elasticsearch 亿级数据检索案例与原理

    版权说明: 本文章版权归本人及博客园共同所有,转载请标明原文出处( https://www.cnblogs.com/mikevictor07/p/10006553.html ),以下内容为个人理解,仅 ...

  10. An ac a day,keep wa away

    zoj 初学者题: 1001 1037 1048 1049 1051 1067 1115 1151 1201 1205 1216 1240 1241 1242 1251 1292 1331 1334 ...