[10] 圆管(Pipe)图形的生成算法
顶点数据的生成
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)图形的生成算法的更多相关文章
- [8] 圆面(Round)图形的生成算法
顶点数据的生成 bool YfBuildRoundVertices ( Yreal radius, Yreal height, Yuint slices, YeOriginPose originPos ...
- [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 ...
- [13] 弧面(Arc)图形的生成算法
顶点数据的生成 bool YfBuildArcVertices ( Yreal radius, Yreal degree, Yreal height, Yuint slices, Yuint stac ...
随机推荐
- jdk与eclipse不匹配的各种问题。。。
- 20169211《Linux内核原理及分析》第十二周作业
Collabtive 系统 SQL 注入实验 实验介绍 SQL注入漏洞的代码注入技术,利用web应用程序和数据库服务器之间的接口.通过把SQL命令插入到Web表单提交或输入域名或页面请求的查询字符串, ...
- Python匹配中文的正则表达式
python 中的字符串: https://www.cnblogs.com/livingintruth/p/3282981.html # -*- coding: utf-8 -*- import re ...
- 【搜索+DP】codevs1066-引水入城
[题目大意] 一个N行M列的矩形,如上图所示,其中每个格子都代表一座城 市,每座城市都有一个海拔高度.现在要在某些城市建造水利设施.水利设施有两种,分别为蓄水厂和输水站.蓄水厂的功能是利用水泵将湖泊中 ...
- [HihoCoder1596]Beautiful Sequence
题目大意: \(n(n\le60)\)个数\(A_{1\sim n}\),将这些数随机打乱,问最后构成的数列满足对于所有的\(2\le i\le n-1\),都有\(2A_i\le A_{i-1}+A ...
- 【BZOJ】2760: [JLOI2011]小A的烦恼【字符串模拟】
2760: [JLOI2011]小A的烦恼 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 406 Solved: 258[Submit][Statu ...
- bzoj 1492
这道题真好... 首先,感觉像DP,但是如果按照原题意,有无数个状态,每个状态又有无数个转移. 然后思考,我们每次买一部分和卖一部分的原因是什么,如果没有那个比例(就是rate=1恒成立),那么很容易 ...
- BZOJ 2749 HAOI 2012 外星人 数论 欧拉函数
题意: 给出一个数,给出的形式是其分解质因数后,对应的质因数pi及其次数qi,问对这个数不停求phi,直至这个数变成1,需要多少次.(多组数据) 范围:pi <= 1e5,qi <= 1e ...
- Codeforces Round #361 (Div. 2) C. Mike and Chocolate Thieves 二分
C. Mike and Chocolate Thieves 题目连接: http://www.codeforces.com/contest/689/problem/C Description Bad ...
- UVALive 5971
Problem J Permutation Counting Dexter considers a permutation of first N natural numbers good if it ...