顶点数据的生成

 bool                        YfBuildGearwheelVertices
(
Yreal radius,
Yreal assistRadius,
Yreal height,
Yuint slices,
YeOriginPose originPose,
Yuint vertexStriding,
Yuint vertexPos,
void* pVerticesBuffer
)
{
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 angleXZ;
Yreal posX, posZ;
Yreal fRadius;
for (Yuint i = ; i < *slices; i++)
{
angleXZ = YD_REAL_TWAIN_PI * i / (slices*);
posX = yf_sin(angleXZ);
posZ = yf_cos(angleXZ);
fRadius = (i% == ) ? radius : assistRadius; // 上顶点
{
nOffset = ( + i) * vertexStriding;
curVertexPtr = (YsVector3*)(vertexPtr + nOffset);
curVertexPtr->x = fRadius * posX;
curVertexPtr->y = height + originOffsetY;
curVertexPtr->z = fRadius * posZ;
} // 下顶点
{
nOffset = ( + *slices + i) * vertexStriding;
curVertexPtr = (YsVector3*)(vertexPtr + nOffset);
curVertexPtr->x = fRadius * posX;
curVertexPtr->y = originOffsetY;
curVertexPtr->z = fRadius * posZ;
}
} return true;
}

三角形索引数据的生成

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

线框索引数据的生成

 bool                        YfBuildGearwheelWireIndices
(
Yuint slices,
YeIndexType indexType,
Yuint indexStriding,
Yuint indexPos,
void* pWireIndicesBuffer
)
{
if (slices < || !pWireIndicesBuffer)
{
return false;
} Yuint numVertices = (slices*) * + ;
Yuint numLines = (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 = + (i + )%(slices*); nOffset += indexStriding;
lineIndexPtr = (YsLineIndex16*)(indexPtr + nOffset);
lineIndexPtr->index0 = + slices* + i;
lineIndexPtr->index1 = + slices* + (i + )%(slices*); nOffset += indexStriding;
lineIndexPtr = (YsLineIndex16*)(indexPtr + nOffset);
lineIndexPtr->index0 = + i;
lineIndexPtr->index1 = + slices* + i;
} Yuint half = * slices * indexStriding;
for (Yuint i = ; i < slices; i++)
{
nOffset = half + (i * ) * indexStriding;
lineIndexPtr = (YsLineIndex16*)(indexPtr + nOffset);
lineIndexPtr->index0 = ;
lineIndexPtr->index1 = + i* + ; nOffset += indexStriding;
lineIndexPtr = (YsLineIndex16*)(indexPtr + nOffset);
lineIndexPtr->index0 = numVertices - ;
lineIndexPtr->index1 = + slices* + i* + ;
}
}
else
{
YsLineIndex32* lineIndexPtr = NULL;
for (Yuint i = ; i < * slices; i++)
{
nOffset = (i * ) * indexStriding;
lineIndexPtr = (YsLineIndex32*)(indexPtr + nOffset);
lineIndexPtr->index0 = + i;
lineIndexPtr->index1 = + (i + )%(slices*); nOffset += indexStriding;
lineIndexPtr = (YsLineIndex32*)(indexPtr + nOffset);
lineIndexPtr->index0 = + slices* + i;
lineIndexPtr->index1 = + slices* + (i + )%(slices*); nOffset += indexStriding;
lineIndexPtr = (YsLineIndex32*)(indexPtr + nOffset);
lineIndexPtr->index0 = + i;
lineIndexPtr->index1 = + slices* + i;
} Yuint half = * slices * indexStriding;
for (Yuint i = ; i < slices; i++)
{
nOffset = half + (i * ) * indexStriding;
lineIndexPtr = (YsLineIndex32*)(indexPtr + nOffset);
lineIndexPtr->index0 = ;
lineIndexPtr->index1 = + i* + ; nOffset += indexStriding;
lineIndexPtr = (YsLineIndex32*)(indexPtr + nOffset);
lineIndexPtr->index0 = numVertices - ;
lineIndexPtr->index1 = + slices* + i* + ;
}
} return true;
}

[14] 齿轮(Gear Wheel)图形的生成算法的更多相关文章

  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. [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. 手动制作用于启动BeagleBoneBlack(am335x)的SD

    1.需求MLO.u-boot.img.uImage.Systemfile 获取MLO.u-boot.img下载U-boot源码,解压获得源码,进入源码目录 cd /home/zyr/Source_co ...

  2. mmcrfs

    mmcrfs command Creates a GPFS™ file system. Synopsis mmcrfs Device {"DiskDesc[;DiskDesc...]&quo ...

  3. django信号调度的用法

    Django中提供了"信号调度",用于在框架执行操作时解耦. 一些动作发生的时候,系统会根据信号定义的函数执行相应的操作 Django中内置的signal Model_signal ...

  4. 希尔排序之Java实现

    希尔排序之Java实现 一.方法一 package cn.com.zfc.lesson21.sort; /** * * @title ShellSort * @describe 希尔排序 1959 年 ...

  5. 「WC2016」挑战NPC

    「WC2016」挑战NPC 解题思路 这个题建图非常厉害,带花树什么的只会口胡根本写不动,所以我写了机房某大佬教我的乱搞. 考虑把一个筐 \(x\) 拆成 \(x1,x2,x3\) 三个点,且这三个点 ...

  6. bzoj5102 [POI2018]Prawnicy 线段树

    $bzoj$跑的太慢了...... 我们考虑用线段树来解决这个问题 考虑扫描线 当扫到左端点$i$时,我们把线段$i$加入线段树 同时,对于每个左端点$i$,我们在线段树上二分出最远的$r$满足$r$ ...

  7. 程序逻辑问题---Writeup

    原题地址:http://ctf5.shiyanbar.com/web/5/index.php 打开后是一处登陆界面 右键查看源代码 发现有一处txt文件 很明显就是程序的源代码 可以看到其中一句 $s ...

  8. c语言scanf()停止接受输入及scanf("%c",&c)吃掉回车或者空格字符的问题

    scanf()函数接收输入数据时,遇以下情况结束一个数据的输入:(不是结束该scanf函数,scanf函数仅在每一个数据域均有数据,并按回车后结束).          ① 遇空格."回车& ...

  9. hdu 2476 区间dp

    题意: 给出两个串s1和s2,一次只能将一个区间刷一次,问最少几次能让s1=s2 例如zzzzzfzzzzz,长度为11,我们就将下标看做0~10 先将0~10刷一次,变成aaaaaaaaaaa 1~ ...

  10. 【10.7校内测试】【队列滑窗】【2-sat】【贪心+栈二分+线段树(noip模拟好题)】【生日祭!】

    比较好想的一道题,直接用队列滑窗,因为扫一遍往队列里加东西时,改变的只有一个值,开桶储存好就行了! #include<bits/stdc++.h> using namespace std; ...