[18] 螺旋楼梯(Spiral Stairs)图形的生成算法
顶点数据的生成
1 bool YfBuildSpiralStairsVertices 2 ( 3 Yreal radius, 4 Yreal assistRadius, 5 Yreal height, 6 Yuint slices, 7 Yuint stacks, 8 YeOriginPose originPose, 9 Yuint vertexStriding, 10 Yuint vertexPos, 11 void* pVerticesBuffer 12 ) 13 { 14 if (stacks < 1 || slices < 3 || !pVerticesBuffer) 15 { 16 return false; 17 } 18 Yuint numVertices = 2 + stacks * 4; 19 //Yuint numTriangles = stacks * 8; 20 21 char* vertexPtr = (char*)pVerticesBuffer + vertexPos; 22 YsVector3* curVertexPtr = NULL; 23 Yuint nOffset = 0; 24 25 Yreal originOffsetY = 0.0f; 26 if (originPose == YE_ORIGIN_POSE_TOP) 27 { 28 originOffsetY = -height; 29 } 30 else if (originPose == YE_ORIGIN_POSE_CENTER) 31 { 32 originOffsetY = -height * 0.5f; 33 } 34 35 Yreal fStepTexcoord = 1.0f / (stacks - 1); 36 Yreal fStepHeight = height / stacks; 37 Yreal fStepAngle = YD_REAL_TWAIN_PI / slices; 38 39 Yreal angleXZ; 40 Yreal posX, posZ; 41 for (Yuint i = 0; i <= stacks; i++) 42 { 43 angleXZ = i * fStepAngle; 44 posX = yf_sin(angleXZ); 45 posZ = yf_cos(angleXZ); 46 47 nOffset = i * 4 * vertexStriding; 48 curVertexPtr = (YsVector3*)(vertexPtr + nOffset); 49 curVertexPtr->x = radius * posX; 50 curVertexPtr->y = i * fStepHeight + originOffsetY; 51 curVertexPtr->z = radius * posZ; 52 53 nOffset += vertexStriding; 54 curVertexPtr = (YsVector3*)(vertexPtr + nOffset); 55 curVertexPtr->x = assistRadius * posX; 56 curVertexPtr->y = i * fStepHeight + originOffsetY; 57 curVertexPtr->z = assistRadius * posZ; 58 59 if (i == stacks) 60 { 61 continue; 62 } 63 64 nOffset += vertexStriding; 65 curVertexPtr = (YsVector3*)(vertexPtr + nOffset); 66 curVertexPtr->x = radius * posX; 67 curVertexPtr->y = (i+1) * fStepHeight + originOffsetY; 68 curVertexPtr->z = radius * posZ; 69 70 nOffset += vertexStriding; 71 curVertexPtr = (YsVector3*)(vertexPtr + nOffset); 72 curVertexPtr->x = assistRadius * posX; 73 curVertexPtr->y = (i+1) * fStepHeight + originOffsetY; 74 curVertexPtr->z = assistRadius * posZ; 75 } 76 77 return true; 78 }
三角形索引数据的生成和线框索引数据的生成与楼梯的生成方式一样
1 bool YfBuildSpiralStairsTriIndices 2 ( 3 Yuint stacks, 4 YeIndexType indexType, 5 Yuint indexStriding, 6 Yuint indexPos, 7 void* pTriIndicesBuffer 8 ) 9 { 10 return YfBuildStairsTriIndices( 11 stacks, 12 indexType, 13 indexStriding, 14 indexPos, 15 pTriIndicesBuffer 16 ); 17 } 18 19 bool YfBuildSpiralStairsWireIndices 20 ( 21 Yuint stacks, 22 YeIndexType indexType, 23 Yuint indexStriding, 24 Yuint indexPos, 25 void* pWireIndicesBuffer 26 ) 27 { 28 return YfBuildStairsWireIndices( 29 stacks, 30 indexType, 31 indexStriding, 32 indexPos, 33 pWireIndicesBuffer 34 ); 35 }
分类:
图形生成算法
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?