顶点数据的生成
bool YfBuildRingVertices
(
Yreal radius,
Yreal assistRadius,
Yreal height,
Yuint slices,
Yuint stacks,
YeOriginPose originPose,
Yuint vertexStriding,
Yuint vertexPos,
void* pVerticesBuffer
)
{
if (slices < || stacks < || !pVerticesBuffer)
{
return false;
} Yuint numVertices = slices * stacks;
Yuint numTriangles = slices * stacks * ; char* vertexPtr = (char*)pVerticesBuffer + vertexPos;
YsVector3* curVertexPtr = NULL;
Yuint nOffset = ; Yreal halfHeight = height * 0.5f;
Yreal originOffsetY = 0.0f;
if (originPose == YE_ORIGIN_POSE_TOP)
{
originOffsetY = -halfHeight;
}
else if (originPose == YE_ORIGIN_POSE_BOTTOM)
{
originOffsetY = halfHeight;
} Yreal angle, s, c;
YsVector3* initVerticesPtr = new YsVector3[slices + ];
for (Yuint j = ; j < slices; j++)
{
angle = YD_REAL_TWAIN_PI * j / slices;
s = yf_sin(angle);
c = yf_cos(angle);
initVerticesPtr[j].x = radius + assistRadius*s;
initVerticesPtr[j].y = halfHeight*c + originOffsetY;
initVerticesPtr[j].z = 0.0f;
} for (Yuint i = ; i < stacks; i++)
{
angle = YD_REAL_TWAIN_PI * i / stacks;
s = yf_sin(angle);
c = yf_cos(angle); for (Yuint j = ; j < slices; j++)
{
nOffset = (i * slices + j) * vertexStriding;
curVertexPtr = (YsVector3*)(vertexPtr + nOffset);
curVertexPtr->x = initVerticesPtr[j].x * s;
curVertexPtr->y = initVerticesPtr[j].y;
curVertexPtr->z = initVerticesPtr[j].x * c;
}
} YD_SAFE_DELETE_ARRAY(initVerticesPtr); return true;
}
三角形索引数据的生成
bool YfBuildRingTriIndices
(
Yuint slices,
Yuint stacks,
YeIndexType indexType,
Yuint indexStriding,
Yuint indexPos,
void* pTriIndicesBuffer
)
{
if (slices < || stacks < || !pTriIndicesBuffer)
{
return false;
} Yuint numVertices = slices * stacks;
Yuint numTriangles = slices * 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++)
{
for (Yuint j = ; j < slices; j++)
{
nOffset = (i*slices + j)* * indexStriding;
triIndexPtr = (YsTriIndex16*)(indexPtr + nOffset);
triIndexPtr->index0 = slices * i + j;
triIndexPtr->index1 = slices * i + (j + )%slices;
triIndexPtr->index2 = slices * ((i + ) % stacks) + j; nOffset += indexStriding;
triIndexPtr = (YsTriIndex16*)(indexPtr + nOffset);
triIndexPtr->index0 = slices * i + (j + )%slices;
triIndexPtr->index1 = slices * ((i + ) % stacks) + (j + )%slices;
triIndexPtr->index2 = slices * ((i + ) % stacks) + j;
}
}
}
else
{
YsTriIndex32* triIndexPtr = NULL;
for (Yuint i = ; i < stacks; i++)
{
for (Yuint j = ; j < slices; j++)
{
nOffset = (i*slices + j)* * indexStriding;
triIndexPtr = (YsTriIndex32*)(indexPtr + nOffset);
triIndexPtr->index0 = slices * i + j;
triIndexPtr->index1 = slices * i + (j + )%slices;
triIndexPtr->index2 = slices * ((i + ) % stacks) + j; nOffset += indexStriding;
triIndexPtr = (YsTriIndex32*)(indexPtr + nOffset);
triIndexPtr->index0 = slices * i + (j + )%slices;
triIndexPtr->index1 = slices * ((i + ) % stacks) + (j + )%slices;
triIndexPtr->index2 = slices * ((i + ) % stacks) + j;
}
}
} return true;
}
线框索引数据的生成
bool YfBuildRingWireIndices
(
Yuint slices,
Yuint stacks,
YeIndexType indexType,
Yuint indexStriding,
Yuint indexPos,
void* pWireIndicesBuffer
)
{
if (slices < || !pWireIndicesBuffer)
{
return false;
} Yuint numVertices = slices * stacks;
Yuint numLines = slices * 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++)
{
for (Yuint j = ; j < slices; j++)
{
nOffset = (i*slices + j) * * indexStriding;
lineIndexPtr = (YsLineIndex16*)(indexPtr + nOffset);
lineIndexPtr->index0 = slices * i + j;
lineIndexPtr->index1 = slices * i + (j + )%slices; nOffset += indexStriding;
lineIndexPtr = (YsLineIndex16*)(indexPtr + nOffset);
lineIndexPtr->index0 = slices * i + j;
lineIndexPtr->index1 = slices * ((i + ) % stacks) + j;
}
}
}
else
{
YsLineIndex32* lineIndexPtr = NULL;
for (Yuint i = ; i < stacks; i++)
{
for (Yuint j = ; j < slices; j++)
{
nOffset = (i*slices + j) * * indexStriding;
lineIndexPtr = (YsLineIndex32*)(indexPtr + nOffset);
lineIndexPtr->index0 = slices * i + j;
lineIndexPtr->index1 = slices * i + (j + )%slices; nOffset += indexStriding;
lineIndexPtr = (YsLineIndex32*)(indexPtr + nOffset);
lineIndexPtr->index0 = slices * i + j;
lineIndexPtr->index1 = slices * ((i + ) % stacks) + j;
}
}
} return true;
}
[9] 圆环(Ring)图形的生成算法的更多相关文章
-
[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 ...
随机推荐
-
数据分析 - 开放街道地图(OpenStreetMap)
数据分析 - 开放街道地图(OpenStreetMap) Reinhard使用OpenStreetMap的开放地图数据作为本次数据分析的数据源,使用Python进行数据清洗,使用MongoDB进行数据 ...
-
谈谈 JavaScript 中的 this 指向问题
JavaScript 中的 this 为一个重难点,它不像静态语言 C#.Java 一样,就表示当前对象.而在 JS 中, this 是运行时确定,而并非定义时就已确定其值. 谈起 this ,必须少 ...
-
创建和使用RMAN存储脚本
创建和使用RMAN存储脚本:1.连接恢复目录(可以不连接到目标库):C:\Users\Administrator>rman target sys/rusky@rusky catalog=rcat ...
-
浅析点对点(End-to-End)的场景文字识别(图片文字)
一.背景 随着智能手机的广泛普及和移动互联网的迅速发展,通过手机等移动终端的摄像头获取.检索和分享资讯已经逐步成为一种生活方式.基于摄像头的 (Camera-based)的应用更加强调对拍摄场景的理解 ...
-
【原】Java学习笔记013 - 阶段测试
package cn.temptation; import java.util.Scanner; public class Sample01 { public static void main(Str ...
-
flutter环境配置
java环境安装 做基于android的原生app,首先需要安装java环境,需要到官网https://www.oracle.com/technetwork/java/javase/downloads ...
-
mui之上拉刷新和mui-content结合解决ios上拉不回弹的bug
打电话.发短信 https://blog.csdn.net/itguangit/article/details/78210770
-
EF使用MySql DBFirst产品的问题总结
一.实体数据模型向导->新建连接->更改数据源 找不到MySql Batabase选项. 解决:需求安装以下两个插件(mysql官网都可以找到)(注意版本,后面会讲到) 1.MySql ...
-
Spring JDBC StoredProcedure类示例
org.springframework.jdbc.core.StoredProcedure类是RDBMS存储过程的对象抽象的超类.这个类是抽象的,目的是让子类将提供一个用于调用的类型化方法,该方法委托 ...
-
各种SSD SMART 信息 转
intel SSD Toolbox SMART信息 解释:03 – Spin Up Time (磁头加载时间)The average time it takes the spindle to spin ...