Visual C++6.0画三维立体图形

在画三维立体图之前,主要是先要找到二维和三维的对应关系,这是转化的关键。
关键代码如下:

			S[i].x=P[i][1]+sqrt(2)/3.0*(-P[i][0]);
			S[i].y=P[i][2]+sqrt(2)/3.0*(-P[i][0]);

一、建立边表结构,在同一屏幕上完成三视图和正等轴测投影图

//消隐之前
//编译环境:Visual C++ 6.0,EasyX_20190219(beta)
#include
#include
#include
#define max 50
#include
#include
using namespace std;

#define pi 3.14159
using namespace std;
double ja=35.3;//54.7
double rad=(double)ja*pi/(double)180.0;
double Dpoint[][4]={
	{0,0,84,1},{110,0,84,1},{110,0,20,1},{140,0,20,1},
	{140,0,0,1},{140,80,0,1},{0,80,0,1},{0,80,54,1},
	{0,60,54,1},{0,60,84,1},{20,60,84,1},{20,20,84,1},
	{110,20,84,1},{110,20,20,1},{60,20,20,1},{60,80,20,1},
	{40,80,54,1},{40,60,54,1},{140,80,20,1},{0,0,0,1}
};

//下标从0开始
int ring[]={
	0,1,12,11,10,9,//0-5
	2,3,18,15,14,13,//6-11
	8,17,16,17,//12-15
	1,2,13,12,//16-19
	3,4,5,18,//20-23
	11,14,15,16,17,10,//24-29
	11,12,13,14,//30-33
	15,18,5,6,7,16,//34-39
	9,10,17,8,//40-43
	0,9,8,7,6,19,//44-49
	0,19,4,3,2,1,//50-55
	4,19,6,5//56-59
};
//构成面的顶点
int surface[12][2]={
	{0,5},{6,11},{12,15},{16,19},{20,23},{24,29},
	{30,33},{34,39},{40,43},{44,49},{50,55},{56,59}
};
//主视图
int XOZ_ring[]={
	1,2,14,10,
	0,7,16,10,
	3,15,17,7,6,4
};
int XOZ_surface[3][2]={
	{0,3},{4,7},{8,13}
};
//侧视图
int YOZ_ring[]={
	0,2,13,12,
	11,10,8,7,15,13,
	3,4,5,15
};
int YOZ_surface[3][2]={
	{0,3},{4,9},{10,13}
};
//俯视图
int XOY_ring[]={
	2,0,9,10,11,12,
	3,5,15,14,12,2,
	14,15,16,17,10,11,
	16,7,9,17
};
int XOY_surface[4][2]={
	{0,5},{6,11},{12,17},{18,21}
};

//正等轴投影
int XYZ_ring[]={
	3,4,5,18,
	5,6,7,16,15,18,
	2,3,18,15,14,13,
	1,2,13,12,
	11,12,13,14,
	10,11,14,15,16,17,
	7,8,17,16,
	8,9,10,17,
	0,1,12,11,10,9
};
int XYZ_surface[9][2]={
	{0,3},{4,9},{10,15},{16,19},{20,23},{24,29},{30,33},{34,37},{38,43}
};

//三维坐标转换为右手坐标系的二维坐标
void transfer(double P[max][4], int n, POINT S[])
{
	int i,j;
	for(i=0;i

效果演示:
Visual C++6.0画三维立体图形_第1张图片
二、给定点的三维坐标值,建立面表、环表、顶点表三表结构,画出三维物体的消隐图

//消隐之后 
//编译环境:Visual C++ 6.0,EasyX_20190219(beta)
#include
#include
#include
#define max 50
#include
#include
using namespace std;
#define pi 3.14159
using namespace std;
double ja=35.3;//54.7
double rad=(double)ja*pi/(double)180.0;
double Dpoint[][4]={
	{0,0,84,1},{110,0,84,1},{110,0,20,1},{140,0,20,1},
	{140,0,0,1},{140,80,0,1},{0,80,0,1},{0,80,54,1},
	{0,60,54,1},{0,60,84,1},{20,60,84,1},{20,20,84,1},
	{110,20,84,1},{110,20,20,1},{60,20,20,1},{60,80,20,1},
	{40,80,54,1},{40,60,54,1},{140,80,20,1},{0,0,0,1}
};

//下标从0开始
int ring[]={
	0,1,12,11,10,9,//0-5
	2,3,18,15,14,13,//6-11
	8,17,16,17,//12-15
	1,2,13,12,//16-19
	3,4,5,18,//20-23
	11,14,15,16,17,10,//24-29
	11,12,13,14,//30-33
	15,18,5,6,7,16,//34-39
	9,10,17,8,//40-43
	0,9,8,7,6,19,//44-49
	0,19,4,3,2,1,//50-55
	4,19,6,5//56-59
};
//构成面的顶点
int surface[12][2]={
	{0,5},{6,11},{12,15},{16,19},{20,23},{24,29},
	{30,33},{34,39},{40,43},{44,49},{50,55},{56,59}
};

//消影
int ring1[]={
	3,4,5,18,
	5,6,7,16,15,18,
	2,3,18,15,14,13,
	1,2,13,12,
	11,12,13,14,
	10,11,14,15,16,17,
	7,8,17,16,
	8,9,10,17,
	0,1,12,11,10,9
};
int surface1[9][2]={
	{0,3},{4,9},{10,15},{16,19},{20,23},{24,29},{30,33},{34,37},{38,43}
};

//三维坐标转换为右手坐标系的二维坐标
void transfer(double P[max][4], int n, POINT S[]){
	int i,j;
	for(i=0;i

效果演示:
Visual C++6.0画三维立体图形_第2张图片
红色为原图,黄色为消影之后的三维立体图,蓝色为消影后的正等轴侧投影图。

你可能感兴趣的:(C++,三维立体图形,计算机图形学)