顶点数据的生成

  1. bool YfBuildHemisphereVertices
  2. (
  3. Yreal radius,
  4. Yuint slices,
  5. Yuint stacks,
  6. YeOriginPose originPose,
  7. Yuint vertexStriding,
  8. Yuint vertexPos,
  9. void* pVerticesBuffer
  10. )
  11. {
  12. if (slices < || stacks < || !pVerticesBuffer)
  13. {
  14. return false;
  15. }
  16.  
  17. Yuint numVertices = slices * (stacks - ) + ;
  18.  
  19. // 顶点赋值
  20. char* vertexPtr = (char*)pVerticesBuffer + vertexPos;
  21. YsVector3* curVertexPtr = NULL;
  22. Yuint nOffset = ;
  23.  
  24. Yreal originOffsetY = 0.0f;
  25. if (originPose == YE_ORIGIN_POSE_TOP)
  26. {
  27. originOffsetY = -radius;
  28. }
  29. else if (originPose == YE_ORIGIN_POSE_BOTTOM)
  30. {
  31. originOffsetY = radius;
  32. }
  33.  
  34. Yreal* pSinList = YD_NEW_ARRAY(Yreal, slices);
  35. Yreal* pCosList = YD_NEW_ARRAY(Yreal, slices);
  36. Yreal angleXZ;
  37. for (Yuint j = ; j < slices; j++)
  38. {
  39. angleXZ = YD_REAL_TWAIN_PI * j / slices;
  40. pSinList[j] = yf_sin(angleXZ);
  41. pCosList[j] = yf_cos(angleXZ);
  42. }
  43.  
  44. // 赋值
  45. {
  46. for (Yuint i = ; i < stacks; i++)
  47. {
  48. if (i == ) // 第一个顶点
  49. {
  50. nOffset = ;
  51. curVertexPtr = (YsVector3*)(vertexPtr + nOffset);
  52. curVertexPtr->x = 0.0f;
  53. curVertexPtr->y = radius + originOffsetY;
  54. curVertexPtr->z = 0.0f;
  55. continue;
  56. }
  57.  
  58. Yreal angleY = YD_REAL_HALF_PI * i / (stacks - );
  59. Yreal posY = radius * yf_cos(angleY);
  60. Yreal radiusXZ = radius * yf_sin(angleY);
  61. Yreal posX, posZ;
  62.  
  63. for (Yuint j = ; j < slices; j++)
  64. {
  65. posX = radiusXZ * pSinList[j];
  66. posZ = radiusXZ * pCosList[j];
  67. nOffset = ((i - ) * slices + j + ) * vertexStriding;
  68. curVertexPtr = (YsVector3*)(vertexPtr + nOffset);
  69. curVertexPtr->x = posX;
  70. curVertexPtr->y = posY + originOffsetY;
  71. curVertexPtr->z = posZ;
  72. }
  73. }
  74. }
  75.  
  76. YD_SAFE_DELETE_ARRAY(pSinList);
  77. YD_SAFE_DELETE_ARRAY(pCosList);
  78.  
  79. return true;
  80. }

三角形索引数据的生成

  1. bool YfBuildHemisphereTriIndices
  2. (
  3. Yuint slices,
  4. Yuint stacks,
  5. YeIndexType indexType,
  6. Yuint indexStriding,
  7. Yuint indexPos,
  8. void* pTriIndicesBuffer
  9. )
  10. {
  11. if (slices < || stacks < || !pTriIndicesBuffer)
  12. {
  13. return false;
  14. }
  15.  
  16. Yuint numVertices = slices * (stacks - ) + ;
  17. if (indexType == YE_INDEX_16_BIT &&
  18. numVertices > YD_MAX_UNSIGNED_INT16)
  19. {
  20. return false;
  21. }
  22. Yuint numTriangles = slices * (stacks - ) * + slices;
  23.  
  24. // 索引赋值
  25. char* indexPtr = (char*)pTriIndicesBuffer + indexPos;
  26. Yuint nOffset = ;
  27. if (indexType == YE_INDEX_16_BIT)
  28. {
  29. YsTriIndex16* triIndexPtr = NULL;
  30.  
  31. for (Yuint i = ; i < stacks - ; i++)
  32. {
  33. if (i == ) // 第一层
  34. {
  35. for (Yuint j = ; j < slices; j++)
  36. {
  37. nOffset = j * indexStriding;
  38. triIndexPtr = (YsTriIndex16*)(indexPtr + nOffset);
  39. triIndexPtr->index0 = ;
  40. triIndexPtr->index1 = + j;
  41. triIndexPtr->index2 = + (j + )%slices;
  42. }
  43. }
  44. else
  45. {
  46. for (Yuint j = ; j < slices; j++)
  47. {
  48. nOffset = (slices + (i - )*slices * + j * ) * indexStriding;
  49. triIndexPtr = (YsTriIndex16*)(indexPtr + nOffset);
  50. triIndexPtr->index0 = + slices * (i - ) + j;
  51. triIndexPtr->index1 = + slices * i + j;
  52. triIndexPtr->index2 = + slices * (i - ) + (j + )%slices;
  53.  
  54. nOffset += indexStriding;
  55. triIndexPtr = (YsTriIndex16*)(indexPtr + nOffset);
  56. triIndexPtr->index0 = + slices * (i - ) + (j + )%slices;
  57. triIndexPtr->index1 = + slices * i + j;
  58. triIndexPtr->index2 = + slices * i + (j + )%slices;
  59. }
  60. }
  61. }
  62. }
  63. else
  64. {
  65. YsTriIndex32* triIndexPtr = NULL;
  66.  
  67. // 赋值
  68. for (Yuint i = ; i < stacks - ; i++)
  69. {
  70. if (i == ) // 第一层
  71. {
  72. for (Yuint j = ; j < slices; j++)
  73. {
  74. nOffset = j * indexStriding;
  75. triIndexPtr = (YsTriIndex32*)(indexPtr + nOffset);
  76. triIndexPtr->index0 = ;
  77. triIndexPtr->index1 = + j;
  78. triIndexPtr->index2 = + (j + )%slices;
  79. }
  80. }
  81. else
  82. {
  83. for (Yuint j = ; j < slices; j++)
  84. {
  85. nOffset = (slices + (i - )*slices * + j * ) * indexStriding;
  86. triIndexPtr = (YsTriIndex32*)(indexPtr + nOffset);
  87. triIndexPtr->index0 = + slices * (i - ) + j;
  88. triIndexPtr->index1 = + slices * i + j;
  89. triIndexPtr->index2 = + slices * (i - ) + (j + )%slices;
  90.  
  91. nOffset += indexStriding;
  92. triIndexPtr = (YsTriIndex32*)(indexPtr + nOffset);
  93. triIndexPtr->index0 = + slices * (i - ) + (j + )%slices;
  94. triIndexPtr->index1 = + slices * i + j;
  95. triIndexPtr->index2 = + slices * i + (j + )%slices;
  96. }
  97. }
  98. }
  99. }
  100.  
  101. return true;
  102. }

线框索引数据的生成

  1. bool YfBuildHemisphereWireIndices
  2. (
  3. Yuint slices,
  4. Yuint stacks,
  5. YeIndexType indexType,
  6. Yuint indexStriding,
  7. Yuint indexPos,
  8. void* pWireIndicesBuffer
  9. )
  10. {
  11. if (slices < || stacks < || !pWireIndicesBuffer)
  12. {
  13. return false;
  14. }
  15.  
  16. Yuint numVertices = slices * (stacks - ) + ;
  17. if (indexType == YE_INDEX_16_BIT &&
  18. numVertices > YD_MAX_UNSIGNED_INT16)
  19. {
  20. return false;
  21. }
  22. Yuint numLines = slices * (stacks - ) * ;
  23.  
  24. char* indexPtr = (char*)pWireIndicesBuffer + indexPos;
  25. Yuint nOffset = ;
  26.  
  27. if (indexType == YE_INDEX_16_BIT)
  28. {
  29. YsLineIndex16* lineIndexPtr = NULL;
  30.  
  31. // 行
  32. for (Yuint j = ; j < stacks; j++)
  33. {
  34. for (Yuint i = ; i < slices; i++)
  35. {
  36. nOffset = ((j - )*slices + i) * indexStriding;
  37. lineIndexPtr = (YsLineIndex16*)(indexPtr + nOffset);
  38. lineIndexPtr->index0 = + (j - )*slices + i;
  39. lineIndexPtr->index1 = + (j - )*slices + (i + )%slices;
  40. }
  41. }
  42.  
  43. Yuint count = slices * (stacks - );
  44.  
  45. // 列
  46. for (Yuint i = ; i < slices; i++)
  47. {
  48. nOffset = (count + i) * indexStriding;
  49. lineIndexPtr = (YsLineIndex16*)(indexPtr + nOffset);
  50. lineIndexPtr->index0 = ;
  51. lineIndexPtr->index1 = + i;
  52. }
  53. count += slices;
  54.  
  55. for (Yuint j = ; j < stacks - ; j++)
  56. {
  57. for (Yuint i = ; i < slices; i++)
  58. {
  59. nOffset = (count + (j - )*slices + i) * indexStriding;
  60. lineIndexPtr = (YsLineIndex16*)(indexPtr + nOffset);
  61. lineIndexPtr->index0 = + (j - )*slices + i;
  62. lineIndexPtr->index1 = + j*slices + i;
  63. }
  64. }
  65. }
  66. else
  67. {
  68. YsLineIndex32* lineIndexPtr = NULL;
  69.  
  70. // 行
  71. for (Yuint j = ; j < stacks; j++)
  72. {
  73. for (Yuint i = ; i < slices; i++)
  74. {
  75. nOffset = ((j - )*slices + i) * indexStriding;
  76. lineIndexPtr = (YsLineIndex32*)(indexPtr + nOffset);
  77. lineIndexPtr->index0 = + (j - )*slices + i;
  78. lineIndexPtr->index1 = + (j - )*slices + (i + )%slices;
  79. }
  80. }
  81.  
  82. Yuint count = slices * (stacks - );
  83.  
  84. // 列
  85. for (Yuint i = ; i < slices; i++)
  86. {
  87. nOffset = (count + i) * indexStriding;
  88. lineIndexPtr = (YsLineIndex32*)(indexPtr + nOffset);
  89. lineIndexPtr->index0 = ;
  90. lineIndexPtr->index1 = + i;
  91. }
  92. count += slices;
  93.  
  94. for (Yuint j = ; j < stacks - ; j++)
  95. {
  96. for (Yuint i = ; i < slices; i++)
  97. {
  98. nOffset = (count + (j - )*slices + i) * indexStriding;
  99. lineIndexPtr = (YsLineIndex32*)(indexPtr + nOffset);
  100. lineIndexPtr->index0 = + (j - )*slices + i;
  101. lineIndexPtr->index1 = + j*slices + i;
  102. }
  103. }
  104. }
  105.  
  106. return true;
  107. }

[19] 半球形(Hemisphere)图形的生成算法的更多相关文章

  1. [20] 鼓状物(Drum)图形的生成算法

    顶点数据的生成 bool YfBuildDrumVertices ( Yreal radius, Yreal assistRadius, Yuint slices, Yuint stacks, YeO ...

  2. [17] 楼梯(Stairs)图形的生成算法

    感觉这图形怎么看怎么像搓衣板. 顶点数据的生成 bool YfBuildStairsVertices ( Yreal width, Yreal length, Yreal height, Yuint ...

  3. [18] 螺旋楼梯(Spiral Stairs)图形的生成算法

    顶点数据的生成 bool YfBuildSpiralStairsVertices ( Yreal radius, Yreal assistRadius, Yreal height, Yuint sli ...

  4. [16] 螺旋面(Spire)图形的生成算法

    顶点数据的生成 bool YfBuildSpireVertices ( Yreal radius, Yreal assistRadius, Yreal height, Yuint slices, Yu ...

  5. [15] 星星(Star)图形的生成算法

    顶点数据的生成 bool YfBuildStarVertices ( Yreal radius, Yreal assistRadius, Yreal height, Yuint slices, YeO ...

  6. [14] 齿轮(Gear Wheel)图形的生成算法

    顶点数据的生成 bool YfBuildGearwheelVertices ( Yreal radius, Yreal assistRadius, Yreal height, Yuint slices ...

  7. [13] 弧面(Arc)图形的生成算法

    顶点数据的生成 bool YfBuildArcVertices ( Yreal radius, Yreal degree, Yreal height, Yuint slices, Yuint stac ...

  8. [12] 扇形体(Fan)图形的生成算法

    顶点数据的生成 bool YfBuildFunVertices ( Yreal radius, Yreal degree, Yreal height, Yuint slices, YeOriginPo ...

  9. [11] 楔形体(Wedge)图形的生成算法

    顶点数据的生成 bool YfBuildWedgeVertices ( Yreal width, Yreal length, Yreal height, YeOriginPose originPose ...

随机推荐

  1. poj3268 Silver Cow Party(两次SPFA || 两次Dijkstra)

    题目链接 http://poj.org/problem?id=3268 题意 有向图中有n个结点,编号1~n,输入终点编号x,求其他结点到x结点来回最短路长度的最大值. 思路 最短路问题,有1000个 ...

  2. ubuntu 14.04 Bob 安装

    1. 附件依赖项安装$ sudo add-apt-repository ppa:biometrics/bob $ sudo apt-get update $ sudo apt-get install ...

  3. NPOI操作Excel文件

    首先,通过NuGet添加NPOI. NPOI依赖SharpZipLib,通过NuGet添加SharpZipLib. 然后添加NPOI. 添加后项目的引用列表如下: 把DataTable转换成Excel ...

  4. Oracle数据库多表查询,子查询,集合运算

    记得自己要敲o~~~ select * from bonus; select * from salgrade; from dual; --笛卡尔积:两张表的乘积 select * from emp,d ...

  5. [leetcode tree]95. Unique Binary Search Trees II

    Given an integer n, generate all structurally unique BST's (binary search trees) that store values 1 ...

  6. sklearn六大板块

    六大板块 分类 回归 聚类 数据降维 数据预处理 特征抽取 统一API estimator.fit(X_train,[y_train]) estimator.fit(X_train,[y_train] ...

  7. poj 3463 最短路+次短路

    独立写查错不能,就是维护一个次短路的dist 题意:给定一个有向图,问从起点到终点,最短路+比最短路距离长1的路的个数. Sample Input25 81 2 31 3 21 4 52 3 12 5 ...

  8. Codeforces Round #279 (Div. 2) B - Queue 水题

    #include<iostream> #include<mem.h> using namespace std; ],q[]; int main() { int n,x,y; m ...

  9. [分享]2013:Linux的黄金之年-十大杰出成就

    2013年已经过去.这一年见证了许多里程碑事件,使得2013年可以称得上是一个Linux的黄金之年.其中一些成果在FOSS和Linux世界更可以称得上是举世瞩目的成就. 1.Android的上升趋势 ...

  10. 通过 ssh 登录到手机 Termux

    通过ssh登录到手机 Termux 测试环境 电脑: macOS Mojave 手机: Huawei Mate10Pro Termux是Android上的一个非常强大的终端模拟器. 强大之处在于支持使 ...