顶点数据的生成

 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. linux下解除端口占用

    1.找出占用端口进程的pid sudo lsof -i:port 2.终止进程 pid

  2. python 学习之dict和set类型

    什么是dict 我们已经知道,list 和 tuple 可以用来表示顺序集合,例如,班里同学的名字: ['Adam', 'Lisa', 'Bart'] 或者考试的成绩列表: [95, 85, 59] ...

  3. MySQL 字段类型占用空间

    MySQL支持多种列类型:数值类型.日期/时间类型和字符串(字符)类型. 首先来看下各类型的存储需求(即占用空间大小): 数值类型存储需求 列类型 存储需求 TINYINT 1个字节 SMALLINT ...

  4. idea导入或打开项目配置问题

    learn项目遇到问题: 1.IntelliJ Idea编译报错:请使用 -source 7 或更高版本以启用 diamond 运算符 file - project structure或者直接快捷键: ...

  5. [ 转载 ] Centos 安装mysql后启动失败 出现 ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’

    MySQL Daemon failed to start Mysql出问题一定要学会查看log https://blog.csdn.net/shuai825644975/article/details ...

  6. 机器学习之路: 深度学习 tensorflow 神经网络优化算法 学习率的设置

    在神经网络中,广泛的使用反向传播和梯度下降算法调整神经网络中参数的取值. 梯度下降和学习率: 假设用 θ 来表示神经网络中的参数, J(θ) 表示在给定参数下训练数据集上损失函数的大小. 那么整个优化 ...

  7. 使用gSOAP工具生成onvif框架代码

    <工具产生背景>          由于SOAP是一种基于xml的文件,手动编写SOAP文件太机械耗时,在这种背景下产生了gSAOP 这个工具,用于生成各种类型的代码,目前支持C/C++, ...

  8. Kolibri v2.0-Buffer Overflow成功复现

    Kolibri v2.0-Buffer Overflow成功复现及分析 文件下载地址:http://pan.baidu.com/s/1eS9r9lS 正文 本次讲解用JMP ESP的方法溢出 关于网上 ...

  9. hdu 4745 区间dp

    题意:求一个环的最长回文序列,是序列不是串 链接:点我 起点是可以任意的, 所以只要求出每个区间的最长回文序列之后取max(dp[1][i]+dp[i+1][n]),即可得最终答案 本来是想扩展两倍的 ...

  10. hdu 3068 Manacher算法

    题意:求最长回文串,模板题 #include<cstdio> #include<iostream> #include<algorithm> #include< ...