[1] 平面(Plane)图形的生成算法
顶点数据的生成
bool YfBuildPlaneVertices
(
Yreal width,
Yreal length,
Yreal height,
Yuint slices,
Yuint stacks,
YeOriginPose originPose,
Yuint vertexStriding,
Yuint vertexPos,
void* pVerticesBuffer
)
{
if (slices < || stacks < || !pVerticesBuffer)
{
return false;
} // 顶点赋值
char* vertexPtr = (char*)pVerticesBuffer + vertexPos;
YsVector3* curVertexPtr = NULL;
Yuint nOffset = ; Yreal xStep = width / slices;
Yreal zStep = length / stacks;
YsVector3 vOrigin;
if (originPose == YE_ORIGIN_POSE_CENTER)
{
vOrigin.x = -width * 0.5f;
vOrigin.z = -length * 0.5f;
} for (Yuint j = ; j < stacks; j++) // Z方向
{
for (Yuint i = ; i < slices; i++) // X方向
{
nOffset = (j*slices + i) * vertexStriding;
curVertexPtr = (YsVector3*)(vertexPtr + nOffset);
curVertexPtr->x = vOrigin.x + i*xStep;
curVertexPtr->y = height;
curVertexPtr->z = vOrigin.z + j*zStep;
}
} return true;
}
三角形索引数据的生成
bool YfBuildPlaneTriIndices
(
Yuint slices,
Yuint stacks,
YeIndexType indexType,
Yuint indexStriding,
Yuint indexPos,
void* pTriIndicesBuffer
)
{
if (slices < || stacks < || !pTriIndicesBuffer)
{
return false;
} Yuint numVertices = slices * stacks;
if (indexType == YE_INDEX_16_BIT &&
numVertices > YD_MAX_UNSIGNED_INT16)
{
return false;
} Yuint numTriangles = (slices - ) * (stacks - ) * ; char* indexPtr = (char*)pTriIndicesBuffer + indexPos;
Yuint nOffset = ; if (indexType == YE_INDEX_16_BIT)
{
YsTriIndex16* triIndexPtr = NULL; for (Yuint j = ; j < stacks - ; j++) // Z方向
{
for (Yuint i = ; i < slices - ; i++) // X方向
{
nOffset = ( * (j*(slices - ) + i)) * indexStriding;
triIndexPtr = (YsTriIndex16*)(indexPtr + nOffset);
triIndexPtr->index0 = j*slices + i;
triIndexPtr->index1 = (j + )*slices + i + ;
triIndexPtr->index2 = j*slices + i + ; nOffset += indexStriding;
triIndexPtr = (YsTriIndex16*)(indexPtr + nOffset);
triIndexPtr->index0 = j*slices + i;
triIndexPtr->index1 = (j + )*slices + i;
triIndexPtr->index2 = (j + )*slices + i + ;
}
}
}
else
{
YsTriIndex32* triIndexPtr = NULL; for (Yuint j = ; j < stacks - ; j++) // Z方向
{
for (Yuint i = ; i < slices - ; i++) // X方向
{
nOffset = ( * (j*(slices - ) + i)) * indexStriding;
triIndexPtr = (YsTriIndex32*)(indexPtr + nOffset);
triIndexPtr->index0 = j*slices + i;
triIndexPtr->index1 = (j + )*slices + i + ;
triIndexPtr->index2 = j*slices + i + ; nOffset += indexStriding;
triIndexPtr = (YsTriIndex32*)(indexPtr + nOffset);
triIndexPtr->index0 = j*slices + i;
triIndexPtr->index1 = (j + )*slices + i;
triIndexPtr->index2 = (j + )*slices + i + ;
}
}
} return true;
}
线框索引数据的生成
bool YfBuildPlaneWireIndices
(
Yuint slices,
Yuint stacks,
YeIndexType indexType,
Yuint indexStriding,
Yuint indexPos,
void* pWireIndicesBuffer
)
{
if (slices < || stacks < || !pWireIndicesBuffer)
{
return false;
} Yuint numVertices = slices * stacks;
if (indexType == YE_INDEX_16_BIT &&
numVertices > YD_MAX_UNSIGNED_INT16)
{
return false;
} Yuint numLines = slices * (stacks - ) +(slices - ) * stacks; char* indexPtr = (char*)pWireIndicesBuffer + indexPos;
Yuint nOffset = ; if (indexType == YE_INDEX_16_BIT)
{
YsLineIndex16* lineIndexPtr = NULL; // 行
for (Yuint j = ; j < stacks; j++)
{
for (Yuint i = ; i < slices - ; i++)
{
nOffset = ((j*(slices - ) + i)) * indexStriding;
lineIndexPtr = (YsLineIndex16*)(indexPtr + nOffset);
lineIndexPtr->index0 = j*slices + i;
lineIndexPtr->index1 = j*slices + i + ;
}
} // 列
Yuint half = (slices - ) * stacks;
for (Yuint i = ; i < slices; i++)
{
for (Yuint j = ; j < stacks - ; j++)
{
nOffset = (half + (i*(stacks - ) + j)) * indexStriding;
lineIndexPtr = (YsLineIndex16*)(indexPtr + nOffset);
lineIndexPtr->index0 = j*slices + i;
lineIndexPtr->index1 = (j + )*slices + i;
}
}
}
else
{
YsLineIndex32* lineIndexPtr = NULL; // 行
for (Yuint j = ; j < stacks; j++)
{
for (Yuint i = ; i < slices - ; i++)
{
nOffset = ((j*(slices - ) + i)) * indexStriding;
lineIndexPtr = (YsLineIndex32*)(indexPtr + nOffset);
lineIndexPtr->index0 = j*slices + i;
lineIndexPtr->index1 = j*slices + i + ;
}
} // 列
Yuint half = (slices - ) * stacks;
for (Yuint i = ; i < slices; i++)
{
for (Yuint j = ; j < stacks - ; j++)
{
nOffset = (half + (i*(stacks - ) + j)) * indexStriding;
lineIndexPtr = (YsLineIndex32*)(indexPtr + nOffset);
lineIndexPtr->index0 = j*slices + i;
lineIndexPtr->index1 = (j + )*slices + i;
}
}
} return true;
}
[1] 平面(Plane)图形的生成算法的更多相关文章
- [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 ...
- [12] 扇形体(Fan)图形的生成算法
顶点数据的生成 bool YfBuildFunVertices ( Yreal radius, Yreal degree, Yreal height, Yuint slices, YeOriginPo ...
随机推荐
- matplotlib使用总结
一.简介 Matplotlib 是一个 Python 的 2D绘图库,它以各种硬拷贝格式和跨平台的交互式环境生成出版质量级别的图形.通过 Matplotlib,开发者可以仅需要几行代码,便可以生成绘图 ...
- mac 用密钥远程登陆
window远程登陆命令:mstsc A为本地主机(即用于控制其他主机的机器) ;B为远程主机(即被控制的机器Server), 假如ip为192.168.60.110;A和B的系统都是Linux 在A ...
- C#中 EF(EntityFramework) 性能优化
现在工作中很少使用原生的sql了,大多数的时候都在使用EF.刚开始的时候,只是在注重功能的实现,最近一段时间在做服务端接口开发.开发的时候也是像之前一样,键盘噼里啪啦的一顿敲,接口秒秒钟上线,但是到联 ...
- 交换机高级特性MUX VLAN
MUX VLAN 基本概念 lMUX VLAN(Multiplex VLAN)提供了一种通过VLAN进行网络资源控制的机制. 例如,在企业网络中,企业员工和企业客户可以访问企业的服务器. 对于企业来说 ...
- 初识Spring——Spring核心容器
一. IOC和DI基础 IOC-Inversion of Control,译为控制反转,是一种遵循依赖倒置原则的代码设计思想. 所谓依赖倒置,就是把原本的高层建筑依赖底层建筑“倒置”过来,变成底层建筑 ...
- ActiveMQ (二):JMS
1.前言 由于ActiveMQ是一种完全符合JMS规范的一种通信工具,所以在使用ActiveMQ前认识JMS规范就变的十分必要了. 认识JMS主要从以下方面: a. JMS 模型 b. JMS 对象模 ...
- 1012 The Best Rank (25)(25 point(s))
problem To evaluate the performance of our first year CS majored students, we consider their grades ...
- map赋值前要先初始化:assignment to entry in nil map
注意这种map的嵌套的形式,make只初始化了map[string]T部分(T为map[int]int),所以下面的赋值会出现错误: test := make(map[string]map[int]i ...
- Django配置参数可选总结
一.可选字段参数 null blank core db_index editable primary_key radio_admin unique True or False db_colum hel ...
- Spring的模块组成
Spring的模块组成 1.核心容器:核心容器提供 Spring 框架的基本功能(Spring Core).核心容器的主要组件是 BeanFactory,它是工厂模式的实现. BeanFactory ...