#include <windows.h>
#include <GL/glut.h>
GLint width=300,height=300;
static GLdouble angle,displace,scale=1,rPace,tPace;
GLdouble rAcc=0.0001d,tAcc=0.0000001d,state=1;
GLint interval=4096;
void triangle(GLfloat x1,GLfloat y1,GLfloat z1,GLfloat x2,GLfloat y2,GLfloat z2,GLfloat x3,GLfloat y3,GLfloat z3)
{
glBegin(GL_TRIANGLES);
glVertex3f(x1,y1,z1);
glVertex3f(x2,y2,z2);
glVertex3f(x3,y3,z3);
glEnd();
}
void init(void)
{
glClearColor(1,1,1,1);
glEnable(GL_DEPTH_TEST);
}
void reshape(GLint w,GLint h)
{
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(0,(GLfloat)w/(GLfloat)h,1,30);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glRotatef(-45,1,0,0);
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glTranslatef(0,displace,0);
glRotatef(angle,0,1,0);
glScalef(scale,scale,scale);
// a(0,0.12,0) b(-0.5,-0.7,-0.29) c(0.5,-0.7,-0.29) d(0,-0.7,0.58)
glColor3f(1,0,0); // abc
triangle(0,0.12,0,-0.5,-0.7,-0.29,0.5,-0.7,-0.29);
glColor3f(0,1,0); // abd
triangle(0,0.12,0,-0.5,-0.7,-0.29,0,-0.7,0.58);
glColor3f(0,0,1); // acd
triangle(0,0.12,0,0.5,-0.7,-0.29,0,-0.7,0.58);
glColor3f(0.5,0.5,0.5); // bcd
triangle(-0.5,-0.7,-0.29,0.5,-0.7,-0.29,0,-0.7,0.58);
glPopMatrix();
glFlush();
}
void idle()
{
if (state>2*interval)
state=1;
if (state++<=interval)
{
angle+=rPace;
displace+=tPace;
scale-=0.8/interval;
rPace+=rAcc;
tPace+=tAcc;
}
else
{
angle+=rPace;
displace-=tPace;
scale+=0.8/interval;
rPace-=rAcc;
tPace-=tAcc;
}
glutPostRedisplay();
}
int main()
{
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(width,height);
glutCreateWindow("Tetrahedron");
glutIdleFunc(idle);
init();
glutReshapeFunc(reshape);
glutDisplayFunc(display);
glutMainLoop();
return 0;
}
OpenGL 旋转的正三棱锥
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 没有多少人知道印度著名演员Vishal Malhotra(维沙尔)与已故的老将Pran有关,Pran是维沙尔妻子拉...