顶点数据的生成

 bool                        YfBuildCapsuleVertices
(
Yreal radius,
Yreal height,
Yuint slices,
Yuint stacks,
YeOriginPose originPose,
Yuint vertexStriding,
Yuint vertexPos,
void* pVerticesBuffer
)
{
Yuint halfStacks = stacks / ;
if (slices < || halfStacks < || !pVerticesBuffer)
{
return false;
} Yuint numVertices = slices * (halfStacks - ) * + ;
Yuint numHalfVertices = numVertices / ; // 顶点赋值
char* vertexPtr = (char*)pVerticesBuffer + vertexPos;
YsVector3* curVertexPtr = NULL; Yuint nOffset = ; Yreal originOffsetY = 0.0f;
if (originPose == YE_ORIGIN_POSE_TOP)
{
originOffsetY = -radius - height*0.5f;
}
else if (originPose == YE_ORIGIN_POSE_BOTTOM)
{
originOffsetY = radius + height*0.5f;
} Yreal halfHeight = height * 0.5f;
Yreal tallness = radius* + height; // 胶囊体真正高度 // 最高顶点
{
nOffset = * vertexStriding;
curVertexPtr = (YsVector3*)(vertexPtr + nOffset);
curVertexPtr->x = 0.0f;
curVertexPtr->y = halfHeight + radius + originOffsetY;
curVertexPtr->z = 0.0f;
}
// 最底顶点
{
nOffset = numHalfVertices * vertexStriding;
curVertexPtr = (YsVector3*)(vertexPtr + nOffset);
curVertexPtr->x = 0.0f;
curVertexPtr->y = -halfHeight - radius + originOffsetY;
curVertexPtr->z = 0.0f;
} 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);
} for (Yuint i = ; i < halfStacks; i++)
{
Yreal angleY = YD_REAL_HALF_PI * i / (halfStacks - );
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 + halfHeight + originOffsetY;
curVertexPtr->z = posZ; nOffset = (numHalfVertices + + (i - ) * slices + j) * vertexStriding;
curVertexPtr = (YsVector3*)(vertexPtr + nOffset);
curVertexPtr->x = posX;
curVertexPtr->y = -posY - halfHeight + originOffsetY;
curVertexPtr->z = posZ;
}
} YD_SAFE_DELETE_ARRAY(pSinList);
YD_SAFE_DELETE_ARRAY(pCosList); return true;
}

三角形索引数据的生成

 bool                        YfBuildCapsuleTriIndices
(
Yuint slices,
Yuint stacks,
YeIndexType indexType,
Yuint indexStriding,
Yuint indexPos,
void* pTriIndicesBuffer
)
{
Yuint halfStacks = stacks / ;
if (slices < || halfStacks < || !pTriIndicesBuffer)
{
return false;
} Yuint numVertices = slices * (halfStacks - ) * + ;
if (indexType == YE_INDEX_16_BIT &&
numVertices > YD_MAX_UNSIGNED_INT16)
{
return false;
}
Yuint numHalfVertices = numVertices / ;
Yuint numTriangles = slices * (halfStacks - ) * ; // 索引赋值
char* indexPtr = (char*)pTriIndicesBuffer + indexPos;
Yuint nOffset = ;
if (indexType == YE_INDEX_16_BIT)
{
YsTriIndex16* triIndexPtr = NULL; for (Yuint i = ; i < halfStacks - ; 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; nOffset += indexStriding;
triIndexPtr = (YsTriIndex16*)(indexPtr + nOffset);
triIndexPtr->index0 = numHalfVertices;
triIndexPtr->index1 = numHalfVertices + + (j + )%slices;
triIndexPtr->index2 = numHalfVertices + + j;
}
}
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; nOffset += indexStriding;
triIndexPtr = (YsTriIndex16*)(indexPtr + nOffset);
triIndexPtr->index0 = numHalfVertices + + slices * (i - ) + j;
triIndexPtr->index1 = numHalfVertices + + slices * (i - ) + (j + )%slices;
triIndexPtr->index2 = numHalfVertices + + slices * i + (j + )%slices; nOffset += indexStriding;
triIndexPtr = (YsTriIndex16*)(indexPtr + nOffset);
triIndexPtr->index0 = numHalfVertices + + slices * (i - ) + j;
triIndexPtr->index1 = numHalfVertices + + slices * i + (j + )%slices;
triIndexPtr->index2 = numHalfVertices + + slices * i + j;
}
}
} // 连接两个半球
for (Yuint j = ; j < slices; j++)
{
nOffset = ((halfStacks - )*slices* + slices* + j*) * indexStriding;
triIndexPtr = (YsTriIndex16*)(indexPtr + nOffset);
triIndexPtr->index0 = + slices * (halfStacks - ) + j;
triIndexPtr->index1 = numHalfVertices + + slices * (halfStacks - ) + j;
triIndexPtr->index2 = + slices * (halfStacks - ) + (j + )%slices; nOffset += indexStriding;
triIndexPtr = (YsTriIndex16*)(indexPtr + nOffset);
triIndexPtr->index0 = + slices * (halfStacks - ) + (j + )%slices;
triIndexPtr->index1 = numHalfVertices + + slices * (halfStacks - ) + j;
triIndexPtr->index2 = numHalfVertices + + slices * (halfStacks - ) + (j + )%slices;
}
}
else
{
YsTriIndex32* triIndexPtr = NULL; for (Yuint i = ; i < halfStacks - ; 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; nOffset += indexStriding;
triIndexPtr = (YsTriIndex32*)(indexPtr + nOffset);
triIndexPtr->index0 = numHalfVertices;
triIndexPtr->index1 = numHalfVertices + + (j + )%slices;
triIndexPtr->index2 = numHalfVertices + (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 + ; nOffset += indexStriding;
triIndexPtr = (YsTriIndex32*)(indexPtr + nOffset);
triIndexPtr->index0 = numHalfVertices + + slices * (i - ) + j;
triIndexPtr->index1 = numHalfVertices + + slices * (i - ) + (j + )%slices;
triIndexPtr->index2 = numHalfVertices + + slices * i + (j + )%slices; nOffset += indexStriding;
triIndexPtr = (YsTriIndex32*)(indexPtr + nOffset);
triIndexPtr->index0 = numHalfVertices + + slices * (i - ) + j;
triIndexPtr->index1 = numHalfVertices + + slices * i + (j + )%slices;
triIndexPtr->index2 = numHalfVertices + + slices * i + j;
}
}
} // 连接两个半球
for (Yuint j = ; j < slices; j++)
{
nOffset = ((halfStacks - )*slices* + slices* + j*) * indexStriding;
triIndexPtr = (YsTriIndex32*)(indexPtr + nOffset);
triIndexPtr->index0 = + slices * (halfStacks - ) + j;
triIndexPtr->index1 = numHalfVertices + + slices * (halfStacks - ) + j;
triIndexPtr->index2 = + slices * (halfStacks - ) + (j + )%slices; nOffset += indexStriding;
triIndexPtr = (YsTriIndex32*)(indexPtr + nOffset);
triIndexPtr->index0 = + slices * (halfStacks - ) + (j + )%slices;
triIndexPtr->index1 = numHalfVertices + + slices * (halfStacks - ) + j;
triIndexPtr->index2 = numHalfVertices + + slices * (halfStacks - ) + (j + )%slices;
}
} return true;
}

线框索引数据的生成

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

[6] 胶囊体(Capsule)图形的生成算法的更多相关文章

  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. JSP的学习三(中文乱码)

    1). 在 JSP 页面上输入中文, 请求页面后不出现乱码: 保证 contentType="text/html; charset=UTF-8", pageEncoding=&qu ...

  2. Ubuntu16.04下Hive的安装与配置

    一.系统环境 os : Ubuntu 16.04 LTS 64bit jdk : 1.8.0_161 hadoop : 2.6.4mysql : 5.7.21 hive : 2.1.0 在配置hive ...

  3. 《Android源码设计模式》--策略模式

    No1: 定义:策略模式定义了一系列的算法,并将每一个算法封装起来,而且使它们还可以相互替换.策略模式让算法独立于使用它的客户而独立变化. No2: 使用场景: 1)针对同一类型问题的多种处理方式,仅 ...

  4. MXNet——symbol

    参考资料:有基础(Pytorch/TensorFlow基础)mxnet+gluon快速入门 symbol symbol 是一个重要的概念,可以理解为符号,就像我们平时使用的代数符号 x,y,z 一样. ...

  5. HDU - 1027 Ignatius and the Princess II 全排列

    Ignatius and the Princess II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K ( ...

  6. 美团DB数据同步到数据仓库的架构与实践

    背景 在数据仓库建模中,未经任何加工处理的原始业务层数据,我们称之为ODS(Operational Data Store)数据.在互联网企业中,常见的ODS数据有业务日志数据(Log)和业务DB数据( ...

  7. 【Performance】chrome调试面板

    本篇文章以chrome版本67.0.3396.99为例,说明性能方面的调试.

  8. BZOJ 2002: [Hnoi2010]Bounce 弹飞绵羊 lct 动态树 splay

    http://www.lydsy.com/JudgeOnline/problem.php?id=2002 http://blog.csdn.net/frods/article/details/5224 ...

  9. 【洛谷】NOIP提高组模拟赛Day2【动态开节点/树状数组】【双头链表模拟】

    U41571 Agent2 题目背景 炎炎夏日还没有过去,Agent们没有一个想出去外面搞事情的.每当ENLIGHTENED总部组织活动时,人人都说有空,结果到了活动日,却一个接着一个咕咕咕了.只有不 ...

  10. 恢复二进制文件中的block符号表

    前篇博客中,使用 杨君的小黑屋 提供的工具恢复二进制文件的符号表,只恢复了函数的符号表,本篇讲述如何恢复block符号表,杨君的博客中使用IDA分析二进制文件,本篇则使用MacOS系统上体验也不错的H ...