顶点数据的生成

 bool                        YfBuildFunVertices
(
Yreal radius,
Yreal degree,
Yreal height,
Yuint slices,
YeOriginPose originPose,
Yuint vertexStriding,
Yuint vertexPos,
void* pVerticesBuffer
)
{
if (degree < || degree > || !pVerticesBuffer)
{
return false;
}
if (slices < || !pVerticesBuffer)
{
return false;
} Yuint numVertices = (slices + ) * ; char* vertexPtr = (char*)pVerticesBuffer + vertexPos;
YsVector3* curVertexPtr = NULL;
Yuint nOffset = ; Yreal originOffsetY = 0.0f;
if (originPose == YE_ORIGIN_POSE_TOP)
{
originOffsetY = -height;
}
else if (originPose == YE_ORIGIN_POSE_CENTER)
{
originOffsetY = -height * 0.5f;
} // 柱顶顶点赋值
{
nOffset = ;
curVertexPtr = (YsVector3*)(vertexPtr + nOffset);
curVertexPtr->x = 0.0f;
curVertexPtr->y = height + originOffsetY;
curVertexPtr->z = 0.0f;
} // 柱底顶点赋值
{
nOffset = (numVertices - ) * vertexStriding;
curVertexPtr = (YsVector3*)(vertexPtr + nOffset);
curVertexPtr->x = 0.0f;
curVertexPtr->y = originOffsetY;
curVertexPtr->z = 0.0f;
} Yreal radian = YD_DEGREE_TO_RADIAN(degree);
Yreal angleXZ;
Yreal posX, posZ;
for (Yuint i = ; i < slices; i++)
{
angleXZ = radian * i / (slices - );
posX = yf_sin(angleXZ);
posZ = yf_cos(angleXZ); // 上顶点
{
nOffset = ( + i) * vertexStriding;
curVertexPtr = (YsVector3*)(vertexPtr + nOffset);
curVertexPtr->x = radius * posX;
curVertexPtr->y = height + originOffsetY;
curVertexPtr->z = radius * posZ;
} // 下顶点
{
nOffset = ( + slices + i) * vertexStriding;
curVertexPtr = (YsVector3*)(vertexPtr + nOffset);
curVertexPtr->x = radius * posX;
curVertexPtr->y = originOffsetY;
curVertexPtr->z = radius * posZ;
}
} return true;
}

三角形索引数据的生成

 bool                        YfBuildFunTriIndices
(
Yuint slices,
YeIndexType indexType,
Yuint indexStriding,
Yuint indexPos,
void* pTriIndicesBuffer
)
{
if (slices < || !pTriIndicesBuffer)
{
return false;
} Yuint numVertices = (slices + ) * ;
Yuint numTriangles = slices * ;
if (indexType == YE_INDEX_16_BIT &&
numVertices > YD_MAX_UNSIGNED_INT16)
{
return false;
} // 索引赋值
char* indexPtr = (char*)pTriIndicesBuffer + indexPos;
Yuint nOffset = ;
if (indexType == YE_INDEX_16_BIT)
{
YsTriIndex16* triIndexPtr = NULL;
for (Yuint i = ; i < slices - ; i++)
{
nOffset = (i * ) * indexStriding;
triIndexPtr = (YsTriIndex16*)(indexPtr + nOffset);
triIndexPtr->index0 = ;
triIndexPtr->index1 = + i;
triIndexPtr->index2 = + i + ; nOffset += indexStriding;
triIndexPtr = (YsTriIndex16*)(indexPtr + nOffset);
triIndexPtr->index0 = numVertices - ;
triIndexPtr->index1 = + slices + i + ;
triIndexPtr->index2 = + slices + i; nOffset += indexStriding;
triIndexPtr = (YsTriIndex16*)(indexPtr + nOffset);
triIndexPtr->index0 = + i;
triIndexPtr->index1 = + slices + i;
triIndexPtr->index2 = + i + ; nOffset += indexStriding;
triIndexPtr = (YsTriIndex16*)(indexPtr + nOffset);
triIndexPtr->index0 = + i + ;
triIndexPtr->index1 = + slices + i;
triIndexPtr->index2 = + slices + i + ;
} nOffset = ((slices - ) * ) * indexStriding;
triIndexPtr = (YsTriIndex16*)(indexPtr + nOffset);
triIndexPtr->index0 = ;
triIndexPtr->index1 = numVertices - ;
triIndexPtr->index2 = ; nOffset += indexStriding;
triIndexPtr = (YsTriIndex16*)(indexPtr + nOffset);
triIndexPtr->index0 = ;
triIndexPtr->index1 = numVertices - ;
triIndexPtr->index2 = + slices; nOffset += indexStriding;
triIndexPtr = (YsTriIndex16*)(indexPtr + nOffset);
triIndexPtr->index0 = ;
triIndexPtr->index1 = slices;
triIndexPtr->index2 = numVertices - ; nOffset += indexStriding;
triIndexPtr = (YsTriIndex16*)(indexPtr + nOffset);
triIndexPtr->index0 = slices;
triIndexPtr->index1 = numVertices - ;
triIndexPtr->index2 = numVertices - ;
}
else
{
YsTriIndex32* triIndexPtr = NULL;
for (Yuint i = ; i < slices - ; i++)
{
nOffset = (i * ) * indexStriding;
triIndexPtr = (YsTriIndex32*)(indexPtr + nOffset);
triIndexPtr->index0 = ;
triIndexPtr->index1 = + i;
triIndexPtr->index2 = + i + ; nOffset += indexStriding;
triIndexPtr = (YsTriIndex32*)(indexPtr + nOffset);
triIndexPtr->index0 = numVertices - ;
triIndexPtr->index1 = + slices + i + ;
triIndexPtr->index2 = + slices + i; nOffset += indexStriding;
triIndexPtr = (YsTriIndex32*)(indexPtr + nOffset);
triIndexPtr->index0 = + i;
triIndexPtr->index1 = + slices + i;
triIndexPtr->index2 = + i + ; nOffset += indexStriding;
triIndexPtr = (YsTriIndex32*)(indexPtr + nOffset);
triIndexPtr->index0 = + i + ;
triIndexPtr->index1 = + slices + i;
triIndexPtr->index2 = + slices + i + ;
} nOffset = ((slices - ) * ) * indexStriding;
triIndexPtr = (YsTriIndex32*)(indexPtr + nOffset);
triIndexPtr->index0 = ;
triIndexPtr->index1 = numVertices - ;
triIndexPtr->index2 = ; nOffset += indexStriding;
triIndexPtr = (YsTriIndex32*)(indexPtr + nOffset);
triIndexPtr->index0 = ;
triIndexPtr->index1 = numVertices - ;
triIndexPtr->index2 = + slices; nOffset += indexStriding;
triIndexPtr = (YsTriIndex32*)(indexPtr + nOffset);
triIndexPtr->index0 = ;
triIndexPtr->index1 = slices;
triIndexPtr->index2 = numVertices - ; nOffset += indexStriding;
triIndexPtr = (YsTriIndex32*)(indexPtr + nOffset);
triIndexPtr->index0 = slices;
triIndexPtr->index1 = numVertices - ;
triIndexPtr->index2 = numVertices - ;
} return true;
}

线框索引数据的生成

 bool                        YfBuildFunWireIndices
(
Yuint slices,
YeIndexType indexType,
Yuint indexStriding,
Yuint indexPos,
void* pWireIndicesBuffer
)
{
if (slices < || !pWireIndicesBuffer)
{
return false;
} Yuint numVertices = (slices + ) * ;
Yuint numLines = slices + (slices-) * + ;
if (indexType == YE_INDEX_16_BIT &&
numVertices > YD_MAX_UNSIGNED_INT16)
{
return false;
} // 索引赋值
char* indexPtr = (char*)pWireIndicesBuffer + indexPos;
Yuint nOffset = ;
if (indexType == YE_INDEX_16_BIT)
{
YsLineIndex16* lineIndexPtr = NULL;
for (Yuint i = ; i < slices - ; i++)
{
nOffset = (i * ) * indexStriding;
lineIndexPtr = (YsLineIndex16*)(indexPtr + nOffset);
lineIndexPtr->index0 = + i;
lineIndexPtr->index1 = + slices + i; nOffset += indexStriding;
lineIndexPtr = (YsLineIndex16*)(indexPtr + nOffset);
lineIndexPtr->index0 = + i;
lineIndexPtr->index1 = + i + ; nOffset += indexStriding;
lineIndexPtr = (YsLineIndex16*)(indexPtr + nOffset);
lineIndexPtr->index0 = + slices + i;
lineIndexPtr->index1 = + slices + i + ;
} nOffset += indexStriding;
lineIndexPtr = (YsLineIndex16*)(indexPtr + nOffset);
lineIndexPtr->index0 = slices;
lineIndexPtr->index1 = *slices; nOffset += indexStriding;
lineIndexPtr = (YsLineIndex16*)(indexPtr + nOffset);
lineIndexPtr->index0 = ;
lineIndexPtr->index1 = *slices + ; nOffset += indexStriding;
lineIndexPtr = (YsLineIndex16*)(indexPtr + nOffset);
lineIndexPtr->index0 = ;
lineIndexPtr->index1 = ; nOffset += indexStriding;
lineIndexPtr = (YsLineIndex16*)(indexPtr + nOffset);
lineIndexPtr->index0 = ;
lineIndexPtr->index1 = slices; nOffset += indexStriding;
lineIndexPtr = (YsLineIndex16*)(indexPtr + nOffset);
lineIndexPtr->index0 = *slices + ;
lineIndexPtr->index1 = slices + ; nOffset += indexStriding;
lineIndexPtr = (YsLineIndex16*)(indexPtr + nOffset);
lineIndexPtr->index0 = *slices + ;
lineIndexPtr->index1 = *slices;
}
else
{
YsLineIndex32* lineIndexPtr = NULL;
for (Yuint i= ; i < slices; i++)
{
YsLineIndex32* lineIndexPtr = NULL;
for (Yuint i = ; i < slices - ; i++)
{
nOffset = (i * ) * indexStriding;
lineIndexPtr = (YsLineIndex32*)(indexPtr + nOffset);
lineIndexPtr->index0 = + i;
lineIndexPtr->index1 = + slices + i; nOffset += indexStriding;
lineIndexPtr = (YsLineIndex32*)(indexPtr + nOffset);
lineIndexPtr->index0 = + i;
lineIndexPtr->index1 = + i + ; nOffset += indexStriding;
lineIndexPtr = (YsLineIndex32*)(indexPtr + nOffset);
lineIndexPtr->index0 = + slices + i;
lineIndexPtr->index1 = + slices + i + ;
} nOffset += indexStriding;
lineIndexPtr = (YsLineIndex32*)(indexPtr + nOffset);
lineIndexPtr->index0 = slices;
lineIndexPtr->index1 = *slices; nOffset += indexStriding;
lineIndexPtr = (YsLineIndex32*)(indexPtr + nOffset);
lineIndexPtr->index0 = ;
lineIndexPtr->index1 = *slices + ; nOffset += indexStriding;
lineIndexPtr = (YsLineIndex32*)(indexPtr + nOffset);
lineIndexPtr->index0 = ;
lineIndexPtr->index1 = ; nOffset += indexStriding;
lineIndexPtr = (YsLineIndex32*)(indexPtr + nOffset);
lineIndexPtr->index0 = ;
lineIndexPtr->index1 = slices; nOffset += indexStriding;
lineIndexPtr = (YsLineIndex32*)(indexPtr + nOffset);
lineIndexPtr->index0 = *slices + ;
lineIndexPtr->index1 = slices + ; nOffset += indexStriding;
lineIndexPtr = (YsLineIndex32*)(indexPtr + nOffset);
lineIndexPtr->index0 = *slices + ;
lineIndexPtr->index1 = *slices;
}
} return true;
}

[12] 扇形体(Fan)图形的生成算法的更多相关文章

  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. [19] 半球形(Hemisphere)图形的生成算法

    顶点数据的生成 bool YfBuildHemisphereVertices ( Yreal radius, Yuint slices, Yuint stacks, YeOriginPose orig ...

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

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

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

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

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

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

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

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

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

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

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

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

随机推荐

  1. [js]正则篇

    一.正则基本概念 1.一种规则.模式.文本处理工具 2.强大的字符串匹配工具 3.在js中常与字符串函数配合使用 二.js正则写法 正则在js中以正则对象存在: (1)var re=new RegEx ...

  2. CSUOJ 1005 Binary Search Tree analog

    Description Binary Search Tree, abbreviated as BST, is a kind of binary tree maintains the following ...

  3. eclipse文本编码格式修改为UTF-8

    1.windows->Preferences...打开"首选项"对话框,左侧导航树,导航到general->Workspace,右 侧Text file encodin ...

  4. shell 变量中间有空格 如何传入整个变量

    parmfile='abc  123' RunProgram programname "${parmfile}"  -->传入abc 123 RunProgram progr ...

  5. Alpha 冲刺报告6

    重感冒,重启中,停工一天

  6. bzoj 4627: [BeiJing2016]回转寿司 -- 权值线段树

    4627: [BeiJing2016]回转寿司 Time Limit: 10 Sec  Memory Limit: 256 MB Description 酷爱日料的小Z经常光顾学校东门外的回转寿司店. ...

  7. hrbust 2176 Mac的投票 二分/水题

    Mac的投票 Time Limit: 1000 MS Memory Limit: 32768 K Total Submit: 52(12 users) Total Accepted: 12(10 us ...

  8. IOS webView学习

    本文简单介绍下在IOS中,webView的基本用法,也顺便强化下自己的基础知识----天明少羽爬楼梯 一.加载外部HTML 显示webView 报错:NSURLSession/NSURLConnect ...

  9. UEFI引导模式

    Author: JinDate: 20140827System: windows 刚帮楼下的公司解决了个问题. 原来的办公电脑,预装linux,他们重装成win7.新买的电脑预装成win8,安装出问题 ...

  10. 重温PHP之冒泡排序

    冒泡排序(Bubble Sort),是一种计算机科学领域的较简单的排序算法. 它重复地走访过要排序的元素列,依次比较两个相邻的元素,如果他们的顺序(如从大到小.首字母从A到Z)错误就把他们交换过来.走 ...