[12] 扇形体(Fan)图形的生成算法
顶点数据的生成
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)图形的生成算法的更多相关文章
- [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 ...
- [13] 弧面(Arc)图形的生成算法
顶点数据的生成 bool YfBuildArcVertices ( Yreal radius, Yreal degree, Yreal height, Yuint slices, Yuint stac ...
- [11] 楔形体(Wedge)图形的生成算法
顶点数据的生成 bool YfBuildWedgeVertices ( Yreal width, Yreal length, Yreal height, YeOriginPose originPose ...
随机推荐
- mac 用密钥远程登陆
window远程登陆命令:mstsc A为本地主机(即用于控制其他主机的机器) ;B为远程主机(即被控制的机器Server), 假如ip为192.168.60.110;A和B的系统都是Linux 在A ...
- memory_get_usage()查看PHP脚本使用内存
memory_get_usage()可以查看当前php使用的内存大小.对于优化算法提高内存使用效率还是很实用的,尤其是对当下的移动端程序. <?php echo memory_get_usage ...
- react-native第一次开发记录
1.安装指定版本 react-native init demo --verbose --version 0.41.0 2.更新依赖包 npm install -g npm-check-updates ...
- QTableView和QTableWidget翻页功能实现
主要使用QTableView和QTableWidget中的三个函数实现 QTableView::verticalScrollBar()->setSliderPosition(): //设置当前 ...
- Java拾遗补缺
JDK9的lib目录下已经不再包含dt.jar和tool.jar.
- JPA实体类中的注解
@Entity 标注于实体类上,通常和@Table是结合使用的,代表是该类是实体类@Table 标注于实体类上,表示该类映射到数据库中的表,没有指定名称的话就表示与数据库中表名为该类的简单类名的表名相 ...
- 【转】JQuery Validate使用总结1
一.导入js库 <script src="../js/jquery.js" type="text/javascript"></script&g ...
- 微信小游戏 lodash 问题
在微信小游戏里引入 lodash 会报错 window._ = require("./js/thirdParty/lodash.js"); 所以得把lodash.js 里面的源码 ...
- MVC 设计模式与三层架构
一.JavaEE开发模式 什么是开发模式 模式是在开发过程中总结出的"套路",总结出的一套约定俗成的设计模式 JavaEE模式 model1模式 技术组成 :jsp+javaBea ...
- 【NOIP2014】生活大爆炸版石头剪刀布
石头剪刀布是常见的猜拳游戏:石头胜剪刀,剪刀胜布,布胜石头.如果两个人出拳一 样,则不分胜负.在<生活大爆炸>第二季第 8 集中出现了一种石头剪刀布的升级版游戏. 升级版游戏在传统的石头剪 ...