[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 ...
随机推荐
- C#中 EF(EntityFramework) 性能优化
现在工作中很少使用原生的sql了,大多数的时候都在使用EF.刚开始的时候,只是在注重功能的实现,最近一段时间在做服务端接口开发.开发的时候也是像之前一样,键盘噼里啪啦的一顿敲,接口秒秒钟上线,但是到联 ...
- mysql 函数group_concat()
本文通过实例介绍了MySQL中的group_concat函数的使用方法,比如select group_concat(name) .MySQL中group_concat函数完整的语法如下:group_c ...
- mysql插入数据时,去掉重复的数据;
1. 利用insert ignore into语句去重 mysql> INSERT IGNORE INTO person_tbl (last_name, first_name) -> VA ...
- 洛谷P3527 [POI2011]MET-Meteors [整体二分]
题目传送门 Meteors 格式难调,题面就不妨放了. 分析: 一道整体二分的练手题. 就是一般的整体二分的套路,但是要注意,将修改和询问加入队列的时候要先加修改再加询问.另外,博主代码打得太丑,常数 ...
- JAVAEE——SSH项目实战03:新增客户、数据字典、文件上传和修改客户
作者: kent鹏 转载请注明出处: http://www.cnblogs.com/xieyupeng/p/7145599.html 一.新增客户 1.数据字典 用于枚举项目中有限个数的字典项 (1 ...
- 1006 Sign In and Sign Out (25)(25 point(s))
problem At the beginning of every day, the first person who signs in the computer room will unlock t ...
- 数据库中drop、delete与truncate的区别
数据库中drop.delete与truncate的区别 drop直接删掉表: truncate删除表中数据,再插入时自增长id又从1开始 :delete删除表中数据,可以加where字句. (1) D ...
- BZOJ 2333: [SCOI2011]棘手的操作 可并堆 左偏树 set
https://www.lydsy.com/JudgeOnline/problem.php?id=2333 需要两个结构分别维护每个连通块的最大值和所有连通块最大值中的最大值,可以用两个可并堆实现,也 ...
- hdu 2110 基础母函数
题意:退出本身并不麻烦,麻烦的是,退出的人需要取走相应比例(1/3)金额的资产.假设公司此时一共有n种价值的资产,每种价值的资产数量已知,请帮助心烦意乱的XHD夫妇计算一共有多少种分割资产的方法. ...
- Jenkins 使用 maven 出现C:\Windows\system32\config\systemprofile的解决
jenkins 使用 maven 出现 C:\Windows\system32\config\systemprofile 的原因是 Jenkins 服务启动的账号使用了系统的账号,在服务里改成具体的桌 ...