[13] 弧面(Arc)图形的生成算法
顶点数据的生成
bool YfBuildArcVertices
(
Yreal radius,
Yreal degree,
Yreal height,
Yuint slices,
Yuint stacks,
YeOriginPose originPose,
Yuint vertexStriding,
Yuint vertexPos,
void* pVerticesBuffer
)
{
if (degree < || degree > || !pVerticesBuffer)
{
return false;
}
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);
} // 赋值
{
Yreal radian = YD_DEGREE_TO_RADIAN(degree);
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 = radian * 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 % slices];
posZ = radiusXZ * pCosList[j % slices]; 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 YfBuildArcTriIndices
(
Yuint slices,
Yuint stacks,
YeIndexType indexType,
Yuint indexStriding,
Yuint indexPos,
void* pTriIndicesBuffer
)
{
if (slices < || stacks < || !pTriIndicesBuffer)
{
return false;
} Yuint numVertices = slices * (stacks - ) + ;
Yuint numTriangles = slices * (stacks - ) * + 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 < 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 = ((i - )*slices * + 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 = ((i - )*slices * + 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 YfBuildArcWireIndices
(
Yuint slices,
Yuint stacks,
YeIndexType indexType,
Yuint indexStriding,
Yuint indexPos,
void* pWireIndicesBuffer
)
{
if (slices < || !pWireIndicesBuffer)
{
return false;
} Yuint numVertices = slices * (stacks - ) + ;
Yuint numLines = slices * (stacks - ) + slices * (stacks - );
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 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 half = slices * (stacks - );
for (Yuint i = ; i < slices; i++)
{
nOffset = (half + i) * indexStriding;
lineIndexPtr = (YsLineIndex16*)(indexPtr + nOffset);
lineIndexPtr->index0 = ;
lineIndexPtr->index1 = + i;
}
half += slices; for (Yuint j = ; j < stacks - ; j++)
{
for (Yuint i = ; i < slices; i++)
{
nOffset = (half + (j - )*slices + i) * indexStriding;
lineIndexPtr = (YsLineIndex16*)(indexPtr + nOffset);
lineIndexPtr->index0 = + (j - )*slices + i;
lineIndexPtr->index1 = + j*slices + i;
}
} //// 列
//Yuint half = slices * (stacks - 1);
//for (Yuint i = 0; i < slices; i++)
//{
// for (Yuint j = 0; j < stacks - 2; j++)
// {
// nOffset = (half + (i*(stacks - 1) + j)) * indexStriding;
// lineIndexPtr = (YsLineIndex16*)(indexPtr + nOffset);
// if (j == 0)
// {
// lineIndexPtr->index0 = 0;
// }
// else
// {
// lineIndexPtr->index0 = 1 + (j - 1)*slices + i;
// } // lineIndexPtr->index1 = 1 + 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 half = slices * (stacks - );
for (Yuint i = ; i < slices; i++)
{
nOffset = (half + i) * indexStriding;
lineIndexPtr = (YsLineIndex32*)(indexPtr + nOffset);
lineIndexPtr->index0 = ;
lineIndexPtr->index1 = + i;
}
half += slices; for (Yuint j = ; j < stacks - ; j++)
{
for (Yuint i = ; i < slices; i++)
{
nOffset = (half + (j - )*slices + i) * indexStriding;
lineIndexPtr = (YsLineIndex32*)(indexPtr + nOffset);
lineIndexPtr->index0 = + (j - )*slices + i;
lineIndexPtr->index1 = + j*slices + i;
}
} // 列
//Yuint half = slices * (stacks - 1);
//for (Yuint i = 0; i < slices; i++)
//{
// for (Yuint j = 0; j < stacks - 2; j++)
// {
// nOffset = (half + (i*(stacks - 1) + j)) * indexStriding;
// lineIndexPtr = (YsLineIndex32*)(indexPtr + nOffset);
// if (j == 0)
// {
// lineIndexPtr->index0 = 0;
// }
// else
// {
// lineIndexPtr->index0 = 1 + (j - 1)*slices + i;
// } // lineIndexPtr->index1 = 1 + j*slices + i;
// }
//}
} return true;
}
[13] 弧面(Arc)图形的生成算法的更多相关文章
- [20] 鼓状物(Drum)图形的生成算法
顶点数据的生成 bool YfBuildDrumVertices ( Yreal radius, Yreal assistRadius, Yuint slices, Yuint stacks, YeO ...
- [17] 楼梯(Stairs)图形的生成算法
感觉这图形怎么看怎么像搓衣板. 顶点数据的生成 bool YfBuildStairsVertices ( Yreal width, Yreal length, Yreal height, Yuint ...
- [19] 半球形(Hemisphere)图形的生成算法
顶点数据的生成 bool YfBuildHemisphereVertices ( Yreal radius, Yuint slices, Yuint stacks, YeOriginPose orig ...
- [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 ...
- [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 ...
随机推荐
- Python之路【第十一篇】: 进程与线程
阅读目录 一. cpython并发编程之多进程1.1 multiprocessing模块介绍1.2 Process类的介绍1.3 Process类的使用1.4 进程间通信(IPC)方式一:队列1.5 ...
- PIL 学习
参考资料:Python图像处理库:pillow Image 类 Pillow 中最重要的类就是 Image,该类存在于同名的模块中.可以通过以下几种方式实例化:从文件中读取图片,处理其他图片得到,或者 ...
- 【小思考】Python的float转换精度损失所想到的
首先,为啥会要讨论这个问题. 我得为昨天拖了小组后腿深表歉意.其实程序逻辑很快就理通了的,但自己总是会因为各种各样的小问题束缚手脚,看接下来这个图片: 稍微有数据敏感性的同学就能看出,中间这么一大堆又 ...
- Revit二次开发示例:CancelSave
在Revit程序中注册文件操作事件,保存新建或打开文件的信息.当保存时,如果当前文件内容和之前的一致时,则弹出对话框提示并取消保存.对话框中有一个功能链接,点击可打开插件所在目录. #region N ...
- python io 模块之 open() 方法(好久没写博客了)
io.open(file, mode='r', buffering=-1, encoding=None, errors=None, newline=None, closefd=True),打开file ...
- android view surfaceView GLSurfaceView
韩梦飞沙 韩亚飞 313134555@qq.com yue31313 han_meng_fei_sha 表面视图 SurfaceView 是 视图 的子类, 刷新界面速度比 视图 块, 因为它 ...
- 【BFS】【最小生成树】Petrozavodsk Winter Training Camp 2018 Day 1: Jagiellonian U Contest, Tuesday, January 30, 2018 Problem G. We Need More Managers!
题意:给你n个点,点带权,任意两点之间的边权是它们的点权的异或值中“1”的个数,问你该图的最小生成树. 看似是个完全图,实际上有很多边是废的.类似……卡诺图的思想?从读入的点出发BFS,每次只到改变它 ...
- 【差分约束系统/DFS版SPFA】BZOJ3436-小K的农场
[题目大意] 总共n个农场,有以下三种描述:农场a比农场b至少多种植了c个单位的作物,农场a比农场b至多多种植了c个单位的作物,农场a与农场b种植的作物数一样多.问是否有可能性. [思路] 农场a比农 ...
- [POI2015]Trzy wieże
[POI2015]Trzy wieże 题目大意: 给定一个长度为\(n(n\le10^6)\)的仅包含'B'.'C'.'S'三种字符的字符串,请找到最长的一段连续子串,使得在这一段内出现过的所有字符 ...
- Shell 学习笔记之条件语句
条件语句 if # if if condition then command fi # if else if condition then command else command fi # if e ...