顶点数据的生成

 bool                        YfBuildPlaneVertices
(
Yreal width,
Yreal length,
Yreal height,
Yuint slices,
Yuint stacks,
YeOriginPose originPose,
Yuint vertexStriding,
Yuint vertexPos,
void* pVerticesBuffer
)
{
if (slices < || stacks < || !pVerticesBuffer)
{
return false;
} // 顶点赋值
char* vertexPtr = (char*)pVerticesBuffer + vertexPos;
YsVector3* curVertexPtr = NULL;
Yuint nOffset = ; Yreal xStep = width / slices;
Yreal zStep = length / stacks;
YsVector3 vOrigin;
if (originPose == YE_ORIGIN_POSE_CENTER)
{
vOrigin.x = -width * 0.5f;
vOrigin.z = -length * 0.5f;
} for (Yuint j = ; j < stacks; j++) // Z方向
{
for (Yuint i = ; i < slices; i++) // X方向
{
nOffset = (j*slices + i) * vertexStriding;
curVertexPtr = (YsVector3*)(vertexPtr + nOffset);
curVertexPtr->x = vOrigin.x + i*xStep;
curVertexPtr->y = height;
curVertexPtr->z = vOrigin.z + j*zStep;
}
} return true;
}

三角形索引数据的生成

 bool                        YfBuildPlaneTriIndices
(
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 - ) * ; char* indexPtr = (char*)pTriIndicesBuffer + indexPos;
Yuint nOffset = ; if (indexType == YE_INDEX_16_BIT)
{
YsTriIndex16* triIndexPtr = NULL; for (Yuint j = ; j < stacks - ; j++) // Z方向
{
for (Yuint i = ; i < slices - ; i++) // X方向
{
nOffset = ( * (j*(slices - ) + i)) * indexStriding;
triIndexPtr = (YsTriIndex16*)(indexPtr + nOffset);
triIndexPtr->index0 = j*slices + i;
triIndexPtr->index1 = (j + )*slices + i + ;
triIndexPtr->index2 = j*slices + i + ; nOffset += indexStriding;
triIndexPtr = (YsTriIndex16*)(indexPtr + nOffset);
triIndexPtr->index0 = j*slices + i;
triIndexPtr->index1 = (j + )*slices + i;
triIndexPtr->index2 = (j + )*slices + i + ;
}
}
}
else
{
YsTriIndex32* triIndexPtr = NULL; for (Yuint j = ; j < stacks - ; j++) // Z方向
{
for (Yuint i = ; i < slices - ; i++) // X方向
{
nOffset = ( * (j*(slices - ) + i)) * indexStriding;
triIndexPtr = (YsTriIndex32*)(indexPtr + nOffset);
triIndexPtr->index0 = j*slices + i;
triIndexPtr->index1 = (j + )*slices + i + ;
triIndexPtr->index2 = j*slices + i + ; nOffset += indexStriding;
triIndexPtr = (YsTriIndex32*)(indexPtr + nOffset);
triIndexPtr->index0 = j*slices + i;
triIndexPtr->index1 = (j + )*slices + i;
triIndexPtr->index2 = (j + )*slices + i + ;
}
}
} return true;
}

线框索引数据的生成

 bool                        YfBuildPlaneWireIndices
(
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 - ) +(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 + ;
}
} // 列
Yuint half = (slices - ) * stacks;
for (Yuint i = ; i < slices; i++)
{
for (Yuint j = ; j < stacks - ; j++)
{
nOffset = (half + (i*(stacks - ) + j)) * 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 + ;
}
} // 列
Yuint half = (slices - ) * stacks;
for (Yuint i = ; i < slices; i++)
{
for (Yuint j = ; j < stacks - ; j++)
{
nOffset = (half + (i*(stacks - ) + j)) * indexStriding;
lineIndexPtr = (YsLineIndex32*)(indexPtr + nOffset);
lineIndexPtr->index0 = j*slices + i;
lineIndexPtr->index1 = (j + )*slices + i;
}
}
} return true;
}

[1] 平面(Plane)图形的生成算法的更多相关文章

  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. [12] 扇形体(Fan)图形的生成算法

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

随机推荐

  1. thinkphp中导入和使用阿里云OSSsdk

    照做绝对行,在ThinkPHP中,第三方库都放在ThinkPHP/Library/Vendor/路径下. 1.下载OSS PHP SDK:https://help.aliyun.com/documen ...

  2. react篇章-React State(状态)

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <title&g ...

  3. CSUOJ 1979 古怪的行列式

    Description 这几天,子浩君潜心研究线性代数. 行列式的值定义如下: 其中,τ(j1j2...jn)为排列j1j2...jn的逆序数. 子浩君很厉害的,但是头脑经常短路,所以他会按照行列式值 ...

  4. Highmaps网页图表教程之图表配置项结构与商业授权

    Highmaps网页图表教程之图表配置项结构与商业授权 Highmaps图表配置项结构 Highmaps最核心的部分就是图表配置项.用户通过图表配置项来对标题进行定制,从而实现自己所要的效果.所以,掌 ...

  5. django创建model

    1.model实例 #!/usr/bin/python # coding:utf-8 from __future__ import unicode_literals from django.db im ...

  6. sql分组排序取top

    写法1: use anypay; select tr.* from (select task_code, max(created_at) as cal from task_log group by t ...

  7. 【洛谷】2144:[FJOI2007]轮状病毒【高精度】【数学推导??(找规律)】

    P2144 [FJOI2007]轮状病毒 题目描述 轮状病毒有很多变种.许多轮状病毒都是由一个轮状基产生.一个n轮状基由圆环上n个不同的基原子和圆心的一个核原子构成.2个原子之间的边表示这2个原子之间 ...

  8. 【转载】HTTP/FTP客户端开发库:libwww、libcurl、libfetch

    网页抓取和ftp访问是目前很常见的一个应用需要,无论是搜索引擎的爬虫,分析程序,资源获取程序,WebService等等都是需 要的,自己开发抓取库当然是最好了,不过开发需要时间和周期,使用现有的Ope ...

  9. Educational Codeforces Round 13 A. Johny Likes Numbers 水题

    A. Johny Likes Numbers 题目连接: http://www.codeforces.com/contest/678/problem/A Description Johny likes ...

  10. Codeforces Round #356 (Div. 2) B. Bear and Finding Criminal 水题

    B. Bear and Finding Criminals 题目连接: http://www.codeforces.com/contest/680/problem/B Description Ther ...