[19] 半球形(Hemisphere)图形的生成算法
顶点数据的生成
- bool YfBuildHemisphereVertices
- (
- Yreal radius,
- Yuint slices,
- Yuint stacks,
- YeOriginPose originPose,
- Yuint vertexStriding,
- Yuint vertexPos,
- void* pVerticesBuffer
- )
- {
- if (slices < || stacks < || !pVerticesBuffer)
- {
- return false;
- }
- Yuint numVertices = slices * (stacks - ) + ;
- // 顶点赋值
- char* vertexPtr = (char*)pVerticesBuffer + vertexPos;
- YsVector3* curVertexPtr = NULL;
- Yuint nOffset = ;
- Yreal originOffsetY = 0.0f;
- if (originPose == YE_ORIGIN_POSE_TOP)
- {
- originOffsetY = -radius;
- }
- else if (originPose == YE_ORIGIN_POSE_BOTTOM)
- {
- originOffsetY = radius;
- }
- Yreal* pSinList = YD_NEW_ARRAY(Yreal, slices);
- Yreal* pCosList = YD_NEW_ARRAY(Yreal, slices);
- Yreal angleXZ;
- for (Yuint j = ; j < slices; j++)
- {
- angleXZ = YD_REAL_TWAIN_PI * j / slices;
- pSinList[j] = yf_sin(angleXZ);
- pCosList[j] = yf_cos(angleXZ);
- }
- // 赋值
- {
- for (Yuint i = ; i < stacks; i++)
- {
- if (i == ) // 第一个顶点
- {
- nOffset = ;
- curVertexPtr = (YsVector3*)(vertexPtr + nOffset);
- curVertexPtr->x = 0.0f;
- curVertexPtr->y = radius + originOffsetY;
- curVertexPtr->z = 0.0f;
- continue;
- }
- Yreal angleY = YD_REAL_HALF_PI * i / (stacks - );
- Yreal posY = radius * yf_cos(angleY);
- Yreal radiusXZ = radius * yf_sin(angleY);
- Yreal posX, posZ;
- for (Yuint j = ; j < slices; j++)
- {
- posX = radiusXZ * pSinList[j];
- posZ = radiusXZ * pCosList[j];
- nOffset = ((i - ) * slices + j + ) * vertexStriding;
- curVertexPtr = (YsVector3*)(vertexPtr + nOffset);
- curVertexPtr->x = posX;
- curVertexPtr->y = posY + originOffsetY;
- curVertexPtr->z = posZ;
- }
- }
- }
- YD_SAFE_DELETE_ARRAY(pSinList);
- YD_SAFE_DELETE_ARRAY(pCosList);
- return true;
- }
三角形索引数据的生成
- bool YfBuildHemisphereTriIndices
- (
- Yuint slices,
- Yuint stacks,
- YeIndexType indexType,
- Yuint indexStriding,
- Yuint indexPos,
- void* pTriIndicesBuffer
- )
- {
- if (slices < || stacks < || !pTriIndicesBuffer)
- {
- return false;
- }
- Yuint numVertices = slices * (stacks - ) + ;
- if (indexType == YE_INDEX_16_BIT &&
- numVertices > YD_MAX_UNSIGNED_INT16)
- {
- return false;
- }
- Yuint numTriangles = slices * (stacks - ) * + slices;
- // 索引赋值
- char* indexPtr = (char*)pTriIndicesBuffer + indexPos;
- Yuint nOffset = ;
- if (indexType == YE_INDEX_16_BIT)
- {
- YsTriIndex16* triIndexPtr = NULL;
- for (Yuint i = ; i < stacks - ; i++)
- {
- if (i == ) // 第一层
- {
- for (Yuint j = ; j < slices; j++)
- {
- nOffset = j * indexStriding;
- triIndexPtr = (YsTriIndex16*)(indexPtr + nOffset);
- triIndexPtr->index0 = ;
- triIndexPtr->index1 = + j;
- triIndexPtr->index2 = + (j + )%slices;
- }
- }
- else
- {
- for (Yuint j = ; j < slices; j++)
- {
- nOffset = (slices + (i - )*slices * + j * ) * indexStriding;
- triIndexPtr = (YsTriIndex16*)(indexPtr + nOffset);
- triIndexPtr->index0 = + slices * (i - ) + j;
- triIndexPtr->index1 = + slices * i + j;
- triIndexPtr->index2 = + slices * (i - ) + (j + )%slices;
- nOffset += indexStriding;
- triIndexPtr = (YsTriIndex16*)(indexPtr + nOffset);
- triIndexPtr->index0 = + slices * (i - ) + (j + )%slices;
- triIndexPtr->index1 = + slices * i + j;
- triIndexPtr->index2 = + slices * i + (j + )%slices;
- }
- }
- }
- }
- else
- {
- YsTriIndex32* triIndexPtr = NULL;
- // 赋值
- for (Yuint i = ; i < stacks - ; i++)
- {
- if (i == ) // 第一层
- {
- for (Yuint j = ; j < slices; j++)
- {
- nOffset = j * indexStriding;
- triIndexPtr = (YsTriIndex32*)(indexPtr + nOffset);
- triIndexPtr->index0 = ;
- triIndexPtr->index1 = + j;
- triIndexPtr->index2 = + (j + )%slices;
- }
- }
- else
- {
- for (Yuint j = ; j < slices; j++)
- {
- nOffset = (slices + (i - )*slices * + j * ) * indexStriding;
- triIndexPtr = (YsTriIndex32*)(indexPtr + nOffset);
- triIndexPtr->index0 = + slices * (i - ) + j;
- triIndexPtr->index1 = + slices * i + j;
- triIndexPtr->index2 = + slices * (i - ) + (j + )%slices;
- nOffset += indexStriding;
- triIndexPtr = (YsTriIndex32*)(indexPtr + nOffset);
- triIndexPtr->index0 = + slices * (i - ) + (j + )%slices;
- triIndexPtr->index1 = + slices * i + j;
- triIndexPtr->index2 = + slices * i + (j + )%slices;
- }
- }
- }
- }
- return true;
- }
线框索引数据的生成
- bool YfBuildHemisphereWireIndices
- (
- Yuint slices,
- Yuint stacks,
- YeIndexType indexType,
- Yuint indexStriding,
- Yuint indexPos,
- void* pWireIndicesBuffer
- )
- {
- if (slices < || stacks < || !pWireIndicesBuffer)
- {
- return false;
- }
- Yuint numVertices = slices * (stacks - ) + ;
- if (indexType == YE_INDEX_16_BIT &&
- numVertices > YD_MAX_UNSIGNED_INT16)
- {
- return false;
- }
- Yuint numLines = slices * (stacks - ) * ;
- char* indexPtr = (char*)pWireIndicesBuffer + indexPos;
- Yuint nOffset = ;
- if (indexType == YE_INDEX_16_BIT)
- {
- YsLineIndex16* lineIndexPtr = NULL;
- // 行
- for (Yuint j = ; j < stacks; j++)
- {
- for (Yuint i = ; i < slices; i++)
- {
- nOffset = ((j - )*slices + i) * indexStriding;
- lineIndexPtr = (YsLineIndex16*)(indexPtr + nOffset);
- lineIndexPtr->index0 = + (j - )*slices + i;
- lineIndexPtr->index1 = + (j - )*slices + (i + )%slices;
- }
- }
- Yuint count = slices * (stacks - );
- // 列
- for (Yuint i = ; i < slices; i++)
- {
- nOffset = (count + i) * indexStriding;
- lineIndexPtr = (YsLineIndex16*)(indexPtr + nOffset);
- lineIndexPtr->index0 = ;
- lineIndexPtr->index1 = + i;
- }
- count += slices;
- for (Yuint j = ; j < stacks - ; j++)
- {
- for (Yuint i = ; i < slices; i++)
- {
- nOffset = (count + (j - )*slices + i) * indexStriding;
- lineIndexPtr = (YsLineIndex16*)(indexPtr + nOffset);
- lineIndexPtr->index0 = + (j - )*slices + i;
- lineIndexPtr->index1 = + j*slices + i;
- }
- }
- }
- else
- {
- YsLineIndex32* lineIndexPtr = NULL;
- // 行
- for (Yuint j = ; j < stacks; j++)
- {
- for (Yuint i = ; i < slices; i++)
- {
- nOffset = ((j - )*slices + i) * indexStriding;
- lineIndexPtr = (YsLineIndex32*)(indexPtr + nOffset);
- lineIndexPtr->index0 = + (j - )*slices + i;
- lineIndexPtr->index1 = + (j - )*slices + (i + )%slices;
- }
- }
- Yuint count = slices * (stacks - );
- // 列
- for (Yuint i = ; i < slices; i++)
- {
- nOffset = (count + i) * indexStriding;
- lineIndexPtr = (YsLineIndex32*)(indexPtr + nOffset);
- lineIndexPtr->index0 = ;
- lineIndexPtr->index1 = + i;
- }
- count += slices;
- for (Yuint j = ; j < stacks - ; j++)
- {
- for (Yuint i = ; i < slices; i++)
- {
- nOffset = (count + (j - )*slices + i) * indexStriding;
- lineIndexPtr = (YsLineIndex32*)(indexPtr + nOffset);
- lineIndexPtr->index0 = + (j - )*slices + i;
- lineIndexPtr->index1 = + j*slices + i;
- }
- }
- }
- return true;
- }
[19] 半球形(Hemisphere)图形的生成算法的更多相关文章
- [20] 鼓状物(Drum)图形的生成算法
顶点数据的生成 bool YfBuildDrumVertices ( Yreal radius, Yreal assistRadius, Yuint slices, Yuint stacks, YeO ...
- [17] 楼梯(Stairs)图形的生成算法
感觉这图形怎么看怎么像搓衣板. 顶点数据的生成 bool YfBuildStairsVertices ( Yreal width, Yreal length, Yreal height, Yuint ...
- [18] 螺旋楼梯(Spiral Stairs)图形的生成算法
顶点数据的生成 bool YfBuildSpiralStairsVertices ( Yreal radius, Yreal assistRadius, Yreal height, Yuint sli ...
- [16] 螺旋面(Spire)图形的生成算法
顶点数据的生成 bool YfBuildSpireVertices ( Yreal radius, Yreal assistRadius, Yreal height, Yuint slices, Yu ...
- [15] 星星(Star)图形的生成算法
顶点数据的生成 bool YfBuildStarVertices ( Yreal radius, Yreal assistRadius, Yreal height, Yuint slices, YeO ...
- [14] 齿轮(Gear Wheel)图形的生成算法
顶点数据的生成 bool YfBuildGearwheelVertices ( Yreal radius, Yreal assistRadius, Yreal height, Yuint slices ...
- [13] 弧面(Arc)图形的生成算法
顶点数据的生成 bool YfBuildArcVertices ( Yreal radius, Yreal degree, Yreal height, Yuint slices, Yuint stac ...
- [12] 扇形体(Fan)图形的生成算法
顶点数据的生成 bool YfBuildFunVertices ( Yreal radius, Yreal degree, Yreal height, Yuint slices, YeOriginPo ...
- [11] 楔形体(Wedge)图形的生成算法
顶点数据的生成 bool YfBuildWedgeVertices ( Yreal width, Yreal length, Yreal height, YeOriginPose originPose ...
随机推荐
- poj3268 Silver Cow Party(两次SPFA || 两次Dijkstra)
题目链接 http://poj.org/problem?id=3268 题意 有向图中有n个结点,编号1~n,输入终点编号x,求其他结点到x结点来回最短路长度的最大值. 思路 最短路问题,有1000个 ...
- ubuntu 14.04 Bob 安装
1. 附件依赖项安装$ sudo add-apt-repository ppa:biometrics/bob $ sudo apt-get update $ sudo apt-get install ...
- NPOI操作Excel文件
首先,通过NuGet添加NPOI. NPOI依赖SharpZipLib,通过NuGet添加SharpZipLib. 然后添加NPOI. 添加后项目的引用列表如下: 把DataTable转换成Excel ...
- Oracle数据库多表查询,子查询,集合运算
记得自己要敲o~~~ select * from bonus; select * from salgrade; from dual; --笛卡尔积:两张表的乘积 select * from emp,d ...
- [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 ...
- sklearn六大板块
六大板块 分类 回归 聚类 数据降维 数据预处理 特征抽取 统一API estimator.fit(X_train,[y_train]) estimator.fit(X_train,[y_train] ...
- poj 3463 最短路+次短路
独立写查错不能,就是维护一个次短路的dist 题意:给定一个有向图,问从起点到终点,最短路+比最短路距离长1的路的个数. Sample Input25 81 2 31 3 21 4 52 3 12 5 ...
- Codeforces Round #279 (Div. 2) B - Queue 水题
#include<iostream> #include<mem.h> using namespace std; ],q[]; int main() { int n,x,y; m ...
- [分享]2013:Linux的黄金之年-十大杰出成就
2013年已经过去.这一年见证了许多里程碑事件,使得2013年可以称得上是一个Linux的黄金之年.其中一些成果在FOSS和Linux世界更可以称得上是举世瞩目的成就. 1.Android的上升趋势 ...
- 通过 ssh 登录到手机 Termux
通过ssh登录到手机 Termux 测试环境 电脑: macOS Mojave 手机: Huawei Mate10Pro Termux是Android上的一个非常强大的终端模拟器. 强大之处在于支持使 ...