3D几何图形的生成算法
在之前的博客上,发布了一个我写的3D几何图形生成的DEMO:
http://www.cnblogs.com/WhyEngine/p/3415040.html
DEMO下载地址:
https://files.cnblogs.com/WhyEngine/GeometryDemo4.0.zip
现在要将图形生成的算法代码发布出来,将分成以下章节:
这一节先将一些宏定义和结构体的代码帖一下
类型定义
// --------------------------------------------------------------------------------------
#define YD_INLINE inline
#define YD_FORCE_INLINE __forceinline
#define YD_NULL 0
#define YD_NONE
// --------------------------------------------------------------------------------------
typedef __int64 Yint64;
typedef signed long Yint32;
typedef signed short Yint16;
typedef signed char Yint8;
typedef unsigned __int64 Yuint64;
typedef unsigned long Yuint32;
typedef unsigned short Yuint16;
typedef unsigned char Yuint8;
typedef unsigned long Ydword;
typedef unsigned short Yword;
typedef unsigned char Ybyte;
typedef float Yreal32;
typedef double Yreal64;
typedef float Yfloat;
typedef double Ydouble;
typedef Yint8 Ychar;
typedef Yint16 Yshort;
typedef Yint32 Yint;
typedef Yuint32 Yuint;
typedef Yreal32 Yreal;
// --------------------------------------------------------------------------------------
typedef int Ybool;
#define YD_FALSE 0
#define YD_TRUE 1
// --------------------------------------------------------------------------------------
宏定义
// --------------------------------------------------------------------------------------
#define YD_REAL_PI 3.14159265358979f // 圆周率
#define YD_REAL_HALF_PI 1.57079632679490f // PI / 2
#define YD_REAL_QUARTER_PI 0.78539816339745f // PI / 4
#define YD_REAL_TWAIN_PI 6.28318530717958f // PI * 2
#define YD_REAL_E 2.71828182845905f // e
#define YD_REAL_LOG2E 1.44269504088896f // log2(e)
#define YD_REAL_LOG10E 0.43429448190325f // log10(e)
#define YD_REAL_LN2 0.69314718055995f // ln(2)
#define YD_REAL_LN10 2.30258509299405f // ln(10)
#define YD_REAL_SQRT_2 1.41421356237310f // sqrt(2)
#define YD_REAL_SQRT_1_2 0.70710678118655f // 1/sqrt(2)
#define YD_REAL_SQRT_3 1.73205077648163f // sqrt(3)
索引结构
// 索引类型(16位索引或32位索引)
enum YeIndexType
{
YE_INDEX_INVALID = 0,
YE_INDEX_16_BIT = 16,
YE_INDEX_32_BIT = 32,
};
// --------------------------------------------------------------------------------------
// 三角面片的索引结构
struct YsTriIndex16
{
Yuint16 index0;
Yuint16 index1;
Yuint16 index2;
};
struct YsTriIndex32
{
Yuint32 index0;
Yuint32 index1;
Yuint32 index2;
};
// --------------------------------------------------------------------------------------
// 线的索引结构
struct YsLineIndex16
{
Yuint16 index0;
Yuint16 index1;
};
struct YsLineIndex32
{
Yuint32 index0;
Yuint32 index1;
};
图形类型定义
// 简单图形的类型
enum YeGraphType
{
YE_GRAPH_INVALID = 0,
YE_GRAPH_PLANE = 1, // 平面
YE_GRAPH_BOX = 2, // 立方体
YE_GRAPH_SPHERE = 3, // 球
YE_GRAPH_CONE = 4, // 圆锥
YE_GRAPH_CYLINDER = 5, // 柱台
YE_GRAPH_CAPSULE = 6, // 胶囊体
YE_GRAPH_PYRAMID = 7, // 金字塔
YE_GRAPH_ROUND = 8, // 圆面
YE_GRAPH_RING = 9, // 圆环
YE_GRAPH_PIPE = 10, // 圆管
YE_GRAPH_WEDGE = 11, // 楔形体
YE_GRAPH_FAN = 12, // 扇形体
YE_GRAPH_ARC = 13, // 弧面
YE_GRAPH_GEARWHEEL = 14, // 齿轮
YE_GRAPH_STAR = 15, // 星星
YE_GRAPH_SPIRE = 16, // 螺旋面
YE_GRAPH_STAIRS = 17, // 楼梯
YE_GRAPH_SPIRAL_STAIRS = 18, // 螺旋楼梯
YE_GRAPH_HEMISPHERE = 19, // 半球形
YE_GRAPH_DRUM = 20, // 鼓状物
};
// 模型的起始位置
enum YeOriginPose
{
YE_ORIGIN_POSE_TOP = 0,
YE_ORIGIN_POSE_CENTER = 1,
YE_ORIGIN_POSE_BOTTOM = 2
};