资源简介
opengl的立方体消隐算法 可以实现选择 放大缩小
代码片段和文件信息
#include
#include
#include
#include
#define GLUT_WHEEL_UP 3 //定义滚轮操作
#define GLUT_WHEEL_DOWN 4
float PI = 3.1415926;
float points[8][3] = {{-1.0-1.0-1.0}{1.0-1.0-1.0} {1.01.0-1.0} {-1.01.0-1.0} {-1.0-1.01.0} {1.0-1.01.0}
{1.01.01.0} {-1.01.01.0}};
float colors[6][3]={{011}{001}{100}{110}{010}{101}};
int faces[6][4]={{4567}{1265}{0321}{0473}{0154}{2376}};
float x[4]y[4]z[4];
float anglex=PI*30/180angley=PI*30/180anglez=PI*30/180;
float size = 1.0;
GLubyte aoyun[]={//0111010001100011000110001100011000101110};
0x000x000x000x000x000x1E0x070x00
0x030xFE0x0F0x800x070xFF0x070xF0
0x0F0xFF0x830xF00x0F0xFF0xC10xF0
0x0F0xFF0xF00xF80x0F0xFF0xF80x78
0x0F0xF30xF80x380x0F0x800x7C0x38
0x0F0x000x380x780x070x040x300x70
0x0F0x0C0x200xF80x070x0C0x010xF8
0x070x0C0x030xF80x000x0C0x0F0xF8
0x080x180x1F0xF00x0E0x380x0F0xF0
0x0F0xF00x8F0xF00x0F0xF00x8F0xF0
0x0F0xF00x8F0xF00x060x000x0F0xF0
0x040x000x030xF00x040x000x000x60
0x060x7F0xF00x000x070x7E0x3E0x00
0x030xFC0x3F0x800x030xFC0x3F0x80
0x010xFE0x7E0x000x000xFF0xF00x00
0x000x1F0x000x000x000x000x000x00};
void Rotationx(float x_float y_float z_int i)//点饶X轴旋转时,改变一个点的坐标
{
x[i] = x_;
y[i] = y_*cos(anglex) - z_*sin(anglex);
z[i] = y_*sin(anglex) + z_*cos(anglex);
}
void Rotationy(float x_float y_float z_int i)//点饶Y轴旋转时,改变一个点的坐标
{
x[i] = x_*cos(angley) + z_*sin(angley);
y[i] = y_;
z[i] = z_*cos(angley) - x_*sin(angley);
}
void Rotationz(float x_float y_float z_int i)//点饶Z轴旋转时,改变一个点的坐标
{
x[i] = x_*cos(anglez) - y_*sin(anglez);
y[i] = x_*sin(anglez) + y_*cos(anglez);
z[i] = z_;
}
void Changex(int aint bint cint d)//一个平面饶X轴旋转时4个点坐标的该改
{
Rotationx(points[a][0]points[a][1]points[a][2]0);
Rotationx(points[b][0]points[b][1]points[b][2]1);
Rotationx(points[c][0]points[c][1]points[c][2]2);
Rotationx(points[d][0]points[d][1]points[d][2]3);
}
void Changey()//一个平面饶Y轴旋转时4个点坐标的该改
{
Rotationy(x[0]y[0]z[0]0);
Rotationy(x[1]y[1]z[1]1);
Rotationy(x[2]y[2]z[2]2);
Rotationy(x[3]y[3]z[3]3);
}
void Changez()//一个平面饶Y轴旋转时4个点坐标的该改
{
Rotationz(x[0]y[0]z[0]0);
Rotationz(x[1]y[1]z[1]1);
Rotationz(x[2]y[2]z[2]2);
Rotationz(x[3]y[3]z[3]3);
}
void init()//初始化
{
// glEnable(GL_DEPTH_TEST);
评论
共有 条评论