顶点数据的生成

 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. SVM 的推导、特点、优缺点、多分类问题及应用

    SVM有如下主要几个特点: (1)  非线性映射是SVM方法的理论基础,SVM利用内积核函数代替向高维空间的非线性映射: (2)  对特征空间划分的最优超平面是SVM的目标,最大化分类边际的思想是SV ...

  2. UIView中常见的方法汇总

    addSubview: 添加一个子视图到接收者并让它在最上面显示出来. - (void)addSubview:(UIView *)view  总结:这个方法同样设置了接收者为下一个视图响应对象.接收者 ...

  3. ThinkPHP导入第三方类库Vendor

    详情查看ThinkPHP3.2手册 架构 > 自动加载 章节 vendor('Uploader','','.class.php')

  4. linux 杂类

    1.linux 下替换windows换行符命令   set ff=unix(命令行)

  5. Linux-数据库4

    存储引擎 什么是存储引擎? mysql中建的库是文件夹,建的表是文件.文件有不同的类型,数据库中的表也有不同的类型,表的类型不同,会对应mysql不同的存取机制,表类型又称为存储引擎. 存储引擎说白了 ...

  6. web服务端安全之权限漏洞

    一.权限漏洞 访问控制是指用户对系统所有访问的权限控制,通常包含水平权限,和垂直权限. 水平越权:同一角色级别的用户之间所产生的问题,如A用户可以未授权访问B用户的数据: 垂直越权:不同角色级别的用户 ...

  7. Python处理海量数据的实战研究

    最近看了July的一些关于Java处理海量数据的问题研究,深有感触,链接:http://blog.csdn.net/v_july_v/article/details/6685962 感谢July ^_ ...

  8. ListView实现下拉刷新功能

    很久没有写博客了,感觉都懒惰了,今天说一下一个自定义的空间,就是ListView下拉列表可以刷新的功能,相信很多同学都看到过这种功能,最典型的就是新浪微博的下拉刷新列表了. 废话不多说,首先呢,下拉刷 ...

  9. CDOJ 42/BZOJ 2753 滑雪与时间胶囊 kruskal

    2753: [SCOI2012]滑雪与时间胶囊 Time Limit: 50 Sec  Memory Limit: 128 MBSubmit: 1376  Solved: 487[Submit][St ...

  10. Codeforces Round #283 (Div. 2) C. Removing Columns 暴力

    C. Removing Columns time limit per test 2 seconds memory limit per test 256 megabytes input standard ...