[18] 螺旋楼梯(Spiral Stairs)图形的生成算法-LMLPHP

[18] 螺旋楼梯(Spiral Stairs)图形的生成算法-LMLPHP
顶点数据的生成

 bool                        YfBuildSpiralStairsVertices
(
Yreal radius,
Yreal assistRadius,
Yreal height,
Yuint slices,
Yuint stacks,
YeOriginPose originPose,
Yuint vertexStriding,
Yuint vertexPos,
void* pVerticesBuffer
)
{
if (stacks < || slices < || !pVerticesBuffer)
{
return false;
}
Yuint numVertices = + stacks * ;
//Yuint numTriangles = stacks * 8; 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;
} Yreal fStepTexcoord = 1.0f / (stacks - );
Yreal fStepHeight = height / stacks;
Yreal fStepAngle = YD_REAL_TWAIN_PI / slices; Yreal angleXZ;
Yreal posX, posZ;
for (Yuint i = ; i <= stacks; i++)
{
angleXZ = i * fStepAngle;
posX = yf_sin(angleXZ);
posZ = yf_cos(angleXZ); nOffset = i * * vertexStriding;
curVertexPtr = (YsVector3*)(vertexPtr + nOffset);
curVertexPtr->x = radius * posX;
curVertexPtr->y = i * fStepHeight + originOffsetY;
curVertexPtr->z = radius * posZ; nOffset += vertexStriding;
curVertexPtr = (YsVector3*)(vertexPtr + nOffset);
curVertexPtr->x = assistRadius * posX;
curVertexPtr->y = i * fStepHeight + originOffsetY;
curVertexPtr->z = assistRadius * posZ; if (i == stacks)
{
continue;
} nOffset += vertexStriding;
curVertexPtr = (YsVector3*)(vertexPtr + nOffset);
curVertexPtr->x = radius * posX;
curVertexPtr->y = (i+) * fStepHeight + originOffsetY;
curVertexPtr->z = radius * posZ; nOffset += vertexStriding;
curVertexPtr = (YsVector3*)(vertexPtr + nOffset);
curVertexPtr->x = assistRadius * posX;
curVertexPtr->y = (i+) * fStepHeight + originOffsetY;
curVertexPtr->z = assistRadius * posZ;
} return true;
}

三角形索引数据的生成和线框索引数据的生成与楼梯的生成方式一样

 bool                        YfBuildSpiralStairsTriIndices
(
Yuint stacks,
YeIndexType indexType,
Yuint indexStriding,
Yuint indexPos,
void* pTriIndicesBuffer
)
{
return YfBuildStairsTriIndices(
stacks,
indexType,
indexStriding,
indexPos,
pTriIndicesBuffer
);
} bool YfBuildSpiralStairsWireIndices
(
Yuint stacks,
YeIndexType indexType,
Yuint indexStriding,
Yuint indexPos,
void* pWireIndicesBuffer
)
{
return YfBuildStairsWireIndices(
stacks,
indexType,
indexStriding,
indexPos,
pWireIndicesBuffer
);
}
05-11 22:44