博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[7] 金字塔(Pyramid)图形的生成算法
阅读量:5757 次
发布时间:2019-06-18

本文共 7217 字,大约阅读时间需要 24 分钟。

顶点数据的生成

1 bool                        YfBuildPyramidVertices 2 ( 3     Yreal                   width,  4     Yreal                   length,  5     Yreal                   height,  6     YeOriginPose            originPose,  7     Yuint                   vertexStriding,  8     Yuint                   vertexPos, 9     void*                   pVerticesBuffer10 )11 {12     if (!pVerticesBuffer)13     {14         return false;15     }16 17     Yuint numVertices  = 5;18 19     char* vertexPtr   = (char*)pVerticesBuffer + vertexPos;20     YsVector3* curVertexPtr   = NULL;21     Yuint nOffset = 0;22 23     YsVector3 vOriginOffset(-width / 2, -height / 2, -length / 2);24     if (originPose == YE_ORIGIN_POSE_TOP)25     {26         vOriginOffset.y = -height;27     }28     else if (originPose == YE_ORIGIN_POSE_BOTTOM)29     {30         vOriginOffset.y = 0.0f;31     }32 33     // 底四个顶点34     for (Yuint j = 0; j < 2; j++)35     {36         for (Yuint i = 0; i < 2; i++)37         {38             nOffset = (j*2 + i) * vertexStriding;39             curVertexPtr = (YsVector3*)(vertexPtr + nOffset);40             curVertexPtr->x = width*i + vOriginOffset.x;41             curVertexPtr->y = vOriginOffset.y;42             curVertexPtr->z = length*j + vOriginOffset.z;43         }44     }45 46     // 顶尖顶点47     nOffset = 4 * vertexStriding;48     curVertexPtr = (YsVector3*)(vertexPtr + nOffset);49     curVertexPtr->x = 0.0f;50     curVertexPtr->y = height + vOriginOffset.y;51     curVertexPtr->z = 0.0f;52  53     return true;54 }

 

三角形索引数据的生成

 

1 bool                        YfBuildPyramidTriIndices 2 ( 3     YeIndexType             indexType, 4     Yuint                   indexStriding,   5     Yuint                   indexPos, 6     void*                   pTriIndicesBuffer 7 ) 8 { 9     if (!pTriIndicesBuffer)10     {11         return false;12     }13 14     char* indexPtr = (char*)pTriIndicesBuffer + indexPos;15     if (indexType == YE_INDEX_16_BIT)16     {17         YsTriIndex16* triIndexPtr = NULL;18 19         // bottom20         triIndexPtr = (YsTriIndex16*)(indexPtr + 0*indexStriding);21         triIndexPtr->index0 = 0; triIndexPtr->index1 = 1; triIndexPtr->index2 = 3;22         triIndexPtr = (YsTriIndex16*)(indexPtr + 1*indexStriding);23         triIndexPtr->index0 = 0; triIndexPtr->index1 = 3; triIndexPtr->index2 = 2;24 25         // 4 face26         triIndexPtr = (YsTriIndex16*)(indexPtr + 2*indexStriding);27         triIndexPtr->index0 = 4; triIndexPtr->index1 = 1; triIndexPtr->index2 = 0;28         triIndexPtr = (YsTriIndex16*)(indexPtr + 3*indexStriding);29         triIndexPtr->index0 = 4; triIndexPtr->index1 = 3; triIndexPtr->index2 = 1;30         triIndexPtr = (YsTriIndex16*)(indexPtr + 4*indexStriding);31         triIndexPtr->index0 = 4; triIndexPtr->index1 = 2; triIndexPtr->index2 = 3;32         triIndexPtr = (YsTriIndex16*)(indexPtr + 5*indexStriding);                                                33         triIndexPtr->index0 = 4; triIndexPtr->index1 = 0; triIndexPtr->index2 = 2;34     }35     else36     {37         YsTriIndex32* triIndexPtr = NULL;38 39         // bottom40         triIndexPtr = (YsTriIndex32*)(indexPtr + 0*indexStriding);41         triIndexPtr->index0 = 0; triIndexPtr->index1 = 1; triIndexPtr->index2 = 3;42         triIndexPtr = (YsTriIndex32*)(indexPtr + 1*indexStriding);43         triIndexPtr->index0 = 0; triIndexPtr->index1 = 3; triIndexPtr->index2 = 2;44 45         // 4 face46         triIndexPtr = (YsTriIndex32*)(indexPtr + 2*indexStriding);47         triIndexPtr->index0 = 4; triIndexPtr->index1 = 1; triIndexPtr->index2 = 0;48         triIndexPtr = (YsTriIndex32*)(indexPtr + 3*indexStriding);49         triIndexPtr->index0 = 4; triIndexPtr->index1 = 3; triIndexPtr->index2 = 1;50         triIndexPtr = (YsTriIndex32*)(indexPtr + 4*indexStriding);51         triIndexPtr->index0 = 4; triIndexPtr->index1 = 2; triIndexPtr->index2 = 3;52         triIndexPtr = (YsTriIndex32*)(indexPtr + 5*indexStriding);                                                53         triIndexPtr->index0 = 4; triIndexPtr->index1 = 0; triIndexPtr->index2 = 2;54     }55 56     return true;57 }

 

线框索引数据的生成

1 bool                        YfBuildPyramidWireIndices 2 ( 3     YeIndexType             indexType, 4     Yuint                   indexStriding,  5     Yuint                   indexPos, 6     void*                   pWireIndicesBuffer 7 ) 8 { 9     if (!pWireIndicesBuffer)10     {11         return false;12     }13 14     Yuint numVertices = 5;15     Yuint numLines    = 8;16     if (indexType == YE_INDEX_16_BIT && 17         numVertices > YD_MAX_UNSIGNED_INT16)18     {19         return false;20     }21 22     // 索引赋值23     char* indexPtr = (char*)pWireIndicesBuffer + indexPos;24     Yuint nOffset = 0;25     if (indexType == YE_INDEX_16_BIT)26     {27         YsLineIndex16* lineIndexPtr = NULL;28         29         // bottom30         lineIndexPtr = (YsLineIndex16*)(indexPtr + 0*indexStriding);31         lineIndexPtr->index0 = 0; lineIndexPtr->index1 = 1; 32         lineIndexPtr = (YsLineIndex16*)(indexPtr + 1*indexStriding);33         lineIndexPtr->index0 = 1; lineIndexPtr->index1 = 3; 34         lineIndexPtr = (YsLineIndex16*)(indexPtr + 2*indexStriding);35         lineIndexPtr->index0 = 3; lineIndexPtr->index1 = 2; 36         lineIndexPtr = (YsLineIndex16*)(indexPtr + 3*indexStriding);37         lineIndexPtr->index0 = 2; lineIndexPtr->index1 = 0; 38 39         // 4 lines40         lineIndexPtr = (YsLineIndex16*)(indexPtr + 4*indexStriding);41         lineIndexPtr->index0 = 4; lineIndexPtr->index1 = 0; 42         lineIndexPtr = (YsLineIndex16*)(indexPtr + 5*indexStriding);43         lineIndexPtr->index0 = 4; lineIndexPtr->index1 = 1; 44         lineIndexPtr = (YsLineIndex16*)(indexPtr + 6*indexStriding);45         lineIndexPtr->index0 = 4; lineIndexPtr->index1 = 2; 46         lineIndexPtr = (YsLineIndex16*)(indexPtr + 7*indexStriding);47         lineIndexPtr->index0 = 4; lineIndexPtr->index1 = 3; 48     }49     else50     {51         YsLineIndex32* lineIndexPtr = NULL;52 53         // bottom54         lineIndexPtr = (YsLineIndex32*)(indexPtr + 0*indexStriding);55         lineIndexPtr->index0 = 0; lineIndexPtr->index1 = 1; 56         lineIndexPtr = (YsLineIndex32*)(indexPtr + 1*indexStriding);57         lineIndexPtr->index0 = 1; lineIndexPtr->index1 = 3; 58         lineIndexPtr = (YsLineIndex32*)(indexPtr + 2*indexStriding);59         lineIndexPtr->index0 = 3; lineIndexPtr->index1 = 2; 60         lineIndexPtr = (YsLineIndex32*)(indexPtr + 3*indexStriding);61         lineIndexPtr->index0 = 2; lineIndexPtr->index1 = 0; 62 63         // 4 lines64         lineIndexPtr = (YsLineIndex32*)(indexPtr + 4*indexStriding);65         lineIndexPtr->index0 = 4; lineIndexPtr->index1 = 0; 66         lineIndexPtr = (YsLineIndex32*)(indexPtr + 5*indexStriding);67         lineIndexPtr->index0 = 4; lineIndexPtr->index1 = 1; 68         lineIndexPtr = (YsLineIndex32*)(indexPtr + 6*indexStriding);69         lineIndexPtr->index0 = 4; lineIndexPtr->index1 = 2; 70         lineIndexPtr = (YsLineIndex32*)(indexPtr + 7*indexStriding);71         lineIndexPtr->index0 = 4; lineIndexPtr->index1 = 3; 72     }73 74     return true;75 }

 

 

转载地址:http://kmpkx.baihongyu.com/

你可能感兴趣的文章
React:JSX
查看>>
python全栈开发笔记---------数据类型-----集合set
查看>>
uva-565-枚举
查看>>
自动文档摘要评价方法:Edmundson,ROUGE
查看>>
题解[ZJOI2007]矩阵游戏
查看>>
10个顶级Web移动开发JavaScript框架推荐
查看>>
<br/>属性
查看>>
Python中__get__ ,__getattr__ ,__getattribute__用法与区别?
查看>>
树的前、中、后序遍历
查看>>
org.apache.hadoop.hdfs.server.datanode.DataNode: Exception in receiveBlock for block
查看>>
平行宇宙和確定世界——讀阿諾爾德「常微分方程」前幾頁的感悟
查看>>
在Ubuntu上设置gmail邮件通知
查看>>
陶哲轩实分析 定义 7.2.1(形式无限级数) 的一点注记
查看>>
js原生API----查找dom
查看>>
css3各种loading写法
查看>>
elixir 入门笔记
查看>>
Linux 小知识翻译 - 「LDAP」
查看>>
react-native 简介及环境
查看>>
html
查看>>
asp.net core 系列 6 MVC框架路由(下)
查看>>