[18] 螺旋楼梯(Spiral Stairs)图形的生成算法
2024-10-14 23:58:32
顶点数据的生成
bool YfBuildSpiralStairsVertices
(
Yreal radius,
Yreal assistRadius,
Yreal height,
Yuint slices,
Yuint stacks,
YeOriginPose originPose,
Yuint vertexStriding,
Yuint vertexPos,
void* pVerticesBuffer
)
{
if (stacks < || slices < || !pVerticesBuffer)
{
return false;
}
Yuint numVertices = + stacks * ;
//Yuint numTriangles = stacks * 8; 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 fStepTexcoord = 1.0f / (stacks - );
Yreal fStepHeight = height / stacks;
Yreal fStepAngle = YD_REAL_TWAIN_PI / slices; Yreal angleXZ;
Yreal posX, posZ;
for (Yuint i = ; i <= stacks; i++)
{
angleXZ = i * fStepAngle;
posX = yf_sin(angleXZ);
posZ = yf_cos(angleXZ); nOffset = i * * vertexStriding;
curVertexPtr = (YsVector3*)(vertexPtr + nOffset);
curVertexPtr->x = radius * posX;
curVertexPtr->y = i * fStepHeight + originOffsetY;
curVertexPtr->z = radius * posZ; nOffset += vertexStriding;
curVertexPtr = (YsVector3*)(vertexPtr + nOffset);
curVertexPtr->x = assistRadius * posX;
curVertexPtr->y = i * fStepHeight + originOffsetY;
curVertexPtr->z = assistRadius * posZ; if (i == stacks)
{
continue;
} nOffset += vertexStriding;
curVertexPtr = (YsVector3*)(vertexPtr + nOffset);
curVertexPtr->x = radius * posX;
curVertexPtr->y = (i+) * fStepHeight + originOffsetY;
curVertexPtr->z = radius * posZ; nOffset += vertexStriding;
curVertexPtr = (YsVector3*)(vertexPtr + nOffset);
curVertexPtr->x = assistRadius * posX;
curVertexPtr->y = (i+) * fStepHeight + originOffsetY;
curVertexPtr->z = assistRadius * posZ;
} return true;
}
三角形索引数据的生成和线框索引数据的生成与楼梯的生成方式一样
bool YfBuildSpiralStairsTriIndices
(
Yuint stacks,
YeIndexType indexType,
Yuint indexStriding,
Yuint indexPos,
void* pTriIndicesBuffer
)
{
return YfBuildStairsTriIndices(
stacks,
indexType,
indexStriding,
indexPos,
pTriIndicesBuffer
);
} bool YfBuildSpiralStairsWireIndices
(
Yuint stacks,
YeIndexType indexType,
Yuint indexStriding,
Yuint indexPos,
void* pWireIndicesBuffer
)
{
return YfBuildStairsWireIndices(
stacks,
indexType,
indexStriding,
indexPos,
pWireIndicesBuffer
);
}
最新文章
- Disruptor-NET和内存栅栏
- 转:TopN推荐系统——推荐的实现与推荐效果的评价指标
- laravel redis
- python之网络爬虫
- poj: 2255
- 如何将jsp中<;input>;设为只读
- Shiro 缓存失效以后的一个问题
- Pyhon之类学习1
- [記錄用]python py2app 檔案批次重新命名
- Python使用heapq实现小顶堆(TopK大)、大顶堆(BtmK小)
- hdu1876(dp)
- linux上安装mysql及简单的使用
- 【Python爬虫实战--2】时间戳转换为指定格式日期
- Python之路【第二篇】:Python基础(二)
- tyvj4865 天天和树tree
- C# new关键字和对象类型转换(双括号、is操作符、as操作符)
- Android动态加载入坑指南
- OTP&;ETS
- PS调出怀旧雨中特写的非主流照片
- 强大的xargs