- 最后登录
- 2009-11-22
- 在线时间
- 2 小时
- 阅读权限
- 5
- 注册时间
- 2009-11-14
- 积分
- 6
- 帖子
- 5
- 精华
- 0
- UID
- 1243037
- 性别
- 女
- 积分
- 6
- 帖子
- 5
- 精华
- 0
- UID
- 1243037
- 性别
- 女
|
用C语言加openGL写的,非原创
#include <windows.h>
#include <gl/gl.h>
#include <gl/glu.h>
#include <gl/glut.h>
//小方块的结构,包括小方块在x,y,z上的旋转角度,颜色数组下标,小方块的三维坐标。
struct rcube{
int xr;
int yr;
int zr;
int cl[6];
GLfloat x;
GLfloat y;
GLfloat z;
};
struct rcube rc[3][3][3];
struct rcube *temp[3][3];
//颜色数组
GLfloat color[6][3]={{1.0,0.0,0.0},{0.0,1.0,0.0},{0.0,0.0,1.0},
{1.0,1.0,0.0},{1.0,0.0,1.0},{0.0,1.0,1.0}};
int tempc[3][3][6];
//有关旋转的一些变量
GLfloat xRot = 10.0f;
GLfloat yRot = 10.0f;
int rotateType=0;
int rotateOK=0;
int rotateRate=50;
int rotate=0;
///////////////////////////////////////////////////////////////////////////////
//画小方块
void drawcube(int cl[6])
{
glBegin(GL_QUADS);
//右面
glColor3fv(color[cl[0]]);
glVertex3f(0.14f,-0.14f,-0.14f);
glVertex3f(0.14f,0.14f,-0.14f);
glVertex3f(0.14f,0.14f,0.14f);
glVertex3f(0.14f,-0.14f,0.14f);
//左面
glColor3fv(color[cl[1]]);
glVertex3f(-0.14f,-0.14f,0.14f);
glVertex3f(-0.14f,0.14f,0.14f);
glVertex3f(-0.14f,0.14f,-0.14f);
glVertex3f(-0.14f,-0.14f,-0.14f);
//前面
glColor3fv(color[cl[2]]);
glVertex3f(-0.14f,0.14f,0.14f);
glVertex3f(-0.14f,-0.14f,0.14f);
glVertex3f(0.14f,-0.14f,0.14f);
glVertex3f(0.14f,0.14f,0.14f);
//后面
glColor3fv(color[cl[3]]);
glVertex3f(-0.14f,0.14f,-0.14f);
glVertex3f(0.14f,0.14f,-0.14f);
glVertex3f(0.14f,-0.14f,-0.14f);
glVertex3f(-0.14f,-0.14f,-0.14f);
//上面
glColor3fv(color[cl[4]]);
glVertex3f(-0.14f,0.14f,-0.14f);
glVertex3f(-0.14f,0.14f,0.14f);
glVertex3f(0.14f,0.14f,0.14f);
glVertex3f(0.14f,0.14f,-0.14f);
//下面
glColor3fv(color[cl[5]]);
glVertex3f(-0.14f,-0.14f,-0.14f);
glVertex3f(0.14f,-0.14f,-0.14f);
glVertex3f(0.14f,-0.14f,0.14f);
glVertex3f(-0.14f,-0.14f,0.14f);
glEnd();
glFlush();
} |
|