• [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 }


     

  • 相关阅读:
    剑指offer-正则表达式匹配-字符串-python****
    剑指offer-构建乘积数组-数组-python
    剑指offer-数组中重复的数字-数组-python
    剑指offer-孩子们的游戏(圆圈中最后剩下的数)-知识迁移能力-python
    剑指offer-扑克牌顺子-知识迁移能力-python
    剑指offer-左旋转字符串-知识迁移能力-python
    剑指offer-和为S的两个数字-知识迁移能力-python
    Shortest Path [3](25分)
    Topological Sort (25分)
    计算机系统基础(一):程序的表示、转换与链接(第十二周小测验)
  • 原文地址:https://www.cnblogs.com/WhyEngine/p/3415263.html
Copyright © 2020-2023  润新知