[17] 楼梯(Stairs)图形的生成算法
感觉这图形怎么看怎么像搓衣板.
顶点数据的生成
bool YfBuildStairsVertices
(
Yreal width,
Yreal length,
Yreal height,
Yuint stacks,
YeOriginPose originPose,
Yuint vertexStriding,
Yuint vertexPos,
void* pVerticesBuffer
)
{
if (stacks < || !pVerticesBuffer)
{
return false;
}
Yuint numVertices = + stacks * ;
//Yuint numTriangles = stacks * 8; char* vertexPtr = (char*)pVerticesBuffer + vertexPos;
YsVector3* curVertexPtr = NULL;
Yuint nOffset = ; YsVector3 vOriginOffset(-width / , -height / , -length / );
if (originPose == YE_ORIGIN_POSE_TOP)
{
vOriginOffset.y = -height;
}
else if (originPose == YE_ORIGIN_POSE_BOTTOM)
{
vOriginOffset.y = 0.0f;
} Yreal fStepLength = length / stacks;
Yreal fStepHeight = height / stacks; for (Yuint i = ; i <= stacks; i++)
{
nOffset = i * * vertexStriding;
curVertexPtr = (YsVector3*)(vertexPtr + nOffset);
curVertexPtr->x = vOriginOffset.x;
curVertexPtr->y = i * fStepHeight + vOriginOffset.y;
curVertexPtr->z = i * fStepLength + vOriginOffset.z; nOffset += vertexStriding;
curVertexPtr = (YsVector3*)(vertexPtr + nOffset);
curVertexPtr->x = width + vOriginOffset.x;
curVertexPtr->y = i * fStepHeight + vOriginOffset.y;
curVertexPtr->z = i * fStepLength + vOriginOffset.z; if (i == stacks)
{
continue;
} nOffset += vertexStriding;
curVertexPtr = (YsVector3*)(vertexPtr + nOffset);
curVertexPtr->x = vOriginOffset.x;
curVertexPtr->y = (i+) * fStepHeight + vOriginOffset.y;
curVertexPtr->z = i * fStepLength + vOriginOffset.z; nOffset += vertexStriding;
curVertexPtr = (YsVector3*)(vertexPtr + nOffset);
curVertexPtr->x = width + vOriginOffset.x;
curVertexPtr->y = (i+) * fStepHeight + vOriginOffset.y;
curVertexPtr->z = i * fStepLength + vOriginOffset.z;
} return true;
}
三角形索引数据的生成
bool YfBuildStairsTriIndices
(
Yuint stacks,
YeIndexType indexType,
Yuint indexStriding,
Yuint indexPos,
void* pTriIndicesBuffer
)
{
if (stacks < || !pTriIndicesBuffer)
{
return false;
}
Yuint numVertices = + stacks * ;
Yuint numTriangles = stacks * ;
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++)
{
nOffset = * i * indexStriding;
triIndexPtr = (YsTriIndex16*)(indexPtr + nOffset);
triIndexPtr->index0 = i* + ;
triIndexPtr->index1 = i* + ;
triIndexPtr->index2 = i* + ; nOffset += indexStriding;
triIndexPtr = (YsTriIndex16*)(indexPtr + nOffset);
triIndexPtr->index0 = i* + ;
triIndexPtr->index1 = i* + ;
triIndexPtr->index2 = i* + ; nOffset += indexStriding;
triIndexPtr = (YsTriIndex16*)(indexPtr + nOffset);
triIndexPtr->index0 = i* + ;
triIndexPtr->index1 = i* + ;
triIndexPtr->index2 = i* + ; nOffset += indexStriding;
triIndexPtr = (YsTriIndex16*)(indexPtr + nOffset);
triIndexPtr->index0 = i* + ;
triIndexPtr->index1 = i* + ;
triIndexPtr->index2 = i* + ; nOffset += indexStriding;
triIndexPtr = (YsTriIndex16*)(indexPtr + nOffset);
triIndexPtr->index0 = i* + ;
triIndexPtr->index1 = i* + ;
triIndexPtr->index2 = i* + ; nOffset += indexStriding;
triIndexPtr = (YsTriIndex16*)(indexPtr + nOffset);
triIndexPtr->index0 = i* + ;
triIndexPtr->index1 = i* + ;
triIndexPtr->index2 = i* + ; nOffset += indexStriding;
triIndexPtr = (YsTriIndex16*)(indexPtr + nOffset);
triIndexPtr->index0 = i* + ;
triIndexPtr->index1 = i* + ;
triIndexPtr->index2 = i* + ; nOffset += indexStriding;
triIndexPtr = (YsTriIndex16*)(indexPtr + nOffset);
triIndexPtr->index0 = i* + ;
triIndexPtr->index1 = i* + ;
triIndexPtr->index2 = i* + ;
}
}
else
{
YsTriIndex32* triIndexPtr = NULL;
for (Yuint i = ; i < stacks; i++)
{
nOffset = * i * indexStriding;
triIndexPtr = (YsTriIndex32*)(indexPtr + nOffset);
triIndexPtr->index0 = i* + ;
triIndexPtr->index1 = i* + ;
triIndexPtr->index2 = i* + ; nOffset += indexStriding;
triIndexPtr = (YsTriIndex32*)(indexPtr + nOffset);
triIndexPtr->index0 = i* + ;
triIndexPtr->index1 = i* + ;
triIndexPtr->index2 = i* + ; nOffset += indexStriding;
triIndexPtr = (YsTriIndex32*)(indexPtr + nOffset);
triIndexPtr->index0 = i* + ;
triIndexPtr->index1 = i* + ;
triIndexPtr->index2 = i* + ; nOffset += indexStriding;
triIndexPtr = (YsTriIndex32*)(indexPtr + nOffset);
triIndexPtr->index0 = i* + ;
triIndexPtr->index1 = i* + ;
triIndexPtr->index2 = i* + ; nOffset += indexStriding;
triIndexPtr = (YsTriIndex32*)(indexPtr + nOffset);
triIndexPtr->index0 = i* + ;
triIndexPtr->index1 = i* + ;
triIndexPtr->index2 = i* + ; nOffset += indexStriding;
triIndexPtr = (YsTriIndex32*)(indexPtr + nOffset);
triIndexPtr->index0 = i* + ;
triIndexPtr->index1 = i* + ;
triIndexPtr->index2 = i* + ; nOffset += indexStriding;
triIndexPtr = (YsTriIndex32*)(indexPtr + nOffset);
triIndexPtr->index0 = i* + ;
triIndexPtr->index1 = i* + ;
triIndexPtr->index2 = i* + ; nOffset += indexStriding;
triIndexPtr = (YsTriIndex32*)(indexPtr + nOffset);
triIndexPtr->index0 = i* + ;
triIndexPtr->index1 = i* + ;
triIndexPtr->index2 = i* + ;
}
} return true;
}
线框索引数据的生成
bool YfBuildStairsWireIndices
(
Yuint stacks,
YeIndexType indexType,
Yuint indexStriding,
Yuint indexPos,
void* pWireIndicesBuffer
)
{
if (stacks < || !pWireIndicesBuffer)
{
return false;
} Yuint numVertices = + stacks * ;
Yuint numLines = + 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 i = ; i < stacks; i++)
{
nOffset = (i * ) * indexStriding;
lineIndexPtr = (YsLineIndex16*)(indexPtr + nOffset);
lineIndexPtr->index0 = i * + ;
lineIndexPtr->index1 = i * + ; nOffset += indexStriding;
lineIndexPtr = (YsLineIndex16*)(indexPtr + nOffset);
lineIndexPtr->index0 = i * + ;
lineIndexPtr->index1 = i * + ; nOffset += indexStriding;
lineIndexPtr = (YsLineIndex16*)(indexPtr + nOffset);
lineIndexPtr->index0 = i * + ;
lineIndexPtr->index1 = i * + ;
nOffset += indexStriding;
lineIndexPtr = (YsLineIndex16*)(indexPtr + nOffset);
lineIndexPtr->index0 = i * + ;
lineIndexPtr->index1 = i * + ;
nOffset += indexStriding;
lineIndexPtr = (YsLineIndex16*)(indexPtr + nOffset);
lineIndexPtr->index0 = i * + ;
lineIndexPtr->index1 = i * + ; nOffset += indexStriding;
lineIndexPtr = (YsLineIndex16*)(indexPtr + nOffset);
lineIndexPtr->index0 = i * + ;
lineIndexPtr->index1 = i * + ;
nOffset += indexStriding;
lineIndexPtr = (YsLineIndex16*)(indexPtr + nOffset);
lineIndexPtr->index0 = i * + ;
lineIndexPtr->index1 = i * + ;
nOffset += indexStriding;
lineIndexPtr = (YsLineIndex16*)(indexPtr + nOffset);
lineIndexPtr->index0 = i * + ;
lineIndexPtr->index1 = i * + ;
} nOffset = (stacks * ) * indexStriding;
lineIndexPtr = (YsLineIndex16*)(indexPtr + nOffset);
lineIndexPtr->index0 = stacks * ;
lineIndexPtr->index1 = stacks * + ;
}
else
{
YsLineIndex32* lineIndexPtr = NULL;
for (Yuint i = ; i < stacks; i++)
{
nOffset = (i * ) * indexStriding;
lineIndexPtr = (YsLineIndex32*)(indexPtr + nOffset);
lineIndexPtr->index0 = i * + ;
lineIndexPtr->index1 = i * + ; nOffset += indexStriding;
lineIndexPtr = (YsLineIndex32*)(indexPtr + nOffset);
lineIndexPtr->index0 = i * + ;
lineIndexPtr->index1 = i * + ; nOffset += indexStriding;
lineIndexPtr = (YsLineIndex32*)(indexPtr + nOffset);
lineIndexPtr->index0 = i * + ;
lineIndexPtr->index1 = i * + ;
nOffset += indexStriding;
lineIndexPtr = (YsLineIndex32*)(indexPtr + nOffset);
lineIndexPtr->index0 = i * + ;
lineIndexPtr->index1 = i * + ;
nOffset += indexStriding;
lineIndexPtr = (YsLineIndex32*)(indexPtr + nOffset);
lineIndexPtr->index0 = i * + ;
lineIndexPtr->index1 = i * + ; nOffset += indexStriding;
lineIndexPtr = (YsLineIndex32*)(indexPtr + nOffset);
lineIndexPtr->index0 = i * + ;
lineIndexPtr->index1 = i * + ;
nOffset += indexStriding;
lineIndexPtr = (YsLineIndex32*)(indexPtr + nOffset);
lineIndexPtr->index0 = i * + ;
lineIndexPtr->index1 = i * + ;
nOffset += indexStriding;
lineIndexPtr = (YsLineIndex32*)(indexPtr + nOffset);
lineIndexPtr->index0 = i * + ;
lineIndexPtr->index1 = i * + ;
} nOffset = (stacks * ) * indexStriding;
lineIndexPtr = (YsLineIndex32*)(indexPtr + nOffset);
lineIndexPtr->index0 = stacks * ;
lineIndexPtr->index1 = stacks * + ;
} return true;
}
[17] 楼梯(Stairs)图形的生成算法的更多相关文章
- [18] 螺旋楼梯(Spiral Stairs)图形的生成算法
顶点数据的生成 bool YfBuildSpiralStairsVertices ( Yreal radius, Yreal assistRadius, Yreal height, Yuint sli ...
- [20] 鼓状物(Drum)图形的生成算法
顶点数据的生成 bool YfBuildDrumVertices ( Yreal radius, Yreal assistRadius, Yuint slices, Yuint stacks, YeO ...
- [19] 半球形(Hemisphere)图形的生成算法
顶点数据的生成 bool YfBuildHemisphereVertices ( Yreal radius, Yuint slices, Yuint stacks, YeOriginPose orig ...
- [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 ...
- [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 ...
随机推荐
- 【Java】 剑指offer(49) 丑数
本文参考自<剑指offer>一书,代码采用Java语言. 更多:<剑指Offer>Java实现合集 题目 我们把只包含因子2.3和5的数称作丑数(Ugly Number). ...
- hdoj2159 FATE(完全背包)
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=2159 思路 每种怪都有无限个,所以使用完全背包来解决.这题比普通完全背包多了一个条件,就是杀怪的个数不 ...
- 《Android源码设计模式》--Builder模式
No1: 将一个复杂对象的构建与它的表示分离,使得同样的构建过程可以创建不同的表示 No2: 在Android源码中,最常用到的Builder模式就是AlertDialog.Builder No3: ...
- C#拖拽操作
C#的拖拽 本文将以Winform为例 有两个主要的事件: DragEnter 拖拽到区域中触发的事件 DragDrop 当拖拽落下的时候出发此事件 饮水思源 参考博客: http://www.cnb ...
- CSS基础-DAY2
CSS属性操作-文本 文本颜色 <head> <style> p{ /*color:#8B5742 ;色码表*/ color: RGBA(255,0,0,0.5); /*调色, ...
- 1020 Tree Traversals (25)(25 point(s))
problem Suppose that all the keys in a binary tree are distinct positive integers. Given the postord ...
- ARM 中必须明白的几个概念
文章具体介绍了关于ARM的22个常用概念. 1.ARM中一些常见英文缩写解释 MSB:最高有效位: LSB:最低有效位: AHB:先进的高性能总线: VPB:连接片内外设功能的VLSI外设总线: EM ...
- 常用SQL脚本记录一
20.SUM()和 列+ 统计结果时:如果列里有一行为null,SUM函数会忽略它:如果+,则结果集也为NULL了 19 SUBSTRING (expression,startIndex, endIn ...
- java设计模式(四)代理模式
适用于为不同操作添加共同的额外行为.通过代理对象访问目标对象,这样可以增加对目标对象的额外操作,达到扩展目标对象功能的目的,如spring事务.AOP等. 要点:1)抽象角色:通过接口或抽象类声明真实 ...
- [PA2014]Pakowanie
[PA2014]Pakowanie 题目大意: \(n(n\le24)\)个物品和\(m(m\le100)\)个背包,每个物体有一个体积\(a_i\),每个背包有一个容量\(c_i\).问装完所有物品 ...